Source code for qrisp.interface.provider_backends.iqm_backend
"""\********************************************************************************* Copyright (c) 2025 the Qrisp authors** This program and the accompanying materials are made available under the* terms of the Eclipse Public License 2.0 which is available at* http://www.eclipse.org/legal/epl-2.0.** This Source Code may also be made available under the following Secondary* Licenses when the conditions for such availability set forth in the Eclipse* Public License, v. 2.0 are satisfied: GNU General Public License, version 2* with the GNU Classpath Exception which is* available at https://www.gnu.org/software/classpath/license.html.** SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0********************************************************************************/"""importqiskitfromqrisp.interfaceimportVirtualBackend
[docs]defIQMBackend(api_token,device_instance):""" This function instantiates an IQMBackend based on VirtualBackend using Qiskit and Qiskit-on-IQM. Parameters ---------- api_token : str An API token retrieved from the IQM Resonance website. device_instance : str The device instance of the IQM backend such as "garnet". For an up-to-date list, see the IQM Resonance website. Examples -------- We evaluate a QuantumFloat multiplication on the 20-qubit IQM Garnet. >>> from qrisp.interface import IQMBackend >>> qrisp_garnet = IQMBackend(api_token = "YOUR_IQM_RESONANCE_TOKEN", device_instance = "garnet") >>> from qrisp import QuantumFloat >>> a = QuantumFloat(2) >>> a[:] = 2 >>> b = a*a >>> b.get_measurement(backend = qrisp_garnet, shots=1000) {4: 0.548, 5: 0.082, 0: 0.063, 6: 0.042, 8: 0.031, 2: 0.029, 12: 0.014, 10: 0.03, 1: 0.027, 7: 0.025, 15: 0.023, 9: 0.021, 14: 0.021, 13: 0.018, 11: 0.014, 3: 0.012} """ifnotisinstance(api_token,str):raiseTypeError("api_token must be a string. You can create an API token on the IQM Resonance website.")ifnotisinstance(device_instance,str):raiseTypeError("Please provide a device_instance as a string. You can retrieve a list of available devices id on the IQM Resonance website.")try:fromiqm.qiskit_iqmimportIQMProvider,transpile_to_IQMexceptImportError:raiseImportError("Please install qiskit-iqm to use the IQMBackend. You can do this by running `pip install qrisp[iqm]`.")defrun_func_iqm(qasm_str,shots=None,token=""):ifshotsisNone:shots=1000server_url="https://cocos.resonance.meetiqm.com/"+device_instancebackend=IQMProvider(server_url,token=api_token).get_backend()qc=qiskit.QuantumCircuit.from_qasm_str(qasm_str)qc_transpiled=transpile_to_IQM(qc,backend)job=backend.run(qc_transpiled,shots=shots)importrecounts=job.result().get_counts()new_counts={}forkeyincounts.keys():counts_string=re.sub(r"\W","",key)new_counts[counts_string]=counts[key]returnnew_countsreturnVirtualBackend(run_func_iqm)
Get in touch!
If you are interested in Qrisp or high-level quantum algorithm research in general connect with us on our
Slack workspace.