anypinn.core.dataset
Data handling for PINN training.
DataCallback
Base class for callbacks that transform data during setup.
Subclass this to apply custom preprocessing (e.g. scaling, normalization) to training data and collocation points before the dataset is constructed.
Source code in src/anypinn/core/dataset.py
on_after_setup(dm: PINNDataModule) -> None
Hook called after PINNDataModule.setup() completes.
Use this to perform post-processing that depends on the fully constructed data module (e.g. adjusting validation functions to account for earlier scaling transforms).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dm
|
PINNDataModule
|
The fully initialized data module. |
required |
Source code in src/anypinn/core/dataset.py
transform_data(data: DataBatch, coll: Tensor) -> tuple[DataBatch, Tensor]
Transform training data and collocation points.
Called during PINNDataModule.setup() after data is loaded
but before the PINNDataset is created. Multiple callbacks
are applied in registration order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataBatch
|
Tuple of (x, y) training tensors. |
required |
coll
|
Tensor
|
Collocation point coordinates. |
required |
Returns:
| Type | Description |
|---|---|
tuple[DataBatch, Tensor]
|
Transformed (data, coll) tuple. |
Source code in src/anypinn/core/dataset.py
PINNDataModule
Bases: LightningDataModule, ABC
LightningDataModule for PINNs. Manages data and collocation datasets and creates the combined PINNDataset.
Collocation points are generated via a CollocationSampler selected by the
collocation_sampler field in TrainingDataConfig (string literal).
Subclasses only need to implement gen_data(); collocation generation is
handled by the sampler resolved from the hyperparameters.
Attributes:
| Name | Type | Description |
|---|---|---|
pinn_ds |
Combined PINNDataset for training. |
|
callbacks |
list[DataCallback]
|
Sequence of DataCallback callbacks applied after data loading. |
Source code in src/anypinn/core/dataset.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
callbacks: list[DataCallback] = list(callbacks) if callbacks else []
instance-attribute
context: InferredContext
property
hp = hp
instance-attribute
__init__(hp: PINNHyperparameters, validation: ValidationRegistry | None = None, callbacks: Sequence[DataCallback] | None = None, residual_scorer: ResidualScorer | None = None) -> None
Source code in src/anypinn/core/dataset.py
gen_data(config: GenerationConfig) -> DataBatch
abstractmethod
Generate synthetic training data from a known solution.
Subclasses implement this to solve the ODE/PDE with known parameters and return the resulting data (optionally with added noise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
GenerationConfig
|
Generation configuration specifying the domain, noise level, and ground-truth arguments. |
required |
Returns:
| Type | Description |
|---|---|
DataBatch
|
Tuple of |
DataBatch
|
|
Source code in src/anypinn/core/dataset.py
load_data(config: IngestionConfig) -> DataBatch
Load training data from a CSV file.
Reads the CSV at config.df_path, extracts x and y columns,
and returns tensors shaped for PINN training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
IngestionConfig
|
Ingestion configuration specifying paths and columns. |
required |
Returns:
| Type | Description |
|---|---|
DataBatch
|
Tuple of |
DataBatch
|
|
Source code in src/anypinn/core/dataset.py
predict_dataloader() -> DataLoader[PredictionBatch]
Returns the prediction dataloader using only the data dataset.
Source code in src/anypinn/core/dataset.py
setup(stage: str | None = None) -> None
Load raw data from IngestionConfig, or generate synthetic data from GenerationConfig. Apply registered callbacks, create InferredContext and datasets.
Source code in src/anypinn/core/dataset.py
train_dataloader() -> DataLoader[TrainingBatch]
Returns the training dataloader using PINNDataset.
Source code in src/anypinn/core/dataset.py
PINNDataset
Bases: Dataset[TrainingBatch]
Dataset used for PINN training. Combines labeled data and collocation points
per sample. Given a data_ratio, the amount of data points K is determined
either by applying data_ratio * batch_size if ratio is a float between 0
and 1 or by an absolute count if ratio is an integer. The remaining C
points are used for collocation. The data points are sampled without
replacement per epoch i.e. cycles through all data points and at the last
batch, wraps around to the first indices to ensure batch size. The collocation
points are sampled with replacement from the pool.
The dataset produces a batch of shape ((x_data[K,d], y_data[K,...]), x_coll[C,d]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_data
|
Tensor
|
Data point x coordinates (time values). |
required |
y_data
|
Tensor
|
Data point y values (observations). |
required |
x_coll
|
Tensor
|
Collocation point x coordinates. |
required |
batch_size
|
int
|
Size of the batch. |
required |
data_ratio
|
float | int
|
Ratio of data points to collocation points, either as a ratio [0,1] or absolute count [0,batch_size]. |
required |
Source code in src/anypinn/core/dataset.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
C = batch_size - self.K
instance-attribute
K = round(data_ratio * batch_size)
instance-attribute
batch_size = batch_size
instance-attribute
total_coll = x_coll.shape[0]
instance-attribute
total_data = x_data.shape[0]
instance-attribute
x_coll = x_coll
instance-attribute
x_data = x_data
instance-attribute
y_data = y_data
instance-attribute
__getitem__(index: int) -> TrainingBatch
Return one sample containing K data points and C collocation points.