Here we are back again with a tutorial on How to Install Qiskit on Windows 10. We will also learn to setup Jupyter Notebook, an Opensource web application that helps you to write Python programs and execute it with a click of a button. Well, Jupyter Notebook supports multiple programming languages such as C++, R etc., but we are going to focus on Python, the language that we will use for writing Qiskit programs. If you are a Linux user, then you may jump to this guide on installing Qiskit on Ubuntu.
Install Anaconda Python Distribution
Step 1: Download the Anaconda Python installer for Windows.
Step 2: Once the installation is complete, launch the “Anaconda Prompt”
Install Qiskit on Windows
Step 3: In the anaconda prompt, type “
pip install qiskit”
The installation process might take a few minutes to complete. Once the installation is successful, go ahead and start the Jupyter notebook.
Launch Jupyter Notebook
Step 4: You are all set to launch the Jupyter Notebook by typing the command “
Once the Jupyter Notebook is started, you can access the notebook using the URL printed in the command output.
Step 5: Let’s create a new Python 3 Notebook by clicking
New > Python 3. This will open a new tab with an editor to write and execute Python programs.
Don’t worry, If you are not familiar with the Jupyter interface. It’s super simple to use. You just need to write your code inside the Code Cells and hit “
Shift+Enter” or click on “
Run” button from the toolbar to execute it. During the execution process, you will see an asterisk displayed next to “
In [*]” and the output is displayed right below the code cell after the execution.
Ok. Let’s start writing the code by importing the Qiskit first.
Step 6: Import Qiskit by typing “
import qiskit” and hit “
The above command will not display any output, as we have just imported the Qiskit library.
Step 7: Let’s now check the version of Qiskit imported by typing the below line.
Well, we are all set and ready to write our first Qiskit program.
First Qiskit Program
In order to execute our program, we can either use a Quantum simulator or a real Quantum device. To use IBM’s Quantum device, we need to create an API token from the IBM Q Experience website.
Step 8: Go to
https://quantum-computing.ibm.com/ and sign-up to create your account
Step 9: Upon sign-in, click on the user icon on the top right corner and select
Step 10: Click the
"Copy token" (blue button) to copy your API token to the clipboard.
Step 11: Let us now go ahead and import IBMQ from Qiskit by typing the below line in the Jupyter Notebook and hit “
from qiskit import IBMQ
Step 12: You now have an IBM Q Experience’s API token, so let’s save that to your computer by typing the below line and hit “
Remember to replace
YOUR-IBM-API-TOKEN with your own.
Once executed, IBM’s API token is now saved onto your computer and you are now ready to access IBM’s Quantum devices.
Step 13: To see that we have connected to the IBM’s Quantum devices, type the below code in the Notebook and hit “
Upon execution, you will see the output as shown below:
Step 14: You are now ready to write your first Qiskit program and execute it on a simulator and also on real Quantum hardware. Shall we?
Copy the below code and paste it into the Jupyter code cell and execute it.
import numpy as np from qiskit import( QuantumCircuit, execute, Aer) from qiskit.visualization import plot_histogram # Use Aer's qasm_simulator simulator = Aer.get_backend('qasm_simulator') # Create a Quantum Circuit acting on the q register circuit = QuantumCircuit(2, 2) # Add a H gate on qubit 0 circuit.h(0) # Add a CX (CNOT) gate on control qubit 0 and target qubit 1 circuit.cx(0, 1) # Map the quantum measurement to the classical bits circuit.measure([0,1], [0,1]) # Execute the circuit on the qasm simulator job = execute(circuit, simulator, shots=1000) # Grab results from the job result = job.result() # Returns counts counts = result.get_counts(circuit) print("\nTotal count for 00 and 11 are:",counts) # Draw the circuit print(circuit.draw(output='text'))
You should see the circuit printed as below:
Ok, what does the program do? I’ll take a break for now and cover that in my next tutorial. Until then, happy Qiiiiiiiiiiiskit.