Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With more things being added here, it would be nice to switch to using the verbose names - I can't tell at a glance what's being disabled here.

tools/find_optional_imports.py

style:
Expand Down
13 changes: 13 additions & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -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."""
13 changes: 13 additions & 0 deletions examples/python/__init__.py
Original file line number Diff line number Diff line change
@@ -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."""
Comment on lines +1 to +13
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples directory isn't a Python package - it's just a collection of scripts - so it shouldn't be made into a package. Doing things like this has surprising effects (mostly this is Python's fault), because editable (developer) installs of Terra will now end up making examples an importable package whenever you open a Python interpreter. That means you wouldn't be able to access a package with that actual name any more (for example https://pypi.org/project/examples/).

(There are ways in our repository structure we can mitigate this, but really the issue is that this shouldn't be a package.)

5 changes: 5 additions & 0 deletions examples/python/commutation_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions examples/python/ibmq/__init__.py
Original file line number Diff line number Diff line change
@@ -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."""
Comment on lines +1 to +14
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, this shouldn't be in a package, because the examples aren't modules, they're scripts.

8 changes: 5 additions & 3 deletions examples/python/ibmq/hello_quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions examples/python/ibmq/using_qiskit_terra_level_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion examples/python/ibmq/using_qiskit_terra_level_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion examples/python/ibmq/using_qiskit_terra_level_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down