From 8b569959d046614e338e100cb8033e5918e778eb Mon Sep 17 00:00:00 2001 From: Arnau Casau <47946624+arnaucasau@users.noreply.github.com> Date: Fri, 17 May 2024 02:58:50 +0200 Subject: [PATCH 1/4] Fix `qiskit.circuit` method header and broken cross-reference (#12394) * Fix qiskit.circuit method header * use object * fix lint * Correct method to be defined on `object` --------- Co-authored-by: Jake Lishman --- qiskit/circuit/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/qiskit/circuit/__init__.py b/qiskit/circuit/__init__.py index 3982fa873349..43087760153e 100644 --- a/qiskit/circuit/__init__.py +++ b/qiskit/circuit/__init__.py @@ -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 `. For greatest efficiency, the returned array should default to a dtype of :class:`complex`. From 8571afe3775fdd2f72354142d14bfc2ac0292da6 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 17 May 2024 08:59:31 -0400 Subject: [PATCH 2/4] Add merge queue to required tests on github actions (#12428) This commit adds the missing config to the github actions workflow for running required tests (currently only arm64 macOS test jobs) to the merge queue. This is necessary to make the job required in the branch protection rules, because the jobs will need to pass as part of the merge queue too. --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0d04e21a1696..08530adfd4f1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,6 +5,7 @@ on: branches: [ main, 'stable/*' ] pull_request: branches: [ main, 'stable/*' ] + merge_group: concurrency: group: ${{ github.repository }}-${{ github.ref }}-${{ github.head_ref }} From 4e3de44bcbde61fae33848a94be2622f5f5bd959 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Fri, 17 May 2024 12:55:48 -0400 Subject: [PATCH 3/4] Add missing paranthesis to pauli_feature_map.py (#12434) --- qiskit/circuit/library/data_preparation/pauli_feature_map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/circuit/library/data_preparation/pauli_feature_map.py b/qiskit/circuit/library/data_preparation/pauli_feature_map.py index b05287ca049f..03bbc031ec63 100644 --- a/qiskit/circuit/library/data_preparation/pauli_feature_map.py +++ b/qiskit/circuit/library/data_preparation/pauli_feature_map.py @@ -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() From 581f24784d5267261c06ead8ec9adf303e291b5a Mon Sep 17 00:00:00 2001 From: "Kevin J. Sung" Date: Fri, 17 May 2024 16:49:16 -0400 Subject: [PATCH 4/4] add insert_barrier argument to UnitaryOverlap (#12321) * add insert_barrier argument to UnitaryOverlap * set fold=-1 in circuit drawing --- qiskit/circuit/library/overlap.py | 10 +++++++++- test/python/circuit/library/test_overlap.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/qiskit/circuit/library/overlap.py b/qiskit/circuit/library/overlap.py index 38f5fb9184e1..2db6a80eedcc 100644 --- a/qiskit/circuit/library/overlap.py +++ b/qiskit/circuit/library/overlap.py @@ -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: @@ -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. @@ -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) diff --git a/test/python/circuit/library/test_overlap.py b/test/python/circuit/library/test_overlap.py index a603f28037b1..1a95e3ba9155 100644 --- a/test/python/circuit/library/test_overlap.py +++ b/test/python/circuit/library/test_overlap.py @@ -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()