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: object

Dataset 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.

X_colloc: Tensor
X_bc: Tensor | None = None
y_bc: Tensor | None = None
X_ic: Tensor | None = None
y_ic: Tensor | None = None
X_data: Tensor | None = None
y_data: Tensor | None = None
meta: dict[str, Any]
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 PIELMDataset from numpy arrays or lists.

Parameters:
  • X_colloc (Any) – Interior collocation points, array-like (N, d).

  • X_bc (Any | None) – Boundary points.

  • y_bc (Any | None) – Boundary target values.

  • X_ic (Any | None) – Initial condition points.

  • y_ic (Any | None) – IC target values.

  • X_data (Any | None) – Observed data points.

  • y_data (Any | None) – Observed data targets.

  • dtype (dtype) – Target tensor dtype.

  • device (str | device) – Target device.

  • meta (dict[str, Any] | None) – Optional metadata.

Return type:

PIELMDataset

Returns:

A new PIELMDataset instance.

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:

PIELMDataset

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: object

Load a PIELMDataset from a CSV file.

By default (when column_map is None) the adapter treats all columns except the last as X_colloc and the last column as y_data.

Parameters:
  • path (str | Path) – Path to the CSV file.

  • 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). When None the default heuristic applies.

  • delimiter (str) – Field delimiter (default ',').

  • dtype (dtype) – Target tensor dtype.

  • device (str | device) – Target device.

load()[source]

Read the CSV and return a PIELMDataset.

Return type:

PIELMDataset

NumPy .npz file adapter.

class pypielm.data.adapters.npz_adapter.NPZAdapter(path, dtype=torch.float64, device='cpu')[source]

Bases: object

Load a PIELMDataset from a NumPy .npz file.

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 as X_colloc and the second as y_data.

Parameters:
  • path (str | Path) – Path to the .npz file.

  • dtype (dtype) – Tensor dtype.

  • device (str | device) – Target device.

load()[source]

Load and return the dataset.

Return type:

PIELMDataset

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: object

Load a task dataset in PINNacle format.

Parameters:
  • root (str | Path) – Root directory of the PINNacle data folder.

  • task (str) – Task identifier string, e.g. 'poisson_classic', or a path to the data file itself.

  • dtype (dtype) – Tensor dtype.

  • device (str | device) – Target device.

load()[source]

Load the task dataset and return a PIELMDataset.

Return type:

PIELMDataset

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: object

Load a PIELMDataset from 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:
  • path (str | Path) – Path to the .h5 / .hdf5 file.

  • equation (str | None) – Equation name key inside the HDF5 file (top-level group), e.g. '1D_Advection'. When None the first top-level group is used.

  • sample_idx (int) – Index of the trajectory/sample to load (time snapshot 0 is used as the target field).

  • dtype (dtype) – Tensor dtype.

  • device (str | device) – Target device.

load()[source]

Load and return the dataset.

Requires the optional h5py dependency and an actual HDF5 file; excluded from automated coverage runs.

Return type:

PIELMDataset

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: object

Convert a torch.utils.data.Dataset into a PIELMDataset.

The torch.utils.data.Dataset must return (x, y) tuples where x are spatial coordinates and y are target values. All items are loaded eagerly into memory.

Parameters:
  • dataset (Dataset) – Source PyTorch dataset returning (x, y) pairs.

  • role (str) – Determines which field of PIELMDataset the loaded points populate. One of 'colloc', 'bc', 'ic', 'data'.

  • dtype (dtype) – Tensor dtype.

  • device (str | device) – Target device.

load()[source]

Eagerly load all items and return a PIELMDataset.

Return type:

PIELMDataset

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: object

Min-max or z-score normalisation of tensors.

Parameters:
  • method (str) – 'minmax' (scale to [0, 1]) or 'zscore' (zero mean, unit variance).

  • eps (float) – Small constant added to denominator to avoid division by zero.

fit(X)[source]

Compute normalisation statistics from X (rows = samples).

Return type:

Normalizer

transform(X)[source]

Apply normalisation (must call fit() first).

Return type:

Tensor

inverse_transform(X)[source]

Reverse the normalisation.

Return type:

Tensor

fit_transform(X)[source]

Fit and transform in one call.

Return type:

Tensor

class pypielm.data.transforms.FeatureExpander(degree=1, trig=False)[source]

Bases: object

Expand input features with polynomial or trigonometric terms.

Useful for augmenting low-dimensional spatial coordinates before passing them to a model.

Parameters:
  • degree (int) – Polynomial degree for monomial expansion (1 = keep original).

  • trig (bool) – If True, append sin and cos of each original feature.

The expansion is stateless — fit_transform and transform behave identically. No fit() call is needed.

fit_transform(X)[source]

Return augmented feature matrix.

Return type:

Tensor

transform(X)[source]

Alias for fit_transform() (stateless).

Return type:

Tensor

class pypielm.data.transforms.Pipeline(steps)[source]

Bases: object

Sequential 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’s fit_transform is used. Subsequent calls to transform() use each step’s transform method (falling back to fit_transform for stateless steps that lack it).

fit_transform(X)[source]

Apply all steps sequentially using their fit_transform method.

Return type:

Tensor

transform(X)[source]

Apply all fitted steps in sequence.

Return type:

Tensor