Error codes and exceptions#

In a notebook or Python script, SMEW reports numerical failures automatically as SMEWError. Its code.name identifies the problem and its message gives the conditions at which it occurred. See When a simulation fails for troubleshooting.

For repeated simulations, save the error name and message with the scenario inputs so that you can identify and investigate failed runs later.

Calling from your own compiled model#

This section is only needed when calling SMEW inside another Numba function. The functions biogeochem_balance_numba, respiration_numba, conc_to_f_CEC_numba and total_to_f_CEC_and_conc_numba return (result, code, message) instead of raising an error directly.

Code 0 means success; a nonzero code means failure and result is None. Return the code and message to ordinary Python, then call smew.raise_for_error(code, message) there. Initialization functions can also return a warning message with code 0; this should be reported separately.

Python reference#

Model error codes and Python exceptions.

Compiled entry points return (result, error_code, error_message). Never renumber or reuse a published code. Raise only at the Python boundary.

class smew.errors.ErrorCode(value)[source]#
OK = 0#
WATER_ALK_RESIDUAL = 1001#
WATER_ALK_SOLVER_INPUT = 1002#
CHEMISTRY_RESIDUAL = 1011#
CHEMISTRY_SOLVER_INPUT = 1012#
CHEMISTRY_RETRY_RESIDUAL = 1021#
CHEMISTRY_RETRY_SOLVER_INPUT = 1022#
CHEMISTRY_NO_CONVERGENCE = 1023#
BIOGEOCHEM_INSUFFICIENT_CATIONS = 1101#
BIOGEOCHEM_MISSING_PORES = 1102#
RESPIRATION_INITIAL_ACTIVITY = 2001#
RESPIRATION_MEAN_ACTIVITY = 2002#
CEC_RESIDUAL = 3001#
CEC_SOLVER_INPUT = 3002#
TOTAL_CEC_RESIDUAL = 3011#
TOTAL_CEC_SOLVER_INPUT = 3012#
F_CEC_ALK_TO_CONC_RESIDUAL = 3021#
F_CEC_ALK_TO_CONC_SOLVER_INPUT = 3022#
WEATHERING_ERROR = 4001#
VEGETATION_CAPACITY = 5001#
VEGETATION_INITIAL_FRACTION = 5002#
VEGETATION_STAGE = 5003#
VEGETATION_STAGE_ORDER = 5004#
VEGETATION_GROWTH = 5005#
exception smew.errors.SMEWError(code, message)[source]#

Model failure with a globally unique code and a complete debug message.

exception smew.errors.SMEWValueError(code, message)[source]#

Model input or convergence error; remains catchable as ValueError.

exception smew.errors.SMEWSolverError(code, message)[source]#

Invalid solver residual; remains catchable as RuntimeError.

smew.errors.raise_for_error(code, message)[source]#

Raise a Python exception after the compiled calculation has returned.