View on QuantumAI | Run in Google Colab | View source on GitHub | Download notebook |
This notebook walks through running a simple circuit on the Quantum Virtual Machine, including the necessary constraints on a device-runnable circuit and how to satisfy them.
Install Cirq and qsim
# @title Install `cirq_google` and `qsimcirq`
try:
import cirq
import cirq_google
except ImportError:
print("installing cirq...")
!pip install --quiet cirq-google
print("installed cirq.")
import cirq
import cirq_google
try:
import qsimcirq
except ImportError:
print("installing qsimcirq...")
!pip install --quiet qsimcirq
print(f"installed qsimcirq.")
import qsimcirq
# Other modules used in this colab
import matplotlib.pyplot as plt
import time
Create a Quantum Virtual Machine
The following cell builds a Quantum Virtual Machine that mimics a particular Google quantum hardware device (currently Rainbow or Weber) using the following customizable steps:
- Constructing a
cirq.NoiseModel
object from device calibration data saved in Cirq. See Representing Noise for more on noise models. - Building a
qsimcirq.QsimSimulator
that uses this noise model. See Noisy Simulation and Noise simulation with qsim for more. - Creating a
cirq.Device
that imposes the same constraints on circuits that the original device would. See Devices for more on these constraint objects. - Packaging the simulator and device into an object that implements the
cirq.Engine
interface that the hardware device would use.
If you don't need this level of control, you can also instantiate a QVM with cirq_google.engine.create_default_noisy_quantum_virtual_machine
, as in QVM Creation Template.
# @title Choose a processor ("rainbow" or "weber")
processor_id = "weber" # @param {type:"string"}
# Construct a simulator with a noise model based on the specified processor.
cal = cirq_google.engine.load_median_device_calibration(processor_id)
noise_props = cirq_google.noise_properties_from_calibration(cal)
noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props)
sim = qsimcirq.QSimSimulator(noise=noise_model)
# Create a device from the public device description
device = cirq_google.engine.create_device_from_processor_id(processor_id)
# Build the simulated local processor from the simulator and device.
sim_processor = cirq_google.engine.SimulatedLocalProcessor(
processor_id=processor_id, sampler=sim, device=device, calibrations={cal.timestamp // 1000: cal}
)
# Package the processor to use an Engine interface
sim_engine = cirq_google.engine.SimulatedLocalEngine([sim_processor])
print(
"Your quantum virtual machine",
processor_id,
"is ready, here is the qubit grid:",
"\n========================\n",
)
print(sim_engine.get_processor(processor_id).get_device())
Your quantum virtual machine weber is ready, here is the qubit grid: ======================== (0, 5)βββ(0, 6) β β β β (1, 4)βββ(1, 5)βββ(1, 6)βββ(1, 7) β β β β β β β β (2, 4)βββ(2, 5)βββ(2, 6)βββ(2, 7)βββ(2, 8) β β β β β β β β β β (3, 2)βββ(3, 3)βββ(3, 4)βββ(3, 5)βββ(3, 6)βββ(3, 7)βββ(3, 8)βββ(3, 9) β β β β β β β β β β β β β β β β (4, 1)βββ(4, 2)βββ(4, 3)βββ(4, 4)βββ(4, 5)βββ(4, 6)βββ(4, 7)βββ(4, 8)βββ(4, 9) β β β β β β β β β β β β β β β β (5, 0)βββ(5, 1)βββ(5, 2)βββ(5, 3)βββ(5, 4)βββ(5, 5)βββ(5, 6)βββ(5, 7)βββ(5, 8) β β β β β β β β β β β β β β (6, 1)βββ(6, 2)βββ(6, 3)βββ(6, 4)βββ(6, 5)βββ(6, 6)βββ(6, 7) β β β β β β β β β β (7, 2)βββ(7, 3)βββ(7, 4)βββ(7, 5)βββ(7, 6) β β β β β β (8, 3)βββ(8, 4)βββ(8, 5) β β (9, 4)
Create a circuit, transform it (to make it executable on Google quantum hardware) and choose qubits on the processor.
The circuit you use needs to be device ready, which means it:
- Is comprised of operations from the device's gate set.
- Is applied to qubits that exist on the device.
- Respects the connectivity of qubits on the device.
Below is an example of a circuit that has the correct topology to be placed on the Weber device, and how it is prepared to be run on the QVM.
Create a GHZ state builder circuit
The generalized GreenbergerβHorneβZeilinger (GHZ) state has the form \(\frac{|00..0β© + |11..1β©}{\sqrt{2} }\) and, in this case, will be constructed using 17 qubits, with a Hadamard and a sequence of CNOT gates:
# Define an abstract line of 17 qubits
number_of_qubits = 17
qubits = cirq.LineQubit.range(number_of_qubits)
# Create a GHZ circuit on this qubit line
ghz_circuit = cirq.Circuit(
cirq.H(qubits[0]),
*[cirq.CNOT(qubits[i - 1], qubits[i]) for i in range(1, number_of_qubits)],
cirq.measure(*qubits, key='out'),
)
print(ghz_circuit)
0: ββββHβββ@βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββM('out')βββ β β 1: ββββββββXβββ@βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β 2: ββββββββββββXβββ@βββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β 3: ββββββββββββββββXβββ@βββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β 4: ββββββββββββββββββββXβββ@βββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β 5: ββββββββββββββββββββββββXβββ@βββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β 6: ββββββββββββββββββββββββββββXβββ@βββββββββββββββββββββββββββββββββββββββMββββββββββ β β 7: ββββββββββββββββββββββββββββββββXβββ@βββββββββββββββββββββββββββββββββββMββββββββββ β β 8: ββββββββββββββββββββββββββββββββββββXβββ@βββββββββββββββββββββββββββββββMββββββββββ β β 9: ββββββββββββββββββββββββββββββββββββββββXβββ@βββββββββββββββββββββββββββMββββββββββ β β 10: βββββββββββββββββββββββββββββββββββββββββββXβββ@βββββββββββββββββββββββMββββββββββ β β 11: βββββββββββββββββββββββββββββββββββββββββββββββXβββ@βββββββββββββββββββMββββββββββ β β 12: βββββββββββββββββββββββββββββββββββββββββββββββββββXβββ@βββββββββββββββMββββββββββ β β 13: βββββββββββββββββββββββββββββββββββββββββββββββββββββββXβββ@βββββββββββMββββββββββ β β 14: βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββXβββ@βββββββMββββββββββ β β 15: βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββXβββ@βββMββββββββββ β β 16: βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββXβββMββββββββββ
Notice that this circuit consists of a sequence of CNOT gates applied consecutively to a single chain of qubits. The connectivity required by the circuit is simple in the sense that it needs a line of qubits which are only connected to their adjacent neighbor in the sequence. As constructed, this consists of 17 cirq.LineQubit
s indexed 0, 1, 2...16
.
Transform the circuit
Before executing a circuit on (virtual) quantum hardware, the operations in the circuit need to be translated to use the types of gates the device supports. The cirq.optimize_for_target_gateset
function does this for you, transforming the operations to use the cirq.SqrtIswapTargetGateset
, which is supported by the Weber processor that this QVM is based on. Learn more about the gate set constraints of Google hardware at the Hardware page.
# Convert the gates in the GHZ circuit to the "SqrtIswap" gateset, which the device uses.
translated_ghz_circuit = cirq.optimize_for_target_gateset(
ghz_circuit, context=cirq.TransformerContext(deep=True), gateset=cirq.SqrtIswapTargetGateset()
)
print(translated_ghz_circuit)
0: ββββPhXZ(a=-1,x=0.25,z=-0.5)ββββββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββM('out')βββ β β β 1: ββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 2: βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 3: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 4: βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 5: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 6: βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 7: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 8: βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 9: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 10: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 11: βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 12: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 13: βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 14: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β 15: βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββMββββββββββ β β β 16: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=0.5,x=0.75,z=-0.5)βββMββββββββββ
Choose qubits on the virtual device
Choose qubits on the device to execute your device ready circuit on. Look at the device map (as above) and choose a set of qubits that fit your circuit (eg a line or a block). The Rainbow and Weber devices have different topologies, some qubit maps may be possible on only one of these devices. As noted, the GHZ example circuit as constructed will fit on a 17 qubit chain of adjacent qubits on the device, so you only need to find this consecutive line of qubits. See Qubit Picking for more advice and methods for selecting qubits.
# Choose qubits on the virtual device
device_qubit_chain = [
cirq.GridQubit(5, 2),
cirq.GridQubit(5, 3),
cirq.GridQubit(4, 3),
cirq.GridQubit(4, 2),
cirq.GridQubit(4, 1),
cirq.GridQubit(5, 1),
cirq.GridQubit(6, 1),
cirq.GridQubit(6, 2),
cirq.GridQubit(6, 3),
cirq.GridQubit(6, 4),
cirq.GridQubit(6, 5),
cirq.GridQubit(7, 5),
cirq.GridQubit(8, 5),
cirq.GridQubit(8, 4),
cirq.GridQubit(8, 3),
cirq.GridQubit(7, 3),
cirq.GridQubit(7, 4),
]
# Layout:
#
# q(4, 1)βββq(4, 2)βββq(4, 3)
# β β
# β β
# q(5, 1) q(5, 2)βββq(5, 3)
# β
# β
# q(6, 1)βββq(6, 2)βββq(6, 3)βββq(6, 4)βββq(6, 5)
# β
# β
# q(7, 3)βββq(7, 4) q(7, 5)
# β β
# β β
# q(8, 3)βββq(8, 4)βββq(8, 5)
Map the transformed circuit to the qubits you chose on the device
The transformed GHZ circuit still needs to be re-mapped to use the selected qubits. The transform_qubits
function of cirq.Circuit
does this automatically, returning a new transformed circuit when given a qubit mapping function.
Because the connectivity qubit chain in the GHZ circuit example follows the sequence of cirq.LineQubit
s in qubits
, it suffices to zip the circuit's qubits together with the chosen device qubits, since both are connected chains of 17 qubits. The dictionary built from these paired qubits can then be turned into a simple lambda function for use with transform_qubits
, as follows:
# Map the line of circuit qubits to the chosen line of device qubits.
qubit_map = dict(zip(qubits, device_qubit_chain))
# Then replace qubits in the circuit according to that map.
device_ready_ghz_circuit = translated_ghz_circuit.transform_qubits(lambda q: qubit_map[q])
print(device_ready_ghz_circuit)
(4, 1): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwapββββββββββββββββββββββββββββββiSwapβββββββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β β β (4, 2): βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwapββββββββββββββββββββββββββββββiSwapβββββββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwap^0.5βββPhXZ(a=-0.5,x=1,z=0)βββiSwap^0.5βββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββΌβββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β β β (4, 3): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwapββββββββββββββββββββββββββββββiSwapβββββββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwap^0.5βββPhXZ(a=-0.5,x=1,z=0)βββiSwap^0.5βββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β β β (5, 1): βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β β β (5, 2): βββPhXZ(a=-1,x=0.25,z=-0.5)ββββββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββΌβββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββM('out')βββ β β β β β β β (5, 3): βββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwap^0.5βββPhXZ(a=-0.5,x=1,z=0)βββiSwap^0.5βββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β (6, 1): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β (6, 2): βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β (6, 3): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β (6, 4): βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β (6, 5): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β (7, 3): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwapββββββββββββββββββββββββββββββiSwapβββββββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)βββββMββββββββββ β β β β β β β (7, 4): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌβββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=0.5,x=0.75,z=-0.5)βββMββββββββββ β β β β β (7, 5): βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwapβββββββPhXZ(a=-0.5,x=1,z=0)βββiSwapβββββββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β β β (8, 3): βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwapββββββββββββββββββββββββββββββiSwapβββββββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwap^0.5βββPhXZ(a=-0.5,x=1,z=0)βββiSwap^0.5βββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β β β (8, 4): βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌβββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwapββββββββββββββββββββββββββββββiSwapβββββββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwap^0.5βββPhXZ(a=-0.5,x=1,z=0)βββiSwap^0.5βββPhXZ(a=-1,x=0.5,z=0.25)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ β β β β β (8, 5): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPhXZ(a=8.22e-09,x=0.75,z=0.5)βββiSwap^0.5ββββββββββββββββββββββββββiSwap^0.5βββPhXZ(a=-0.196,x=0.667,z=1.0)ββββiSwap^0.5βββPhXZ(a=-0.5,x=1,z=0)βββiSwap^0.5βββPhXZ(a=-1,x=0.5,z=0.25)ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββMββββββββββ
Running other circuits
In principle, you can run any custom Circuit with a quantum virtual machine, but realistically there are some constraints. As mentioned, the circuits need to be mappable to the device. Additionally, the number of qubits that are simulatable depends highly on the hardware available to you and how long you are able to run your simulation. As the QVM is instantiated as above, with a qsimcirq.QSimSimulator
, it only uses the default, local qsim simulator. However, qsim has plenty of support for being run in a Google Cloud instance, with a variable amount of compute power. In order to get the most capacity possible for qsim, use Multinode Simulation.
For an example of building and running a much larger circuit, see the QVM Stabilizer Example tutorial.
Execute Your Circuit on the Quantum Virtual Machine
You can run the now device-ready circuit, as you would with any other cirq.Engine
instance, by getting a sampler from it and using the run
function on the circuits. Your choice of repetitions
is intrinsically related to the accuracy of your simulated results. We recommend 3000 repetitions for trial runs, and 10,000 repetitions for accuracy-critical runs, but you can stick to one to ten repetitions when testing a code pipeline. You can read more about this in this paper.
# @title Execute your device ready circuit on the Quantum Virtual Machine
circuit = device_ready_ghz_circuit
repetitions = 3000
start = time.time()
results = sim_engine.get_sampler(processor_id).run(circuit, repetitions=repetitions)
elapsed = time.time() - start
print('Circuit successfully executed on your quantum virtual machine', processor_id)
print(f'QVM runtime: {elapsed:.04g}s ({repetitions} repetitions)')
print('You can now print or plot "results"')
Circuit successfully executed on your quantum virtual machine weber QVM runtime: 33.95s (3000 repetitions) You can now print or plot "results"
Visualize Output
Finally, you can use a state histogram to plot the measured results.
ax = cirq.plot_state_histogram(results.histogram(key='out'))
ax.get_xaxis().set_ticks([])
plt.gcf().set_size_inches(10, 4)
plt.show(ax)
The leftmost and rightmost bars correspond to \(|00..0\rangle\) and \(|11..1\rangle\), respectively, which matches expectation for a GHZ state. Natural \(|1\rangle β |0\rangle\) decay causes \(|11..1\rangle\) to be much less common than \(|00..0\rangle\), and other states also appear due to the various error mechanisms in the hardware that are mimicked by the simulated noise model. Learn more about these errors here.