Qubits

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

A qubit is the basic unit of quantum information, a quantum bit: a two level system that can exist in superposition of those two possible states. Cirq also supports higher dimensional systems, so called qudits that we won't cover here.

In Cirq, a Qubit is nothing else than an abstract object that has an identifier, a cirq.Qid and some other potential metadata to represent device specific properties that can be used to validate a circuit. In contrast to real qubits, the Cirq qubit does not have any state. The reason for this is that the actual state of the qubits is maintained in the quantum processor, or, in case of simulation, in the simulated state vector.

qubit = cirq.NamedQubit("myqubit")

# creates an equal superposition of |0> and |1> when simulated
circuit = cirq.Circuit(cirq.H(qubit))

# see the "myqubit" identifier at the left of the circuit
print(circuit)

# run simulation
result = cirq.Simulator().simulate(circuit)

print("result:")
print(result)
myqubit: ───H───
result:
measurements: (no measurements)
output vector: 0.707|0⟩ + 0.707|1⟩

Qubit types

There are 3 main qubit types in Cirq:

  • cirq.NamedQubit - an abstract qubit that only has a name, nothing else. Use this when you don't need anything else and you don't need to create too many qubits in bulk.
  • cirq.LineQubit - a qubit that is identified by an integer index in a line. Some devices have lines of qubits, LineQubit can be useful to represent that. Also cirq.LineQubit.range(3) is a very easy way to create 3 qubits.
  • cirq.GridQubit - a qubit that is placed on a grid and is identified by the 2D coordinates. Most of Google's chips are represented using GridQubits.

Some providers provide their own qubit types. For example Pasqal defines a TwoDQubit and a ThreeDQubit to represent the specific topology of neutral atoms when validating circuits.