diff --git a/crates/circuit/src/gate_matrix.rs b/crates/circuit/src/gate_matrix.rs index a38783ef7e7f..6b04b8512fb0 100644 --- a/crates/circuit/src/gate_matrix.rs +++ b/crates/circuit/src/gate_matrix.rs @@ -387,12 +387,12 @@ pub fn cu_gate(theta: f64, phi: f64, lam: f64, gamma: f64) -> GateArray2Q { C_ZERO, c64(0., gamma).exp() * cos_theta, C_ZERO, - c64(0., gamma + phi).exp() * (-1.) * sin_theta, + c64(0., gamma + lam).exp() * (-1.) * sin_theta, ], [C_ZERO, C_ZERO, C_ONE, C_ZERO], [ C_ZERO, - c64(0., gamma + lam).exp() * sin_theta, + c64(0., gamma + phi).exp() * sin_theta, C_ZERO, c64(0., gamma + phi + lam).exp() * cos_theta, ], diff --git a/releasenotes/notes/fix-cu-rust-6464b6893ecca1b3.yaml b/releasenotes/notes/fix-cu-rust-6464b6893ecca1b3.yaml new file mode 100644 index 000000000000..406d6052a1df --- /dev/null +++ b/releasenotes/notes/fix-cu-rust-6464b6893ecca1b3.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + Fixed the definition of the :class:`.CUGate` matrix in Rust-space. + While this was not noticable while handling the :class:`.CUGate` purely on + Python side, this had knock-on effects when transpiler passes were using the + Rust representation, such as could happen in :class:`.Consolidate2qBlocks`. + Fixed `#13118 `__. + diff --git a/test/python/circuit/test_rust_equivalence.py b/test/python/circuit/test_rust_equivalence.py index b6ec28f82e8d..db4f1441bea3 100644 --- a/test/python/circuit/test_rust_equivalence.py +++ b/test/python/circuit/test_rust_equivalence.py @@ -66,7 +66,7 @@ def test_definitions(self): continue with self.subTest(name=name): - params = [pi] * standard_gate._num_params() + params = [0.1 * (i + 1) for i in range(standard_gate._num_params())] py_def = gate_class.base_class(*params).definition rs_def = standard_gate._get_definition(params) if py_def is None: @@ -141,7 +141,7 @@ def test_matrix(self): continue with self.subTest(name=name): - params = [0.1] * standard_gate._num_params() + params = [0.1 * (i + 1) for i in range(standard_gate._num_params())] py_def = gate_class.base_class(*params).to_matrix() rs_def = standard_gate._to_matrix(params) np.testing.assert_allclose(rs_def, py_def)