-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running circuit with classical condition can cause KeyError
#375
Comments
Another code snippet that leads to the same error: U3_op = Op.create(OpType.U3, [-0.09, -0.39, -0.17])
Ry_op = Op.create(OpType.Ry, [0.1])
op_map = {(0,):U3_op, (1,):Ry_op}
multiplexor = MultiplexorBox(op_map)
main_circ = Circuit(0, 2, "main_circ")
qreg_0 = main_circ.add_q_register("qreg_0",3)
creg_3 = main_circ.add_c_register("creg_3",1)
main_circ.add_gate(multiplexor,[qreg_0[1], qreg_0[2]], condition = reg_eq(creg_3, 3))
backend = AerBackend()
no_pass_circ = backend.get_compiled_circuit(main_circ, optimisation_level=2)
counts = backend.run_circuit(no_pass_circ).get_counts() |
I think this is a question of giving an appropriate error message when the circuit contains classical ops which are not supported by the It may also be possible to run the circuits if we can convert the |
I think this is a real bug. We should really be able to convert this circuit and run it. But it is failing in |
Minimal example: from pytket.circuit import Bit, Circuit, OpType, Qubit
from pytket.unit_id import _TEMP_BIT_NAME
from pytket.extensions.qiskit import tk_to_qiskit
c = Circuit(1, 1)
treg = c.add_c_register(_TEMP_BIT_NAME, 1)
c.add_c_range_predicate(1, 1, [Bit(0)], treg[0])
c.add_gate(OpType.X, [Qubit(0)], condition_bits=[treg[0]], condition_value=1)
c.add_gate(OpType.Y, [Qubit(0)], condition_bits=[treg[0]], condition_value=1)
print(tk_to_qiskit(c)) |
Benny and I found this by running a randomly generated circuit through the compiler.
When preparing classical registers to pass to
append_tk_command_to_qiskit
, there's a check here that excludes scratch registers that are used to store results ofreg_eq(creg_0, 3)
.However, under certain conditions, this leads to a
KeyError
becauseregname
istk_SCRATCH_BIT
.Recreate with:
Results in:
KeyError: 'tk_SCRATCH_BIT'
Running the circuit above or with
OpType.CH
replaced byOpType.CV
results in the same error.The text was updated successfully, but these errors were encountered: