Skip to content

Commit

Permalink
Allow barriers in overlap circuit inputs (#11179)
Browse files Browse the repository at this point in the history
* Allow barriers in overlap circuit inputs

* Minor fixes plus test with barriers

* Check parameter number on barrier test, similar to other non-failing tests.

* test order

* Add release note
  • Loading branch information
caleb-johnson committed Nov 8, 2023
1 parent af643eb commit 25c46dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion qiskit/circuit/library/overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from qiskit.circuit import QuantumCircuit, Gate
from qiskit.circuit.parametervector import ParameterVector
from qiskit.circuit.exceptions import CircuitError
from qiskit.circuit import Barrier


class UnitaryOverlap(QuantumCircuit):
Expand Down Expand Up @@ -101,7 +102,7 @@ def _check_unitary(circuit):
"""Check a circuit is unitary by checking if all operations are of type ``Gate``."""

for instruction in circuit.data:
if not isinstance(instruction.operation, Gate):
if not isinstance(instruction.operation, (Gate, Barrier)):
raise CircuitError(
(
"One or more instructions cannot be converted to"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Fixed a bug which caused :class:`~qiskit.circuit.library.UnitaryOverlap` to error upon initialization if given an input circuit containing a barrier.
9 changes: 9 additions & 0 deletions test/python/circuit/library/test_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ def test_partial_parameterized_inputs2(self):
overlap = UnitaryOverlap(unitary1, unitary2)
self.assertEqual(overlap.num_parameters, unitary1.num_parameters)

def test_barrier(self):
"""Test that barriers on input circuits are well handled"""
unitary1 = EfficientSU2(1, reps=0)
unitary1.barrier()
unitary2 = EfficientSU2(1, reps=1)
unitary2.barrier()
overlap = UnitaryOverlap(unitary1, unitary2)
self.assertEqual(overlap.num_parameters, unitary1.num_parameters + unitary2.num_parameters)

def test_measurements(self):
"""Test that exception is thrown for measurements"""
unitary1 = EfficientSU2(2)
Expand Down

0 comments on commit 25c46dc

Please sign in to comment.