Hello Quantum World

Written by Mia von Steinkirch

QC Sandbox is a platform to help software engineers and quantum computing enthusiasts learn quantum software languages, through interactive coding tutorials, curated articles, and quantum games.

In this very simple hello world example, you will learn how to create a qubit and a circuit in one of the open-source quantum software languages available: Google's Cirq.

Create a qubit:

import cirq
msg = cirq.LineQubit(0)

Create a circuit and add your qubit:

circuit = cirq.Circuit()
0: ───X───

Run the simulator and measure the qubit:

import numpy as np
sim = cirq.Simulator()
original_message = sim.simulate(circuit)
expected = cirq.bloch_vector_from_state_vector(original_message.final_state, 0)
print("\nBloch Sphere of Message After X Gate:")
print("x: ", np.around(expected[0], 4), "y: ", np.around(expected[1], 4),
          "z: ", np.around(expected[2], 4))
Bloch Sphere of Message After X Gate:
x:  0.0 y:  0.0 z:  -1.0

Congratulations, you measured your first qubit!

Check out the source code (Jupyter notebook) here.