Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IBMBackend.run() #1138

Merged
merged 70 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
2ff792e
initial support for backend.run()
merav-aharoni Oct 9, 2023
c877f1e
Added temporary session support
merav-aharoni Oct 9, 2023
cb4c0b0
Merge branch 'main' into backend_run
merav-aharoni Oct 9, 2023
af9f907
Copied test_backend.py from the provider
merav-aharoni Oct 10, 2023
7ce7531
Merge branch 'main' of github.com:merav-aharoni/qiskit-ibm-runtime in…
merav-aharoni Oct 10, 2023
cc6d58a
Merge branch 'backend_run' of github.com:merav-aharoni/qiskit-ibm-run…
merav-aharoni Oct 10, 2023
7867c17
Added all status types from the provider
merav-aharoni Oct 10, 2023
0c4e0cb
Added test_ibm_job_states.py from provider. Added 'transpiler' direct…
merav-aharoni Oct 10, 2023
17c4ec2
lint
merav-aharoni Oct 10, 2023
7b9f6cc
black
merav-aharoni Oct 10, 2023
aab2a87
lint
merav-aharoni Oct 10, 2023
71cb86d
Added integration tests from the provider
merav-aharoni Oct 12, 2023
0878511
Merge branch 'main' into backend_run
merav-aharoni Oct 12, 2023
d0a5a5b
added test_ibm_job and made necessary changes
merav-aharoni Oct 15, 2023
e99cd2e
Merge branch 'backend_run' of github.com:merav-aharoni/qiskit-ibm-run…
merav-aharoni Oct 15, 2023
8ca95c5
Fixed several tests
merav-aharoni Oct 16, 2023
b17413b
Fixed missing job methods in test
merav-aharoni Oct 16, 2023
2a95e9b
Changed exception type
merav-aharoni Oct 16, 2023
40917a4
Added test_ibm_job_attributes.py
merav-aharoni Oct 16, 2023
d117151
Added test_ibm_job_attributes.py that was missed in previous commit
merav-aharoni Oct 17, 2023
e72524d
Added test class TestBackendRunInSession for backend.run with session
merav-aharoni Oct 17, 2023
03c8fb8
Cleaning up code
merav-aharoni Oct 17, 2023
ac1e464
lint, added missing parameter
merav-aharoni Oct 17, 2023
e5ac535
Merge branch 'main' into backend_run
merav-aharoni Oct 17, 2023
ef7b314
Merge branch 'main' into backend_run
merav-aharoni Oct 19, 2023
535c875
Added more tests from qiskit-ibm-provider
merav-aharoni Oct 19, 2023
f173124
Inherit from BaseQiskitTestCase
merav-aharoni Oct 19, 2023
21103e6
Merge branch 'backend_run' of github.com:merav-aharoni/qiskit-ibm-run…
merav-aharoni Oct 19, 2023
757af8e
Enabled several tests
merav-aharoni Oct 19, 2023
862723e
removed method _deprecate_id_instruction
merav-aharoni Oct 22, 2023
3697ec3
lint, unused imports
merav-aharoni Oct 22, 2023
373ace1
Merge branch 'main' into backend_run
merav-aharoni Oct 22, 2023
b74f848
Merge branch 'main' into backend_run
kt474 Oct 24, 2023
b9dcf5e
Merge branch 'main' into backend_run
merav-aharoni Oct 26, 2023
e98456b
Removed instance parameter from tests with backend.run()
merav-aharoni Oct 26, 2023
3806d0a
Removed instance from decorator
merav-aharoni Oct 26, 2023
191837e
Changed test to run on quantum channel only
merav-aharoni Oct 26, 2023
ddcc326
Removed instance parameter when getting backend
merav-aharoni Oct 26, 2023
2f24d01
lint
merav-aharoni Oct 26, 2023
f900340
Copied transpiler directory from the provider
merav-aharoni Oct 26, 2023
60c5ecd
black
merav-aharoni Oct 26, 2023
c3b8b79
Merge branch 'main' into backend_run
merav-aharoni Oct 26, 2023
5906284
fix more tests
kt474 Oct 27, 2023
9b8d4aa
update test_session
kt474 Oct 27, 2023
064a8c0
added tranpiler passes entry point
merav-aharoni Oct 29, 2023
f53e227
Merge branch 'backend_run' of github.com:merav-aharoni/qiskit-ibm-run…
merav-aharoni Oct 29, 2023
15daa81
Merge branch 'main' into backend_run
merav-aharoni Oct 29, 2023
7d1c885
Removed obsolete JobStatus types, and removed the tests that were che…
merav-aharoni Oct 29, 2023
99c27f0
Removed unnecessary check
merav-aharoni Oct 29, 2023
37f2bf1
Merge branch 'backend_run' of github.com:merav-aharoni/qiskit-ibm-run…
merav-aharoni Oct 29, 2023
ebf5647
Removed exception parameter from validate_job_tags. Use 'import_job_t…
merav-aharoni Oct 29, 2023
349e12d
Put back the check if circuit is indeed of type 'QuantumCircuit'. Upd…
merav-aharoni Oct 29, 2023
db9afb4
Update qiskit_ibm_runtime/ibm_backend.py
merav-aharoni Oct 31, 2023
7bb3447
Cleaned up code involving session setup
merav-aharoni Oct 31, 2023
bdbcdae
Removed setting of 'skip_transpilation' because set by default by Qasm3
merav-aharoni Oct 31, 2023
c13d879
Replaced in path 'qiskit-ibm-provider' with 'qiskit-ibm-runtime'.
merav-aharoni Oct 31, 2023
9f9c099
Added None to get() statement
merav-aharoni Oct 31, 2023
bd10133
Merge branch 'main' into backend_run
kt474 Oct 31, 2023
f3b295e
Merge branch 'main' into backend_run
merav-aharoni Nov 2, 2023
b78acfc
Changed warning to error when init_circuit is boolean
merav-aharoni Nov 6, 2023
7a53693
Merge branch 'backend_run' of github.com:merav-aharoni/qiskit-ibm-run…
merav-aharoni Nov 6, 2023
f85c85c
Merge branch 'main' into backend_run
merav-aharoni Nov 6, 2023
c004bbb
Fixed setting of start_session
merav-aharoni Nov 6, 2023
e6022c2
Removed max_time parameter, because wasn't reaching the server.
merav-aharoni Nov 6, 2023
db9534c
Merge branch 'main' into backend_run
kt474 Nov 6, 2023
7dbe1d4
Release note
merav-aharoni Nov 7, 2023
4edc1d4
Merge branch 'backend_run' of github.com:merav-aharoni/qiskit-ibm-run…
merav-aharoni Nov 7, 2023
9c71052
Merge branch 'main' into backend_run
merav-aharoni Nov 7, 2023
47c5ceb
Merge branch 'main' into backend_run
kt474 Nov 7, 2023
12fa82f
address comment
kt474 Nov 7, 2023
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
318 changes: 308 additions & 10 deletions qiskit_ibm_runtime/ibm_backend.py

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions qiskit_ibm_runtime/qiskit_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from qiskit_ibm_provider.utils.backend_decoder import configuration_from_server_data
from qiskit_ibm_runtime import ibm_backend

