View source on GitHub |
Device object representing Google devices with a grid qubit layout.
cirq_google.devices.GridDevice(
metadata: cirq.GridDeviceMetadata
)
For end users, instances of this class are typically accessed via
Engine.get_processor('processor_name').get_device()
.
This class is compliant with the core cirq.Device
abstraction. In particular:
* Device information is captured in the `metadata` property.
* An instance of `GridDevice` can be used to validate circuits, moments, and operations.
Example use cases | |
---|---|
Get an instance of a Google grid device.
Print the grid layout of the device.
Determine whether a circuit can be run on the device.
Determine whether an operation can be run on the device.
Get the
Determine whether a gate is available on the device.
|
Notes about CompilationTargetGatesets:
- If a device contains gates which yield multiple compilation target gatesets, the user can only choose one target gateset to compile to. For example, a device may contain both SYC and SQRT_ISWAP gates which yield two separate target gatesets, but a circuit can only be compiled to either SYC or SQRT_ISWAP for its two-qubit gates, not both.
- For a given compilation target gateset, gates which are part of the device's gateset but not the target gateset are not decomposed. However, they may still be merged with other gates in the circuit.
- A circuit which contains
cirq.WaitGate
s will be dropped if it is transformed using CompilationTargetGatesets generated by GridDevice. To better control circuit timing, insert WaitGates after the circuit has been transformed.
Notes for cirq_google internal implementation:
For Google devices, the
DeviceSpecification proto
is the main specification for device information surfaced by the Quantum Computing Service.
Thus, this class should typically be instantiated using a DeviceSpecification
proto via the
from_proto()
class method.
Attributes | |
---|---|
metadata
|
Get metadata information for the device. |
Methods
from_proto
@classmethod
from_proto( proto:
cirq_google.api.v2.device_pb2.DeviceSpecification
) -> 'GridDevice'
Deserializes the DeviceSpecification
to a GridDevice
.
Args | |
---|---|
proto
|
The DeviceSpecification proto describing a Google device.
|
Raises | |
---|---|
ValueError
|
If the given DeviceSpecification is invalid. It is invalid if:
|
to_proto
to_proto(
out: Optional[cirq_google.api.v2.device_pb2.DeviceSpecification
] = None
) -> cirq_google.api.v2.device_pb2.DeviceSpecification
Serializes the GridDevice to a DeviceSpecification.
Args | |
---|---|
out
|
Optional DeviceSpecification to be populated. Fields are populated in-place. |
Returns | |
---|---|
The populated DeviceSpecification if out is specified, or the newly created DeviceSpecification. |
validate_circuit
validate_circuit(
circuit: 'cirq.AbstractCircuit'
) -> None
Raises an exception if a circuit is not valid.
Args | |
---|---|
circuit
|
The circuit to validate. |
Raises | |
---|---|
ValueError
|
The circuit isn't valid for this device. |
validate_moment
validate_moment(
moment: 'cirq.Moment'
) -> None
Raises an exception if a moment is not valid.
Args | |
---|---|
moment
|
The moment to validate. |
Raises | |
---|---|
ValueError
|
The moment isn't valid for this device. |
validate_operation
validate_operation(
operation: cirq.Operation
) -> None
Raises an exception if an operation is not valid.
An operation is valid if
* The operation is in the device gateset.
* The operation targets a valid qubit
* The operation targets a valid qubit pair, if it is a two-qubit operation.
Args | |
---|---|
operation
|
The operation to validate. |
Raises | |
---|---|
ValueError
|
The operation isn't valid for this device. |
__eq__
__eq__(
other: _SupportsValueEquality
) -> bool
__ne__
__ne__(
other: _SupportsValueEquality
) -> bool