From cc6ffb996cd518eac7ce6f5a702e07b229e68b63 Mon Sep 17 00:00:00 2001 From: chensgit169 Date: Sun, 20 Aug 2023 18:30:44 +0800 Subject: [PATCH 1/9] add 'dev_*.py' --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a9439f81..584c299e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,4 @@ thirdparty *.so MANIFEST.in *.pyd -dev*.py +dev_*.py From fecc0fe8a940841db8e90b29fc67ac37e9cbcb79 Mon Sep 17 00:00:00 2001 From: chensgit169 Date: Mon, 21 Aug 2023 10:36:42 +0800 Subject: [PATCH 2/9] fix import path of pulse --- src/quafu/dagcircuits/circuit_dag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quafu/dagcircuits/circuit_dag.py b/src/quafu/dagcircuits/circuit_dag.py index d309bd60..7e9fe1c7 100644 --- a/src/quafu/dagcircuits/circuit_dag.py +++ b/src/quafu/dagcircuits/circuit_dag.py @@ -3,7 +3,7 @@ from quafu.elements.element_gates import * from quafu.elements.quantum_element import Barrier, Delay, Measure, XYResonance -from quafu.pulses.quantum_pulse import GaussianPulse, RectPulse, FlattopPulse +from quafu.elements.quantum_element.pulses.quantum_pulse import GaussianPulse, RectPulse, FlattopPulse import networkx as nx from typing import Dict, Any, List, Union From c912eefb981dfc30b518137fb085afc34354d825 Mon Sep 17 00:00:00 2001 From: chensgit169 Date: Mon, 21 Aug 2023 10:37:22 +0800 Subject: [PATCH 3/9] fix gate missing --- src/quafu/elements/element_gates/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/quafu/elements/element_gates/__init__.py b/src/quafu/elements/element_gates/__init__.py index e49ce602..b0c18749 100644 --- a/src/quafu/elements/element_gates/__init__.py +++ b/src/quafu/elements/element_gates/__init__.py @@ -26,6 +26,15 @@ "ZGate", "IdGate", "WGate", + "HGate", + "SGate", + "SdgGate", + "TGate", + "TdgGate", + "SXGate", + "SXdgGate", + "SYGate", + "SYdgGate", "SWGate", "PhaseGate", "RXGate", From c637b73a94b7384fed9fc05f0db933099b41691c Mon Sep 17 00:00:00 2001 From: chensgit169 Date: Mon, 21 Aug 2023 10:39:40 +0800 Subject: [PATCH 4/9] add QuantumRegister into __init__.__all__ --- src/quafu/circuits/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/quafu/circuits/__init__.py b/src/quafu/circuits/__init__.py index 455d107d..2af4d8ec 100644 --- a/src/quafu/circuits/__init__.py +++ b/src/quafu/circuits/__init__.py @@ -1,3 +1,4 @@ """Quafu quantum circuits""" -from .quantum_circuit import * +from .quantum_circuit import QuantumCircuit +from .quantum_register import QuantumRegister From 11e868b1f08f4aff9304cf0f56297db909e939b4 Mon Sep 17 00:00:00 2001 From: chensgit169 Date: Mon, 21 Aug 2023 10:40:54 +0800 Subject: [PATCH 5/9] move implementation of ``from_qasm`` from ``qc`` to ``qfasm_convertor``(tested) --- src/quafu/circuits/quantum_circuit.py | 138 +--------------------- src/quafu/qfasm/qfasm_convertor.py | 161 +++++++++++++++++++++++++- 2 files changed, 162 insertions(+), 137 deletions(-) diff --git a/src/quafu/circuits/quantum_circuit.py b/src/quafu/circuits/quantum_circuit.py index c9477135..c04a3ed1 100644 --- a/src/quafu/circuits/quantum_circuit.py +++ b/src/quafu/circuits/quantum_circuit.py @@ -267,142 +267,8 @@ def from_openqasm(self, openqasm: str): Args: openqasm: input openqasm str. """ - from numpy import pi - import re - - self.openqasm = openqasm - # lines = self.openqasm.strip("\n").splitlines(";") - lines = self.openqasm.splitlines() - lines = [line for line in lines if line] - self.gates = [] - self.measures = {} - measured_qubits = [] - global_valid = True - for line in lines[2:]: - if line: - operations_qbs = line.split(" ", 1) - operations = operations_qbs[0] - if operations == "qreg": - qbs = operations_qbs[1] - num = int(re.findall("\d+", qbs)[0]) - reg = QuantumRegister(num) - self.qregs.append(reg) - elif operations == "creg": - pass - elif operations == "measure": - qbs = operations_qbs[1] - indstr = re.findall("\d+", qbs) - inds = [int(indst) for indst in indstr] - mb = inds[0] - cb = inds[1] - self.measures[mb] = cb - measured_qubits.append(mb) - else: - qbs = operations_qbs[1] - indstr = re.findall("\d+", qbs) - inds = [int(indst) for indst in indstr] - valid = True - for pos in inds: - if pos in measured_qubits: - valid = False - global_valid = False - break - - if valid: - if operations == "barrier": - self.barrier(inds) - - else: - sp_op = operations.split("(") - gatename = sp_op[0] - if gatename == "delay": - paras = sp_op[1].strip("()") - duration = int(re.findall("\d+", paras)[0]) - unit = re.findall("[a-z]+", paras)[0] - self.delay(inds[0], duration, unit) - elif gatename == "xy": - paras = sp_op[1].strip("()") - duration = int(re.findall("\d+", paras)[0]) - unit = re.findall("[a-z]+", paras)[0] - self.xy(min(inds), max(inds), duration, unit) - else: - if len(sp_op) > 1: - paras = sp_op[1].strip("()") - parastr = paras.split(",") - paras = [ - eval(parai, {"pi": pi}) for parai in parastr - ] - - if gatename == "cx": - self.cnot(inds[0], inds[1]) - elif gatename == "cy": - self.cy(inds[0], inds[1]) - elif gatename == "cz": - self.cz(inds[0], inds[1]) - elif gatename == "cp": - self.cp(inds[0], inds[1], paras[0]) - elif gatename == "swap": - self.swap(inds[0], inds[1]) - elif gatename == "rx": - self.rx(inds[0], paras[0]) - elif gatename == "ry": - self.ry(inds[0], paras[0]) - elif gatename == "rz": - self.rz(inds[0], paras[0]) - elif gatename == "p": - self.p(inds[0], paras[0]) - elif gatename == "x": - self.x(inds[0]) - elif gatename == "y": - self.y(inds[0]) - elif gatename == "z": - self.z(inds[0]) - elif gatename == "h": - self.h(inds[0]) - elif gatename == "id": - self.id(inds[0]) - elif gatename == "s": - self.s(inds[0]) - elif gatename == "sdg": - self.sdg(inds[0]) - elif gatename == "t": - self.t(inds[0]) - elif gatename == "tdg": - self.tdg(inds[0]) - elif gatename == "sx": - self.sx(inds[0]) - elif gatename == "ccx": - self.toffoli(inds[0], inds[1], inds[2]) - elif gatename == "cswap": - self.fredkin(inds[0], inds[1], inds[2]) - elif gatename == "u1": - self.rz(inds[0], paras[0]) - elif gatename == "u2": - self.rz(inds[0], paras[1]) - self.ry(inds[0], pi / 2) - self.rz(inds[0], paras[0]) - elif gatename == "u3": - self.rz(inds[0], paras[2]) - self.ry(inds[0], paras[0]) - self.rz(inds[0], paras[1]) - elif gatename == "rxx": - self.rxx(inds[0], inds[1], paras[0]) - elif gatename == "ryy": - self.ryy(inds[0], inds[1], paras[0]) - elif gatename == "rzz": - self.rzz(inds[0], inds[1], paras[0]) - else: - print( - "Warning: Operations %s may be not supported by QuantumCircuit class currently." - % gatename - ) - - if not self.measures: - self.measures = dict(zip(range(self.num), range(self.num))) - if not global_valid: - print( - "Warning: All operations after measurement will be removed for executing on experiment" - ) + from quafu.qfasm.qfasm_convertor import qasm2_to_quafu_qc + return qasm2_to_quafu_qc(self, openqasm) def to_openqasm(self) -> str: """ diff --git a/src/quafu/qfasm/qfasm_convertor.py b/src/quafu/qfasm/qfasm_convertor.py index d79d9449..f4414191 100644 --- a/src/quafu/qfasm/qfasm_convertor.py +++ b/src/quafu/qfasm/qfasm_convertor.py @@ -1,7 +1,8 @@ from .qfasm_parser import QfasmParser, QregNode from quafu.dagcircuits.circuit_dag import node_to_gate from quafu.dagcircuits.instruction_node import InstructionNode -from quafu.circuits.quantum_circuit import QuantumCircuit +from quafu.circuits import QuantumCircuit, QuantumRegister +from quafu.elements.quantum_element import Instruction def qasm_to_circuit(qasm): @@ -26,3 +27,161 @@ def qasm_to_circuit(qasm): q.openqasm = qasm q.measures = measures return q + + +def qasm2_to_quafu_qc(qc: QuantumCircuit, openqasm: str): + """ + Initialize pyquafu circuit from openqasm text, mainly by + utilizing regular expressions. This function is developed + not only to be backward compatible with pure quantum part of + OPENQASM2.0, but also to support provide foundation of more + powerful syntax parser. + """ + from numpy import pi + import re + + qc.openqasm = openqasm + # lines = self.openqasm.strip("\n").splitlines(";") + lines = qc.openqasm.splitlines() + lines = [line for line in lines if line] + qc.gates = [] + qc.measures = {} + measured_qubits = [] + global_valid = True + for line in lines[2:]: + if line: + operations_qbs = line.split(" ", 1) + operations = operations_qbs[0] + if operations == "qreg": + qbs = operations_qbs[1] + num = int(re.findall("\d+", qbs)[0]) + reg = QuantumRegister(num) + qc.qregs.append(reg) + elif operations == "creg": + pass + elif operations == "measure": + qbs = operations_qbs[1] + indstr = re.findall("\d+", qbs) + inds = [int(indst) for indst in indstr] + mb = inds[0] + cb = inds[1] + qc.measures[mb] = cb + measured_qubits.append(mb) + else: + qbs = operations_qbs[1] + indstr = re.findall("\d+", qbs) + inds = [int(indst) for indst in indstr] + valid = True + for pos in inds: + if pos in measured_qubits: + valid = False + global_valid = False + break + + if valid: + if operations == "barrier": + qc.barrier(inds) + + else: + sp_op = operations.split("(") + gatename = sp_op[0] + if gatename == "delay": + paras = sp_op[1].strip("()") + duration = int(re.findall("\d+", paras)[0]) + unit = re.findall("[a-z]+", paras)[0] + qc.delay(inds[0], duration, unit) + elif gatename == "xy": + paras = sp_op[1].strip("()") + duration = int(re.findall("\d+", paras)[0]) + unit = re.findall("[a-z]+", paras)[0] + qc.xy(min(inds), max(inds), duration, unit) + else: + if len(sp_op) > 1: + paras = sp_op[1].strip("()") + parastr = paras.split(",") + paras = [ + eval(parai, {"pi": pi}) for parai in parastr + ] + + if gatename == "cx": + qc.cnot(inds[0], inds[1]) + elif gatename == "cy": + qc.cy(inds[0], inds[1]) + elif gatename == "cz": + qc.cz(inds[0], inds[1]) + elif gatename == "cp": + qc.cp(inds[0], inds[1], paras[0]) + elif gatename == "swap": + qc.swap(inds[0], inds[1]) + elif gatename == "rx": + qc.rx(inds[0], paras[0]) + elif gatename == "ry": + qc.ry(inds[0], paras[0]) + elif gatename == "rz": + qc.rz(inds[0], paras[0]) + elif gatename == "p": + qc.p(inds[0], paras[0]) + elif gatename == "x": + qc.x(inds[0]) + elif gatename == "y": + qc.y(inds[0]) + elif gatename == "z": + qc.z(inds[0]) + elif gatename == "h": + qc.h(inds[0]) + elif gatename == "id": + qc.id(inds[0]) + elif gatename == "s": + qc.s(inds[0]) + elif gatename == "sdg": + qc.sdg(inds[0]) + elif gatename == "t": + qc.t(inds[0]) + elif gatename == "tdg": + qc.tdg(inds[0]) + elif gatename == "sx": + qc.sx(inds[0]) + elif gatename == "ccx": + qc.toffoli(inds[0], inds[1], inds[2]) + elif gatename == "cswap": + qc.fredkin(inds[0], inds[1], inds[2]) + elif gatename == "u1": + qc.rz(inds[0], paras[0]) + elif gatename == "u2": + qc.rz(inds[0], paras[1]) + qc.ry(inds[0], pi / 2) + qc.rz(inds[0], paras[0]) + elif gatename == "u3": + qc.rz(inds[0], paras[2]) + qc.ry(inds[0], paras[0]) + qc.rz(inds[0], paras[1]) + elif gatename == "rxx": + qc.rxx(inds[0], inds[1], paras[0]) + elif gatename == "ryy": + qc.ryy(inds[0], inds[1], paras[0]) + elif gatename == "rzz": + qc.rzz(inds[0], inds[1], paras[0]) + else: + print( + "Warning: Operations %s may be not supported by QuantumCircuit class currently." + % gatename + ) + + if not qc.measures: + qc.measures = dict(zip(range(qc.num), range(qc.num))) + if not global_valid: + print( + "Warning: All operations after measurement will be removed for executing on experiment" + ) + + +if __name__ == '__main__': + import re + + pattern = r"[a-z]" + + text = "Hello, world! This is a test." + + matches = re.findall(pattern, text) + + print(matches) From 705e03cc7ddc04c26e0a3205cc93037f6294ee29 Mon Sep 17 00:00:00 2001 From: chensgit169 Date: Tue, 22 Aug 2023 20:20:01 +0800 Subject: [PATCH 6/9] fix subscripts of cbits label --- src/quafu/visualisation/circuitPlot.py | 437 +++++++++++-------------- 1 file changed, 191 insertions(+), 246 deletions(-) diff --git a/src/quafu/visualisation/circuitPlot.py b/src/quafu/visualisation/circuitPlot.py index 41b15c93..67c002de 100644 --- a/src/quafu/visualisation/circuitPlot.py +++ b/src/quafu/visualisation/circuitPlot.py @@ -27,12 +27,12 @@ line_args = {} box_args = {} -DEEPCOLOR = "#0C161F" -BLUE = "#1f77b4" -ORANGE = "#ff7f0e" -GREEN = "#2ca02c" -GOLDEN = "#FFB240" -GARNET = "#C0392B" +DEEPCOLOR = '#0C161F' +BLUE = '#1f77b4' +ORANGE = '#ff7f0e' +GREEN = '#2ca02c' +GOLDEN = '#FFB240' +GARNET = '#C0392B' """ layers(zorder): @@ -45,32 +45,18 @@ 5: labels """ -su2_gate_names = [ - "x", - "y", - "z", - "id", - "w", - "h", - "t", - "tdg", - "s", - "sdg", - "sx", - "sy", - "sw", - "phase", - "rx", - "ry", - "rz", -] - -swap_gate_names = ["swap", "iswap"] -r2_gate_names = ["rxx", "ryy", "rzz"] -c2_gate_names = ["cp", "cs", "ct", "cx", "cy", "cz"] -c3_gate_names = ["fredkin", "toffoli"] -mc_gate_names = ["mcx", "mcy", "mcz"] -operation_names = ["barrier", "delay"] +su2_gate_names = ['x', 'y', 'z', 'id', 'w', + 'h', 't', 'tdg', 's', 'sdg', 'sx', 'sy', 'sw', + 'phase', + 'rx', 'ry', 'rz', + ] + +swap_gate_names = ['swap', 'iswap'] +r2_gate_names = ['rxx', 'ryy', 'rzz'] +c2_gate_names = ['cp', 'cs', 'ct', 'cx', 'cy', 'cz'] +c3_gate_names = ['fredkin', 'toffoli'] +mc_gate_names = ['mcx', 'mcy', 'mcz'] +operation_names = ['barrier', 'delay'] class CircuitPlotManager: @@ -80,10 +66,9 @@ class CircuitPlotManager: To be initialized when circuit.plot() is called. """ - # colors - _wire_color = "#FF0000" - _light_blue = "#3B82F6" + _wire_color = '#FF0000' + _light_blue = '#3B82F6' _ec = DEEPCOLOR _wire_lw = 1.5 @@ -92,7 +77,7 @@ class CircuitPlotManager: _a = 0.5 # box width and height, unit: ax _barrier_width = _a / 3 # barrier width - _stroke = pe.withStroke(linewidth=2, foreground="white") + _stroke = pe.withStroke(linewidth=2, foreground='white') def __init__(self, qc): """ @@ -139,25 +124,21 @@ def __init__(self, qc): self._proc_measure(self.depth - 1, q) # step2: initialize bit-label - self.q_label = {y: r"$|q_{%d}\rangle$" % i for i, y in self.used_qbit_y.items()} - self.c_label = { - self.used_qbit_y[iq]: f"c_{ic}" for iq, ic in qc.measures.items() - } + self.q_label = {y: r'$|q_{%d}\rangle$' % i for i, y in self.used_qbit_y.items()} + self.c_label = {self.used_qbit_y[iq]: r'c_{%d}' % ic for iq, ic in qc.measures.items()} # step3: figure coordination self.xs = np.arange(-3 / 2, self.depth + 3 / 2) self.ys = np.arange(-2, self.used_qbit_num + 1 / 2) - def __call__( - self, - title=None, - init_labels=None, - end_labels=None, - save_path: str = None, - show: bool = False, - *args, - **kwargs, - ): + def __call__(self, + title=None, + init_labels=None, + end_labels=None, + save_path: str = None, + show: bool = False, + *args, + **kwargs): """ :param title :param init_labels: dict, {qbit: label} @@ -174,27 +155,22 @@ def __call__( # import random # plt.gca().xkcd(randomness=random.randint(0, 1000)) if title is not None: - title = Text( - (self.xs[0] + self.xs[-1]) / 2, - -0.8, - title, - size=30, - ha="center", - va="baseline", - ) + title = Text((self.xs[0] + self.xs[-1]) / 2, -0.8, + title, + size=30, + ha='center', va='baseline') self._text_list.append(title) # initialize a figure _size_x = self._a_inch * abs(self.xs[-1] - self.xs[0]) _size_y = self._a_inch * abs(self.ys[-1] - self.ys[0]) fig = plt.figure(figsize=(_size_x, _size_y)) # inch - ax = fig.add_axes( - [0, 0, 1, 1], - aspect=1, - xlim=[self.xs[0], self.xs[-1]], - ylim=[self.ys[0], self.ys[-1]], - ) - ax.axis("off") + ax = fig.add_axes([0, 0, 1, 1], + aspect=1, + xlim=[self.xs[0], self.xs[-1]], + ylim=[self.ys[0], self.ys[-1]], + ) + ax.axis('off') ax.invert_yaxis() self._circuit_wires() @@ -203,29 +179,27 @@ def __call__( self._render_circuit() if save_path is not None: - plt.savefig(save_path, dpi=300, bbox_inches="tight") + plt.savefig(save_path, dpi=300, bbox_inches='tight') if show: plt.show() def _process_ins(self, ins: Instruction, append: bool = True): name = ins.name - assert ( - name in Instruction.ins_classes - ), "If this should occur, please report a bug." + assert name in Instruction.ins_classes, 'If this should occur, please report a bug.' name = name.lower() _which = slice(np.min(ins.pos), np.max(ins.pos) + 1) depth = np.max(self.dorders[_which]) paras = ins.paras - if name == "barrier": + if name == 'barrier': self._proc_barrier(depth, ins.pos) - elif name == "measure": + elif name == 'measure': self._proc_measure(depth, ins.pos) elif name in su2_gate_names: self._proc_su2(name, depth, ins.pos, paras) elif name in swap_gate_names: - self._proc_swap(depth, ins.pos, name == "iswap") + self._proc_swap(depth, ins.pos, name == 'iswap') elif name in r2_gate_names: # TODO: combine into one box self._proc_su2(name[-1], depth, ins.pos[0], paras) @@ -233,10 +207,8 @@ def _process_ins(self, ins: Instruction, append: bool = True): elif isinstance(ins, ControlledGate): self._proc_ctrl(depth, ins) else: - raise NotImplementedError( - f"Gate {name} is not supported yet.\n" - f"If this should occur, please report a bug." - ) + raise NotImplementedError(f'Gate {name} is not supported yet.\n' + f'If this should occur, please report a bug.') if append: self.dorders[_which] = depth + 1 @@ -254,147 +226,129 @@ def _circuit_wires(self): x1 = self.xs[-1] - 1 self._h_wire_points.append([[x0, y], [x1, y]]) - def _inits_label(self, labels: dict[int:str] = None): - """qubit-labeling""" + def _inits_label(self, labels: dict[int: str] = None): + """ qubit-labeling """ if labels is None: labels = self.q_label for i, label in labels.items(): - txt = Text( - -2 / 3, - i, - label, - size=18, - color=DEEPCOLOR, - ha="right", - va="center", - ) + txt = Text(-2 / 3, i, + label, + size=18, + color=DEEPCOLOR, + ha='right', + va='center', + ) self._text_list.append(txt) - def _measured_label(self, labels: dict[int:str] = None): - """measured qubit-labeling""" + def _measured_label(self, labels: dict[int: str] = None): + """ measured qubit-labeling """ if labels is None: labels = self.c_label for i, label in labels.items(): - label = r"$%s$" % label - txt = Text( - self.xs[-1] - 3 / 4, - i, - label, - size=18, - color=DEEPCOLOR, - ha="left", - va="center", - ) + label = r'$%s$' % label + txt = Text(self.xs[-1] - 3 / 4, i, + label, + size=18, + color=DEEPCOLOR, + ha='left', + va='center', + ) self._text_list.append(txt) def _gate_bbox(self, x, y, fc: str): - """Single qubit gate box""" + """ Single qubit gate box """ a = self._a from matplotlib.patches import FancyBboxPatch - - bbox = FancyBboxPatch( - (-a / 2 + x, -a / 2 + y), - a, - a, # this warning belongs to matplotlib - boxstyle=f"round, pad={0.2 * a}", - edgecolor=DEEPCOLOR, - facecolor=fc, - ) + bbox = FancyBboxPatch((-a / 2 + x, -a / 2 + y), a, a, # this warning belongs to matplotlib + boxstyle=f'round, pad={0.2 * a}', + edgecolor=DEEPCOLOR, + facecolor=fc, + ) self._closed_patches.append(bbox) def _gate_label(self, x, y, s): if not s: return None _dy = 0.05 - text = Text( - x, - y + _dy, - s, - size=24, - color=DEEPCOLOR, - ha="center", - va="center", - ) + text = Text(x, y + _dy, + s, + size=24, + color=DEEPCOLOR, + ha='center', + va='center', + ) text.set_path_effects([self._stroke]) self._text_list.append(text) def _para_label(self, x, y, para_txt): - """label parameters""" + """ label parameters """ if not para_txt: return None _dx = 0 - text = Text( - x + _dx, - y + 0.8 * self._a, - para_txt, - size=12, - color=DEEPCOLOR, - ha="center", - va="top", - ) + text = Text(x + _dx, y + 0.8 * self._a, + para_txt, + size=12, + color=DEEPCOLOR, + ha='center', + va='top', + ) self._text_list.append(text) def _measure_label(self, x, y): from matplotlib.patches import FancyArrow - a = self._a r = 1.1 * a d = 1.2 * a / 3.5 - arrow = FancyArrow( - x=x, - y=y + d, - dx=0.15, - dy=-0.35, - width=0.04, - facecolor=DEEPCOLOR, - head_width=0.07, - head_length=0.15, - edgecolor="white", - ) - arc = Arc( - (x, y + d), - width=r, - height=r, - lw=1, - theta1=180, - theta2=0, - fill=False, - zorder=4, - color=DEEPCOLOR, - capstyle="round", - ) - center_bkg = Circle( - (x, y + d), - radius=0.035, - color="white", - ) - center = Circle( - (x, y + d), - radius=0.025, - facecolor=DEEPCOLOR, - ) + arrow = FancyArrow(x=x, + y=y + d, + dx=0.15, + dy=-0.35, + width=0.04, + facecolor=DEEPCOLOR, + head_width=0.07, + head_length=0.15, + edgecolor='white') + arc = Arc((x, y + d), + width=r, + height=r, + lw=1, + theta1=180, + theta2=0, + fill=False, + zorder=4, + color=DEEPCOLOR, + capstyle='round', + ) + center_bkg = Circle((x, y + d), + radius=0.035, + color='white', + ) + center = Circle((x, y + d), + radius=0.025, + facecolor=DEEPCOLOR, + ) self._mea_arc_patches.append(arc) self._mea_point_patches += [center_bkg, arrow, center] ######################################################################### # region # # # # processing-functions: decompose ins into graphical elements # # # def _proc_su2(self, id_name, depth, pos, paras): - if id_name in ["x", "y", "z", "h", "id", "s", "t", "p", "u"]: - fc = "#EE7057" + if id_name in ['x', 'y', 'z', 'h', 'id', 's', 't', 'p', 'u']: + fc = '#EE7057' label = id_name.capitalize() - elif id_name in ["rx", "ry", "rz"]: - fc = "#6366F1" + elif id_name in ['rx', 'ry', 'rz']: + fc = '#6366F1' label = id_name.upper() else: - fc = "#8C9197" - label = "?" + fc = '#8C9197' + label = '?' - if id_name in ["rx", "ry", "rz", "p"]: + if id_name in ['rx', 'ry', 'rz', 'p']: # too long to display: r'$\theta=$' + f'{paras:.3f}' (TODO) - para_txt = f"({paras:.3f})" + para_txt = f'({paras:.3f})' else: para_txt = None @@ -421,20 +375,17 @@ def _proc_ctrl(self, depth, ins: ControlledGate, ctrl_type: bool = True): tar_name = ins.targ_name.lower()[-1] pos = ins.targs if isinstance(ins.targs, int) else ins.targs[0] x = self.used_qbit_y[pos] - if tar_name == "x": + if tar_name == 'x': self._not_points.append((depth, x)) else: self._proc_su2(tar_name, depth, pos, None) - elif name == "cswap": + elif name == 'cswap': self._swap_points += [[depth, self.used_qbit_y[p]] for p in ins.targs] - elif name == "ccx": + elif name == 'ccx': self._not_points.append((depth, self.used_qbit_y[ins.targs])) else: from quafu.elements.element_gates import ControlledU - - assert isinstance( - ins, ControlledU - ), f"unknown gate: {name}, {ins.__class__.__name__}" + assert isinstance(ins, ControlledU), f'unknown gate: {name}, {ins.__class__.__name__}' self._process_ins(ins, append=False) def _proc_swap(self, depth, pos, iswap: bool = False): @@ -452,8 +403,8 @@ def _proc_barrier(self, depth, pos: list): for p in pos: y = self.used_qbit_y[p] - y0 = y - 1 / 2 - y1 = y + 1 / 2 + y0 = (y - 1 / 2) + y1 = (y + 1 / 2) nodes = [[x0, y0], [x0, y1], [x1, y1], [x1, y0], [x0, y0]] self._barrier_points.append(nodes) @@ -469,7 +420,6 @@ def _proc_measure(self, depth, pos: int): # x0 = depth # x1 = self.depth - 1 / 2 # self._h_wire_points.append([[x0, y], [x1, y]]) - # endregion ######################################################################### @@ -477,49 +427,45 @@ def _proc_measure(self, depth, pos: int): # # # # # # # # # # # # # # rendering functions # # # # # # # # # # # # # ######################################################################### def _render_h_wires(self): - h_lines = LineCollection( - self._h_wire_points, - zorder=0, - colors=self._wire_color, - alpha=0.8, - linewidths=2, - ) + h_lines = LineCollection(self._h_wire_points, + zorder=0, + colors=self._wire_color, + alpha=0.8, + linewidths=2, + ) plt.gca().add_collection(h_lines) def _render_ctrl_wires(self): - v_lines = LineCollection( - self._ctrl_wire_points, - zorder=0, - colors=self._light_blue, - alpha=0.8, - linewidths=4, - ) + v_lines = LineCollection(self._ctrl_wire_points, + zorder=0, + colors=self._light_blue, + alpha=0.8, + linewidths=4, + ) plt.gca().add_collection(v_lines) def _render_closed_patch(self): - collection = PatchCollection( - self._closed_patches, - match_original=True, - zorder=3, - ec=self._ec, - linewidths=0.5, - ) + collection = PatchCollection(self._closed_patches, + match_original=True, + zorder=3, + ec=self._ec, + linewidths=0.5, + ) plt.gca().add_collection(collection) def _render_ctrl_nodes(self): circle_collection = [] r = self._a / 4 for x, y, ctrl in self._ctrl_points: - fc = "#3B82F6" if ctrl else "white" + fc = '#3B82F6' if ctrl else 'white' circle = Circle((x, y), radius=r, fc=fc) circle_collection.append(circle) - circles = PatchCollection( - circle_collection, - match_original=True, - zorder=5, - ec=self._ec, - linewidths=2, - ) + circles = PatchCollection(circle_collection, + match_original=True, + zorder=5, + ec=self._ec, + linewidths=2, + ) plt.gca().add_collection(circles) def _render_not_nodes(self): @@ -530,16 +476,16 @@ def _render_not_nodes(self): for x, y in self._not_points: points.append([[x, y - rp], [x, y + rp]]) points.append([[x - rp, y], [x + rp, y]]) - circle = Circle((x, y), radius=r, lw=1, fc="#3B82F6") + circle = Circle((x, y), radius=r, lw=1, + fc='#3B82F6') self._closed_patches.append(circle) - collection = LineCollection( - points, - zorder=5, - colors="white", - linewidths=2, - capstyle="round", - ) + collection = LineCollection(points, + zorder=5, + colors='white', + linewidths=2, + capstyle='round', + ) plt.gca().add_collection(collection) def _render_swap_nodes(self): @@ -548,50 +494,49 @@ def _render_swap_nodes(self): for x, y in self._swap_points: points.append([[x - r, y - r], [x + r, y + r]]) points.append([[x + r, y - r], [x - r, y + r]]) - collection = LineCollection( - points, - zorder=5, - colors="#3B82F6", - linewidths=4, - capstyle="round", - ) + collection = LineCollection(points, + zorder=5, + colors='#3B82F6', + linewidths=4, + capstyle='round', + ) plt.gca().add_collection(collection) # iswap-cirlces i_circles = [] for x, y in self._iswap_points: - circle = Circle( - (x, y), radius=2 ** (1 / 2) * r, lw=3, ec="#3B82F6", fill=False - ) + circle = Circle((x, y), radius=2 ** (1 / 2) * r, lw=3, + ec='#3B82F6', fill=False) i_circles.append(circle) - collection = PatchCollection( - i_circles, - match_original=True, - zorder=5, - ) + collection = PatchCollection(i_circles, + match_original=True, + zorder=5, + ) plt.gca().add_collection(collection) def _render_measure(self): - stroke = pe.withStroke(linewidth=4, foreground="white") - arcs = PatchCollection( - self._mea_arc_patches, match_original=True, capstyle="round", zorder=4 - ) + stroke = pe.withStroke(linewidth=4, foreground='white') + arcs = PatchCollection(self._mea_arc_patches, + match_original=True, + capstyle='round', + zorder=4) arcs.set_path_effects([stroke]) plt.gca().add_collection(arcs) - pointers = PatchCollection( - self._mea_point_patches, # note the order - match_original=True, - zorder=5, - facecolors=DEEPCOLOR, - linewidths=2, - ) + pointers = PatchCollection(self._mea_point_patches, # note the order + match_original=True, + zorder=5, + facecolors=DEEPCOLOR, + linewidths=2, + ) plt.gca().add_collection(pointers) def _render_barrier(self): - barrier = PolyCollection( - self._barrier_points, closed=True, fc="lightgray", hatch="///", zorder=4 - ) + barrier = PolyCollection(self._barrier_points, + closed=True, + fc='lightgray', + hatch='///', + zorder=4) plt.gca().add_collection(barrier) def _render_txt(self): From 275794b3f2ee29c4d228a69ffe773dda2633b5f1 Mon Sep 17 00:00:00 2001 From: chensgit169 Date: Tue, 22 Aug 2023 20:27:24 +0800 Subject: [PATCH 7/9] add qfasm exceptions --- src/quafu/qfasm/qfasm_convertor.py | 93 ++++++++++-------------------- src/quafu/qfasm/qfasm_parser.py | 2 +- src/quafu/qfasm/qfasmlex.py | 4 +- src/quafu/tasks/tasks.py | 1 - 4 files changed, 33 insertions(+), 67 deletions(-) diff --git a/src/quafu/qfasm/qfasm_convertor.py b/src/quafu/qfasm/qfasm_convertor.py index f4414191..6adfa919 100644 --- a/src/quafu/qfasm/qfasm_convertor.py +++ b/src/quafu/qfasm/qfasm_convertor.py @@ -2,7 +2,6 @@ from quafu.dagcircuits.circuit_dag import node_to_gate from quafu.dagcircuits.instruction_node import InstructionNode from quafu.circuits import QuantumCircuit, QuantumRegister -from quafu.elements.quantum_element import Instruction def qasm_to_circuit(qasm): @@ -41,33 +40,39 @@ def qasm2_to_quafu_qc(qc: QuantumCircuit, openqasm: str): import re qc.openqasm = openqasm - # lines = self.openqasm.strip("\n").splitlines(";") + lines = qc.openqasm.splitlines() lines = [line for line in lines if line] + lines = [line for line in lines if not line.startswith("//")] # annotations + + # init qc qc.gates = [] qc.measures = {} measured_qubits = [] global_valid = True + + # proceed line by line for line in lines[2:]: if line: operations_qbs = line.split(" ", 1) operations = operations_qbs[0] if operations == "qreg": qbs = operations_qbs[1] - num = int(re.findall("\d+", qbs)[0]) + num = int(re.findall(r"\d+", qbs)[0]) reg = QuantumRegister(num) qc.qregs.append(reg) elif operations == "creg": pass elif operations == "measure": qbs = operations_qbs[1] - indstr = re.findall("\d+", qbs) + indstr = re.findall(r"\d+", qbs) inds = [int(indst) for indst in indstr] mb = inds[0] cb = inds[1] qc.measures[mb] = cb measured_qubits.append(mb) else: + # apply some kind of instruction qbs = operations_qbs[1] indstr = re.findall("\d+", qbs) inds = [int(indst) for indst in indstr] @@ -83,16 +88,16 @@ def qasm2_to_quafu_qc(qc: QuantumCircuit, openqasm: str): qc.barrier(inds) else: - sp_op = operations.split("(") - gatename = sp_op[0] + sp_op = operations.split("(") # parameters + gatename = sp_op[0].lower() if gatename == "delay": paras = sp_op[1].strip("()") - duration = int(re.findall("\d+", paras)[0]) + duration = int(re.findall(r"\d+", paras)[0]) unit = re.findall("[a-z]+", paras)[0] qc.delay(inds[0], duration, unit) elif gatename == "xy": paras = sp_op[1].strip("()") - duration = int(re.findall("\d+", paras)[0]) + duration = int(re.findall(r"\d+", paras)[0]) unit = re.findall("[a-z]+", paras)[0] qc.xy(min(inds), max(inds), duration, unit) else: @@ -103,44 +108,18 @@ def qasm2_to_quafu_qc(qc: QuantumCircuit, openqasm: str): eval(parai, {"pi": pi}) for parai in parastr ] - if gatename == "cx": - qc.cnot(inds[0], inds[1]) - elif gatename == "cy": - qc.cy(inds[0], inds[1]) - elif gatename == "cz": - qc.cz(inds[0], inds[1]) + if gatename in ["cx", "cy", "cz", "swap"]: + funcs = {"cx": qc.cnot, "cy": qc.cy, "cz": qc.cz, "swap": qc.swap} + funcs[gatename](inds[0], inds[1]) elif gatename == "cp": qc.cp(inds[0], inds[1], paras[0]) - elif gatename == "swap": - qc.swap(inds[0], inds[1]) - elif gatename == "rx": - qc.rx(inds[0], paras[0]) - elif gatename == "ry": - qc.ry(inds[0], paras[0]) - elif gatename == "rz": - qc.rz(inds[0], paras[0]) - elif gatename == "p": - qc.p(inds[0], paras[0]) - elif gatename == "x": - qc.x(inds[0]) - elif gatename == "y": - qc.y(inds[0]) - elif gatename == "z": - qc.z(inds[0]) - elif gatename == "h": - qc.h(inds[0]) - elif gatename == "id": - qc.id(inds[0]) - elif gatename == "s": - qc.s(inds[0]) - elif gatename == "sdg": - qc.sdg(inds[0]) - elif gatename == "t": - qc.t(inds[0]) - elif gatename == "tdg": - qc.tdg(inds[0]) - elif gatename == "sx": - qc.sx(inds[0]) + elif gatename in ["rx", "ry", "rz", "p"]: + funcs = {"rx": qc.rx, "ry": qc.ry, "rz": qc.rz, "p": qc.p} + funcs[gatename](inds[0], paras[0]) + elif gatename in ["x", "y", "z", "h", "id", "s", "sdg", "t", "tdg", "sx"]: + func = {"x": qc.x, "y": qc.y, "z": qc.z, "h": qc.h, "id": qc.id, + "s": qc.s, "sdg": qc.sdg, "t": qc.t, "tdg": qc.tdg, "sx": qc.sx} + func[gatename](inds[0]) elif gatename == "ccx": qc.toffoli(inds[0], inds[1], inds[2]) elif gatename == "cswap": @@ -155,12 +134,9 @@ def qasm2_to_quafu_qc(qc: QuantumCircuit, openqasm: str): qc.rz(inds[0], paras[2]) qc.ry(inds[0], paras[0]) qc.rz(inds[0], paras[1]) - elif gatename == "rxx": - qc.rxx(inds[0], inds[1], paras[0]) - elif gatename == "ryy": - qc.ryy(inds[0], inds[1], paras[0]) - elif gatename == "rzz": - qc.rzz(inds[0], inds[1], paras[0]) + elif gatename in ["rxx", "ryy", "rzz"]: + funcs = {"rxx": qc.rxx, "ryy": qc.ryy, "rzz": qc.rzz} + funcs[gatename](inds[0], inds[1], paras[0]) else: print( "Warning: Operations %s may be not supported by QuantumCircuit class currently." @@ -170,18 +146,7 @@ def qasm2_to_quafu_qc(qc: QuantumCircuit, openqasm: str): if not qc.measures: qc.measures = dict(zip(range(qc.num), range(qc.num))) if not global_valid: - print( - "Warning: All operations after measurement will be removed for executing on experiment" - ) - - -if __name__ == '__main__': - import re - - pattern = r"[a-z]" - - text = "Hello, world! This is a test." - - matches = re.findall(pattern, text) + import warnings + warnings.warn("All operations after measurement will be removed for executing on experiment") - print(matches) + return qc diff --git a/src/quafu/qfasm/qfasm_parser.py b/src/quafu/qfasm/qfasm_parser.py index 9f97974c..5a0aa348 100644 --- a/src/quafu/qfasm/qfasm_parser.py +++ b/src/quafu/qfasm/qfasm_parser.py @@ -209,7 +209,7 @@ def p_expression_none(self, p): p[0] = p[1] def p_expression_term(self, p): - "expression : term" + """expression : term""" p[0] = p[1] def p_expression_m(self, p): diff --git a/src/quafu/qfasm/qfasmlex.py b/src/quafu/qfasm/qfasmlex.py index a12497e9..c5e73297 100644 --- a/src/quafu/qfasm/qfasmlex.py +++ b/src/quafu/qfasm/qfasmlex.py @@ -9,6 +9,8 @@ class QfasmLexer(object): def __init__(self): + self.lexer = None + self.data = None self.build() def input(self, data): @@ -91,7 +93,7 @@ def t_error(self, t): print("Illegal character '%s'" % t.value[0]) def t_newline(self, t): - r"\n+" + r"""\n+""" t.lexer.lineno += len(t.value) def build(self, **kwargs): diff --git a/src/quafu/tasks/tasks.py b/src/quafu/tasks/tasks.py index ffadf7ca..e6028be4 100644 --- a/src/quafu/tasks/tasks.py +++ b/src/quafu/tasks/tasks.py @@ -39,7 +39,6 @@ class Task(object): priority (int): priority level of the task submit_history (dict): circuit submitted with this task backend (dict): quantum backend that execute the task. - """ def __init__(self, user: User = None): From cba883b88e6b3b981f0d917f4bd372b0f88cb348 Mon Sep 17 00:00:00 2001 From: chensgit169 Date: Tue, 22 Aug 2023 20:27:36 +0800 Subject: [PATCH 8/9] add qfasm exceptions --- src/quafu/qfasm/exceptions.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/quafu/qfasm/exceptions.py diff --git a/src/quafu/qfasm/exceptions.py b/src/quafu/qfasm/exceptions.py new file mode 100644 index 00000000..b8555142 --- /dev/null +++ b/src/quafu/qfasm/exceptions.py @@ -0,0 +1,16 @@ +from quafu.exceptions import QuafuError + + +class QfasmError(QuafuError): + """ + Base class for errors raised by Qfasm. + """ + pass + + +class QfasmSyntaxError(QfasmError): + pass + + +class QfasmSemanticError(QfasmError): + pass From c0a838918c902fe4dc58aafe19668ef697124a59 Mon Sep 17 00:00:00 2001 From: chensgit169 Date: Tue, 22 Aug 2023 20:27:49 +0800 Subject: [PATCH 9/9] Revert "add qfasm exceptions" This reverts commit 275794b3f2ee29c4d228a69ffe773dda2633b5f1. --- src/quafu/qfasm/qfasm_convertor.py | 93 ++++++++++++++++++++---------- src/quafu/qfasm/qfasm_parser.py | 2 +- src/quafu/qfasm/qfasmlex.py | 4 +- src/quafu/tasks/tasks.py | 1 + 4 files changed, 67 insertions(+), 33 deletions(-) diff --git a/src/quafu/qfasm/qfasm_convertor.py b/src/quafu/qfasm/qfasm_convertor.py index 6adfa919..f4414191 100644 --- a/src/quafu/qfasm/qfasm_convertor.py +++ b/src/quafu/qfasm/qfasm_convertor.py @@ -2,6 +2,7 @@ from quafu.dagcircuits.circuit_dag import node_to_gate from quafu.dagcircuits.instruction_node import InstructionNode from quafu.circuits import QuantumCircuit, QuantumRegister +from quafu.elements.quantum_element import Instruction def qasm_to_circuit(qasm): @@ -40,39 +41,33 @@ def qasm2_to_quafu_qc(qc: QuantumCircuit, openqasm: str): import re qc.openqasm = openqasm - + # lines = self.openqasm.strip("\n").splitlines(";") lines = qc.openqasm.splitlines() lines = [line for line in lines if line] - lines = [line for line in lines if not line.startswith("//")] # annotations - - # init qc qc.gates = [] qc.measures = {} measured_qubits = [] global_valid = True - - # proceed line by line for line in lines[2:]: if line: operations_qbs = line.split(" ", 1) operations = operations_qbs[0] if operations == "qreg": qbs = operations_qbs[1] - num = int(re.findall(r"\d+", qbs)[0]) + num = int(re.findall("\d+", qbs)[0]) reg = QuantumRegister(num) qc.qregs.append(reg) elif operations == "creg": pass elif operations == "measure": qbs = operations_qbs[1] - indstr = re.findall(r"\d+", qbs) + indstr = re.findall("\d+", qbs) inds = [int(indst) for indst in indstr] mb = inds[0] cb = inds[1] qc.measures[mb] = cb measured_qubits.append(mb) else: - # apply some kind of instruction qbs = operations_qbs[1] indstr = re.findall("\d+", qbs) inds = [int(indst) for indst in indstr] @@ -88,16 +83,16 @@ def qasm2_to_quafu_qc(qc: QuantumCircuit, openqasm: str): qc.barrier(inds) else: - sp_op = operations.split("(") # parameters - gatename = sp_op[0].lower() + sp_op = operations.split("(") + gatename = sp_op[0] if gatename == "delay": paras = sp_op[1].strip("()") - duration = int(re.findall(r"\d+", paras)[0]) + duration = int(re.findall("\d+", paras)[0]) unit = re.findall("[a-z]+", paras)[0] qc.delay(inds[0], duration, unit) elif gatename == "xy": paras = sp_op[1].strip("()") - duration = int(re.findall(r"\d+", paras)[0]) + duration = int(re.findall("\d+", paras)[0]) unit = re.findall("[a-z]+", paras)[0] qc.xy(min(inds), max(inds), duration, unit) else: @@ -108,18 +103,44 @@ def qasm2_to_quafu_qc(qc: QuantumCircuit, openqasm: str): eval(parai, {"pi": pi}) for parai in parastr ] - if gatename in ["cx", "cy", "cz", "swap"]: - funcs = {"cx": qc.cnot, "cy": qc.cy, "cz": qc.cz, "swap": qc.swap} - funcs[gatename](inds[0], inds[1]) + if gatename == "cx": + qc.cnot(inds[0], inds[1]) + elif gatename == "cy": + qc.cy(inds[0], inds[1]) + elif gatename == "cz": + qc.cz(inds[0], inds[1]) elif gatename == "cp": qc.cp(inds[0], inds[1], paras[0]) - elif gatename in ["rx", "ry", "rz", "p"]: - funcs = {"rx": qc.rx, "ry": qc.ry, "rz": qc.rz, "p": qc.p} - funcs[gatename](inds[0], paras[0]) - elif gatename in ["x", "y", "z", "h", "id", "s", "sdg", "t", "tdg", "sx"]: - func = {"x": qc.x, "y": qc.y, "z": qc.z, "h": qc.h, "id": qc.id, - "s": qc.s, "sdg": qc.sdg, "t": qc.t, "tdg": qc.tdg, "sx": qc.sx} - func[gatename](inds[0]) + elif gatename == "swap": + qc.swap(inds[0], inds[1]) + elif gatename == "rx": + qc.rx(inds[0], paras[0]) + elif gatename == "ry": + qc.ry(inds[0], paras[0]) + elif gatename == "rz": + qc.rz(inds[0], paras[0]) + elif gatename == "p": + qc.p(inds[0], paras[0]) + elif gatename == "x": + qc.x(inds[0]) + elif gatename == "y": + qc.y(inds[0]) + elif gatename == "z": + qc.z(inds[0]) + elif gatename == "h": + qc.h(inds[0]) + elif gatename == "id": + qc.id(inds[0]) + elif gatename == "s": + qc.s(inds[0]) + elif gatename == "sdg": + qc.sdg(inds[0]) + elif gatename == "t": + qc.t(inds[0]) + elif gatename == "tdg": + qc.tdg(inds[0]) + elif gatename == "sx": + qc.sx(inds[0]) elif gatename == "ccx": qc.toffoli(inds[0], inds[1], inds[2]) elif gatename == "cswap": @@ -134,9 +155,12 @@ def qasm2_to_quafu_qc(qc: QuantumCircuit, openqasm: str): qc.rz(inds[0], paras[2]) qc.ry(inds[0], paras[0]) qc.rz(inds[0], paras[1]) - elif gatename in ["rxx", "ryy", "rzz"]: - funcs = {"rxx": qc.rxx, "ryy": qc.ryy, "rzz": qc.rzz} - funcs[gatename](inds[0], inds[1], paras[0]) + elif gatename == "rxx": + qc.rxx(inds[0], inds[1], paras[0]) + elif gatename == "ryy": + qc.ryy(inds[0], inds[1], paras[0]) + elif gatename == "rzz": + qc.rzz(inds[0], inds[1], paras[0]) else: print( "Warning: Operations %s may be not supported by QuantumCircuit class currently." @@ -146,7 +170,18 @@ def qasm2_to_quafu_qc(qc: QuantumCircuit, openqasm: str): if not qc.measures: qc.measures = dict(zip(range(qc.num), range(qc.num))) if not global_valid: - import warnings - warnings.warn("All operations after measurement will be removed for executing on experiment") + print( + "Warning: All operations after measurement will be removed for executing on experiment" + ) + + +if __name__ == '__main__': + import re + + pattern = r"[a-z]" + + text = "Hello, world! This is a test." + + matches = re.findall(pattern, text) - return qc + print(matches) diff --git a/src/quafu/qfasm/qfasm_parser.py b/src/quafu/qfasm/qfasm_parser.py index 5a0aa348..9f97974c 100644 --- a/src/quafu/qfasm/qfasm_parser.py +++ b/src/quafu/qfasm/qfasm_parser.py @@ -209,7 +209,7 @@ def p_expression_none(self, p): p[0] = p[1] def p_expression_term(self, p): - """expression : term""" + "expression : term" p[0] = p[1] def p_expression_m(self, p): diff --git a/src/quafu/qfasm/qfasmlex.py b/src/quafu/qfasm/qfasmlex.py index c5e73297..a12497e9 100644 --- a/src/quafu/qfasm/qfasmlex.py +++ b/src/quafu/qfasm/qfasmlex.py @@ -9,8 +9,6 @@ class QfasmLexer(object): def __init__(self): - self.lexer = None - self.data = None self.build() def input(self, data): @@ -93,7 +91,7 @@ def t_error(self, t): print("Illegal character '%s'" % t.value[0]) def t_newline(self, t): - r"""\n+""" + r"\n+" t.lexer.lineno += len(t.value) def build(self, **kwargs): diff --git a/src/quafu/tasks/tasks.py b/src/quafu/tasks/tasks.py index e6028be4..ffadf7ca 100644 --- a/src/quafu/tasks/tasks.py +++ b/src/quafu/tasks/tasks.py @@ -39,6 +39,7 @@ class Task(object): priority (int): priority level of the task submit_history (dict): circuit submitted with this task backend (dict): quantum backend that execute the task. + """ def __init__(self, user: User = None):