-
Notifications
You must be signed in to change notification settings - Fork 375
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
Cluster backend #1281
Cluster backend #1281
Changes from 15 commits
bea9481
1ce8807
5371bb4
44ed808
dc56af3
fb9da38
b2f6565
92fa323
fce954d
c5b2f3c
f0fcbac
b152345
4a17d16
d715065
a06090a
c6edd4c
10c8bb8
878ff18
e82cd86
9ca5f93
6205f5a
5fc18fb
1d6ee6c
e0e7f99
86d7981
3e21fb9
a3fb874
332b7aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -27,11 +27,16 @@ | |||
from qiskit.providers.models import BackendStatus | ||||
from qiskit.result import Result | ||||
from qiskit.utils import deprecate_arguments | ||||
from qiskit.circuit import QuantumCircuit | ||||
from qiskit.pulse import Schedule | ||||
from qiskit.qobj import QasmQobj, PulseQobj | ||||
from qiskit.compiler import assemble | ||||
|
||||
from ..aerjob import AerJob | ||||
from ..aererror import AerError | ||||
from .cluster.utils import split | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For organization we should rename |
||||
from .cluster.aerjobset import AerJobSet | ||||
|
||||
|
||||
# Logger | ||||
logger = logging.getLogger(__name__) | ||||
|
@@ -135,6 +140,9 @@ def run(self, | |||
``backend_options`` taking precedence. This kwarg is deprecated | ||||
and direct kwarg's should be used for options to pass them to | ||||
``run_options``. | ||||
|
||||
Raises: | ||||
ValueError: if run is not implemented | ||||
""" | ||||
# DEPRECATED | ||||
if backend_options is not None: | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove backend_options
Suggested change
|
||||
|
@@ -146,28 +154,68 @@ def run(self, | |||
DeprecationWarning, | ||||
stacklevel=3) | ||||
|
||||
if isinstance(circuits, (QasmQobj, PulseQobj)): | ||||
warnings.warn('Using a qobj for run() is deprecated and will be ' | ||||
'removed in a future release.', | ||||
PendingDeprecationWarning, | ||||
stacklevel=2) | ||||
qobj = circuits | ||||
executor = None | ||||
if backend_options and "executor" in backend_options: | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. backend options has been deprecated long enough that we can remove it in 0.9 release so this isn't needed.
Suggested change
|
||||
executor = backend_options["executor"] | ||||
del backend_options["executor"] | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really want to support doing this in |
||||
|
||||
if "executor" in run_options: | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. run options are supposed to be the same as the options that can be set with |
||||
executor = run_options["executor"] | ||||
del run_options["executor"] | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing this why not just add
and have it all run on dask. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At first, I added the executor option as your code but DASK client variable is needed to be a local variable for the serialization. So I moved the executor option as a run option. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand this comment on why it can't be a a config option? Is the probably re-using an executor between calls to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
These codes occur a cloudpickle error because the executor is not a local variable. The same error is mentioned in this website So I changed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found that the following code can be executed. I don't know why this code is ok but I can move
|
||||
|
||||
if executor: | ||||
if isinstance(circuits, (QasmQobj, PulseQobj)): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing the deprecation warning the single job path raises |
||||
experiments = split(circuits) | ||||
elif isinstance(circuits, (QuantumCircuit, Schedule)): | ||||
experiments = [assemble(circuits, self)] | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we some control about batch size for splitting circuits. Splitting to 1-circuit per job may be quite inefficient if there are lots of cirucits? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also if we can control this we could use the executor code for default execution but with 1 batch and the default ThreadPoolExecutor |
||||
elif ( | ||||
isinstance(circuits, list) and | ||||
all(isinstance(circ, QuantumCircuit) for circ in circuits) or | ||||
isinstance(circuits, list) and | ||||
all(isinstance(circ, Schedule) for circ in circuits) | ||||
): | ||||
experiments = [assemble(circ, self) for circ in circuits] | ||||
else: | ||||
raise ValueError( | ||||
"run() is not implemented for this " | ||||
"type of experiment ({})".format(str(type(circuits)))) | ||||
|
||||
for experiment in experiments: | ||||
self._add_options_to_qobj(experiment, | ||||
backend_options=backend_options, | ||||
**run_options) | ||||
# Optional validation | ||||
if validate: | ||||
self._validate(experiment) | ||||
|
||||
job_id = str(uuid.uuid4()) | ||||
aer_job_set = AerJobSet(self, job_id, self._run, experiments, executor) | ||||
aer_job_set.submit() | ||||
return aer_job_set | ||||
|
||||
else: | ||||
qobj = assemble(circuits, self) | ||||
if isinstance(circuits, (QasmQobj, PulseQobj)): | ||||
warnings.warn('Using a qobj for run() is deprecated and will be ' | ||||
'removed in a future release.', | ||||
PendingDeprecationWarning, | ||||
stacklevel=2) | ||||
qobj = circuits | ||||
else: | ||||
qobj = assemble(circuits, self) | ||||
|
||||
# Add backend options to the Job qobj | ||||
self._add_options_to_qobj( | ||||
qobj, backend_options=backend_options, **run_options) | ||||
# Add backend options to the Job qobj | ||||
self._add_options_to_qobj( | ||||
qobj, backend_options=backend_options, **run_options) | ||||
|
||||
# Optional validation | ||||
if validate: | ||||
self._validate(qobj) | ||||
# Optional validation | ||||
if validate: | ||||
self._validate(qobj) | ||||
|
||||
# Submit job | ||||
job_id = str(uuid.uuid4()) | ||||
aer_job = AerJob(self, job_id, self._run, qobj) | ||||
aer_job.submit() | ||||
return aer_job | ||||
# Submit job | ||||
job_id = str(uuid.uuid4()) | ||||
aer_job = AerJob(self, job_id, self._run, qobj) | ||||
aer_job.submit() | ||||
return aer_job | ||||
|
||||
def configuration(self): | ||||
"""Return the simulator backend configuration. | ||||
|
@@ -236,7 +284,7 @@ def status(self): | |||
pending_jobs=0, | ||||
status_msg='') | ||||
|
||||
def _run_job(self, job_id, qobj, backend_options, noise_model, validate): | ||||
def _run_job(self, job_id, qobj, backend_options=None, noise_model=None, validate=False): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method can be removed since it has been deprecated for long enough |
||||
"""Run a qobj job""" | ||||
warnings.warn( | ||||
'The `_run_job` method has been deprecated. Use `_run` instead.', | ||||
|
@@ -256,6 +304,9 @@ def _run_job(self, job_id, qobj, backend_options, noise_model, validate): | |||
noise_model=noise_model) | ||||
return self._run(qobj, job_id) | ||||
|
||||
def _dummy_job(self): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this here for? |
||||
return | ||||
|
||||
def _run(self, qobj, job_id=''): | ||||
"""Run a job""" | ||||
# Start timer | ||||
|
@@ -347,6 +398,7 @@ def set_option(self, key, value): | |||
setattr(self._options, key, getattr(self._default_options(), key)) | ||||
|
||||
def set_options(self, **fields): | ||||
"""Set the simulator options""" | ||||
for key, value in fields.items(): | ||||
self.set_option(key, value) | ||||
|
||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,31 @@ | ||||
# -*- coding: utf-8 -*- | ||||
|
||||
# This code is part of Qiskit. | ||||
# | ||||
# (C) Copyright IBM 2018, 2019. | ||||
# | ||||
# 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. | ||||
""" | ||||
=========================================================== | ||||
Cluster Backend (:mod:`qiskit.providers.aer.backends.cluster`) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole sphinx docstring should be removed. there is no reason for this module to appear in API docs and it is refering to a class from old PR that doesn't exist anymore
Suggested change
|
||||
=========================================================== | ||||
|
||||
.. currentmodule:: qiskit.providers.aer.backends.cluster | ||||
|
||||
High level mechanism for handling cluster jobs. | ||||
|
||||
Classes | ||||
========================== | ||||
.. autosummary:: | ||||
:toctree: ../stubs/ | ||||
|
||||
ClusterBackend | ||||
""" | ||||
|
||||
from .aerjobset import AerJobSet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
executor
should be an arg of__init__
like with AerJobSet, not to submit