Skip to content

Commit

Permalink
Fix a bug in isometry.rs (#12469) (#12471)
Browse files Browse the repository at this point in the history
* remove assertion

* extend the test

* add release notes

* fix release notes

* Update releasenotes/notes/fix-isometry-rust-adf0eed09c6611f1.yaml

Co-authored-by: Matthew Treinish <[email protected]>

---------

Co-authored-by: Matthew Treinish <[email protected]>
(cherry picked from commit 0f0a634)

Co-authored-by: Shelly Garion <[email protected]>
  • Loading branch information
mergify[bot] and ShellyGarion authored May 28, 2024
1 parent 2a5c492 commit bac400d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion crates/accelerate/src/isometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ fn construct_basis_states(
} else if i == target_label {
e2 += 1;
} else {
assert!(j <= 1);
e1 += state_free[j] as usize;
e2 += state_free[j] as usize;
j += 1
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/fix-isometry-rust-adf0eed09c6611f1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fix a bug in :class:`~.library.Isometry` due to an unnecessary assertion,
that led to an error in :meth:`.UnitaryGate.control`
when :class:`~.library.UnitaryGate` had more that two qubits.
5 changes: 2 additions & 3 deletions test/python/circuit/test_controlled_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,9 @@ def test_controlled_unitary(self, num_ctrl_qubits):
self.assertTrue(is_unitary_matrix(base_mat))
self.assertTrue(matrix_equal(cop_mat, test_op.data))

@data(1, 2, 3, 4, 5)
def test_controlled_random_unitary(self, num_ctrl_qubits):
@combine(num_ctrl_qubits=(1, 2, 3, 4, 5), num_target=(2, 3))
def test_controlled_random_unitary(self, num_ctrl_qubits, num_target):
"""Test the matrix data of an Operator based on a random UnitaryGate."""
num_target = 2
base_gate = random_unitary(2**num_target).to_instruction()
base_mat = base_gate.to_matrix()
cgate = base_gate.control(num_ctrl_qubits)
Expand Down

0 comments on commit bac400d

Please sign in to comment.