Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the matrix representation of CUGate in Rust (backport #13121) #13124

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading