Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.
Merged
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
6 changes: 3 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ disable=no-self-use, # disabled as it is too verbose
import-outside-toplevel,
docstring-first-line-empty,
no-name-in-module, # remove when pylint behaves
import-error # remove when pylint behaves

import-error, # remove when pylint behaves
bad-continuation, bad-whitespace, # differences of opinion with black

[REPORTS]

Expand Down Expand Up @@ -212,7 +212,7 @@ max-nested-blocks=5
[FORMAT]

# Maximum number of characters on a single line.
max-line-length=100
max-line-length=105

# Regexp for a line that is allowed to be longer than the limit.
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ mypy:
mypy --module qiskit_ibm_provider

style:
pycodestyle qiskit_ibm_provider test

black --check qiskit_ibm_provider test setup.py docs/tutorials
test:
python -m unittest -v

Expand All @@ -37,3 +36,6 @@ test3:

runtime_integration:
python -m unittest -v test/ibm/runtime/test_runtime_integration.py

black:
black qiskit_ibm_provider test setup.py docs/tutorials
28 changes: 17 additions & 11 deletions docs/tutorials/1_the_ibm_quantum_account.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"source": [
"from qiskit_ibm_provider import IBMProvider\n",
"\n",
"# IBMProvider.save_account(TOKEN)\n"
"# IBMProvider.save_account(TOKEN)"
]
},
{
Expand Down Expand Up @@ -135,7 +135,7 @@
],
"source": [
"provider = IBMProvider()\n",
"provider\n"
"provider"
]
},
{
Expand Down Expand Up @@ -216,7 +216,7 @@
}
],
"source": [
"backend = provider.get_backend('ibmq_armonk')\n",
"backend = provider.get_backend(\"ibmq_armonk\")\n",
"backend"
]
},
Expand Down Expand Up @@ -774,6 +774,7 @@
"source": [
"props = backend.properties()\n",
"\n",
"\n",
"def describe_qubit(qubit, properties):\n",
" \"\"\"Print a string describing some of reported properties of the given qubit.\"\"\"\n",
"\n",
Expand All @@ -782,12 +783,15 @@
" ns = 1e9\n",
" GHz = 1e-9\n",
"\n",
" print(f\"Qubit {qubit} has a \\n\"\n",
" f\" - T1 time of {properties.t1(qubit)} microseconds\\n\"\n",
" f\" - T2 time of {properties.t2(qubit)} microseconds\\n\"\n",
" f\" - SX gate error of {properties.gate_error('sx', qubit)}\\n\"\n",
" f\" - SX gate duration of {properties.gate_length('sx', qubit)*ns} nanoseconds\\n\"\n",
" f\" - resonant frequency of {properties.frequency(qubit) * GHz} GHz\")\n",
" print(\n",
" f\"Qubit {qubit} has a \\n\"\n",
" f\" - T1 time of {properties.t1(qubit)} microseconds\\n\"\n",
" f\" - T2 time of {properties.t2(qubit)} microseconds\\n\"\n",
" f\" - SX gate error of {properties.gate_error('sx', qubit)}\\n\"\n",
" f\" - SX gate duration of {properties.gate_length('sx', qubit)*ns} nanoseconds\\n\"\n",
" f\" - resonant frequency of {properties.frequency(qubit) * GHz} GHz\"\n",
" )\n",
"\n",
"\n",
"describe_qubit(0, props)"
]
Expand Down Expand Up @@ -1164,8 +1168,8 @@
"metadata": {},
"outputs": [],
"source": [
"backend = provider.get_backend('ibmq_qasm_simulator')\n",
"circs = transpile([circuit]*50, backend=backend)\n",
"backend = provider.get_backend(\"ibmq_qasm_simulator\")\n",
"circs = transpile([circuit] * 50, backend=backend)\n",
"\n",
"# Submit them all to the backend\n",
"job = backend.run(circs, max_circuits_per_job=10)"
Expand Down Expand Up @@ -1412,6 +1416,7 @@
],
"source": [
"from qiskit_ibm_provider.version import __version__\n",
"\n",
"print(\"qiskit-ibm-provider version: {}\".format(__version__))"
]
},
Expand Down Expand Up @@ -1448,6 +1453,7 @@
],
"source": [
"import qiskit.tools.jupyter\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
]
Expand Down
121 changes: 64 additions & 57 deletions docs/tutorials/2_jupyter_tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,17 @@
"outputs": [],
"source": [
"from qiskit_ibm_provider import least_busy\n",
"backend = least_busy(provider.backends(simulator=False, filters=lambda b: b.configuration().n_qubits >= 5))\n",
"\n",
"backend = least_busy(\n",
" provider.backends(\n",
" simulator=False, filters=lambda b: b.configuration().n_qubits >= 5\n",
" )\n",
")\n",
"\n",
"qc = QuantumCircuit(2, 2)\n",
"qc.h(0)\n",
"qc.cx(0, 1)\n",
"qc.measure([0,1], [0,1])\n",
"qc.measure([0, 1], [0, 1])\n",
"\n",
"mapped_circuit = transpile(qc, backend=backend)\n",
"job = backend.run(mapped_circuit, shots=1024)"
Expand Down Expand Up @@ -301,64 +306,66 @@
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-10T11:28:28.529479Z",
"start_time": "2019-08-10T11:28:28.521774Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"qiskit-ibm-provider version: 0.1.0\n"
]
}
],
"source": [
"from qiskit_ibm_provider.version import __version__\n",
"print(\"qiskit-ibm-provider version: {}\".format(__version__))"
]
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-10T11:28:28.529479Z",
"start_time": "2019-08-10T11:28:28.521774Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"qiskit-ibm-provider version: 0.1.0\n"
]
}
],
"source": [
"from qiskit_ibm_provider.version import __version__\n",
"\n",
"print(\"qiskit-ibm-provider version: {}\".format(__version__))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<h3>Version Information</h3><table><tr><th>Qiskit Software</th><th>Version</th></tr><tr><td><code>qiskit-terra</code></td><td>0.18.3</td></tr><tr><td><code>qiskit-aer</code></td><td>0.9.0</td></tr><tr><td><code>qiskit-ignis</code></td><td>0.6.0</td></tr><tr><td><code>qiskit-ibmq-provider (deprecated)</code></td><td>0.17.0</td></tr><tr><td><code>qiskit-aqua (deprecated)</code></td><td>0.9.5</td></tr><tr><td><code>qiskit</code></td><td>0.31.0</td></tr><tr><th>System information</th></tr><tr><td>Python</td><td>3.7.11 (default, Jul 27 2021, 07:03:16) \n",
"[Clang 10.0.0 ]</td></tr><tr><td>OS</td><td>Darwin</td></tr><tr><td>CPUs</td><td>8</td></tr><tr><td>Memory (Gb)</td><td>32.0</td></tr><tr><td colspan='2'>Mon Sep 13 00:15:27 2021 EDT</td></tr></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<h3>Version Information</h3><table><tr><th>Qiskit Software</th><th>Version</th></tr><tr><td><code>qiskit-terra</code></td><td>0.18.3</td></tr><tr><td><code>qiskit-aer</code></td><td>0.9.0</td></tr><tr><td><code>qiskit-ignis</code></td><td>0.6.0</td></tr><tr><td><code>qiskit-ibmq-provider (deprecated)</code></td><td>0.17.0</td></tr><tr><td><code>qiskit-aqua (deprecated)</code></td><td>0.9.5</td></tr><tr><td><code>qiskit</code></td><td>0.31.0</td></tr><tr><th>System information</th></tr><tr><td>Python</td><td>3.7.11 (default, Jul 27 2021, 07:03:16) \n",
"[Clang 10.0.0 ]</td></tr><tr><td>OS</td><td>Darwin</td></tr><tr><td>CPUs</td><td>8</td></tr><tr><td>Memory (Gb)</td><td>32.0</td></tr><tr><td colspan='2'>Mon Sep 13 00:15:27 2021 EDT</td></tr></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
{
"data": {
"text/html": [
"<div style='width: 100%; background-color:#d5d9e0;padding-left: 10px; padding-bottom: 10px; padding-right: 10px; padding-top: 5px'><h3>This code is a part of Qiskit</h3><p>&copy; Copyright IBM 2017, 2021.</p><p>This code is licensed under the Apache License, Version 2.0. You may<br>obtain a copy of this license in the LICENSE.txt file in the root directory<br> of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.<p>Any modifications or derivative works of this code must retain this<br>copyright notice, and modified files need to carry a notice indicating<br>that they have been altered from the originals.</p></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import qiskit.tools.jupyter\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
]
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div style='width: 100%; background-color:#d5d9e0;padding-left: 10px; padding-bottom: 10px; padding-right: 10px; padding-top: 5px'><h3>This code is a part of Qiskit</h3><p>&copy; Copyright IBM 2017, 2021.</p><p>This code is licensed under the Apache License, Version 2.0. You may<br>obtain a copy of this license in the LICENSE.txt file in the root directory<br> of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.<p>Any modifications or derivative works of this code must retain this<br>copyright notice, and modified files need to carry a notice indicating<br>that they have been altered from the originals.</p></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import qiskit.tools.jupyter\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
]
},
{
"cell_type": "code",
Expand Down
32 changes: 19 additions & 13 deletions qiskit_ibm_provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@
setup_logger(logger)

# Constants used by the IBM Quantum logger.
QISKIT_IBM_PROVIDER_LOGGER_NAME = 'qiskit_ibm_provider'
QISKIT_IBM_PROVIDER_LOGGER_NAME = "qiskit_ibm_provider"
"""The name of the IBM Quantum logger."""
QISKIT_IBM_PROVIDER_LOG_LEVEL = 'QISKIT_IBM_PROVIDER_LOG_LEVEL'
QISKIT_IBM_PROVIDER_LOG_LEVEL = "QISKIT_IBM_PROVIDER_LOG_LEVEL"
"""The environment variable name that is used to set the level for the IBM Quantum logger."""
QISKIT_IBM_PROVIDER_LOG_FILE = 'QISKIT_IBM_PROVIDER_LOG_FILE'
QISKIT_IBM_PROVIDER_LOG_FILE = "QISKIT_IBM_PROVIDER_LOG_FILE"
"""The environment variable name that is used to set the file for the IBM Quantum logger."""


def least_busy(
backends: List[Union[Backend, BaseBackend]],
reservation_lookahead: Optional[int] = 60
backends: List[Union[Backend, BaseBackend]],
reservation_lookahead: Optional[int] = 60,
) -> Union[Backend, BaseBackend]:
"""Return the least busy backend from a list.

Expand All @@ -131,27 +131,33 @@ def least_busy(
does not have the ``pending_jobs`` attribute in its status.
"""
if not backends:
raise IBMError('Unable to find the least_busy '
'backend from an empty list.') from None
raise IBMError(
"Unable to find the least_busy " "backend from an empty list."
) from None
try:
candidates = []
now = datetime.now()
for back in backends:
backend_status = back.status()
if not backend_status.operational or backend_status.status_msg != 'active':
if not backend_status.operational or backend_status.status_msg != "active":
continue
if reservation_lookahead and isinstance(back, IBMBackend):
end_time = now + timedelta(minutes=reservation_lookahead)
try:
if back.reservations(now, end_time):
continue
except Exception as err: # pylint: disable=broad-except
logger.warning("Unable to find backend reservation information. "
"It will not be taken into consideration. %s", str(err))
logger.warning(
"Unable to find backend reservation information. "
"It will not be taken into consideration. %s",
str(err),
)
candidates.append(back)
if not candidates:
raise IBMError('No backend matches the criteria.')
raise IBMError("No backend matches the criteria.")
return min(candidates, key=lambda b: b.status().pending_jobs)
except AttributeError as ex:
raise IBMError('A backend in the list does not have the `pending_jobs` '
'attribute in its status.') from ex
raise IBMError(
"A backend in the list does not have the `pending_jobs` "
"attribute in its status."
) from ex
2 changes: 1 addition & 1 deletion qiskit_ibm_provider/api/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

"""IBM Quantum API clients."""

from .base import BaseClient, WebsocketClientCloseCode
from .account import AccountClient
from .auth import AuthClient
from .base import BaseClient, WebsocketClientCloseCode
from .version import VersionClient
from .websocket import WebsocketClient
Loading