import qiskit
from qrisp.interface import VirtualBackend
def VTTBackend(api_token, device_instance, port=None):
"""
This function instantiates an IQMBackend based on VirtualBackend
using Qiskit and Qiskit-on-IQM.
Parameters
----------
api_token : str
An API token retrieved from VTT QX.
device_instance : str
The device instance of the IQM backend such as "q5" or "q50".
For an up-to-date list, see the VTT QX dashboard.
port : int, optional
The port to listen. The default is None.
"""
if not isinstance(api_token, str):
raise TypeError(
"api_token must be a string. You can create an API token using the VTT QX dashboard."
)
if not isinstance(device_instance, str):
raise TypeError(
"Please provide a device_instance as a string. You can see a list of available devices id in the VTT QX dashboard."
)
try:
from iqm.qiskit_iqm import IQMProvider, transpile_to_IQM
except ImportError:
raise ImportError(
"Please install qiskit-iqm to use the IQMBackend. You can do this by running `pip install qrisp[iqm]`."
)
def run_func_iqm(qasm_str, shots=None, token=""):
if shots is None:
= 1000
shots = "https://qx.vtt.fi/api/devices/" + device_instance
server_url = IQMProvider(server_url, token=api_token).get_backend()
backend = qiskit.QuantumCircuit.from_qasm_str(qasm_str)
qc = transpile_to_IQM(qc, backend)
qc_transpiled
= backend.run(qc_transpiled, shots=shots)
job import re
= job.result().get_counts()
counts = {}
new_counts for key in counts.keys():
= re.sub(r"\W", "", key)
counts_string = counts[key]
new_counts[counts_string]
return new_counts
return VirtualBackend(run_func_iqm, port=port)
Introduction to Qrisp and VTT QX
This notebook demonstrates how to use Qrisp, a high-level quantum programming language, with VTT’s quantum computers.
We’ll start by defining a custom function VTTBackend
that will take care of job submissions to VTT QX.
1. Setting Up the VTT Backend
The VTTBackend
function connects Qrisp to VTT’s quantum computers through the VTT QX platform. It requires:
api_token
: Your personal access token from your VTT QX project.device_instance
: The quantum device slug (q5
orq50
).
= VTTBackend(api_token="YOUR_API_TOKEN_HERE", device_instance="q50")
qrisp_qx
# Replace YOUR_API_TOKEN_HERE with your actual token from VTT QX.
2. Running a Simple Qrisp Program
from qrisp import QuantumVariable, h, cx
# Create a GHZ state with 3 qubits
def create_ghz_state(n_qubits=3):
# Create a quantum variable with n_qubits
= QuantumVariable(n_qubits)
qv
# Apply Hadamard to the first qubit
0])
h(qv[
# Apply CNOTs to create entanglement
for i in range(n_qubits - 1):
+ 1])
cx(qv[i], qv[i
return qv
# Create the GHZ state
= create_ghz_state(3)
ghz
# Measure the state
= ghz.get_measurement(backend=qrisp_qx, shots=1000)
result_ghz print(result_ghz)
# For simulation, use the default backend
# result_ghz_sim = ghz.get_measurement(shots=1000)
# print("Simulated GHZ state measurement:")
# print(result_ghz_sim)
{'000': 0.463, '111': 0.41, '011': 0.04, '110': 0.036, '001': 0.018, '100': 0.014, '101': 0.013, '010': 0.006}
Conclusion
This tutorial demonstrated how to: - Connect Qrisp to VTT QX quantum computers - Create and execute a simple GHZ quantum circuits
For more information, check the Qrisp documentation and the VTT QX documentation.