Saving Experiment Data to the Cloud¶
Qiskit Experiments is designed to work with Qiskit’s online experiment
database, where you
can view and share results of experiments you’ve run as
objects. This tutorial shows how to save your experimental results to the
database. You will need to have
qiskit-ibmq-provider installed locally
and an account in the Qiskit cloud service. We will use the
which is open and available to everyone.
Let’s run a \(T_1\) experiment and save the results to the experiment database.
from qiskit_experiments.library.characterization import T1 import numpy as np t1_delays = np.arange(1e-6, 600e-6, 50e-6) # Create an experiment for qubit 0, # setting the unit to microseconds, # with the specified time intervals exp = T1(qubit=0, delays=t1_delays) print(exp.circuits())
┌───┐ ░ ┌─────────────────┐ ░ ┌─┐ q: ┤ X ├─░─┤ Delay(1e-06[s]) ├─░─┤M├ └───┘ ░ └─────────────────┘ ░ └╥┘ c: 1/═══════════════════════════════╩═ 0
Now we run the experiment.
block_for_results() blocks execution
until the experiment is complete, then
save() is called to save the
data to ResultsDB.
from qiskit import IBMQ IBMQ.load_account() provider = IBMQ.get_provider(hub="ibm-q", group="open", project="main") backend = provider.get_backend("ibmq_lima") t1_expdata = exp.run(backend=backend, shots=1000).block_for_results() t1_expdata.save()
You can view the experiment online at https://quantum-computing.ibm.com/experiments/10a43cb0-7cb9-41db-ad74-18ea6cf63704
Note that calling
save() before the experiment is complete will
instantiate an experiment entry in the database, but it will not have
complete data. To fix this, you can call
save() again once the
experiment is done running.
Our \(T_1\) figure and analysis results:
display(t1_expdata.figure(0)) for result in t1_expdata.analysis_results(): print(result)
AnalysisResult - name: @Parameters_T1Analysis - value: CurveFitResult: - fitting method: least_squares - number of sub-models: 1 * F_exp_decay(x) = amp * exp(-x/tau) + base - success: True - number of function evals: 6 - degree of freedom: 9 - chi-square: 11.482176770249533 - reduced chi-square: 1.2757974189166148 - Akaike info crit.: 5.470672047146003 - Bayesian info crit.: 6.925391996510005 - init params: * amp = 0.9380619380619382 * tau = 0.00012486915523303855 * base = 0.006493506493506494 - fit params: * amp = 0.9504789294517044 ± 0.007423697983317722 * tau = 6.285861999775442e-05 ± 1.5384043570510136e-06 * base = 0.009541610991605803 ± 0.001460757413231069 - correlations: * (tau, base) = -0.44714123092529423 * (amp, tau) = -0.16684981921128555 * (amp, base) = -0.13083060052901557 - quality: good - device_components: ['Q0'] - verified: False AnalysisResult - name: T1 - value: (6.29+/-0.15)e-05 - χ²: 1.2757974189166148 - quality: good - extra: <1 items> - device_components: ['Q0'] - verified: False
You can also view the results at the IBM Quantum Experiments pane on the cloud.
By default, the interface displays all experiments you have privilege to see, but this link shows your own experiments. You can change that setting by clicking on the All Experiments dropdown. You can also filter by device, date, provider, and result by clicking on the filter icon.
Individual experiment pages show the plot, and one or more important analysis results, which for the \(T_1\) experiment is the fitted \(T_1\) value.
The metadata field shows experiment metadata included in the
You can change the quality and verify/unverify the results upon selection of an analysis result. Quality is an automatic parameter generated by the experiment analysis based on pre-set criteria. The verification field is for a human to determine whether the result is acceptable.
Loading an experiment from the database¶
You can also retrieve the full
ExperimentData object from the database service.
Let’s load a previous T1
which we’ve made public by editing the
Share level field:
from qiskit_experiments.framework.experiment_data import ExperimentData service = ExperimentData.get_service_from_backend(backend) load_expdata = ExperimentData.load("9640736e-d797-4321-b063-d503f8e98571", service)
To display the figure, which is serialized into a string, we need the
from IPython.display import SVG SVG(load_expdata.figure(0).figure)
The analysis results have been retrieved as well:
for result in load_expdata.analysis_results(): print(result)
AnalysisResult - name: T1 - value: 0.0001040+/-0.0000028 - χ²: 0.8523786276663019 - quality: good - extra: <1 items> - device_components: ['Q0'] - verified: False AnalysisResult - name: @Parameters_T1Analysis - value: CurveFitResult: - fitting method: least_squares - number of sub-models: 1 * F_exp_decay(x) = amp * exp(-x/tau) + base - success: True - number of function evals: 9 - degree of freedom: 9 - chi-square: 7.671407648996717 - reduced chi-square: 0.8523786276663019 - Akaike info crit.: 0.6311217041870707 - Bayesian info crit.: 2.085841653551072 - init params: * amp = 0.923076923076923 * tau = 0.00016946294665316433 * base = 0.033466533466533464 - fit params: * amp = 0.9266620487665083 ± 0.007096409569790425 * tau = 0.00010401411623191737 ± 2.767679521974391e-06 * base = 0.036302726197354626 ± 0.0037184540724124844 - correlations: * (tau, base) = -0.6740808746060173 * (amp, base) = -0.4231810882291163 * (amp, tau) = 0.09302612202500576 - quality: good - device_components: ['Q0'] - verified: False
Auto-saving an experiment¶
auto_save feature automatically saves changes to the ExperimentData object to
the cloud service whenever it’s updated.
exp = T1(qubit=0, delays=t1_delays) t1_expdata = exp.run(backend=backend, shots=1000) t1_expdata.auto_save = True t1_expdata.block_for_results()
You can view the experiment online at https://quantum-computing.ibm.com/experiments/cdaff3fa-f621-4915-a4d8-812d05d9a9ca <ExperimentData[T1], backend: ibmq_lima, status: ExperimentStatus.DONE, experiment_id: cdaff3fa-f621-4915-a4d8-812d05d9a9ca>
Deleting an experiment¶
Both figures and analysis results can be deleted. Note that unless you
have auto save on, the update has to be manually saved to the remote
database by calling
save(). Because there are two analysis results, one for
the T1 parameter and one for the curve fitting results, we delete twice.
t1_expdata.delete_figure(0) t1_expdata.delete_analysis_result(0) t1_expdata.delete_analysis_result(0)
Are you sure you want to delete the experiment plot? [y/N]: y Are you sure you want to delete the analysis result? [y/N]: y Are you sure you want to delete the analysis result? [y/N]: y
The web interface shows that both the figure and analysis result have been deleted:
Tagging and sharing experiments¶
Tags and notes can be added to experiments to help identify specific experiments in the interface. For example, an experiment can be tagged and made public with the following code.
t1_expdata.tags = ['tag1', 'tag2'] t1_expdata.share_level = "public" t1_expdata.notes = "Example note."
These fields can also be updated in the web interface. For more information about using the interface, consult its documentation.
import qiskit.tools.jupyter %qiskit_copyright
This code is a part of Qiskit
© Copyright IBM 2017, 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.