From dce17c48751fd9ff6bbd4f3f8355734f2d088ea9 Mon Sep 17 00:00:00 2001 From: WrathfulSpatula Date: Wed, 4 Dec 2024 17:39:38 -0500 Subject: [PATCH] Improve QrackCircuit input from Qiskit --- debian/changelog | 24 +++++++++++++++++++++++ debian/files | 2 +- pyqrack/qrack_circuit.py | 41 ++++++++++++++++++++++++---------------- setup.py | 2 +- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1785543..158d78e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,27 @@ +pyqrack (1.34.3) bionic; urgency=medium + + * Qiskit v1.3 update (Bionic 4/4) + + -- Daniel Strano Wed, 04 Dec 2024 14:21:10 -0500 + +pyqrack (1.34.2) focal; urgency=medium + + * Qiskit v1.3 update (Focal 3/4) + + -- Daniel Strano Wed, 04 Dec 2024 14:19:44 -0500 + +pyqrack (1.34.1) jammy; urgency=medium + + * Qiskit v1.3 update (Jammy 2/4) + + -- Daniel Strano Wed, 04 Dec 2024 14:17:22 -0500 + +pyqrack (1.34.0) noble; urgency=medium + + * Qiskit v1.3 update (Noble 1/4) + + -- Daniel Strano Wed, 04 Dec 2024 14:13:59 -0500 + pyqrack (1.33.4) bionic; urgency=medium * Bounds checking and QrackCircuit to string (Bionic 4/4) diff --git a/debian/files b/debian/files index 91b2d64..4a7359f 100644 --- a/debian/files +++ b/debian/files @@ -1 +1 @@ -pyqrack_1.33.4_source.buildinfo libs optional +pyqrack_1.34.3_source.buildinfo libs optional diff --git a/pyqrack/qrack_circuit.py b/pyqrack/qrack_circuit.py index d55771c..491a5a5 100644 --- a/pyqrack/qrack_circuit.py +++ b/pyqrack/qrack_circuit.py @@ -385,6 +385,18 @@ def string_to_qiskit_circuit(circ_string): return circ + def _u3_to_mtrx(params): + th = float(params[0]) + ph = float(params[1]) + lm = float(params[2]) + + c = math.cos(th / 2) + s = math.sin(th / 2) + el = np.exp(1j * lm) + ep = np.exp(1j * ph) + + return [ c + 0j, -el * s, ep * s, el * ep * c] + def in_from_qiskit_circuit(circ): """Read a Qiskit circuit into a QrackCircuit @@ -404,29 +416,26 @@ def in_from_qiskit_circuit(circ): out = QrackCircuit() - basis_gates = ["u", "cx"] - circ = transpile(circ, basis_gates=basis_gates, optimization_level=3) + basis_gates = ["x", "y", "z", "u", "cx", "cy", "cz", "cu"] + circ = transpile(circ, basis_gates=basis_gates, optimization_level=0) for gate in circ.data: o = gate.operation - if o.name == "u": - th = float(o.params[0]) - ph = float(o.params[1]) - lm = float(o.params[2]) - - c = math.cos(th / 2) - s = math.sin(th / 2) - - op = [ - c + 0j, - -np.exp(1j * lm) * s, - np.exp(1j * ph) * s, - np.exp(1j * (ph + lm)) * c - ] + op = [] + if o.name in ["x", "cx"]: + op = [0, 1, 1, 0] + elif o.name in ["y", "cy"]: + op = [0, -1j, 1j, 0] + elif o.name in ["z", "cz"]: + op = [1, 0, 0, -1] + else: + op = QrackCircuit._u3_to_mtrx(o.params) + if o.name in ["x", "y", "z", "u"]: out.mtrx(op, circ.find_bit(gate.qubits[0])[0]) else: ctrls = [] for c in gate.qubits[0:1]: ctrls.append(circ.find_bit(c)[0]) + out.ucmtrx(ctrls, [0, 1, 1, 0], circ.find_bit(gate.qubits[1])[0], 1) return out diff --git a/setup.py b/setup.py index 97f0b14..891390f 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup -VERSION = "1.34.0" +VERSION = "1.34.4" # Read long description from README. README_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md')