Skip to content

Qiskit

Qiskit is an open-source toolkit for useful quantum computing. It allows the creation and execution of Quantum circuits. They can be run in a local simulator or on a remote Quantum Computer. Additional information can be found at https://qiskit.org/

Install directions

You will need an existing Conda install.

  1. conda create --name qiskit python=3.9
  2. conda activate qiskit
  3. conda install -c conda-forge qiskit-ibm-runtime

Example usage

Run a simple quantum circuit on a remote Quantum computer. This is based on the example at https://github.com/Qiskit/qiskit-ibm-runtime and adapted to run at CCI. You will need an existing account and auth token from https://quantum-computing.ibm.com/ .

  1. Create a script example.py that sets up a simple quantum circuit and runs it.
import os
from qiskit_ibm_runtime import QiskitRuntimeService, Session, Options, Sampler
from qiskit import QuantumCircuit

#Reads auth token from env variable QISKIT_IBM_TOKEN
service = QiskitRuntimeService(channel="ibm_quantum", instance="ibm-q/open/main" , token=os.getenv('QISKIT_IBM_TOKEN') )

options = Options(optimization_level=1)
options.execution.shots = 1024  # Options can be set using auto-complete.

bell = QuantumCircuit(2)
bell.h(0)
bell.cx(0, 1)
bell.measure_all()

with Session(service=service, backend="ibmq_qasm_simulator") as session:
    sampler = Sampler(session=session, options=options)
    job = sampler.run(circuits=bell)
    print(f"Job ID is {job.job_id()}")
    print(f"Job result is {job.result()}")
  1. Run these commands to setup the execution environment and run our script
#Prior to execution of our script we need to setup the proxy so we can reach the IBM Quantum Cloud to submit our job.
export http_proxy=http://proxy:8888
export https_proxy=$http_proxy

#Activate conda
conda activate qiskit  

#Set IBM Quantum Cloud token
export QISKIT_IBM_TOKEN="MY_IBM_CLOUD_API_KEY...f43242342sfsf"

#execute our script
python example.py

RPI's Quantum Computer

For information on requesting access to and running on RPI's IBM Quantum System One visit https://itssc.rpi.edu/hc/en-us/articles/17609648152845-Quantum-computing

Running QisKit from Google Colab

It is also possible to run Qiskit using Google Colab. Jobs can be submitted to either simulators or RPI's Quantum computer from Google Colab. Create a new notebook at https://colab.research.google.com/ and then run the command below in the first code block. You can then run the above example or any other Qiskit code in your notebook.

!pip install qiskit qiskit_ibm_runtime ipywidgets
from google.colab import userdata

Google includes a secure method for storing credentials outside your notebook. It is called secrets, and can be found under the key icon in Colab. To use this feature add a secret with the name QISKIT_IBM_TOKEN and your key to colab. Then in the example code replace the environment variable access token=os.getenv('QISKIT_IBM_TOKEN') with token=userdata.get('QISKIT_IBM_TOKEN')