We're celebrating World Quantum Day 2022! Join us

cirq_google.engine.AbstractLocalProcessor

Partial implementation of AbstractProcessor using in-memory objects.

Inherits From: AbstractProcessor

This implements reservation creation and scheduling using an in-memory list for time slots and reservations. Any time slot not specified by initialization is assumed to be UNALLOCATED (available for reservation).

processor_id Unique string id of the processor.
engine The parent AbstractEngine object, if available.
expected_down_time Optional datetime of the next expected downtime. For informational purpose only.
expected_recovery_time Optional datetime when the processor is expected to be available again. For informational purpose only.
schedule List of time slots that the scheduling/reservation should use. All time slots must be non-overlapping.
project_name A project_name for resource naming.

Methods

create_reservation

View source

Creates a reservation on this processor.

Args
start_time the starting date/time of the reservation.
end_time the ending date/time of the reservation.
whitelisted_users a list of emails that are allowed to send programs during this reservation (in addition to users with permission "quantum.reservations.use" on the project).

Raises
ValueError if start_time is after end_time.

engine

View source

Returns the parent Engine object.

Returns
The program's parent Engine.

Raises
ValueError if no engine has been defined for this processor.

expected_down_time

View source

Returns the start of the next expected down time of the processor, if set.

expected_recovery_time

View source

Returns the expected the processor should be available, if set.

get_calibration

View source

Retrieve metadata about a specific calibration run.

Args
calibration_timestamp_seconds The timestamp of the calibration in seconds since epoch.

Returns
The calibration data.

get_current_calibration

View source

Returns metadata about the current calibration for a processor.

Returns
The calibration data or None if there is no current calibration.

get_device

View source

Returns a Device created from the processor's device specification.

This method queries the processor to retrieve the device specification, which is then use to create a Device that will validate that operations are supported and use the correct qubits.

Args
gate_sets An iterable of serializers that can be used in the device.

Returns
A cirq.Devive representing the processor.

get_device_specification

View source

Returns a device specification proto for use in determining information about the device.

Returns
Device specification proto if present.

get_latest_calibration

View source

Returns the latest calibration with the provided timestamp or earlier.

get_program

View source

Returns an AbstractProgram for an existing Quantum Engine program.

Args
program_id Unique ID of the program within the parent project.

Returns
An AbstractProgram for the program.

get_reservation

View source

Retrieve a reservation given its id.

get_sampler

View source

Returns a sampler backed by the processor.

Args
gate_set Determines how to serialize circuits if needed.

get_schedule

View source

Retrieves the schedule for a processor.

The schedule may be filtered by time.

Args
from_time Filters the returned schedule to only include entries that end no earlier than the given value. Specified either as an absolute time (datetime.datetime) or as a time relative to now (datetime.timedelta). Defaults to now (a relative time of 0). Set to None to omit this filter.
to_time Filters the returned schedule to only include entries that start no later than the given value. Specified either as an absolute time (datetime.datetime) or as a time relative to now (datetime.timedelta). Defaults to two weeks from now (a relative time of two weeks). Set to None to omit this filter.
time_slot_type Filters the returned schedule to only include entries with a given type (e.g. maintenance, open swim). Defaults to None. Set to None to omit this filter.

Returns
Time slots that fit the criteria.

health

View source

Returns the current health of processor.

list_calibrations

View source

Retrieve metadata about a specific calibration run.

Args
earliest_timestamp The earliest timestamp of a calibration to return in UTC.
latest_timestamp The latest timestamp of a calibration to return in UTC.

Returns
The list of calibration data with the most recent first.

list_programs

View source

Returns a list of previously executed quantum programs.

Args
created_after retrieve programs that were created after this date or time.
created_before retrieve programs that were created before this date or time.
has_labels retrieve programs 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:*'}

list_reservations

View source

Retrieves the reservations from a processor.

Only reservations from this processor and project will be returned. The schedule may be filtered by starting and ending time.

Args
from_time Filters the returned reservations to only include entries that end no earlier than the given value. Specified either as an absolute time (datetime.datetime) or as a time relative to now (datetime.timedelta). Defaults to now (a relative time of 0). Set to None to omit this filter.
to_time Filters the returned reservations to only include entries that start no later than the given value. Specified either as an absolute time (datetime.datetime) or as a time relative to now (datetime.timedelta). Defaults to two weeks from now (a relative time of two weeks). Set to None to omit this filter.

