# Create your first quantum circuit¶

Start your quantum journey with an introduction to the qubit and the quantum 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 .

## 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 ( or ), 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 and states of a classical bit. The quantum state corresponding to is usually written as . This special state is called a computational basis state.

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

There is another computational basis state, written as , which plays the same role as does for a bit. Like , 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 gate. The quantum gate is a generalization of the classical gate. On the computational basis states, the quantum gate mimics the classical gate. It changes the qubit’s state from state to , and vice versa:

People working on quantum computing usually use a different notation for the quantum gate: .

What you’ve seen so far is an algebraic way of writing down how the 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 gate.

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

1. To open Circuit Composer, select the circuit icon on the left-hand navigation of IBM Quantum Experience. 2. To create a new circuit, select the 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 state (this is a common convention).

1. To add an gate to your circuit, drag and drop the instruction from the palette of quantum instructions to q, the top quantum wire. 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 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.

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 instruction that you previously placed on q, the top quantum wire. 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, q, 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 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. 2. Select the 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.

1. Access the results by selecting the link at the end of the page. The results report includes a lot of useful information. At the end of the report, you’ll see a histogram of all your executions. 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 state because the qubits were initially in the state and the gate changes the state to the 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.