Repository navigation
Expand file tree
/
Copy patherrors.py
More file actions
45 lines (27 loc) · 1.35 KB
/
Copy patherrors.py
File metadata and controls
45 lines (27 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Error hierarchy for optcon.
Every failure mode that this library is supposed to *catch* gets its own
exception class, so that callers can distinguish "your physics is wrong" from
"your code is wrong".
"""
from __future__ import annotations
class OptConError(Exception):
"""Base class for every optcon failure."""
class UnitError(OptConError):
"""A unit name is unknown or a unit expression is malformed."""
class DimensionError(OptConError):
"""Two quantities with incompatible dimensions were combined."""
class AmplitudeOrderError(OptConError):
"""A field amplitude and a power-like quantity were combined directly.
``transmission`` and ``sqrt(transmission)`` are not interchangeable; this
error is raised when the algebra proves they were mixed.
"""
class ContractViolation(OptConError):
"""A declared physical contract does not hold."""
class AdjointCheckFailure(ContractViolation):
"""A supplied adjoint/derivative disagrees with finite differences."""
class EvidenceGateFailure(ContractViolation):
"""A numerical result lacks evidence required for a declared decision."""
def __init__(self, failed_requirements: tuple[str, ...]):
self.failed_requirements = tuple(failed_requirements)
names = ", ".join(self.failed_requirements)
super().__init__(f"decision evidence is incomplete: {names}")