qat.comm.exceptions
All exceptions raised by QPUs and Plugins are Thrift exceptions. This is particularly usefull when using a remote QPU/Plugin, since it allows the server to cleanly catch the exception and transmit it to the client. Upon receiving the exception, the client will raise it, thus emulating a ‘local’ behavior.
Enumeration of error types |
|
Exception raised by Plugins |
|
Exception raised by QPUs |
Some additional information is packed inside the exception, taking the form of a file name and a line number. Additionally, exceptions come with an error code that characterizes the type of error that appeared inside the Plugin/QPU:
from qat.lang.AQASM import Program, RZ
from qat.qpus import CLinalg
from qat.comm.exceptions.ttypes import QPUException
prog = Program()
qbits = prog.qalloc(1)
RZ(0.4)(qbits)
circuit = prog.to_circ(include_matrices=False)
job = circuit.to_job()
try:
result = CLinalg().submit(job)
except QPUException as excp:
print(excp)
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ImportError: cannot import name 'CLinalg' from 'qat.qpus' (/var/lib/jenkins/workspace/dqlm-tutorial-doc_rc/runtime_linux-x86_64_cpython_python39/usr/local/lib64/python3.9/qaptiva-packages/qat/modules/__init__.so)
Here code \(14\) means that the simulator encountered a non supported gate (here a gate with no matrix).
Another useful code is the one raised when a break instruction is triggered:
from qat.lang.AQASM import Program
from qat.qpus import get_default_qpu
from qat.comm.exceptions.ttypes import QPUException
prog = Program()
qbits = prog.qalloc(1)
cbits = prog.calloc(1)
prog.measure(qbits[0], cbits[0])
prog.cbreak(~cbits[0])
circuit = prog.to_circ()
job = circuit.to_job()
try:
result = get_default_qpu().submit(job)
except QPUException as excp:
print(excp)
QPUException(code=2, modulename='qat.pylinalg', message="The option 'nbshots = 0' is incompatible with a circuit containing intermediate measurements", file=None, line=None)
Code \(10\) will always refer to a triggered break instruction.