diff --git a/crates/accelerate/src/unitary_synthesis.rs b/crates/accelerate/src/unitary_synthesis.rs index 9917deab3721..6ce6f78776f3 100644 --- a/crates/accelerate/src/unitary_synthesis.rs +++ b/crates/accelerate/src/unitary_synthesis.rs @@ -951,7 +951,11 @@ fn synth_su4_sequence( _ => panic!(), }; if synth_dir != preferred_dir { - reversed_synth_su4_sequence(su4_mat, decomposer_2q, approximation_degree) + reversed_synth_su4_sequence( + su4_mat.clone(), + decomposer_2q, + approximation_degree, + ) } else { Ok(sequence) } @@ -962,22 +966,22 @@ fn synth_su4_sequence( } fn reversed_synth_su4_sequence( - su4_mat: Array2, + mut su4_mat: Array2, decomposer_2q: &DecomposerElement, approximation_degree: Option, ) -> PyResult { let is_approximate = approximation_degree.is_none() || approximation_degree.unwrap() != 1.0; // Swap rows 1 and 2 - let (mut row_1, mut row_2) = su4_mat_mm.multi_slice_mut((s![1, ..], s![2, ..])); + let (mut row_1, mut row_2) = su4_mat.multi_slice_mut((s![1, ..], s![2, ..])); azip!((x in &mut row_1, y in &mut row_2) (*x, *y) = (*y, *x)); // Swap columns 1 and 2 - let (mut col_1, mut col_2) = su4_mat_mm.multi_slice_mut((s![.., 1], s![.., 2])); + let (mut col_1, mut col_2) = su4_mat.multi_slice_mut((s![.., 1], s![.., 2])); azip!((x in &mut col_1, y in &mut col_2) (*x, *y) = (*y, *x)); let mut synth = if let DecomposerType::TwoQubitBasisDecomposer(decomp) = &decomposer_2q.decomposer { - decomp.call_inner(su4_mat_mm.view(), None, is_approximate, None)? + decomp.call_inner(su4_mat.view(), None, is_approximate, None)? } else { panic!("reversed_synth_su4_sequence should only be called for TwoQubitBasisDecomposer.") }; @@ -1041,7 +1045,12 @@ fn synth_su4_dag( _ => panic!("There are no more than 2 possible synth directions."), }; if synth_dir != preferred_dir { - reversed_synth_su4_dag(py, su4_mat, decomposer_2q, approximation_degree) + reversed_synth_su4_dag( + py, + su4_mat.clone(), + decomposer_2q, + approximation_degree, + ) } else { Ok(synth_dag) } @@ -1053,19 +1062,18 @@ fn synth_su4_dag( fn reversed_synth_su4_dag( py: Python<'_>, - su4_mat: &Array2, + mut su4_mat: Array2, decomposer_2q: &DecomposerElement, approximation_degree: Option, ) -> PyResult { let is_approximate = approximation_degree.is_none() || approximation_degree.unwrap() != 1.0; - let mut su4_mat_mm = su4_mat.clone(); // Swap rows 1 and 2 - let (mut row_1, mut row_2) = su4_mat_mm.multi_slice_mut((s![1, ..], s![2, ..])); + let (mut row_1, mut row_2) = su4_mat.multi_slice_mut((s![1, ..], s![2, ..])); azip!((x in &mut row_1, y in &mut row_2) (*x, *y) = (*y, *x)); // Swap columns 1 and 2 - let (mut col_1, mut col_2) = su4_mat_mm.multi_slice_mut((s![.., 1], s![.., 2])); + let (mut col_1, mut col_2) = su4_mat.multi_slice_mut((s![.., 1], s![.., 2])); azip!((x in &mut col_1, y in &mut col_2) (*x, *y) = (*y, *x)); let synth_dag = if let DecomposerType::XXDecomposer(decomposer) = &decomposer_2q.decomposer { @@ -1075,7 +1083,7 @@ fn reversed_synth_su4_dag( decomposer .call_bound( py, - (su4_mat_mm.clone().into_pyarray_bound(py),), + (su4_mat.clone().into_pyarray_bound(py),), Some(&kwargs.into_py_dict_bound(py)), )? .extract::(py)?