Data Layer (pypielm.data)¶
Data loading and preprocessing.
Public surface:
from pypielm.data import (
PIELMDataset,
auto_load,
Normalizer,
FeatureExpander,
Pipeline,
CSVAdapter,
NPZAdapter,
PINNacleAdapter,
PDEBenchAdapter,
TorchDatasetAdapter,
)
PIELMDataset¶
Core dataset container for PyPIELM.
PIELMDataset is the canonical input to every model.fit() call.
It holds collocation, boundary, initial condition, and optional observation
tensors and exposes convenience constructors and device-migration helpers.
- class pypielm.data.dataset.PIELMDataset(X_colloc, X_bc=None, y_bc=None, X_ic=None, y_ic=None, X_data=None, y_data=None, meta=<factory>)[source]¶
Bases:
objectDataset container passed to
fit().Fields:
X_colloc— Interior collocation points(N_pde, d).X_bc— Boundary condition points(N_bc, d)(optional).y_bc— BC target values(N_bc, m)(optional).X_ic— Initial condition points(N_ic, d)(optional).y_ic— IC target values(N_ic, m)(optional).X_data— Observed data points(N_obs, d)(optional).y_data— Observed target values(N_obs, m)(optional).meta— Free-form metadata dict.
- classmethod from_arrays(X_colloc, *, X_bc=None, y_bc=None, X_ic=None, y_ic=None, X_data=None, y_data=None, dtype=torch.float64, device='cpu', meta=None)[source]¶
Construct a
PIELMDatasetfrom numpy arrays or lists.- Parameters:
- Return type:
- Returns:
A new
PIELMDatasetinstance.
- to(device, dtype=None)[source]¶
Move all tensors to device (and optionally cast to dtype).
Returns a new
PIELMDataset; the original is unchanged.- Return type:
Adapters¶
Data adapters for loading datasets from various external formats.
Public surface:
from pypielm.data.adapters import (
CSVAdapter,
NPZAdapter,
PINNacleAdapter,
PDEBenchAdapter,
TorchDatasetAdapter,
)
CSV file adapter.
- class pypielm.data.adapters.csv_adapter.CSVAdapter(path, column_map=None, delimiter=',', dtype=torch.float64, device='cpu')[source]¶
Bases:
objectLoad a
PIELMDatasetfrom a CSV file.By default (when column_map is
None) the adapter treats all columns except the last asX_collocand the last column asy_data.- Parameters:
column_map (
dict[str,list[str|int]] |None) – Optional dict mapping field names ('X_colloc','X_bc','y_bc','X_ic','y_ic','X_data','y_data') to lists of column names or column indices (0-based integers). WhenNonethe default heuristic applies.delimiter (
str) – Field delimiter (default',').dtype (
dtype) – Target tensor dtype.
- load()[source]¶
Read the CSV and return a
PIELMDataset.- Return type:
NumPy .npz file adapter.
- class pypielm.data.adapters.npz_adapter.NPZAdapter(path, dtype=torch.float64, device='cpu')[source]¶
Bases:
objectLoad a
PIELMDatasetfrom a NumPy.npzfile.Expected keys in the archive:
'X_colloc', and optionally'X_bc','y_bc','X_ic','y_ic','X_data','y_data'.When no
'X_colloc'key is present but the archive has exactly two arrays, the first is treated asX_collocand the second asy_data.- Parameters:
PINNacle dataset adapter.
PINNacle (https://github.com/lu-group/pinn-benchmark) distributes datasets as HDF5 / npz archives with a specific directory structure. This adapter ports the logic from the reference benchmark_framework implementation to operate directly on the raw files.
- class pypielm.data.adapters.pinnacle_adapter.PINNacleAdapter(root, task, dtype=torch.float64, device='cpu')[source]¶
Bases:
objectLoad a task dataset in PINNacle format.
- Parameters:
- load()[source]¶
Load the task dataset and return a
PIELMDataset.- Return type:
PDEBench dataset adapter.
PDEBench (https://github.com/pdebench/PDEBench) distributes datasets as HDF5
files. This adapter reads a single PDE task file and converts it to
PIELMDataset.
h5py is an optional dependency — a clear ImportError is raised if missing.
- class pypielm.data.adapters.pdebench_adapter.PDEBenchAdapter(path, equation=None, sample_idx=0, dtype=torch.float64, device='cpu')[source]¶
Bases:
objectLoad a
PIELMDatasetfrom a PDEBench HDF5 file.The adapter reads the spatial grid coordinates (
x) and the solution field (u) and flattens them into(N, d)and(N, m)arrays suitable for a PIELM collocation problem.- Parameters:
PyTorch Dataset / DataLoader adapter.
Wraps a standard torch.utils.data.Dataset to produce a
PIELMDataset.
- class pypielm.data.adapters.torch_adapter.TorchDatasetAdapter(dataset, role='data', dtype=torch.float64, device='cpu')[source]¶
Bases:
objectConvert a
torch.utils.data.Datasetinto aPIELMDataset.The
torch.utils.data.Datasetmust return(x, y)tuples where x are spatial coordinates and y are target values. All items are loaded eagerly into memory.- Parameters:
- load()[source]¶
Eagerly load all items and return a
PIELMDataset.- Return type:
Transforms¶
Data preprocessing transforms.
Provides:
- Normalizer — min-max or z-score normalisation (fit on train only).
- FeatureExpander — polynomial / trigonometric feature augmentation.
- Pipeline — sequential composition of transforms.
- class pypielm.data.transforms.Normalizer(method='minmax', eps=1e-08)[source]¶
Bases:
objectMin-max or z-score normalisation of tensors.
- Parameters:
- class pypielm.data.transforms.FeatureExpander(degree=1, trig=False)[source]¶
Bases:
objectExpand input features with polynomial or trigonometric terms.
Useful for augmenting low-dimensional spatial coordinates before passing them to a model.
- Parameters:
The expansion is stateless —
fit_transformandtransformbehave identically. Nofit()call is needed.- transform(X)[source]¶
Alias for
fit_transform()(stateless).- Return type:
- class pypielm.data.transforms.Pipeline(steps)[source]¶
Bases:
objectSequential composition of transform steps.
- Parameters:
steps (
list[Any]) – List of transform objects. Each must expose at least one of: -fit_transform(X)(called on the first invocation) -transform(X)(called on subsequent invocations)
On the first call to
fit_transform()each step’sfit_transformis used. Subsequent calls totransform()use each step’stransformmethod (falling back tofit_transformfor stateless steps that lack it).