ProjectQ
ProjectQ copied to clipboard
confusing error message for circuit
When a circuit cannot be compiled because gates are not available an error RecursionError: maximum recursion depth exceeded is generated. It would be better to generate an error indicating why the circuit cannot be compiled, e.g. CircuitRecursionError: cannot find circuit for [xxx].
A minimal example:
import projectq
from projectq import MainEngine
from projectq.ops import H, S, T, CZ, Z, X, Y
from projectq.setups import restrictedgateset
engine_list = restrictedgateset.get_engine_list(one_qubit_gates=(X,Y,Z, H,T,), two_qubit_gates=(CZ,))
engine_list+=[projectq.cengines.ManualMapper(lambda ii: ii)]
eng = MainEngine(backend=projectq.backends.CommandPrinter(),engine_list=engine_list ) # create a default compiler (the back-end is a simulator)
qubits=eng.allocate_qureg(2)
q0 = qubits[0]
H | q0
S | q0
eng.flush()
Thanks for the suggestion to annotate the message of these errors in future versions.
The reason for your error is that this setup currently does not support your gate set as it currently requires Rz gates (as most experimental setups use this):
https://projectq.readthedocs.io/en/latest/projectq.setups.html#module-projectq.setups.restrictedgateset
Let me know if you have a special gate set in mind and what it is used for. Future version will support a discrete gate set to get estimates for error correction overheads...
By the way:
projectq.cengines.ManualMapper(lambda ii: ii)
One can probably remove this mapper by adapting the backend.