Google Internal Gates in Cirq

View on QuantumAI Run in Google Colab View source on GitHub Download notebook
    import cirq
    import cirq_google
except ImportError:
    print("installing cirq...")
    !pip install --quiet cirq
    print("installed cirq.")
    import cirq
    import cirq_google

Google has a wealth of gates implemented internally that don't exist or have equivalents in Cirq. cirq_google.InternalGate allows the creation of Cirq circuits that contain place holder operations that will get translated to the correct internal gate.


Instances of cirq_google.InternalGate act as placeholder objects for google internal gates. During translation, the correct gate is identified through the gate_module and gate_name properties. Then an instance of that gate is created using the kwargs arguments passed to the InternalGate constructor.

internal_gate_args = {
    # Arguments to be passed to the constructor of the internal gate.
internal_gate = cirq_google.InternalGate(
    gate_module='GATE_MODULE',  # Module of class. 
    gate_name='GATE_NAMPE',  # Class name.
    num_qubits=2,  # Number of qubits that the gate acts on.
cirq_google.InternalGate(gate_name="GATE_NAME", gate_module="GATE_MODULE", num_qubits=2, )


  1. InternalGate is serializable.
  2. Values of kwargs must be serializable as api.v2.ArgValue
  3. If a value is not serializable as api.v2.ArgValue (e.g. a value with unit) then the translator will need to updated to know what to do for that gate.