Esempio n. 1
0
def _build_gateset_and_gate_durations(
    proto: v2.device_pb2.DeviceSpecification,
) -> Tuple[cirq.Gateset, Dict[cirq.GateFamily, cirq.Duration]]:
    """Extracts gate set and gate duration information from the given DeviceSpecification proto."""

    gates_list: List[Union[Type[cirq.Gate], cirq.Gate, cirq.GateFamily]] = []
    gate_durations: Dict[cirq.GateFamily, cirq.Duration] = {}

    # TODO(#5050) Describe how to add/remove gates.

    for gate_spec in proto.valid_gates:
        gate_name = gate_spec.WhichOneof('gate')
        cirq_gates: List[Union[Type[cirq.Gate], cirq.Gate, cirq.GateFamily]] = []

        if gate_name == 'syc':
            cirq_gates = [ops.FSimGateFamily(gates_to_accept=[ops.SYC])]
        elif gate_name == 'sqrt_iswap':
            cirq_gates = [ops.FSimGateFamily(gates_to_accept=[cirq.SQRT_ISWAP])]
        elif gate_name == 'sqrt_iswap_inv':
            cirq_gates = [ops.FSimGateFamily(gates_to_accept=[cirq.SQRT_ISWAP_INV])]
        elif gate_name == 'cz':
            cirq_gates = [ops.FSimGateFamily(gates_to_accept=[cirq.CZ])]
        elif gate_name == 'phased_xz':
            cirq_gates = [cirq.PhasedXZGate, cirq.XPowGate, cirq.YPowGate, cirq.PhasedXPowGate]
        elif gate_name == 'virtual_zpow':
            cirq_gates = [cirq.GateFamily(cirq.ZPowGate, tags_to_ignore=[ops.PhysicalZTag()])]
        elif gate_name == 'physical_zpow':
            cirq_gates = [cirq.GateFamily(cirq.ZPowGate, tags_to_accept=[ops.PhysicalZTag()])]
        elif gate_name == 'coupler_pulse':
            cirq_gates = [experimental_ops.CouplerPulse]
        elif gate_name == 'meas':
            cirq_gates = [cirq.MeasurementGate]
        elif gate_name == 'wait':
            cirq_gates = [cirq.WaitGate]
        else:
            # coverage: ignore
            warnings.warn(
                f"The DeviceSpecification contains the gate '{gate_name}' which is not recognized"
                " by Cirq and will be ignored. This may be due to an out-of-date Cirq version.",
                UserWarning,
            )
            continue

        gates_list.extend(cirq_gates)

        # TODO(#5050) Allow different gate representations of the same gate to be looked up in
        # gate_durations.
        for g in cirq_gates:
            if not isinstance(g, cirq.GateFamily):
                g = cirq.GateFamily(g)
            gate_durations[g] = cirq.Duration(picos=gate_spec.gate_duration_picos)

    # TODO(#4833) Add identity gate support
    # TODO(#5050) Add GlobalPhaseGate support

    return cirq.Gateset(*gates_list), gate_durations
Esempio n. 2
0
import warnings

import cirq
from cirq_google import ops
from cirq_google import transformers
from cirq_google.api import v2
from cirq_google.devices import known_devices
from cirq_google.experimental import ops as experimental_ops

SYC_GATE_FAMILY = cirq.GateFamily(ops.SYC)
SQRT_ISWAP_GATE_FAMILY = cirq.GateFamily(cirq.SQRT_ISWAP)
SQRT_ISWAP_INV_GATE_FAMILY = cirq.GateFamily(cirq.SQRT_ISWAP_INV)
CZ_GATE_FAMILY = cirq.GateFamily(cirq.CZ)
PHASED_XZ_GATE_FAMILY = cirq.GateFamily(cirq.PhasedXZGate)
VIRTUAL_ZPOW_GATE_FAMILY = cirq.GateFamily(cirq.ZPowGate,
                                           tags_to_ignore=[ops.PhysicalZTag()])
PHYSICAL_ZPOW_GATE_FAMILY = cirq.GateFamily(
    cirq.ZPowGate, tags_to_accept=[ops.PhysicalZTag()])
COUPLER_PULSE_GATE_FAMILY = cirq.GateFamily(experimental_ops.CouplerPulse)
MEASUREMENT_GATE_FAMILY = cirq.GateFamily(cirq.MeasurementGate)
WAIT_GATE_FAMILY = cirq.GateFamily(cirq.WaitGate)


def _validate_device_specification(
        proto: v2.device_pb2.DeviceSpecification) -> None:
    """Raises a ValueError if the `DeviceSpecification` proto is invalid."""

    qubit_set = set()
    for q_name in proto.valid_qubits:
        # Qubit names must be unique.
        if q_name in qubit_set:
Esempio n. 3
0
import warnings

import cirq
from cirq_google import ops
from cirq_google import transformers
from cirq_google.api import v2
from cirq_google.devices import known_devices
from cirq_google.experimental import ops as experimental_ops


SYC_GATE_FAMILY = cirq.GateFamily(ops.SYC)
SQRT_ISWAP_GATE_FAMILY = cirq.GateFamily(cirq.SQRT_ISWAP)
SQRT_ISWAP_INV_GATE_FAMILY = cirq.GateFamily(cirq.SQRT_ISWAP_INV)
CZ_GATE_FAMILY = cirq.GateFamily(cirq.CZ)
PHASED_XZ_GATE_FAMILY = cirq.GateFamily(cirq.PhasedXZGate)
VIRTUAL_ZPOW_GATE_FAMILY = cirq.GateFamily(cirq.ZPowGate, tags_to_ignore=[ops.PhysicalZTag()])
PHYSICAL_ZPOW_GATE_FAMILY = cirq.GateFamily(cirq.ZPowGate, tags_to_accept=[ops.PhysicalZTag()])
COUPLER_PULSE_GATE_FAMILY = cirq.GateFamily(experimental_ops.CouplerPulse)
MEASUREMENT_GATE_FAMILY = cirq.GateFamily(cirq.MeasurementGate)
WAIT_GATE_FAMILY = cirq.GateFamily(cirq.WaitGate)


def _validate_device_specification(proto: v2.device_pb2.DeviceSpecification) -> None:
    """Raises a ValueError if the `DeviceSpecification` proto is invalid."""

    qubit_set = set()
    for q_name in proto.valid_qubits:
        # Qubit names must be unique.
        if q_name in qubit_set:
            raise ValueError(
                f"Invalid DeviceSpecification: valid_qubits contains duplicate qubit '{q_name}'."