from .utils.utils import validate_job_tags
from .accounts import AccountManager, Account, ChannelType
from .api.clients import AuthClient, VersionClient
from .api.clients.runtime import RuntimeClient
Expand Down Expand Up @@ -1344,6 +1345,8 @@ def jobs(
"The 'instance' keyword is only supported for ``ibm_quantum`` runtime."
)
hub, group, project = from_instance_format(instance)
if job_tags:
validate_job_tags(job_tags)

job_responses = [] # type: List[Dict[str, Any]]
current_page_limit = limit or 20
Expand Down
10 changes: 5 additions & 5 deletions qiskit_ibm_runtime/runtime_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
from qiskit.providers.job import JobV1 as Job

# pylint: disable=unused-import,cyclic-import
from qiskit_ibm_provider.utils import validate_job_tags, utc_to_local
from qiskit_ibm_provider.utils import utc_to_local
from qiskit_ibm_runtime import qiskit_runtime_service

from .utils.utils import validate_job_tags
from .constants import API_TO_JOB_ERROR_MESSAGE, API_TO_JOB_STATUS, DEFAULT_DECODERS
from .exceptions import (
IBMApiError,
Expand All @@ -40,12 +41,10 @@
RuntimeJobMaxTimeoutError,
)
from .program.result_decoder import ResultDecoder
from .utils import RuntimeDecoder
from .api.clients import RuntimeClient, RuntimeWebsocketClient, WebsocketClientCloseCode
from .exceptions import IBMError
from .api.exceptions import RequestsApiError
from .api.client_parameters import ClientParameters
from .utils.utils import CallableStr

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -419,7 +418,7 @@ def update_tags(self, new_tags: List[str]) -> List[str]:
with the server or updating the job tags.
"""
tags_to_update = set(new_tags)
validate_job_tags(new_tags, RuntimeInvalidStateError)
validate_job_tags(new_tags)

response = self._api_client.update_tags(job_id=self.job_id(), tags=list(tags_to_update))

Expand Down Expand Up @@ -575,7 +574,8 @@ def _stream_results(
traceback.format_exc(),
)

def _empty_result_queue(self, result_queue: queue.Queue) -> None:
@staticmethod
def _empty_result_queue(result_queue: queue.Queue) -> None:
"""Empty the result queue.

