anypinn.core.dataset
Data handling for PINN training.
DataCallback
Abstract base class for building new data callbacks.
Source code in src/anypinn/core/dataset.py
on_after_setup(dm: PINNDataModule) -> None
transform_data(data: DataBatch, coll: Tensor) -> tuple[DataBatch, Tensor]
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
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 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 | |
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
load_data(config: IngestionConfig) -> DataBatch
Load raw data from IngestionConfig.
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
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.