Your First Circuit
A quantum circuit is the basic unit of work in quantum programming. You describe a computation by choosing a set of qubits and then listing a sequence of gates — elementary operations applied one after another, from left to right.
Anatomy of a circuit
Every circuit starts with all qubits in the state . A gate transforms the current state into a new one. The simplest single-qubit gate is the X gate, which swaps the amplitudes of and :
Its matrix confirms this directly:
Multiplying by the column vector for gives , which is exactly . On the Bloch sphere, is a rotation around the -axis, mapping the north pole to the south pole.
Creating a circuit in code
The simulator API makes building a circuit straightforward:
- Call
circuit(n)to create a fresh -qubit circuit. - Chain gate calls — for example,
c.x(0)applies to qubit 0. - Return the circuit object so the simulator can read its state vector.
This is the entire pattern you will use in every circuit exercise on this platform. The simulator initialises all qubits to automatically, so the code below starts from and ends in after one gate:
const c = circuit(1);
c.x(0);
return c;
Try it
Complete the circuit so the single qubit ends in . Press Run to see the state vector, then Check to grade your answer.
After running, the state vector should show amplitude for the basis state and amplitude for . That is the signature of a definite — no superposition, just a clean flip.
Sign in on the full site to ask questions and join the discussion.