Skip to content

Errors

Exception and warning classes raised by mechestim. See Common Errors for symptoms and fixes.

Class Type When raised
MechEstimError Exception (base) Base class for all mechestim exceptions
BudgetExhaustedError Exception Operation would exceed remaining FLOP budget
NoBudgetContextError Exception No active budget (rare — global default usually prevents this)
SymmetryError Exception Tensor data is not symmetric within tolerance
MechEstimWarning Warning (base) Base class for all mechestim warnings
SymmetryLossWarning Warning An operation caused loss of symmetry metadata

API Reference

mechestim.errors

Exception and warning classes for mechestim.

BudgetExhaustedError

Bases: MechEstimError

Raised when an operation would exceed the FLOP budget.

Source code in src/mechestim/errors.py
class BudgetExhaustedError(MechEstimError):
    """Raised when an operation would exceed the FLOP budget."""

    def __init__(self, op_name: str, *, flop_cost: int, flops_remaining: int):
        self.op_name = op_name
        self.flop_cost = flop_cost
        self.flops_remaining = flops_remaining
        super().__init__(
            f"{op_name} would cost {flop_cost:,} FLOPs but only "
            f"{flops_remaining:,} remain. "
            f"See: {_DOCS_BASE}/#budgetexhaustederror"
        )

MechEstimError

Bases: Exception

Base exception for all mechestim errors.

Source code in src/mechestim/errors.py
class MechEstimError(Exception):
    """Base exception for all mechestim errors."""

MechEstimWarning

Bases: UserWarning

Warning issued when mechestim detects potential numerical issues.

Source code in src/mechestim/errors.py
class MechEstimWarning(UserWarning):
    """Warning issued when mechestim detects potential numerical issues."""

NoBudgetContextError

Bases: MechEstimError

Raised when a counted operation is called outside a BudgetContext.

Source code in src/mechestim/errors.py
class NoBudgetContextError(MechEstimError):
    """Raised when a counted operation is called outside a BudgetContext."""

    def __init__(self):
        super().__init__(
            "No active BudgetContext. "
            "Wrap your code in `with mechestim.BudgetContext(...):`  "
            f"See: {_DOCS_BASE}/#nobudgetcontexterror"
        )

SymmetryError

Bases: MechEstimError

Raised when a claimed tensor symmetry does not hold.

Source code in src/mechestim/errors.py
class SymmetryError(MechEstimError):
    """Raised when a claimed tensor symmetry does not hold."""

    def __init__(
        self,
        axes: tuple[int, ...],
        max_deviation: float,
        atol: float = 1e-6,
        rtol: float = 1e-5,
    ):
        self.axes = axes
        self.max_deviation = max_deviation
        self.atol = atol
        self.rtol = rtol
        super().__init__(
            f"Tensor not symmetric along axes ({', '.join(str(d) for d in axes)}): "
            f"max deviation = {max_deviation} "
            f"(tolerance: atol={atol}, rtol={rtol}). "
            f"See: {_DOCS_BASE}/#symmetryerror"
        )

SymmetryLossWarning

Bases: MechEstimWarning

Warning issued when an operation causes loss of symmetry metadata.

Source code in src/mechestim/errors.py
class SymmetryLossWarning(MechEstimWarning):
    """Warning issued when an operation causes loss of symmetry metadata."""