gpridge.errors ============== .. py:module:: gpridge.errors .. autoapi-nested-parse:: Exception hierarchy for GPRidge. Every error the library raises on purpose derives from :class:`GPRidgeError`. The subclasses mirror the ``GPR_ERR_*`` status codes of the C API (``gpr/capi/gpridge_c.h``) and carry the code as :attr:`GPRidgeError.status`, so one classification serves C, C++ and Python callers. Each subclass also derives from the built-in exception that the same failure raised before this hierarchy existed (``ValueError`` for a bad argument, ``RuntimeError`` for a failed computation, ``MemoryError`` for an allocation failure), so an ``except ValueError`` or ``except RuntimeError`` written against older releases keeps catching it. The compiled ``_core`` extension translates C++ exceptions with the same rules as ``status_from_exception`` in ``gpridge_c.cpp``: ==================================== ========================= C++ exception Python exception ==================================== ========================= ``std::bad_alloc`` :class:`AllocationError` ``std::length_error`` :class:`SizeLimitError` ``std::invalid_argument`` :class:`InvalidArgumentError` ``std::domain_error`` :class:`InvalidArgumentError` any other ``std::exception`` :class:`InternalError` ==================================== ========================= The ctypes bridge to ``libgpr_engine`` (:mod:`gpridge.engine`) speaks the rgpot engine ABI, whose status codes are not the ``GPR_ERR_*`` set; its failures raise :class:`EngineError` with the engine's return code. This module imports nothing compiled, so it is available even when the ``_core`` extension is not. Exceptions ---------- .. autoapisummary:: gpridge.errors.GPRidgeError gpridge.errors.NullHandleError gpridge.errors.InvalidArgumentError gpridge.errors.NotTrainedError gpridge.errors.AllocationError gpridge.errors.CholeskyError gpridge.errors.OptimizerError gpridge.errors.NotConvergedError gpridge.errors.SizeLimitError gpridge.errors.OracleError gpridge.errors.UnsupportedError gpridge.errors.ABIError gpridge.errors.OutOfSupportError gpridge.errors.UnitMismatchError gpridge.errors.InternalError gpridge.errors.EngineError Functions --------- .. autoapisummary:: gpridge.errors.error_for_status gpridge.errors.status_name Module Contents --------------- .. py:exception:: GPRidgeError Bases: :py:obj:`Exception` Base class of every error GPRidge raises on purpose. ``status`` is the matching ``GPR_ERR_*`` code (``0`` when the error has no C counterpart) and ``status_name`` its symbolic name. .. py:attribute:: status :type: int :value: 0 .. py:attribute:: status_name :type: str :value: '' .. py:exception:: NullHandleError Bases: :py:obj:`GPRidgeError`, :py:obj:`ValueError` ``GPR_ERR_NULL_HANDLE``: a required handle or object was absent. .. py:attribute:: status :value: -1 .. py:attribute:: status_name :value: 'GPR_ERR_NULL_HANDLE' .. py:exception:: InvalidArgumentError Bases: :py:obj:`GPRidgeError`, :py:obj:`ValueError` ``GPR_ERR_INVALID_ARG``: a size, shape, key or value out of range. .. py:attribute:: status :value: -2 .. py:attribute:: status_name :value: 'GPR_ERR_INVALID_ARG' .. py:exception:: NotTrainedError Bases: :py:obj:`GPRidgeError`, :py:obj:`ValueError` ``GPR_ERR_NOT_TRAINED``: the model has no training data. A ``ValueError``, as ``get_alpha`` on an untrained model raised before. .. py:attribute:: status :value: -3 .. py:attribute:: status_name :value: 'GPR_ERR_NOT_TRAINED' .. py:exception:: AllocationError Bases: :py:obj:`GPRidgeError`, :py:obj:`MemoryError` ``GPR_ERR_ALLOC``: a memory allocation failed. .. py:attribute:: status :value: -4 .. py:attribute:: status_name :value: 'GPR_ERR_ALLOC' .. py:exception:: CholeskyError Bases: :py:obj:`GPRidgeError`, :py:obj:`RuntimeError` ``GPR_ERR_CHOLESKY``: the covariance matrix is not positive definite. .. py:attribute:: status :value: -5 .. py:attribute:: status_name :value: 'GPR_ERR_CHOLESKY' .. py:exception:: OptimizerError Bases: :py:obj:`GPRidgeError`, :py:obj:`RuntimeError` ``GPR_ERR_OPTIMIZER``: the hyperparameter optimizer failed. .. py:attribute:: status :value: -6 .. py:attribute:: status_name :value: 'GPR_ERR_OPTIMIZER' .. py:exception:: NotConvergedError Bases: :py:obj:`GPRidgeError`, :py:obj:`RuntimeError` ``GPR_ERR_NOT_CONVERGED``: a search ended without converging. .. py:attribute:: status :value: -7 .. py:attribute:: status_name :value: 'GPR_ERR_NOT_CONVERGED' .. py:exception:: SizeLimitError Bases: :py:obj:`GPRidgeError`, :py:obj:`ValueError` ``GPR_ERR_SIZE_LIMIT``: the problem exceeds an index limit. .. py:attribute:: status :value: -8 .. py:attribute:: status_name :value: 'GPR_ERR_SIZE_LIMIT' .. py:exception:: OracleError Bases: :py:obj:`GPRidgeError`, :py:obj:`RuntimeError` ``GPR_ERR_ORACLE``: the oracle failed past the search's bound. .. py:attribute:: status :value: -9 .. py:attribute:: status_name :value: 'GPR_ERR_ORACLE' .. py:exception:: UnsupportedError Bases: :py:obj:`GPRidgeError`, :py:obj:`NotImplementedError` ``GPR_ERR_UNSUPPORTED``: the feature is absent from this build. .. py:attribute:: status :value: -10 .. py:attribute:: status_name :value: 'GPR_ERR_UNSUPPORTED' .. py:exception:: ABIError Bases: :py:obj:`GPRidgeError`, :py:obj:`RuntimeError` ``GPR_ERR_ABI``: header and library disagree. .. py:attribute:: status :value: -11 .. py:attribute:: status_name :value: 'GPR_ERR_ABI' .. py:exception:: OutOfSupportError Bases: :py:obj:`GPRidgeError`, :py:obj:`ValueError` ``GPR_ERR_OUT_OF_SUPPORT``: a query's posterior energy standard deviation exceeds the caller's ``max_energy_std``. .. py:attribute:: status :value: -12 .. py:attribute:: status_name :value: 'GPR_ERR_OUT_OF_SUPPORT' .. py:exception:: UnitMismatchError Bases: :py:obj:`GPRidgeError`, :py:obj:`ValueError` ``GPR_ERR_UNIT_MISMATCH``: inputs that must share a unit were computed in different ones, such as prefactor halves with different ``omega_scale``. .. py:attribute:: status :value: -13 .. py:attribute:: status_name :value: 'GPR_ERR_UNIT_MISMATCH' .. py:exception:: InternalError Bases: :py:obj:`GPRidgeError`, :py:obj:`RuntimeError` ``GPR_ERR_INTERNAL``: any other failure inside the library. .. py:attribute:: status :value: -99 .. py:attribute:: status_name :value: 'GPR_ERR_INTERNAL' .. py:exception:: EngineError(message: str, code: int | None = None) Bases: :py:obj:`GPRidgeError`, :py:obj:`RuntimeError` A failure reported by ``libgpr_engine`` over the rgpot engine ABI. ``code`` is the engine's return value (``None`` when the call returned a null handle instead of a code). .. py:attribute:: status_name :value: 'RGPOT_ENGINE_ERROR' .. py:attribute:: code :value: None .. py:function:: error_for_status(status: int) -> type[GPRidgeError] The exception class for a ``GPR_ERR_*`` code. Unknown codes map to :class:`InternalError`, as the C API reports them. .. py:function:: status_name(status: int) -> str Short static name of a ``GPR_*`` status code (``gpr_status_name``).