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 Barrier broadcast arguments #11113

Merged
merged 1 commit into from
Oct 25, 2023
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
3 changes: 0 additions & 3 deletions qiskit/circuit/barrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion test/python/circuit/test_circuit_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down