torchphysics.utils.data package

Submodules

torchphysics.utils.data.dataloader module

class torchphysics.utils.data.dataloader.PointsDataLoader(data_points, batch_size, shuffle=False, num_workers=0, pin_memory=False, drop_last=False)[source]

Bases: DataLoader

A DataLoader that can be used in a condition to load minibatches of paired data points as the input and output of a model.

Parameters:
  • data_points (Points or tuple) – One or multiple Points object containing multiple data points or tuples of data points. If a tuple of Points objects is given, they should all have the same length, as data will be loaded in tuples where the i-th points are loaded simultaneously.

  • batch_size (int) – The size of the loaded batches.

  • shuffle (bool) – Whether to shuffle the order of the data points at initialization.

  • num_workers (int) – The amount of workers used during data loading, see also: the PyTorch documentation

  • pin_memory (bool) – Whether to use pinned memory during data loading, see also: the PyTorch documentation

  • drop_last (bool) – Whether to drop the last (and non-batch-size-) minibatch.

class torchphysics.utils.data.dataloader.PointsDataset(data_points, batch_size, shuffle=False, drop_last=False)[source]

Bases: Dataset

A PyTorch Dataset to load tuples of data points.

Parameters:
  • data_points (Points or tuple) – One or multiple Points object containing multiple data points or tuples of data points. If a tuple of Points objects is given, they should all have the same length, as data will be loaded in tuples where the i-th points are loaded simultaneously.

  • batch_size (int) – The size of the loaded batches.

  • shuffle (bool) – Whether to shuffle the order of the data points at initialization.

  • drop_last (bool) – Whether to drop the last (and non-batch-size-) minibatch.

__getitem__(idx)[source]

Returns the item at the given index.

Parameters:

idx (int) – The index of the desired point.

__len__()[source]

Returns the number of points of this dataset.

torchphysics.utils.data.deeponet_dataloader module

class torchphysics.utils.data.deeponet_dataloader.DeepONetDataLoader(branch_data, trunk_data, output_data, branch_space, trunk_space, output_space, branch_batch_size, trunk_batch_size, shuffle_branch=False, shuffle_trunk=True, num_workers=0, pin_memory=False)[source]

Bases: DataLoader

A DataLoader that can be used in a condition to load minibatches of paired data points as the input and output of a DeepONet-model.

Parameters:
  • branch_data (torch.tensor) – A tensor containing the input data for the branch network. Has to be of the shape: [number_of_functions, discrete_points_of_branch_net, function_space_dim] For example, if we have a batch of 20 vector-functions (\(f:\R o \R^2\)) and use 100 discrete points for the evaluation (where the branch nets evaluates f), the shape would be: [20, 100, 2]

  • trunk_data (torch.tensor) –

    A tensor containing the input data for the trunk network. There are two different possibilites for the shape of this data:

    1. Every branch input function uses the same trunk values, then we can pass in the shape: [number_of_trunk_points, input_dim_of_trunk_net] This can speed up the trainings process.

    2. Or every branch function has different values for the trunk net, then we need the shape: [number_of_functions, number_of_trunk_points, input_dim_of_trunk_net] If this is the case, remember to set ‘trunk_input_copied = false’ inside the trunk net, to get the right trainings process.

  • output_data (torch.tensor) – A tensor containing the expected output of the network. Shape of the data should be: [number_of_functions, number_of_trunk_points, output_dim].

  • branch_space (torchphysics.spaces.Space) – The output space of the functions, that are used as the branch input.

  • trunk_space (torchphysics.spaces.Space) – The input space of the trunk network.

  • output_space (torchphysics.spaces.Space) – The output space in which the solution is.

  • branch_batch_size (int) – The size of the loaded batches for trunk and branch.

  • trunk_batch_size (int) – The size of the loaded batches for trunk and branch.

  • shuffle_branch (bool) – Whether to shuffle the order of the branch functions at initialization.

  • shuffle_trunk (bool) – Whether to shuffle the order of the trunk points at initialization.

  • num_workers (int) – The amount of workers used during data loading, see also: the PyTorch documentation

  • pin_memory (bool) – Whether to use pinned memory during data loading, see also: the PyTorch documentation

class torchphysics.utils.data.deeponet_dataloader.DeepONetDataset(branch_data_points, trunk_data_points, out_data_points, branch_space, trunk_space, output_space, branch_batch_size, trunk_batch_size, shuffle_branch=False, shuffle_trunk=True)[source]

Bases: Dataset

A PyTorch Dataset to load tuples of data points, used via DeepONetDataLoader. Used if all branch inputs have the same trunk points.

__getitem__(idx)[source]

Returns the item at the given index.

Parameters:

idx (int) – The index of the desired point.

__len__()[source]

Returns the number of points of this dataset.

class torchphysics.utils.data.deeponet_dataloader.DeepONetDataset_Unique(branch_data_points, trunk_data_points, out_data_points, branch_space, trunk_space, output_space, branch_batch_size, trunk_batch_size, shuffle_branch=False, shuffle_trunk=True)[source]

Bases: Dataset

A PyTorch Dataset to load tuples of data points, used in the DeepONetDataLoader. Is used when every branch input has unique trunk inputs -> Ordering of points is important.

__getitem__(idx)[source]

Returns the item at the given index.

Parameters:

idx (int) – The index of the desired point.

__len__()[source]

Returns the number of points of this dataset.