diff --git a/crates/accelerate/src/isometry.rs b/crates/accelerate/src/isometry.rs index 8d0761666bb6..a4e83358a7da 100644 --- a/crates/accelerate/src/isometry.rs +++ b/crates/accelerate/src/isometry.rs @@ -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 diff --git a/releasenotes/notes/fix-isometry-rust-adf0eed09c6611f1.yaml b/releasenotes/notes/fix-isometry-rust-adf0eed09c6611f1.yaml new file mode 100644 index 000000000000..4eeaa9aa3d7a --- /dev/null +++ b/releasenotes/notes/fix-isometry-rust-adf0eed09c6611f1.yaml @@ -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. diff --git a/test/python/circuit/test_controlled_gate.py b/test/python/circuit/test_controlled_gate.py index f0d6dd3a8f7e..ced7229415ea 100644 --- a/test/python/circuit/test_controlled_gate.py +++ b/test/python/circuit/test_controlled_gate.py @@ -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)