Args:
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/runtime_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def validate(self, channel: str) -> None:
)

if self.job_tags:
validate_job_tags(self.job_tags, IBMInputValueError)
validate_job_tags(self.job_tags)
31 changes: 31 additions & 0 deletions qiskit_ibm_runtime/transpiler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
#
# 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.

"""
====================================================================
IBM Backend Transpiler Tools (:mod:`qiskit_ibm_provider.transpiler`)
====================================================================

A collection of transpiler tools for working with IBM Quantum's
next-generation backends that support advanced "dynamic circuit"
capabilities. Ie., circuits with support for classical
compute and control-flow/feedback based off of measurement results.

Transpiler Passes
==================

.. autosummary::
:toctree: ../stubs/

passes

"""
36 changes: 36 additions & 0 deletions qiskit_ibm_runtime/transpiler/passes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
#
# 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.

"""
================================================================
Transpiler Passes (:mod:`qiskit_ibm_provider.transpiler.passes`)
================================================================

.. currentmodule:: qiskit_ibm_provider.transpiler.passes

A collection of transpiler passes for IBM backends.

.. autosummary::
:toctree: ../stubs/

basis
scheduling


"""

from .basis import ConvertIdToDelay

# circuit scheduling
from .scheduling import ASAPScheduleAnalysis
from .scheduling import PadDynamicalDecoupling
from .scheduling import PadDelay
23 changes: 23 additions & 0 deletions qiskit_ibm_runtime/transpiler/passes/basis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
#
# 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.

"""
==========================================================
Basis (:mod:`qiskit_ibm_provider.transpiler.passes.basis`)
==========================================================

.. currentmodule:: qiskit_ibm_provider.transpiler.passes.basis

Passes to layout circuits to IBM backend's instruction sets.
"""

from .convert_id_to_delay import ConvertIdToDelay
87 changes: 87 additions & 0 deletions qiskit_ibm_runtime/transpiler/passes/basis/convert_id_to_delay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
#
# 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.

"""Pass to convert Id gate operations to a delay instruction."""

from typing import Dict

from qiskit.converters import dag_to_circuit, circuit_to_dag

from qiskit.circuit import ControlFlowOp
from qiskit.circuit import Delay
from qiskit.circuit.library import IGate
from qiskit.dagcircuit import DAGCircuit
from qiskit.transpiler.basepasses import TransformationPass
from qiskit.transpiler.instruction_durations import InstructionDurations


class ConvertIdToDelay(TransformationPass):
"""Convert :class:`qiskit.circuit.library.standard_gates.IGate` to
a delay of the corresponding length.
"""

def __init__(self, durations: InstructionDurations, gate: str = "sx"):
"""Convert :class:`qiskit.circuit.library.IGate` to a
Convert :class:`qiskit.circuit.Delay`.

Args:
duration: Duration of the delay to replace the identity gate with.
gate: Single qubit gate to extract duration from.
"""
self.durations = durations
self.gate = gate
self._cached_durations: Dict[int, int] = {}

super().__init__()

def run(self, dag: DAGCircuit) -> DAGCircuit:
self._run_inner(dag)
return dag

def _run_inner(self, dag: DAGCircuit) -> bool:
"""Run the pass on one :class:`.DAGCircuit`, mutating it. Returns ``True`` if the circuit
was modified and ``False`` if not."""
modified = False
qubit_index_map = {bit: index for index, bit in enumerate(dag.qubits)}
for node in dag.op_nodes():
if isinstance(node.op, ControlFlowOp):
modified_blocks = False
new_dags = []
for block in node.op.blocks:
new_dag = circuit_to_dag(block)
modified_blocks |= self._run_inner(new_dag)
new_dags.append(new_dag)
if not modified_blocks:
continue
dag.substitute_node(
node,
node.op.replace_blocks(dag_to_circuit(block) for block in new_dags),
inplace=True,
)
elif isinstance(node.op, IGate):
delay_op = Delay(self._get_duration(qubit_index_map[node.qargs[0]]))
dag.substitute_node(node, delay_op, inplace=True)

modified = True

return modified

def _get_duration(self, qubit: int) -> int:
"""Get the duration of a gate in dt."""
duration = self._cached_durations.get(qubit, None)
if duration:
return duration

duration = self.durations.get(self.gate, qubit)
self._cached_durations[qubit] = duration

return duration
Loading
Loading