diff --git a/.gitignore b/.gitignore index 37c8bf76..4cc1629c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # Data and configs *.toml +!examples/slac_fel/slac-fel-tutorial.toml +!examples/slac_fel/test_tomls/dec2025.toml # Logging files *.db @@ -19,6 +21,7 @@ data/* # Files *.png +!examples/slac_fel/figures/focused_drift_adaptation.png !docs/images/*.png *.txt !docs/requirements.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 35872eff..e621c54a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Reproducible SLAC-FEL scientific example with a focused December 2025 drift-adaptation tutorial, pretrained model and scalers, paper-style replay figure, full-month configuration, documentation, and tests - Community health files: `CONTRIBUTING.md` (including guidelines for AI/LLM-assisted contributions), `CODE_OF_CONDUCT.md`, `SECURITY.md`, and this changelog - GitHub issue templates for bug reports and feature requests @@ -44,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `ruff format` — and it carried three advisories. ### Fixed +- The configured experiment seed is now applied at startup to Python, NumPy, Torch, and CUDA, enabling deterministic scientific metrics and adapted checkpoints for repeat runs - `WandBLogger.url` called `Run.get_url()`, which wandb removed in the upgrade to 0.30; it raised `AttributeError`. It now reads the `Run.url` property, which exists across the whole supported range (`wandb>=0.22.0`). diff --git a/README.md b/README.md index f25c17e9..dd7bec81 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ From the project root: uv run python -m src.main --config examples/mnist/mnist.toml uv run python -m src.main --config examples/cifar/cifar10_vit.toml uv run python -m src.main --config examples/imagenet/imagenet_vit.toml # requires ImageNet data at data.path +uv run python -m src.main --config examples/slac_fel/slac-fel-tutorial.toml --set data.path=/path/to/fel-tutorial-data ``` ## Metrics Logging @@ -83,7 +84,7 @@ uv run python -m src.main --config examples/mnist/mnist.toml --set logging.backe # To view results for MLflow, run `mlflow ui` in another terminal and navigate to http://localhost:5000 ``` -Currently the mnist example sets the logging to wandb in the toml `config` file. The other examples do not set any metric for the logging backend, which defaults to wandb. +Logging is configured in the TOML `[logging]` section. The default backend is `"none"`; examples may opt into WandB or MLflow and may write long-format metrics to a local CSV file. ## Configuration Overview @@ -94,7 +95,7 @@ Primary sections in config TOML: - `[train]` - `[drift_detection]` - `[continual_learning]` (optional but recommended) -- `[visualization]` (optional) +- `[logging]` (optional; experiment tracking and CSV output) Top-level fields commonly used: @@ -200,7 +201,7 @@ See [`docs/architecture.md`](docs/architecture.md) for the full pipeline, includ - Update batch size and worker count with `[train] batch_size` and `[train] num_workers`. ## Output -The console logger reports per-stage metrics (`eval`, `drift`, `cl`). When `[visualization] input` is set, the run also writes a metrics CSV at that path for external plotting. +The console logger reports per-stage metrics (`eval`, `drift`, `cl`). Set `[logging] metrics_output_path` to write the same long-format metrics to a CSV file for external analysis and plotting. ## Deployment diff --git a/examples/README.md b/examples/README.md index 2fdcb3c4..6a5a2b72 100644 --- a/examples/README.md +++ b/examples/README.md @@ -18,9 +18,11 @@ uv run python -m src.main --config | [`mnist/`](mnist/README.md) | `mnist` | 3-layer CNN (`Cnn`, ~1M params) | Simulated: cumulative random affine per stream window | Auto-downloaded to `./data` | Yes — CPU is fine | | [`cifar/`](cifar/README.md) | `cifar10` | ViT-B/16 or VGG-11 (`VisionModelCifar`) | Simulated: random affine per stream window | Auto-downloaded to `./data` | GPU strongly recommended | | [`imagenet/`](imagenet/README.md) | `imagenet` | ViT-B/16 (`VisionModelImageNet`) | Simulated: cumulative random affine per stream window | **You provide** ILSVRC-2012 in `ImageFolder` layout | No — multi-GPU scale | +| [`slac_fel/`](slac_fel/README.md) | `slac-fel` | Pretrained fully connected surrogate | Measured: chronological accelerator operating regimes | **You provide** the focused 14-file FEL subset | Yes — CPU is fine | -**Start with `mnist/`.** It is the only example that ships a pretrained -checkpoint, downloads its own data, and finishes in minutes on CPU. +**Start with `mnist/`** for the simplest self-contained workflow. It +downloads its own data and finishes in minutes on CPU. Use `slac_fel/` +for a measured scientific stream after obtaining the focused dataset. ## How an Example Is Wired Up @@ -39,22 +41,16 @@ An example becomes runnable through three pieces: To add your own, mirror the MNIST layout and add a branch to `get_example()`. See [`docs/model_harness.md`](../docs/model_harness.md) for the full contract. -## How Drift Is Simulated +## Where Drift Comes From -None of these datasets drift on their own, so each harness manufactures drift the -same way: `update_data_stream()` draws a seeded random affine transform -(rotation / scale / shear / translation) and rebuilds the train, validation, and -stream loaders through it. Every time the stream is exhausted, another transform -is drawn, so the input distribution keeps moving away from what the model was -trained on and monitored accuracy degrades. +The computer-vision harnesses manufacture drift with seeded random affine +transformations such as rotation, scale, shear, and translation. MNIST and +ImageNet accumulate those transformations over time, while CIFAR applies a +fresh perturbation to each stream window. -MNIST and ImageNet **compose** the whole history of transforms (drift accumulates -and gets progressively worse); CIFAR applies only the most recent one (each -window is a fresh, independent perturbation). Historical replay loaders follow -the same convention — MNIST replays *every* prior regime, CIFAR replays only the -immediately preceding one. - -The number of windows is capped by `[drift_detection] max_stream_updates`. +The SLAC-FEL example instead consumes chronological accelerator observations. +Its drift signals arise from changes in the measured surrogate error, not from +synthetic input transformations. ## What Every Run Produces @@ -63,7 +59,7 @@ The number of windows is capped by `[drift_detection] max_stream_updates`. confidence, then a `CL Updates (drift_event_id=N)` bar and before/after test accuracy on both the current and historical distributions. - **CSV** — long-format `step,metric,value` at the path in - `[visualization] input` (e.g. `output/mnist.csv`). Metric names are stage + `[logging] metrics_output_path` (e.g. `output/mnist.csv`). Metric names are stage prefixed: `eval/*` (per-batch accuracy and loss, plus `test_curr_acc` and `test_hist_acc` after each CL round), `drift/*` (score, regime, confidence, the monitored metric), `cl/*` (per-iteration losses and FLOP/time counters). @@ -72,8 +68,8 @@ The number of windows is capped by `[drift_detection] max_stream_updates`. console + CSV. See [`docs/tracking.md`](../docs/tracking.md) for backend setup, the full metric namespace, and annotated screenshots of a run. -The package does not bundle a plotting step: `[visualization] input` is written -for you to chart externally. +The package does not bundle a common plotting step. Long-format CSV metrics are +written to `[logging] metrics_output_path` for external analysis and plotting. ## Common Overrides diff --git a/examples/slac_fel/README.md b/examples/slac_fel/README.md new file mode 100644 index 00000000..59d1e466 --- /dev/null +++ b/examples/slac_fel/README.md @@ -0,0 +1,232 @@ +# SLAC-FEL Scientific Example + +This example applies Apeiron to measured data from the Linac Coherent Light +Source free-electron laser (LCLS FEL) at SLAC. It demonstrates how to monitor a +pretrained scientific surrogate, detect a change in its prediction error, and +adapt the model to the changed operating regime. + +Unlike the computer-vision examples, this workflow does not manufacture drift +with image transformations. The stream consists of chronological accelerator +observations. + +## What the Model Predicts + +Each observation contains: + +- 341 accelerator state and control readbacks used as model inputs. +- One measured FEL pulse-energy target, + `GDET:FEE1:241:ENRC`, expressed in millijoules (mJ). +- A timestamp that preserves the experimental ordering. + +The pretrained neural-network surrogate maps the 341 accelerator variables to +the measured pulse energy. As accelerator conditions change, the relationship +learned by the surrogate may become less accurate. + +Apeiron monitors the model's mean absolute error (MAE). The focused tutorial +uses Page-Hinkley to identify a large error transition and then performs a +short online-EWC adaptation. + +## Tutorial Scope + +The focused tutorial uses 14 chronological files: + +```text +data_730.pkl +data_731.pkl +... +data_743.pkl +``` + +Together they contain 70,000 observations from December 2 through December 4, +2025. The major transition begins in `data_740.pkl`. + +The focused subset was selected because it provides: + +- a stable pre-transition period; +- one clear detector event; +- a substantial loss of accuracy under the pretrained model; +- measurable recovery after adaptation; +- a short CPU runtime; +- deterministic results under seed 42. + +The full December paper-reproduction configuration remains available at +`test_tomls/dec2025.toml`, but it is not required for this tutorial. + +## Repository Contents + +```text +examples/slac_fel/ +├── README.md +├── __init__.py +├── model.py +├── utils.py +├── slac-fel-tutorial.toml +├── model/ +│ ├── feature_config.yml +│ ├── final_lcls_fel_model.pt +│ ├── lcls_fel_input_scaler.pt +│ └── lcls_fel_output_scaler.pt +└── test_tomls/ + └── dec2025.toml +``` + +The pretrained model, feature definition, and scalers are included in the +repository. + +## Data Availability + +The permanent public hosting location for the focused dataset is still being +determined. Until that location is finalized, collaborators who already have +the data can place the 14 files in any local directory and provide that +directory at runtime. + +The tutorial does not require a fixed filesystem layout or storage service. + +## Run the Tutorial + +From the repository root, first install the locked environment: + +```bash +uv sync +``` + +Then run the tutorial: + +```bash +uv run python -m src.main \ + --config examples/slac_fel/slac-fel-tutorial.toml \ + --set data.path=/path/to/fel-tutorial-data +``` + +Output paths may also be overridden: + +```bash +uv run python -m src.main \ + --config examples/slac_fel/slac-fel-tutorial.toml \ + --set data.path=/path/to/fel-tutorial-data \ + --set model.ckpts_path=/path/to/run/checkpoints \ + --set logging.metrics_output_path=/path/to/run/metrics.csv +``` +The supplied configuration runs on CPU and uses: + +- seed 42; +- Page-Hinkley drift detection; +- a 10-observation detector warm-up; +- online EWC with historical replay; +- 200 adaptation updates; +- 13 stream updates after the initial window; +- detector reset after adaptation. + +## Expected Result + +A validated CPU run produces one drift event: + +```text +DRIFT DETECTED (Event #1) +``` + +The event occurs while processing `data_740.pkl`. Apeiron then completes 200 +continual-learning updates, saves `drift_adaptation_1.pt`, and resumes +monitoring through `data_743.pkl`. + +The exact pipeline step is 31 with the supplied configuration. The complete +run should process all 14 files once, without wrapping back to the first file. + +Typical artifacts are: + +```text +output/slac-fel/tutorial/ +├── metrics.csv +└── checkpoints/ + ├── drift_adaptation_1.pt + └── latest +``` + +Runtime depends on the machine. The validated CPU workflow finishes in well +under one minute. + +## Reproduce the Figure + +The focused paper-style replay is summarized below: + +![Focused SLAC-FEL drift-adaptation replay](figures/focused_drift_adaptation.png) + +The blue curve shows the original pretrained surrogate. The red curve uses +the pretrained model before the detected transition and the adapted checkpoint +from the beginning of the trigger window. The lower panel shows the +corresponding rolling absolute error. + +This is an offline segmented replay aligned with the paper analysis. It is +not a strict causal replay because the adapted checkpoint becomes available only +after the trigger window has been processed. + +Regenerate the figure after completing the tutorial run: + +```bash +uv run python -m examples.slac_fel.plot_tutorial \ + --data /path/to/fel-tutorial-data \ + --checkpoint output/slac-fel/tutorial/checkpoints/drift_adaptation_1.pt \ + --output examples/slac_fel/figures/focused_drift_adaptation.png +``` +## Interpreting the Result + +The tutorial demonstrates a real tradeoff rather than universal improvement. + +Across the changed regime, the static pretrained model has approximately +12.33 mJ MAE, while the adapted checkpoint has approximately 0.61 mJ MAE. +Adaptation therefore provides a large improvement after the transition. + +However, replaying the adapted checkpoint on the earlier stable regime +increases MAE from approximately 0.16 mJ to 0.55 mJ. The update improves the +new regime but does not preserve all historical behavior. + +This distinction is central to trustworthy adaptation: + +- a drift alert indicates statistical evidence of change; +- it does not establish the physical cause of that change; +- adaptation can improve current performance while degrading prior regimes; +- operational deployment may require additional scientific or safety checks + before an update is accepted. + +The example labels the event only as a detected change. It does not classify +the accelerator condition as normal, anomalous, unsafe, or adversarial. + +## How the Example Connects to Apeiron + +`model.py` implements the `BaseModelHarness` interface for the FEL surrogate. +It is responsible for: + +- loading the pretrained neural network and scalers; +- reading the chronological pickle files lazily; +- creating train, validation, stream, and replay loaders; +- converting scaled prediction error back to millijoules; +- constructing the optimizer used during adaptation. + +`utils.py` handles feature configuration, scaler loading, numeric file +ordering, and time-window construction. + +`slac-fel-tutorial.toml` contains the focused experiment parameters. The +external data location is supplied with `--set data.path=...`, so the tutorial +does not depend on a particular storage service or filesystem layout. + +## Implementation Provenance + +The FEL harness and December reproduction configuration were ported from +APEIRON commit +`5542efbb47fdfddbb0b3202beaa2ad4c68cc3bd2`, committed by Sara Miskovich +during the original SLAC-FEL paper-reproduction work. + +The feature configuration, pretrained model, and input and output scalers are +retained unchanged from that source commit. The focused configuration, +current-main compatibility updates, tests, documentation, and replay figure +were added for this tutorial. + +## Full December Reproduction + +The full configuration is: + +```text +examples/slac_fel/test_tomls/dec2025.toml +``` + +It expects 150 files, `data_699.pkl` through `data_848.pkl`. diff --git a/examples/slac_fel/__init__.py b/examples/slac_fel/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/examples/slac_fel/figures/focused_drift_adaptation.png b/examples/slac_fel/figures/focused_drift_adaptation.png new file mode 100644 index 00000000..161e04cf Binary files /dev/null and b/examples/slac_fel/figures/focused_drift_adaptation.png differ diff --git a/examples/slac_fel/model.py b/examples/slac_fel/model.py new file mode 100644 index 00000000..52ded207 --- /dev/null +++ b/examples/slac_fel/model.py @@ -0,0 +1,607 @@ +# examples/slac_fel/model.py +"""SLAC FEL model harness for the BaseSim continuous-learning framework. + +This harness wraps a 7-layer ELU regression network with dropout regularisation, +trained to predict HXR pulse intensity from accelerator settings. The pre-processed +accelerator data is chronologically sorted and sliced into time windows, +each of which is served in order by ``update_data_stream()``. +""" + +from __future__ import annotations + +import gc +import logging +import os +from typing import Any, List, Optional, Tuple + +import torch +import torch.nn.functional as F +from torch import Tensor, nn +from torch.optim import Optimizer +from torch.utils.data import ConcatDataset, DataLoader, WeightedRandomSampler + +from apeiron.config.configuration import Config +from apeiron.model.torch_model_harness import BaseModelHarness + +from examples.slac_fel.utils import ( + FELDataset, + discover_window_files, + load_feature_config, + load_fel_data, + load_scalers, + load_window_file, + make_loader, + split_into_windows, + split_timestamps, +) + + +_log = logging.getLogger(__name__) + + +# ------------------------------------------------------------------------------------------------- +# Neural-network architecture +# Matches FELNeuralNetwork in train_fel_model.py from surrogate repo model arch on 4/20/2026 +# ------------------------------------------------------------------------------------------------- +class FELNet(nn.Module): + """7-layer fully-connected ELU regression network. + Predicts FEL pulse intensity from scaled accelerator inputs.""" + + def __init__(self, input_size=None, output_size=1): + super(FELNet, self).__init__() + + self.net = nn.Sequential( + nn.Linear(input_size, 1024), + nn.ELU(), + nn.Linear(1024, 512), + nn.ELU(), + nn.Linear(512, 256), + nn.ELU(), + nn.Linear(256, 128), + nn.ELU(), + nn.Dropout(p=0.05), + nn.Linear(128, 64), + nn.ELU(), + nn.Dropout(p=0.05), + nn.Linear(64, 32), + nn.ELU(), + nn.Linear(32, 16), + nn.ELU(), + nn.Dropout(p=0.05), + nn.Linear(16, output_size), + nn.Softplus(beta=1.0, threshold=20.0), + ) + + def forward(self, x: Tensor) -> Tensor: + if not torch.isfinite(x).all(): + n_bad = (~torch.isfinite(x)).sum().item() + _log.warning( + "FELNet.forward: %d non-finite values in input. Replacing with 0", + n_bad, + ) + x = torch.nan_to_num(x, nan=0.0, posinf=1e6, neginf=-1e6) + + out = self.net(x) + + # Detect NaN outputs + if not torch.isfinite(out).all(): + if torch.isnan(out).any(): + _log.warning("Model produced NaN predictions. Replacing with 0.") + out = torch.nan_to_num(out, nan=0.0, posinf=1e6, neginf=-1e6) + + return out + + +# --------------------------------------------------------------------------- +# Regression metrics (match MetricFn = Callable[[Tensor, Tensor], Any]) +# --------------------------------------------------------------------------- +@torch.no_grad() +def mse_metric(y_hat: Tensor, y: Tensor) -> Tensor: + """Mean-squared error computed on the batch.""" + return F.mse_loss(y_hat, y) + + +@torch.no_grad() +def mae_metric(y_hat: Tensor, y: Tensor) -> Tensor: + """Mean-absolute error computed on the batch.""" + return F.l1_loss(y_hat, y) + + +# --------------------------------------------------------------------------- +# Model harness +# --------------------------------------------------------------------------- + +# Fraction of each time window reserved for validation +_VAL_FRACTION: float = 0.2 + +# Early stopping for the CL training loop (see SLAC_FEL.cl_should_stop). +# Set _ES_PATIENCE = 0 to disable. Training stops once the monitored validation +# metric has not improved by more than _ES_MIN_DELTA for _ES_PATIENCE consecutive +# checks, where checks happen every _ES_INTERVAL iterations. +_ES_PATIENCE: int = 0 +_ES_INTERVAL: int = 100 +_ES_MIN_DELTA: float = 0.0 + +# Recency weighting for the historical replay buffer (see get_hist_dataloaders). +# Per-sample weight decays as _HIST_RECENCY_DECAY ** window_age, so the most +# recent past window dominates the replay and stale operating points contribute +# progressively less. Set to 1.0 to recover uniform replay over all history +# windows; smaller values (e.g. 0.5) emphasise recent regimes more strongly. +_HIST_RECENCY_DECAY: float = 0.5 + +# Directory containing: input_scaler.pt, output_scaler.pt, feature_config.yml +config_path = "examples/slac_fel/model" + + +class SLAC_FEL(BaseModelHarness): + """Continuous-learning harness for the LCLS FEL regression model. + + The data path (``cfg.data.path``) must point to a directory containing: + + * ``hxr_*.pkl`` – pre-filtered, chronologically-sorted DataFrames. Files + are loaded lazily one at a time as windows are consumed, keeping only + one file's worth of tensors in memory at once. + * **OR** ``data.pkl`` – a single monolithic DataFrame that will be split + into fixed-size windows via ``cfg.data.batch_size`` (legacy fallback). + + The data path (``cfg.model``) must point to a directory containing: + * ``input_scaler.pt`` – BoTorch ``AffineInputTransform`` for inputs + * ``output_scaler.pt`` – BoTorch ``AffineInputTransform`` for the target + * ``feature_config.yml`` – YAML listing input / output variable names + * ``model_pretrained.pt`` (optional) – pretrained checkpoint for the FELNet model + + Each call to :meth:`update_data_stream` advances to the next time window. + """ + + def __init__(self, cfg: Config) -> None: + # ----- scalers & feature config (always needed) ---------------------- + self.input_scaler, self.output_scaler = load_scalers( + config_path, device=cfg.device + ) + self.input_cols, self.output_cols = load_feature_config(config_path) + + # ----- discover per-file windows or fall back to monolithic ---------- + self._window_file_paths = discover_window_files(cfg.data.path) + self._lazy = len(self._window_file_paths) > 0 + + # Dimensions come from the feature config – no data loading needed. + input_size = len(self.input_cols) + output_size = len(self.output_cols) + + if self._lazy: + # Lazy mode: files are loaded one at a time as windows are consumed. + self._file_idx: int = 0 + self._active_windows: List[Tuple[Tensor, Tensor]] = [] + self._active_timestamps: List = [] + self._active_window_idx: int = 0 + # num_windows is unknown until all files are scanned; use -1 as sentinel. + self.num_windows: int = -1 + print( + f"[SLAC-FEL] Lazy loading: {len(self._window_file_paths)} file(s) in " + f"{cfg.data.path} (window_size={cfg.data.batch_size}, " + f"input_dim={input_size}, output_dim={output_size})" + ) + else: + # Legacy mode: single data.pkl split into fixed-size windows. + X, y, timestamps = load_fel_data( + cfg.data.path, config_path, device=cfg.device + ) + print( + f"[SLAC-FEL] Legacy mode: single data file {cfg.data.path} with {X.shape[0]} samples" + ) + self.windows = split_into_windows(X, y, window_size=cfg.data.batch_size) + self.window_timestamps = split_timestamps( + timestamps, window_size=cfg.data.batch_size + ) + self.num_windows = len(self.windows) + print( + f"[SLAC-FEL] Legacy mode: {self.num_windows} windows " + f"(window_size={cfg.data.batch_size}, " + f"input_dim={input_size}, output_dim={output_size})" + ) + + # ----- build model --------------------------------------------------- + pretrained_path = cfg.model.pretrained_path + if pretrained_path: + model = self._load_pretrained_direct( + pretrained_path, input_size, output_size, cfg.device + ) + else: + model = FELNet(input_size=input_size, output_size=output_size) + + super().__init__(cfg=cfg, model=model) + + # ----- eval metrics (regression) ------------------------------------- + # "mae" is the scaled-space error used for drift detection (metric_index + # 0). "mae_mj" untransforms to physical mJ so logs/CSV expose real error. + self.eval_metrics = {"mae": mae_metric, "mae_mj": self._mae_mj} + self.higher_is_better = {"mae": False, "mae_mj": False} + + # ----- streaming state ----------------------------------------------- + self.window_idx: int = 0 + self.history_windows: List[Tuple[Tensor, Tensor]] = [] + self._current_window: Optional[Tuple[Tensor, Tensor]] = None + self.current_window_timerange: Optional[Tuple[str, str]] = None + + # Cap history to prevent unbounded memory growth + self.max_history_windows: int = 20 + + self._cur_train_loader: Optional[DataLoader] = None + self._cur_val_loader: Optional[DataLoader] = None + + # Dedicated RNGs so batch shuffle and replay sampling are reproducible + # run-to-run, decoupled from other global-RNG usage (e.g. dropout). + self._loader_gen = torch.Generator() + self._loader_gen.manual_seed(cfg.seed) + self._hist_gen = torch.Generator() + self._hist_gen.manual_seed(cfg.seed + 1) + + # ----- early-stopping state (per drift event) ------------------------ + self._es_best_metric: Optional[float] = None + self._es_best_state: Optional[dict] = None + self._es_evals_no_improve: int = 0 + + @torch.no_grad() + def _mae_mj(self, y_hat: Tensor, y: Tensor) -> Tensor: + """Mean-absolute error in physical mJ (untransform before comparing).""" + y_hat_mj = self.output_scaler.untransform(y_hat) # type: ignore[operator] + y_mj = self.output_scaler.untransform(y) # type: ignore[operator] + return F.l1_loss(y_hat_mj, y_mj) + + # --------------------------------------------------------------------- # + # Required overrides + # --------------------------------------------------------------------- # + + def get_optimizer(self) -> Optimizer: # noqa: D102 + return torch.optim.Adam(self.model.parameters(), lr=self.cfg.train.init_lr) + + def get_criterion(self): # noqa: D102 + return nn.MSELoss() + + def get_stream_dataloader(self): + assert self._cur_val_loader is not None + return self._cur_val_loader + + def get_train_dataloaders(self): + assert self._cur_train_loader is not None and self._cur_val_loader is not None + return self._cur_train_loader, self._cur_val_loader + + def get_hist_dataloaders( + self, + ) -> Tuple[Optional[DataLoader], Optional[DataLoader]]: + """Return loaders over previously-seen time windows, recency-weighted. + + Returns ``(None, None)`` until at least two windows have been served. + + The FEL input->output mapping drifts over time (concept drift), so + replaying every past window with equal weight anchors the model to stale + operating points and hurts current-window accuracy. Instead, the training + (replay) loader draws samples with a :class:`WeightedRandomSampler` whose + per-sample weight decays as ``_HIST_RECENCY_DECAY ** window_age`` (age 0 = + most recent past window). Recent regimes therefore dominate the replay + while older ones still contribute a little to guard against forgetting. + The validation loader stays uniform since it is only used for reporting. + """ + if self.window_idx <= 1: + return None, None + + # Build one view per history window, newest first, together with an + # aligned per-sample recency weight (weights index in the same order the + # ConcatDataset concatenates the views). + hist_train_views: List[FELDataset] = [] + hist_val_views: List[FELDataset] = [] + train_sample_weights: List[float] = [] + + for age, (X_w, y_w) in enumerate(reversed(self.history_windows)): + n = X_w.shape[0] + n_val = max(1, int(n * _VAL_FRACTION)) + n_train = n - n_val + hist_train_views.append(FELDataset(X_w[:n_train], y_w[:n_train])) + hist_val_views.append(FELDataset(X_w[n_train:], y_w[n_train:])) + train_sample_weights.extend([_HIST_RECENCY_DECAY**age] * n_train) + + ds_hist_train: ConcatDataset[Any] = ConcatDataset(hist_train_views) + ds_hist_val: ConcatDataset[Any] = ConcatDataset(hist_val_views) + + bs = self.cfg.train.batch_size + nw = self.cfg.train.num_workers + pin = torch.cuda.is_available() + + hist_sampler = WeightedRandomSampler( + weights=train_sample_weights, + num_samples=len(ds_hist_train), + replacement=True, + generator=self._hist_gen, + ) + + return ( + make_loader( + ds_hist_train, + bs, + shuffle=False, + sampler=hist_sampler, + num_workers=nw, + pin_memory=pin, + ), + make_loader(ds_hist_val, bs, shuffle=False, num_workers=nw, pin_memory=pin), + ) + + def cl_should_stop(self, iter_count: int) -> bool: + """Validation-based early stopping for the CL training loop. + + Every ``_ES_INTERVAL`` iterations the monitored validation metric + (``drift_detection.metric_index`` of :attr:`eval_metrics`) is evaluated. + Training stops once it has failed to improve by more than + ``_ES_MIN_DELTA`` for ``_ES_PATIENCE`` consecutive checks, at which point + the best-scoring weights seen during this drift event are restored. The + state is reset at ``iter_count == 0`` so each drift event stops + independently. Set ``_ES_PATIENCE = 0`` to disable. + """ + if _ES_PATIENCE <= 0: + return False + + # Reset at the start of each drift event's training loop. + if iter_count == 0: + self._es_best_metric = None + self._es_best_state = None + self._es_evals_no_improve = 0 + + if (iter_count + 1) % _ES_INTERVAL != 0: + return False + + metric_idx = self.cfg.drift_detection.metric_index + metric_names = list(self.eval_metrics.keys()) + metric_name = ( + metric_names[metric_idx] + if metric_idx < len(metric_names) + else metric_names[0] + ) + higher_is_better = self.higher_is_better.get(metric_name, True) + + val_metric = self.eval()[metric_idx] + self.model.train() # eval() switched the model into eval mode + + if self._es_best_metric is None: + improved = True + elif higher_is_better: + improved = val_metric > self._es_best_metric + _ES_MIN_DELTA + else: + improved = val_metric < self._es_best_metric - _ES_MIN_DELTA + + if improved: + self._es_best_metric = val_metric + self._es_best_state = { + k: v.detach().cpu().clone() for k, v in self.model.state_dict().items() + } + self._es_evals_no_improve = 0 + return False + + self._es_evals_no_improve += 1 + if self._es_evals_no_improve < _ES_PATIENCE: + return False + + # Patience exhausted: restore the best weights and stop. + if self._es_best_state is not None: + self.model.load_state_dict(self._es_best_state) + _log.info( + "[SLAC-FEL] Early stopping CL at iter %d (best %s=%.4g, no improvement " + "for %d checks).", + iter_count + 1, + metric_name, + self._es_best_metric, + _ES_PATIENCE, + ) + return True + + def _load_active_file(self) -> None: + """Load the next pkl file into ``_active_windows`` / ``_active_timestamps``. + + Wraps around to the first file once all files have been consumed and + frees the previous file's tensors (those no longer referenced by + ``history_windows``) via an explicit GC pass. + """ + if self._file_idx >= len(self._window_file_paths): + print( + f"[SLAC-FEL] All {len(self._window_file_paths)} file(s) exhausted; " + "wrapping around to the first file." + ) + self._file_idx = 0 + + pkl_path = self._window_file_paths[self._file_idx] + print( + f"[SLAC-FEL] Loading file " + f"{self._file_idx + 1}/{len(self._window_file_paths)}: " + f"{os.path.basename(pkl_path)}" + ) + + X_w, y_w, idx = load_window_file( + pkl_path, + self.input_cols, + self.output_cols, + self.input_scaler, + self.output_scaler, + ) + self._active_windows = split_into_windows( + X_w, y_w, window_size=self.cfg.data.batch_size + ) + self._active_timestamps = split_timestamps( + idx, window_size=self.cfg.data.batch_size + ) + self._active_window_idx = 0 + self._file_idx += 1 + gc.collect() + print( + f"[SLAC-FEL] Ready: {len(self._active_windows)} windows from " + f"{os.path.basename(pkl_path)} " + f"({X_w.shape[0]} samples, window_size={self.cfg.data.batch_size})" + ) + + def update_data_stream(self) -> None: + """Advance to the next chronological time window. + + In lazy mode each pkl file is loaded on demand when the current file's + windows are exhausted. In legacy mode all windows are already in memory. + """ + self._dispose_current_loaders() + + # ── Archive the *previous* window into history ──────────────────── + if self._current_window is not None: + self.history_windows.append(self._current_window) + self._current_window = None + # Evict oldest windows when cap is reached + while len(self.history_windows) > self.max_history_windows: + self.history_windows.pop(0) + + # ── Fetch the next window tensors ───────────────────────────────── + if self._lazy: + # Load a new file if we've consumed all windows from the current one. + if self._active_window_idx >= len(self._active_windows): + self._load_active_file() + + X_w, y_w = self._active_windows[self._active_window_idx] + ts = self._active_timestamps[self._active_window_idx] + self._active_window_idx += 1 + window_label = ( + f"{self._file_idx}/{len(self._window_file_paths)} " + f"(win {self._active_window_idx}/{len(self._active_windows)} in file)" + ) + else: + if self.window_idx >= self.num_windows: + print( + f"Warning: All {self.num_windows} time windows exhausted; " + "wrapping around to the first window." + ) + self.window_idx = 0 + + X_w, y_w = self.windows[self.window_idx] + ts = self.window_timestamps[self.window_idx] + window_label = f"{self.window_idx + 1}/{self.num_windows}" + + # Record timestamp range for this window + self.current_window_timerange = (str(ts[0]), str(ts[-1])) + + # Keep a reference so the next call can archive it without reloading + self._current_window = (X_w, y_w) + + # Train / val split (last _VAL_FRACTION chronologically) + n = X_w.shape[0] + n_val = max(1, int(n * _VAL_FRACTION)) + n_train = n - n_val + # Safety: ensure both splits have at least 1 sample + if n_train < 1: + n_train = max(1, n - 1) + n_val = n - n_train + + ds_train = FELDataset(X_w[:n_train], y_w[:n_train]) + ds_val = FELDataset(X_w[n_train:], y_w[n_train:]) + + bs = self.cfg.train.batch_size + nw = self.cfg.train.num_workers + pin = torch.cuda.is_available() + + self._cur_train_loader = make_loader( + ds_train, + bs, + shuffle=True, + num_workers=nw, + pin_memory=pin, + generator=self._loader_gen, + ) + self._cur_val_loader = make_loader( + ds_val, bs, shuffle=False, num_workers=nw, pin_memory=pin + ) + + print( + f"[SLAC-FEL] Window {window_label}: " + f"{n_train} train / {n_val} val samples " + f"[{self.current_window_timerange[0]} → {self.current_window_timerange[1]}]" + ) + self.window_idx += 1 + + # --------------------------------------------------------------------- # + # Helpers + # --------------------------------------------------------------------- # + + @staticmethod + def _load_pretrained_direct( + path: str, input_size: int, output_size: int, device: str + ) -> FELNet: + """Load a pretrained checkpoint directly with no weight modifications. + + Supports two save formats produced by ``train_fel_model.py``: + + 1. A raw ``nn.Sequential`` (saved via ``torch.save(model.net, ...)``). + The Sequential is wrapped inside a new :class:`FELNet` whose + architecture is defined entirely by the checkpoint. + 2. A ``state_dict`` (plain ``dict``). The input dimension is inferred + from the first Linear layer's weight shape so that :class:`FELNet` + is constructed to match exactly, then ``load_state_dict`` is called + with ``strict=True``. + + Raises: + FileNotFoundError: If *path* does not exist. + RuntimeError: If the checkpoint shapes are incompatible with the + data (e.g. the data has a different number of input features + than the model expects). + """ + state = torch.load(path, map_location=device, weights_only=False) + + if isinstance(state, nn.Sequential): + # Format 1: checkpoint is the raw nn.Sequential + # Infer input/output dims from the first and last Linear layers + first_linear = next(m for m in state.modules() if isinstance(m, nn.Linear)) + last_linear = list(m for m in state.modules() if isinstance(m, nn.Linear))[ + -1 + ] + ckpt_in = first_linear.in_features + ckpt_out = last_linear.out_features + + if ckpt_in != input_size: + raise RuntimeError( + f"Pretrained model expects {ckpt_in} input features but " + f"the data has {input_size}. Ensure the feature_config.yml " + f"and scalers match the checkpoint." + ) + + model = FELNet(input_size=ckpt_in, output_size=ckpt_out) + model.net.load_state_dict(state.state_dict(), strict=True) + print(f"Loaded pretrained FEL model (nn.Sequential) from {path}") + + elif isinstance(state, dict): + # Format 2: checkpoint is a state_dict + # Strip torch.compile artefact from keys + sd = {k.replace("_orig_mod.", ""): v for k, v in state.items()} + + # Infer input dim from the first weight tensor + first_weight_key = next( + k for k in sd if k.endswith(".weight") and sd[k].dim() == 2 + ) + ckpt_in = sd[first_weight_key].shape[1] + + if ckpt_in != input_size: + raise RuntimeError( + f"Pretrained model expects {ckpt_in} input features but " + f"the data has {input_size}. Ensure the feature_config.yml " + f"and scalers match the checkpoint." + ) + + model = FELNet(input_size=ckpt_in, output_size=output_size) + model.load_state_dict(sd, strict=True) + print(f"Loaded pretrained FEL model (state_dict) from {path}") + + else: + raise TypeError( + f"Unexpected checkpoint type {type(state).__name__} from {path}. " + f"Expected nn.Sequential or state_dict." + ) + + return model + + def _dispose_current_loaders(self) -> None: + if self._cur_train_loader is not None: + del self._cur_train_loader + self._cur_train_loader = None + if self._cur_val_loader is not None: + del self._cur_val_loader + self._cur_val_loader = None + gc.collect() diff --git a/examples/slac_fel/model/feature_config.yml b/examples/slac_fel/model/feature_config.yml new file mode 100644 index 00000000..c62e96de --- /dev/null +++ b/examples/slac_fel/model/feature_config.yml @@ -0,0 +1,2743 @@ +device: cpu +input_transformers: +- resources/lcls_fel_input_scaler.pt +input_variables: + QUAD:LI21:211:BACT: + variable_class: TorchScalarVariable + default_value: 6.030075550079346 + read_only: false + value_range: + - 3.2707419395446777 + - 7.083395004272461 + unit: kG + QUAD:LI21:221:BACT: + variable_class: TorchScalarVariable + default_value: -0.22167986631393433 + read_only: false + value_range: + - -0.7424343228340149 + - 0.2432546466588974 + unit: kG + QUAD:LI21:243:BACT: + variable_class: TorchScalarVariable + default_value: -0.0006752711487933993 + read_only: false + value_range: + - -0.0007149674347601831 + - -0.0006156182498671114 + unit: kG-m + QUAD:LI21:251:BACT: + variable_class: TorchScalarVariable + default_value: -0.14767540991306305 + read_only: false + value_range: + - -0.7296757698059082 + - 0.25308719277381897 + unit: kG + QUAD:LI21:271:BACT: + variable_class: TorchScalarVariable + default_value: -6.2067694664001465 + read_only: false + value_range: + - -7.801762104034424 + - -4.287487983703613 + unit: kG + QUAD:LI21:335:BACT: + variable_class: TorchScalarVariable + default_value: -5.328253269195557 + read_only: false + value_range: + - -5.428651332855225 + - -5.321958065032959 + unit: kG + QUAD:LI24:713:BACT: + variable_class: TorchScalarVariable + default_value: 35.41676330566406 + read_only: false + value_range: + - 23.610397338867188 + - 35.42658615112305 + unit: kG + QUAD:LI24:740:BACT: + variable_class: TorchScalarVariable + default_value: -0.0005302699573803693 + read_only: false + value_range: + - -0.9996497631072998 + - 1.100592851638794 + unit: kG + QUAD:LI24:860:BACT: + variable_class: TorchScalarVariable + default_value: 0.4042496532201767 + read_only: false + value_range: + - -1.2825469970703125 + - 2.1002092361450195 + unit: kG + QUAD:LI24:892:BACT: + variable_class: TorchScalarVariable + default_value: -40.7828369140625 + read_only: false + value_range: + - -40.78890609741211 + - -27.187170028686523 + unit: kG + QUAD:LI24:902:BACT: + variable_class: TorchScalarVariable + default_value: 17.336612701416016 + read_only: false + value_range: + - 11.556938171386719 + - 17.337291717529297 + unit: kG + QUAD:CLTH:140:BACT: + variable_class: TorchScalarVariable + default_value: -21.54228973388672 + read_only: false + value_range: + - -21.91339683532715 + - -21.316192626953125 + unit: kG + QUAD:CLTH:170:BACT: + variable_class: TorchScalarVariable + default_value: 11.69263744354248 + read_only: false + value_range: + - 11.570372581481934 + - 11.913098335266113 + unit: kG + QUAD:BSYH:445:BACT: + variable_class: TorchScalarVariable + default_value: 39.05901336669922 + read_only: false + value_range: + - 38.6727409362793 + - 39.68069076538086 + unit: kG + QUAD:LTUH:285:BACT: + variable_class: TorchScalarVariable + default_value: -68.72994232177734 + read_only: false + value_range: + - -69.82388305664062 + - -58.627498626708984 + unit: kG + QUAD:LTUH:295:BACT: + variable_class: TorchScalarVariable + default_value: -68.79946899414062 + read_only: false + value_range: + - -69.89398956298828 + - -62.51885986328125 + unit: kG + QUAD:LTUH:385:BACT: + variable_class: TorchScalarVariable + default_value: -68.75484466552734 + read_only: false + value_range: + - -69.84967803955078 + - -58.85036849975586 + unit: kG + QUAD:LTUH:395:BACT: + variable_class: TorchScalarVariable + default_value: -68.72314453125 + read_only: false + value_range: + - -69.81681823730469 + - -58.62387466430664 + unit: kG + QUAD:LTUH:440:BACT: + variable_class: TorchScalarVariable + default_value: -2.281162738800049 + read_only: false + value_range: + - -5.002049922943115 + - 4.872499942779541 + unit: kG + QUAD:LTUH:460:BACT: + variable_class: TorchScalarVariable + default_value: -0.8954360485076904 + read_only: false + value_range: + - -4.96889591217041 + - 4.391031742095947 + unit: kG + QUAD:LTUH:485:BACT: + variable_class: TorchScalarVariable + default_value: -68.74945831298828 + read_only: false + value_range: + - -69.84385681152344 + - -58.85063934326172 + unit: kG + QUAD:LTUH:495:BACT: + variable_class: TorchScalarVariable + default_value: -68.73614501953125 + read_only: false + value_range: + - -69.82984924316406 + - -58.84379959106445 + unit: kG + QUAD:LTUH:585:BACT: + variable_class: TorchScalarVariable + default_value: -68.71878051757812 + read_only: false + value_range: + - -69.81290435791016 + - -58.6135139465332 + unit: kG + QUAD:LTUH:595:BACT: + variable_class: TorchScalarVariable + default_value: -68.78495025634766 + read_only: false + value_range: + - -69.88025665283203 + - -58.66910171508789 + unit: kG + QUAD:DMPH:300:BACT: + variable_class: TorchScalarVariable + default_value: 31.637060165405273 + read_only: false + value_range: + - 27.602787017822266 + - 32.03553771972656 + unit: kG + QUAD:DMPH:380:BACT: + variable_class: TorchScalarVariable + default_value: -25.045557022094727 + read_only: false + value_range: + - -25.263795852661133 + - -22.069438934326172 + unit: kG + QUAD:DMPH:500:BACT: + variable_class: TorchScalarVariable + default_value: -23.642780303955078 + read_only: false + value_range: + - -24.01908302307129 + - -23.397724151611328 + unit: kG + QUAD:DMPH:600:BACT: + variable_class: TorchScalarVariable + default_value: -23.648740768432617 + read_only: false + value_range: + - -24.024883270263672 + - -20.174333572387695 + unit: kG + QUAD:BSYH:465:BACT: + variable_class: TorchScalarVariable + default_value: -35.822792053222656 + read_only: false + value_range: + - -36.393035888671875 + - -31.709379196166992 + unit: kG + QUAD:BSYH:640:BACT: + variable_class: TorchScalarVariable + default_value: 27.010040283203125 + read_only: false + value_range: + - 17.822553634643555 + - 27.48724365234375 + unit: kG + QUAD:BSYH:735:BACT: + variable_class: TorchScalarVariable + default_value: -18.543298721313477 + read_only: false + value_range: + - -18.838489532470703 + - -17.74009132385254 + unit: kG + QUAD:BSYH:910:BACT: + variable_class: TorchScalarVariable + default_value: 17.757822036743164 + read_only: false + value_range: + - 15.264426231384277 + - 18.11552619934082 + unit: kG + QUAD:LTUH:110:BACT: + variable_class: TorchScalarVariable + default_value: -55.096763610839844 + read_only: false + value_range: + - -55.97401428222656 + - -47.1643180847168 + unit: kG + QUAD:LTUH:120:BACT: + variable_class: TorchScalarVariable + default_value: 38.62837219238281 + read_only: false + value_range: + - 33.06697463989258 + - 39.2436637878418 + unit: kG + QUAD:LTUH:180:BACT: + variable_class: TorchScalarVariable + default_value: 116.76960754394531 + read_only: false + value_range: + - 99.60626220703125 + - 118.62828826904297 + unit: kG + QUAD:LTUH:190:BACT: + variable_class: TorchScalarVariable + default_value: -111.29957580566406 + read_only: false + value_range: + - -113.0712661743164 + - -95.2757797241211 + unit: kG + QUAD:LTUH:130:BACT: + variable_class: TorchScalarVariable + default_value: -68.94131469726562 + read_only: false + value_range: + - -70.038818359375 + - -59.015647888183594 + unit: kG + QUAD:LTUH:150:BACT: + variable_class: TorchScalarVariable + default_value: 68.9623794555664 + read_only: false + value_range: + - 58.82075119018555 + - 70.06075286865234 + unit: kG + QUAD:LTUH:170:BACT: + variable_class: TorchScalarVariable + default_value: -69.00261688232422 + read_only: false + value_range: + - -70.10100555419922 + - -58.86089324951172 + unit: kG + QUAD:LTUH:350:BACT: + variable_class: TorchScalarVariable + default_value: 49.77518844604492 + read_only: false + value_range: + - 42.46773910522461 + - 50.56687545776367 + unit: kG + QUAD:LTUH:450:BACT: + variable_class: TorchScalarVariable + default_value: 49.589073181152344 + read_only: false + value_range: + - 42.292335510253906 + - 50.37962341308594 + unit: kG + QUAD:LTUH:550:BACT: + variable_class: TorchScalarVariable + default_value: 49.23419952392578 + read_only: false + value_range: + - 41.99699020385742 + - 50.01803970336914 + unit: kG + QUAD:LTUH:290:BACT: + variable_class: TorchScalarVariable + default_value: 137.0901641845703 + read_only: false + value_range: + - 135.7318115234375 + - 139.2747802734375 + unit: kG + QUAD:LTUH:390:BACT: + variable_class: TorchScalarVariable + default_value: 137.2481231689453 + read_only: false + value_range: + - 117.06791687011719 + - 139.43606567382812 + unit: kG + QUAD:LTUH:490:BACT: + variable_class: TorchScalarVariable + default_value: 136.9311065673828 + read_only: false + value_range: + - 117.22069549560547 + - 139.11268615722656 + unit: kG + QUAD:LTUH:590:BACT: + variable_class: TorchScalarVariable + default_value: 137.08688354492188 + read_only: false + value_range: + - 117.35442352294922 + - 139.27085876464844 + unit: kG + QUAD:LTUH:250:BACT: + variable_class: TorchScalarVariable + default_value: 49.557777404785156 + read_only: false + value_range: + - 42.422725677490234 + - 50.346900939941406 + unit: kG + QUAD:LTUH:620:BACT: + variable_class: TorchScalarVariable + default_value: -45.03540802001953 + read_only: false + value_range: + - -54.6842155456543 + - -36.9230842590332 + unit: kG + QUAD:LTUH:640:BACT: + variable_class: TorchScalarVariable + default_value: 49.21936798095703 + read_only: false + value_range: + - 37.15061569213867 + - 58.81219482421875 + unit: kG + QUAD:LTUH:660:BACT: + variable_class: TorchScalarVariable + default_value: -69.18975067138672 + read_only: false + value_range: + - -77.35741424560547 + - -57.796470642089844 + unit: kG + QUAD:LTUH:680:BACT: + variable_class: TorchScalarVariable + default_value: 47.888877868652344 + read_only: false + value_range: + - 34.01578903198242 + - 62.26810073852539 + unit: kG + QUAD:LTUH:720:BACT: + variable_class: TorchScalarVariable + default_value: 15.408587455749512 + read_only: false + value_range: + - 13.143723487854004 + - 15.75007438659668 + unit: kG-m + QUAD:LTUH:730:BACT: + variable_class: TorchScalarVariable + default_value: -15.387463569641113 + read_only: false + value_range: + - -15.728804588317871 + - -13.961954116821289 + unit: kG + QUAD:LTUH:740:BACT: + variable_class: TorchScalarVariable + default_value: 15.418059349060059 + read_only: false + value_range: + - 13.198366165161133 + - 15.759831428527832 + unit: kG + QUAD:LTUH:750:BACT: + variable_class: TorchScalarVariable + default_value: -15.42436695098877 + read_only: false + value_range: + - -15.765908241271973 + - -13.997550010681152 + unit: kG + QUAD:LTUH:760:BACT: + variable_class: TorchScalarVariable + default_value: 15.395170211791992 + read_only: false + value_range: + - 13.13112735748291 + - 15.736696243286133 + unit: kG + QUAD:LTUH:770:BACT: + variable_class: TorchScalarVariable + default_value: -15.381906509399414 + read_only: false + value_range: + - -15.722893714904785 + - -13.120884895324707 + unit: kG + QUAD:LTUH:820:BACT: + variable_class: TorchScalarVariable + default_value: 29.859907150268555 + read_only: false + value_range: + - 21.836652755737305 + - 31.44784164428711 + unit: kG + QUAD:LTUH:840:BACT: + variable_class: TorchScalarVariable + default_value: -26.527732849121094 + read_only: false + value_range: + - -28.012258529663086 + - -24.921369552612305 + unit: kG + QUAD:LTUH:860:BACT: + variable_class: TorchScalarVariable + default_value: 18.940080642700195 + read_only: false + value_range: + - 17.5400333404541 + - 22.54979133605957 + unit: kG + QUAD:LTUH:880:BACT: + variable_class: TorchScalarVariable + default_value: -19.915769577026367 + read_only: false + value_range: + - -20.96946907043457 + - -19.381351470947266 + unit: kG + QUAD:UNDH:1380:BACT: + variable_class: TorchScalarVariable + default_value: 30.00006675720215 + read_only: false + value_range: + - 29.987991333007812 + - 30.014312744140625 + unit: kG + QUAD:UNDH:1480:BACT: + variable_class: TorchScalarVariable + default_value: -29.999717712402344 + read_only: false + value_range: + - -30.0033016204834 + - -29.99729347229004 + unit: kG + QUAD:UNDH:1580:BACT: + variable_class: TorchScalarVariable + default_value: 30.00047492980957 + read_only: false + value_range: + - 29.99797248840332 + - 30.002107620239258 + unit: kG + QUAD:UNDH:1680:BACT: + variable_class: TorchScalarVariable + default_value: -30.000215530395508 + read_only: false + value_range: + - -30.003171920776367 + - -29.9971866607666 + unit: kG + QUAD:UNDH:1780:BACT: + variable_class: TorchScalarVariable + default_value: 30.000083923339844 + read_only: false + value_range: + - 29.997570037841797 + - 30.00188636779785 + unit: kG + QUAD:UNDH:1880:BACT: + variable_class: TorchScalarVariable + default_value: -29.999813079833984 + read_only: false + value_range: + - -30.001985549926758 + - -29.997087478637695 + unit: kG + QUAD:UNDH:1980:BACT: + variable_class: TorchScalarVariable + default_value: 29.999773025512695 + read_only: false + value_range: + - 29.994216918945312 + - 30.006370544433594 + unit: kG + QUAD:UNDH:2080:BACT: + variable_class: TorchScalarVariable + default_value: -29.999937057495117 + read_only: false + value_range: + - -30.00302505493164 + - -29.997581481933594 + unit: kG + QUAD:UNDH:2180:BACT: + variable_class: TorchScalarVariable + default_value: 30.000242233276367 + read_only: false + value_range: + - 29.997495651245117 + - 30.0020809173584 + unit: kG + QUAD:UNDH:2280:BACT: + variable_class: TorchScalarVariable + default_value: -29.999507904052734 + read_only: false + value_range: + - -30.002283096313477 + - -29.997661590576172 + unit: kG + QUAD:UNDH:2380:BACT: + variable_class: TorchScalarVariable + default_value: 30.000028610229492 + read_only: false + value_range: + - 29.99715232849121 + - 30.00275421142578 + unit: kG + QUAD:UNDH:2480:BACT: + variable_class: TorchScalarVariable + default_value: -29.99951934814453 + read_only: false + value_range: + - -30.002347946166992 + - -29.99751853942871 + unit: kG + QUAD:UNDH:2580:BACT: + variable_class: TorchScalarVariable + default_value: 29.9998779296875 + read_only: false + value_range: + - 29.997821807861328 + - 30.002620697021484 + unit: kG + QUAD:UNDH:2680:BACT: + variable_class: TorchScalarVariable + default_value: -29.99985694885254 + read_only: false + value_range: + - -30.001996994018555 + - -29.997228622436523 + unit: kG + QUAD:UNDH:2780:BACT: + variable_class: TorchScalarVariable + default_value: 30.000137329101562 + read_only: false + value_range: + - 29.99728012084961 + - 30.001819610595703 + unit: kG + QUAD:UNDH:2880:BACT: + variable_class: TorchScalarVariable + default_value: -29.999929428100586 + read_only: false + value_range: + - -30.013427734375 + - -29.995588302612305 + unit: kG + QUAD:UNDH:2980:BACT: + variable_class: TorchScalarVariable + default_value: 29.999967575073242 + read_only: false + value_range: + - 29.99782371520996 + - 30.003271102905273 + unit: kG + QUAD:UNDH:3080:BACT: + variable_class: TorchScalarVariable + default_value: -30.000049591064453 + read_only: false + value_range: + - -30.00230598449707 + - -29.997459411621094 + unit: kG + QUAD:UNDH:3180:BACT: + variable_class: TorchScalarVariable + default_value: 30.000024795532227 + read_only: false + value_range: + - 29.996400833129883 + - 30.003795623779297 + unit: kG + QUAD:UNDH:3280:BACT: + variable_class: TorchScalarVariable + default_value: -29.999662399291992 + read_only: false + value_range: + - -30.002262115478516 + - -29.99651336669922 + unit: kG + QUAD:UNDH:3380:BACT: + variable_class: TorchScalarVariable + default_value: 30.000160217285156 + read_only: false + value_range: + - 29.997285842895508 + - 30.003522872924805 + unit: kG + QUAD:UNDH:3480:BACT: + variable_class: TorchScalarVariable + default_value: -29.999841690063477 + read_only: false + value_range: + - -30.002470016479492 + - -29.99711036682129 + unit: kG + QUAD:UNDH:3580:BACT: + variable_class: TorchScalarVariable + default_value: 30.000520706176758 + read_only: false + value_range: + - 29.99619483947754 + - 30.004093170166016 + unit: kG + QUAD:UNDH:3680:BACT: + variable_class: TorchScalarVariable + default_value: -29.999616622924805 + read_only: false + value_range: + - -30.003984451293945 + - -29.996126174926758 + unit: kG + QUAD:UNDH:3780:BACT: + variable_class: TorchScalarVariable + default_value: 30.0001277923584 + read_only: false + value_range: + - 29.997133255004883 + - 30.00319480895996 + unit: kG + QUAD:UNDH:3880:BACT: + variable_class: TorchScalarVariable + default_value: -30.000167846679688 + read_only: false + value_range: + - -30.002561569213867 + - -29.99714469909668 + unit: kG + QUAD:UNDH:3980:BACT: + variable_class: TorchScalarVariable + default_value: 30.000091552734375 + read_only: false + value_range: + - 29.994361877441406 + - 30.00579071044922 + unit: kG + QUAD:UNDH:4080:BACT: + variable_class: TorchScalarVariable + default_value: -30.00008773803711 + read_only: false + value_range: + - -30.006589889526367 + - -29.99155616760254 + unit: kG + QUAD:UNDH:4180:BACT: + variable_class: TorchScalarVariable + default_value: 29.999652862548828 + read_only: false + value_range: + - 29.99405860900879 + - 30.004716873168945 + unit: kG + QUAD:UNDH:4280:BACT: + variable_class: TorchScalarVariable + default_value: -29.99981689453125 + read_only: false + value_range: + - -30.005260467529297 + - -29.993431091308594 + unit: kG + QUAD:UNDH:4380:BACT: + variable_class: TorchScalarVariable + default_value: 30.00043296813965 + read_only: false + value_range: + - 29.99149513244629 + - 30.00352668762207 + unit: kG + QUAD:UNDH:4480:BACT: + variable_class: TorchScalarVariable + default_value: -29.9997501373291 + read_only: false + value_range: + - -30.007246017456055 + - -29.97597885131836 + unit: kG + QUAD:UNDH:4580:BACT: + variable_class: TorchScalarVariable + default_value: 30.000293731689453 + read_only: false + value_range: + - 29.99628448486328 + - 30.009353637695312 + unit: kG + QUAD:UNDH:4680:BACT: + variable_class: TorchScalarVariable + default_value: -40.96110916137695 + read_only: false + value_range: + - -41.023189544677734 + - -39.94914245605469 + unit: kG + QUAD:LI21:201:BACT: + variable_class: TorchScalarVariable + default_value: -7.023688793182373 + read_only: false + value_range: + - -8.62252426147461 + - -2.9184024333953857 + unit: kG + QUAD:LI21:301:BACT: + variable_class: TorchScalarVariable + default_value: -0.1838965117931366 + read_only: false + value_range: + - -0.1839919537305832 + - -0.18380530178546906 + unit: kG + QUAD:LI24:701:BACT: + variable_class: TorchScalarVariable + default_value: -20.95453453063965 + read_only: false + value_range: + - -20.955387115478516 + - -13.969274520874023 + unit: kG + QUAD:LI21:401:BACT: + variable_class: TorchScalarVariable + default_value: 1.2579798698425293 + read_only: false + value_range: + - 0.807345986366272 + - 1.2974697351455688 + unit: kG + QUAD:LI21:501:BACT: + variable_class: TorchScalarVariable + default_value: -1.5395961999893188 + read_only: false + value_range: + - -1.6181596517562866 + - -0.9817104935646057 + unit: kG + QUAD:LI21:601:BACT: + variable_class: TorchScalarVariable + default_value: 1.765993356704712 + read_only: false + value_range: + - 1.2652913331985474 + - 1.8709330558776855 + unit: kG + QUAD:LI21:701:BACT: + variable_class: TorchScalarVariable + default_value: -2.207437038421631 + read_only: false + value_range: + - -2.3438212871551514 + - -1.5526777505874634 + unit: kG + QUAD:LI21:801:BACT: + variable_class: TorchScalarVariable + default_value: 2.7435076236724854 + read_only: false + value_range: + - 1.8732759952545166 + - 2.8998312950134277 + unit: kG + QUAD:LI21:901:BACT: + variable_class: TorchScalarVariable + default_value: -3.2224531173706055 + read_only: false + value_range: + - -3.4157297611236572 + - -2.152127742767334 + unit: kG + QUAD:LI22:201:BACT: + variable_class: TorchScalarVariable + default_value: 3.124361753463745 + read_only: false + value_range: + - 2.0494790077209473 + - 3.560842275619507 + unit: kG + QUAD:LI22:301:BACT: + variable_class: TorchScalarVariable + default_value: -4.022610187530518 + read_only: false + value_range: + - -4.522728443145752 + - -2.434352159500122 + unit: kG + QUAD:LI22:401:BACT: + variable_class: TorchScalarVariable + default_value: 4.441101551055908 + read_only: false + value_range: + - 2.675431728363037 + - 4.936089992523193 + unit: kG + QUAD:LI22:501:BACT: + variable_class: TorchScalarVariable + default_value: -5.158733367919922 + read_only: false + value_range: + - -5.76203727722168 + - -3.146383047103882 + unit: kG + QUAD:LI22:601:BACT: + variable_class: TorchScalarVariable + default_value: 6.213307857513428 + read_only: false + value_range: + - 3.7713868618011475 + - 6.909282684326172 + unit: kG + QUAD:LI22:701:BACT: + variable_class: TorchScalarVariable + default_value: -6.612524509429932 + read_only: false + value_range: + - -7.327755451202393 + - -3.9155988693237305 + unit: kG + QUAD:LI22:801:BACT: + variable_class: TorchScalarVariable + default_value: 7.286632537841797 + read_only: false + value_range: + - 4.332723140716553 + - 8.138812065124512 + unit: kG + QUAD:LI22:901:BACT: + variable_class: TorchScalarVariable + default_value: -6.613517761230469 + read_only: false + value_range: + - -7.293863296508789 + - -3.9421448707580566 + unit: kG + QUAD:LI23:201:BACT: + variable_class: TorchScalarVariable + default_value: 6.20369815826416 + read_only: false + value_range: + - 3.6991350650787354 + - 6.829252243041992 + unit: kG + QUAD:LI23:301:BACT: + variable_class: TorchScalarVariable + default_value: -6.603721618652344 + read_only: false + value_range: + - -7.275477409362793 + - -3.937861680984497 + unit: kG + QUAD:LI23:401:BACT: + variable_class: TorchScalarVariable + default_value: 6.099545001983643 + read_only: false + value_range: + - 3.627194404602051 + - 6.7084641456604 + unit: kG + QUAD:LI23:501:BACT: + variable_class: TorchScalarVariable + default_value: -6.796770095825195 + read_only: false + value_range: + - -7.48622465133667 + - -4.047740936279297 + unit: kG + QUAD:LI23:601:BACT: + variable_class: TorchScalarVariable + default_value: 7.231057643890381 + read_only: false + value_range: + - 4.294067859649658 + - 7.962332725524902 + unit: kG + QUAD:LI23:701:BACT: + variable_class: TorchScalarVariable + default_value: -8.0819730758667 + read_only: false + value_range: + - -8.897425651550293 + - -4.805255889892578 + unit: kG + QUAD:LI23:801:BACT: + variable_class: TorchScalarVariable + default_value: 9.420169830322266 + read_only: false + value_range: + - 5.585941314697266 + - 10.347235679626465 + unit: kG + QUAD:LI23:901:BACT: + variable_class: TorchScalarVariable + default_value: -9.803484916687012 + read_only: false + value_range: + - -10.765859603881836 + - -5.8162946701049805 + unit: kG + QUAD:LI24:201:BACT: + variable_class: TorchScalarVariable + default_value: 11.029939651489258 + read_only: false + value_range: + - 6.811530590057373 + - 11.965710639953613 + unit: kG + QUAD:LI24:301:BACT: + variable_class: TorchScalarVariable + default_value: -12.313459396362305 + read_only: false + value_range: + - -13.151202201843262 + - -7.702062129974365 + unit: kG + QUAD:LI24:401:BACT: + variable_class: TorchScalarVariable + default_value: 14.647502899169922 + read_only: false + value_range: + - 9.044830322265625 + - 15.84463119506836 + unit: kG + QUAD:LI24:501:BACT: + variable_class: TorchScalarVariable + default_value: -14.135113716125488 + read_only: false + value_range: + - -14.76771068572998 + - -9.022802352905273 + unit: kG + QUAD:LI24:601:BACT: + variable_class: TorchScalarVariable + default_value: 9.412679672241211 + read_only: false + value_range: + - 6.159085750579834 + - 9.750685691833496 + unit: kG + QUAD:LI24:702:BACT: + variable_class: TorchScalarVariable + default_value: -20.95453453063965 + read_only: false + value_range: + - -20.955387115478516 + - -13.969274520874023 + unit: kG + QUAD:LI24:901:BACT: + variable_class: TorchScalarVariable + default_value: 17.336612701416016 + read_only: false + value_range: + - 11.556938171386719 + - 17.337291717529297 + unit: kG + QUAD:LI25:201:BACT: + variable_class: TorchScalarVariable + default_value: 11.577884674072266 + read_only: false + value_range: + - 7.857098579406738 + - 11.652408599853516 + unit: kG + QUAD:LI25:301:BACT: + variable_class: TorchScalarVariable + default_value: -8.047331809997559 + read_only: false + value_range: + - -8.348615646362305 + - -5.753606796264648 + unit: kG + QUAD:LI25:401:BACT: + variable_class: TorchScalarVariable + default_value: 7.526213645935059 + read_only: false + value_range: + - 5.471653461456299 + - 7.811742782592773 + unit: kG + QUAD:LI25:501:BACT: + variable_class: TorchScalarVariable + default_value: -7.366200923919678 + read_only: false + value_range: + - -7.65356969833374 + - -5.456874370574951 + unit: kG + QUAD:LI25:601:BACT: + variable_class: TorchScalarVariable + default_value: 7.2868452072143555 + read_only: false + value_range: + - 5.396615982055664 + - 7.85613489151001 + unit: kG + QUAD:LI25:701:BACT: + variable_class: TorchScalarVariable + default_value: -7.611361503601074 + read_only: false + value_range: + - -8.188580513000488 + - -5.722440242767334 + unit: kG + QUAD:LI25:801:BACT: + variable_class: TorchScalarVariable + default_value: 8.196151733398438 + read_only: false + value_range: + - 5.894128799438477 + - 8.821040153503418 + unit: kG + QUAD:LI25:901:BACT: + variable_class: TorchScalarVariable + default_value: -8.082236289978027 + read_only: false + value_range: + - -8.701128005981445 + - -5.903156280517578 + unit: kG + QUAD:LI26:201:BACT: + variable_class: TorchScalarVariable + default_value: 8.905728340148926 + read_only: false + value_range: + - 0.19921469688415527 + - 15.584007263183594 + unit: kG + QUAD:LI26:301:BACT: + variable_class: TorchScalarVariable + default_value: -8.64865493774414 + read_only: false + value_range: + - -15.154759407043457 + - -0.20027148723602295 + unit: kG + QUAD:LI26:401:BACT: + variable_class: TorchScalarVariable + default_value: 10.174625396728516 + read_only: false + value_range: + - 0.20270586013793945 + - 19.882917404174805 + unit: kG + QUAD:LI26:501:BACT: + variable_class: TorchScalarVariable + default_value: -9.74402904510498 + read_only: false + value_range: + - -19.614015579223633 + - -3.0157687664031982 + unit: kG + QUAD:LI26:601:BACT: + variable_class: TorchScalarVariable + default_value: 11.1459379196167 + read_only: false + value_range: + - 5.45085334777832 + - 20.66390609741211 + unit: kG + QUAD:LI26:701:BACT: + variable_class: TorchScalarVariable + default_value: -10.12381362915039 + read_only: false + value_range: + - -18.370912551879883 + - -5.957860946655273 + unit: kG + QUAD:LI26:801:BACT: + variable_class: TorchScalarVariable + default_value: 11.111616134643555 + read_only: false + value_range: + - 4.757839679718018 + - 17.604393005371094 + unit: kG + QUAD:LI26:901:BACT: + variable_class: TorchScalarVariable + default_value: -6.741613388061523 + read_only: false + value_range: + - -14.644014358520508 + - -1.6580276489257812 + unit: kG + QUAD:LI27:201:BACT: + variable_class: TorchScalarVariable + default_value: 10.094886779785156 + read_only: false + value_range: + - 8.172499656677246 + - 11.214076042175293 + unit: kG + QUAD:LI27:301:BACT: + variable_class: TorchScalarVariable + default_value: -10.549817085266113 + read_only: false + value_range: + - -11.98211669921875 + - -8.845065116882324 + unit: kG + QUAD:LI27:401:BACT: + variable_class: TorchScalarVariable + default_value: 10.561673164367676 + read_only: false + value_range: + - 8.908507347106934 + - 11.973215103149414 + unit: kG + QUAD:LI27:501:BACT: + variable_class: TorchScalarVariable + default_value: -10.882133483886719 + read_only: false + value_range: + - -12.33036994934082 + - -9.249858856201172 + unit: kG + QUAD:LI27:601:BACT: + variable_class: TorchScalarVariable + default_value: 11.223258018493652 + read_only: false + value_range: + - 9.59332275390625 + - 12.69169807434082 + unit: kG + QUAD:LI27:701:BACT: + variable_class: TorchScalarVariable + default_value: -11.427587509155273 + read_only: false + value_range: + - -12.907695770263672 + - -9.589673042297363 + unit: kG + QUAD:LI27:801:BACT: + variable_class: TorchScalarVariable + default_value: 12.065448760986328 + read_only: false + value_range: + - 9.860147476196289 + - 13.635490417480469 + unit: kG + QUAD:LI27:901:BACT: + variable_class: TorchScalarVariable + default_value: -11.866600036621094 + read_only: false + value_range: + - -13.421582221984863 + - -9.440723419189453 + unit: kG + QUAD:LI28:201:BACT: + variable_class: TorchScalarVariable + default_value: 11.9609375 + read_only: false + value_range: + - 9.472262382507324 + - 13.893677711486816 + unit: kG + QUAD:LI28:301:BACT: + variable_class: TorchScalarVariable + default_value: -12.753613948822021 + read_only: false + value_range: + - -14.007567405700684 + - -10.167932510375977 + unit: kG + QUAD:LI28:401:BACT: + variable_class: TorchScalarVariable + default_value: 12.519538879394531 + read_only: false + value_range: + - 6.579861164093018 + - 13.932640075683594 + unit: kG + QUAD:LI28:501:BACT: + variable_class: TorchScalarVariable + default_value: -12.634086608886719 + read_only: false + value_range: + - -14.213104248046875 + - -0.19370371103286743 + unit: kG + QUAD:LI28:601:BACT: + variable_class: TorchScalarVariable + default_value: 12.7022066116333 + read_only: false + value_range: + - 3.7928245067596436 + - 14.216349601745605 + unit: kG + QUAD:LI28:701:BACT: + variable_class: TorchScalarVariable + default_value: -12.894618034362793 + read_only: false + value_range: + - -14.55186939239502 + - -0.1930026412010193 + unit: kG + QUAD:LI28:801:BACT: + variable_class: TorchScalarVariable + default_value: 13.278484344482422 + read_only: false + value_range: + - 4.67686128616333 + - 14.962789535522461 + unit: kG + QUAD:LI28:901:BACT: + variable_class: TorchScalarVariable + default_value: -12.830718040466309 + read_only: false + value_range: + - -15.136317253112793 + - -10.62944507598877 + unit: kG + QUAD:LI29:201:BACT: + variable_class: TorchScalarVariable + default_value: 12.873763084411621 + read_only: false + value_range: + - 11.162287712097168 + - 14.436914443969727 + unit: kG + QUAD:LI29:301:BACT: + variable_class: TorchScalarVariable + default_value: -13.665643692016602 + read_only: false + value_range: + - -15.086411476135254 + - -11.917793273925781 + unit: kG + QUAD:LI29:401:BACT: + variable_class: TorchScalarVariable + default_value: 13.422246932983398 + read_only: false + value_range: + - 11.776640892028809 + - 14.72998332977295 + unit: kG + QUAD:LI29:501:BACT: + variable_class: TorchScalarVariable + default_value: -13.534170150756836 + read_only: false + value_range: + - -14.724255561828613 + - -12.009578704833984 + unit: kG + QUAD:LI29:601:BACT: + variable_class: TorchScalarVariable + default_value: 13.623615264892578 + read_only: false + value_range: + - 12.262092590332031 + - 14.792816162109375 + unit: kG + QUAD:LI29:701:BACT: + variable_class: TorchScalarVariable + default_value: -13.72568130493164 + read_only: false + value_range: + - -14.942991256713867 + - -12.557027816772461 + unit: kG + QUAD:LI29:801:BACT: + variable_class: TorchScalarVariable + default_value: 14.187458992004395 + read_only: false + value_range: + - 13.038265228271484 + - 15.494569778442383 + unit: kG + QUAD:LI29:901:BACT: + variable_class: TorchScalarVariable + default_value: -13.750750541687012 + read_only: false + value_range: + - -14.965811729431152 + - -12.749227523803711 + unit: kG + QUAD:LI30:201:BACT: + variable_class: TorchScalarVariable + default_value: 13.900449752807617 + read_only: false + value_range: + - 13.056685447692871 + - 15.010658264160156 + unit: kG + QUAD:LI30:301:BACT: + variable_class: TorchScalarVariable + default_value: -14.54440689086914 + read_only: false + value_range: + - -15.614253044128418 + - -13.801875114440918 + unit: kG + QUAD:LI30:401:BACT: + variable_class: TorchScalarVariable + default_value: 14.226929664611816 + read_only: false + value_range: + - 13.69515609741211 + - 15.213142395019531 + unit: kG + QUAD:LI30:501:BACT: + variable_class: TorchScalarVariable + default_value: -14.464568138122559 + read_only: false + value_range: + - -15.207056045532227 + - -13.957844734191895 + unit: kG + QUAD:LI30:601:BACT: + variable_class: TorchScalarVariable + default_value: 14.611154556274414 + read_only: false + value_range: + - 14.037918090820312 + - 15.212827682495117 + unit: kG + QUAD:LI30:701:BACT: + variable_class: TorchScalarVariable + default_value: -14.73243236541748 + read_only: false + value_range: + - -15.229225158691406 + - -14.343217849731445 + unit: kG + QUAD:LI30:801:BACT: + variable_class: TorchScalarVariable + default_value: 18.059956550598145 + read_only: false + value_range: + - 17.74070930480957 + - 18.47154426574707 + unit: kG + QUAD:IN20:631:BACT: + variable_class: TorchScalarVariable + default_value: 7.1585211753845215 + read_only: false + value_range: + - 7.153985977172852 + - 7.1621880531311035 + unit: kG + QUAD:IN20:651:BACT: + variable_class: TorchScalarVariable + default_value: -5.918021202087402 + read_only: false + value_range: + - -5.921041488647461 + - -5.817676544189453 + unit: kG + QUAD:IN20:731:BACT: + variable_class: TorchScalarVariable + default_value: 10.907441139221191 + read_only: false + value_range: + - 10.724224090576172 + - 10.911758422851562 + unit: kG + QUAD:IN20:771:BACT: + variable_class: TorchScalarVariable + default_value: -3.469513177871704 + read_only: false + value_range: + - -3.473116636276245 + - -3.41040301322937 + unit: kG + QUAD:IN20:781:BACT: + variable_class: TorchScalarVariable + default_value: 6.631329536437988 + read_only: false + value_range: + - 6.627516269683838 + - 6.637024402618408 + unit: kG + QUAD:LI21:131:BACT: + variable_class: TorchScalarVariable + default_value: -2.4340152740478516 + read_only: false + value_range: + - -2.4352543354034424 + - -2.4310882091522217 + unit: kG + QUAD:LI21:161:BACT: + variable_class: TorchScalarVariable + default_value: 1.3784031867980957 + read_only: false + value_range: + - 1.3774464130401611 + - 1.379645586013794 + unit: kG + QUAD:LI21:278:BACT: + variable_class: TorchScalarVariable + default_value: 7.573178768157959 + read_only: false + value_range: + - 5.390344142913818 + - 10.096536636352539 + unit: kG + QUAD:LI21:315:BACT: + variable_class: TorchScalarVariable + default_value: 5.590969562530518 + read_only: false + value_range: + - 5.388442516326904 + - 5.799100399017334 + unit: kG + SOLN:IN20:121:BACT: + variable_class: TorchScalarVariable + default_value: 0.4843061864376068 + read_only: false + value_range: + - 0.4750012755393982 + - 0.4898073077201843 + unit: kG-m + SOLN:IN20:311:BACT: + variable_class: TorchScalarVariable + default_value: -0.000622840307187289 + read_only: false + value_range: + - -0.0006276898202486336 + - -0.000619793776422739 + unit: kG-m + QUAD:IN20:121:BACT: + variable_class: TorchScalarVariable + default_value: 0.0037149195559322834 + read_only: false + value_range: + - -0.012858917005360126 + - 0.014996109530329704 + unit: kG + QUAD:IN20:122:BACT: + variable_class: TorchScalarVariable + default_value: 0.004051219206303358 + read_only: false + value_range: + - -0.011106831952929497 + - 0.014521649107336998 + unit: kG + QUAD:IN20:361:BACT: + variable_class: TorchScalarVariable + default_value: -3.630293846130371 + read_only: false + value_range: + - -4.05964994430542 + - -3.170670747756958 + unit: kG + QUAD:IN20:371:BACT: + variable_class: TorchScalarVariable + default_value: 2.7550361156463623 + read_only: false + value_range: + - 2.470209836959839 + - 3.0689961910247803 + unit: kG + QUAD:IN20:425:BACT: + variable_class: TorchScalarVariable + default_value: -1.6361221075057983 + read_only: false + value_range: + - -3.1995935440063477 + - -0.5901550054550171 + unit: kG + QUAD:IN20:441:BACT: + variable_class: TorchScalarVariable + default_value: 0.07104134559631348 + read_only: false + value_range: + - -0.538829505443573 + - 1.268821358680725 + unit: kG + QUAD:IN20:511:BACT: + variable_class: TorchScalarVariable + default_value: 2.8956358432769775 + read_only: false + value_range: + - 0.6183972358703613 + - 4.204927444458008 + unit: kG + QUAD:IN20:525:BACT: + variable_class: TorchScalarVariable + default_value: -2.226306200027466 + read_only: false + value_range: + - -3.698307514190674 + - -0.8770037889480591 + unit: kG + ACCL:LI21:1:L1S_S_AV: + variable_class: TorchScalarVariable + default_value: 105.69712448120117 + read_only: false + value_range: + - 100.00001525878906 + - 111.22259521484375 + unit: Megavolts + ACCL:LI21:180:L1X_S_AV: + variable_class: TorchScalarVariable + default_value: 18.41381072998047 + read_only: false + value_range: + - 6.948431968688965 + - 25.50543975830078 + unit: Megavolts + ACCL:LI22:1:ADES: + variable_class: TorchScalarVariable + default_value: 5227.193359375 + read_only: false + value_range: + - 3502.705322265625 + - 5997.24365234375 + unit: MeV + ACCL:LI25:1:ADES: + variable_class: TorchScalarVariable + default_value: 6133.2021484375 + read_only: false + value_range: + - 5606.73388671875 + - 8023.0810546875 + unit: MeV + ACCL:LI21:1:L1S_S_PV: + variable_class: TorchScalarVariable + default_value: -22.458297729492188 + read_only: false + value_range: + - -33.887779235839844 + - -15.789875030517578 + unit: deg 2856 MHz + ACCL:LI21:180:L1X_S_PV: + variable_class: TorchScalarVariable + default_value: -159.9999237060547 + read_only: false + value_range: + - -175.42947387695312 + - -156.74661254882812 + unit: deg 11.424 GHz + ACCL:LI22:1:PDES: + variable_class: TorchScalarVariable + default_value: -36.95354461669922 + read_only: false + value_range: + - -44.52250289916992 + - -26.240581512451172 + unit: Degrees + CAMR:IN20:186:XRMS: + variable_class: TorchScalarVariable + default_value: 334.7821044921875 + read_only: false + value_range: + - 250.59193420410156 + - 379.858154296875 + unit: um + CAMR:IN20:186:YRMS: + variable_class: TorchScalarVariable + default_value: 325.3790588378906 + read_only: false + value_range: + - 251.82470703125 + - 377.97906494140625 + unit: um + BLEN:LI21:265:AIMAX1H: + variable_class: TorchScalarVariable + default_value: 216.41799926757812 + read_only: false + value_range: + - 21.628271102905273 + - 295.4963073730469 + unit: A + BLEN:LI24:886:BIMAX1H: + variable_class: TorchScalarVariable + default_value: 3116.6708984375 + read_only: false + value_range: + - 1230.0247802734375 + - 5643.43408203125 + unit: A + SIOC:SYS0:ML00:CALC038: + variable_class: TorchScalarVariable + default_value: 250.0469512939453 + read_only: false + value_range: + - 240.00051879882812 + - 274.9855651855469 + unit: pC + SIOC:SYS0:ML00:CALC252: + variable_class: TorchScalarVariable + default_value: 178.77903747558594 + read_only: false + value_range: + - 0.0 + - 199.99745178222656 + unit: pC + BEND:DMPH:400:BACT: + variable_class: TorchScalarVariable + default_value: 10.62000846862793 + read_only: false + value_range: + - 10.514976501464844 + - 10.789048194885254 + unit: GeV/c + SIOC:SYS0:ML00:AO627: + variable_class: TorchScalarVariable + default_value: 9718.16796875 + read_only: false + value_range: + - 9500.0078125 + - 9999.8466796875 + unit: eV + XCOR:UNDH:1380:BACT: + variable_class: TorchScalarVariable + default_value: 3.13312302751001e-05 + read_only: false + value_range: + - -0.0009821036364883184 + - 0.0009955056011676788 + unit: kG-m + XCOR:UNDH:1480:BACT: + variable_class: TorchScalarVariable + default_value: 9.630867862142622e-05 + read_only: false + value_range: + - -0.0002964562445413321 + - 0.000836852181237191 + unit: kG-m + XCOR:UNDH:1580:BACT: + variable_class: TorchScalarVariable + default_value: 0.0001912557054311037 + read_only: false + value_range: + - -0.0003992630518041551 + - 0.000698764924891293 + unit: kG-m + XCOR:UNDH:1680:BACT: + variable_class: TorchScalarVariable + default_value: 4.132541289436631e-05 + read_only: false + value_range: + - -0.0002583581954240799 + - 0.0002874867932405323 + unit: kG-m + XCOR:UNDH:1780:BACT: + variable_class: TorchScalarVariable + default_value: -0.00010225858568446711 + read_only: false + value_range: + - -0.0005246761720627546 + - 0.00040158562478609383 + unit: kG-m + XCOR:UNDH:1880:BACT: + variable_class: TorchScalarVariable + default_value: -0.0001250849454663694 + read_only: false + value_range: + - -0.0003737287479452789 + - 0.0003176488680765033 + unit: kG-m + XCOR:UNDH:1980:BACT: + variable_class: TorchScalarVariable + default_value: -0.0001198389581986703 + read_only: false + value_range: + - -0.000429774314397946 + - 0.0005280743353068829 + unit: kG-m + XCOR:UNDH:2080:BACT: + variable_class: TorchScalarVariable + default_value: -1.230518682859838e-05 + read_only: false + value_range: + - -0.0004994860501028597 + - 0.0009310322348028421 + unit: kG-m + XCOR:UNDH:2180:BACT: + variable_class: TorchScalarVariable + default_value: 2.3291771867661737e-05 + read_only: false + value_range: + - -0.0007958629867061973 + - 0.0009633363224565983 + unit: kG-m + XCOR:UNDH:2280:BACT: + variable_class: TorchScalarVariable + default_value: 6.911856871738564e-06 + read_only: false + value_range: + - -0.0006120636244304478 + - 0.0005776818725280464 + unit: kG-m + XCOR:UNDH:2380:BACT: + variable_class: TorchScalarVariable + default_value: -3.974194987677038e-05 + read_only: false + value_range: + - -0.0002869816089514643 + - 0.0002396650961600244 + unit: kG-m + XCOR:UNDH:2480:BACT: + variable_class: TorchScalarVariable + default_value: -2.5063609427888878e-05 + read_only: false + value_range: + - -0.0006338375387713313 + - 0.00015527963114436716 + unit: kG-m + XCOR:UNDH:2580:BACT: + variable_class: TorchScalarVariable + default_value: 7.192694283730816e-06 + read_only: false + value_range: + - -0.0003280419623479247 + - 0.0002896543883252889 + unit: kG-m + XCOR:UNDH:2680:BACT: + variable_class: TorchScalarVariable + default_value: 3.241708691348322e-05 + read_only: false + value_range: + - -0.00016108786803670228 + - 0.0005595804541371763 + unit: kG-m + XCOR:UNDH:2780:BACT: + variable_class: TorchScalarVariable + default_value: 4.75671658932697e-05 + read_only: false + value_range: + - -0.0008402586099691689 + - 0.0005265165818855166 + unit: kG-m + XCOR:UNDH:2880:BACT: + variable_class: TorchScalarVariable + default_value: -5.291559318720829e-06 + read_only: false + value_range: + - -0.000255841325270012 + - 0.0009620104683563113 + unit: kG-m + XCOR:UNDH:2980:BACT: + variable_class: TorchScalarVariable + default_value: -6.859230779809877e-05 + read_only: false + value_range: + - -0.000788069621194154 + - 0.00013974700414109975 + unit: kG-m + XCOR:UNDH:3080:BACT: + variable_class: TorchScalarVariable + default_value: -8.781007636571303e-05 + read_only: false + value_range: + - -0.0003647462581284344 + - 7.703727169428021e-05 + unit: kG-m + XCOR:UNDH:3180:BACT: + variable_class: TorchScalarVariable + default_value: -9.890428191283718e-05 + read_only: false + value_range: + - -0.000600970524828881 + - 0.00024407422461081296 + unit: kG-m + XCOR:UNDH:3280:BACT: + variable_class: TorchScalarVariable + default_value: -2.2034822904970497e-05 + read_only: false + value_range: + - -0.0008363833767361939 + - 0.0003439175197854638 + unit: kG-m + XCOR:UNDH:3380:BACT: + variable_class: TorchScalarVariable + default_value: 6.628128517149889e-07 + read_only: false + value_range: + - -0.00027618854073807597 + - 0.0002918792306445539 + unit: kG-m + XCOR:UNDH:3480:BACT: + variable_class: TorchScalarVariable + default_value: 1.1350202839821577e-06 + read_only: false + value_range: + - -0.00026849121786653996 + - 0.0005286589730530977 + unit: kG-m + XCOR:UNDH:3580:BACT: + variable_class: TorchScalarVariable + default_value: 6.533164196298458e-06 + read_only: false + value_range: + - -0.0004505771794356406 + - 0.00020057357323821634 + unit: kG-m + XCOR:UNDH:3680:BACT: + variable_class: TorchScalarVariable + default_value: 2.2087098841439e-05 + read_only: false + value_range: + - -0.00022451893892139196 + - 0.00032661628210917115 + unit: kG-m + XCOR:UNDH:3780:BACT: + variable_class: TorchScalarVariable + default_value: 3.672538514365442e-05 + read_only: false + value_range: + - -0.00045030718320049345 + - 0.0005812929593957961 + unit: kG-m + XCOR:UNDH:3880:BACT: + variable_class: TorchScalarVariable + default_value: -2.799393712393794e-07 + read_only: false + value_range: + - -0.00025016232393682003 + - 0.0002342849038541317 + unit: kG-m + XCOR:UNDH:3980:BACT: + variable_class: TorchScalarVariable + default_value: -4.283879025024362e-05 + read_only: false + value_range: + - -0.000595622812397778 + - 0.0004537559289019555 + unit: kG-m + XCOR:UNDH:4080:BACT: + variable_class: TorchScalarVariable + default_value: -7.95123414718546e-05 + read_only: false + value_range: + - -0.00026854994939640164 + - 6.59581201034598e-05 + unit: kG-m + XCOR:UNDH:4180:BACT: + variable_class: TorchScalarVariable + default_value: -0.00011508604802656919 + read_only: false + value_range: + - -0.000695984810590744 + - 0.0005792076117359102 + unit: kG-m + XCOR:UNDH:4280:BACT: + variable_class: TorchScalarVariable + default_value: -6.0163034504512325e-05 + read_only: false + value_range: + - -0.0006600914057344198 + - 0.0008707446977496147 + unit: kG-m + XCOR:UNDH:4380:BACT: + variable_class: TorchScalarVariable + default_value: -4.7088681753848505e-07 + read_only: false + value_range: + - -0.0006451521185226738 + - 0.0009396484238095582 + unit: kG-m + XCOR:UNDH:4480:BACT: + variable_class: TorchScalarVariable + default_value: 6.965340435272083e-05 + read_only: false + value_range: + - -0.0003751741605810821 + - 0.0006930948002263904 + unit: kG-m + XCOR:UNDH:4580:BACT: + variable_class: TorchScalarVariable + default_value: 8.208939107134938e-05 + read_only: false + value_range: + - -0.0009115072898566723 + - 0.0009999098256230354 + unit: kG-m + XCOR:UNDH:4680:BACT: + variable_class: TorchScalarVariable + default_value: 3.859415301121771e-05 + read_only: false + value_range: + - -0.0009910506196320057 + - 0.000999510521069169 + unit: kG-m + XCOR:UNDH:4780:BACT: + variable_class: TorchScalarVariable + default_value: 2.317506869076169e-06 + read_only: false + value_range: + - -0.0007537493947893381 + - 0.0002590437652543187 + unit: kG-m + YCOR:UNDH:1380:BACT: + variable_class: TorchScalarVariable + default_value: 0.00017729130922816694 + read_only: false + value_range: + - -0.0007998915389180183 + - 0.002322693355381489 + unit: kG-m + YCOR:UNDH:1480:BACT: + variable_class: TorchScalarVariable + default_value: 0.00031440614839084446 + read_only: false + value_range: + - -0.001001303200609982 + - 0.0020921085961163044 + unit: kG-m + YCOR:UNDH:1580:BACT: + variable_class: TorchScalarVariable + default_value: 0.0001898530317703262 + read_only: false + value_range: + - -0.0011799116618931293 + - 0.0010067607508972287 + unit: kG-m + YCOR:UNDH:1680:BACT: + variable_class: TorchScalarVariable + default_value: 0.00014480395475402474 + read_only: false + value_range: + - -0.0009916082490235567 + - 0.0007648301543667912 + unit: kG-m + YCOR:UNDH:1780:BACT: + variable_class: TorchScalarVariable + default_value: 5.8549034292809665e-05 + read_only: false + value_range: + - -0.00043671546154655516 + - 0.00047224925947375596 + unit: kG-m + YCOR:UNDH:1880:BACT: + variable_class: TorchScalarVariable + default_value: 6.50418660370633e-05 + read_only: false + value_range: + - -0.0005957565153948963 + - 0.0011087642051279545 + unit: kG-m + YCOR:UNDH:1980:BACT: + variable_class: TorchScalarVariable + default_value: 7.378652662737295e-05 + read_only: false + value_range: + - -0.00016657126252539456 + - 0.000654485949780792 + unit: kG-m + YCOR:UNDH:2080:BACT: + variable_class: TorchScalarVariable + default_value: 9.250422408513259e-06 + read_only: false + value_range: + - -0.0005237142322584987 + - 0.0015063132159411907 + unit: kG-m + YCOR:UNDH:2180:BACT: + variable_class: TorchScalarVariable + default_value: -3.7039623634882446e-07 + read_only: false + value_range: + - -0.000575279991608113 + - 0.0008172884117811918 + unit: kG-m + YCOR:UNDH:2280:BACT: + variable_class: TorchScalarVariable + default_value: -2.622389729367569e-05 + read_only: false + value_range: + - -0.0006034813122823834 + - 0.0005024568527005613 + unit: kG-m + YCOR:UNDH:2380:BACT: + variable_class: TorchScalarVariable + default_value: 4.5798168457622523e-07 + read_only: false + value_range: + - -0.00027631359989754856 + - 0.00037451452226378024 + unit: kG-m + YCOR:UNDH:2480:BACT: + variable_class: TorchScalarVariable + default_value: 3.1043302442412823e-05 + read_only: false + value_range: + - -0.00037303115823306143 + - 0.0004823935159947723 + unit: kG-m + YCOR:UNDH:2580:BACT: + variable_class: TorchScalarVariable + default_value: 3.581157943699509e-05 + read_only: false + value_range: + - -0.000279325497103855 + - 0.00023415032774209976 + unit: kG-m + YCOR:UNDH:2680:BACT: + variable_class: TorchScalarVariable + default_value: 3.493251642794348e-05 + read_only: false + value_range: + - -0.0005424672272056341 + - 0.0003341590636409819 + unit: kG-m + YCOR:UNDH:2780:BACT: + variable_class: TorchScalarVariable + default_value: -4.738057668873807e-06 + read_only: false + value_range: + - -0.0006376646342687309 + - 0.0002725540252868086 + unit: kG-m + YCOR:UNDH:2880:BACT: + variable_class: TorchScalarVariable + default_value: -3.3163527405122295e-05 + read_only: false + value_range: + - -0.00047650589840486646 + - 0.0005619300645776093 + unit: kG-m + YCOR:UNDH:2980:BACT: + variable_class: TorchScalarVariable + default_value: -2.180776937166229e-05 + read_only: false + value_range: + - -0.0004848685930483043 + - 0.0004569693701341748 + unit: kG-m + YCOR:UNDH:3080:BACT: + variable_class: TorchScalarVariable + default_value: 2.912725722126197e-05 + read_only: false + value_range: + - -0.0007536783814430237 + - 0.00027199735632166266 + unit: kG-m + YCOR:UNDH:3180:BACT: + variable_class: TorchScalarVariable + default_value: 5.818250429001637e-05 + read_only: false + value_range: + - -0.0004203379503451288 + - 0.00025513191940262914 + unit: kG-m + YCOR:UNDH:3280:BACT: + variable_class: TorchScalarVariable + default_value: 3.7361638533184305e-05 + read_only: false + value_range: + - -0.0006829249323345721 + - 0.0004671179340220988 + unit: kG-m + YCOR:UNDH:3380:BACT: + variable_class: TorchScalarVariable + default_value: -1.5515148334088735e-05 + read_only: false + value_range: + - -0.0003889016225002706 + - 0.000672376190777868 + unit: kG-m + YCOR:UNDH:3480:BACT: + variable_class: TorchScalarVariable + default_value: -6.104487692937255e-05 + read_only: false + value_range: + - -0.0005380988586694002 + - 0.0007592468173243105 + unit: kG-m + YCOR:UNDH:3580:BACT: + variable_class: TorchScalarVariable + default_value: -4.485617637328687e-07 + read_only: false + value_range: + - -0.00022893176355864853 + - 0.0005933999782428145 + unit: kG-m + YCOR:UNDH:3680:BACT: + variable_class: TorchScalarVariable + default_value: 5.021193283027969e-05 + read_only: false + value_range: + - -0.0004956517950631678 + - 0.00038829297409392893 + unit: kG-m + YCOR:UNDH:3780:BACT: + variable_class: TorchScalarVariable + default_value: 5.110011261422187e-05 + read_only: false + value_range: + - -0.0008113833609968424 + - 0.0005073792999610305 + unit: kG-m + YCOR:UNDH:3880:BACT: + variable_class: TorchScalarVariable + default_value: 3.6485995224211365e-05 + read_only: false + value_range: + - -0.001201955950818956 + - 0.0003546945517882705 + unit: kG-m + YCOR:UNDH:3980:BACT: + variable_class: TorchScalarVariable + default_value: -4.168170562479645e-06 + read_only: false + value_range: + - -0.0003619982744567096 + - 0.00044134663767181337 + unit: kG-m + YCOR:UNDH:4080:BACT: + variable_class: TorchScalarVariable + default_value: 3.254912735428661e-05 + read_only: false + value_range: + - -0.00086312455823645 + - 0.0015412082429975271 + unit: kG-m + YCOR:UNDH:4180:BACT: + variable_class: TorchScalarVariable + default_value: 3.716743231052533e-05 + read_only: false + value_range: + - -0.000343025429174304 + - 0.0018032232765108347 + unit: kG-m + YCOR:UNDH:4280:BACT: + variable_class: TorchScalarVariable + default_value: 4.520393122220412e-05 + read_only: false + value_range: + - -0.0007666326127946377 + - 0.0016142847016453743 + unit: kG-m + YCOR:UNDH:4380:BACT: + variable_class: TorchScalarVariable + default_value: 6.290613964665681e-05 + read_only: false + value_range: + - -0.0002774629683699459 + - 0.0007250587223097682 + unit: kG-m + YCOR:UNDH:4480:BACT: + variable_class: TorchScalarVariable + default_value: 3.94530979974661e-05 + read_only: false + value_range: + - -0.0010996756609529257 + - 0.0009239603532478213 + unit: kG-m + YCOR:UNDH:4580:BACT: + variable_class: TorchScalarVariable + default_value: 1.5519786757067777e-05 + read_only: false + value_range: + - -0.0007436369196511805 + - 0.0009525191853754222 + unit: kG-m + YCOR:UNDH:4680:BACT: + variable_class: TorchScalarVariable + default_value: 4.632295258488739e-06 + read_only: false + value_range: + - -0.0007205481524579227 + - 0.0007914139423519373 + unit: kG-m + YCOR:UNDH:4780:BACT: + variable_class: TorchScalarVariable + default_value: 4.5491628952731844e-07 + read_only: false + value_range: + - -0.0008967298199422657 + - 0.002440386451780796 + unit: kG-m + PHAS:UNDH:1495:GapAct: + variable_class: TorchScalarVariable + default_value: 17.09600067138672 + read_only: false + value_range: + - 12.887749671936035 + - 19.842500686645508 + unit: mm + PHAS:UNDH:1595:GapAct: + variable_class: TorchScalarVariable + default_value: 16.92675018310547 + read_only: false + value_range: + - 13.457249641418457 + - 19.69675064086914 + unit: mm + PHAS:UNDH:1695:GapAct: + variable_class: TorchScalarVariable + default_value: 17.17799949645996 + read_only: false + value_range: + - 13.475500106811523 + - 19.9375 + unit: mm + PHAS:UNDH:1795:GapAct: + variable_class: TorchScalarVariable + default_value: 17.150249481201172 + read_only: false + value_range: + - 13.711999893188477 + - 19.952749252319336 + unit: mm + PHAS:UNDH:1895:GapAct: + variable_class: TorchScalarVariable + default_value: 17.151750564575195 + read_only: false + value_range: + - 12.88325023651123 + - 21.66925048828125 + unit: mm + PHAS:UNDH:1995:GapAct: + variable_class: TorchScalarVariable + default_value: 16.70050048828125 + read_only: false + value_range: + - 13.025500297546387 + - 19.37700080871582 + unit: mm + PHAS:UNDH:2095:GapAct: + variable_class: TorchScalarVariable + default_value: 13.987750053405762 + read_only: false + value_range: + - 12.039750099182129 + - 21.5627498626709 + unit: mm + PHAS:UNDH:2295:GapAct: + variable_class: TorchScalarVariable + default_value: 17.1560001373291 + read_only: false + value_range: + - 15.122750282287598 + - 19.872249603271484 + unit: mm + PHAS:UNDH:2395:GapAct: + variable_class: TorchScalarVariable + default_value: 17.085250854492188 + read_only: false + value_range: + - 15.775500297546387 + - 19.839000701904297 + unit: mm + PHAS:UNDH:2495:GapAct: + variable_class: TorchScalarVariable + default_value: 17.100299835205078 + read_only: false + value_range: + - 15.794549942016602 + - 19.753049850463867 + unit: mm + PHAS:UNDH:2595:GapAct: + variable_class: TorchScalarVariable + default_value: 17.18524932861328 + read_only: false + value_range: + - 15.999750137329102 + - 19.761249542236328 + unit: mm + PHAS:UNDH:2695:GapAct: + variable_class: TorchScalarVariable + default_value: 17.05525016784668 + read_only: false + value_range: + - 15.70300006866455 + - 19.62350082397461 + unit: mm + PHAS:UNDH:2795:GapAct: + variable_class: TorchScalarVariable + default_value: 13.4375 + read_only: false + value_range: + - 12.000499725341797 + - 21.482999801635742 + unit: mm + PHAS:UNDH:2995:GapAct: + variable_class: TorchScalarVariable + default_value: 17.074249267578125 + read_only: false + value_range: + - 15.177499771118164 + - 19.37299919128418 + unit: mm + PHAS:UNDH:3095:GapAct: + variable_class: TorchScalarVariable + default_value: 17.328250885009766 + read_only: false + value_range: + - 15.979000091552734 + - 19.485000610351562 + unit: mm + PHAS:UNDH:3195:GapAct: + variable_class: TorchScalarVariable + default_value: 17.351749420166016 + read_only: false + value_range: + - 16.09025001525879 + - 19.515750885009766 + unit: mm + PHAS:UNDH:3295:GapAct: + variable_class: TorchScalarVariable + default_value: 17.33074951171875 + read_only: false + value_range: + - 16.107749938964844 + - 19.400249481201172 + unit: mm + PHAS:UNDH:3395:GapAct: + variable_class: TorchScalarVariable + default_value: 17.22504997253418 + read_only: false + value_range: + - 15.645050048828125 + - 19.246299743652344 + unit: mm + PHAS:UNDH:3495:GapAct: + variable_class: TorchScalarVariable + default_value: 17.085750579833984 + read_only: false + value_range: + - 15.306249618530273 + - 19.056499481201172 + unit: mm + PHAS:UNDH:3595:GapAct: + variable_class: TorchScalarVariable + default_value: 17.528499603271484 + read_only: false + value_range: + - 16.104000091552734 + - 19.414499282836914 + unit: mm + PHAS:UNDH:3695:GapAct: + variable_class: TorchScalarVariable + default_value: 17.35955047607422 + read_only: false + value_range: + - 15.976799964904785 + - 19.209800720214844 + unit: mm + PHAS:UNDH:3795:GapAct: + variable_class: TorchScalarVariable + default_value: 17.451250076293945 + read_only: false + value_range: + - 16.036500930786133 + - 19.357749938964844 + unit: mm + PHAS:UNDH:3895:GapAct: + variable_class: TorchScalarVariable + default_value: 17.1924991607666 + read_only: false + value_range: + - 15.628000259399414 + - 19.13425064086914 + unit: mm + PHAS:UNDH:3995:GapAct: + variable_class: TorchScalarVariable + default_value: 17.428499221801758 + read_only: false + value_range: + - 15.836750030517578 + - 19.548749923706055 + unit: mm + PHAS:UNDH:4095:GapAct: + variable_class: TorchScalarVariable + default_value: 17.29599952697754 + read_only: false + value_range: + - 15.634499549865723 + - 19.4377498626709 + unit: mm + PHAS:UNDH:4195:GapAct: + variable_class: TorchScalarVariable + default_value: 17.535749435424805 + read_only: false + value_range: + - 15.929499626159668 + - 19.74074935913086 + unit: mm + PHAS:UNDH:4295:GapAct: + variable_class: TorchScalarVariable + default_value: 17.65625 + read_only: false + value_range: + - 16.04924964904785 + - 19.942249298095703 + unit: mm + PHAS:UNDH:4395:GapAct: + variable_class: TorchScalarVariable + default_value: 17.837749481201172 + read_only: false + value_range: + - 16.163249969482422 + - 20.100000381469727 + unit: mm + PHAS:UNDH:4495:GapAct: + variable_class: TorchScalarVariable + default_value: 17.925050735473633 + read_only: false + value_range: + - 16.167049407958984 + - 20.292800903320312 + unit: mm + PHAS:UNDH:4595:GapAct: + variable_class: TorchScalarVariable + default_value: 17.870250701904297 + read_only: false + value_range: + - 16.056249618530273 + - 20.256500244140625 + unit: mm + PHAS:UNDH:4695:GapAct: + variable_class: TorchScalarVariable + default_value: 18.060749053955078 + read_only: false + value_range: + - 16.15974998474121 + - 20.651500701904297 + unit: mm + USEG:UNDH:1450:GapAct: + variable_class: TorchScalarVariable + default_value: 7.361015796661377 + read_only: false + value_range: + - 7.279615879058838 + - 7.818066120147705 + unit: mm + USEG:UNDH:1550:GapAct: + variable_class: TorchScalarVariable + default_value: 7.30649995803833 + read_only: false + value_range: + - 7.224699974060059 + - 7.689549922943115 + unit: mm + USEG:UNDH:1650:GapAct: + variable_class: TorchScalarVariable + default_value: 7.34915018081665 + read_only: false + value_range: + - 7.26485013961792 + - 7.781050205230713 + unit: mm + USEG:UNDH:1750:GapAct: + variable_class: TorchScalarVariable + default_value: 7.351600170135498 + read_only: false + value_range: + - 7.26800012588501 + - 7.856249809265137 + unit: mm + USEG:UNDH:1850:GapAct: + variable_class: TorchScalarVariable + default_value: 7.363550186157227 + read_only: false + value_range: + - 7.281449794769287 + - 7.713500022888184 + unit: mm + USEG:UNDH:1950:GapAct: + variable_class: TorchScalarVariable + default_value: 7.373700141906738 + read_only: false + value_range: + - 7.2893500328063965 + - 7.892950057983398 + unit: mm + USEG:UNDH:2050:GapAct: + variable_class: TorchScalarVariable + default_value: 7.415949821472168 + read_only: false + value_range: + - 7.33489990234375 + - 7.853750228881836 + unit: mm + USEG:UNDH:2250:GapAct: + variable_class: TorchScalarVariable + default_value: 7.3844499588012695 + read_only: false + value_range: + - 7.302999973297119 + - 7.526899814605713 + unit: mm + USEG:UNDH:2350:GapAct: + variable_class: TorchScalarVariable + default_value: 7.341549873352051 + read_only: false + value_range: + - 7.261600017547607 + - 7.484300136566162 + unit: mm + USEG:UNDH:2450:GapAct: + variable_class: TorchScalarVariable + default_value: 7.395100116729736 + read_only: false + value_range: + - 7.315549850463867 + - 7.534749984741211 + unit: mm + USEG:UNDH:2550:GapAct: + variable_class: TorchScalarVariable + default_value: 7.377200126647949 + read_only: false + value_range: + - 7.2970499992370605 + - 7.513150215148926 + unit: mm + USEG:UNDH:2650:GapAct: + variable_class: TorchScalarVariable + default_value: 7.381100177764893 + read_only: false + value_range: + - 7.300250053405762 + - 7.513599872589111 + unit: mm + USEG:UNDH:2750:GapAct: + variable_class: TorchScalarVariable + default_value: 7.34975004196167 + read_only: false + value_range: + - 7.271550178527832 + - 7.478300094604492 + unit: mm + USEG:UNDH:2950:GapAct: + variable_class: TorchScalarVariable + default_value: 7.348100185394287 + read_only: false + value_range: + - 7.263750076293945 + - 7.472449779510498 + unit: mm + USEG:UNDH:3050:GapAct: + variable_class: TorchScalarVariable + default_value: 7.388850212097168 + read_only: false + value_range: + - 7.3042497634887695 + - 7.509349822998047 + unit: mm + USEG:UNDH:3150:GapAct: + variable_class: TorchScalarVariable + default_value: 7.359650135040283 + read_only: false + value_range: + - 7.274099826812744 + - 7.476900100708008 + unit: mm + USEG:UNDH:3250:GapAct: + variable_class: TorchScalarVariable + default_value: 7.302149772644043 + read_only: false + value_range: + - 7.216700077056885 + - 7.415649890899658 + unit: mm + USEG:UNDH:3350:GapAct: + variable_class: TorchScalarVariable + default_value: 7.351399898529053 + read_only: false + value_range: + - 7.26455020904541 + - 7.462900161743164 + unit: mm + USEG:UNDH:3450:GapAct: + variable_class: TorchScalarVariable + default_value: 7.383646011352539 + read_only: false + value_range: + - 7.296596050262451 + - 7.490096092224121 + unit: mm + USEG:UNDH:3550:GapAct: + variable_class: TorchScalarVariable + default_value: 7.361299991607666 + read_only: false + value_range: + - 7.273449897766113 + - 7.786499977111816 + unit: mm + USEG:UNDH:3650:GapAct: + variable_class: TorchScalarVariable + default_value: 7.330599784851074 + read_only: false + value_range: + - 7.241399765014648 + - 7.441450119018555 + unit: mm + USEG:UNDH:3750:GapAct: + variable_class: TorchScalarVariable + default_value: 7.390850067138672 + read_only: false + value_range: + - 7.298250198364258 + - 7.496600151062012 + unit: mm + USEG:UNDH:3850:GapAct: + variable_class: TorchScalarVariable + default_value: 7.423999786376953 + read_only: false + value_range: + - 7.329649925231934 + - 7.530849933624268 + unit: mm + USEG:UNDH:3950:GapAct: + variable_class: TorchScalarVariable + default_value: 7.375850200653076 + read_only: false + value_range: + - 7.278649806976318 + - 7.482250213623047 + unit: mm + USEG:UNDH:4050:GapAct: + variable_class: TorchScalarVariable + default_value: 7.404399871826172 + read_only: false + value_range: + - 7.3043999671936035 + - 7.512650012969971 + unit: mm + USEG:UNDH:4150:GapAct: + variable_class: TorchScalarVariable + default_value: 7.379950046539307 + read_only: false + value_range: + - 7.280350208282471 + - 7.491950035095215 + unit: mm + USEG:UNDH:4250:GapAct: + variable_class: TorchScalarVariable + default_value: 7.43149995803833 + read_only: false + value_range: + - 7.328199863433838 + - 7.5457000732421875 + unit: mm + USEG:UNDH:4350:GapAct: + variable_class: TorchScalarVariable + default_value: 7.406050205230713 + read_only: false + value_range: + - 7.29925012588501 + - 7.521850109100342 + unit: mm + USEG:UNDH:4450:GapAct: + variable_class: TorchScalarVariable + default_value: 7.386149883270264 + read_only: false + value_range: + - 7.27554988861084 + - 7.502200126647949 + unit: mm + USEG:UNDH:4550:GapAct: + variable_class: TorchScalarVariable + default_value: 7.370250225067139 + read_only: false + value_range: + - 7.259799957275391 + - 7.48829984664917 + unit: mm + USEG:UNDH:4650:GapAct: + variable_class: TorchScalarVariable + default_value: 7.40084981918335 + read_only: false + value_range: + - 7.28754997253418 + - 7.523250102996826 + unit: mm + USEG:UNDH:4750:GapAct: + variable_class: TorchScalarVariable + default_value: 7.515850067138672 + read_only: false + value_range: + - 7.395750045776367 + - 7.641449928283691 + unit: mm +model: resources/lcls_fel_final_model_cpu.pt +model_class: TorchModule +output_format: tensor +output_transformers: +- resources/lcls_fel_output_scaler.pt +output_variables: + GDET:FEE1:241:ENRC: + read_only: false + variable_class: TorchScalarVariable + unit: mJ +precision: double diff --git a/examples/slac_fel/model/final_lcls_fel_model.pt b/examples/slac_fel/model/final_lcls_fel_model.pt new file mode 100644 index 00000000..ccb3a28d Binary files /dev/null and b/examples/slac_fel/model/final_lcls_fel_model.pt differ diff --git a/examples/slac_fel/model/lcls_fel_input_scaler.pt b/examples/slac_fel/model/lcls_fel_input_scaler.pt new file mode 100644 index 00000000..60d115f2 Binary files /dev/null and b/examples/slac_fel/model/lcls_fel_input_scaler.pt differ diff --git a/examples/slac_fel/model/lcls_fel_output_scaler.pt b/examples/slac_fel/model/lcls_fel_output_scaler.pt new file mode 100644 index 00000000..74f25ed1 Binary files /dev/null and b/examples/slac_fel/model/lcls_fel_output_scaler.pt differ diff --git a/examples/slac_fel/plot_tutorial.py b/examples/slac_fel/plot_tutorial.py new file mode 100644 index 00000000..58429b67 --- /dev/null +++ b/examples/slac_fel/plot_tutorial.py @@ -0,0 +1,395 @@ +"""Reproduce the focused SLAC-FEL drift-adaptation figure.""" + +from __future__ import annotations + +import argparse +from collections.abc import Callable +from pathlib import Path +from typing import cast + +import matplotlib + +matplotlib.use("Agg") + +import matplotlib.dates as mdates +import matplotlib.pyplot as plt +import pandas as pd +import torch + +from examples.slac_fel.model import FELNet +from examples.slac_fel.utils import ( + discover_window_files, + load_feature_config, + load_scalers, + load_window_file, +) + +TRIGGER_FILE = "data_740.pkl" +ROLLING_SAMPLES = 500 + + +def load_adapted_model( + checkpoint_path: Path, + input_size: int, + output_size: int, +) -> FELNet: + """Load one drift-adapted FEL checkpoint.""" + model = FELNet( + input_size=input_size, + output_size=output_size, + ) + + state = torch.load( + checkpoint_path, + map_location="cpu", + weights_only=False, + ) + + model.load_state_dict(state) + model.eval() + return model + + +def build_predictions( + data_dir: Path, + model_dir: Path, + checkpoint_path: Path, +) -> tuple[pd.DataFrame, pd.Timestamp]: + """Evaluate static and adapted models on the focused stream.""" + input_columns, output_columns = load_feature_config(str(model_dir)) + + input_scaler, output_scaler = load_scalers( + str(model_dir), + device="cpu", + ) + + # BoTorch exposes this as a method at runtime, but its current + # type information describes the attribute as a Tensor. + untransform = cast( + Callable[[torch.Tensor], torch.Tensor], + output_scaler.untransform, + ) + + loaded_static_model = torch.load( + model_dir / "final_lcls_fel_model.pt", + map_location="cpu", + weights_only=False, + ) + + if not isinstance( + loaded_static_model, + torch.nn.Module, + ): + raise TypeError("The pretrained FEL artifact is not a Torch module") + + static_model = loaded_static_model + static_model.eval() + + adapted_model = load_adapted_model( + checkpoint_path, + input_size=len(input_columns), + output_size=len(output_columns), + ) + + records = [] + trigger_time = None + + for path_string in discover_window_files(str(data_dir)): + data_path = Path(path_string) + + inputs, targets_scaled, timestamps = load_window_file( + str(data_path), + input_columns, + output_columns, + input_scaler, + output_scaler, + ) + + with torch.no_grad(): + measured = untransform(targets_scaled) + static_prediction = untransform(static_model(inputs)) + adapted_prediction = untransform(adapted_model(inputs)) + + use_adapted = data_path.name >= TRIGGER_FILE + + if data_path.name == TRIGGER_FILE: + trigger_time = pd.Timestamp(timestamps[0]) + + segmented_prediction = adapted_prediction if use_adapted else static_prediction + + frame = pd.DataFrame( + { + "measurement": (measured.squeeze(-1).cpu().numpy()), + "static_prediction": (static_prediction.squeeze(-1).cpu().numpy()), + "segmented_prediction": ( + segmented_prediction.squeeze(-1).cpu().numpy() + ), + "file": data_path.name, + }, + index=pd.DatetimeIndex(timestamps), + ) + + records.append(frame) + + if trigger_time is None: + raise ValueError(f"Trigger file {TRIGGER_FILE} was not found") + + result = pd.concat(records).sort_index() + + result["static_absolute_error"] = ( + result["static_prediction"] - result["measurement"] + ).abs() + + result["segmented_absolute_error"] = ( + result["segmented_prediction"] - result["measurement"] + ).abs() + + return result, trigger_time + + +def plot_focused_replay( + predictions: pd.DataFrame, + trigger_time: pd.Timestamp, + output_path: Path, +) -> None: + """Plot measured intensity, predictions, and absolute error.""" + rolling = ( + predictions[ + [ + "measurement", + "static_prediction", + "segmented_prediction", + "static_absolute_error", + "segmented_absolute_error", + ] + ] + .rolling( + ROLLING_SAMPLES, + min_periods=1, + ) + .mean() + ) + + static_mae = predictions["static_absolute_error"].mean() + + segmented_mae = predictions["segmented_absolute_error"].mean() + + improvement = static_mae / segmented_mae + + figure, axes = plt.subplots( + 2, + 1, + figsize=(14, 8), + sharex=True, + gridspec_kw={"height_ratios": [3, 1]}, + ) + + signal_axis, error_axis = axes + + signal_axis.scatter( + predictions.index, + predictions["measurement"], + color="#9ca3af", + s=2, + alpha=0.08, + rasterized=True, + label="Measured pulse energy (raw)", + ) + + signal_axis.plot( + rolling.index, + rolling["measurement"], + color="#111827", + linewidth=1.6, + label="Measured pulse energy (rolling mean)", + ) + + signal_axis.plot( + rolling.index, + rolling["static_prediction"], + color="#3b82f6", + linewidth=1.5, + label="Static pretrained model", + ) + + signal_axis.plot( + rolling.index, + rolling["segmented_prediction"], + color="#e11d48", + linewidth=1.8, + label="Paper-style segmented replay", + ) + + error_axis.plot( + rolling.index, + rolling["static_absolute_error"], + color="#3b82f6", + linewidth=1.4, + label="Static absolute error", + ) + + error_axis.plot( + rolling.index, + rolling["segmented_absolute_error"], + color="#e11d48", + linewidth=1.6, + label="Segmented absolute error", + ) + + for axis in axes: + axis.axvline( + trigger_time, + color="#f97316", + linestyle="--", + linewidth=1.6, + label=("Detected transition" if axis is signal_axis else None), + ) + axis.grid(alpha=0.25) + + signal_axis.annotate( + "Detected transition\ndata_740.pkl", + xy=(trigger_time, 0.98), + xycoords=( + "data", + "axes fraction", + ), + xytext=(8, -8), + textcoords="offset points", + color="#c2410c", + fontsize=9, + ha="left", + va="top", + ) + + signal_axis.set_title("APEIRON SLAC-FEL focused drift-adaptation tutorial") + signal_axis.set_ylabel("FEL pulse energy (mJ)") + signal_axis.legend( + loc="upper left", + ncol=2, + ) + + error_axis.set_ylabel("Absolute error (mJ)") + error_axis.set_xlabel("Time") + error_axis.legend(loc="upper left") + + locator = mdates.AutoDateLocator( + minticks=4, + maxticks=9, + ) + formatter = mdates.ConciseDateFormatter(locator) + + error_axis.xaxis.set_major_locator(locator) + error_axis.xaxis.set_major_formatter(formatter) + + figure.subplots_adjust( + left=0.07, + right=0.985, + top=0.94, + bottom=0.13, + hspace=0.06, + ) + + figure.text( + 0.5, + 0.065, + ( + f"Static MAE: {static_mae:.3f} mJ " + f"Segmented replay MAE: " + f"{segmented_mae:.3f} mJ " + f"Improvement: {improvement:.1f}x" + ), + fontsize=11, + ha="center", + ) + + figure.text( + 0.5, + 0.025, + ( + "Paper-style offline replay: the adapted checkpoint is " + "applied from the start of the trigger window." + ), + color="#4b5563", + fontsize=9, + ha="center", + ) + + output_path.parent.mkdir( + parents=True, + exist_ok=True, + ) + + figure.savefig( + output_path, + dpi=180, + ) + plt.close(figure) + + print("Samples:", len(predictions)) + print("Trigger time:", trigger_time) + print("Static MAE:", static_mae, "mJ") + print( + "Segmented replay MAE:", + segmented_mae, + "mJ", + ) + print("Improvement:", improvement, "x") + print("Figure:", output_path) + + +def parse_args() -> argparse.Namespace: + """Parse command-line arguments.""" + parser = argparse.ArgumentParser( + description=("Generate the focused SLAC-FEL tutorial figure.") + ) + + parser.add_argument( + "--data", + type=Path, + required=True, + help="Directory containing data_730.pkl through data_743.pkl.", + ) + + parser.add_argument( + "--checkpoint", + type=Path, + required=True, + help="Adapted drift_adaptation_1.pt checkpoint.", + ) + + parser.add_argument( + "--output", + type=Path, + required=True, + help="Output PNG path.", + ) + + parser.add_argument( + "--model-dir", + type=Path, + default=Path("examples/slac_fel/model"), + help="Directory containing the pretrained model and scalers.", + ) + + return parser.parse_args() + + +def main() -> None: + """Run the focused replay and plotting workflow.""" + args = parse_args() + + predictions, trigger_time = build_predictions( + data_dir=args.data, + model_dir=args.model_dir, + checkpoint_path=args.checkpoint, + ) + + plot_focused_replay( + predictions=predictions, + trigger_time=trigger_time, + output_path=args.output, + ) + + +if __name__ == "__main__": + main() diff --git a/examples/slac_fel/slac-fel-tutorial.toml b/examples/slac_fel/slac-fel-tutorial.toml new file mode 100644 index 00000000..e7e82dc1 --- /dev/null +++ b/examples/slac_fel/slac-fel-tutorial.toml @@ -0,0 +1,55 @@ +# Focused SLAC-FEL drift-adaptation tutorial. +# +# Expected dataset: +# data_730.pkl through data_743.pkl +# +# Provide its location at runtime: +# --set data.path=/path/to/tutorial/data +# +# The subset contains one major regime transition at data_740.pkl. +# Page-Hinkley detects the transition and initiates one short adaptation. + +seed = 42 +device = "cpu" +multi_gpu = false +verbosity = "INFO" + +[model] +name = "fel" +pretrained_path = "examples/slac_fel/model/final_lcls_fel_model.pt" +max_ckpts = 2 +ckpts_path = "output/slac-fel/tutorial/checkpoints" + +[data] +name = "slac-fel" +path = "data/slac-fel/tutorial" +batch_size = 5000 + +[train] +batch_size = 512 +num_workers = 0 +init_lr = 1e-5 +max_iter = 200 +grad_accumulation_steps = 1 + +[continual_learning] +update_mode = "ewc_online" +mix_historic_data = true +ewc_lambda = 1000.0 +ewc_ema_decay = 0.95 + +[drift_detection] +detector_name = "PageHinkleyDetector" +detection_interval = 2 +aggregation = "mean" +metric_index = 0 +reset_after_learning = true +max_stream_updates = 13 +ph_min_instances = 10 +ph_delta = 0.3 +ph_threshold = 2.0 +ph_alpha = 0.9999 + +[logging] +backend = "none" +metrics_output_path = "output/slac-fel/tutorial/metrics.csv" diff --git a/examples/slac_fel/test_tomls/dec2025.toml b/examples/slac_fel/test_tomls/dec2025.toml new file mode 100644 index 00000000..33e978bf --- /dev/null +++ b/examples/slac_fel/test_tomls/dec2025.toml @@ -0,0 +1,62 @@ +# December 2025 whole-month reproduction configuration. +# +# Expected dataset: +# data_699.pkl through data_848.pkl +# +# Provide the dataset location at runtime: +# --set data.path=/path/to/dec2025-data +# +# Run: +# uv run python -m src.main \ +# --config examples/slac_fel/test_tomls/dec2025.toml \ +# --set data.path=/path/to/dec2025-data + +seed = 42 +device = "cpu" +multi_gpu = false +verbosity = "DEBUG" + +[model] +name = "fel" +pretrained_path = "examples/slac_fel/model/final_lcls_fel_model.pt" +max_ckpts = 20 +ckpts_path = "output/slac-fel/dec2025" + +[data] +name = "slac-fel" +path = "output/slac-fel/dec2025_data" +batch_size = 5000 + +[train] +batch_size = 512 +num_workers = 0 +init_lr = 1e-5 +max_iter = 6000 +grad_accumulation_steps = 1 + +[continual_learning] +update_mode = "ewc_online" +mix_historic_data = true +ewc_lambda = 1000.0 +ewc_ema_decay = 0.95 + +[drift_detection] +detector_name = "EnsembleDetector" +ensemble_detectors = ["PageHinkleyDetector", "KSWINDetector"] +ensemble_voting = "any" +kswin_alpha = 0.05 +kswin_window_size = 20 +kswin_stat_size = 10 +ph_min_instances = 30 +ph_delta = 0.3 +ph_threshold = 2.0 +ph_alpha = 0.9999 +metric_index = 0 +detection_interval = 2 +aggregation = "mean" +reset_after_learning = false +max_stream_updates = 150 + +[logging] +backend = "none" +metrics_output_path = "output/slac-fel/dec2025.csv" diff --git a/examples/slac_fel/utils.py b/examples/slac_fel/utils.py new file mode 100644 index 00000000..19f68177 --- /dev/null +++ b/examples/slac_fel/utils.py @@ -0,0 +1,455 @@ +# examples/slac_fel/utils.py +"""Data-loading utilities for the SLAC FEL continuous-learning example. + +The data pipeline assumes that all heavy cleaning (archive pull, filtering, +exclusion windows, invalid-PV removal, column selection) has already been done +and the results saved as individual pickle files (``data_1.pkl``, +``data_2.pkl``, …). All pickle files are loaded, concatenated into a single +dataset in chronological order, and then split into fixed-size windows +controlled by ``cfg.data.batch_size``. + +If only a single ``data.pkl`` is present (legacy layout), it is loaded in its +entirety and split into fixed-size windows via ``window_size``. + +Expected directory layout (pointed to by ``cfg.data.path``):: + + / + data_1.pkl # pandas DataFrame, datetime-indexed, sorted + data_2.pkl # ... + ... +""" + +from __future__ import annotations + +import glob +import logging +import os +import re +import warnings +from typing import List, Optional, Tuple + +import pandas as pd +import torch +import yaml +from torch import Tensor +from torch.utils.data import DataLoader, Dataset, Sampler + +_log = logging.getLogger(__name__) + + +# --------------------------------------------------------------------------- +# Dataset +# --------------------------------------------------------------------------- +class FELDataset(Dataset): + """Simple dataset wrapping pre-scaled input/output tensors.""" + + def __init__(self, X: Tensor, y: Tensor) -> None: + assert X.shape[0] == y.shape[0], "X and y must have the same number of samples" + self.X = X.float() + self.y = y.float() + + def __len__(self) -> int: + return self.X.shape[0] + + def __getitem__(self, idx: int) -> Tuple[Tensor, Tensor]: + return self.X[idx], self.y[idx] + + +# --------------------------------------------------------------------------- +# DataLoader helper +# --------------------------------------------------------------------------- +def _seed_worker(_worker_id: int) -> None: + """Seed a DataLoader worker's NumPy/random RNGs from its Torch seed. + + Torch already gives each worker a distinct, run-reproducible base seed + (derived from the loader's ``generator``); this propagates it so any + NumPy/``random`` usage inside ``__getitem__`` is reproducible too. + """ + import random as _random + + import numpy as _np + + worker_seed = torch.initial_seed() % 2**32 + _np.random.seed(worker_seed) + _random.seed(worker_seed) + + +def make_loader( + ds: Dataset, + batch_size: int, + shuffle: bool, + num_workers: int = 4, + pin_memory: bool = True, + persistent_workers: bool = True, + prefetch_factor: int = 2, + sampler: Optional[Sampler] = None, + generator: Optional[torch.Generator] = None, +) -> DataLoader: + """Build a ``DataLoader`` from a ``Dataset``. + + Args: + ds: The base dataset. + batch_size: Batch size. + shuffle: Whether to shuffle. Ignored when *sampler* is given. + num_workers: Number of data-loading workers. + pin_memory: Pin CUDA memory for faster transfers. + persistent_workers: Keep worker processes alive between iterations. + prefetch_factor: Samples to prefetch per worker. + sampler: Optional sampler; mutually exclusive with ``shuffle``. When + provided, ``shuffle`` is not passed to the ``DataLoader``. + generator: Optional RNG that seeds shuffling and worker base seeds so + batch order is reproducible run-to-run. + + Returns: + DataLoader built from *ds* with the given settings. + """ + kwargs: dict = dict(batch_size=batch_size, drop_last=False) + if sampler is not None: + kwargs["sampler"] = sampler + else: + kwargs["shuffle"] = shuffle + if generator is not None: + kwargs["generator"] = generator + if num_workers > 0: + kwargs.update( + dict( + num_workers=num_workers, + pin_memory=pin_memory, + persistent_workers=persistent_workers, + prefetch_factor=prefetch_factor, + worker_init_fn=_seed_worker, + ) + ) + return DataLoader(ds, **kwargs) # type: ignore[arg-type] + + +# --------------------------------------------------------------------------- +# Feature-config helpers +# --------------------------------------------------------------------------- +def load_feature_config(data_path: str) -> Tuple[List[str], List[str]]: + """Read ``feature_config.yml`` and return ``(input_cols, output_cols)``. + + The YAML file is expected to have top-level keys ``input_variables`` and + ``output_variables``, each mapping variable names to metadata dicts. + """ + cfg_path = os.path.join(data_path, "feature_config.yml") + with open(cfg_path, "r") as fh: + yml = yaml.safe_load(fh) + input_cols = list(yml["input_variables"].keys()) + output_cols = list(yml["output_variables"].keys()) + return input_cols, output_cols + + +# --------------------------------------------------------------------------- +# Scaler helpers +# --------------------------------------------------------------------------- +def load_scalers( + data_path: str, device: str = "cpu" +) -> Tuple[torch.nn.Module, torch.nn.Module]: + """Load the saved BoTorch ``AffineInputTransform`` scalers. + + Tries the new naming convention (``input_scaler.pt``) first, then + falls back to the legacy names (``lcls_fel_input_scaler.pt``). + + Args: + data_path: Directory containing the scaler ``.pt`` files. + device: Device to map the scalers to. + + Returns: + Tuple of ``(input_scaler, output_scaler)``. + """ + # New names (train_fel_model.py v2) → legacy names (fallback) + input_candidates = ["input_scaler.pt", "lcls_fel_input_scaler.pt"] + output_candidates = ["output_scaler.pt", "lcls_fel_output_scaler.pt"] + + def _load_first(candidates: list[str]) -> torch.nn.Module: + for name in candidates: + path = os.path.join(data_path, name) + if os.path.exists(path): + return torch.load(path, map_location=device, weights_only=False) + raise FileNotFoundError(f"No scaler found in {data_path}; tried {candidates}") + + input_scaler = _load_first(input_candidates) + output_scaler = _load_first(output_candidates) + return input_scaler, output_scaler + + +# --------------------------------------------------------------------------- +# Data loading +# --------------------------------------------------------------------------- +def load_fel_data( + data_path: str, config_path: str, device: str = "cpu" +) -> Tuple[Tensor, Tensor, pd.Index]: + """Load a single ``data.pkl``, apply scalers, and return scaled tensors. + + Note that with the current workflow, prefer :func:`discover_window_files` + + :func:`load_window_file` for per-file lazy loading. + + Args: + data_path: Directory containing ``data.pkl``, scalers, and + ``feature_config.yml``. + config_path: Directory containing ``feature_config.yml`` and scaler files. + device: Device string (used for scaler loading only; tensors stay on + CPU here). + + Returns: + Tuple of ``(X_scaled, y_scaled, timestamps)``. + """ + df: pd.DataFrame = pd.read_pickle(os.path.join(data_path, "data.pkl")) + + # Ensure sorted by time + df = df.sort_index() + + input_cols, output_cols = load_feature_config(config_path) + input_scaler, output_scaler = load_scalers(config_path, device=device) + + # Drop rows with NaN in any input or output column + all_cols = input_cols + output_cols + n_before = len(df) + df = df.dropna(subset=all_cols) + n_dropped = n_before - len(df) + if n_dropped > 0: + pct = 100.0 * n_dropped / n_before + msg = ( + f"[load_fel_data] Dropped {n_dropped}/{n_before} rows " + f"({pct:.1f}%) containing NaN values" + ) + warnings.warn(msg, stacklevel=2) + _log.warning(msg) + + X_raw = torch.as_tensor(df[input_cols].values, dtype=torch.float32) + y_raw = torch.as_tensor(df[output_cols].values, dtype=torch.float32) + + # TODO: maybe import botorch scalers differently to avoid the type: ignore here + X_scaled: Tensor = input_scaler.transform(X_raw) # type: ignore[operator] + y_scaled: Tensor = output_scaler.transform(y_raw) # type: ignore[operator] + + return X_scaled, y_scaled, df.index + + +# --------------------------------------------------------------------------- +# Per-file window discovery & lazy loading +# --------------------------------------------------------------------------- + + +def _natural_sort_key(path: str) -> Tuple[str, int]: + """Sort key that orders ``data_1.pkl`` < ``data_2.pkl`` < ``data_10.pkl``. + + Falls back to lexicographic order if no numeric suffix is found. + """ + basename = os.path.basename(path) + m = re.search(r"(\d+)", basename) + if m: + return (basename[: m.start()], int(m.group(1))) + return (basename, 0) + + +def discover_window_files(data_path: str) -> List[str]: + """Return sorted paths to ``data_*.pkl`` files in *data_path*. + + Files are sorted by the numeric suffix so that ``data_1.pkl`` comes + before ``data_2.pkl`` and ``data_10.pkl``. + + Args: + data_path: Directory to search. + + Returns: + List of absolute paths, one per window file, sorted by numeric suffix. + """ + pattern = os.path.join(data_path, "data_*.pkl") + paths = glob.glob(pattern) + paths.sort(key=_natural_sort_key) + return paths + + +def load_window_file( + pkl_path: str, + input_cols: List[str], + output_cols: List[str], + input_scaler: torch.nn.Module, + output_scaler: torch.nn.Module, +) -> Tuple[Tensor, Tensor, pd.Index]: + """Load a single window pickle, scale, and return ``(X, y, index)`` tensors. + + Args: + pkl_path: Path to a single ``data_.pkl`` file. + input_cols: Column names for input features (from ``feature_config.yml``). + output_cols: Column names for output targets. + input_scaler: Pre-fitted scaler for inputs. + output_scaler: Pre-fitted scaler for outputs. + + Returns: + Tuple ``(X_scaled, y_scaled, index)`` where ``X_scaled`` is + ``[N, n_inputs]`` float32, ``y_scaled`` is ``[N, n_outputs]`` float32, + and ``index`` is the DataFrame index after NaN filtering. + """ + df: pd.DataFrame = pd.read_pickle(pkl_path) + df = df.sort_index() + + # Drop rows with NaN in any input or output column + all_cols = input_cols + output_cols + n_before = len(df) + df = df.dropna(subset=all_cols) + n_dropped = n_before - len(df) + if n_dropped > 0: + pct = 100.0 * n_dropped / n_before + basename = os.path.basename(pkl_path) + msg = ( + f"[load_window_file] {basename}: Dropped {n_dropped}/{n_before} rows " + f"({pct:.1f}%) containing NaN values" + ) + warnings.warn(msg, stacklevel=2) + _log.warning(msg) + + X_raw = torch.as_tensor(df[input_cols].values, dtype=torch.float32) + y_raw = torch.as_tensor(df[output_cols].values, dtype=torch.float32) + + X_scaled: Tensor = input_scaler.transform(X_raw) # type: ignore[operator] + y_scaled: Tensor = output_scaler.transform(y_raw) # type: ignore[operator] + + return X_scaled, y_scaled, df.index + + +def load_all_window_files( + data_path: str, + input_cols: List[str], + output_cols: List[str], + input_scaler: torch.nn.Module, + output_scaler: torch.nn.Module, +) -> Tuple[Tensor, Tensor, pd.Index]: + """Load all ``data_*.pkl`` files, concatenate, and return scaled tensors. + + Each pickle is loaded and scaled individually via :func:`load_window_file`, + then the results are concatenated into a single pair of tensors in + chronological order (files are sorted by numeric suffix). + + Args: + data_path: Directory containing ``data_*.pkl`` files. + input_cols: Column names for input features. + output_cols: Column names for output targets. + input_scaler: Pre-fitted scaler for inputs. + output_scaler: Pre-fitted scaler for outputs. + + Returns: + Tuple ``(X_all, y_all, timestamps)`` with all windows concatenated + along dim 0. ``timestamps`` is the combined DataFrame index + preserving the chronological order of every row. + + Raises: + FileNotFoundError: If no ``data_*.pkl`` files are found in *data_path*. + """ + window_files = discover_window_files(data_path) + if not window_files: + raise FileNotFoundError(f"No data_*.pkl files found in {data_path}") + + X_parts: List[Tensor] = [] + y_parts: List[Tensor] = [] + index_parts: List[pd.Index] = [] + total_samples = 0 + + for pkl_path in window_files: + X_w, y_w, idx = load_window_file( + pkl_path, input_cols, output_cols, input_scaler, output_scaler + ) + X_parts.append(X_w) + y_parts.append(y_w) + index_parts.append(idx) + total_samples += X_w.shape[0] + _log.info( + "[load_all_window_files] Loaded %s: %d samples", + os.path.basename(pkl_path), + X_w.shape[0], + ) + + X_all = torch.cat(X_parts, dim=0) + y_all = torch.cat(y_parts, dim=0) + timestamps = index_parts[0].append(index_parts[1:]) + + _log.info( + "[load_all_window_files] Combined %d files → %d total samples", + len(window_files), + total_samples, + ) + + return X_all, y_all, timestamps + + +# --------------------------------------------------------------------------- +# Windowing +# --------------------------------------------------------------------------- + +# Default number of samples per time window. Can be overridden by the caller. +DEFAULT_WINDOW_SIZE: int = 5000 + + +def split_into_windows( + X: Tensor, + y: Tensor, + window_size: int = DEFAULT_WINDOW_SIZE, + min_window_size: int = 2, +) -> List[Tuple[Tensor, Tensor]]: + """Split chronologically-ordered tensors into non-overlapping windows. + + If the final chunk has fewer than *min_window_size* samples it is merged + into the preceding window so that every window is large enough for a + meaningful train/val split. + + Args: + X: Input features ``[N, D]``. + y: Targets ``[N, T]``. + window_size: Number of samples per window. + min_window_size: Minimum samples in a window. A trailing chunk + smaller than this is merged into the previous window. + + Returns: + List of ``(X_chunk, y_chunk)`` tuples. + """ + n = X.shape[0] + windows: List[Tuple[Tensor, Tensor]] = [] + for start in range(0, n, window_size): + end = min(start + window_size, n) + windows.append((X[start:end], y[start:end])) + + # Merge a too-small trailing window into the previous one + if len(windows) > 1 and windows[-1][0].shape[0] < min_window_size: + prev_X, prev_y = windows[-2] + tail_X, tail_y = windows[-1] + windows[-2] = ( + torch.cat([prev_X, tail_X], dim=0), + torch.cat([prev_y, tail_y], dim=0), + ) + windows.pop() + + return windows + + +def split_timestamps( + timestamps: pd.Index, + window_size: int = DEFAULT_WINDOW_SIZE, + min_window_size: int = 2, +) -> List[pd.Index]: + """Split a timestamp index to match :func:`split_into_windows`. + + Applies the same chunking and merging logic so that + ``split_timestamps(ts, ws)[i]`` aligns row-for-row with + ``split_into_windows(X, y, ws)[i]``. + + Args: + timestamps: Row-aligned index (same length as the tensors). + window_size: Number of samples per window. + min_window_size: Merge trailing chunk if smaller than this. + + Returns: + List of ``pd.Index`` slices, one per window. + """ + n = len(timestamps) + chunks: List[pd.Index] = [] + for start in range(0, n, window_size): + end = min(start + window_size, n) + chunks.append(timestamps[start:end]) + + if len(chunks) > 1 and len(chunks[-1]) < min_window_size: + chunks[-2] = chunks[-2].append(chunks[-1]) + chunks.pop() + + return chunks diff --git a/examples/utils.py b/examples/utils.py index 0cde7b74..213af549 100644 --- a/examples/utils.py +++ b/examples/utils.py @@ -15,6 +15,10 @@ def get_example(cfg: Config) -> BaseModelHarness: from examples.imagenet.model import IMAGENET_VISION return IMAGENET_VISION(cfg=cfg) + elif cfg.data.name == "slac-fel": + from examples.slac_fel.model import SLAC_FEL + + return SLAC_FEL(cfg=cfg) else: raise NotImplementedError( f"Example for dataset {cfg.data.name} is not implemented." diff --git a/pyproject.toml b/pyproject.toml index e78ea032..0af713a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,9 @@ dependencies = [ "transformers (>=5.0.0)", "river (>=0.21.0,<0.24.0)", "evidently (>=0.4.0,<0.8.0)", - "matplotlib (>=3.10.7,<4.0.0)" + "matplotlib (>=3.10.7,<4.0.0)", + "botorch>=0.18.1", + "pyyaml>=6.0.3", ] [dependency-groups] @@ -51,7 +53,8 @@ dev = [ "mypy (>=1.18.2,<2.0.0)", "ruff (>=0.14.4,<0.15.0)", "pytest (>=9.0.1,<10.0.0)", - "pytest-cov (>=7.0.0,<8.0.0)" + "pytest-cov (>=7.0.0,<8.0.0)", + "types-pyyaml>=6.0.12.20261103", ] diff --git a/src/apeiron/config/configuration.py b/src/apeiron/config/configuration.py index ff4753ec..3350365e 100644 --- a/src/apeiron/config/configuration.py +++ b/src/apeiron/config/configuration.py @@ -30,6 +30,34 @@ from apeiron.logger.logger import MetricsBackend +def seed_everything(seed: int) -> None: + """Seed Python, NumPy, and Torch for repeatable runs. + + Deterministic Torch algorithms are requested in warning mode so + operations without deterministic implementations warn rather + than terminate the experiment. + """ + import random + + import numpy as np + + os.environ["PYTHONHASHSEED"] = str(seed) + random.seed(seed) + np.random.seed(seed) + torch.manual_seed(seed) + torch.cuda.manual_seed_all(seed) + + torch.backends.cudnn.deterministic = True + torch.backends.cudnn.benchmark = False + try: + torch.use_deterministic_algorithms( + True, + warn_only=True, + ) + except Exception: + pass + + def get_available_device(multi_gpu: bool = False) -> torch.device: """ Return a ``torch.device`` with sensible fallbacks. diff --git a/src/main.py b/src/main.py index e8cc2641..1ebfa9d7 100644 --- a/src/main.py +++ b/src/main.py @@ -1,7 +1,11 @@ import sys from apeiron.logger import get_logger, configure_backend -from apeiron.config.configuration import build_config, Config +from apeiron.config.configuration import ( + Config, + build_config, + seed_everything, +) from examples.utils import get_example @@ -11,6 +15,9 @@ def main(argv: list[str] | None = None) -> int: cfg: Config = build_config(argv) + # Seed before model construction, data shuffling, or replay. + seed_everything(cfg.seed) + # Must precede get_example(): get_logger() ignores its arguments once an # instance exists, so a harness that logs from __init__ would pin the config. backend = configure_backend(cfg) diff --git a/tests/test_config.py b/tests/test_config.py index 430e2d77..f0bb9504 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -3,10 +3,12 @@ from __future__ import annotations import os +import random import textwrap from pathlib import Path from unittest.mock import patch +import numpy as np import pytest import torch @@ -23,6 +25,7 @@ kv_to_nested, load_toml, parse_args, + seed_everything, _select_best_gpu, ) @@ -276,6 +279,59 @@ def test_drift_detection_defaults(self): assert dd.detection_interval == 10 +# --------------------------------------------------------------------------- +# seed_everything +# --------------------------------------------------------------------------- +class TestSeedEverything: + def test_repeats_python_numpy_and_torch_sequences(self): + python_state = random.getstate() + numpy_state = np.random.get_state() + torch_state = torch.random.get_rng_state() + deterministic_state = torch.are_deterministic_algorithms_enabled() + cudnn_deterministic = torch.backends.cudnn.deterministic + cudnn_benchmark = torch.backends.cudnn.benchmark + previous_hash_seed = os.environ.get("PYTHONHASHSEED") + + try: + with patch("torch.cuda.manual_seed_all") as manual_seed_all: + seed_everything(123) + first = ( + random.random(), + np.random.random(), + torch.rand(4), + ) + + seed_everything(123) + second = ( + random.random(), + np.random.random(), + torch.rand(4), + ) + + assert manual_seed_all.call_count >= 2 + manual_seed_all.assert_called_with(123) + + assert first[0] == second[0] + assert first[1] == second[1] + assert torch.equal(first[2], second[2]) + assert os.environ["PYTHONHASHSEED"] == "123" + assert torch.are_deterministic_algorithms_enabled() + assert torch.backends.cudnn.deterministic + assert not torch.backends.cudnn.benchmark + finally: + random.setstate(python_state) + np.random.set_state(numpy_state) + torch.random.set_rng_state(torch_state) + torch.use_deterministic_algorithms(deterministic_state) + torch.backends.cudnn.deterministic = cudnn_deterministic + torch.backends.cudnn.benchmark = cudnn_benchmark + + if previous_hash_seed is None: + os.environ.pop("PYTHONHASHSEED", None) + else: + os.environ["PYTHONHASHSEED"] = previous_hash_seed + + # --------------------------------------------------------------------------- # get_available_device / _select_best_gpu # --------------------------------------------------------------------------- diff --git a/tests/test_slac_fel_example.py b/tests/test_slac_fel_example.py new file mode 100644 index 00000000..949b04df --- /dev/null +++ b/tests/test_slac_fel_example.py @@ -0,0 +1,197 @@ +"""Tests for the SLAC-FEL scientific example.""" + +import sys +from pathlib import Path + +import pandas as pd +import torch + +from apeiron.config.configuration import build_config + +PROJECT_ROOT = Path(__file__).resolve().parents[1] + +if str(PROJECT_ROOT) not in sys.path: + sys.path.append(str(PROJECT_ROOT)) + + +MODEL_DIR = Path("examples/slac_fel/model") +TUTORIAL_CONFIG = Path("examples/slac_fel/slac-fel-tutorial.toml") + + +def test_tutorial_configuration(): + cfg = build_config( + [ + "--config", + str(TUTORIAL_CONFIG), + ] + ) + + assert cfg.seed == 42 + assert cfg.device == "cpu" + assert cfg.data.name == "slac-fel" + assert cfg.data.batch_size == 5000 + assert cfg.train.max_iter == 200 + assert cfg.drift_detection.detector_name == ("PageHinkleyDetector") + assert cfg.drift_detection.max_stream_updates == 13 + assert cfg.drift_detection.ph_min_instances == 10 + assert cfg.drift_detection.ph_threshold == 2.0 + assert cfg.drift_detection.reset_after_learning is True + + +def test_feature_configuration_and_scalers(): + from examples.slac_fel.utils import ( + load_feature_config, + load_scalers, + ) + + input_columns, output_columns = load_feature_config(str(MODEL_DIR)) + + input_scaler, output_scaler = load_scalers( + str(MODEL_DIR), + device="cpu", + ) + + assert len(input_columns) == 341 + assert output_columns == ["GDET:FEE1:241:ENRC"] + assert input_scaler.state_dict()["_coefficient"].shape == (341,) + assert output_scaler.state_dict()["_coefficient"].shape == (1,) + + +def test_pretrained_model_dimensions(): + model = torch.load( + MODEL_DIR / "final_lcls_fel_model.pt", + map_location="cpu", + weights_only=False, + ) + model.eval() + + with torch.no_grad(): + output = model(torch.zeros(2, 341)) + + assert output.shape == (2, 1) + + +def test_window_files_are_sorted_by_numeric_suffix( + tmp_path: Path, +): + from examples.slac_fel.utils import discover_window_files + + for name in [ + "data_10.pkl", + "data_2.pkl", + "data_1.pkl", + "unrelated.pkl", + ]: + (tmp_path / name).touch() + + discovered = discover_window_files(str(tmp_path)) + + assert [Path(item).name for item in discovered] == [ + "data_1.pkl", + "data_2.pkl", + "data_10.pkl", + ] + + +def test_small_trailing_window_is_merged(): + from examples.slac_fel.utils import split_into_windows + + inputs = torch.arange(18).reshape(9, 2) + targets = torch.arange(9).reshape(9, 1) + + windows = split_into_windows( + inputs, + targets, + window_size=4, + min_window_size=2, + ) + + assert [len(window_inputs) for window_inputs, _ in windows] == [ + 4, + 5, + ] + + reconstructed_inputs = torch.cat([window_inputs for window_inputs, _ in windows]) + reconstructed_targets = torch.cat([window_targets for _, window_targets in windows]) + + assert torch.equal(reconstructed_inputs, inputs) + assert torch.equal(reconstructed_targets, targets) + + +def test_focused_replay_plot(tmp_path: Path): + from examples.slac_fel.plot_tutorial import ( + plot_focused_replay, + ) + + timestamps = pd.date_range( + "2025-12-04T00:00:00-08:00", + periods=12, + freq="min", + ) + + frame = pd.DataFrame( + { + "measurement": [ + 0.4, + 0.5, + 0.6, + 0.7, + 0.8, + 0.9, + 0.8, + 0.7, + 0.6, + 0.5, + 0.4, + 0.3, + ], + "static_prediction": [ + 0.5, + 0.5, + 0.5, + 0.5, + 0.5, + 0.5, + 1.5, + 1.5, + 1.5, + 1.5, + 1.5, + 1.5, + ], + "segmented_prediction": [ + 0.5, + 0.5, + 0.5, + 0.5, + 0.5, + 0.5, + 0.8, + 0.7, + 0.6, + 0.5, + 0.4, + 0.3, + ], + }, + index=timestamps, + ) + + frame["static_absolute_error"] = ( + frame["static_prediction"] - frame["measurement"] + ).abs() + + frame["segmented_absolute_error"] = ( + frame["segmented_prediction"] - frame["measurement"] + ).abs() + + output = tmp_path / "focused-replay.png" + + plot_focused_replay( + predictions=frame, + trigger_time=timestamps[6], + output_path=output, + ) + + assert output.is_file() + assert output.stat().st_size > 1_000 diff --git a/uv.lock b/uv.lock index c67841fd..995a02f2 100644 --- a/uv.lock +++ b/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 3 +revision = 5 requires-python = "==3.13.*" [[package]] @@ -113,6 +113,7 @@ name = "apeiron" version = "0.1.0" source = { editable = "." } dependencies = [ + { name = "botorch" }, { name = "evidently" }, { name = "matplotlib" }, { name = "mlflow" }, @@ -121,6 +122,7 @@ dependencies = [ { name = "pandas" }, { name = "pandas-stubs" }, { name = "psutil" }, + { name = "pyyaml" }, { name = "river" }, { name = "torch" }, { name = "torchvision" }, @@ -136,10 +138,12 @@ dev = [ { name = "pytest" }, { name = "pytest-cov" }, { name = "ruff" }, + { name = "types-pyyaml" }, ] [package.metadata] requires-dist = [ + { name = "botorch", specifier = ">=0.18.1" }, { name = "evidently", specifier = ">=0.4.0,<0.8.0" }, { name = "matplotlib", specifier = ">=3.10.7,<4.0.0" }, { name = "mlflow", specifier = ">=2.10.0" }, @@ -148,6 +152,7 @@ requires-dist = [ { name = "pandas", specifier = ">=2.3.3,<3.0.0" }, { name = "pandas-stubs", specifier = ">=2.3.0" }, { name = "psutil", specifier = ">=5.9.0" }, + { name = "pyyaml", specifier = ">=6.0.3" }, { name = "river", specifier = ">=0.21.0,<0.24.0" }, { name = "torch", specifier = ">=2.13.0" }, { name = "torchvision", specifier = ">=0.28.0,<0.29.0" }, @@ -163,6 +168,7 @@ dev = [ { name = "pytest", specifier = ">=9.0.1,<10.0.0" }, { name = "pytest-cov", specifier = ">=7.0.0,<8.0.0" }, { name = "ruff", specifier = ">=0.14.4,<0.15.0" }, + { name = "types-pyyaml", specifier = ">=6.0.12.20261103" }, ] [[package]] @@ -192,6 +198,26 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/10/cb/f2ad4230dc2eb1a74edf38f1a38b9b52277f75bef262d8908e60d957e13c/blinker-1.9.0-py3-none-any.whl", hash = "sha256:ba0efaa9080b619ff2f3459d1d500c57bddea4a6b424b60a91141db6fd2f08bc", size = 8458, upload-time = "2024-11-08T17:25:46.184Z" }, ] +[[package]] +name = "botorch" +version = "0.18.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "gpytorch" }, + { name = "linear-operator" }, + { name = "multipledispatch" }, + { name = "ninja" }, + { name = "pyre-extensions" }, + { name = "scipy" }, + { name = "threadpoolctl" }, + { name = "torch" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/af/65/ac1539542d183f5d69ded6d134c60cd77ad5d9657ff1c35e54bf140984b3/botorch-0.18.1.tar.gz", hash = "sha256:f3e444efae2622b3ad88a5efe1859583ba2cd0913761f76677a189b2fd1aee99", size = 5090211, upload-time = "2026-06-08T22:45:15.659Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c1/50/aaffc306e9f609596a50a3220832058ccee6023436ba6eceb750c3ebc45a/botorch-0.18.1-py3-none-any.whl", hash = "sha256:fa1cd4483fbc21087dcc40088b6031661e46ce5fe9d0b47a56ebcd578c260f33", size = 5960420, upload-time = "2026-06-08T22:45:12.091Z" }, +] + [[package]] name = "cachetools" version = "7.2.0" @@ -776,6 +802,21 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/11/59/6474c44460037b8474d85c1a82311ec7244f3aabd53197be5b06a4db778e/googleapis_common_protos-1.75.4-py3-none-any.whl", hash = "sha256:e8eb9cffa9a9f3423090cc7a086012004196abab388a0561690e81887fd79cc1", size = 307743, upload-time = "2026-09-24T23:19:57.136Z" }, ] +[[package]] +name = "gpytorch" +version = "1.15.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "linear-operator" }, + { name = "mpmath" }, + { name = "scikit-learn" }, + { name = "scipy" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/23/00/cac3e309b2f66518d937ce4d9fa821f167d9070d004fcb070b1780cd1d94/gpytorch-1.15.2.tar.gz", hash = "sha256:380625e93f851b85f772b25c5fb0a6c6d2e3eb2ef667f1e566ab4f95b8775361", size = 2781831, upload-time = "2026-02-28T01:12:55.172Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b6/70/c419a361b09ccb618b5165daa919003ccdd9c148356f7ff71a710db6bcf0/gpytorch-1.15.2-py3-none-any.whl", hash = "sha256:2112fdc7c0c0bf56a7f2444663cfc80fdfc3e19724399d6303a83d8efdd71e9e", size = 291209, upload-time = "2026-02-28T01:12:52.587Z" }, +] + [[package]] name = "graphene" version = "3.4.3" @@ -1055,6 +1096,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/43/80/b1a6fbdd7da825cdd55c71aa81eb6cfa82c513c360774152eacb50b4a771/librt-0.16.0-cp313-cp313-win_arm64.whl", hash = "sha256:83d4041a3d9b2fd053a8a4e1f22878b3e5833e2712956382d5c048d791454e91", size = 116557, upload-time = "2026-09-29T00:53:30.012Z" }, ] +[[package]] +name = "linear-operator" +version = "0.6.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "scipy" }, + { name = "torch" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/02/1a/0d6d0269cf7327e31a2fe80b274d5bf5001dc4462acbef26240da6ac5dfe/linear_operator-0.6.1.tar.gz", hash = "sha256:3fba49a8080d16f822a5d870f462279cd6afbcf4ed670f4511b38fad96f61831", size = 181898, upload-time = "2026-02-27T23:43:18.716Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e6/34/ee74708a93704baca5c1ef439817c4cb649f73382c518380ccc5ab335603/linear_operator-0.6.1-py3-none-any.whl", hash = "sha256:a5981c1fcda08df3a210dffb6e8019b4751f4afaf3ffc822c24eaaf56b11eed9", size = 174770, upload-time = "2026-02-27T23:43:17.074Z" }, +] + [[package]] name = "litestar" version = "2.24.0" @@ -1327,6 +1381,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/20/f1/11873ce60ad824ac44f796de9879879dcd62672a172cbafe6e26eb2ea848/multipart-2.0.1-py3-none-any.whl", hash = "sha256:ac54d6bd0353ee30d2703af75adacd8b2052d4adb634e9e74dc7c5b06e0bcd86", size = 16448, upload-time = "2026-09-25T14:07:01.247Z" }, ] +[[package]] +name = "multipledispatch" +version = "1.0.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/fe/3e/a62c3b824c7dec33c4a1578bcc842e6c30300051033a4e5975ed86cc2536/multipledispatch-1.0.0.tar.gz", hash = "sha256:5c839915465c68206c3e9c473357908216c28383b425361e5d144594bf85a7e0", size = 12385, upload-time = "2023-06-27T16:45:11.074Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/51/c0/00c9809d8b9346eb238a6bbd5f83e846a4ce4503da94a4c08cb7284c325b/multipledispatch-1.0.0-py3-none-any.whl", hash = "sha256:0c53cd8b077546da4e48869f49b13164bebafd0c2a5afceb6bb6a316e7fb46e4", size = 12818, upload-time = "2023-06-27T16:45:09.418Z" }, +] + [[package]] name = "mypy" version = "1.20.2" @@ -1376,6 +1439,32 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/7e/cd/fe58041e9011f307c490e3e17dd48cc516448f7c698a3f2d9d9d65d7e6a8/networkx-3.7-py3-none-any.whl", hash = "sha256:e3fd2c13a7814cee3746340d8d7f8598a67f16a58bf47fb7f8793fab6efca1b0", size = 2142205, upload-time = "2026-09-21T16:45:14.609Z" }, ] +[[package]] +name = "ninja" +version = "1.13.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ac/92/410b7917d16ab54c04b05cc32b9284803671d91cf79d33be6009c28d4ea8/ninja-1.13.2.tar.gz", hash = "sha256:525bfa3fc88aa30a4467df270fd5be6f9fcae8061d54d4df74ea1dc5abd5a975", size = 243739, upload-time = "2026-08-30T15:49:51.897Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b5/b8/90a9518f2264637084d6199bc20c2f3fb97fefc4c474d277720150c3bd6d/ninja-1.13.2-py3-none-macosx_10_9_universal2.whl", hash = "sha256:fd82e26c0706ad4ab88e5fdd26f3fab0a987a90f810160f6c322e752c6af298b", size = 306611, upload-time = "2026-08-30T15:49:28.267Z" }, + { url = "https://files.pythonhosted.org/packages/35/54/7368ce188625e39acc03ee362bb86cc9bfa6ad15e25c50889ae36e2889b3/ninja-1.13.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:d775a5e43e9088f507a6250d57fcf5678eb31268c545feb5064ffeee33735622", size = 177180, upload-time = "2026-08-30T15:49:29.59Z" }, + { url = "https://files.pythonhosted.org/packages/80/1a/0b5601ece2a5de97253e7c7c442b70315333955593c2b55616fd17f1706f/ninja-1.13.2-py3-none-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:81d95081c0ad7c95f67bf682220361ed2a32659d7861b4766b03433c58f22516", size = 199485, upload-time = "2026-08-30T15:49:30.72Z" }, + { url = "https://files.pythonhosted.org/packages/48/23/fcbe234a66966e35928c47b86336f92a7612db4781665f4e5f5fddef9630/ninja-1.13.2-py3-none-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:227cbc3ae3e5e429692388103cae8c09451df086cd2d342dae0795af0d162547", size = 197676, upload-time = "2026-08-30T15:49:32.026Z" }, + { url = "https://files.pythonhosted.org/packages/24/eb/a6ca97ef0ff7bb8bdcb395ec65a716e65d7c1f40896c3afe0090bb3e1535/ninja-1.13.2-py3-none-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:1684c60d031c54c1d049541b64243c0c567dca5463dbd77682a8901780af293d", size = 187980, upload-time = "2026-08-30T15:49:33.372Z" }, + { url = "https://files.pythonhosted.org/packages/6e/53/ebfed7b689c338dd8ebeec9c0730c8d56821292f14e2536e5f3ef1a05744/ninja-1.13.2-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:65a24341b5ac09fcadcc37082660be40a94174e51a937fabf6e2cae26225fa2c", size = 183365, upload-time = "2026-08-30T15:49:34.53Z" }, + { url = "https://files.pythonhosted.org/packages/c7/d6/dcf06d7ab44ade992ae5aa1228feff317684b463a1bd47e8642b30ac922e/ninja-1.13.2-py3-none-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:aa3d2ae5706a2c4d1e93edc951d1c6cbb45107413c404f8fde1741239efbc9a0", size = 155089, upload-time = "2026-08-30T15:49:35.72Z" }, + { url = "https://files.pythonhosted.org/packages/e1/6b/6513c09c33382b17c05b4349b8e81437b18680d0d7ec6fb8f7edc29adda1/ninja-1.13.2-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:919572cbc3f233261ecd41fe1f3efc9d44aa02464a4588867e06a8b4f6f416ea", size = 152149, upload-time = "2026-08-30T15:49:36.971Z" }, + { url = "https://files.pythonhosted.org/packages/4d/70/d59fa4261f5ce586f43d8716de1da33d813afc116f0bf9173bf4cdbfdb2a/ninja-1.13.2-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:0e083700470c02ca154a855ae6d692d03564f5064cae52e113896f9ccc078418", size = 525392, upload-time = "2026-08-30T15:49:38.136Z" }, + { url = "https://files.pythonhosted.org/packages/37/04/c8c2dc5b2f5fee79a1691d490256b178b7e1af97d56769117422ae8a23cc/ninja-1.13.2-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:59d71c3e15b6b6f3d903eb0c27285544e0747ca59925ada7037bb1af781ad4b3", size = 466268, upload-time = "2026-08-30T15:49:39.479Z" }, + { url = "https://files.pythonhosted.org/packages/f3/6d/fce288647e53e96e0f0929a3c5b23986aae1b7101ea8889a3090237c5d13/ninja-1.13.2-py3-none-musllinux_1_2_i686.whl", hash = "sha256:f90f84affc441e219f15fe52532806c1c9dbd22fb66c3addddce88a3deaabab7", size = 605088, upload-time = "2026-08-30T15:49:40.826Z" }, + { url = "https://files.pythonhosted.org/packages/10/a2/d8eedd25d0ae80b9e874aea362013e67416877c8f732eb4d5e7c971fdb9c/ninja-1.13.2-py3-none-musllinux_1_2_ppc64le.whl", hash = "sha256:b2f687437fac460b27b7eadc99039b1163016fb4ba7276e2782a192d9f24ee0e", size = 610806, upload-time = "2026-08-30T15:49:42.168Z" }, + { url = "https://files.pythonhosted.org/packages/14/0f/696d96821fad1b5767fd311c1569dde8881a57412369bfe7b11bcbfde036/ninja-1.13.2-py3-none-musllinux_1_2_riscv64.whl", hash = "sha256:09de9ab04f7352f51570c73fd4913acb1e6c24be0a72cd8b80243d4d3ed04925", size = 533978, upload-time = "2026-08-30T15:49:43.451Z" }, + { url = "https://files.pythonhosted.org/packages/5d/69/28844ca579156776a202217a7cd66f60d06a0710a935e879bb89ce396ecc/ninja-1.13.2-py3-none-musllinux_1_2_s390x.whl", hash = "sha256:6a87bf42b123abe2f37737300185f0a303a891899da85d73a3613ee80547e578", size = 653822, upload-time = "2026-08-30T15:49:44.724Z" }, + { url = "https://files.pythonhosted.org/packages/f5/5f/c511f2952f94ab2966d60edd9c34e744ea32f2724b1184b62270bde55b3a/ninja-1.13.2-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:915bd482c4be41c75120fd67a22e0bb3f0fbb3bbc5f95b89787deadd59e27ef2", size = 544460, upload-time = "2026-08-30T15:49:46.29Z" }, + { url = "https://files.pythonhosted.org/packages/79/e7/fb0e828e89ac77ef77183a0834f17c4108e66088732fed86a3cc3c776a7a/ninja-1.13.2-py3-none-win32.whl", hash = "sha256:792cadbb9decfd1f776d4d0a6930feb46d08302eb57c176bcf26b09de5748e9f", size = 270319, upload-time = "2026-08-30T15:49:47.942Z" }, + { url = "https://files.pythonhosted.org/packages/3f/dd/3766b5f4d32e8a9b97d195496b0b01fbbe2e1a41669dab0cd6492a6ce199/ninja-1.13.2-py3-none-win_amd64.whl", hash = "sha256:1293f4078278b70d0ee4b6cc8f3a9e030656c9b2f59909970343c4fe76070118", size = 311798, upload-time = "2026-08-30T15:49:49.351Z" }, + { url = "https://files.pythonhosted.org/packages/b7/8d/59a31fa508070d042571d9d226b541a21000756817313f397da22287ad34/ninja-1.13.2-py3-none-win_arm64.whl", hash = "sha256:1db9852e528efa7702f5123969f86678663e46d57ff28ab13f5fd84d64a85fb1", size = 290620, upload-time = "2026-08-30T15:49:50.639Z" }, +] + [[package]] name = "nltk" version = "3.10.3" @@ -2001,6 +2090,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/38/bb/d215ee7c73b61497b28a5503f9f53523f294fcc936762b7caf90e0c1c2b5/pyparsing-3.3.3-py3-none-any.whl", hash = "sha256:ece8c00a69cf01b45d0b1dedabb469c90d8caf996d4fda40f147627a122849a4", size = 126420, upload-time = "2026-09-20T20:59:04.025Z" }, ] +[[package]] +name = "pyre-extensions" +version = "0.0.32" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, + { name = "typing-inspect" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a7/53/5bc2532536e921c48366ad1047c1344ccef6afa5e84053f0f6e20a453767/pyre_extensions-0.0.32.tar.gz", hash = "sha256:5396715f14ea56c4d5fd0a88c57ca7e44faa468f905909edd7de4ad90ed85e55", size = 10852, upload-time = "2024-11-22T19:26:44.152Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a4/7a/9812cb8be9828ab688203c5ac5f743c60652887f0c00995a6f6f19f912bd/pyre_extensions-0.0.32-py3-none-any.whl", hash = "sha256:a63ba6883ab02f4b1a9f372ed4eb4a2f4c6f3d74879aa2725186fdfcfe3e5c68", size = 12766, upload-time = "2024-11-22T19:26:42.465Z" }, +] + [[package]] name = "pytest" version = "9.1.1" @@ -2552,6 +2654,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/dc/bf/205d0004930ede8f542fb58f601526fccf4ae7626075ca1e6c4de5d3d652/typer-0.27.2-py3-none-any.whl", hash = "sha256:b3a5fc4342d5fc8fda8fc3010b1cf117e9249aab7fae800c2eff62fd3842d97d", size = 123130, upload-time = "2026-08-28T10:26:53.752Z" }, ] +[[package]] +name = "types-pyyaml" +version = "6.0.12.20261103" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d9/82/2ed4d215a2840b467a9a864f03b0d21904250e28f5e1f006ad36fba0311a/types_pyyaml-6.0.12.20261103.tar.gz", hash = "sha256:7a1b5f837881dd35d5448b5f18275164f89f206185e31e8eae6e0b42607bc001", size = 18911, upload-time = "2026-11-03T08:45:23.714Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e8/10/4353eb86278f6a59aeb9fe2be4d979c20b110b4009fa455a3ea6467cf5cb/types_pyyaml-6.0.12.20261103-py3-none-any.whl", hash = "sha256:444654c61f635dab82c092a511aa96a0ce31164810784b9a37314e3e56532ac8", size = 21299, upload-time = "2026-11-03T08:45:22.749Z" }, +] + [[package]] name = "types-tqdm" version = "4.70.0.20260906"