From bb1a3f30f0eeb86c1779b736185008fbd0786246 Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Fri, 20 Oct 2023 21:38:15 -0400 Subject: [PATCH 01/13] remove outdated link --- docs/howtos/cloud_service.rst | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/docs/howtos/cloud_service.rst b/docs/howtos/cloud_service.rst index 5f06517eff..fb3aebad53 100644 --- a/docs/howtos/cloud_service.rst +++ b/docs/howtos/cloud_service.rst @@ -189,11 +189,4 @@ Web interface You can also view experiment results as well as change the tags and share level at the `IBM Quantum Experiments pane `__ -on the cloud. The documentation below explains how to view, search, and share experiment -data entries. - -See also --------- - -* `Experiments web interface documentation `__ - +on the cloud. From 33ab2b2727a17938eb33383c784dcf7c703e5aab Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Tue, 24 Oct 2023 11:37:08 -0400 Subject: [PATCH 02/13] rewording --- docs/_ext/custom_styles/formatter.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/_ext/custom_styles/formatter.py b/docs/_ext/custom_styles/formatter.py index a218f9476e..1b54325ddf 100644 --- a/docs/_ext/custom_styles/formatter.py +++ b/docs/_ext/custom_styles/formatter.py @@ -38,8 +38,7 @@ def format_header(self, lines: List[str]) -> List[str]: def format_overview(self, lines: List[str]) -> List[str]: """Format overview section.""" format_lines = [ - "" - ".. rubric:: Overview", + "" ".. rubric:: Overview", "", ] format_lines.extend(lines) @@ -167,7 +166,7 @@ def format_analysis_opts(self, lines: List[str]) -> List[str]: format_lines = [ ".. rubric:: Analysis options", "", - "These are the keyword arguments of :meth:`run` method.", + "These are the keyword arguments of the :meth:`run` method.", "", ] for line in _write_options(lines, self.indent): From 95e5fcc592b34efba7ff6ac7d3b4bdd377e13599 Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Tue, 24 Oct 2023 14:05:01 -0400 Subject: [PATCH 03/13] fix docstring --- qiskit_experiments/framework/base_experiment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit_experiments/framework/base_experiment.py b/qiskit_experiments/framework/base_experiment.py index 882fc20a3f..2bbb12cf7e 100644 --- a/qiskit_experiments/framework/base_experiment.py +++ b/qiskit_experiments/framework/base_experiment.py @@ -293,8 +293,8 @@ def job_info(self, backend: Backend = None): Args: backend: Optional, the backend for which to get job distribution - information. If not specified, the experiment must already have a - set backend. + information. If not specified, the experiment must already have a + set backend. Returns: dict: A dictionary containing information about job distribution. From 71dc042b7cb871da9437622b1dee63aa3be58813 Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Tue, 24 Oct 2023 19:52:06 -0400 Subject: [PATCH 04/13] update textbook links --- docs/manuals/verification/quantum_volume.rst | 4 ++-- docs/manuals/verification/randomized_benchmarking.rst | 4 ++-- docs/tutorials/calibrations.rst | 2 +- qiskit_experiments/library/characterization/cr_hamiltonian.py | 2 +- .../library/characterization/multi_state_discrimination.py | 2 +- qiskit_experiments/library/characterization/rabi.py | 4 ++-- qiskit_experiments/library/quantum_volume/qv_experiment.py | 4 ++-- .../library/randomized_benchmarking/standard_rb.py | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/manuals/verification/quantum_volume.rst b/docs/manuals/verification/quantum_volume.rst index a4ea74e771..069fc73855 100644 --- a/docs/manuals/verification/quantum_volume.rst +++ b/docs/manuals/verification/quantum_volume.rst @@ -8,7 +8,7 @@ that the computer successfully implements. Quantum computing systems with high-fidelity operations, high connectivity, large calibrated gate sets, and circuit rewriting toolchains are expected to have higher quantum volumes. See the `Qiskit -Textbook `__ +Textbook `__ for an explanation on the QV method, which is described in Refs. [1]_ [2]_. The Quantum Volume is determined by the largest successful circuit depth @@ -190,5 +190,5 @@ See also -------- * API documentation: :mod:`~qiskit_experiments.library.quantum_volume` -* Qiskit Textbook: `Measuring Quantum Volume `__ +* Qiskit Textbook: `Measuring Quantum Volume `__ diff --git a/docs/manuals/verification/randomized_benchmarking.rst b/docs/manuals/verification/randomized_benchmarking.rst index 16fbd07f20..592054946e 100644 --- a/docs/manuals/verification/randomized_benchmarking.rst +++ b/docs/manuals/verification/randomized_benchmarking.rst @@ -8,7 +8,7 @@ identity. After running the circuits, the number of shots resulting in an error output different from the ground state) are counted, and from this data one can infer error estimates for the quantum device, by calculating the Error Per Clifford. See the `Qiskit Textbook -`__ for an +`__ for an explanation on the RB method, which is based on Refs. [1]_ [2]_. .. jupyter-execute:: @@ -309,4 +309,4 @@ See also -------- * API documentation: :mod:`~qiskit_experiments.library.randomized_benchmarking` -* Qiskit Textbook: `Randomized Benchmarking `__ +* Qiskit Textbook: `Randomized Benchmarking `__ diff --git a/docs/tutorials/calibrations.rst b/docs/tutorials/calibrations.rst index de1cff5e6a..a3024177a2 100644 --- a/docs/tutorials/calibrations.rst +++ b/docs/tutorials/calibrations.rst @@ -491,7 +491,7 @@ See also -------- * API documentation: :mod:`~qiskit_experiments.calibration_management` and :mod:`~qiskit_experiments.library.calibration` -* Qiskit Textbook: `Calibrating Qubits with Qiskit Pulse `__ +* Qiskit Textbook: `Calibrating Qubits with Qiskit Pulse `__ diff --git a/qiskit_experiments/library/characterization/cr_hamiltonian.py b/qiskit_experiments/library/characterization/cr_hamiltonian.py index e655fd2fc5..97378dd2b7 100644 --- a/qiskit_experiments/library/characterization/cr_hamiltonian.py +++ b/qiskit_experiments/library/characterization/cr_hamiltonian.py @@ -122,7 +122,7 @@ class CrossResonanceHamiltonian(BaseExperiment): # section: manual .. ref_website:: Qiskit Textbook 6.7, - https://qiskit.org/textbook/ch-quantum-hardware/hamiltonian-tomography.html + https://github.com/Qiskit/textbook/blob/main/notebooks/quantum-hardware-pulses/hamiltonian-tomography.ipynb """ # Number of CR pulses. The flat top duration per pulse is divided by this number. diff --git a/qiskit_experiments/library/characterization/multi_state_discrimination.py b/qiskit_experiments/library/characterization/multi_state_discrimination.py index 14078af813..ffea405a52 100644 --- a/qiskit_experiments/library/characterization/multi_state_discrimination.py +++ b/qiskit_experiments/library/characterization/multi_state_discrimination.py @@ -55,7 +55,7 @@ class MultiStateDiscrimination(BaseExperiment): # section: reference `Qiskit Textbook\ - `_ + `_ """ diff --git a/qiskit_experiments/library/characterization/rabi.py b/qiskit_experiments/library/characterization/rabi.py index 4f102f84d3..724354f53d 100644 --- a/qiskit_experiments/library/characterization/rabi.py +++ b/qiskit_experiments/library/characterization/rabi.py @@ -50,8 +50,8 @@ class Rabi(BaseExperiment, RestlessMixin): # section: manual :ref:`Rabi Calibration` - See also `Qiskit Textbook `_ + See also the `Qiskit Textbook + `_ for the pulse level programming of a Rabi experiment. # section: analysis_ref diff --git a/qiskit_experiments/library/quantum_volume/qv_experiment.py b/qiskit_experiments/library/quantum_volume/qv_experiment.py index 8f1528f157..d3435dc6b6 100644 --- a/qiskit_experiments/library/quantum_volume/qv_experiment.py +++ b/qiskit_experiments/library/quantum_volume/qv_experiment.py @@ -40,8 +40,8 @@ class QuantumVolume(BaseExperiment): The Quantum Volume is determined by the largest circuit depth :math:`d_{max}`, and equals to :math:`2^{d_{max}}`. - See `Qiskit Textbook - `_ + See the `Qiskit Textbook + `_ for an explanation on the QV protocol. In the QV experiment we generate :class:`~qiskit.circuit.library.QuantumVolume` circuits on diff --git a/qiskit_experiments/library/randomized_benchmarking/standard_rb.py b/qiskit_experiments/library/randomized_benchmarking/standard_rb.py index 3da209f07a..33944ea70a 100644 --- a/qiskit_experiments/library/randomized_benchmarking/standard_rb.py +++ b/qiskit_experiments/library/randomized_benchmarking/standard_rb.py @@ -60,7 +60,7 @@ class StandardRB(BaseExperiment, RestlessMixin): Randomized Benchmarking (RB) is an efficient and robust method for estimating the average error rate of a set of quantum gate operations. See `Qiskit Textbook - `_ + `_ for an explanation on the RB method. A standard RB experiment generates sequences of random Cliffords From decf0f7eedcf8f3b1677644a0fe9807230c98e0f Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Wed, 25 Oct 2023 10:11:39 -0400 Subject: [PATCH 05/13] fix link --- docs/manuals/measurement/readout_mitigation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/manuals/measurement/readout_mitigation.rst b/docs/manuals/measurement/readout_mitigation.rst index 2b69142d27..0fed52b920 100644 --- a/docs/manuals/measurement/readout_mitigation.rst +++ b/docs/manuals/measurement/readout_mitigation.rst @@ -180,4 +180,4 @@ See also * API documentation: :mod:`~qiskit_experiments.library.characterization.LocalReadoutError`, :mod:`~qiskit_experiments.library.characterization.CorrelatedReadoutError` -* Qiskit Textbook: `Measurement Error Mitigation `__ +* Qiskit Textbook: `Measurement Error Mitigation `__ From 7dea966814090e4bce187f364dbdd57602abc0f7 Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Wed, 25 Oct 2023 10:47:19 -0400 Subject: [PATCH 06/13] update drag links --- .../library/calibration/fine_drag_cal.py | 12 ++++++------ .../library/calibration/rough_drag_cal.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qiskit_experiments/library/calibration/fine_drag_cal.py b/qiskit_experiments/library/calibration/fine_drag_cal.py index 7c52e2d6bd..c79bad7562 100644 --- a/qiskit_experiments/library/calibration/fine_drag_cal.py +++ b/qiskit_experiments/library/calibration/fine_drag_cal.py @@ -30,7 +30,7 @@ class FineDragCal(BaseCalibrationExperiment, FineDrag): - """A calibration version of the fine drag experiment.""" + """A calibration version of the fine DRAG experiment.""" def __init__( self, @@ -41,7 +41,7 @@ def __init__( cal_parameter_name: Optional[str] = "β", auto_update: bool = True, ): - r"""See class :class:`FineDrag` for details. + r"""See class :class:`.FineDrag` for details. Note that this class implicitly assumes that the target angle of the gate is :math:`\pi` as seen from the default experiment options. @@ -148,7 +148,7 @@ def update_calibrations(self, experiment_data: ExperimentData): class FineXDragCal(FineDragCal): - """Fine drag calibration of X gate.""" + """Fine DRAG calibration of X gate.""" def __init__( self, @@ -158,7 +158,7 @@ def __init__( cal_parameter_name: Optional[str] = "β", auto_update: bool = True, ): - r"""see class :class:`FineDrag` for details. + r"""see class :class:`.FineDrag` for details. Args: physical_qubits: Sequence containing the qubit for which to run the @@ -180,7 +180,7 @@ def __init__( class FineSXDragCal(FineDragCal): - """Fine drag calibration of X gate.""" + """Fine DRAG calibration of X gate.""" def __init__( self, @@ -190,7 +190,7 @@ def __init__( cal_parameter_name: Optional[str] = "β", auto_update: bool = True, ): - r"""see class :class:`FineDrag` for details. + r"""see class :class:`.FineDrag` for details. Args: physical_qubits: Sequence containing the qubit for which to run the diff --git a/qiskit_experiments/library/calibration/rough_drag_cal.py b/qiskit_experiments/library/calibration/rough_drag_cal.py index 53c0efcb63..21e055f8c4 100644 --- a/qiskit_experiments/library/calibration/rough_drag_cal.py +++ b/qiskit_experiments/library/calibration/rough_drag_cal.py @@ -102,7 +102,7 @@ def _attach_calibrations(self, circuit: QuantumCircuit): def update_calibrations(self, experiment_data: ExperimentData): """Update the beta using the value directly reported from the fit. - See :class:`DragCalAnalysis` for details on the fit. + See :class:`.DragCalAnalysis` for details on the fit. """ new_beta = BaseUpdater.get_value( From 7decd9479c82d3beda5f468107a922778d4b9ddc Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Wed, 25 Oct 2023 16:58:16 -0400 Subject: [PATCH 07/13] minor QV edits --- docs/manuals/verification/quantum_volume.rst | 6 +++--- qiskit_experiments/library/quantum_volume/qv_analysis.py | 6 +++--- qiskit_experiments/library/quantum_volume/qv_experiment.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/manuals/verification/quantum_volume.rst b/docs/manuals/verification/quantum_volume.rst index 069fc73855..2b01b515fa 100644 --- a/docs/manuals/verification/quantum_volume.rst +++ b/docs/manuals/verification/quantum_volume.rst @@ -20,8 +20,8 @@ a random permutation on the :math:`d` qubit. Then these circuits run on the quantum backend and on an ideal simulator (either :class:`qiskit_aer.AerSimulator` or :class:`qiskit.quantum_info.Statevector`). -A depth :math:`d` QV circuit is successful if it has ‘mean heavy-output -probability’ > 2/3 with confidence level > 0.977 (corresponding to +A depth :math:`d` QV circuit is successful if it has `mean heavy-output +probability` > 2/3 with confidence level > 0.977 (corresponding to z_value = 2), and at least 100 trials have been ran. .. note:: @@ -68,7 +68,7 @@ more trials may reduce the error bars to allow passing the threshold. The analysis results of the QV Experiment are: -- The mean heavy output probabilities (HOP) and standard deviation +- The mean heavy-output probabilities (HOP) and standard deviation - The calculated quantum volume, which will be None if the experiment does not pass the threshold diff --git a/qiskit_experiments/library/quantum_volume/qv_analysis.py b/qiskit_experiments/library/quantum_volume/qv_analysis.py index d1575309d8..730b4bb020 100644 --- a/qiskit_experiments/library/quantum_volume/qv_analysis.py +++ b/qiskit_experiments/library/quantum_volume/qv_analysis.py @@ -34,7 +34,7 @@ class QuantumVolumeAnalysis(BaseAnalysis): # section: overview Calculate the quantum volume of the analysed system. The quantum volume is determined by the largest successful circuit depth. - A depth is successful if it has 'mean heavy-output probability' > 2/3 with confidence + A depth is successful if it has `mean heavy-output probability` > 2/3 with confidence level > 0.977 (corresponding to z_value = 2), and at least 100 trials have been ran. we assume the error (standard deviation) of the heavy output probability is due to a binomial distribution. The standard deviation for binomial distribution is @@ -175,7 +175,7 @@ def _calc_quantum_volume(self, heavy_output_prob_exp, depth, trials): """ Calc the quantum volume of the analysed system. quantum volume is determined by the largest successful depth. - A depth is successful if it has 'mean heavy-output probability' > 2/3 with confidence + A depth is successful if it has `mean heavy-output probability` > 2/3 with confidence level > 0.977 (corresponding to z_value = 2), and at least 100 trials have been ran. we assume the error (standard deviation) of the heavy output probability is due to a binomial distribution. standard deviation for binomial distribution is sqrt(np(1-p)), @@ -187,7 +187,7 @@ def _calc_quantum_volume(self, heavy_output_prob_exp, depth, trials): whether the results passed the threshold, the confidence of the result, the heavy output probability for each trial, - the mean heavy output probability, + the mean heavy-output probability, the error of the heavy output probability, the depth of the circuit, the number of trials ran diff --git a/qiskit_experiments/library/quantum_volume/qv_experiment.py b/qiskit_experiments/library/quantum_volume/qv_experiment.py index d3435dc6b6..9e8bea0012 100644 --- a/qiskit_experiments/library/quantum_volume/qv_experiment.py +++ b/qiskit_experiments/library/quantum_volume/qv_experiment.py @@ -50,7 +50,7 @@ class QuantumVolume(BaseExperiment): Then these circuits run on the quantum backend and on an ideal simulator (either :class:`~qiskit_aer.AerSimulator` or :class:`~qiskit.quantum_info.Statevector`). - A depth :math:`d` QV circuit is successful if it has 'mean heavy-output probability' > 2/3 with + A depth :math:`d` QV circuit is successful if it has `mean heavy-output probability` > 2/3 with confidence level > 0.977 (corresponding to z_value = 2), and at least 100 trials have been ran. See :class:`QuantumVolumeAnalysis` documentation for additional From 383274704fff402c342ef095403bb949e8818db7 Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Mon, 30 Oct 2023 12:16:14 -0400 Subject: [PATCH 08/13] update contributor test syntax with a working example --- CONTRIBUTING.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7f4b45191f..e54b267a0b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 -``` 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. From b3079f0347a8ff9459395cb8de56d6713908145c Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Mon, 30 Oct 2023 13:12:27 -0400 Subject: [PATCH 09/13] add session howto --- docs/conf.py | 1 + docs/howtos/runtime_sessions.rst | 70 ++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 docs/howtos/runtime_sessions.rst diff --git a/docs/conf.py b/docs/conf.py index 527c1b7da0..b2165afb6b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -174,6 +174,7 @@ "qiskit_ibm_provider": ("https://qiskit.org/ecosystem/ibm-provider/", None), "qiskit_aer": ("https://qiskit.org/ecosystem/aer", None), "qiskit_dynamics": ("https://qiskit.org/documentation/dynamics", None), + "qiskit_ibm_runtime": ("https://qiskit.org/ecosystem/ibm-runtime/", None), } diff --git a/docs/howtos/runtime_sessions.rst b/docs/howtos/runtime_sessions.rst new file mode 100644 index 0000000000..18369ac2ca --- /dev/null +++ b/docs/howtos/runtime_sessions.rst @@ -0,0 +1,70 @@ +Use Experiments with Runtime sessions +===================================== + +Problem +------- + +You want to run experiments in a `Runtime session +`_ so that jobs can run in close temporal proximity. + +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() + +2. Use the ``qiskit-ibm-runtime`` provider. This requires extracting the circuits from the + 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 +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. \ No newline at end of file From 80590e4298996be93cab67528367a5fa792993e3 Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Thu, 2 Nov 2023 13:59:26 -0400 Subject: [PATCH 10/13] add styling --- qiskit_experiments/data_processing/data_processor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qiskit_experiments/data_processing/data_processor.py b/qiskit_experiments/data_processing/data_processor.py index 80a639b123..6be3761650 100644 --- a/qiskit_experiments/data_processing/data_processor.py +++ b/qiskit_experiments/data_processing/data_processor.py @@ -48,14 +48,14 @@ class DataProcessor: A DataProcessor defines a sequence of operations to perform on experimental data. Calling an instance of DataProcessor applies this sequence on the input argument. A DataProcessor is created with a list of DataAction instances. Each DataAction - applies its _process method on the data and returns the processed data. The nodes + applies its ``_process`` method on the data and returns the processed data. The nodes in the DataProcessor may also perform data validation and some minor formatting. The output of one data action serves as input for the next data action. - DataProcessor.__call__(datum) usually takes in an entry from the data property of + ``DataProcessor.__call__(datum)`` usually takes in an entry from the data property of an ExperimentData object (i.e. a dict containing metadata and memory keys and possibly counts, like the Result.data property) and produces the formatted data. - DataProcessor.__call__(datum) extracts the data from the given datum under - DataProcessor._input_key (which is specified at initialization) of the given datum. + ``DataProcessor.__call__(datum)`` extracts the data from the given datum under + ``DataProcessor._input_key`` (which is specified at initialization) of the given datum. """ def __init__( From e3ba04567bb8011ebc955ffd2d416743e911ba0e Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Wed, 8 Nov 2023 01:37:51 -0500 Subject: [PATCH 11/13] update sessions howto Co-authored-by: Will Shanks --- docs/howtos/runtime_sessions.rst | 56 ++++++++------------------------ 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/docs/howtos/runtime_sessions.rst b/docs/howtos/runtime_sessions.rst index 18369ac2ca..441f48f447 100644 --- a/docs/howtos/runtime_sessions.rst +++ b/docs/howtos/runtime_sessions.rst @@ -10,9 +10,11 @@ You want to run experiments in a `Runtime session Solution -------- -There are two pathways currently supported: +Use the :class:`~qiskit_ibm_provider.IBMBackend` object in ``qiskit-ibm-provider``, which supports sessions. -1. Use the :class:`~qiskit_ibm_provider.IBMBackend` object in ``qiskit-ibm-provider``, which supports sessions. +In this example, we will set the ``max_circuits`` property to an artificially low value so that the experiment will be +split into multiple jobs that run sequentially in a single session. When running real experiments with a +large number of circuits that can't fit in a single job, it may be helpful to follow this usage pattern: .. jupyter-input:: @@ -26,45 +28,15 @@ There are two pathways currently supported: qc.x(0) with backend.open_session() as session: - tomography = ProcessTomography(qc) - tomography_result = tomography.run(backend) - tomography_result.block_for_results() + exp = ProcessTomography(qc) + exp.set_experiment_options(max_circuits=3) + exp_data = exp.run(backend) + exp_data.block_for_results() + # Calling cancel because session.close() is not available for qiskit-ibm-provider<=0.7.2. + # It is safe to call cancel since block_for_results() ensures there are no outstanding jobs + # still running that would be canceled. session.cancel() -2. Use the ``qiskit-ibm-runtime`` provider. This requires extracting the circuits from the - 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 -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. \ No newline at end of file +Note that runtime primitives are not currently supported natively in Qiskit Experiments, so either +the `backend.run()` path or the ``circuit-runner`` program in ``qiskit-ibm-runtime`` is required +to run experiments. From 7c99c9b31986efaa4698659fd08714628cf71e0f Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Wed, 8 Nov 2023 01:39:58 -0500 Subject: [PATCH 12/13] update formatter Co-authored-by: Will Shanks --- docs/_ext/custom_styles/formatter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/_ext/custom_styles/formatter.py b/docs/_ext/custom_styles/formatter.py index 1b54325ddf..5a3b2d45af 100644 --- a/docs/_ext/custom_styles/formatter.py +++ b/docs/_ext/custom_styles/formatter.py @@ -38,7 +38,8 @@ def format_header(self, lines: List[str]) -> List[str]: def format_overview(self, lines: List[str]) -> List[str]: """Format overview section.""" format_lines = [ - "" ".. rubric:: Overview", + "", + ".. rubric:: Overview", "", ] format_lines.extend(lines) From 3774c344d2c3b3968992675873b7885416549ff8 Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Wed, 8 Nov 2023 14:20:47 -0500 Subject: [PATCH 13/13] remove mention of circuit-runner --- docs/howtos/runtime_sessions.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/howtos/runtime_sessions.rst b/docs/howtos/runtime_sessions.rst index 441f48f447..9b07705e76 100644 --- a/docs/howtos/runtime_sessions.rst +++ b/docs/howtos/runtime_sessions.rst @@ -37,6 +37,5 @@ large number of circuits that can't fit in a single job, it may be helpful to fo # still running that would be canceled. session.cancel() -Note that runtime primitives are not currently supported natively in Qiskit Experiments, so either -the `backend.run()` path or the ``circuit-runner`` program in ``qiskit-ibm-runtime`` is required -to run experiments. +Note that runtime primitives are not currently supported natively in Qiskit Experiments, so +the ``backend.run()`` path is required to run experiments.