QVM Basic Example

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

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.

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.LineQubits 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.LineQubits 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.

Circuit successfully executed on your quantum virtual machine weber
QVM runtime: 36.02s (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)

png

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.