Getting started with Qrisp on IQM
Download this Notebook
Download qrisp-starter.ipynb to run locally on your machine.
Qrisp is a quantum programming language build around the concept of quantum variables. It is designed to be a high-level language that is easy to use and understand. Qrisp is a great tool for beginners to learn quantum computing and for experts to quickly prototype quantum algorithms. It offers a fresh take on quantum programming. You can learn more about Qrisp on the official website: https://qrisp.eu/.
In this notebook, you will learn how to …
… get started with Qrisp.
… run a Qrisp program on an IQM backend both mock and real device.
This notebook is from https://www.iqmacademy.com/learn/qrisp/00-intro/ with few edits to make it simpler to use on IQM device Sirius
note: you can run this notebook with token.txt file next to it
Installing the necessary packages
In order to get started, make sure you have the appropriate packages installed. Make sure that you install qrisp with the iqm extension.
%%capture
%pip install qrisp[iqm]
# On some systems, you may need to use quotes around the extras:
#!pip install "qrisp[iqm]"
Imports
In order to use Qrisp, you need to import the qrisp package. You can do this by running from qrisp import *
ofcourse it is not the best practice to import everything like this, but for the sake of simplicity in this notebook we do it.
from qrisp import *
from qrisp.interface import IQMBackend
Qrisp provides advanced quantum data types such as QuantumFloat that we will use in this example. In this example we wil encode a 2 it will multiply it with itself and then measure the result.
Let’s run it on a simulator first.
a = QuantumFloat(2)
a[:] = 2
a.get_measurement()
                                                                                     
{2: 1.0}
Running on IQM Resonance
Now let’s run circuits on IQM Resonance. IQM provides both real quantum hardware and a mock backend for testing.
Token Authentication
To access IQM quantum computers, you need an API Token. Get one at
by clicking “Create Token” in the side panel.
Note: Here, We will use IQM Sirius (16 qubits, 0.30 credits/second) as it’s the most cost-effective option and can perform this demo efficiently.
from pathlib import Path
from getpass import getpass
token_file = Path('token.txt')
if not token_file.exists():
    token = ""
    while token == "":
        token = getpass("Please enter the token from that you generated from IQM resonance")
        token_file.write_text(token)
else:
    print("Reusing existing token.txt")
token = token_file.read_text()
# IQM Backend for Sirius (mock Hardware)
iqm_mock = IQMBackend(api_token = token, device_instance = "sirius:mock")
# IQM Backend for Sirius (real Hardware)
iqm_sirius = IQMBackend(api_token = token, device_instance = "sirius")
/srv/conda/envs/notebook/lib/python3.10/site-packages/iqm/iqm_client/iqm_client.py:142: UserWarning: Your IQM Client version 28.0.0 was built for a different version of IQM Server. You might encounter issues. For the best experience, consider using a version of IQM Client that satisfies 29.2.0 <= iqm-client < 30.0.
  warnings.warn(version_incompatibility_msg)
/srv/conda/envs/notebook/lib/python3.10/site-packages/iqm/iqm_client/iqm_client.py:142: UserWarning: Your IQM Client version 28.0.0 was built for a different version of IQM Server. You might encounter issues. For the best experience, consider using a version of IQM Client that satisfies 30.1.0 <= iqm-client < 31.0.
  warnings.warn(version_incompatibility_msg)
Compare all three runs: Simulator vs Mock vs Real Hardware
This will consume credits (0.30 credits/second).
# local simulator
a = QuantumFloat(2)
a[:] = 2
sim_result = a.get_measurement()
print(f"Qrisp Simulator:  {sim_result}")
print("Simulator: Perfect (no noise)")
Qrisp Simulator:  {2: 1.0}                                                           
Simulator: Perfect (no noise)
# mock backend on IQM resonance
a = QuantumFloat(2)
a[:] = 2
mock_result = a.get_measurement(backend=iqm_mock, shots=500)
print(f"IQM Mock Backend: {mock_result}")
print("Mock: Simulates IQM backend behavior (with noise model), zero credits used")
IQM Mock Backend: {0: 1.0}
Mock: Simulates IQM backend behavior (with noise model), zero credits used
Tip
Always test on the mock backend (above) first before using real hardware to avoid wasting credits!
# real hardware backend on IQM sirius
a = QuantumFloat(2)
a[:] = 2
iqm_result = a.get_measurement(backend=iqm_sirius, shots=500)
print(f"IQM Sirius (Real): {iqm_result}")
print("Real Hardware with actual NISQ noise")
IQM Sirius (Real): {2: 0.952, 0: 0.028, 3: 0.018, 1: 0.002}
Real Hardware with actual NISQ noise