cirq_google.engine.EngineProgram

A program created via the Quantum Engine API.

Inherits From: AbstractProgram

This program wraps a Circuit with additional metadata used to schedule against the devices managed by Quantum Engine.

project_id A project_id of the parent Google Cloud Project.
program_id Unique ID of the program within the parent project.
context Engine configuration and context to use.
_program The optional current program state.
result_type The type of program that was created.

project_id A project_id of the parent Google Cloud Project.
program_id Unique ID of the program within the parent project.

Methods

add_labels

View source

Adds new labels to a previously created quantum program.

Params
labels New labels to add to the existing program labels.

Returns
This EngineProgram.

add_labels_async

View source

Adds new labels to a previously created quantum program.

Params
labels New labels to add to the existing program labels.

Returns
This EngineProgram.

batch_size

View source

Returns the number of programs in a batch program.

Raises
ValueError if the program created was not a batch program.

batch_size_async

View source

Returns the number of programs in a batch program.

Raises
ValueError if the program created was not a batch program.

create_time

View source

Returns when the program was created.

delete

View source

Deletes a previously created quantum program.

Params
delete_jobs If True will delete all the program's jobs, other this will fail if the program contains any jobs.

delete_async

View source

Deletes a previously created quantum program.

Params
delete_jobs If True will delete all the program's jobs, other this will fail if the program contains any jobs.

delete_job

View source

Deletes the job and result, if any.

delete_job_async

View source

Deletes the job and result, if any.

description

View source

Returns the description of the program.

engine

View source

Returns the parent Engine object.

Returns
The program's parent Engine.

get_circuit

View source

Returns the cirq Circuit for the Quantum Engine program. This is only supported if the program was created with the V2 protos.

Args
program_num if this is a batch program, the index of the circuit in the batch. This argument is zero-indexed. Negative values indexing from the end of the list.

Returns
The program's cirq Circuit.

get_circuit_async

View source

Returns the cirq Circuit for the Quantum Engine program. This is only supported if the program was created with the V2 protos.

Args
program_num if this is a batch program, the index of the circuit in the batch. This argument is zero-indexed. Negative values indexing from the end of the list.

Returns
The program's cirq Circuit.

get_job

View source

Returns an EngineJob for an existing Quantum Engine job.

Args
job_id Unique ID of the job within the parent program.

Returns
A EngineJob for the job.

labels

View source

Returns the labels of the program.

list_jobs

View source

Returns the list of jobs for this program.

Args
project_id A project_id of the parent Google Cloud Project.
program_id Unique ID of the program within the parent project.
created_after retrieve jobs that were created after this date or time.
created_before retrieve jobs that were created after this date or time.
has_labels retrieve jobs that have labels on them specified by this dict. If the value is set to *, filters having the label regardless of the label value will be filtered. For example, to query programs that have the shape label and have the color label with value red can be queried using

{'color': 'red', 'shape':'*'}

execution_states retrieve jobs that have an execution state that is contained in execution_states. See quantum.ExecutionStatus.State enum for accepted values.

list_jobs_async

View source

Returns the list of jobs for this program.

Args
project_id A project_id of the parent Google Cloud Project.
program_id Unique ID of the program within the parent project.
created_after retrieve jobs that were created after this date or time.
created_before retrieve jobs that were created after this date or time.
has_labels retrieve jobs that have labels on them specified by this dict. If the value is set to *, filters having the label regardless of the label value will be filtered. For example, to query programs that have the shape label and have the color label with value red can be queried using

{'color': 'red', 'shape':'*'}

execution_states retrieve jobs that have an execution state that is contained in execution_states. See quantum.ExecutionStatus.State enum for accepted values.

remove_labels

View source

Removes labels with given keys from the labels of a previously created quantum program.

Params
label_keys Label keys to remove from the existing program labels.

Returns
This EngineProgram.

remove_labels_async

View source

Removes labels with given keys from the labels of a previously created quantum program.

Params
label_keys Label keys to remove from the existing program labels.

Returns
This EngineProgram.

run

View source

Runs the supplied Circuit via Quantum Engine.

Args
job_id Optional job id to use. If this is not provided, a random id of the format 'job-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day.
param_resolver Parameters to run with the program.
repetitions The number of repetitions to simulate.
processor_ids Deprecated list of candidate processor ids to run the program. Only allowed to contain one processor_id. If the argument processor_id is non-empty, processor_ids will be ignored.
description An optional description to set on the job.
labels Optional set of labels to set on the job.
processor_id Processor id for running the program. If not set, processor_ids will be used.
run_name A unique identifier representing an automation run for the specified processor. An Automation Run contains a collection of device configurations for a processor. If specified, processor_id is required to be set.
device_config_name An identifier used to select the processor configuration utilized to run the job. A configuration identifies the set of available qubits, couplers, and supported gates in the processor. If specified, processor_id is required to be set.

