From d05fcb44120cfd05c6e3876aaa87dd43707f7d2b Mon Sep 17 00:00:00 2001 From: Marvin Bechtold Date: Mon, 29 Apr 2024 11:49:36 +0200 Subject: [PATCH 1/3] Update and fix tests --- app/model/response_cut_circuits.py | 6 +++--- app/model/response_gate_cut_circuits.py | 4 ++-- app/partition.py | 2 +- requirements.txt | 6 +++--- test/test_circuit_cutting.py | 16 ++++++++++++---- test/test_gate_cutting.py | 2 +- test/test_partition.py | 2 +- test/test_reconstruction.py | 12 ++++++------ test/test_reconstruction_gate_cutting.py | 2 +- 9 files changed, 30 insertions(+), 22 deletions(-) diff --git a/app/model/response_cut_circuits.py b/app/model/response_cut_circuits.py index 87add29..249da4f 100644 --- a/app/model/response_cut_circuits.py +++ b/app/model/response_cut_circuits.py @@ -22,7 +22,7 @@ import jsonpickle import marshmallow as ma -from qiskit import qasm3 +from qiskit import qasm3, qasm2 class CutCircuitsResponse: @@ -41,9 +41,9 @@ def __init__( super().__init__() self.max_subcircuit_width = max_subcircuit_width if format == "openqasm2": - self.subcircuits = [circ.qasm() for circ in subcircuits] + self.subcircuits = [qasm2.dumps(circ) for circ in subcircuits] self.individual_subcircuits = [ - circ.qasm() for circ in individual_subcircuits + qasm2.dumps(circ) for circ in individual_subcircuits ] elif format == "openqasm3": self.subcircuits = [qasm3.dumps(circ) for circ in subcircuits] diff --git a/app/model/response_gate_cut_circuits.py b/app/model/response_gate_cut_circuits.py index 4a7491e..ea1fc11 100644 --- a/app/model/response_gate_cut_circuits.py +++ b/app/model/response_gate_cut_circuits.py @@ -21,7 +21,7 @@ import pickle import marshmallow as ma -from qiskit import qasm3 +from qiskit import qasm3, qasm2 class GateCutCircuitsResponse: @@ -36,7 +36,7 @@ def __init__( super().__init__() if format == "openqasm2": self.individual_subcircuits = [ - circ.qasm() for circ in individual_subcircuits + qasm2.dumps(circ) for circ in individual_subcircuits ] elif format == "openqasm3": self.individual_subcircuits = [ diff --git a/app/partition.py b/app/partition.py index dd7f44e..a5d66a0 100644 --- a/app/partition.py +++ b/app/partition.py @@ -39,7 +39,7 @@ def dag_to_hypergraph(dag: DAGDependency, k=2): e += 1 index_vector.append(len(edge_vector)) for qarg in node.qargs: - edge_vector.append(qarg.index) + edge_vector.append(qarg._index) return kahypar.Hypergraph(n, e, index_vector, edge_vector, k) diff --git a/requirements.txt b/requirements.txt index 3189232..eb8272c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ Flask==2.1.2 Flask-RESTful==0.3.9 -qiskit==0.43.0 +qiskit==1.0.2 requests==2.28.0 urllib3==1.26.9 Werkzeug==2.1.2 @@ -9,7 +9,7 @@ black==21.8b0 click==8.0.1 marshmallow==3.13.0 coverage==5.5 -circuit-knitting-toolbox==0.5.0 +circuit-knitting-toolbox==0.7.1 numpy~=1.23.5 argschema~=3.0.4 jsonpickle~=3.0.0 @@ -18,4 +18,4 @@ symengine==0.9.2 docplex>=2.23.222 cplex>=22.1.0.0 kahypar~=1.1.7 -qiskit_qasm3_import~=0.3.0 +qiskit_qasm3_import~=0.4.2 diff --git a/test/test_circuit_cutting.py b/test/test_circuit_cutting.py index 6ba908d..eabcfe4 100644 --- a/test/test_circuit_cutting.py +++ b/test/test_circuit_cutting.py @@ -1,8 +1,12 @@ +import codecs import json import os +import pickle import sys import unittest +from qiskit import qasm3 + parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) from app import create_app @@ -55,19 +59,23 @@ def test_automatic_cutting_qasm3(self): print(response.get_json()) def test_automatic_cutting_qiskit(self): + circuit = qasm3.loads( + 'OPENQASM 3;\ninclude "stdgates.inc";\nbit[4] meas;\nqubit[4] _all_qubits;\nlet q = _all_qubits[0:3];\nh q[0];\ncx q[0], q[1];\ncx q[1], q[2];\ncx q[2], q[3];\nmeas[0] = measure q[0];\nmeas[1] = measure q[1];\nmeas[2] = measure q[2];\nmeas[3] = measure q[3];\n' + ) + pickle_bytes = codecs.encode(pickle.dumps(circuit), "base64").decode() response = self.client.post( "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lChqawIAAGqhAgAASwBdlGpnAgAASwCGlGGGlIGUam8CAABqoQIAAEsBXZRqZwIAAEsB\nhpRhhpSBlGpzAgAAaqECAABLAl2UamcCAABLAoaUYYaUgZRqdwIAAGqhAgAASwNdlGpnAgAASwOG\nlGGGlIGUamICAABqoQIAAEsEXZRqZwIAAEsEhpRhhpSBlHWMCV9hbmNpbGxhc5RdlIwNX2NhbGli\ncmF0aW9uc5SMC2NvbGxlY3Rpb25zlIwLZGVmYXVsdGRpY3SUk5SMCGJ1aWx0aW5zlIwEZGljdJST\nlIWUUpSMEF9wYXJhbWV0ZXJfdGFibGWUjB1xaXNraXQuY2lyY3VpdC5wYXJhbWV0ZXJ0YWJsZZSM\nDlBhcmFtZXRlclRhYmxllJOUKYGUTn2UKIwGX3RhYmxllH2UKGi5atgCAACME1BhcmFtZXRlclJl\nZmVyZW5jZXOUk5QpgZRdlChoo0sAhpRo4ksAhpRqBgEAAEsAhpRqKgEAAEsAhpRqTgEAAEsAhpRq\ncgEAAEsAhpRlYmqnAQAAauACAAApgZRdlChqnQEAAEsAhpRqygEAAEsAhpRq7gEAAEsAhpRqEgIA\nAEsAhpRqNgIAAEsAhpRlYnWMBV9rZXlzlI+UKGi5aqcBAACQjAZfbmFtZXOUj5QoaLFqowEAAJB1\nhpRiaMFOjAdfbGF5b3V0lE6MDV9nbG9iYWxfcGhhc2WUSwCMCGR1cmF0aW9ulE6MBHVuaXSUaC+M\nCV9tZXRhZGF0YZROdWIu\n", + "max_subcircuit_width": 3, + "circuit": pickle_bytes, "method": "automatic", "max_num_subcircuits": 2, - "max_cuts": 3, + "max_cuts": 2, "circuit_format": "qiskit", } ), content_type="application/json", ) - self.assertEqual(response.status_code, 200) + self.assertEqual(200, response.status_code) print(response.get_json()) diff --git a/test/test_gate_cutting.py b/test/test_gate_cutting.py index a644a72..2ec53f5 100644 --- a/test/test_gate_cutting.py +++ b/test/test_gate_cutting.py @@ -36,7 +36,7 @@ def _generate_reconstruction_test(num_qubits=4, partition_labels=None, reps=2): circuit = circuit.decompose() params = [np.random.random() * 2 * np.pi for _ in circuit.parameters] - circuit = circuit.bind_parameters(params) + circuit = circuit.assign_parameters(params) partitioned_problem = partition_problem( circuit=circuit, diff --git a/test/test_partition.py b/test/test_partition.py index d5f309f..87ddfa5 100644 --- a/test/test_partition.py +++ b/test/test_partition.py @@ -18,7 +18,7 @@ def test_get_partitions(self): circuit = circuit.decompose() params = [(np.pi * i) / 16 for i in range(len(circuit.parameters))] - circuit = circuit.bind_parameters(params) + circuit = circuit.assign_parameters(params) partitions, partition_sizes = get_partitions( circuit, num_partitions=num_partitions, diff --git a/test/test_reconstruction.py b/test/test_reconstruction.py index dfd7d8c..129c3d9 100644 --- a/test/test_reconstruction.py +++ b/test/test_reconstruction.py @@ -14,7 +14,7 @@ from circuit_knitting.cutting.cutqc.wire_cutting_evaluation import ( run_subcircuits, ) -from qiskit import QuantumCircuit, transpile +from qiskit import QuantumCircuit, transpile, qasm2 from qiskit.circuit.library import EfficientSU2 from qiskit.providers import JobError, JobTimeoutError from qiskit.providers.jobstatus import JOB_FINAL_STATES @@ -46,7 +46,7 @@ def generate_su2_test(num_qubits): circuit = circuit.decompose() params = [(np.pi * i) / 16 for i in range(len(circuit.parameters))] - circuit = circuit.bind_parameters(params) + circuit = circuit.assign_parameters(params) cuts = cut_circuit_wires( circuit=circuit, method="automatic", @@ -64,9 +64,9 @@ def generate_su2_test(num_qubits): subcircuit_instance_probabilities = run_subcircuits(individual_subcircuits) - cuts["subcircuits"] = [sc.qasm() for sc in cuts["subcircuits"]] + cuts["subcircuits"] = [qasm2.dumps(sc) for sc in cuts["subcircuits"]] cuts["complete_path_map"] = jsonpickle.encode(cuts["complete_path_map"], keys=True) - cuts["individual_subcircuits"] = [sc.qasm() for sc in individual_subcircuits] + cuts["individual_subcircuits"] = [qasm2.dumps(sc) for sc in individual_subcircuits] cuts["init_meas_subcircuit_map"] = jsonpickle.encode( init_meas_subcircuit_map, keys=True ) @@ -106,7 +106,7 @@ def test_reconstruction(self): "/combineResults", data=json.dumps( { - "circuit": circuit.qasm(), + "circuit": qasm2.dumps(circuit), "subcircuit_results": subcircuit_instance_probabilities, "cuts": cuts, }, @@ -130,7 +130,7 @@ def test_reconstruction_quokka(self): "/combineResultsQuokka", data=json.dumps( { - "circuit": circuit.qasm(), + "circuit": qasm2.dumps(circuit), "subcircuit_results": subcircuit_instance_probabilities, "cuts": cuts, }, diff --git a/test/test_reconstruction_gate_cutting.py b/test/test_reconstruction_gate_cutting.py index 7e00d24..b27f586 100644 --- a/test/test_reconstruction_gate_cutting.py +++ b/test/test_reconstruction_gate_cutting.py @@ -48,7 +48,7 @@ def _generate_reconstruction_test(num_qubits=4, partition_labels=None, reps=2): circuit = circuit.decompose() params = [np.random.random() * 2 * np.pi for _ in circuit.parameters] - circuit = circuit.bind_parameters(params) + circuit = circuit.assign_parameters(params) observables = PauliList(["Z" * num_qubits]) From e46f5373522ffda2e2c458c230b006175de40866 Mon Sep 17 00:00:00 2001 From: Marvin Bechtold Date: Mon, 29 Apr 2024 12:18:10 +0200 Subject: [PATCH 2/3] Fix tests --- requirements.txt | 1 + test/test_gate_cutting.py | 4 ++-- test/test_reconstruction_gate_cutting.py | 5 ++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index eb8272c..51ab6ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ docplex>=2.23.222 cplex>=22.1.0.0 kahypar~=1.1.7 qiskit_qasm3_import~=0.4.2 +dill>=0.3.8 \ No newline at end of file diff --git a/test/test_gate_cutting.py b/test/test_gate_cutting.py index 2ec53f5..9e9cb3b 100644 --- a/test/test_gate_cutting.py +++ b/test/test_gate_cutting.py @@ -7,7 +7,7 @@ import numpy as np from circuit_knitting.cutting import partition_problem, generate_cutting_experiments -from qiskit import qasm3 +from qiskit import qasm3, qasm2 from qiskit.circuit.library import EfficientSU2 from qiskit.quantum_info import PauliList from qiskit_aer.primitives import Sampler @@ -134,7 +134,7 @@ def test_reconstruction(self): "/gate-cutting/combineResultsQuokka", data=json.dumps( { - "circuit": circuit.qasm(), + "circuit": qasm2.dumps(circuit), "subcircuit_results": results, "cuts": { "subcircuit_labels": subcircuit_labels, diff --git a/test/test_reconstruction_gate_cutting.py b/test/test_reconstruction_gate_cutting.py index b27f586..d9938dd 100644 --- a/test/test_reconstruction_gate_cutting.py +++ b/test/test_reconstruction_gate_cutting.py @@ -78,10 +78,9 @@ def _generate_reconstruction_test(num_qubits=4, partition_labels=None, reps=2): qc_meas = circuit.measure_all(inplace=False) result_exact = sampler_exact.run(qc_meas).result() - exact_experiment = result_exact.experiments[0] exact_distribution = counts_to_array( - exact_experiment["quasi_dists"], - exact_experiment["metadata"]["simulator_metadata"]["num_qubits"], + result_exact.quasi_dists[0], + result_exact.metadata[0]["simulator_metadata"]["num_qubits"], ) reconstructed_counts = reconstruct_distribution( From 5c9c2d4e9a131afd8e8b88f3b0945b89d2c01a44 Mon Sep 17 00:00:00 2001 From: Marvin Bechtold Date: Mon, 29 Apr 2024 12:21:13 +0200 Subject: [PATCH 3/3] Fix requirements.txt --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 51ab6ad..eecda9f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,6 @@ numpy~=1.23.5 argschema~=3.0.4 jsonpickle~=3.0.0 pytest~=7.2 -symengine==0.9.2 docplex>=2.23.222 cplex>=22.1.0.0 kahypar~=1.1.7