Install Qiskit (Ubuntu 22.04)
-
Make sure you have python3 command available.
-
Create a directory.
mkdir qiskit-project
-
Run the following command, you may need to install python3.10-venv package.
python3 -m venv qiskit-project/
-
Activate your new environment.
source qiskit-project/bin/activate
Now your terminal prompt should be prefixed by "(qiskit-project)".
-
Use pip to install qiskit.
pip install qiskit
-
Use pip to install qiskit runtime.
pip install qiskit-ibm-runtime
You can run
pip list
to see the active packages in your virtual environment.
Run Qiskit code on IBM's simulators (Ubuntu 22.04)
Note that we assume you have an account with IBM and your terminal
is still in the virtual environment.
- Open up python interpreter.
python3
-
Enter the following command in the interpreter. Please replace "<MY_IBM_QUANTUM_TOKEN>"
with your actual token.
from qiskit_ibm_runtime import QiskitRuntimeService
QiskitRuntimeService.save_account(channel="ibm_quantum", token="<MY_IBM_QUANTUM_TOKEN>", set_as_default=True)
service = QiskitRuntimeService()
quit()
Your credentials will be saved to $HOME/.qiskit/qiskit-ibm.json. Next time you can use QiskitRuntimeService() to initialize your account.
- Download the this python file and run it with the following command.
python3 bell.py
If everything is setting up correctly, you should see
a printed ascii circuit for bell00 state, and an output
like {'00': 0.4845, '11': 0.5155}, which is the
output of IBM's simulator.
Note
- Once you have gone through the installation process. Each time you want to run your program
with IBM's machine, you will need to activate the python virtual environment by doing the following.
source qiskit-project/bin/activate
Your python code should always be ran inside this environment.