diff --git a/qiskit/circuit/barrier.py b/qiskit/circuit/barrier.py index 4bb37558bc20..54e6b2c06191 100644 --- a/qiskit/circuit/barrier.py +++ b/qiskit/circuit/barrier.py @@ -47,8 +47,5 @@ def inverse(self): """Special case. Return self.""" return Barrier(self.num_qubits) - def broadcast_arguments(self, qargs, cargs): - yield [qarg for sublist in qargs for qarg in sublist], [] - def c_if(self, classical, val): raise QiskitError("Barriers are compiler directives and cannot be conditional.") diff --git a/releasenotes/notes/fix-barrier-arg-list-check-ff69f37ede6bdf6c.yaml b/releasenotes/notes/fix-barrier-arg-list-check-ff69f37ede6bdf6c.yaml new file mode 100644 index 000000000000..b620a72666f3 --- /dev/null +++ b/releasenotes/notes/fix-barrier-arg-list-check-ff69f37ede6bdf6c.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixed an issue with the :class:`.Barrier` class. When adding a + :class:`.Barrier` instance to a :class:`.QuantumCircuit` with the + :meth:`.QuantumCircuit.append` method previously there was no validation + that the size of the barrier matched the qargs specified. diff --git a/test/python/circuit/test_circuit_operations.py b/test/python/circuit/test_circuit_operations.py index 1cd66723ecfd..11770d896bc6 100644 --- a/test/python/circuit/test_circuit_operations.py +++ b/test/python/circuit/test_circuit_operations.py @@ -17,7 +17,7 @@ from ddt import data, ddt from qiskit import BasicAer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute -from qiskit.circuit import Gate, Instruction, Measure, Parameter +from qiskit.circuit import Gate, Instruction, Measure, Parameter, Barrier from qiskit.circuit.bit import Bit from qiskit.circuit.classicalregister import Clbit from qiskit.circuit.exceptions import CircuitError @@ -156,6 +156,8 @@ def test_append_rejects_bad_arguments_opaque(self, bad_arg): qc.append(inst, bad_arg, [0, 1]) with self.assertRaisesRegex(CircuitError, "The amount of clbit arguments"): qc.append(inst, [0, 1], bad_arg) + with self.assertRaisesRegex(CircuitError, "The amount of qubit arguments"): + qc.append(Barrier(4), bad_arg) def test_anding_self(self): """Test that qc &= qc finishes, which can be prone to infinite while-loops.