Source code for pnps.exceptions
# SPDX-FileCopyrightText: 2026 John C. Travers and contributors
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""The exception and warning hierarchies.
Every error raised by this package is a :class:`PnpsError` and every warning it emits
is a :class:`PnpsWarning`, so callers can catch or filter the whole family with one
clause and still tell the cases apart. Each error also derives from the built-in
exception it refines (:class:`ValueError` for a bad argument, :class:`RuntimeError`
for a failed run), so code written against the built-ins keeps working. Raise the
most specific subclass; never raise a bare :class:`Exception`.
solprop's own errors (:class:`solprop.exceptions.SolpropError`) pass through
unchanged: they describe the engine, not the instrument.
"""
__all__ = [
"ConfigError",
"DelayError",
"EngineError",
"GridError",
"GridRuleError",
"InstrumentError",
"MaterialError",
"PnpsError",
"PnpsWarning",
"PulseError",
"PulseFileError",
"ReductionError",
"ScanError",
"ThreadBindingWarning",
"UnsupportedError",
"WindowOverlapWarning",
]
[docs]
class PnpsError(Exception):
"""Base class of every error this package raises."""
[docs]
class ConfigError(PnpsError, ValueError):
"""A configuration this package cannot build or run: a bad or missing setting."""
[docs]
class GridError(PnpsError, ValueError):
"""A time or transverse grid that cannot be built from the given limits."""
[docs]
class GridRuleError(GridError):
"""The grids solprop builds no longer reproduce this package's grids."""
[docs]
class MaterialError(PnpsError, ValueError):
"""A material model asked for outside what it can evaluate."""
[docs]
class InstrumentError(PnpsError, ValueError):
"""An instrument part (beam, mask hole, collection window) that is not valid."""
[docs]
class PulseError(PnpsError, ValueError):
"""An input pulse that cannot be built, prepared or measured."""
[docs]
class PulseFileError(PulseError, TypeError):
"""A pulse file whose datasets are missing or of the wrong kind."""
[docs]
class DelayError(PnpsError, TypeError, ValueError):
"""A delay that is not a scalar, or that lies outside the protected headroom."""
[docs]
class ReductionError(PnpsError, ValueError):
"""A saved plane that cannot be reduced to the observables as asked."""
[docs]
class ScanError(PnpsError, ValueError):
"""A scan, shard selection or scan file that is not consistent."""
[docs]
class EngineError(PnpsError, RuntimeError):
"""A run on solprop that went wrong: a broken invariant or a missing part."""
[docs]
class UnsupportedError(PnpsError, NotImplementedError):
"""A feature this package does not provide (yet); the message says why."""
[docs]
class PnpsWarning(UserWarning):
"""Base class of every warning this package emits."""
[docs]
class ThreadBindingWarning(PnpsWarning):
"""OpenMP thread binding had confined the process's main thread to one CPU.
With ``OMP_PROC_BIND`` set, starting solprop's native backend binds the main thread
to its first place; numba's pool and solprop's march then run on that one CPU.
This package restores the thread's CPUs and emits this warning; leave
``OMP_PROC_BIND`` and ``OMP_PLACES`` unset to avoid both (see the manual's
clusters page).
"""
[docs]
class WindowOverlapWarning(PnpsWarning):
"""An exact collection window overlaps the far field of an input hole.
With ``Config.exact_windows`` a window collects only the nonlinear part of the
field, so the transmitted input light a detector behind that window would also
see is left out of its spectra.
"""