gpridge.errors

Exception hierarchy for GPRidge.

Every error the library raises on purpose derives from GPRidgeError. The subclasses mirror the GPR_ERR_* status codes of the C API (gpr/capi/gpridge_c.h) and carry the code as 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

AllocationError

std::length_error

SizeLimitError

std::invalid_argument

InvalidArgumentError

std::domain_error

InvalidArgumentError

any other std::exception

InternalError

The ctypes bridge to libgpr_engine (gpridge.engine) speaks the rgpot engine ABI, whose status codes are not the GPR_ERR_* set; its failures raise EngineError with the engine’s return code.

This module imports nothing compiled, so it is available even when the _core extension is not.

Exceptions

GPRidgeError

Base class of every error GPRidge raises on purpose.

NullHandleError

GPR_ERR_NULL_HANDLE: a required handle or object was absent.

InvalidArgumentError

GPR_ERR_INVALID_ARG: a size, shape, key or value out of range.

NotTrainedError

GPR_ERR_NOT_TRAINED: the model has no training data.

AllocationError

GPR_ERR_ALLOC: a memory allocation failed.

CholeskyError

GPR_ERR_CHOLESKY: the covariance matrix is not positive definite.

OptimizerError

GPR_ERR_OPTIMIZER: the hyperparameter optimizer failed.

NotConvergedError

GPR_ERR_NOT_CONVERGED: a search ended without converging.

SizeLimitError

GPR_ERR_SIZE_LIMIT: the problem exceeds an index limit.

OracleError

GPR_ERR_ORACLE: the oracle failed past the search's bound.

UnsupportedError

GPR_ERR_UNSUPPORTED: the feature is absent from this build.

ABIError

GPR_ERR_ABI: header and library disagree.

OutOfSupportError

GPR_ERR_OUT_OF_SUPPORT: a query's posterior energy standard

UnitMismatchError

GPR_ERR_UNIT_MISMATCH: inputs that must share a unit were

InternalError

GPR_ERR_INTERNAL: any other failure inside the library.

EngineError

A failure reported by libgpr_engine over the rgpot engine ABI.

Functions

error_for_status(→ type[GPRidgeError])

The exception class for a GPR_ERR_* code.

status_name(→ str)

Short static name of a GPR_* status code (gpr_status_name).

Module Contents

exception gpridge.errors.GPRidgeError

Bases: 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.

status: int = 0
status_name: str = ''
exception gpridge.errors.NullHandleError

Bases: GPRidgeError, ValueError

GPR_ERR_NULL_HANDLE: a required handle or object was absent.

status = -1
status_name = 'GPR_ERR_NULL_HANDLE'
exception gpridge.errors.InvalidArgumentError

Bases: GPRidgeError, ValueError

GPR_ERR_INVALID_ARG: a size, shape, key or value out of range.

status = -2
status_name = 'GPR_ERR_INVALID_ARG'
exception gpridge.errors.NotTrainedError

Bases: GPRidgeError, ValueError

GPR_ERR_NOT_TRAINED: the model has no training data.

A ValueError, as get_alpha on an untrained model raised before.

status = -3
status_name = 'GPR_ERR_NOT_TRAINED'
exception gpridge.errors.AllocationError

Bases: GPRidgeError, MemoryError

GPR_ERR_ALLOC: a memory allocation failed.

status = -4
status_name = 'GPR_ERR_ALLOC'
exception gpridge.errors.CholeskyError

Bases: GPRidgeError, RuntimeError

GPR_ERR_CHOLESKY: the covariance matrix is not positive definite.

status = -5
status_name = 'GPR_ERR_CHOLESKY'
exception gpridge.errors.OptimizerError

Bases: GPRidgeError, RuntimeError

GPR_ERR_OPTIMIZER: the hyperparameter optimizer failed.

status = -6
status_name = 'GPR_ERR_OPTIMIZER'
exception gpridge.errors.NotConvergedError

Bases: GPRidgeError, RuntimeError

GPR_ERR_NOT_CONVERGED: a search ended without converging.

status = -7
status_name = 'GPR_ERR_NOT_CONVERGED'
exception gpridge.errors.SizeLimitError

Bases: GPRidgeError, ValueError

GPR_ERR_SIZE_LIMIT: the problem exceeds an index limit.

status = -8
status_name = 'GPR_ERR_SIZE_LIMIT'
exception gpridge.errors.OracleError

Bases: GPRidgeError, RuntimeError

GPR_ERR_ORACLE: the oracle failed past the search’s bound.

status = -9
status_name = 'GPR_ERR_ORACLE'
exception gpridge.errors.UnsupportedError

Bases: GPRidgeError, NotImplementedError

GPR_ERR_UNSUPPORTED: the feature is absent from this build.

status = -10
status_name = 'GPR_ERR_UNSUPPORTED'
exception gpridge.errors.ABIError

Bases: GPRidgeError, RuntimeError

GPR_ERR_ABI: header and library disagree.

status = -11
status_name = 'GPR_ERR_ABI'
exception gpridge.errors.OutOfSupportError

Bases: GPRidgeError, ValueError

GPR_ERR_OUT_OF_SUPPORT: a query’s posterior energy standard deviation exceeds the caller’s max_energy_std.

status = -12
status_name = 'GPR_ERR_OUT_OF_SUPPORT'
exception gpridge.errors.UnitMismatchError

Bases: GPRidgeError, ValueError

GPR_ERR_UNIT_MISMATCH: inputs that must share a unit were computed in different ones, such as prefactor halves with different omega_scale.

status = -13
status_name = 'GPR_ERR_UNIT_MISMATCH'
exception gpridge.errors.InternalError

Bases: GPRidgeError, RuntimeError

GPR_ERR_INTERNAL: any other failure inside the library.

status = -99
status_name = 'GPR_ERR_INTERNAL'
exception gpridge.errors.EngineError(message: str, code: int | None = None)

Bases: GPRidgeError, 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).

status_name = 'RGPOT_ENGINE_ERROR'
code = None
gpridge.errors.error_for_status(status: int) → type[GPRidgeError]

The exception class for a GPR_ERR_* code.

Unknown codes map to InternalError, as the C API reports them.

gpridge.errors.status_name(status: int) → str

Short static name of a GPR_* status code (gpr_status_name).