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 LinAlg
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 = LinAlg().submit(job)
except QPUException as excp:
print(excp)
QPUException(code=14, modulename='qat.linalg', message='The Gate :_0 cannot be computed! Maybe the matrix is missing?', file='/var/lib/jenkins/workspace/qat-linalg_rc/qat-linalg/src/simulator.cpp', line=742)
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=1, modulename=None, message="The option 'nbshots = 0' is incompatible with a circuit containing intermediate measurements", file='qpu_server.h', line=759)
Code \(10\) will always refer to a triggered break instruction.