Returns
A single Result for this run.

Raises
ValueError If a processor id hasn't been specified to run the job
ValueError If only one of run_name and device_config_name are specified.
ValueError If processor_ids has more than one processor id.
ValueError If either run_name and device_config_name are set but processor_id is empty.

run_async

View source

Runs the supplied Circuit via Quantum Engine.

Args
job_id Optional job id to use. If this is not provided, a random id of the format 'job-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day.
param_resolver Parameters to run with the program.
repetitions The number of repetitions to simulate.
processor_ids Deprecated list of candidate processor ids to run the program. Only allowed to contain one processor_id. If the argument processor_id is non-empty, processor_ids will be ignored.
description An optional description to set on the job.
labels Optional set of labels to set on the job.
processor_id Processor id for running the program. If not set, processor_ids will be used.
run_name A unique identifier representing an automation run for the specified processor. An Automation Run contains a collection of device configurations for a processor. If specified, processor_id is required to be set.
device_config_name An identifier used to select the processor configuration utilized to run the job. A configuration identifies the set of available qubits, couplers, and supported gates in the processor. If specified, processor_id is required to be set.

Returns
A single Result for this run.

Raises
ValueError If a processor id hasn't been specified to run the job
ValueError If only one of run_name and device_config_name are specified.
ValueError If processor_ids has more than one processor id.
ValueError If either run_name and device_config_name are set but processor_id is empty.

run_batch

View source

Runs a batch of circuits on the QuantumEngine.

This method should only be used if the Program object was created with a BatchProgram. The number of parameter sweeps should match the number of circuits within that BatchProgram.

This method does not block until a result is returned. However, no results will be available until the entire batch is complete.

Args
job_id Optional job id to use. If this is not provided, a random id of the format 'job-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day.
params_list Parameter sweeps to run with the program. There must be one Sweepable object for each circuit in the batch. If this is None, it is assumed that the circuits are not parameterized and do not require sweeps.
repetitions The number of circuit repetitions to run.
processor_ids Deprecated list of candidate processor ids to run the program. Only allowed to contain one processor_id. If the argument processor_id is non-empty, processor_ids will be ignored.
description An optional description to set on the job.
labels Optional set of labels to set on the job.
processor_id Processor id for running the program. If not set, processor_ids will be used.
run_name A unique identifier representing an automation run for the specified processor. An Automation Run contains a collection of device configurations for a processor. If specified, processor_id is required to be set.
device_config_name An identifier used to select the processor configuration utilized to run the job. A configuration identifies the set of available qubits, couplers, and supported gates in the processor. If specified, processor_id is required to be set.

Returns
An EngineJob. If this is iterated over it returns a list of TrialResults. All TrialResults for the first circuit are listed first, then the TrialResults for the second, etc. The TrialResults for a circuit are listed in the order imposed by the associated parameter sweep.

Raises
ValueError if the program was not a batch program or no processors were supplied.
Raises

ValueError If neither processor_id or processor_ids are set.
ValueError If only one of run_name and device_config_name are specified.
ValueError If processor_ids has more than one processor id.
ValueError If either run_name and device_config_name are set but processor_id is empty.

run_batch_async

View source

Runs a batch of circuits on the QuantumEngine.

This method should only be used if the Program object was created with a BatchProgram. The number of parameter sweeps should match the number of circuits within that BatchProgram.

This method does not block until a result is returned. However, no results will be available until the entire batch is complete.

Args
job_id Optional job id to use. If this is not provided, a random id of the format 'job-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day.
params_list Parameter sweeps to run with the program. There must be one Sweepable object for each circuit in the batch. If this is None, it is assumed that the circuits are not parameterized and do not require sweeps.
repetitions The number of circuit repetitions to run.
processor_ids Deprecated list of candidate processor ids to run the program. Only allowed to contain one processor_id. If the argument processor_id is non-empty, processor_ids will be ignored.
description An optional description to set on the job.
labels Optional set of labels to set on the job.
processor_id Processor id for running the program. If not set, processor_ids will be used.
run_name A unique identifier representing an automation run for the specified processor. An Automation Run contains a collection of device configurations for a processor. If specified, processor_id is required to be set.
device_config_name An identifier used to select the processor configuration utilized to run the job. A configuration identifies the set of available qubits, couplers, and supported gates in the processor. If specified, processor_id is required to be set.

Returns
An EngineJob. If this is iterated over it returns a list of TrialResults. All TrialResults for the first circuit are listed first, then the TrialResults for the second, etc. The TrialResults for a circuit are listed in the order imposed by the associated parameter sweep.

