Create your first quantum circuit

Start your quantum journey with an introduction to the qubit and the quantum \text{NOT} gate, the two fundamental concepts you need to understand to quantum compute. Then, explore how to use Circuit Composer to create your first quantum circuit, run your circuit on IBM Quantum Experience, and interpret the results.

You do not need to be familiar with quantum computing or classical programming to follow along. It was adapted from the excellent introduction to quantum computing, Quantum Computing for the Very Curious [1].

The state of a qubit

Similar to the way conventional computers are made up of bits, quantum computers are made up of quantum bits, or qubits. Just like a bit, a qubit has a state. However, while the state of a bit is a number ( 0 or 1 ), the state of a qubit is a vector. More specifically, the state of a qubit is a vector in a two-dimensional vector space. This vector space is known as state space.

Two special quantum states correspond to the 0 and 1 states of a classical bit. The quantum state corresponding to 0 is usually written as |0\rangle . This special state is called a computational basis state.

|0\rangle is a single symbol, much like the symbol 0 . A quantum computer can manipulate |0\rangle in ways similar to how a conventional computer can manipulate 0 .

There is another computational basis state, written as |1\rangle , which plays the same role as 1 does for a bit. Like |0\rangle , |1\rangle is a notation for a two-dimensional vector.

To quantum compute, you need to be able to change the state of qubits. This is what quantum logic gates are for.

The quantum NOT gate

One of the simpler quantum logic gates to learn first is the quantum \text{NOT} gate. The quantum \text{NOT} gate is a generalization of the classical \text{NOT} gate. On the computational basis states, the quantum \text{NOT} gate mimics the classical \text{NOT} gate. It changes the qubit’s state from |0\rangle state to |1\rangle , and vice versa:

\text{NOT} \; \vert 0 \rangle = \vert 1 \rangle,
\text{NOT} \; \vert 1 \rangle = \vert 0 \rangle.

People working on quantum computing usually use a different notation for the quantum \text{NOT} gate: X .

What you’ve seen so far is an algebraic way of writing down how the X gate works. You can also make a visual representation, called the quantum circuit representation. IBM Quantum Experience makes it easy to program quantum computers in the quantum circuit representation with Circuit Composer.

For the remainder of this tutorial, you can use Circuit Composer to follow along as you build and run a complete quantum circuit featuring the quantum \text{NOT} gate.

You will first need to sign in to IBM Quantum Experience if you have not already done so.

Sign in to IBM Quantum Experience

  1. Visit https://quantum-computing.ibm.com.

  2. Sign in or Create an IBMid account.

Sign-in page.

Open Circuit Composer

  1. To open Circuit Composer, select the circuit icon on the left-hand navigation of IBM Quantum Experience.

    Left-hand navigation button of Circuit Composer.
  2. To create a new circuit, select the New Circuit button.

    New circuit button.

A set of horizontal lines resembling a ruled piece of paper appears. The lines from left to right are called quantum wires. A quantum wire represents a single qubit. The notation on the left of the wire indicates which qubit the wire represents, and shows that each qubit is initially in the |0\rangle state (this is a common convention).

Add an X gate

  1. To add an X gate to your circuit, drag and drop the X instruction from the palette of quantum instructions to q[0], the top quantum wire.

    Simple quantum circuit.

The term wire and the way it’s drawn might suggest the qubit is moving through space, but it’s helpful to instead think of left-to-right as representing the passage of time. First, there is an empty segment of wire representing a period of time during which no gates are applied to the qubit. Next, the X gate is applied, and then the quantum wire continues, leaving the desired output.

To retrieve this output from a quantum computer, the qubit must be measured. Measurement has a dramatic effect on qubits, so it is considered an operation itself, and is represented in IBM Quantum Experience with a measurement instruction.

Add a measurement instruction

  1. To add a measurement to your circuit, drag and drop the measurement instruction from the palette of quantum instructions to the right of the X instruction that you previously placed on q[0], the top quantum wire.

    Simple quantum circuit.

The measurement result is recorded as a classical bit, drawn as classical wire in the same fashion as a quantum wire. Quantum and classical wires are distinguished by the notation on the left of the wire. Here, the quantum wires are marked as q[0], q[1], etc.; the classical wires are marked as c1, c2, etc. The vertical wire coming out of the measurement instruction depicts information flowing from the quantum wire down to the classical wire.

This is a complete quantum circuit featuring the X gate in Circuit Composer that can be run on IBM Quantum Experience.

Run the circuit

  1. To run this circuit, first save it by selecting the Unsaved changes button.

    Save button.
  2. Select the Run button.

    Run button.

You’ll then be prompted to select a backend, which is a term that refers to either a classical simulator of a quantum computer or a real quantum computer, also referred to as a quantum system. You’ll also be prompted to select the number of shots, which is the number of times the quantum circuit is executed.

Choose backend and shots

  1. Select the default backend, which is ibmq_qasm_simulator.

  2. Leave the number of shots as the default. You can feel free to change this number, but you don’t need to right now.

  3. Select the Run button.

Once your circuit has been run, you can access the results report.

Read the results

  1. Access the results by selecting the link at the end of the page.

    Result report.

The results report includes a lot of useful information. At the end of the report, you’ll see a histogram of all your executions.

Histogram.

The horizontal axis of the histogram denotes the computational basis states; the vertical axis denotes the probability (relative frequency) of observing that state. In this case, the only state that was observed was the |1\rangle state because the qubits were initially in the |0\rangle state and the X gate changes the |0\rangle state to the |1\rangle state. Here, the circuit was run on a simulator. Would you expect the same result if the circuit was run on a real quantum computer? After thinking about it, try it out yourself!

Next steps

Congratulations! You performed your first quantum computation!

Haven’t built it yet? Complete the steps above in Circuit Composer.

Ready for more? Use Circuit Composer to follow along with these learning resources.

References

  1. Andy Matuschak and Michael A. Nielsen, “Quantum Computing for the Very Curious”, https://quantum.country/qcvc, San Francisco (2019).