qiskit.providers.ibmq.experiment.ExperimentService
class ExperimentService(provider)
Provides experiment related services.
This class is the main interface to invoke IBM Quantum Experience experiment services, which allow you to create, delete, update, query, and retrieve experiments, experiment plots, and analysis results. The experiment
attribute of AccountProvider
is an instance of this class, and the main syntax for using the services is provider.experiment.<action>
. For example:
from qiskit import IBMQ
provider = IBMQ.load_account()
# Retrieve all experiments.
experiments = provider.experiment.experiments()
# Retrieve experiments with filtering.
experiment_filtered = provider.experiment.experiments(backend_name='foo')
# Retrieve a specific experiment using its ID.
experiment = provider.experiment.retrieve_experiment(EXPERIMENT_ID)
# Upload a new experiment.
from qiskit.providers.ibmq.experiment import Experiment
new_exp = Experiment(
provider=provider,
backend_name=backend_name,
experiment_type='test',
tags=['qiskit-test']
)
provider.experiment.upload_experiment(new_exp)
# Update an experiment.
new_exp.end_datetime = datetime.now()
provider.experiment.update_experiment(new_exp)
# Delete an experiment.
provider.experiment.delete_experiment(EXPERIMENT_ID)
Similar syntax applies to analysis results and experiment plots. Classes Experiment
and AnalysisResult
encapsulate data of an experiment and an analysis result, respectively.
IBMQBackendService constructor.
Parameters
provider (AccountProvider
) – IBM Quantum Experience account provider.
__init__
__init__(provider)
IBMQBackendService constructor.
Parameters
provider (AccountProvider
) – IBM Quantum Experience account provider.
Methods
__init__ (provider) | IBMQBackendService constructor. |
analysis_results ([limit, backend_name, …]) | Retrieve all analysis results, with optional filtering. |
backends () | Return a list of backends. |
delete_analysis_result (result) | Delete an analysis result. |
delete_experiment (experiment) | Delete an experiment. |
delete_plot (experiment, plot_name) | Delete an experiment plot. |
device_components ([backend_name]) | Return the device components. |
experiments ([limit, backend_name, type, …]) | Retrieve all experiments, with optional filtering. |
retrieve_analysis_result (result_id) | Retrieve an analysis result. |
retrieve_experiment (experiment_id) | Retrieve an experiment. |
retrieve_plot (experiment, plot_name[, file_name]) | Retrieve an experiment plot. |
update_analysis_result (result) | Update an analysis result. |
update_experiment (experiment) | Update an experiment. |
update_plot (experiment, plot, plot_name) | Update an experiment plot. |
upload_analysis_result (result) | Upload an analysis result. |
upload_experiment (experiment) | Upload a new experiment. |
upload_plot (experiment, plot[, plot_name]) | Upload an experiment plot. |
analysis_results
analysis_results(limit=10, backend_name=None, device_components=None, experiment_id=None, result_type=None, quality=None, verified=None)
Retrieve all analysis results, with optional filtering.
Parameters
- limit (
Optional
[int
]) – Number of analysis results to retrieve. - backend_name (
Optional
[str
]) – Backend name used for filtering. - device_components (
Optional
[List
[str
]]) – Filter by device components. An analysis result’s device components must match this list exactly for it to be included. - experiment_id (
Optional
[str
]) – Experiment ID used for filtering. - result_type (
Optional
[str
]) – Analysis result type used for filtering. - quality (
Optional
[List
[Tuple
[str
,Union
[str
,ResultQuality
]]]]) – Quality value used for filtering. Each element in this list is a tuple of an operator and a value. The operator is one oflt
,le
,gt
,ge
, andeq
. The value is one of theResultQuality
values. For example,analysis_results(quality=[('ge', 'Bad'), ('lt', 'Good')])
will return all analysis results with a quality ofBad
andNo Information
. - verified (
Optional
[bool
]) – Indicates whether this result has been verified..
Return type
List
[AnalysisResult
]
Returns
A list of analysis results.
Raises
ValueError – If an invalid parameter value is specified.
backends
backends()
Return a list of backends.
Return type
List
[Dict
]
Returns
A list of backends.
delete_analysis_result
delete_analysis_result(result)
Delete an analysis result.
Parameters
result (Union
[AnalysisResult
, str
]) – The AnalysisResult
object or the analysis result UUID.
This method prompts for confirmation and requires a response before proceeding.
Return type
Optional
[AnalysisResult
]
Returns
The deleted analysis result.
delete_experiment
delete_experiment(experiment)
Delete an experiment.
Parameters
experiment (Union
[Experiment
, str
]) – The Experiment
object or the experiment ID.
This method prompts for confirmation and requires a response before proceeding.
Return type
Optional
[Experiment
]
Returns
Deleted experiment.
delete_plot
delete_plot(experiment, plot_name)
Delete an experiment plot.
This method prompts for confirmation and requires a response before proceeding.
Parameters
- experiment (
Union
[Experiment
,str
]) – TheExperiment
object or the experiment UUID. - plot_name (
str
) – Name of the plot.
Return type
None
device_components
device_components(backend_name=None)
Return the device components.
Parameters
backend_name (Optional
[str
]) – Name of the backend whose components are to be retrieved.
Return type
List
[DeviceComponent
]
Returns
A list of device components.
experiments
experiments(limit=10, backend_name=None, type=None, start_datetime=None, end_datetime=None, device_components=None, tags=None, tags_operator='OR', hub=None, group=None, project=None, exclude_public=False, public_only=False, exclude_mine=False, mine_only=False)
Retrieve all experiments, with optional filtering.
By default, results returned are as inclusive as possible. For example, if you don’t specify any filters, all experiments visible to you are returned. This includes your own experiments as well as those shared with you, from all providers you have access to (not just from the provider you used to invoke this experiment service).
Parameters
-
limit (
Optional
[int
]) – Number of experiments to retrieve.None
indicates no limit. -
backend_name (
Optional
[str
]) – Backend name used for filtering. -
type (
Optional
[str
]) – Experiment type used for filtering. -
start_datetime (
Optional
[datetime
]) – Filter by the given start timestamp, in local time. This is used to find experiments whose start date/time is after (greater than or equal to) this local timestamp. -
end_datetime (
Optional
[datetime
]) – Filter by the given end timestamp, in local time. This is used to find experiments whose start date/time is before (less than or equal to) this local timestamp. -
device_components (
Optional
[List
[str
]]) – Filter by device components. An experiment must have analysis results with device components matching the given list exactly to be included. -
tags (
Optional
[List
[str
]]) – Filter by tags assigned to experiments. -
tags_operator (
Optional
[str
]) –Logical operator to use when filtering by job tags. Valid values are “AND” and “OR”:
- If “AND” is specified, then an experiment must have all of the tags specified in tags to be included.
- If “OR” is specified, then an experiment only needs to have any of the tags specified in tags to be included.
-
hub (
Optional
[str
]) – Filter by hub. -
group (
Optional
[str
]) – Filter by hub and group. hub must also be specified if group is. -
project (
Optional
[str
]) – Filter by hub, group, and project. hub and group must also be specified if project is. -
exclude_public (
Optional
[bool
]) – IfTrue
, experiments withshare_level=public
(that is, experiments visible to all users) will not be returned. Cannot beTrue
if public_only isTrue
. -
public_only (
Optional
[bool
]) – IfTrue
, only experiments withshare_level=public
(that is, experiments visible to all users) will be returned. Cannot beTrue
if exclude_public isTrue
. -
exclude_mine (
Optional
[bool
]) – IfTrue
, experiments where I am the owner will not be returned. Cannot beTrue
if mine_only isTrue
. -
mine_only (
Optional
[bool
]) – IfTrue
, only experiments where I am the owner will be returned. Cannot beTrue
if exclude_mine isTrue
.
Return type
List
[Experiment
]
Returns
A list of experiments.
Raises
ValueError – If an invalid parameter value is specified.
retrieve_analysis_result
retrieve_analysis_result(result_id)
Retrieve an analysis result.
Parameters
result_id (str
) – Analysis result UUID.
Return type
AnalysisResult
Returns
Retrieved analysis result.
Raises
- AnalysisResultNotFoundError – If the analysis result is not found.
- RequestsApiError – If an unexpected error occurred when retrieving analysis result from the server.
retrieve_experiment
retrieve_experiment(experiment_id)
Retrieve an experiment.
Parameters
experiment_id (str
) – Experiment uuid.
Return type
Experiment
Returns
Retrieved experiment.
Raises
- ExperimentNotFoundError – If the experiment is not found.
- RequestsApiError – If an unexpected error occurred when retrieving experiment from the server.
retrieve_plot
retrieve_plot(experiment, plot_name, file_name=None)
Retrieve an experiment plot.
Parameters
- experiment (
Union
[Experiment
,str
]) – TheExperiment
object or the experiment UUID. - plot_name (
str
) – Name of the plot. - file_name (
Optional
[str
]) – Name of the local file to save the plot to. IfNone
, the content of the plot is returned instead.
Return type
Union
[int
, bytes
]
Returns
The size of the plot if file_name is specified. Otherwise the content of the plot in bytes.
Raises
- PlotNotFoundError – If the plot is not found.
- RequestsApiError – If an unexpected error occurred when retrieving plot from the server.
update_analysis_result
update_analysis_result(result)
Update an analysis result.
Parameters
result (AnalysisResult
) – The analysis result to update.
Return type
None
update_experiment
update_experiment(experiment)
Update an experiment.
Only the following experiment attributes can be updated:
- end_datetime
- share_level (visibility)
- notes (use empty string to clear notes)
Parameters
experiment (Experiment
) – Experiment to be updated.
Return type
None
update_plot
update_plot(experiment, plot, plot_name)
Update an experiment plot.
Parameters
- experiment (
Union
[Experiment
,str
]) – TheExperiment
object or the experiment UUID. - plot (
Union
[str
,bytes
]) – Name of the plot file or plot data to upload. - plot_name (
str
) – Name of the plot to update.
Return type
Dict
Returns
A dictionary with name and size of the uploaded plot.
upload_analysis_result
upload_analysis_result(result)
Upload an analysis result.
Parameters
result (AnalysisResult
) – The analysis result to upload.
Return type
None
upload_experiment
upload_experiment(experiment)
Upload a new experiment.
Parameters
experiment (Experiment
) – The experiment to upload.
Return type
None
upload_plot
upload_plot(experiment, plot, plot_name=None)
Upload an experiment plot.
Parameters
- experiment (
Union
[Experiment
,str
]) – TheExperiment
object or the experiment UUID. - plot (
Union
[str
,bytes
]) – Name of the plot file or plot data to upload. - plot_name (
Optional
[str
]) – Name of the plot. IfNone
, the plot file name, if given, or a generated name is used.
Return type
Dict
Returns
A dictionary with name and size of the uploaded plot.