cirq_ionq.service.Service

A class to access IonQ's API.

To access the API, this class requires a remote host url and an API key. These can be specified in the constructor via the parameters remote_host and api_key. Alternatively these can be specified by setting the environment variables IONQ_REMOTE_HOST and IONQ_API_KEY.

remote_host The location of the api in the form of an url. If this is None, then this instance will use the environment variable IONQ_REMOTE_HOST. If that variable is not set, then this uses https://api.ionq.co/{api_version}, where {api_version} is the api_version specified below.
api_key A string key which allows access to the api. If this is None, then this instance will use the environment variable IONQ_API_KEY. If that variable is not set, then this will raise an EnvironmentError.
default_target Which target to default to using. If set to None, no default is set and target must always be specified in calls. If set, then this default is used, unless a target is specified for a given call. Supports either 'qpu' or 'simulator'.
api_version Version of the api. Defaults to 'v0.3'.
max_retry_seconds The number of seconds to retry calls for. Defaults to one hour.
job_settings A dictionary of settings which can override behavior for circuits when run on IonQ hardware.
verbose Whether to print to stdio and stderr on retriable errors.

OSError If the api_key is None and has no corresponding environment variable set. This is actually an EnvironmentError which is equal to an OSError.

Methods

create_job

View source

Create a new job to run the given circuit.

Args
circuit The circuit to run.
repetitions The number of times to repeat the circuit. Defaults to 100.
name An optional name for the created job. Different from the job_id.
target Where to run the job. Can be 'qpu' or 'simulator'.
error_mitigation A dictionary of error mitigation settings. Valid keys include:

  • 'debias': A boolean indicating whether to use the debiasing technique for aggregating results. This technique is used to reduce the bias in the results caused by measurement error and can improve the accuracy of the output.
extra_query_params Specify any parameters to include in the request.

Returns
A cirq_ionq.IonQJob which can be queried for status or results.

Raises
IonQException If there was an error accessing the API.

get_current_calibration

View source

Gets the most recent calbration via the API.

Note that currently there is only one target, so this returns the calibration of that target.

The calibration include device specification (number of qubits, connectivity), as well as fidelities and timings of gates.

Returns
A cirq_ionq.Calibration containing the device specification and calibrations.

Raises
IonQException If there was an error accessing the API.

get_job

View source

Gets a job that has been created on the IonQ API.

Args
job_id The UUID of the job. Jobs are assigned these numbers by the server during the creation of the job.

Returns
A cirq_ionq.IonQJob which can be queried for status or results.

Raises
IonQNotFoundException If there was no job with the given job_id.
IonQException If there was an error accessing the API.

list_calibrations

View source

List calibrations via the API.

Args
start If supplied, only calibrations after this date and time. Accurate to seconds.
end If supplied, only calibrations before this date and time. Accurate to seconds.
limit The maximum number of calibrations to return.
batch_size The size of the batches requested per http GET call.

Returns
A sequence of calibrations.

Raises
IonQException If there was an error accessing the API.

list_jobs

View source

Lists jobs that have been created on the IonQ API.

Args
status If supplied will filter to only jobs with this status.
limit The maximum number of jobs to return.
batch_size The size of the batches requested per http GET call.

Returns
A sequence of jobs.

Raises
IonQException If there was an error accessing the API.

run

View source

Run the given circuit on the IonQ API.

Args
circuit The circuit to run.
repetitions The number of times to run the circuit.
name An optional name for the created job. Different from the job_id.
target Where to run the job. Can be 'qpu' or 'simulator'.
param_resolver A cirq.ParamResolver to resolve parameters in circuit.
seed If the target is simulation the seed for generating results. If None, this will be np.random, if an int, will be np.random.RandomState(int), otherwise must be a modulate similar to np.random.
error_mitigation A dictionary of error mitigation settings. Valid keys include:

  • 'debias': A boolean indicating whether to use the debiasing technique for aggregating results. This technique is used to reduce the bias in the results caused by measurement error and can improve the accuracy of the output.
sharpen A boolean that determines how to aggregate error mitigated. If True, apply majority vote mitigation; if False, apply average mitigation.
extra_query_params Specify any parameters to include in the request.

Returns
A cirq.Result for running the circuit.

sampler

View source

Returns a cirq.Sampler object for accessing the sampler interface.

Args
target The target to sample against. Either this or default_target on this service must be specified. If this is None, uses the default_target. If both default_target and target are specified, uses target.
seed If the target is simulation the seed for generating results. If None, this will be np.random, if an int, will be np.random.RandomState(int), otherwise must be a modulate similar to np.random.

Returns
A cirq.Sampler for the IonQ API.