Skip to content

Commit

Permalink
Merge branch 'main' into move-target
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss authored May 20, 2024
2 parents a3fcd78 + 581f247 commit aeefdab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ main, 'stable/*' ]
pull_request:
branches: [ main, 'stable/*' ]
merge_group:

concurrency:
group: ${{ github.repository }}-${{ github.ref }}-${{ github.head_ref }}
Expand Down
7 changes: 4 additions & 3 deletions qiskit/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,11 @@
``__array__``. This is used by :meth:`Gate.to_matrix`, and has the signature:
.. currentmodule:: None
.. py:method:: __array__(dtype=None, copy=None)
.. py:method:: object.__array__(dtype=None, copy=None)
Return a Numpy array representing the gate. This can use the gate's :attr:`~Instruction.params`
field, and may assume that these are numeric values (assuming the subclass expects that) and not
Return a Numpy array representing the gate. This can use the gate's
:attr:`~qiskit.circuit.Instruction.params` field, and may assume that these are numeric
values (assuming the subclass expects that) and not
:ref:`compile-time parameters <circuit-compile-time-parameters>`.
For greatest efficiency, the returned array should default to a dtype of :class:`complex`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class PauliFeatureMap(NLocal):
>>> from qiskit.circuit.library import EfficientSU2
>>> prep = PauliFeatureMap(3, reps=3, paulis=['Z', 'YY', 'ZXZ'])
>>> wavefunction = EfficientSU2(3)
>>> classifier = prep.compose(wavefunction
>>> classifier = prep.compose(wavefunction)
>>> classifier.num_parameters
27
>>> classifier.count_ops()
Expand Down
10 changes: 9 additions & 1 deletion qiskit/circuit/library/overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class UnitaryOverlap(QuantumCircuit):
"""

def __init__(
self, unitary1: QuantumCircuit, unitary2: QuantumCircuit, prefix1="p1", prefix2="p2"
self,
unitary1: QuantumCircuit,
unitary2: QuantumCircuit,
prefix1: str = "p1",
prefix2: str = "p2",
insert_barrier: bool = False,
):
"""
Args:
Expand All @@ -69,6 +74,7 @@ def __init__(
if it is parameterized. Defaults to ``"p1"``.
prefix2: The name of the parameter vector associated to ``unitary2``,
if it is parameterized. Defaults to ``"p2"``.
insert_barrier: Whether to insert a barrier between the two unitaries.
Raises:
CircuitError: Number of qubits in ``unitary1`` and ``unitary2`` does not match.
Expand All @@ -95,6 +101,8 @@ def __init__(
# Generate the actual overlap circuit
super().__init__(unitaries[0].num_qubits, name="UnitaryOverlap")
self.compose(unitaries[0], inplace=True)
if insert_barrier:
self.barrier()
self.compose(unitaries[1].inverse(), inplace=True)


Expand Down
15 changes: 15 additions & 0 deletions test/python/circuit/library/test_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ def test_mismatching_qubits(self):
with self.assertRaises(CircuitError):
_ = UnitaryOverlap(unitary1, unitary2)

def test_insert_barrier(self):
"""Test inserting barrier between circuits"""
unitary1 = EfficientSU2(1, reps=1)
unitary2 = EfficientSU2(1, reps=1)
overlap = UnitaryOverlap(unitary1, unitary2, insert_barrier=True)
self.assertEqual(overlap.count_ops()["barrier"], 1)
self.assertEqual(
str(overlap.draw(fold=-1, output="text")).strip(),
"""
┌───────────────────────────────────────┐ ░ ┌──────────────────────────────────────────┐
q: ┤ EfficientSU2(p1[0],p1[1],p1[2],p1[3]) ├─░─┤ EfficientSU2_dg(p2[0],p2[1],p2[2],p2[3]) ├
└───────────────────────────────────────┘ ░ └──────────────────────────────────────────┘
""".strip(),
)


if __name__ == "__main__":
unittest.main()

0 comments on commit aeefdab

Please sign in to comment.