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.

qat.comm.exceptions.ttypes.ErrorType

Enumeration of error types

qat.comm.exceptions.ttypes.GeneratorException

Exception raised by BatchGenerators

qat.comm.exceptions.ttypes.PluginException

Exception raised by Plugins

qat.comm.exceptions.ttypes.QPUException

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 12, in <module>
  File "qat/core/qpu/qpu.py", line 240, in qat.core.qpu.qpu.CommonQPU.submit
  File "qat/core/qpu/qpu.py", line 243, in qat.core.qpu.qpu.CommonQPU.submit
  File "/usr/local/lib/python3.12/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "qat/pybindlinalg/base_qpu.py", line 540, in qat.pybindlinalg.base_qpu.PybindLinAlg._submit_batch
  File "qat/core/qpu/qpu.py", line 166, in qat.core.qpu.qpu.CommonQPU._submit_batch
  File "qat/pybindlinalg/base_qpu.py", line 97, in qat.pybindlinalg.base_qpu.license_context.new_submit_job
  File "/usr/local/lib/python3.12/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "qat/pybindlinalg/base_qpu.py", line 85, in _allocate_license
RuntimeError: No temporary license file found

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)
Traceback (most recent call last):
  File "qat/core/junction.py", line 85, in qat.core.junction.Junction._submit_batch
  File "qat/core/optimizer.py", line 131, in qat.core.optimizer.Optimizer.run
  File "qat/core/qpu/qpu.py", line 240, in qat.core.qpu.qpu.CommonQPU.submit
  File "qat/core/qpu/qpu.py", line 243, in qat.core.qpu.qpu.CommonQPU.submit
  File "/usr/local/lib/python3.12/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "qat/pybindlinalg/base_qpu.py", line 540, in qat.pybindlinalg.base_qpu.PybindLinAlg._submit_batch
  File "qat/core/qpu/qpu.py", line 166, in qat.core.qpu.qpu.CommonQPU._submit_batch
  File "qat/pybindlinalg/base_qpu.py", line 97, in qat.pybindlinalg.base_qpu.license_context.new_submit_job
  File "/usr/local/lib/python3.12/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "qat/pybindlinalg/base_qpu.py", line 85, in _allocate_license
RuntimeError: No temporary license file found

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 14, in <module>
  File "qat/core/qpu/qpu.py", line 240, in qat.core.qpu.qpu.CommonQPU.submit
  File "qat/core/qpu/qpu.py", line 243, in qat.core.qpu.qpu.CommonQPU.submit
  File "qat/core/junction.py", line 102, in qat.core.junction.Junction._submit_batch
qat.comm.exceptions.ttypes.PluginException: PluginException(code=None, modulename='qat.plugins.junction', message='Caught exception from junction: "No temporary license file found" [see /tmp/tmph9qb6qrh.junction.log for traceback info]', file=None, line=None)

Code \(10\) will always refer to a triggered break instruction.