Skip to main contentIBM Quantum Documentation Preview
This is a preview build of IBM Quantum® documentation. Refer to quantum.cloud.ibm.com/docs for the official documentation.

Quick start

Build your first quantum circuit in under two minutes, on your local environment - no sign-in or API key necessary.

New to Python and virtual environments?
  • It is recommended to use a Python virtual environment.
Click to expand for more information about Python.
  • To install Python, first check the "Programming Language" section on the Qiskit PyPI project page to determine which Python versions are supported by the most recent release. For download instructions, see the Python Beginners Guide.
Note

These instructions use the standard Python distribution from pypi.org. However, you can use other Python distributions, such as Anaconda or miniconda, along with other dependency management workflows like Poetry.

Click to expand for more information on virtual environments.

  • Use Python virtual environments to separate Qiskit from other applications. A Python virtual environment is an isolated space to work with Python for a specific purpose — so you can install whatever packages you wish, and set up libraries, dependencies, and so on, without affecting the "base" Python environment on your machine.

One important advantage of a virtual environment is that if your Python environment becomes corrupted somewhere along the way, you can easily delete the virtual environment and start over!

Choose a preferred location in which to store information about your virtual environments. Typically they're stored in a directory named .venv within each project directory you're working in.

To work in your virtual environment, navigate to your project directory and create a minimal environment with only Python installed in it.

python3 -m venv .venv

Next, activate your new environment.

source .venv/bin/activate

1. Install Qiskit

Run the following command in your terminal to install the Qiskit and Qiskit Aer (local simulation) packages, as well as the Qiskit visualization module.

pip install qiskit qiskit-aer qiskit[visualization]
 
# On a zsh terminal, use this line instead:
# pip install qiskit qiskit-aer 'qiskit[visualization]'

2. Build your circuit

Open a Python environment, then run this code, which builds a Bell state (two entangled qubits).

from qiskit import QuantumCircuit
from qiskit.transpiler import generate_preset_pass_manager
from qiskit_aer import AerSimulator
 
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
 
sim = AerSimulator()
pass_manager = generate_preset_pass_manager()
 
transpiled = pass_manager.run(qc)
 
result = sim.run(transpiled, shots=1024).result()
print(result.get_counts())

Output:

{'00': 505, '11': 519}

The expected output is a near-even split between '00' and '11'.


Visualize your results

To get a histogram of your results, add the following code to your program.

from qiskit.visualization import plot_histogram
 
counts = result.get_counts()
plot_histogram(counts)
# Include the next line if you are not using Python in a Jupyter notebook
# plt.show()

Output:

Output of the previous code cell

This result is a signature of quantum entanglement.

Try changing the code to see how it affects the results. For example, add a third qubit by replacing qc.cx(0, 1) with qc.cx(1, 2), or include a bit-flip by adding qc.x(1).


Next steps

Recommendations