We're celebrating World Quantum Day 2022! Join us

cirq_google.devices.GridDevice

Device object representing Google devices with a grid qubit layout.

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.
>>> device = cirq_google.get_engine().get_processor('processor_name').get_device()
  • Print the grid layout of the device.
>>> print(device)
  • Determine whether a circuit can be run on the device.
>>> device.validate_circuit(circuit)  # Raises a ValueError if the circuit is invalid.
  • Determine whether an operation can be run on the device.
>>> device.validate_operation(operation)  # Raises a ValueError if the operation is invalid.
  • Get the cirq.Gateset containing valid gates for the device, and inspect the full list of valid gates.
>>> gateset = device.metadata.gateset
>>> print(gateset)
  • Determine whether a gate is available on the device.
>>> gate in device.metadata.gateset
  • Get a collection of valid qubits on the device.
>>> device.metadata.qubit_set
  • Get a collection of valid qubit pairs for two-qubit gates.
>>> device.metadata.qubit_pairs
  • Get a collection of isolated qubits, i.e. qubits which are not part of any qubit pair.
>>> device.metadata.isolated_qubits
  • Get a collection of approximate gate durations for every gate supported by the device.
>>> device.metadata.gate_durations

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 is should be instantiated using a DeviceSpecification proto via the from_proto() class method.

metadata Get metadata information for the device.

Methods

can_add_operation_into_moment

THIS FUNCTION IS DEPRECATED.

IT WILL BE REMOVED IN cirq v0.15.

can_add_operation_into_moment will be removed in the future. Consider using device.validate_circuit instead.

Determines if it's possible to add an operation into a moment.

    For example, on the XmonDevice two CZs shouldn't be placed in the same
    moment if they are on adjacent qubits.

    Args:
        operation: The operation being added.
        moment: The moment being transformed.

    Returns:
        Whether or not the moment will validate after adding the operation.

decompose_operation

THIS FUNCTION IS DEPRECATED.

IT WILL BE REMOVED IN cirq v0.15.

Devices will no longer decompose operations.

Returns a device-valid decomposition for the given operation.

    This method is used when adding operations into circuits with a device
    specified, to avoid spurious failures due to e.g. using a Hadamard gate
    that must be decomposed into native gates.

from_proto

View source

Create a GridDevice from a DeviceSpecification proto.

Args
proto The DeviceSpecification proto describing a Google device.

Raises
ValueError If the given DeviceSpecification is invalid. It is invalid if:

validate_circuit

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

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

View source

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__

__ne__