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

Allow barriers in overlap circuit inputs #11179

Merged
merged 5 commits into from
Nov 8, 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: 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