From d94d32ba458891d705b7b6e52d63c7221cd0a1a8 Mon Sep 17 00:00:00 2001 From: David Yonge-Mallo Date: Thu, 14 Sep 2023 09:41:36 +0200 Subject: [PATCH 1/2] Restore missing copyright headers in some test files. --- tests/test_cnot_mapper.py | 17 +++++++++++++++++ tests/test_phasepoly.py | 17 +++++++++++++++++ tests/test_ry.py | 13 +++++++++++++ 3 files changed, 47 insertions(+) diff --git a/tests/test_cnot_mapper.py b/tests/test_cnot_mapper.py index 56aee605..cd1c9235 100644 --- a/tests/test_cnot_mapper.py +++ b/tests/test_cnot_mapper.py @@ -1,3 +1,20 @@ +# PyZX - Python library for quantum circuit rewriting +# and optimization using the ZX-calculus +# Copyright (C) 2018 - Aleks Kissinger and John van de Wetering + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + import copy import unittest import sys diff --git a/tests/test_phasepoly.py b/tests/test_phasepoly.py index 6ea18584..f4f17437 100644 --- a/tests/test_phasepoly.py +++ b/tests/test_phasepoly.py @@ -1,3 +1,20 @@ +# PyZX - Python library for quantum circuit rewriting +# and optimization using the ZX-calculus +# Copyright (C) 2018 - Aleks Kissinger and John van de Wetering + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + from typing import List import unittest import sys, os diff --git a/tests/test_ry.py b/tests/test_ry.py index 96508cba..2506c592 100644 --- a/tests/test_ry.py +++ b/tests/test_ry.py @@ -1,7 +1,20 @@ +# PyZX - Python library for quantum circuit rewriting +# and optimization using the ZX-calculus +# Copyright (C) 2018 - Aleks Kissinger and John van de Wetering + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import unittest import random import sys From c0438732b9e6da46790c9b856f849eea45db8432 Mon Sep 17 00:00:00 2001 From: David Yonge-Mallo Date: Thu, 14 Sep 2023 09:46:44 +0200 Subject: [PATCH 2/2] In qasmparser.py, consistently use single quotes for qiskit gate name literals. --- pyzx/circuit/qasmparser.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pyzx/circuit/qasmparser.py b/pyzx/circuit/qasmparser.py index ca10fe8e..4e7539ef 100644 --- a/pyzx/circuit/qasmparser.py +++ b/pyzx/circuit/qasmparser.py @@ -169,13 +169,13 @@ def parse_command(self, c: str, registers: Dict[str,Tuple[int,int]]) -> List[Gat for g in circ.gates: gates.append(g.reposition(argset)) continue - if name in ("x", "z", "s", "t", "h", "sdg", "tdg"): - if name in ("sdg", "tdg"): + if name in ('x', 'z', 's', 't', 'h', 'sdg', 'tdg'): + if name in ('sdg', 'tdg'): g = qasm_gate_table[name](argset[0],adjoint=True) # type: ignore # mypy can't handle - else: g = qasm_gate_table[name](argset[0]) # type: ignore # - Gate subclasses with different numbers of parameters gates.append(g) continue - if name.startswith(("rx", "ry", "rz", "p", "u1", "crz")): + if name.startswith(('rx', 'ry', 'rz', 'p', 'u1', 'crz')): i = name.find('(') j = name.find(')') if i == -1 or j == -1: raise TypeError("Invalid specification {}".format(name)) @@ -201,7 +201,7 @@ def parse_command(self, c: str, registers: Dict[str,Tuple[int,int]]) -> List[Gat gates.append(NOT(argset[0])) gates.append(ZPhase(argset[0],phase=-phase/2)) gates.append(NOT(argset[0])) - elif name.startswith("ry"): gates.append(YPhase(argset[0],phase=phase)) + elif name.startswith('ry'): gates.append(YPhase(argset[0],phase=phase)) else: raise TypeError("Invalid specification {}".format(name)) continue if name.startswith('u2') or name.startswith('u3'): # see https://arxiv.org/pdf/1707.03429.pdf @@ -225,11 +225,11 @@ def parse_command(self, c: str, registers: Dict[str,Tuple[int,int]]) -> List[Gat gates.append(XPhase(argset[0],phase=Fraction(1,2))) gates.append(ZPhase(argset[0],phase=(phases[1]+3)%2)) continue - if name in ("cx","CX","cz","ch", "swap"): + if name in ('cx', 'CX', 'cz', 'ch', 'swap'): g = qasm_gate_table[name](control=argset[0],target=argset[1]) # type: ignore gates.append(g) continue - if name in ("ccx", "ccz"): + if name in ('ccx', 'ccz'): g = qasm_gate_table[name](ctrl1=argset[0],ctrl2=argset[1],target=argset[2]) # type: ignore gates.append(g) continue