-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add sessions how-to and update links #1297
Merged
Merged
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bb1a3f3
remove outdated link
coruscating 33ab2b2
rewording
coruscating cf87818
Merge remote-tracking branch 'upstream/main' into update-docs
coruscating 95e5fcc
fix docstring
coruscating 71dc042
update textbook links
coruscating decf0f7
fix link
coruscating 7dea966
update drag links
coruscating 7decd94
minor QV edits
coruscating 3832747
update contributor test syntax with a working
coruscating b3079f0
add session howto
coruscating 0ccb305
Merge branch 'main' into update-docs
coruscating 80590e4
add styling
coruscating e3ba045
update sessions howto
coruscating 0686feb
Merge remote-tracking branch 'upstream/main' into update-docs
coruscating 7c99c9b
update formatter
coruscating 3774c34
remove mention of circuit-runner
coruscating File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,21 +104,17 @@ https://stestr.readthedocs.io/en/stable/MANUAL.html#test-selection | |
If you want to run a single test module, test class, or individual test method you can | ||
do this faster with the `-n`/`--no-discover` option. For example, to run a module: | ||
``` | ||
tox -- -n test.python.test_examples | ||
tox -epy310 -- -n test.framework.test_composite | ||
``` | ||
Or to run the same module by path: | ||
|
||
``` | ||
tox -- -n test/python/test_examples.py | ||
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 wish this worked 🙂 It would make tab completion easier. I try it sometimes because it's what pytest uses and I forget it's not what unittest uses. |
||
``` | ||
To run a class: | ||
|
||
``` | ||
tox -- -n test.python.test_examples.TestPythonExamples | ||
tox -epy310 -- -n test.framework.test_composite.TestCompositeExperimentData | ||
``` | ||
|
||
To run a method: | ||
``` | ||
tox -- -n test.python.test_examples.TestPythonExamples.test_all_examples | ||
tox -epy310 -- -n test.framework.test_composite.TestCompositeExperimentData.test_composite_save_load | ||
``` | ||
|
||
Note that tests will fail automatically if they do not finish execution within 60 seconds. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Use Experiments with Runtime sessions | ||
===================================== | ||
|
||
Problem | ||
------- | ||
|
||
You want to run experiments in a `Runtime session | ||
<https://qiskit.org/ecosystem/ibm-runtime/sessions.html>`_ so that jobs can run in close temporal proximity. | ||
wshanks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Solution | ||
-------- | ||
|
||
There are two pathways currently supported: | ||
|
||
1. Use the :class:`~qiskit_ibm_provider.IBMBackend` object in ``qiskit-ibm-provider``, which supports sessions. | ||
|
||
.. jupyter-input:: | ||
|
||
from qiskit_ibm_provider import IBMProvider | ||
from qiskit_experiments.library.tomography import ProcessTomography | ||
from qiskit import QuantumCircuit | ||
|
||
provider = IBMProvider() | ||
backend = provider.get_backend("ibm_nairobi") | ||
qc = QuantumCircuit(1) | ||
qc.x(0) | ||
|
||
with backend.open_session() as session: | ||
tomography = ProcessTomography(qc) | ||
tomography_result = tomography.run(backend) | ||
tomography_result.block_for_results() | ||
session.cancel() | ||
coruscating marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
2. Use the ``qiskit-ibm-runtime`` provider. This requires extracting the circuits from the | ||
wshanks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
experiment and running them using :meth:`qiskit_ibm_runtime.Session.run`: | ||
|
||
.. jupyter-input:: | ||
|
||
from qiskit_experiments.library import StandardRB | ||
from qiskit_ibm_runtime import Session, QiskitRuntimeService | ||
import numpy as np | ||
|
||
exp = StandardRB([0], np.arange(1,800,200)) | ||
backend = "ibm_nairobi" | ||
|
||
# all run options must be set before execution | ||
exp.set_run_options(shots=100) | ||
|
||
def run_jobs(session, job_circuits, run_options = None): | ||
runtime_inputs={'circuits': job_circuits, | ||
'skip_transpilation': True, | ||
**run_options} | ||
jobs = session.run(program_id="circuit-runner", inputs=runtime_inputs) | ||
return jobs | ||
|
||
service = QiskitRuntimeService() | ||
|
||
with Session(service=service, backend=backend) as session: | ||
exp.backend = service.get_backend(session.backend()) | ||
jobs = run_jobs(session, exp._transpiled_circuits(), exp.run_options) | ||
session.close() | ||
|
||
# exp_data will be the usual experiment data object | ||
exp_data = exp._initialize_experiment_data() | ||
exp_data.add_jobs(jobs) | ||
exp_data = exp.analysis.run(exp_data).block_for_results() | ||
|
||
Runtime primitives are not currently supported natively in Qiskit Experiments, so running jobs | ||
wshanks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with the Runtime provider must be done with the ``circuit-runner`` program. We also turn off | ||
transpilation with ``skip_transpilation`` since Qiskit Experiments already transpiles the circuits. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These commands were not working since some environments such as lint did not recognize the option, so an environment has to be specified.