Skip to content

AdamStoppingConfig

from cascaqit import AdamStoppingConfig

AdamStoppingConfig

AdamStoppingConfig(
    window_size: int = 3,
    min_iterations: int = 3,
    update_norm_tolerance: float = 0.0001,
    gradient_uncertainty_norm_tolerance: float
    | None = None,
    schema_version: str = ADAM_SCHEMA_VERSION,
)

Stop Adam when consecutive parameter updates are small. window_size must be at least 2, min_iterations must be at least window_size, and update_norm_tolerance must be positive. Once enough iterations have completed, every projected update norm in the latest window must be at or below the threshold.

Optional gradient_uncertainty_norm_tolerance must be positive. When enabled, every gradient uncertainty norm in the same window must also meet its threshold. This limits estimation uncertainty, not gradient magnitude. GradientConfig controls repeated gradient estimation.

This is an engineering stopping condition, not proof of global optimality. Bound projection can also shrink updates; inspect stopping records, gradients and energy history together.

from cascaqit import AdamConfig, AdamStoppingConfig

stopping = AdamStoppingConfig(window_size=2, min_iterations=3,
                              update_norm_tolerance=1e-4)
assert AdamConfig(stopping=stopping).stopping == stopping
assert AdamStoppingConfig.from_json(stopping.to_json()) == stopping
assert "gradient_uncertainty_norm_tolerance" not in stopping.to_dict()

from_dict

from_dict(data: Mapping[str, Any]) -> AdamStoppingConfig

Restore AdamStoppingConfig from a dictionary. Omitted fields use defaults; nested configurations are restored and validated. Missing required fields or invalid values can raise KeyError, TypeError or ValueError.

from_json

from_json(text: str) -> AdamStoppingConfig

Parse a JSON object and call from_dict(), returning AdamStoppingConfig. Invalid JSON raises a parsing error; a non-object root raises TypeError.

to_dict

to_dict() -> dict[str, Any]

gradient_uncertainty_norm_tolerance is omitted when disabled. Return a JSON-compatible dictionary, serializing nested objects and converting tuples to arrays. This stores the declaration, not an execution result.

to_json

to_json(*, indent: int | None = None) -> str

Return a JSON string without writing a file. indent=None uses compact formatting; supply an indentation width for readable output.

stable_hash

stable_hash() -> str

Return the SHA-256 hex digest of canonical JSON. Fields, identifiers and metadata can affect it. Use it to compare saved content, not to decide physical equivalence.