Raises
ValueError if the program was not a batch program or no processors were supplied.
Raises

ValueError If neither processor_id or processor_ids are set.
ValueError If only one of run_name and device_config_name are specified.
ValueError If processor_ids has more than one processor id.
ValueError If either run_name and device_config_name are set but processor_id is empty.

run_calibration

View source

Runs layers of calibration routines on the Quantum Engine.

This method should only be used if the Program object was created with a FocusedCalibration.

This method does not block until a result is returned. However, no results will be available until all calibration routines complete.

Args
job_id Optional job id to use. If this is not provided, a random id of the format 'calibration-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day.
processor_ids The engine processors that should be candidates to run the program. Only one of these will be scheduled for execution.
description An optional description to set on the job.
labels Optional set of labels to set on the job.

Returns
An EngineJob. Results can be accessed with calibration_results().

Raises
ValueError If no processors are specified.

run_calibration_async

View source

Runs layers of calibration routines on the Quantum Engine.

This method should only be used if the Program object was created with a FocusedCalibration.

This method does not block until a result is returned. However, no results will be available until all calibration routines complete.

Args
job_id Optional job id to use. If this is not provided, a random id of the format 'calibration-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day.
processor_ids The engine processors that should be candidates to run the program. Only one of these will be scheduled for execution.
description An optional description to set on the job.
labels Optional set of labels to set on the job.

Returns
An EngineJob. Results can be accessed with calibration_results().

Raises
ValueError If no processors are specified.

run_sweep

View source

Runs the program on the QuantumEngine.

In contrast to run, this runs across multiple parameter sweeps, and does not block until a result is returned.

Args
job_id Optional job id to use. If this is not provided, a random id of the format 'job-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day.
params Parameters to run with the program.
repetitions The number of circuit repetitions to run.
processor_ids Deprecated list of candidate processor ids to run the program. Only allowed to contain one processor_id. If the argument processor_id is non-empty, processor_ids will be ignored.
description An optional description to set on the job.
labels Optional set of labels to set on the job.
processor_id Processor id for running the program. If not set, processor_ids will be used.
run_name A unique identifier representing an automation run for the specified processor. An Automation Run contains a collection of device configurations for a processor. If specified, processor_id is required to be set.
device_config_name An identifier used to select the processor configuration utilized to run the job. A configuration identifies the set of available qubits, couplers, and supported gates in the processor. If specified, processor_id is required to be set.

Returns
An EngineJob. If this is iterated over it returns a list of TrialResults, one for each parameter sweep.

Raises
ValueError If called on a program that is a batch of programs.
ValueError If a processor id hasn't been specified to run the job
ValueError If only one of run_name and device_config_name are specified.
ValueError If processor_ids has more than one processor id.
ValueError If either run_name and device_config_name are set but processor_id is empty.

run_sweep_async

View source

Runs the program on the QuantumEngine.

In contrast to run, this runs across multiple parameter sweeps, and does not block until a result is returned.

Args
job_id Optional job id to use. If this is not provided, a random id of the format 'job-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day.
params Parameters to run with the program.
repetitions The number of circuit repetitions to run.
processor_ids Deprecated list of candidate processor ids to run the program. Only allowed to contain one processor_id. If the argument processor_id is non-empty, processor_ids will be ignored.
description An optional description to set on the job.
labels Optional set of labels to set on the job.
processor_id Processor id for running the program. If not set, processor_ids will be used.
run_name A unique identifier representing an automation run for the specified processor. An Automation Run contains a collection of device configurations for a processor. If specified, processor_id is required to be set.
device_config_name An identifier used to select the processor configuration utilized to run the job. A configuration identifies the set of available qubits, couplers, and supported gates in the processor. If specified, processor_id is required to be set.

Returns
An EngineJob. If this is iterated over it returns a list of TrialResults, one for each parameter sweep.

Raises
ValueError If called on a program that is a batch of programs.
ValueError If a processor id hasn't been specified to run the job
ValueError If only one of run_name and device_config_name are specified.
ValueError If processor_ids has more than one processor id.
ValueError If either run_name and device_config_name are set but processor_id is empty.

set_description

View source

Sets the description of the program.

Params
description The new description for the program.

Returns
This EngineProgram.

set_description_async

View source

Sets the description of the program.

Params
description The new description for the program.

Returns
This EngineProgram.

set_labels

View source

Sets (overwriting) the labels for a previously created quantum program.

Params
labels The entire set of new program labels.

Returns
This EngineProgram.

set_labels_async

View source

Sets (overwriting) the labels for a previously created quantum program.

Params
labels The entire set of new program labels.

Returns
This EngineProgram.

update_time

View source

Returns when the program was last updated.