From 81c9e3167b116ab43a3d4ca244fbbccca0ba40cf Mon Sep 17 00:00:00 2001 From: dhruvbhq Date: Sun, 27 Jun 2021 12:23:57 +0530 Subject: [PATCH] Fixed issue 6612 by covering ibmq examples by lint check --- Make.bat | 3 +++ Makefile | 2 +- examples/__init__.py | 13 +++++++++++++ examples/python/__init__.py | 13 +++++++++++++ examples/python/commutation_relation.py | 5 +++++ examples/python/ibmq/__init__.py | 14 ++++++++++++++ examples/python/ibmq/hello_quantum.py | 8 +++++--- examples/python/ibmq/using_qiskit_terra_level_0.py | 6 +++--- examples/python/ibmq/using_qiskit_terra_level_1.py | 3 ++- examples/python/ibmq/using_qiskit_terra_level_2.py | 4 +++- tox.ini | 1 + 11 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 examples/__init__.py create mode 100644 examples/python/__init__.py create mode 100644 examples/python/ibmq/__init__.py diff --git a/Make.bat b/Make.bat index 0380960e70bd..09c85f9d0b21 100644 --- a/Make.bat +++ b/Make.bat @@ -42,6 +42,9 @@ GOTO :next :lint pylint qiskit test +python "tools/verify_headers.py" qiskit test tools examples +pylint -rn --disable="C0103, W0621, E0611, E0401" examples +python "tools/find_optional_imports.py" IF errorlevel 9009 GOTO :error GOTO :next diff --git a/Makefile b/Makefile index 8d780de74b91..12c0278ac8c9 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ env: lint: pylint -rn qiskit test tools tools/verify_headers.py qiskit test tools examples - pylint -rn --disable='C0103, C0114, W0621' examples/python/*.py + pylint -rn --disable='C0103, W0621, E0611, E0401' examples tools/find_optional_imports.py style: diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 000000000000..eb8a3648ab14 --- /dev/null +++ b/examples/__init__.py @@ -0,0 +1,13 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2017. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +"""Simple examples to demonstrate the usage of Qiskit Terra.""" diff --git a/examples/python/__init__.py b/examples/python/__init__.py new file mode 100644 index 000000000000..eb8a3648ab14 --- /dev/null +++ b/examples/python/__init__.py @@ -0,0 +1,13 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2017. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +"""Simple examples to demonstrate the usage of Qiskit Terra.""" diff --git a/examples/python/commutation_relation.py b/examples/python/commutation_relation.py index 6dd71981fa20..a4cb11827d48 100644 --- a/examples/python/commutation_relation.py +++ b/examples/python/commutation_relation.py @@ -10,6 +10,11 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. +""" +Example showing how to cancel redundant gates in a quantum circuit using +Qiskit. +""" + from qiskit import QuantumCircuit from qiskit.transpiler import PassManager diff --git a/examples/python/ibmq/__init__.py b/examples/python/ibmq/__init__.py new file mode 100644 index 000000000000..d4769813f80b --- /dev/null +++ b/examples/python/ibmq/__init__.py @@ -0,0 +1,14 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2017. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +"""Simple examples to demonstrate the usage of Qiskit Terra on the remote IBMQ +provider.""" diff --git a/examples/python/ibmq/hello_quantum.py b/examples/python/ibmq/hello_quantum.py index 63affd35cbbb..23ba74d4e05e 100644 --- a/examples/python/ibmq/hello_quantum.py +++ b/examples/python/ibmq/hello_quantum.py @@ -13,9 +13,11 @@ """Example used in the README. In this example a Bell state is made.""" # Import Qiskit +import sys from qiskit import QuantumCircuit from qiskit import execute, IBMQ, BasicAer from qiskit.providers.ibmq import least_busy +from qiskit.providers.ibmq.exceptions import IBMQProviderError, IBMQAccountCredentialsNotFound # Create a Quantum Circuit qc = QuantumCircuit(2, 2) @@ -42,13 +44,13 @@ # Authenticate for access to remote backends try: provider = IBMQ.load_account() -except: +except IBMQAccountCredentialsNotFound: print( """WARNING: No valid IBMQ credentials found on disk. You must store your credentials using IBMQ.save_account(token, url). For now, there's only access to local simulator backends...""" ) - exit(0) + sys.exit() # see a list of available remote backends ibmq_backends = provider.backends() @@ -60,7 +62,7 @@ least_busy_device = least_busy( provider.backends(filters=lambda x: x.configuration().n_qubits >= 2, simulator=False) ) -except: +except IBMQProviderError: print("All devices are currently unavailable.") print("Running on current least busy device: ", least_busy_device) diff --git a/examples/python/ibmq/using_qiskit_terra_level_0.py b/examples/python/ibmq/using_qiskit_terra_level_0.py index 49a8c137104b..90ca5a4edcf8 100644 --- a/examples/python/ibmq/using_qiskit_terra_level_0.py +++ b/examples/python/ibmq/using_qiskit_terra_level_0.py @@ -16,18 +16,18 @@ 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 from qiskit import execute, IBMQ, BasicAer from qiskit.providers.ibmq import least_busy from qiskit.tools.monitor import job_monitor +from qiskit.providers.ibmq.exceptions import IBMQProviderError provider = IBMQ.load_account() @@ -64,7 +64,7 @@ try: # select least busy available device and execute. least_busy_device = least_busy(provider.backends(simulator=False)) -except: +except IBMQProviderError: print("All devices are currently unavailable.") print("Running on current least busy device: ", least_busy_device) diff --git a/examples/python/ibmq/using_qiskit_terra_level_1.py b/examples/python/ibmq/using_qiskit_terra_level_1.py index 1722b367e1bc..ffb3d23cb25e 100644 --- a/examples/python/ibmq/using_qiskit_terra_level_1.py +++ b/examples/python/ibmq/using_qiskit_terra_level_1.py @@ -33,6 +33,7 @@ from qiskit.compiler import transpile, assemble from qiskit.providers.ibmq import least_busy from qiskit.tools.monitor import job_monitor +from qiskit.providers.ibmq.exceptions import IBMQProviderError provider = IBMQ.load_account() @@ -63,7 +64,7 @@ try: # select least busy available device and execute. least_busy_device = least_busy(provider.backends(simulator=False)) -except: +except IBMQProviderError: print("All devices are currently unavailable.") print("Running on current least busy device: ", least_busy_device) diff --git a/examples/python/ibmq/using_qiskit_terra_level_2.py b/examples/python/ibmq/using_qiskit_terra_level_2.py index edf2ff02d1a9..14f42932c51f 100644 --- a/examples/python/ibmq/using_qiskit_terra_level_2.py +++ b/examples/python/ibmq/using_qiskit_terra_level_2.py @@ -35,6 +35,8 @@ from qiskit.transpiler.passes import CXDirection from qiskit.transpiler.passes import LookaheadSwap +from qiskit.providers.ibmq.exceptions import IBMQProviderError + provider = IBMQ.load_account() @@ -68,7 +70,7 @@ try: # select least busy available device and execute. least_busy_device = least_busy(provider.backends(simulator=False)) -except: +except IBMQProviderError: print("All devices are currently unavailable.") print("Running on current least busy device: ", least_busy_device) diff --git a/tox.ini b/tox.ini index 10df4fe1f734..bc95a152b4f9 100644 --- a/tox.ini +++ b/tox.ini @@ -24,6 +24,7 @@ basepython = python3 commands = black --check {posargs} qiskit test tools examples setup.py pylint -rn qiskit test tools + pylint -rn --disable='C0103, W0621, E0611, E0401' examples {toxinidir}/tools/verify_headers.py qiskit test tools examples {toxinidir}/tools/find_optional_imports.py reno lint