View on QuantumAI
|
Run in Google Colab
|
View source on GitHub
|
|
try:
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.
InternalGate
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_NAME', # Class name.
num_qubits=2, # Number of qubits that the gate acts on.
**internal_gate_args,
)
internal_gate
cirq_google.InternalGate(gate_name="GATE_NAME", gate_module="GATE_MODULE", num_qubits=2, )
cirq.Circuit(internal_gate(*cirq.LineQubit.range(2)))
Notes
- InternalGate is serializable.
- Values of
kwargsmust be serializable as api.v2.ArgValue - 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.
View on QuantumAI
Run in Google Colab
View source on GitHub