This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
axtreme is a Python library extending Ax (Facebook's Adaptive Experimentation) and BoTorch (Bayesian Optimization in PyTorch) for design of experiments, active learning, and extreme response analysis. It targets reliability engineering scenarios like estimating 50-year storm loads from surrogate models.
uv sync # Install all dependencies (dev included)
uv sync --extra cuda # With CUDA support
uv sync --extra examples # With example dependencies (openturns, numba)
uv run pre-commit install # Setup pre-commit hooks
# Testing
uv run pytest # Run all tests
uv run pytest tests/path/test_file.py::test_name # Single test
uv run pytest -m "not system" # Skip long-running system tests
uv run pytest --cov # With coverage
# Linting & Formatting
uv run ruff format # Format code
uv run ruff check --fix # Lint with auto-fix
uv run pyright # Type checking (primary)
uv run mypy # Type checking (secondary)
uv run pre-commit run --all-files # Run all checks (ruff, pyright, mypy)The codebase is designed around three key protocols that define the extension points:
Simulator(simulator/base.py):__call__(x: ndarray[n_points, n_dims], n_simulations_per_point) -> ndarray[n_points, n_sims, n_outputs]-- wraps any simulation model.QoIEstimator(qoi/qoi_estimator.py):__call__(model: Model) -> Tensor[n_estimates]-- estimates a scalar quantity of interest from a BoTorch surrogate model. Hasmean()andvar()methods for aggregation (overridable for special samplers like UT).PosteriorSampler(sampling/base.py):__call__(posterior: GPyTorchPosterior) -> Tensor-- draws samples from GP posteriors with different strategies.
- Experiment setup (
experiment.py): Create Ax Experiment, initialize with Sobol points - Simulation (
evaluation.py):EvaluationFunctionwraps aSimulator, runs it, fits a distribution (Gumbel) to outputs ->SimulationPointResults - Ax integration (
runner.py+metrics.py):LocalMetadataRunnerexecutes evaluation, stores results in trial metadata;LocalMetadataMetricfetches them back - Surrogate model: Ax/BoTorch fits a GP to collected data
- QoI estimation (
qoi/): EitherGPBruteForce(full-period simulation) orMarginalCDFExtrapolation(CDF^N extrapolation) estimates the extreme response quantity - Acquisition (
acquisition/qoi_look_ahead.py):QoILookAheaduses fantasy models to select the next point that most reduces QoI variance - Repeat from step 2
qoi/: Two strategies for extreme value estimation.GPBruteForcesimulates all timesteps per period.MarginalCDFExtrapolationapproximates via single-timestep CDF raised to power N -- much faster for large N.sampling/:MeanSampler(no uncertainty),IndependentMCSampler(diagonalizes cross-point covariance),NormalIndependentSampler,UTSampler(unscented transform, needs custom mean/var).distributions/:ApproximateMixture(conservative tail extrapolation for safety-critical use),icdf(inverse CDF via root-finding for distributions without analytic inverse).data/: PyTorch Dataset/Sampler wrappers includingNumpyFileDataset(memory-mapped), importance sampling support, custom batch samplers.utils/transforms.py: Converts Ax transforms to BoTorch space so models can operate in problem space rather than Ax's normalized space.eval/:QoIJob/QoIJobResultfor organizing and serializing QoI evaluation runs.
*b: batch dimensions (arbitrary)n: number of input pointsm: output dimensionality- GP posterior shape:
(*b, n, m)
- Formatter/Linter: Ruff (configured in
ruff.toml). Selects ALL rules then ignores specific ones. - Line length: 120 characters
- Docstrings: Follow Google style.
- Type hints: Required on all functions. Pyright in basic mode with strict-ish overrides. Stubs in
stubs/directory for untyped third-party libraries. - Imports: Absolute only (no relative imports). Grouped: stdlib, third-party, local.
- Test markers:
integration,external,system(very long),non_deterministic. Tests mirrorsrc/structure. - TODOs: Use
# @TODO: Description. AUTHOR, YYYY-MM-DDformat.
- numpy < 2.0: Pinned for compatibility with the scipy/torch/botorch ecosystem.
- ax-platform == 0.3.7: Pinned exact version; Ax APIs can change significantly between versions.
- Single output only: Multi-output GP support is not yet implemented across the QoI pipeline.