So in Week 1, we (or at least I) struggled greatly through installing QISKit and Anaconda and Python. Now, it’s time to use those programs. Firstly, we need to learn how to access jupyter notebooks so if you haven’t downloaded the jupyter notebook tutorials already, you can download it by downloading the tutorials on: QISKit installation.
Okay, so now open up the Anaconda Prompt and change the directory to where the tutorial is. The file should be qiskit-tutorial-master. You can change the directory through cd ___ (___ is the location). For example, the default directory in my Anaconda was Users\Eric so I typed in:
cd Desktop
cd QISKit
cd qiskit-tutorial-master
Now, you need to activate the QISKit environment by typing activate QISKitenv
Afterward, you can type jupyter notebook index.ipynb
This should open up jupyter notebooks to the QISKit tutorial page.
From here, what I did to start coding was click the jupyter logo in the top left which took me to the directory of all the files in qiskit-tutorial-master. Then, I clicked “New” in the top right and clicked on Python 3.
Here are some important commands in Jupyter.
ctrl + enter: runs the current cell
shift + enter: runs the current cell and then moves to the next cell
To begin, we first need to import qiskit and its required packages. Here is the code to import the required packages:
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from math import pi
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, QISKitError
from qiskit import available_backends, execute, register, get_backend
from qiskit.tools.visualization import circuit_drawer
from qiskit.tools.qi.qi import state_fidelity
Now, you can run this through shift + enter which will move to the next cell by creating another cell. Keep in mind, you will need to run the aforementioned package imports each time you want to use the code that you will write.
This link will bring you to Jupyter’s guide on how to get started using QISKit: Getting Started – QISKit
There is also a very good link to all of Jupyter’s quantum gates and their code: Using Different Gates
There is a very good example of running quantum codes using QISKit explained by IBM’s Ali Javadi available HERE.