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