Returns
A list of reservations.

remove_reservation

View source

Removes a reservation on this processor.

run

View source

Runs the supplied Circuit on this processor.

Args
program The Circuit to execute. If a circuit is provided, a moment by moment schedule will be used.
program_id A user-provided identifier for the program. This must be unique within the Google Cloud project being used. If this parameter is not provided, a random id of the format 'prog-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day.
job_id Job identifier 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.
gate_set The gate set used to serialize the circuit. The gate set must be supported by the selected processor.
program_description An optional description to set on the program.
program_labels Optional set of labels to set on the program.
job_description An optional description to set on the job.
job_labels Optional set of labels to set on the job.

Returns
A single Result for this run.

run_batch

View source

Runs the supplied Circuits on this processor.

This will combine each Circuit provided in programs into a BatchProgram. Each circuit will pair with the associated parameter sweep provided in the params_list. The number of programs is required to match the number of sweeps. This method does not block until a result is returned. However, no results will be available until the entire batch is complete. Args: programs: The Circuits to execute as a batch. program_id: A user-provided identifier for the program. This must be unique within the Google Cloud project being used. If this parameter is not provided, a random id of the format 'prog-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day. job_id: Job identifier 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 use with the circuits. The number of sweeps should match the number of circuits and will be paired in order with the circuits. If this is None, it is assumed that the circuits are not parameterized and do not require sweeps. repetitions: Number of circuit repetitions to run. Each sweep value of each circuit in the batch will run with the same repetitions. gate_set: The gate set used to serialize the circuit. The gate set must be supported by the selected processor. program_description: An optional description to set on the program. program_labels: Optional set of labels to set on the program. job_description: An optional description to set on the job. job_labels: Optional set of labels to set on the job. Returns: An AbstractJob. If this is iterated over it returns a list of cirq.Result. All Results for the first circuit are listed first, then the Results for the second, etc. The Results for a circuit are listed in the order imposed by the associated parameter sweep.

run_calibration

View source

Runs the specified calibrations on the processor.

Each calibration will be specified by a CalibrationLayer that contains the type of the calibrations to run, a Circuit to optimize, and any arguments needed by the calibration routine. Arguments and circuits needed for each layer will vary based on the calibration type. However, the typical calibration routine may require a single moment defining the gates to optimize, for example. Note: this is an experimental API and is not yet fully supported for all users. Args: layers: The layers of calibration to execute as a batch. program_id: A user-provided identifier for the program. This must be unique within the Google Cloud project being used. If this parameter 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. job_id: Job identifier 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. gate_set: The gate set used to serialize the circuit. The gate set must be supported by the selected processor. program_description: An optional description to set on the program. program_labels: Optional set of labels to set on the program. job_description: An optional description to set on the job. job_labels: Optional set of labels to set on the job. By defauly, this will add a 'calibration' label to the job. Returns: An AbstractJob whose results can be retrieved by calling calibration_results().

run_sweep

View source

Runs the supplied Circuit on this processor.

In contrast to run, this runs across multiple parameter sweeps, and does not block until a result is returned. Args: program: The Circuit to execute. If a circuit is provided, a moment by moment schedule will be used. program_id: A user-provided identifier for the program. This must be unique within the Google Cloud project being used. If this parameter is not provided, a random id of the format 'prog-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day. job_id: Job identifier 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. gate_set: The gate set used to serialize the circuit. The gate set must be supported by the selected processor. program_description: An optional description to set on the program. program_labels: Optional set of labels to set on the program. job_description: An optional description to set on the job. job_labels: Optional set of labels to set on the job. Returns: An AbstractJob. If this is iterated over it returns a list of cirq.Result, one for each parameter sweep.

set_engine

View source

Sets the parent processor.

supported_languages

View source

Returns the list of processor supported program languages.

update_reservation

View source

Updates a reservation with new information.

Updates a reservation with a new start date, end date, or list of additional users. For each field, it the argument is left as None, it will not be updated.

Args
reservation_id The string identifier of the reservation to change.
start_time New starting time of the reservation. If unspecified, starting time is left unchanged.
end_time New ending time of the reservation. If unspecified, ending time is left unchanged.
whitelisted_users The new list of whitelisted users to allow on the reservation. If unspecified, the users are left unchanged.

Raises
ValueError if reservation_id does not exist.