Utilities (pypielm.utils)¶
Utilities: reproducibility helpers, YAML config loader, and type coercions.
Implemented across Steps 2 (reproducibility) and 10 (config / CLI).
- pypielm.utils.seed_everything(seed=42, *, deterministic=True)[source]¶
Set all relevant random seeds for full reproducibility.
Seeds: Python
random,numpy.random, PyTorch CPU, PyTorch CUDA, and Apple MPS (seeded implicitly viatorch.manual_seed()).
- pypielm.utils.get_device(prefer_cuda=True, prefer_mps=True)[source]¶
Return the best available
torch.device.Priority order: CUDA > MPS (Apple Silicon) > CPU.
- Parameters:
- Return type:
- Returns:
A
torch.device.
Config Loader¶
YAML-based experiment configuration loader and runner.
- class pypielm.utils.config.ExperimentConfig(model='core_pielm', model_kwargs=<factory>, data=<factory>, pde=<factory>, seed=42, device='cpu', output_dir='runs/')[source]¶
Bases:
objectFully-specified configuration for a single PyPIELM experiment.
All fields can be populated from a YAML file via
load_config().- Parameters:
model (
str) – Registered model name (e.g.'core_pielm').model_kwargs (
dict[str,Any]) – Keyword arguments forwarded to the model constructor.data (
dict[str,Any]) – Data loading specification (source,path, split ratios).pde (
dict[str,Any]) – PDE configuration (operator,collocation,n_collocation).seed (
int) – Global random seed (passed toseed_everything()).device (
str) – Target device string.output_dir (
str) – Directory for saving artefacts (model, results, figures).
Example YAML:
model: core_pielm model_kwargs: hidden_dim: 300 ridge_lambda: 1.0e-8 data: source: pinnacle path: data/poisson_classic.dat val_ratio: 0.1 test_ratio: 0.2 pde: operator: laplacian collocation: LHSSampler n_collocation: 1000 seed: 42 device: cpu output_dir: runs/poisson_classic_core/
- pypielm.utils.config.load_config(path)[source]¶
Load and validate an experiment config from a YAML file.
- Parameters:
- Return type:
- Returns:
A populated
ExperimentConfiginstance.- Raises:
FileNotFoundError – If
pathdoes not exist.ValueError – If required fields are missing or values are invalid.
- pypielm.utils.config.run_experiment(config)[source]¶
Execute a single experiment defined by
config.Steps performed:
Seed everything via
seed_everything().Load data via
auto_load()(ifdata.pathis given) or build a synthetic dataset for dry-runs.Instantiate the model from the registry.
Resolve PDE operator and collocation sampler.
Call
model.fit(dataset, ...).Evaluate metrics on the test split.
Save checkpoint +
results.jsontooutput_dir.
- Parameters:
config (
ExperimentConfig) – A validatedExperimentConfig.- Returns:
'metrics': dict of metric name → float.'config': the config as a plain dict.'artifacts': list of paths of saved files.
- Return type:
Dictionary with keys
Reproducibility¶
Utility helpers: reproducibility and device selection.
- pypielm.utils.reproducibility.seed_everything(seed=42, *, deterministic=True)[source]¶
Set all relevant random seeds for full reproducibility.
Seeds: Python
random,numpy.random, PyTorch CPU, PyTorch CUDA, and Apple MPS (seeded implicitly viatorch.manual_seed()).
- pypielm.utils.reproducibility.get_device(prefer_cuda=True, prefer_mps=True)[source]¶
Return the best available
torch.device.Priority order: CUDA > MPS (Apple Silicon) > CPU.
- Parameters:
- Return type:
- Returns:
A
torch.device.