A class to access IonQ's API.
cirq_ionq.service.Service(
remote_host: Optional[str] = None,
api_key: Optional[str] = None,
default_target: Optional[str] = None,
api_version='v0.3',
max_retry_seconds: int = 3600,
job_settings: Optional[dict] = None,
verbose=False
)
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
.
Args |
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.
|
Raises |
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_job(
circuit: cirq.AbstractCircuit,
repetitions: int = 100,
name: Optional[str] = None,
target: Optional[str] = None,
error_mitigation: Optional[dict] = None,
extra_query_params: Optional[dict] = None
) -> cirq_ionq.job.Job
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
get_current_calibration() -> cirq_ionq.calibration.Calibration
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.
Raises |
IonQException
|
If there was an error accessing the API.
|
get_job
View source
get_job(
job_id: str
) -> cirq_ionq.job.Job
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(
start: Optional[datetime.datetime] = None,
end: Optional[datetime.datetime] = None,
limit: int = 100,
batch_size: int = 1000
) -> Sequence[cirq_ionq.calibration.Calibration
]
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
list_jobs(
status: Optional[str] = None, limit: int = 100, batch_size: int = 1000
) -> Sequence[cirq_ionq.job.Job
]
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(
circuit: cirq.Circuit,
repetitions: int,
name: Optional[str] = None,
target: Optional[str] = None,
param_resolver: cirq.ParamResolverOrSimilarType = cirq.ParamResolver({}),
seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
error_mitigation: Optional[dict] = None,
sharpen: Optional[bool] = None,
extra_query_params: Optional[dict] = None
) -> cirq.Result
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.
|
sampler
View source
sampler(
target: Optional[str] = None, seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
)
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 .
|