From f0c833199d52a3d04b36b0109a1b15a31e77f230 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 4 May 2020 09:44:43 -0400 Subject: [PATCH] lint in the example files (#4363) Co-authored-by: Jay Gambetta --- Makefile | 1 + examples/python/commutation_relation.py | 10 +++++----- examples/python/load_qasm.py | 2 +- examples/python/rippleadd.py | 6 +++--- examples/python/stochastic_swap.py | 4 ++-- examples/python/using_qiskit_terra_level_0.py | 12 +++++------- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 0b38c2760c98..9b626cb9996c 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,7 @@ env: # Ignoring generated ones with .py extension. lint: pylint -rn qiskit test + pylint -rn --disable='C0103, C0114, W0621' examples/python/*.py style: pycodestyle --max-line-length=100 qiskit test diff --git a/examples/python/commutation_relation.py b/examples/python/commutation_relation.py index 3674a3786fba..0547fa072e22 100644 --- a/examples/python/commutation_relation.py +++ b/examples/python/commutation_relation.py @@ -12,7 +12,7 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -from qiskit import * +from qiskit import QuantumCircuit from qiskit.transpiler import PassManager from qiskit.transpiler.passes import CommutationAnalysis, CommutativeCancellation @@ -22,18 +22,18 @@ circuit.cx(0, 1) circuit.cx(2, 1) circuit.cx(4, 3) -circuit.cx(2, 3) +circuit.cx(2, 3) circuit.z(0) circuit.z(4) circuit.cx(0, 1) circuit.cx(2, 1) circuit.cx(4, 3) -circuit.cx(2, 3) -circuit.cx(3, 2) +circuit.cx(2, 3) +circuit.cx(3, 2) print(circuit) pm = PassManager() pm.append([CommutationAnalysis(), CommutativeCancellation()]) -new_circuit=pm.run(circuit) +new_circuit = pm.run(circuit) print(new_circuit) diff --git a/examples/python/load_qasm.py b/examples/python/load_qasm.py index b7ae33179d87..ab5a3cf52f6e 100644 --- a/examples/python/load_qasm.py +++ b/examples/python/load_qasm.py @@ -15,7 +15,7 @@ """Example on how to load a file into a QuantumCircuit.""" from qiskit import QuantumCircuit -from qiskit import QiskitError, execute, BasicAer +from qiskit import execute, BasicAer circ = QuantumCircuit.from_qasm_file("examples/qasm/entangled_registers.qasm") print(circ) diff --git a/examples/python/rippleadd.py b/examples/python/rippleadd.py index 77fab8c755c9..c0fe3a4edd5e 100644 --- a/examples/python/rippleadd.py +++ b/examples/python/rippleadd.py @@ -25,7 +25,7 @@ # Set the backend name and coupling map. ############################################################### backend = BasicAer.get_backend("qasm_simulator") -coupling_map = [[0,1], [0, 8], [1, 2], [1, 9], [2, 3], [2, 10], [3, 4], [3, 11], +coupling_map = [[0, 1], [0, 8], [1, 2], [1, 9], [2, 3], [2, 10], [3, 4], [3, 11], [4, 5], [4, 12], [5, 6], [5, 13], [6, 7], [6, 14], [7, 15], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]] @@ -38,7 +38,7 @@ b = QuantumRegister(n, "b") cin = QuantumRegister(1, "cin") cout = QuantumRegister(1, "cout") -ans = ClassicalRegister(n+1, "ans") +ans = ClassicalRegister(n + 1, "ans") qc = QuantumCircuit(a, b, cin, cout, ans, name="rippleadd") @@ -69,7 +69,7 @@ def unmajority(p, a, b, c): # Set the inputs to the adder qc.x(a[0]) # Set input a = 0...0001 -qc.x(b) # Set input b = 1...1111 +qc.x(b) # Set input b = 1...1111 # Apply the adder qc += adder_subcircuit # Measure the output register in the computational basis diff --git a/examples/python/stochastic_swap.py b/examples/python/stochastic_swap.py index 15833b49fd6a..07a6f17a6c30 100644 --- a/examples/python/stochastic_swap.py +++ b/examples/python/stochastic_swap.py @@ -15,8 +15,8 @@ """Example of using the StochasticSwap pass.""" from qiskit.transpiler.passes import StochasticSwap -from qiskit.transpiler import CouplingMap, Layout -from qiskit.converters import circuit_to_dag, dag_to_circuit +from qiskit.transpiler import CouplingMap +from qiskit.converters import circuit_to_dag from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit coupling = CouplingMap([[0, 1], [1, 2], [1, 3]]) diff --git a/examples/python/using_qiskit_terra_level_0.py b/examples/python/using_qiskit_terra_level_0.py index ff794537b2bd..82bdc3a27c38 100644 --- a/examples/python/using_qiskit_terra_level_0.py +++ b/examples/python/using_qiskit_terra_level_0.py @@ -18,27 +18,25 @@ This example shows the most basic way to user Terra. It builds some circuits and runs them on both the BasicAer (local Qiskit provider) or IBMQ (remote IBMQ provider). -To control the compile parameters we have provided a transpile function which can be used +To control the compile parameters we have provided a transpile function which can be used as a level 1 user. """ -import time - # Import the Qiskit modules -from qiskit import QuantumCircuit, QiskitError +from qiskit import QuantumCircuit from qiskit import execute, BasicAer # making first circuit: bell state qc1 = QuantumCircuit(2, 2) qc1.h(0) qc1.cx(0, 1) -qc1.measure([0,1], [0,1]) +qc1.measure([0, 1], [0, 1]) # making another circuit: superpositions qc2 = QuantumCircuit(2, 2) -qc2.h([0,1]) -qc2.measure([0,1], [0,1]) +qc2.h([0, 1]) +qc2.measure([0, 1], [0, 1]) # setting up the backend print("(BasicAER Backends)")