-
-
Notifications
You must be signed in to change notification settings - Fork 21
Description
System and Environment Information
OS: Windows 10
MQT Version: 2.3.0 on Python 3.11, installed with uv
Qiskit 2.1.2
Bug Description
The following code (straight from the documentation) fails:
from mqt.predictor.rl import Predictor as RL_Predictor
from mqt.bench.targets import get_device
device = get_device("iqm_crystal_20")
rl_pred = RL_Predictor(device=device, figure_of_merit="expected_fidelity")
rl_pred.train_model(timesteps=100000)with error (I shortened the path a bit)
File ".viqm\Lib\site-packages\mqt\predictor\rl\parsing.py", line 153, in get_bqskit_native_gates
raise ValueError(msg)
ValueError: The 'r' gate of device 'iqm_crystal_20' is not supported in BQSKIT. It happens immediately after the training starts. The "r" gate is indeed defined in IQM's definition of Crystal (aka Garnet). I assume that the resolution of this error depends on BQSKIT.
If you look at Qiskit's definition of the RGate (the "r" gate in question), it seems to be equivalent to the BQSKIT U1qGate. Then, the fix is a simple addition to the gate_map in parsing.py.
If one goes ahead and adds the gate to the dict, this allows the training to proceed to the next error: U1qGate._qasm_name is an unallowed value by qasm, because it starts with a capital U. This, again, can be solved by pretending that gate is the r gate to qiskit, qasm, and bqskit, though the fix is rather ugly.
from bqskit.ir.gates.parameterized.u1q import U1qGate
from qiskit.qasm2 import CustomInstruction
from qiskit.circuit.library import RGate
import qiskit.qasm2
U1qGate._qasm_name = "r"
qiskit.qasm2.LEGACY_CUSTOM_INSTRUCTIONS = qiskit.qasm2.LEGACY_CUSTOM_INSTRUCTIONS + (
CustomInstruction("r", 2, 1, RGate,builtin=True),
)This fixes the gate issue. The training eventually fails seemingly because the IQM device is not bidirectional, causing a KeyError in reward.py.
I guess the issue doesn't lie in this repo. I'd be glad if there was a pretrained model for the IQM device.
Steps to Reproduce
Run the code from this page for iqm_crystal_20.
from mqt.predictor.rl import Predictor as RL_Predictor
from mqt.bench.targets import get_device
device = get_device("iqm_crystal_20")
rl_pred = RL_Predictor(device=device, figure_of_merit="expected_fidelity")
rl_pred.train_model(timesteps=100000)