From 01e7ab5829aaddc04c49eb3beec568802f97a638 Mon Sep 17 00:00:00 2001 From: Jim Garrison Date: Fri, 7 Mar 2025 22:43:56 -0500 Subject: [PATCH] Fix tests The `efficient_su2` function returns gates in a slightly different order than a `decompose`d `EfficientSU2`, hence these changes. --- ...generate_exact_sampling_coefficients.ipynb | 2 +- ...gate_cutting_to_reduce_circuit_width.ipynb | 2 +- ...gate_cutting_to_reduce_circuit_depth.ipynb | 2 +- pyproject.toml | 2 +- .../notes/bump-qiskit-30bb4efa538e5ef0.yaml | 4 ++++ test/cut_finding/test_cco_utils.py | 8 +++---- test/cut_finding/test_cut_finder_results.py | 24 +++++++++---------- test/qpd/test_qpd.py | 2 +- test/test_cutting_decomposition.py | 4 ++-- test/test_cutting_workflows.py | 4 ++-- test/test_find_cuts.py | 2 +- test/utils/test_transforms.py | 2 +- 12 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 releasenotes/notes/bump-qiskit-30bb4efa538e5ef0.yaml diff --git a/docs/how-tos/how_to_generate_exact_sampling_coefficients.ipynb b/docs/how-tos/how_to_generate_exact_sampling_coefficients.ipynb index 57916649..25bbc759 100644 --- a/docs/how-tos/how_to_generate_exact_sampling_coefficients.ipynb +++ b/docs/how-tos/how_to_generate_exact_sampling_coefficients.ipynb @@ -48,7 +48,7 @@ } ], "source": [ - "circuit = efficient_su2(4, entanglement=\"linear\", reps=2).decompose()\n", + "circuit = efficient_su2(4, entanglement=\"linear\", reps=2)\n", "circuit.assign_parameters([0.8] * len(circuit.parameters), inplace=True)\n", "observable = SparsePauliOp([\"ZZZZ\"])\n", "circuit.draw(\"mpl\", scale=0.8)" diff --git a/docs/tutorials/01_gate_cutting_to_reduce_circuit_width.ipynb b/docs/tutorials/01_gate_cutting_to_reduce_circuit_width.ipynb index a11fc11c..e83d5c25 100644 --- a/docs/tutorials/01_gate_cutting_to_reduce_circuit_width.ipynb +++ b/docs/tutorials/01_gate_cutting_to_reduce_circuit_width.ipynb @@ -53,7 +53,7 @@ "source": [ "from qiskit.circuit.library import efficient_su2\n", "\n", - "qc = efficient_su2(4, entanglement=\"linear\", reps=2).decompose()\n", + "qc = efficient_su2(4, entanglement=\"linear\", reps=2)\n", "qc.assign_parameters([0.4] * len(qc.parameters), inplace=True)\n", "\n", "qc.draw(\"mpl\", scale=0.8)" diff --git a/docs/tutorials/02_gate_cutting_to_reduce_circuit_depth.ipynb b/docs/tutorials/02_gate_cutting_to_reduce_circuit_depth.ipynb index 866d66cb..bc0706bd 100644 --- a/docs/tutorials/02_gate_cutting_to_reduce_circuit_depth.ipynb +++ b/docs/tutorials/02_gate_cutting_to_reduce_circuit_depth.ipynb @@ -53,7 +53,7 @@ "source": [ "from qiskit.circuit.library import efficient_su2\n", "\n", - "circuit = efficient_su2(num_qubits=4, entanglement=\"circular\").decompose()\n", + "circuit = efficient_su2(num_qubits=4, entanglement=\"circular\")\n", "circuit.assign_parameters([0.4] * len(circuit.parameters), inplace=True)\n", "circuit.draw(\"mpl\", scale=0.8)" ] diff --git a/pyproject.toml b/pyproject.toml index 35daa241..418a98a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ dependencies = [ "scipy>=1.5.2", "rustworkx>=0.14.0", "qiskit-aer>=0.14.0.1", - "qiskit>=1.1.0, !=1.3.0, <2.0", + "qiskit>=1.3.1, <2.0", "qiskit-ibm-runtime>=0.24.0", ] diff --git a/releasenotes/notes/bump-qiskit-30bb4efa538e5ef0.yaml b/releasenotes/notes/bump-qiskit-30bb4efa538e5ef0.yaml new file mode 100644 index 00000000..7e5dcc28 --- /dev/null +++ b/releasenotes/notes/bump-qiskit-30bb4efa538e5ef0.yaml @@ -0,0 +1,4 @@ +--- +upgrade: + - | + Qiskit SDK 1.3.1 or higher is now required. diff --git a/test/cut_finding/test_cco_utils.py b/test/cut_finding/test_cco_utils.py index 06fb8254..9cd1871c 100644 --- a/test/cut_finding/test_cco_utils.py +++ b/test/cut_finding/test_cco_utils.py @@ -40,7 +40,7 @@ def create_test_circuit_1(): def create_test_circuit_2(): - tc_2 = efficient_su2(2, entanglement="linear", reps=2).decompose() + tc_2 = efficient_su2(2, entanglement="linear", reps=2) tc_2.assign_parameters([0.4] * len(tc_2.parameters), inplace=True) return tc_2 @@ -80,18 +80,18 @@ def internal_test_circuit(): create_test_circuit_2, [ CircuitElement("ry", [0.4], [0], None), - CircuitElement("rz", [0.4], [0], None), CircuitElement("ry", [0.4], [1], None), + CircuitElement("rz", [0.4], [0], None), CircuitElement("rz", [0.4], [1], None), CircuitElement("cx", [], [0, 1], 3), CircuitElement("ry", [0.4], [0], None), - CircuitElement("rz", [0.4], [0], None), CircuitElement("ry", [0.4], [1], None), + CircuitElement("rz", [0.4], [0], None), CircuitElement("rz", [0.4], [1], None), CircuitElement("cx", [], [0, 1], 3), CircuitElement("ry", [0.4], [0], None), - CircuitElement("rz", [0.4], [0], None), CircuitElement("ry", [0.4], [1], None), + CircuitElement("rz", [0.4], [0], None), CircuitElement("rz", [0.4], [1], None), ], ), diff --git a/test/cut_finding/test_cut_finder_results.py b/test/cut_finding/test_cut_finder_results.py index c04d6651..a5809c80 100644 --- a/test/cut_finding/test_cut_finder_results.py +++ b/test/cut_finding/test_cut_finder_results.py @@ -41,7 +41,7 @@ class TestCuttingFourQubitCircuit(unittest.TestCase): def setUp(self): - qc = efficient_su2(4, entanglement="linear", reps=2).decompose() + qc = efficient_su2(4, entanglement="linear", reps=2) qc.assign_parameters([0.4] * len(qc.parameters), inplace=True) self.circuit_internal = qc_to_cco_circuit(qc) @@ -134,13 +134,13 @@ def test_four_qubit_cutting_workflow(self): CutIdentifier( cut_action="CutTwoQubitGate", cut_location=CutLocation( - instruction_id=17, gate_name="cx", qubits=[2, 3] + instruction_id=10, gate_name="cx", qubits=[2, 3] ), ), CutIdentifier( cut_action="CutTwoQubitGate", cut_location=CutLocation( - instruction_id=25, gate_name="cx", qubits=[2, 3] + instruction_id=21, gate_name="cx", qubits=[2, 3] ), ), ] @@ -233,16 +233,16 @@ def test_four_qubit_cutting_workflow(self): instruction_id=9, gate_name="cx", qubits=[1, 2], input=1 ), ), - CutIdentifier( - cut_action="CutBothWires", - cut_location=CutLocation( - instruction_id=12, gate_name="cx", qubits=[0, 1] - ), - ), SingleWireCutIdentifier( cut_action="CutLeftWire", wire_cut_location=WireCutLocation( - instruction_id=17, gate_name="cx", qubits=[2, 3], input=1 + instruction_id=10, gate_name="cx", qubits=[2, 3], input=1 + ), + ), + CutIdentifier( + cut_action="CutBothWires", + cut_location=CutLocation( + instruction_id=19, gate_name="cx", qubits=[0, 1] ), ), CutIdentifier( @@ -254,7 +254,7 @@ def test_four_qubit_cutting_workflow(self): CutIdentifier( cut_action="CutBothWires", cut_location=CutLocation( - instruction_id=25, gate_name="cx", qubits=[2, 3] + instruction_id=21, gate_name="cx", qubits=[2, 3] ), ), ] @@ -290,7 +290,7 @@ def test_four_qubit_cutting_workflow(self): SingleWireCutIdentifier( cut_action="CutLeftWire", wire_cut_location=WireCutLocation( - instruction_id=17, gate_name="cx", qubits=[2, 3], input=1 + instruction_id=10, gate_name="cx", qubits=[2, 3], input=1 ), ), SingleWireCutIdentifier( diff --git a/test/qpd/test_qpd.py b/test/qpd/test_qpd.py index b38513f6..f3bc8cdc 100644 --- a/test/qpd/test_qpd.py +++ b/test/qpd/test_qpd.py @@ -72,7 +72,7 @@ class TestQPDFunctions(unittest.TestCase): def setUp(self): # Use HWEA for simplicity and easy visualization - qpd_circuit = efficient_su2(4, entanglement="linear", reps=2).decompose() + qpd_circuit = efficient_su2(4, entanglement="linear", reps=2) # We will instantiate 2 QPDBasis objects using from_instruction rxx_gate = RXXGate(np.pi / 3) diff --git a/test/test_cutting_decomposition.py b/test/test_cutting_decomposition.py index 4e43338a..c7decf98 100644 --- a/test/test_cutting_decomposition.py +++ b/test/test_cutting_decomposition.py @@ -37,8 +37,8 @@ class TestCuttingDecomposition(unittest.TestCase): def setUp(self): # Use HWEA for simplicity and easy visualization - circuit = efficient_su2(4, entanglement="linear", reps=2).decompose() - qpd_circuit = efficient_su2(4, entanglement="linear", reps=2).decompose() + circuit = efficient_su2(4, entanglement="linear", reps=2) + qpd_circuit = efficient_su2(4, entanglement="linear", reps=2) # We will instantiate 2 QPDBasis objects using from_instruction rxx_gate = RXXGate(np.pi / 3) diff --git a/test/test_cutting_workflows.py b/test/test_cutting_workflows.py index ce8713f2..4371b9cd 100644 --- a/test/test_cutting_workflows.py +++ b/test/test_cutting_workflows.py @@ -38,7 +38,7 @@ def test_transpile_before_realizing_basis_id(): """Test a workflow where a :class:`.SingleQubitQPDGate` is passed through the transpiler.""" num_qubits = 4 - circuit = efficient_su2(num_qubits, entanglement="linear", reps=2).decompose() + circuit = efficient_su2(num_qubits, entanglement="linear", reps=2) circuit.assign_parameters([0.8] * len(circuit.parameters), inplace=True) observables = PauliList(["ZZII"]) subcircuits, bases, subobservables = partition_problem( @@ -72,7 +72,7 @@ def test_transpile_before_realizing_basis_id(): ) def test_exotic_labels(label1, label2): """Test workflow with labels of non-uniform type.""" - circuit = efficient_su2(4, entanglement="linear", reps=2).decompose() + circuit = efficient_su2(4, entanglement="linear", reps=2) circuit.assign_parameters([0.8] * len(circuit.parameters), inplace=True) observables = PauliList(["ZZII", "IZZI", "IIZZ", "XIXI", "ZIZZ", "IXIX"]) subcircuits, bases, subobservables = partition_problem( diff --git a/test/test_find_cuts.py b/test/test_find_cuts.py index 888b459a..7754bc30 100644 --- a/test/test_find_cuts.py +++ b/test/test_find_cuts.py @@ -49,7 +49,7 @@ def test_find_cuts(self): assert metadata["minimum_reached"] is True with self.subTest("Cut both wires instance"): - qc = efficient_su2(4, entanglement="linear", reps=2).decompose() + qc = efficient_su2(4, entanglement="linear", reps=2) qc.assign_parameters([0.4] * len(qc.parameters), inplace=True) optimization = OptimizationParameters( seed=12345, gate_lo=False, wire_lo=True diff --git a/test/utils/test_transforms.py b/test/utils/test_transforms.py index 7972e433..b05d6bb5 100644 --- a/test/utils/test_transforms.py +++ b/test/utils/test_transforms.py @@ -33,7 +33,7 @@ def prepare_hwea(): - circuit = efficient_su2(4, entanglement="linear", reps=1).decompose() + circuit = efficient_su2(4, entanglement="linear", reps=1) # Exchange CNOTs with gates we support for i, gate in enumerate(circuit.data):