Skip to content

Commit

Permalink
Fix the matrix representation of CUGate in Rust (#13121)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
  • Loading branch information
Cryoris and mtreinish authored Sep 10, 2024
1 parent 1962704 commit 8929e12
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crates/circuit/src/gate_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand Down
9 changes: 9 additions & 0 deletions releasenotes/notes/fix-cu-rust-6464b6893ecca1b3.yaml
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/Qiskit/qiskit/issues/13118>`__.
4 changes: 2 additions & 2 deletions test/python/circuit/test_rust_equivalence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8929e12

Please sign in to comment.