From 6375114006b3ecdfdbfbc791a2df45c0c6072c2b Mon Sep 17 00:00:00 2001 From: "Davide Gessa (dakk)" Date: Fri, 22 Dec 2023 11:42:30 +0100 Subject: [PATCH] integrate linters for jupyter notebooks and tests --- docs/source/example_big_circuit.ipynb | 1 + docs/source/example_deutsch_jozsa.ipynb | 7 +++-- docs/source/example_grover.ipynb | 9 +++--- docs/source/example_grover_factors.ipynb | 6 ++-- docs/source/example_grover_hash.ipynb | 17 ++++++----- docs/source/example_grover_subset.ipynb | 3 +- docs/source/example_grover_sudoku.ipynb | 16 ++++++----- docs/source/example_simon.ipynb | 8 +++--- docs/source/example_unitary_of_f.ipynb | 8 ++++-- docs/source/exporter.ipynb | 11 ++++---- docs/source/how_it_works.ipynb | 16 ++++++----- docs/source/quickstart.ipynb | 17 ++++++----- qlasskit/algorithms/counting.py | 1 + test/__init__.py | 2 +- test/test_algo.py | 4 +-- test/test_algo_deutschjozsa.py | 3 +- test/test_algo_grover.py | 2 +- test/test_algo_simon.py | 3 +- test/test_bool_optimizer.py | 9 ++---- test/test_compiler.py | 7 +++-- test/test_qlassf.py | 2 +- test/test_qlassf_bool.py | 31 +++++++++++--------- test/test_qlassf_builtin.py | 5 +--- test/test_qlassf_for_loop.py | 22 +++++++++++---- test/test_qlassf_functiondef.py | 5 +--- test/test_qlassf_hybrid_quantum.py | 6 ++-- test/test_qlassf_ifthenelse.py | 2 +- test/test_qlassf_int.py | 36 ++++++++++++++++++------ test/test_qlassf_list.py | 20 +++++++++---- test/test_qlassf_matrix.py | 35 ++++++++++++++++------- test/test_qlassf_tuple.py | 28 +++++++++++------- test/test_types.py | 7 +---- test/utils.py | 26 +++++++---------- tox.ini | 3 +- 34 files changed, 219 insertions(+), 159 deletions(-) create mode 100644 qlasskit/algorithms/counting.py diff --git a/docs/source/example_big_circuit.ipynb b/docs/source/example_big_circuit.ipynb index 91684458..22bfb9c4 100644 --- a/docs/source/example_big_circuit.ipynb +++ b/docs/source/example_big_circuit.ipynb @@ -24,6 +24,7 @@ "source": [ "from qlasskit import Qint8, Qlist, boolopt, qlassfa\n", "\n", + "\n", "@qlassfa(bool_optimizer=boolopt.fastOptimizer)\n", "def test(message: Qlist[Qint8, 32]) -> Qint8:\n", " h_val = Qint8(0)\n", diff --git a/docs/source/example_deutsch_jozsa.ipynb b/docs/source/example_deutsch_jozsa.ipynb index 2b0f5686..cbb83460 100644 --- a/docs/source/example_deutsch_jozsa.ipynb +++ b/docs/source/example_deutsch_jozsa.ipynb @@ -15,6 +15,7 @@ "source": [ "from qlasskit import qlassf, Qint4\n", "\n", + "\n", "@qlassf\n", "def f(a: Qint4) -> bool:\n", " return a > 7" @@ -38,7 +39,7 @@ } ], "source": [ - "f.export('qiskit').draw('mpl')" + "f.export(\"qiskit\").draw(\"mpl\")" ] }, { @@ -70,8 +71,8 @@ } ], "source": [ - "qc = q_algo.export('qiskit')\n", - "qc.draw('mpl')" + "qc = q_algo.export(\"qiskit\")\n", + "qc.draw(\"mpl\")" ] }, { diff --git a/docs/source/example_grover.ipynb b/docs/source/example_grover.ipynb index 3f696436..aa416ec2 100644 --- a/docs/source/example_grover.ipynb +++ b/docs/source/example_grover.ipynb @@ -18,12 +18,13 @@ "source": [ "from qlasskit import qlassf, Qlist, Qint2\n", "\n", + "\n", "@qlassf\n", "def and_all(a_list: Qlist[bool, 4]) -> bool:\n", " r = True\n", " for i in a_list:\n", " r = r and i\n", - " return r " + " return r" ] }, { @@ -51,7 +52,7 @@ } ], "source": [ - "and_all.export('qiskit').draw('mpl')" + "and_all.export(\"qiskit\").draw(\"mpl\")" ] }, { @@ -97,8 +98,8 @@ } ], "source": [ - "qc = q_algo.export('qiskit')\n", - "qc.draw('mpl')" + "qc = q_algo.export(\"qiskit\")\n", + "qc.draw(\"mpl\")" ] }, { diff --git a/docs/source/example_grover_factors.ipynb b/docs/source/example_grover_factors.ipynb index 7b9d928f..5809def1 100644 --- a/docs/source/example_grover_factors.ipynb +++ b/docs/source/example_grover_factors.ipynb @@ -17,10 +17,12 @@ "from qlasskit import qlassf, Qint2\n", "from qlasskit.algorithms import Grover\n", "\n", + "\n", "@qlassf\n", "def factorize(a: Tuple[Qint2, Qint2]) -> bool:\n", " return a[0] * a[1] == 9\n", "\n", + "\n", "q_algo = Grover(factorize)" ] }, @@ -45,7 +47,7 @@ "from qiskit import Aer, QuantumCircuit, transpile\n", "from qiskit.visualization import plot_histogram\n", "\n", - "qc = q_algo.export('qiskit')\n", + "qc = q_algo.export(\"qiskit\")\n", "qc.measure_all()\n", "simulator = Aer.get_backend(\"aer_simulator\")\n", "circ = transpile(qc, simulator)\n", @@ -74,7 +76,7 @@ } ], "source": [ - "qc.draw('mpl')" + "qc.draw(\"mpl\")" ] } ], diff --git a/docs/source/example_grover_hash.ipynb b/docs/source/example_grover_hash.ipynb index 2d13ec0a..2dc622a1 100644 --- a/docs/source/example_grover_hash.ipynb +++ b/docs/source/example_grover_hash.ipynb @@ -19,11 +19,12 @@ "source": [ "from qlasskit import qlassf, Qint4, Qint8, Qlist\n", "\n", + "\n", "@qlassf\n", "def hash_simp(m: Qlist[Qint4, 2]) -> Qint8:\n", " hv = 0\n", " for i in m:\n", - " hv = ((hv << 4) ^ (hv >> 1) ^ i) & 0xff\n", + " hv = ((hv << 4) ^ (hv >> 1) ^ i) & 0xFF\n", "\n", " return hv" ] @@ -51,9 +52,11 @@ "source": [ "from collections import Counter\n", "\n", - "d = Counter(hex(hash_simp.original_f((x, y))) for x in range(2**4) for y in range(2**4))\n", + "d = Counter(\n", + " hex(hash_simp.original_f((x, y))) for x in range(2**4) for y in range(2**4)\n", + ")\n", "\n", - "print('Hash function output space:', len(d))" + "print(\"Hash function output space:\", len(d))" ] }, { @@ -81,7 +84,7 @@ } ], "source": [ - "hash_simp.export('qiskit').draw('mpl')" + "hash_simp.export(\"qiskit\").draw(\"mpl\")" ] }, { @@ -100,7 +103,7 @@ "source": [ "from qlasskit.algorithms import Grover\n", "\n", - "q_algo = Grover(hash_simp, Qint8(0xca))" + "q_algo = Grover(hash_simp, Qint8(0xCA))" ] }, { @@ -131,7 +134,7 @@ "from qiskit import Aer, QuantumCircuit, transpile\n", "from qiskit.visualization import plot_histogram\n", "\n", - "qc = q_algo.export('qiskit')\n", + "qc = q_algo.export(\"qiskit\")\n", "qc.measure_all()\n", "simulator = Aer.get_backend(\"aer_simulator\")\n", "circ = transpile(qc, simulator)\n", @@ -163,7 +166,7 @@ } ], "source": [ - "print(hex(hash_simp.original_f((12,12))))" + "print(hex(hash_simp.original_f((12, 12))))" ] } ], diff --git a/docs/source/example_grover_subset.ipynb b/docs/source/example_grover_subset.ipynb index eac3c3cd..d3c34102 100644 --- a/docs/source/example_grover_subset.ipynb +++ b/docs/source/example_grover_subset.ipynb @@ -18,6 +18,7 @@ "from qlasskit import qlassf, Qint2, Qint3\n", "from typing import Tuple\n", "\n", + "\n", "@qlassf\n", "def subset_sum(ii: Tuple[Qint2, Qint2]) -> Qint3:\n", " l = [0, 5, 2, 3]\n", @@ -72,7 +73,7 @@ "from qiskit import Aer, QuantumCircuit, transpile\n", "from qiskit.visualization import plot_histogram\n", "\n", - "qc = q_algo.export('qiskit')\n", + "qc = q_algo.export(\"qiskit\")\n", "qc.measure_all()\n", "simulator = Aer.get_backend(\"aer_simulator\")\n", "circ = transpile(qc, simulator)\n", diff --git a/docs/source/example_grover_sudoku.ipynb b/docs/source/example_grover_sudoku.ipynb index 0f469c36..da740c2e 100644 --- a/docs/source/example_grover_sudoku.ipynb +++ b/docs/source/example_grover_sudoku.ipynb @@ -21,16 +21,18 @@ "from qlasskit import qlassf, Qint2, Qint4, Qmatrix\n", "from qlasskit.algorithms import Grover\n", "\n", + "\n", "@qlassf\n", - "def sudoku_check(m: Qmatrix[bool,2,2]) -> bool:\n", + "def sudoku_check(m: Qmatrix[bool, 2, 2]) -> bool:\n", " constr = m[0][0]\n", - " sub0 = (m[0][0] ^ m[0][1])\n", - " sub1 = (m[1][0] ^ m[1][1]) \n", - " sub2 = (m[0][0] ^ m[1][0])\n", - " sub3 = (m[0][1] ^ m[1][1])\n", + " sub0 = m[0][0] ^ m[0][1]\n", + " sub1 = m[1][0] ^ m[1][1]\n", + " sub2 = m[0][0] ^ m[1][0]\n", + " sub3 = m[0][1] ^ m[1][1]\n", " return sub0 and sub1 and sub2 and sub3 and constr\n", "\n", - "q_algo = Grover(sudoku_check)\n" + "\n", + "q_algo = Grover(sudoku_check)" ] }, { @@ -63,7 +65,7 @@ "from qiskit import Aer, QuantumCircuit, transpile\n", "from qiskit.visualization import plot_histogram\n", "\n", - "qc = q_algo.export('qiskit')\n", + "qc = q_algo.export(\"qiskit\")\n", "qc.measure_all()\n", "simulator = Aer.get_backend(\"aer_simulator\")\n", "circ = transpile(qc, simulator)\n", diff --git a/docs/source/example_simon.ipynb b/docs/source/example_simon.ipynb index cfaed44b..05728d9b 100644 --- a/docs/source/example_simon.ipynb +++ b/docs/source/example_simon.ipynb @@ -15,6 +15,7 @@ "source": [ "from qlasskit import qlassf, Qint4\n", "\n", + "\n", "@qlassf\n", "def f(a: Qint4) -> Qint4:\n", " return (a >> 3) + 1" @@ -38,8 +39,7 @@ } ], "source": [ - "\n", - "f.export('qiskit').draw('mpl')" + "f.export(\"qiskit\").draw(\"mpl\")" ] }, { @@ -71,8 +71,8 @@ } ], "source": [ - "qc = q_algo.export('qiskit')\n", - "qc.draw('mpl')" + "qc = q_algo.export(\"qiskit\")\n", + "qc.draw(\"mpl\")" ] }, { diff --git a/docs/source/example_unitary_of_f.ipynb b/docs/source/example_unitary_of_f.ipynb index ad04bd2b..666f7d40 100644 --- a/docs/source/example_unitary_of_f.ipynb +++ b/docs/source/example_unitary_of_f.ipynb @@ -41,16 +41,18 @@ "from qiskit.visualization import array_to_latex\n", "from qlasskit import qlassf\n", "\n", + "\n", "@qlassf\n", "def f(a: bool, b: bool) -> bool:\n", " return a ^ (not b)\n", "\n", + "\n", "print(f\"\\n{f}\\n\")\n", "\n", "qc = QuantumCircuit(f.num_qubits, f.num_qubits)\n", "qc.append(f.gate(), f.qubits)\n", "\n", - "qc.decompose().draw('mpl')\n" + "qc.decompose().draw(\"mpl\")" ] }, { @@ -85,10 +87,10 @@ } ], "source": [ - "simulator = Aer.get_backend('unitary_simulator')\n", + "simulator = Aer.get_backend(\"unitary_simulator\")\n", "job = execute(qc, simulator, shots=8192)\n", "result = job.result()\n", - "array_to_latex(result.get_unitary(qc,3), max_size=16)\n" + "array_to_latex(result.get_unitary(qc, 3), max_size=16)" ] } ], diff --git a/docs/source/exporter.ipynb b/docs/source/exporter.ipynb index 4f0e02cb..87301c8c 100644 --- a/docs/source/exporter.ipynb +++ b/docs/source/exporter.ipynb @@ -22,6 +22,7 @@ "source": [ "from qlasskit import Qint2, qlassf\n", "\n", + "\n", "@qlassf\n", "def hello_world(a: bool, b: Qint2) -> Qint2:\n", " return b + (1 if a else 0)" @@ -52,8 +53,8 @@ } ], "source": [ - "qc = hello_world.export('qiskit')\n", - "qc.draw('mpl')" + "qc = hello_world.export(\"qiskit\")\n", + "qc.draw(\"mpl\")" ] }, { @@ -86,8 +87,8 @@ } ], "source": [ - "qc = hello_world.export('qasm')\n", - "print (qc)" + "qc = hello_world.export(\"qasm\")\n", + "print(qc)" ] }, { @@ -135,7 +136,7 @@ "source": [ "import cirq\n", "\n", - "qc = hello_world.export('cirq')\n", + "qc = hello_world.export(\"cirq\")\n", "qc" ] }, diff --git a/docs/source/how_it_works.ipynb b/docs/source/how_it_works.ipynb index 0bf6bb0c..fe3b9699 100644 --- a/docs/source/how_it_works.ipynb +++ b/docs/source/how_it_works.ipynb @@ -31,11 +31,12 @@ "from qlasskit import qlassf, Qint2, Qint4\n", "from qiskit import QuantumCircuit\n", "\n", + "\n", "@qlassf\n", "def f_comp(b: bool, n: Qint2) -> Qint2:\n", - " for i in range(3):\n", - " n += (1 if b else 2)\n", - " return n" + " for i in range(3):\n", + " n += 1 if b else 2\n", + " return n" ] }, { @@ -74,13 +75,14 @@ "def f1(b: bool, n: Qint2) -> Qint2:\n", " return n + (1 if b else 2)\n", "\n", + "\n", "qc = QuantumCircuit(f_comp.num_qubits * 2 - 1)\n", "\n", "for i in range(3):\n", " qc.barrier(label=f\"it_{i}\")\n", " qc.append(f1.gate(), [0] + list(range(1 + i * 2, 5 + i * 2)))\n", "\n", - "print('Operations:', qc.decompose().count_ops())\n", + "print(\"Operations:\", qc.decompose().count_ops())\n", "qc.decompose().draw(\"mpl\")" ] }, @@ -119,7 +121,7 @@ "qc = QuantumCircuit(f_comp.num_qubits)\n", "qc.append(f_comp.gate(), f_comp.qubits)\n", "\n", - "print('Operations:', qc.decompose().count_ops())\n", + "print(\"Operations:\", qc.decompose().count_ops())\n", "qc.decompose().draw(\"mpl\")" ] }, @@ -150,7 +152,7 @@ "source": [ "@qlassf\n", "def f(n: Qint4) -> bool:\n", - " return n == 3 " + " return n == 3" ] }, { @@ -222,7 +224,7 @@ } ], "source": [ - "f.export().draw('mpl')" + "f.export().draw(\"mpl\")" ] } ], diff --git a/docs/source/quickstart.ipynb b/docs/source/quickstart.ipynb index 59eae55e..f1fe0361 100644 --- a/docs/source/quickstart.ipynb +++ b/docs/source/quickstart.ipynb @@ -21,7 +21,8 @@ "source": [ "from qlasskit import qlassf, Qint2\n", "\n", - "@qlassf \n", + "\n", + "@qlassf\n", "def sum_two_numbers(a: Qint2, b: Qint2) -> Qint2:\n", " return a + b" ] @@ -51,8 +52,8 @@ } ], "source": [ - "circuit = sum_two_numbers.export('qiskit')\n", - "circuit.draw('mpl')" + "circuit = sum_two_numbers.export(\"qiskit\")\n", + "circuit.draw(\"mpl\")" ] }, { @@ -82,12 +83,14 @@ "source": [ "from qiskit import QuantumCircuit\n", "\n", - "qc = QuantumCircuit(sum_two_numbers.num_qubits,len(sum_two_numbers.output_qubits))\n", + "qc = QuantumCircuit(sum_two_numbers.num_qubits, len(sum_two_numbers.output_qubits))\n", "\n", - "qc.initialize(sum_two_numbers.encode_input(Qint2(1), Qint2(2)), sum_two_numbers.input_qubits)\n", - "qc.append(sum_two_numbers.gate('qiskit'), sum_two_numbers.qubits)\n", + "qc.initialize(\n", + " sum_two_numbers.encode_input(Qint2(1), Qint2(2)), sum_two_numbers.input_qubits\n", + ")\n", + "qc.append(sum_two_numbers.gate(\"qiskit\"), sum_two_numbers.qubits)\n", "qc.measure(sum_two_numbers.output_qubits, range(len(sum_two_numbers.output_qubits)))\n", - "qc.draw('mpl')" + "qc.draw(\"mpl\")" ] }, { diff --git a/qlasskit/algorithms/counting.py b/qlasskit/algorithms/counting.py new file mode 100644 index 00000000..fc91751d --- /dev/null +++ b/qlasskit/algorithms/counting.py @@ -0,0 +1 @@ +# https://github.com/Qiskit/textbook/blob/main/notebooks/ch-algorithms/quantum-counting.ipynb diff --git a/test/__init__.py b/test/__init__.py index f3ea63ea..23785582 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -13,6 +13,6 @@ # limitations under the License. try: - import utils # needed by vscode + import utils # noqa: F401 # needed by vscode except: pass diff --git a/test/test_algo.py b/test/test_algo.py index c5023f4b..e6b7863c 100644 --- a/test/test_algo.py +++ b/test/test_algo.py @@ -18,9 +18,9 @@ from parameterized import parameterized_class from sympy import And, Not, Symbol -from qlasskit import Qint2, Qint4, Qlist, qlassf +from qlasskit import qlassf from qlasskit.algorithms import ConstantOracleException, QAlgorithm, oraclize -from qlasskit.types import format_outcome, interpret_as_qtype +from qlasskit.types import interpret_as_qtype from .utils import ENABLED_COMPILERS diff --git a/test/test_algo_deutschjozsa.py b/test/test_algo_deutschjozsa.py index 221252c1..fc9a2fc0 100644 --- a/test/test_algo_deutschjozsa.py +++ b/test/test_algo_deutschjozsa.py @@ -16,9 +16,8 @@ from parameterized import parameterized_class -from qlasskit import Qint2, Qint4, qlassf +from qlasskit import qlassf from qlasskit.algorithms import DeutschJozsa -from qlasskit.compiler import SupportedCompilers from .utils import ENABLED_COMPILERS, qiskit_measure_and_count diff --git a/test/test_algo_grover.py b/test/test_algo_grover.py index a8de76f2..ba9fad54 100644 --- a/test/test_algo_grover.py +++ b/test/test_algo_grover.py @@ -14,7 +14,7 @@ import unittest -from qlasskit import Qint2, Qint4, qlassf +from qlasskit import Qint2, qlassf from qlasskit.algorithms import Grover from .utils import qiskit_measure_and_count diff --git a/test/test_algo_simon.py b/test/test_algo_simon.py index c23be55a..eb3b94dd 100644 --- a/test/test_algo_simon.py +++ b/test/test_algo_simon.py @@ -16,9 +16,8 @@ from parameterized import parameterized_class -from qlasskit import Qint2, Qint4, qlassf +from qlasskit import qlassf from qlasskit.algorithms import Simon -from qlasskit.compiler import SupportedCompilers from .utils import ENABLED_COMPILERS, qiskit_measure_and_count diff --git a/test/test_bool_optimizer.py b/test/test_bool_optimizer.py index a8ba7820..1f30c0d6 100644 --- a/test/test_bool_optimizer.py +++ b/test/test_bool_optimizer.py @@ -12,10 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - -from parameterized import parameterized_class -from sympy import And, Not, Or, Symbol, symbols -from sympy.logic.boolalg import BooleanTrue - -from qlasskit.boolopt import bool_optimizer +# import unittest +# from qlasskit.boolopt import bool_optimizer diff --git a/test/test_compiler.py b/test/test_compiler.py index 0f376a8a..1f6fca29 100644 --- a/test/test_compiler.py +++ b/test/test_compiler.py @@ -16,7 +16,7 @@ from parameterized import parameterized_class -from qlasskit import compiler, qlassf +from qlasskit import qlassf from .utils import ENABLED_COMPILERS, compute_and_compare_results @@ -39,7 +39,10 @@ def test_and_long(self): compute_and_compare_results(self, qf) def test_and_long_with_not(self): - f = "def test(a: bool, b: bool, c: bool, d: bool) -> bool:\n\treturn a and b and not c and d" + f = ( + "def test(a: bool, b: bool, c: bool, d: bool) -> bool:\n\t" + "return a and b and not c and d" + ) qf = qlassf(f, to_compile=True, compiler=self.compiler) compute_and_compare_results(self, qf) diff --git a/test/test_qlassf.py b/test/test_qlassf.py index 0faef1a7..8d3618e4 100644 --- a/test/test_qlassf.py +++ b/test/test_qlassf.py @@ -16,7 +16,7 @@ from parameterized import parameterized_class -from qlasskit import Qint, Qint2, Qint4, Qint12, QlassF, exceptions, qlassf +from qlasskit import Qint2, Qint4, QlassF, exceptions, qlassf from qlasskit.boolopt.bool_optimizer import defaultOptimizerDebug from . import utils diff --git a/test/test_qlassf_bool.py b/test/test_qlassf_bool.py index 74434f35..b0d623f8 100644 --- a/test/test_qlassf_bool.py +++ b/test/test_qlassf_bool.py @@ -16,9 +16,9 @@ from parameterized import parameterized_class from sympy import Symbol, symbols -from sympy.logic import ITE, And, Not, Or, false, simplify_logic, true +from sympy.logic import ITE, And, Not, false, true -from qlasskit import QlassF, exceptions, qlassf +from qlasskit import exceptions, qlassf from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, compute_and_compare_results @@ -127,7 +127,10 @@ def test_ifexp(self): def test_ifexp2(self): ex = ITE(And(a, And(Not(b), c)), true, false) - f = "def test(a: bool, b: bool, c: bool) -> bool:\n\treturn True if a and (not b) and c else False" + f = ( + "def test(a: bool, b: bool, c: bool) -> bool:\n" + "\treturn True if a and (not b) and c else False" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) @@ -138,7 +141,7 @@ def test_ifexp3(self): exp = And(a, Not(And(b, c))) f = ( "def test(a: bool, b: bool, c: bool) -> bool:\n" - + "\treturn (c and not b) if a and ((not b) and c) else (a and not c)" + "\treturn (c and not b) if a and ((not b) and c) else (a and not c)" ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) @@ -157,8 +160,8 @@ def test_assign(self): def test_assign2(self): f = ( "def test(a: bool, b: bool, c: bool) -> bool:\n" - + "\td = a and (not b) and c\n" - + "\treturn True if d else False" + "\td = a and (not b) and c\n" + "\treturn True if d else False" ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) @@ -169,11 +172,11 @@ def test_assign2(self): def test_assign3(self): f = ( "def test(a: bool, b: bool, c: bool) -> bool:\n" - + "\td = a and (not b) and c\n" - + "\te = a and b and c\n" - + "\tg = (not a) and b and c\n" - + "\th = (not a) and b and (not c)\n" - + "\treturn g if d and e else h" + "\td = a and (not b) and c\n" + "\te = a and b and c\n" + "\tg = (not a) and b and c\n" + "\th = (not a) and b and (not c)\n" + "\treturn g if d and e else h" ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) @@ -184,16 +187,16 @@ def test_assign3(self): @parameterized_class(("compiler"), ENABLED_COMPILERS) class TestQlassfBoolBitwise(unittest.TestCase): def test_bitwise_and(self): - f = f"def test(a: bool, b: bool) -> bool:\n\treturn a & b" + f = "def test(a: bool, b: bool) -> bool:\n\treturn a & b" qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_bitwise_or(self): - f = f"def test(a: bool, b: bool) -> bool:\n\treturn a | b" + f = "def test(a: bool, b: bool) -> bool:\n\treturn a | b" qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_bitwise_xor(self): - f = f"def test(a: bool, b: bool) -> bool:\n\treturn a ^ b" + f = "def test(a: bool, b: bool) -> bool:\n\treturn a ^ b" qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) diff --git a/test/test_qlassf_builtin.py b/test/test_qlassf_builtin.py index 670c2eaa..086cef6f 100644 --- a/test/test_qlassf_builtin.py +++ b/test/test_qlassf_builtin.py @@ -13,13 +13,10 @@ # limitations under the License. import unittest -from typing import Tuple from parameterized import parameterized_class -from sympy import Symbol, symbols -from sympy.logic import ITE, And, Not, Or, false, simplify_logic, true -from qlasskit import QlassF, exceptions, qlassf +from qlasskit import qlassf from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, compute_and_compare_results diff --git a/test/test_qlassf_for_loop.py b/test/test_qlassf_for_loop.py index 074ed897..73fa59fd 100644 --- a/test/test_qlassf_for_loop.py +++ b/test/test_qlassf_for_loop.py @@ -16,9 +16,8 @@ from parameterized import parameterized_class from sympy import Symbol, symbols -from sympy.logic import ITE, And, Not, Or, Xor, false, simplify_logic, true -from qlasskit import Qint2, Qint4, Qint8, QlassF, exceptions, qlassf +from qlasskit import qlassf from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, compute_and_compare_results @@ -54,21 +53,32 @@ def test_for_nit_bool_many(self): compute_and_compare_results(self, qf) # def test_for_nit_tbool_many(self): - # f = "def test(a: Tuple[bool,bool]) -> Tuple[bool,bool]:\n\tfor i in range(32):\n\t\ta[0] = not a[0]\n\t\ta[1] = not a[1]\n\treturn a" + # f = ( + # "def test(a: Tuple[bool,bool]) -> Tuple[bool,bool]:\n\tfor i in range(32):\n" + # "\t\ta[0] = not a[0]\n\t\ta[1] = not a[1]\n\treturn a" # qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) # compute_and_compare_results(self, qf) def test_for_cond(self): - f = "def test(a: Qint2, b: bool) -> Qint2:\n\tfor i in range(2):\n\t\ta += (i if b else 1)\n\treturn a" + f = ( + "def test(a: Qint2, b: bool) -> Qint2:\n\tfor i in range(2):\n" + "\t\ta += (i if b else 1)\n\treturn a" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_for_sum(self): - f = "def hash(k: Qint4) -> bool:\n\tz = 1\n\tfor i in range(3):\n\t\tz += i\n\treturn z == 3" + f = ( + "def hash(k: Qint4) -> bool:\n\tz = 1\n\tfor i in range(3):\n" + "\t\tz += i\n\treturn z == 3" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_for_sum2(self): - f = "def hash(k: Qlist[bool, 4]) -> bool:\n\th = True\n\tfor i in range(len(k)):\n\t\th = h and k[i]\n\treturn h" + f = ( + "def hash(k: Qlist[bool, 4]) -> bool:\n\th = True\n\tfor i in range(len(k)):" + "\n\t\th = h and k[i]\n\treturn h" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) diff --git a/test/test_qlassf_functiondef.py b/test/test_qlassf_functiondef.py index 9f23d6a8..7bd19890 100644 --- a/test/test_qlassf_functiondef.py +++ b/test/test_qlassf_functiondef.py @@ -13,13 +13,10 @@ # limitations under the License. import unittest -from typing import Tuple from parameterized import parameterized_class -from sympy import Symbol, symbols -from sympy.logic import ITE, And, Not, Or, false, simplify_logic, true -from qlasskit import QlassF, exceptions, qlassf +from qlasskit import qlassf from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, compute_and_compare_results diff --git a/test/test_qlassf_hybrid_quantum.py b/test/test_qlassf_hybrid_quantum.py index 97fb8cba..8e6f1f2a 100644 --- a/test/test_qlassf_hybrid_quantum.py +++ b/test/test_qlassf_hybrid_quantum.py @@ -14,11 +14,9 @@ import unittest -from parameterized import parameterized_class +from qlasskit import qlassf -from qlasskit import QlassF, exceptions, qlassf - -from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, qiskit_measure_and_count +from .utils import COMPILATION_ENABLED, qiskit_measure_and_count class TestQlassfHybridQuantum(unittest.TestCase): diff --git a/test/test_qlassf_ifthenelse.py b/test/test_qlassf_ifthenelse.py index b93e7748..3ad4ae4f 100644 --- a/test/test_qlassf_ifthenelse.py +++ b/test/test_qlassf_ifthenelse.py @@ -16,7 +16,7 @@ from parameterized import parameterized_class -from qlasskit import QlassF, exceptions, qlassf +from qlasskit import exceptions, qlassf from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, compute_and_compare_results diff --git a/test/test_qlassf_int.py b/test/test_qlassf_int.py index 97fcc427..7fed3714 100644 --- a/test/test_qlassf_int.py +++ b/test/test_qlassf_int.py @@ -16,9 +16,9 @@ from parameterized import parameterized_class from sympy import Symbol, symbols -from sympy.logic import ITE, And, Not, Or, Xor, false, simplify_logic, true +from sympy.logic import And, Not -from qlasskit import Qint2, Qint4, Qint8, QlassF, exceptions, qlassf +from qlasskit import Qint2, Qint4, exceptions, qlassf from .utils import ( COMPILATION_ENABLED, @@ -63,7 +63,10 @@ def test_int_arg(self): compute_and_compare_results(self, qf) def test_int_arg2(self): - f = f"def test(a: {self.ttype_str}, b: bool) -> bool:\n\treturn a[1] if (a[0] and b) else a[0]" + f = ( + f"def test(a: {self.ttype_str}, b: bool) -> bool:\n" + "\treturn a[1] if (a[0] and b) else a[0]" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) @@ -80,13 +83,19 @@ def test_int_arg_unbound_index(self): ) def test_int_return_tuple(self): - f = f"def test(a: {self.ttype_str}) -> Tuple[{self.ttype_str}, bool]:\n\tb = a[0] and a[1]\n\treturn (a, b)" + f = ( + f"def test(a: {self.ttype_str}) -> Tuple[{self.ttype_str}, bool]:\n" + "\tb = a[0] and a[1]\n\treturn (a, b)" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), self.ttype_size + 1) compute_and_compare_results(self, qf) def test_int_tuple(self): - f = f"def test(a: Tuple[{self.ttype_str}, {self.ttype_str}]) -> bool:\n\treturn a[0][0] and a[1][1]" + f = ( + f"def test(a: Tuple[{self.ttype_str}, {self.ttype_str}]) -> bool:\n" + "\treturn a[0][0] and a[1][1]" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) @@ -211,7 +220,7 @@ def test_int_int_compare_neq(self): compute_and_compare_results(self, qf) def test_const_int_compare_gt(self): - f = f"def test(a: Qint4) -> bool:\n\treturn a > 6" + f = "def test(a: Qint4) -> bool:\n\treturn a > 6" qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) @@ -371,17 +380,26 @@ def test_sub_const3(self): ) class TestQlassfIntBitwise(unittest.TestCase): def test_bitwise_and(self): - f = f"def test(a: {self.ttype_str}, b: {self.ttype_str}) -> {self.ttype_str}:\n\treturn a & b" + f = ( + f"def test(a: {self.ttype_str}, b: {self.ttype_str}) -> {self.ttype_str}:\n" + "\treturn a & b" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_bitwise_or(self): - f = f"def test(a: {self.ttype_str}, b: {self.ttype_str}) -> {self.ttype_str}:\n\treturn a | b" + f = ( + f"def test(a: {self.ttype_str}, b: {self.ttype_str}) -> {self.ttype_str}:\n" + "\treturn a | b" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_bitwise_xor(self): - f = f"def test(a: {self.ttype_str}, b: {self.ttype_str}) -> {self.ttype_str}:\n\treturn a ^ b" + f = ( + f"def test(a: {self.ttype_str}, b: {self.ttype_str}) -> {self.ttype_str}:\n" + "\treturn a ^ b" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) diff --git a/test/test_qlassf_list.py b/test/test_qlassf_list.py index 8ba0afff..422ac569 100644 --- a/test/test_qlassf_list.py +++ b/test/test_qlassf_list.py @@ -13,13 +13,12 @@ # limitations under the License. import unittest -from typing import Tuple from parameterized import parameterized_class from sympy import Symbol, symbols -from sympy.logic import ITE, And, Not, Or, false, simplify_logic, true +from sympy.logic import And -from qlasskit import QlassF, exceptions, qlassf +from qlasskit import qlassf from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, compute_and_compare_results @@ -77,7 +76,10 @@ def test_list_iterator_varlist(self): compute_and_compare_results(self, qf) def test_list_len(self): - f = "def test(a: Qlist[Qint2, 2]) -> Qint2:\n\tc = 0\n\tfor x in range(len(a)):\n\t\tc += a[x]\n\treturn c" + f = ( + "def test(a: Qlist[Qint2, 2]) -> Qint2:\n\tc = 0\n\tfor x in range(len(a)):\n" + "\t\tc += a[x]\n\treturn c" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) @@ -91,7 +93,10 @@ def test_list_access_with_var_on_tuple(self): if self.compiler == "internal": return - f = "def test(ab: Tuple[Qint2, Qint2]) -> Qint2:\n\tc = [1,2,3,2]\n\tai,bi = ab\n\td = c[ai] + c[bi]\n\treturn d" + f = ( + "def test(ab: Tuple[Qint2, Qint2]) -> Qint2:\n\tc = [1,2,3,2]\n\tai,bi = ab\n" + "\td = c[ai] + c[bi]\n\treturn d" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) @@ -100,6 +105,9 @@ def test_list_access_with_var_on_tuple2(self): if self.compiler == "internal": return - f = "def test(ab: Tuple[Qint2, Qint2]) -> Qint2:\n\tc = [1,2,3,2]\n\td = c[ab[0]] + c[ab[1]]\n\treturn d" + f = ( + "def test(ab: Tuple[Qint2, Qint2]) -> Qint2:\n\tc = [1,2,3,2]\n" + "\td = c[ab[0]] + c[ab[1]]\n\treturn d" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) diff --git a/test/test_qlassf_matrix.py b/test/test_qlassf_matrix.py index 1671e0b3..6a6f9a58 100644 --- a/test/test_qlassf_matrix.py +++ b/test/test_qlassf_matrix.py @@ -13,13 +13,11 @@ # limitations under the License. import unittest -from typing import Tuple from parameterized import parameterized_class from sympy import Symbol, symbols -from sympy.logic import ITE, And, Not, Or, false, simplify_logic, true -from qlasskit import QlassF, exceptions, qlassf +from qlasskit import qlassf from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, compute_and_compare_results @@ -44,7 +42,10 @@ def test_matrix_const_2x3(self): compute_and_compare_results(self, qf) def test_matrix_const_3x2(self): - f = "def test() -> Qmatrix[bool, 3, 2]:\n\treturn [[True, True], [True, False], [True, False]]" + f = ( + "def test() -> Qmatrix[bool, 3, 2]:\n\treturn [[True, True], [True, False], " + "[True, False]]" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) @@ -57,22 +58,34 @@ def test_matrix_access(self): compute_and_compare_results(self, qf) def test_matrix_iterator_var(self): - f = "def test(a: Qmatrix[Qint2, 2, 2]) -> Qint2:\n\tc = 0\n\tfor x in a:\n\t\tfor y in x:\n\t\t\tc += y\n\treturn c" + f = ( + "def test(a: Qmatrix[Qint2, 2, 2]) -> Qint2:\n\tc = 0\n\tfor x in a:\n" + "\t\tfor y in x:\n\t\t\tc += y\n\treturn c" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_matrix_iterator_list(self): - f = "def test(a: Qint2) -> Qint2:\n\tc = 0\n\tfor x in [[1,2],[3,4]]:\n\t\tfor y in x:\n\t\t\tc += y + a\n\treturn c" + f = ( + "def test(a: Qint2) -> Qint2:\n\tc = 0\n\tfor x in [[1,2],[3,4]]:\n" + "\t\tfor y in x:\n\t\t\tc += y + a\n\treturn c" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_matrix_iterator_varlist(self): - f = "def test(a: Qint2) -> Qint2:\n\tc = [[1,2],[3,4]]\n\tfor x in c:\n\t\tfor y in x:\n\t\t\ta += y\n\treturn a" + f = ( + "def test(a: Qint2) -> Qint2:\n\tc = [[1,2],[3,4]]\n\tfor x in c:\n" + "\t\tfor y in x:\n\t\t\ta += y\n\treturn a" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_matrix_len(self): - f = "def test(a: Qmatrix[Qint2, 2, 2]) -> Qint2:\n\tc = 0\n\tfor x in range(len(a)):\n\t\tc += a[x][0]\n\treturn c" + f = ( + "def test(a: Qmatrix[Qint2, 2, 2]) -> Qint2:\n\tc = 0\n" + "\tfor x in range(len(a)):\n\t\tc += a[x][0]\n\treturn c" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) @@ -86,7 +99,8 @@ def test_matrix_len(self): # if self.compiler == "internal": # return - # f = "def test(ab: Tuple[Qint2, Qint2]) -> Qint2:\n\tc = [1,2,3,2]\n\tai,bi = ab\n\td = c[ai] + c[bi]\n\treturn d" + # f = ("def test(ab: Tuple[Qint2, Qint2]) -> Qint2:\n\tc = [1,2,3,2]\n\tai,bi = ab\n" + # "\td = c[ai] + c[bi]\n\treturn d") # qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) # compute_and_compare_results(self, qf) @@ -95,6 +109,7 @@ def test_matrix_len(self): # if self.compiler == "internal": # return - # f = "def test(ab: Tuple[Qint2, Qint2]) -> Qint2:\n\tc = [1,2,3,2]\n\td = c[ab[0]] + c[ab[1]]\n\treturn d" + # f = ("def test(ab: Tuple[Qint2, Qint2]) -> Qint2:\n\tc = [1,2,3,2]\n" + # "\td = c[ab[0]] + c[ab[1]]\n\treturn d") # qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) # compute_and_compare_results(self, qf) diff --git a/test/test_qlassf_tuple.py b/test/test_qlassf_tuple.py index c16a020f..783f0171 100644 --- a/test/test_qlassf_tuple.py +++ b/test/test_qlassf_tuple.py @@ -13,13 +13,12 @@ # limitations under the License. import unittest -from typing import Tuple from parameterized import parameterized_class -from sympy import Symbol, symbols, sympify -from sympy.logic import ITE, And, Not, Or, false, simplify_logic, true +from sympy import Symbol, symbols +from sympy.logic import And -from qlasskit import QlassF, exceptions, qlassf +from qlasskit import qlassf from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, compute_and_compare_results @@ -52,16 +51,19 @@ def test_tuple_item_swap(self): compute_and_compare_results(self, qf) def test_tuple_ite(self): - f = "def test(b: bool, a: Tuple[bool, bool]) -> Tuple[bool,bool]:\n\treturn (a[1],a[0]) if b else a" + f = ( + "def test(b: bool, a: Tuple[bool, bool]) -> Tuple[bool,bool]:\n" + "\treturn (a[1],a[0]) if b else a" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_tuple_arg_assign(self): f = ( "def test(a: Tuple[bool, bool]) -> bool:\n" - + "\tb = a[0]\n" - + "\tc = a[1]\n" - + "\treturn b and c" + "\tb = a[0]\n" + "\tc = a[1]\n" + "\treturn b and c" ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) @@ -70,7 +72,10 @@ def test_tuple_arg_assign(self): compute_and_compare_results(self, qf) def test_tuple_of_tuple_arg(self): - f = "def test(a: Tuple[Tuple[bool, bool], bool]) -> bool:\n\treturn a[0][0] and a[0][1] and a[1]" + f = ( + "def test(a: Tuple[Tuple[bool, bool], bool]) -> bool:\n" + "\treturn a[0][0] and a[0][1] and a[1]" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) @@ -165,7 +170,10 @@ def test_tuple_int_compare(self): compute_and_compare_results(self, qf) def test_tuple_iterator_var(self): - f = "def test(a: Tuple[Qint2, Qint2]) -> Qint2:\n\tc = 0\n\tfor x in a:\n\t\tc += x\n\treturn c" + f = ( + "def test(a: Tuple[Qint2, Qint2]) -> Qint2:\n\tc = 0\n\tfor x in a:\n" + "\t\tc += x\n\treturn c" + ) qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) diff --git a/test/test_types.py b/test/test_types.py index 3922163a..90ffc547 100644 --- a/test/test_types.py +++ b/test/test_types.py @@ -15,14 +15,9 @@ import unittest from typing import Tuple -from parameterized import parameterized_class -from sympy import And, Not, Symbol - -from qlasskit import Qint2, Qint4, Qlist, qlassf +from qlasskit import Qint2, Qint4, Qlist from qlasskit.types import format_outcome, interpret_as_qtype -from .utils import ENABLED_COMPILERS - class TestTypes_format_outcome(unittest.TestCase): def test_format_outcome_str(self): diff --git a/test/utils.py b/test/utils.py index f8d3212b..8e7fdb5b 100644 --- a/test/utils.py +++ b/test/utils.py @@ -17,13 +17,13 @@ import os import random import threading -from typing import Tuple, get_args +from typing import get_args from qiskit import QuantumCircuit, transpile from qiskit_aer import Aer from sympy.logic.boolalg import gateinputcount -from qlasskit import Qint, QlassF, Qtype, compiler, const_to_qtype +from qlasskit import Qint, Qtype, const_to_qtype from qlasskit.qcircuit import CNotSim, GateNotSimulableException COMPILATION_ENABLED = True @@ -31,14 +31,14 @@ ENABLED_COMPILERS = [("internal",)] try: - import tweedledum + import tweedledum # noqa: F401 ENABLED_COMPILERS.append(("tweedledum",)) except: pass try: - from pyqrack import qrack_simulator + from pyqrack import qrack_simulator # noqa: F401 from qiskit.providers.qrack import Qrack qsk_simulator = Qrack.get_backend("qasm_simulator") @@ -97,20 +97,15 @@ def qiskit_measure_and_count(circ, shots=1): return counts -def compute_result_of_qcircuit(cls, qf, truth_line): +def compute_result_of_qcircuit(cls, qf, truth_line): # noqa: C901 """Simulate the quantum circuit for a given truth_line containing inputs""" circ = qf.circuit() gate = qf.gate() qc = QuantumCircuit(gate.num_qubits) + res_str = "" - # Prepare inputs [qc.initialize(1 if truth_line[i] else 0, i) for i in range(qf.input_size)] - qc.append(gate, list(range(qf.num_qubits))) - - # print(qc.decompose().draw("text")) - - # Measure counts = qiskit_measure_and_count(qc) res = list(counts.keys())[0][::-1] @@ -118,7 +113,6 @@ def compute_result_of_qcircuit(cls, qf, truth_line): if len(res) < qc.num_qubits: res += "0" * (qc.num_qubits - len(res)) - res_str = "" for qname in qf.truth_table_header()[-qf.output_size :]: res_str += res[circ.qubit_map[qname]] @@ -141,7 +135,7 @@ def compute_result_of_qcircuit_using_cnotsim(cls, qf, truth_line): return res_str -def compute_result_of_originalf(cls, qf, truth_line): +def compute_result_of_originalf(cls, qf, truth_line): # noqa: C901 """Compute the result of originalf for a given truth_line containing inputs""" def truth_to_arg(truth, i, argtt): @@ -162,11 +156,11 @@ def truth_to_arg(truth, i, argtt): def res_to_str(res): """Translate res to a binary string""" - if type(res) == bool: + if type(res) is bool: return "1" if res else "0" - elif type(res) == tuple or type(res) == list: + elif type(res) is tuple or type(res) is list: return "".join([res_to_str(x) for x in res]) - elif type(res) == int: + elif type(res) is int: qc = const_to_qtype(res) try: qi = qf.returns.ttype.from_bool(qc[1]) diff --git a/tox.ini b/tox.ini index 67da42b5..82a360bd 100644 --- a/tox.ini +++ b/tox.ini @@ -45,6 +45,7 @@ deps = flake8 commands = flake8 ./qlasskit + flake8 ./test [testenv:isort] deps = @@ -56,7 +57,7 @@ commands = [testenv:black] deps = ; {[testenv]deps} - black + black[jupyter] commands = black .