pararealml.operators.ml.pidon package

Submodules

pararealml.operators.ml.pidon.auto_differentiator module

class pararealml.operators.ml.pidon.auto_differentiator.AutoDifferentiator(persistent: bool = False, watch_accessed_variables: bool = True)[source]

Bases: tensorflow.python.eager.backprop.GradientTape

A class providing various differential operators using TensorFlow’s auto-differentiation capabilities.

batch_curl(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, curl_ind: int = 0, coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0, )>) → tensorflow.python.framework.ops.Tensor[source]

Returns the curl_ind-th component of the curl of y.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • curl_ind – the index of the component of the curl of y to compute; if y is a two dimensional vector field, it must be 0
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the curl_ind-th component of the curl of y

batch_divergence(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0, )>) → tensorflow.python.framework.ops.Tensor[source]

Returns the divergence of y.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the divergence of y

batch_gradient(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, x_axis: Union[int, tensorflow.python.framework.ops.Tensor], coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0,)>) → tensorflow.python.framework.ops.Tensor[source]

Returns the element(s) of the gradient of y with respect to the element of x defined by x_axis.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • x_axis – the element of x to take the gradient with respect to
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the gradient of y with respect to the element of x defined by x_axis

batch_hessian(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, x_axis1: int, x_axis2: int, coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0, )>) → tensorflow.python.framework.ops.Tensor[source]

Returns the element(s) of the Hessian of y with respect to the elements of x defined by x_axis1 and x_axis2.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • x_axis1 – the first element of x to take the Hessian with respect to
  • x_axis2 – the second element of x to take the Hessian with respect to
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the Hessian of y with respect to the elements of x defined by x_axis1 and x_axis2

batch_laplacian(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0, )>) → tensorflow.python.framework.ops.Tensor[source]

Returns the element-wise scalar Laplacian of y.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the Laplacian of y

batch_vector_laplacian(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, vector_laplacian_ind: int, coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0, )>) → tensorflow.python.framework.ops.Tensor[source]

Returns the vector Laplacian of y.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • vector_laplacian_ind – the index of the component of the vector Laplacian of y to compute
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the vector Laplacian of y

pararealml.operators.ml.pidon.collocation_point_sampler module

class pararealml.operators.ml.pidon.collocation_point_sampler.AxialBoundaryPoints[source]

Bases: tuple

Spatio-temporal collocation points sampled from the lower and upper boundaries of a spatial axis.

lower_boundary_points

Alias for field number 0

upper_boundary_points

Alias for field number 1

class pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPointSampler[source]

Bases: abc.ABC

A base class for collocation point samplers.

sample_boundary_points(n_points: int, t_interval: Tuple[float, float], x_intervals: Sequence[Tuple[float, float]]) → Sequence[pararealml.operators.ml.pidon.collocation_point_sampler.AxialBoundaryPoints][source]

Samples a set of points organized into a sequence of pairs from the boundaries of a spatio-temporal domain.

Parameters:
  • n_points – the number of points to sample
  • t_interval – the bounds of the temporal domain
  • x_intervals – a sequence of the bounds of the spatial domain
Returns:

a set of boundary points organized into a sequence of pairs

sample_domain_points(n_points: int, t_interval: Tuple[float, float], x_intervals: Optional[Sequence[Tuple[float, float]]]) → pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPoints[source]

Samples a set of points from a spatio-temporal domain. If the spatial domain intervals are undefined, it only samples from the temporal domain.

Parameters:
  • n_points – the number of points to sample
  • t_interval – the bounds of the temporal domain
  • x_intervals – a sequence of the bounds of the spatial domain
Returns:

a set of domain points

class pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPoints[source]

Bases: tuple

Collocation points from a spatio-temporal domain.

t

Alias for field number 0

x

Alias for field number 1

class pararealml.operators.ml.pidon.collocation_point_sampler.UniformRandomCollocationPointSampler[source]

Bases: pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPointSampler

A uniform random collocation point sampler.

sample_boundary_points(n_points: int, t_interval: Tuple[float, float], x_intervals: Sequence[Tuple[float, float]]) → Sequence[pararealml.operators.ml.pidon.collocation_point_sampler.AxialBoundaryPoints][source]

Samples a set of points organized into a sequence of pairs from the boundaries of a spatio-temporal domain.

Parameters:
  • n_points – the number of points to sample
  • t_interval – the bounds of the temporal domain
  • x_intervals – a sequence of the bounds of the spatial domain
Returns:

a set of boundary points organized into a sequence of pairs

sample_domain_points(n_points: int, t_interval: Tuple[float, float], x_intervals: Optional[Sequence[Tuple[float, float]]]) → pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPoints[source]

Samples a set of points from a spatio-temporal domain. If the spatial domain intervals are undefined, it only samples from the temporal domain.

Parameters:
  • n_points – the number of points to sample
  • t_interval – the bounds of the temporal domain
  • x_intervals – a sequence of the bounds of the spatial domain
Returns:

a set of domain points

pararealml.operators.ml.pidon.data_set module

class pararealml.operators.ml.pidon.data_set.BoundaryDataBatch[source]

Bases: tuple

A container for boundary batch data.

axes

Alias for field number 5

d_y_over_d_n

Alias for field number 4

t

Alias for field number 1

u

Alias for field number 0

x

Alias for field number 2

y

Alias for field number 3

class pararealml.operators.ml.pidon.data_set.DataBatch[source]

Bases: tuple

A container for a data batch including domain data, initial value data, and optionally boundary data.

boundary

Alias for field number 2

domain

Alias for field number 0

initial

Alias for field number 1

class pararealml.operators.ml.pidon.data_set.DataSet(cp: pararealml.constrained_problem.ConstrainedProblem, t_interval: Tuple[float, float], y_0_functions: Iterable[Callable[[Optional[numpy.ndarray]], numpy.ndarray]], point_sampler: pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPointSampler, n_domain_points: int, n_boundary_points: int = 0, vertex_oriented: bool = False)[source]

Bases: object

A generator and container of all the data necessary to train a physics-informed DeepONet with variable initial conditions.

boundary_collocation_data

The boundary collocation data points where the columns represent t, x, y, the derivative of y with respect to the unit normal vector of the boundary, and finally the axis denoting the direction of the normal vector.

constrained_problem

The constrained problem the data set is built around.

domain_collocation_data

The domain collocation data points where the first column is t and all other columns are x.

get_iterator(n_batches: int, n_ic_repeats: int = 1, shuffle: bool = True) → pararealml.operators.ml.pidon.data_set.DataSetIterator[source]

Returns an iterator over the data set to enable iterating over the Cartesian product of the initial value data and the collocation data batch by batch.

Parameters:
  • n_batches – the number of batches to map the underlying data to
  • n_ic_repeats – the number of times to repeat the initial collocation data samples in an epoch
  • shuffle – whether to shuffle the data behind the iterator
Returns:

the iterator over the data set

initial_collocation_data

The initial collocation data points where the first column is t and all other columns are x.

initial_value_data

The initial value data where each row is a different initial condition function and each column represents a component of the initial condition function evaluated over a point of the constrained problem’s mesh.

class pararealml.operators.ml.pidon.data_set.DataSetIterator(data_set: pararealml.operators.ml.pidon.data_set.DataSet, n_batches: int, n_ic_repeats: int = 1, shuffle: bool = True)[source]

Bases: collections.abc.Iterator

An iterator over a data set that computes the Cartesian products of the initial value data with the domain, initial, and boundary collocation data.

boundary_batch_size

The boundary data batch size used by the iterator.

domain_batch_size

The domain data batch size used by the iterator.

get_full_batch() → pararealml.operators.ml.pidon.data_set.DataBatch[source]

Returns the full Cartesian product of all the initial value data and all the domain, initial, and boundary collocation data contained within the underlying data set.

initial_batch_size

The initial data batch size used by the iterator.

reset()[source]

Resets the iterator so that the data set can be iterated over again.

class pararealml.operators.ml.pidon.data_set.DomainDataBatch[source]

Bases: tuple

A container for domain batch data.

t

Alias for field number 1

u

Alias for field number 0

x

Alias for field number 2

class pararealml.operators.ml.pidon.data_set.InitialDataBatch[source]

Bases: tuple

A container for initial condition batch data.

t

Alias for field number 1

u

Alias for field number 0

x

Alias for field number 2

y

Alias for field number 3

pararealml.operators.ml.pidon.loss module

class pararealml.operators.ml.pidon.loss.Loss[source]

Bases: tuple

A collection of the various losses of a physics-informed DeepONet.

bc_losses

Alias for field number 2

classmethod construct(diff_eq_loss: tensorflow.python.framework.ops.Tensor, ic_loss: tensorflow.python.framework.ops.Tensor, bc_losses: Optional[Tuple[tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor]], diff_eq_loss_weight: float, ic_loss_weight: float, bc_loss_weight: float) → pararealml.operators.ml.pidon.loss.Loss[source]

Calculates the weighted total loss given the weights for the different components of the total loss and returns a Loss instance.

Parameters:
  • diff_eq_loss – the differential equation loss tensor
  • ic_loss – the initial condition loss tensor
  • bc_losses – a tuple of the Dirichlet and Neumann boundary condition loss tensors
  • diff_eq_loss_weight – the weight of the differential equation part of the total physics-informed loss
  • ic_loss_weight – the weight of the initial condition part of the total physics-informed loss
  • bc_loss_weight – the weight of the boundary condition part of the total physics-informed loss
Returns:

the losses including the weighted total

diff_eq_loss

Alias for field number 0

ic_loss

Alias for field number 1

classmethod mean(losses: Sequence[pararealml.operators.ml.pidon.loss.Loss], diff_eq_loss_weight: float, ic_loss_weight: float, bc_loss_weight: float) → pararealml.operators.ml.pidon.loss.Loss[source]

Computes the mean of the provided losses.

Parameters:
  • losses – the losses to average over
  • diff_eq_loss_weight – the weight of the differential equation part of the total physics-informed loss
  • ic_loss_weight – the weight of the initial condition part of the total physics-informed loss
  • bc_loss_weight – the weight of the boundary condition part of the total physics-informed loss
Returns:

the mean loss

weighted_total_loss

Alias for field number 3

pararealml.operators.ml.pidon.pi_deeponet module

class pararealml.operators.ml.pidon.pi_deeponet.PIDeepONet(cp: pararealml.constrained_problem.ConstrainedProblem, latent_output_size: int, branch_hidden_layer_sizes: Optional[List[int]] = None, trunk_hidden_layer_sizes: Optional[List[int]] = None, branch_initialization: str = 'glorot_uniform', trunk_initialization: str = 'glorot_uniform', branch_activation: Optional[str] = 'tanh', trunk_activation: Optional[str] = 'tanh', vertex_oriented: bool = False)[source]

Bases: pararealml.operators.ml.deeponet.DeepONet

A Physics-Informed DeepONet model.

See: https://arxiv.org/abs/2103.10974

constrained_problem

The constrained problem the model is built around.

fit(epochs: int, optimizer: Union[str, Dict[str, Any], keras.optimizer_v2.optimizer_v2.OptimizerV2], training_data: pararealml.operators.ml.pidon.data_set.DataSetIterator, test_data: Optional[pararealml.operators.ml.pidon.data_set.DataSetIterator] = None, diff_eq_loss_weight: float = 1.0, ic_loss_weight: float = 1.0, bc_loss_weight: float = 1.0, verbose: bool = True) → Tuple[List[pararealml.operators.ml.pidon.loss.Loss], List[pararealml.operators.ml.pidon.loss.Loss]][source]

Fits the branch and trunk net parameters by minimising the physics-informed loss function over the provided training data set. It also evaluates the loss over both the training data and the test data, if provided, for every epoch.

Parameters:
  • epochs – the number of epochs over the training data
  • optimizer – the optimizer to use to minimize the loss function
  • training_data – the data set providing the training mini batches
  • test_data – the data set providing the test mini batches
  • diff_eq_loss_weight – the weight of the differential equation part of the total physics-informed loss
  • ic_loss_weight – the weight of the initial condition part of the total physics-informed loss
  • bc_loss_weight – the weight of the boundary condition part of the total physics-informed loss
  • verbose – whether loss information should be periodically printed to the console
Returns:

the training and test loss histories

fit_with_lbfgs(training_data: pararealml.operators.ml.pidon.data_set.DataSetIterator, max_iterations: int, gradient_tol: float, test_data: Optional[pararealml.operators.ml.pidon.data_set.DataSetIterator] = None, diff_eq_loss_weight: float = 1.0, ic_loss_weight: float = 1.0, bc_loss_weight: float = 1.0, verbose: bool = True) → Tuple[pararealml.operators.ml.pidon.loss.Loss, Optional[pararealml.operators.ml.pidon.loss.Loss]][source]

Fits the branch and trunk net parameters by minimising the physics-informed loss function over the provided training data set using the L-BFGS optimization method. It also evaluates the loss over both the training data and the test data, if provided, for every epoch.

Parameters:
  • training_data – the data set providing the full training batch
  • max_iterations – the maximum number of iterations to perform the optimization for
  • gradient_tol – the threshold on the gradient vector; if the largest element of the absolute value of the gradient vector is less than this threshold, the optimization is stopped
  • test_data – the data set providing the full test batch
  • diff_eq_loss_weight – the weight of the differential equation part of the total physics-informed loss
  • ic_loss_weight – the weight of the initial condition part of the total physics-informed loss
  • bc_loss_weight – the weight of the boundary condition part of the total physics-informed loss
  • verbose – whether loss information should be periodically printed to the console
Returns:

the training and test loss histories

pararealml.operators.ml.pidon.pidon_operator module

class pararealml.operators.ml.pidon.pidon_operator.DataArgs[source]

Bases: tuple

A container class for arguments pertaining to the generation and traversal of PIDON data sets.

n_batches

Alias for field number 2

n_boundary_points

Alias for field number 3

n_domain_points

Alias for field number 1

n_ic_repeats

Alias for field number 4

shuffle

Alias for field number 5

y_0_functions

Alias for field number 0

class pararealml.operators.ml.pidon.pidon_operator.ModelArgs[source]

Bases: tuple

A container class for arguments pertaining to the architecture of a PIDON model.

branch_activation

Alias for field number 5

branch_hidden_layer_sizes

Alias for field number 1

branch_initialization

Alias for field number 3

latent_output_size

Alias for field number 0

trunk_activation

Alias for field number 6

trunk_hidden_layer_sizes

Alias for field number 2

trunk_initialization

Alias for field number 4

class pararealml.operators.ml.pidon.pidon_operator.OptimizationArgs[source]

Bases: tuple

A container class for arguments pertaining to the training of a PIDON model.

bc_loss_weight

Alias for field number 4

diff_eq_loss_weight

Alias for field number 2

epochs

Alias for field number 1

ic_loss_weight

Alias for field number 3

optimizer

Alias for field number 0

verbose

Alias for field number 5

class pararealml.operators.ml.pidon.pidon_operator.PIDONOperator(sampler: pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPointSampler, d_t: float, vertex_oriented: bool, auto_regression_mode: bool = False)[source]

Bases: pararealml.operator.Operator

A physics-informed DeepONet based unsupervised machine learning operator for solving initial value problems.

auto_regression_mode

Whether the operator functions in auto-regression mode.

model

The physics-informed DeepONet model behind the operator.

solve(ivp: pararealml.initial_value_problem.InitialValueProblem, parallel_enabled: bool = True) → pararealml.solution.Solution[source]

Returns the IVP’s solution.

Parameters:
  • ivp – the initial value problem to solve
  • parallel_enabled – whether in-time parallelization is enabled
Returns:

the solution of the IVP

train(cp: pararealml.constrained_problem.ConstrainedProblem, t_interval: Tuple[float, float], *, training_data_args: pararealml.operators.ml.pidon.pidon_operator.DataArgs, model_args: pararealml.operators.ml.pidon.pidon_operator.ModelArgs, optimization_args: pararealml.operators.ml.pidon.pidon_operator.OptimizationArgs, test_data_args: Optional[pararealml.operators.ml.pidon.pidon_operator.DataArgs] = None, secondary_optimization_args: Optional[pararealml.operators.ml.pidon.pidon_operator.SecondaryOptimizationArgs] = None) → Tuple[Sequence[pararealml.operators.ml.pidon.loss.Loss], Sequence[pararealml.operators.ml.pidon.loss.Loss]][source]

Trains a physics-informed DeepONet model on the provided constrained problem, time interval, and initial condition functions using the model and training arguments. It also saves the trained model to use as the predictor for solving IVPs.

Parameters:
  • cp – the constrained problem to train the operator on
  • t_interval – the time interval to train the operator on
  • training_data_args – the training data generation and batch size arguments
  • model_args – the physics-informed DeepONet model arguments
  • optimization_args – the physics-informed DeepONet model optimization arguments
  • test_data_args – the test data generation and batch size arguments
  • secondary_optimization_args – the physics-informed DeepONet model optimization arguments for fine tuning the model parameters using a (quasi) second order optimization method
Returns:

the training loss history and the test loss history

class pararealml.operators.ml.pidon.pidon_operator.SecondaryOptimizationArgs[source]

Bases: tuple

A container class for arguments pertaining to the training of a PIDON model using a second order optimization method to fine tune the model parameters.

bc_loss_weight

Alias for field number 4

diff_eq_loss_weight

Alias for field number 2

gradient_tol

Alias for field number 1

ic_loss_weight

Alias for field number 3

max_iterations

Alias for field number 0

verbose

Alias for field number 5

pararealml.operators.ml.pidon.pidon_symbol_mapper module

class pararealml.operators.ml.pidon.pidon_symbol_mapper.PIDONSymbolMapArg[source]

Bases: tuple

The arguments to the PIDON map functions.

auto_diff

Alias for field number 0

t

Alias for field number 1

x

Alias for field number 2

y_hat

Alias for field number 3

class pararealml.operators.ml.pidon.pidon_symbol_mapper.PIDONSymbolMapper(cp: pararealml.constrained_problem.ConstrainedProblem)[source]

Bases: pararealml.operators.symbol_mapper.SymbolMapper

A symbol mapper implementation for the PIDON operator.

t_map_function() → Callable[[pararealml.operators.ml.pidon.pidon_symbol_mapper.PIDONSymbolMapArg], tensorflow.python.framework.ops.Tensor][source]

Returns a function for mapping t to a numerical value.

x_map_function(x_axis: int) → Callable[[pararealml.operators.ml.pidon.pidon_symbol_mapper.PIDONSymbolMapArg], tensorflow.python.framework.ops.Tensor][source]

Returns a function for mapping a component of x to a numerical value.

Parameters:x_axis – the component of x to return a map for
Returns:the mapper function for x
y_curl_map_function(y_indices: Sequence[int], indices_contiguous: Union[bool, numpy.bool_], curl_ind: int) → Callable[[pararealml.operators.ml.pidon.pidon_symbol_mapper.PIDONSymbolMapArg], tensorflow.python.framework.ops.Tensor][source]

Returns a function for mapping the curl of a set of components of y to a numerical value.

Parameters:
  • y_indices – the components of y whose curl to return a map for
  • indices_contiguous – whether the indices are contiguous
  • curl_ind – the index of the component of the curl to map
Returns:

the mapper function for the curl of y

y_divergence_map_function(y_indices: Sequence[int], indices_contiguous: Union[bool, numpy.bool_]) → Callable[[pararealml.operators.ml.pidon.pidon_symbol_mapper.PIDONSymbolMapArg], tensorflow.python.framework.ops.Tensor][source]

Returns a function for mapping the divergence of a set of components of y to a numerical value.

Parameters:
  • y_indices – the components of y whose divergence to return a map for
  • indices_contiguous – whether the indices are contiguous
Returns:

the mapper function for the divergence of y

y_gradient_map_function(y_ind: int, x_axis: int) → Callable[source]

Returns a function for mapping a component of the gradient of y to a numerical value.

Parameters:
  • y_ind – the component of y whose gradient to return a map for
  • x_axis – the x-axis denoting the element of the gradient to return a map for
Returns:

the mapper function for the gradient of y

y_hessian_map_function(y_ind: int, x_axis1: int, x_axis2: int) → Callable[[pararealml.operators.ml.pidon.pidon_symbol_mapper.PIDONSymbolMapArg], tensorflow.python.framework.ops.Tensor][source]

Returns a function for mapping a component of the Hessian of y to a numerical value.

Parameters:
  • y_ind – the component of y whose Hessian to return a map for
  • x_axis1 – the first x-axis denoting the element of the gradient to return a map for
  • x_axis2 – the second x-axis denoting the element of the gradient to return a map for
Returns:

the mapper function for the Hessian of y

y_laplacian_map_function(y_ind: int) → Callable[[pararealml.operators.ml.pidon.pidon_symbol_mapper.PIDONSymbolMapArg], tensorflow.python.framework.ops.Tensor][source]

Returns a function for mapping a component of the element-wise scalar Laplacian of y to a numerical value.

Parameters:y_ind – the component of y whose Laplacian to return a mp for
Returns:the mapper function for the Laplacian of y
y_map_function(y_ind: int) → Callable[[pararealml.operators.ml.pidon.pidon_symbol_mapper.PIDONSymbolMapArg], tensorflow.python.framework.ops.Tensor][source]

Returns a function for mapping a component of y to a numerical value.

Parameters:y_ind – the component of y to return a map for
Returns:the mapper function for y
y_vector_laplacian_map_function(y_indices: Sequence[int], indices_contiguous: Union[bool, numpy.bool_], vector_laplacian_ind: int) → Callable[[pararealml.operators.ml.pidon.pidon_symbol_mapper.PIDONSymbolMapArg], tensorflow.python.framework.ops.Tensor][source]

Returns a function for mapping the vector Laplacian of a set of components of y to a numerical value.

Parameters:
  • y_indices – the components of y whose vector Laplacian to return a map for
  • indices_contiguous – whether the indices are contiguous
  • vector_laplacian_ind – the index of the component of the vector Laplacian to map
Returns:

the mapper function for the vector Laplacian of y

Module contents

class pararealml.operators.ml.pidon.AutoDifferentiator(persistent: bool = False, watch_accessed_variables: bool = True)[source]

Bases: tensorflow.python.eager.backprop.GradientTape

A class providing various differential operators using TensorFlow’s auto-differentiation capabilities.

batch_curl(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, curl_ind: int = 0, coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0, )>) → tensorflow.python.framework.ops.Tensor[source]

Returns the curl_ind-th component of the curl of y.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • curl_ind – the index of the component of the curl of y to compute; if y is a two dimensional vector field, it must be 0
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the curl_ind-th component of the curl of y

batch_divergence(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0, )>) → tensorflow.python.framework.ops.Tensor[source]

Returns the divergence of y.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the divergence of y

batch_gradient(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, x_axis: Union[int, tensorflow.python.framework.ops.Tensor], coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0,)>) → tensorflow.python.framework.ops.Tensor[source]

Returns the element(s) of the gradient of y with respect to the element of x defined by x_axis.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • x_axis – the element of x to take the gradient with respect to
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the gradient of y with respect to the element of x defined by x_axis

batch_hessian(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, x_axis1: int, x_axis2: int, coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0, )>) → tensorflow.python.framework.ops.Tensor[source]

Returns the element(s) of the Hessian of y with respect to the elements of x defined by x_axis1 and x_axis2.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • x_axis1 – the first element of x to take the Hessian with respect to
  • x_axis2 – the second element of x to take the Hessian with respect to
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the Hessian of y with respect to the elements of x defined by x_axis1 and x_axis2

batch_laplacian(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0, )>) → tensorflow.python.framework.ops.Tensor[source]

Returns the element-wise scalar Laplacian of y.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the Laplacian of y

batch_vector_laplacian(x: tensorflow.python.framework.ops.Tensor, y: tensorflow.python.framework.ops.Tensor, vector_laplacian_ind: int, coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0, )>) → tensorflow.python.framework.ops.Tensor[source]

Returns the vector Laplacian of y.

Parameters:
  • x – the input tensor
  • y – the output tensor
  • vector_laplacian_ind – the index of the component of the vector Laplacian of y to compute
  • coordinate_system_type – the type of the coordinate system x is from
Returns:

the vector Laplacian of y

class pararealml.operators.ml.pidon.CollocationPointSampler[source]

Bases: abc.ABC

A base class for collocation point samplers.

sample_boundary_points(n_points: int, t_interval: Tuple[float, float], x_intervals: Sequence[Tuple[float, float]]) → Sequence[pararealml.operators.ml.pidon.collocation_point_sampler.AxialBoundaryPoints][source]

Samples a set of points organized into a sequence of pairs from the boundaries of a spatio-temporal domain.

Parameters:
  • n_points – the number of points to sample
  • t_interval – the bounds of the temporal domain
  • x_intervals – a sequence of the bounds of the spatial domain
Returns:

a set of boundary points organized into a sequence of pairs

sample_domain_points(n_points: int, t_interval: Tuple[float, float], x_intervals: Optional[Sequence[Tuple[float, float]]]) → pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPoints[source]

Samples a set of points from a spatio-temporal domain. If the spatial domain intervals are undefined, it only samples from the temporal domain.

Parameters:
  • n_points – the number of points to sample
  • t_interval – the bounds of the temporal domain
  • x_intervals – a sequence of the bounds of the spatial domain
Returns:

a set of domain points

class pararealml.operators.ml.pidon.UniformRandomCollocationPointSampler[source]

Bases: pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPointSampler

A uniform random collocation point sampler.

sample_boundary_points(n_points: int, t_interval: Tuple[float, float], x_intervals: Sequence[Tuple[float, float]]) → Sequence[pararealml.operators.ml.pidon.collocation_point_sampler.AxialBoundaryPoints][source]

Samples a set of points organized into a sequence of pairs from the boundaries of a spatio-temporal domain.

Parameters:
  • n_points – the number of points to sample
  • t_interval – the bounds of the temporal domain
  • x_intervals – a sequence of the bounds of the spatial domain
Returns:

a set of boundary points organized into a sequence of pairs

sample_domain_points(n_points: int, t_interval: Tuple[float, float], x_intervals: Optional[Sequence[Tuple[float, float]]]) → pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPoints[source]

Samples a set of points from a spatio-temporal domain. If the spatial domain intervals are undefined, it only samples from the temporal domain.

Parameters:
  • n_points – the number of points to sample
  • t_interval – the bounds of the temporal domain
  • x_intervals – a sequence of the bounds of the spatial domain
Returns:

a set of domain points

class pararealml.operators.ml.pidon.DataSet(cp: pararealml.constrained_problem.ConstrainedProblem, t_interval: Tuple[float, float], y_0_functions: Iterable[Callable[[Optional[numpy.ndarray]], numpy.ndarray]], point_sampler: pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPointSampler, n_domain_points: int, n_boundary_points: int = 0, vertex_oriented: bool = False)[source]

Bases: object

A generator and container of all the data necessary to train a physics-informed DeepONet with variable initial conditions.

boundary_collocation_data

The boundary collocation data points where the columns represent t, x, y, the derivative of y with respect to the unit normal vector of the boundary, and finally the axis denoting the direction of the normal vector.

constrained_problem

The constrained problem the data set is built around.

domain_collocation_data

The domain collocation data points where the first column is t and all other columns are x.

get_iterator(n_batches: int, n_ic_repeats: int = 1, shuffle: bool = True) → pararealml.operators.ml.pidon.data_set.DataSetIterator[source]

Returns an iterator over the data set to enable iterating over the Cartesian product of the initial value data and the collocation data batch by batch.

Parameters:
  • n_batches – the number of batches to map the underlying data to
  • n_ic_repeats – the number of times to repeat the initial collocation data samples in an epoch
  • shuffle – whether to shuffle the data behind the iterator
Returns:

the iterator over the data set

initial_collocation_data

The initial collocation data points where the first column is t and all other columns are x.

initial_value_data

The initial value data where each row is a different initial condition function and each column represents a component of the initial condition function evaluated over a point of the constrained problem’s mesh.

class pararealml.operators.ml.pidon.Loss[source]

Bases: tuple

A collection of the various losses of a physics-informed DeepONet.

bc_losses

Alias for field number 2

classmethod construct(diff_eq_loss: tensorflow.python.framework.ops.Tensor, ic_loss: tensorflow.python.framework.ops.Tensor, bc_losses: Optional[Tuple[tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor]], diff_eq_loss_weight: float, ic_loss_weight: float, bc_loss_weight: float) → pararealml.operators.ml.pidon.loss.Loss[source]

Calculates the weighted total loss given the weights for the different components of the total loss and returns a Loss instance.

Parameters:
  • diff_eq_loss – the differential equation loss tensor
  • ic_loss – the initial condition loss tensor
  • bc_losses – a tuple of the Dirichlet and Neumann boundary condition loss tensors
  • diff_eq_loss_weight – the weight of the differential equation part of the total physics-informed loss
  • ic_loss_weight – the weight of the initial condition part of the total physics-informed loss
  • bc_loss_weight – the weight of the boundary condition part of the total physics-informed loss
Returns:

the losses including the weighted total

diff_eq_loss

Alias for field number 0

ic_loss

Alias for field number 1

classmethod mean(losses: Sequence[pararealml.operators.ml.pidon.loss.Loss], diff_eq_loss_weight: float, ic_loss_weight: float, bc_loss_weight: float) → pararealml.operators.ml.pidon.loss.Loss[source]

Computes the mean of the provided losses.

Parameters:
  • losses – the losses to average over
  • diff_eq_loss_weight – the weight of the differential equation part of the total physics-informed loss
  • ic_loss_weight – the weight of the initial condition part of the total physics-informed loss
  • bc_loss_weight – the weight of the boundary condition part of the total physics-informed loss
Returns:

the mean loss

weighted_total_loss

Alias for field number 3

class pararealml.operators.ml.pidon.PIDeepONet(cp: pararealml.constrained_problem.ConstrainedProblem, latent_output_size: int, branch_hidden_layer_sizes: Optional[List[int]] = None, trunk_hidden_layer_sizes: Optional[List[int]] = None, branch_initialization: str = 'glorot_uniform', trunk_initialization: str = 'glorot_uniform', branch_activation: Optional[str] = 'tanh', trunk_activation: Optional[str] = 'tanh', vertex_oriented: bool = False)[source]

Bases: pararealml.operators.ml.deeponet.DeepONet

A Physics-Informed DeepONet model.

See: https://arxiv.org/abs/2103.10974

constrained_problem

The constrained problem the model is built around.

fit(epochs: int, optimizer: Union[str, Dict[str, Any], keras.optimizer_v2.optimizer_v2.OptimizerV2], training_data: pararealml.operators.ml.pidon.data_set.DataSetIterator, test_data: Optional[pararealml.operators.ml.pidon.data_set.DataSetIterator] = None, diff_eq_loss_weight: float = 1.0, ic_loss_weight: float = 1.0, bc_loss_weight: float = 1.0, verbose: bool = True) → Tuple[List[pararealml.operators.ml.pidon.loss.Loss], List[pararealml.operators.ml.pidon.loss.Loss]][source]

Fits the branch and trunk net parameters by minimising the physics-informed loss function over the provided training data set. It also evaluates the loss over both the training data and the test data, if provided, for every epoch.

Parameters:
  • epochs – the number of epochs over the training data
  • optimizer – the optimizer to use to minimize the loss function
  • training_data – the data set providing the training mini batches
  • test_data – the data set providing the test mini batches
  • diff_eq_loss_weight – the weight of the differential equation part of the total physics-informed loss
  • ic_loss_weight – the weight of the initial condition part of the total physics-informed loss
  • bc_loss_weight – the weight of the boundary condition part of the total physics-informed loss
  • verbose – whether loss information should be periodically printed to the console
Returns:

the training and test loss histories

fit_with_lbfgs(training_data: pararealml.operators.ml.pidon.data_set.DataSetIterator, max_iterations: int, gradient_tol: float, test_data: Optional[pararealml.operators.ml.pidon.data_set.DataSetIterator] = None, diff_eq_loss_weight: float = 1.0, ic_loss_weight: float = 1.0, bc_loss_weight: float = 1.0, verbose: bool = True) → Tuple[pararealml.operators.ml.pidon.loss.Loss, Optional[pararealml.operators.ml.pidon.loss.Loss]][source]

Fits the branch and trunk net parameters by minimising the physics-informed loss function over the provided training data set using the L-BFGS optimization method. It also evaluates the loss over both the training data and the test data, if provided, for every epoch.

Parameters:
  • training_data – the data set providing the full training batch
  • max_iterations – the maximum number of iterations to perform the optimization for
  • gradient_tol – the threshold on the gradient vector; if the largest element of the absolute value of the gradient vector is less than this threshold, the optimization is stopped
  • test_data – the data set providing the full test batch
  • diff_eq_loss_weight – the weight of the differential equation part of the total physics-informed loss
  • ic_loss_weight – the weight of the initial condition part of the total physics-informed loss
  • bc_loss_weight – the weight of the boundary condition part of the total physics-informed loss
  • verbose – whether loss information should be periodically printed to the console
Returns:

the training and test loss histories

class pararealml.operators.ml.pidon.DataArgs[source]

Bases: tuple

A container class for arguments pertaining to the generation and traversal of PIDON data sets.

n_batches

Alias for field number 2

n_boundary_points

Alias for field number 3

n_domain_points

Alias for field number 1

n_ic_repeats

Alias for field number 4

shuffle

Alias for field number 5

y_0_functions

Alias for field number 0

class pararealml.operators.ml.pidon.ModelArgs[source]

Bases: tuple

A container class for arguments pertaining to the architecture of a PIDON model.

branch_activation

Alias for field number 5

branch_hidden_layer_sizes

Alias for field number 1

branch_initialization

Alias for field number 3

latent_output_size

Alias for field number 0

trunk_activation

Alias for field number 6

trunk_hidden_layer_sizes

Alias for field number 2

trunk_initialization

Alias for field number 4

class pararealml.operators.ml.pidon.OptimizationArgs[source]

Bases: tuple

A container class for arguments pertaining to the training of a PIDON model.

bc_loss_weight

Alias for field number 4

diff_eq_loss_weight

Alias for field number 2

epochs

Alias for field number 1

ic_loss_weight

Alias for field number 3

optimizer

Alias for field number 0

verbose

Alias for field number 5

class pararealml.operators.ml.pidon.SecondaryOptimizationArgs[source]

Bases: tuple

A container class for arguments pertaining to the training of a PIDON model using a second order optimization method to fine tune the model parameters.

bc_loss_weight

Alias for field number 4

diff_eq_loss_weight

Alias for field number 2

gradient_tol

Alias for field number 1

ic_loss_weight

Alias for field number 3

max_iterations

Alias for field number 0

verbose

Alias for field number 5

class pararealml.operators.ml.pidon.PIDONOperator(sampler: pararealml.operators.ml.pidon.collocation_point_sampler.CollocationPointSampler, d_t: float, vertex_oriented: bool, auto_regression_mode: bool = False)[source]

Bases: pararealml.operator.Operator

A physics-informed DeepONet based unsupervised machine learning operator for solving initial value problems.

auto_regression_mode

Whether the operator functions in auto-regression mode.

model

The physics-informed DeepONet model behind the operator.

solve(ivp: pararealml.initial_value_problem.InitialValueProblem, parallel_enabled: bool = True) → pararealml.solution.Solution[source]

Returns the IVP’s solution.

Parameters:
  • ivp – the initial value problem to solve
  • parallel_enabled – whether in-time parallelization is enabled
Returns:

the solution of the IVP

train(cp: pararealml.constrained_problem.ConstrainedProblem, t_interval: Tuple[float, float], *, training_data_args: pararealml.operators.ml.pidon.pidon_operator.DataArgs, model_args: pararealml.operators.ml.pidon.pidon_operator.ModelArgs, optimization_args: pararealml.operators.ml.pidon.pidon_operator.OptimizationArgs, test_data_args: Optional[pararealml.operators.ml.pidon.pidon_operator.DataArgs] = None, secondary_optimization_args: Optional[pararealml.operators.ml.pidon.pidon_operator.SecondaryOptimizationArgs] = None) → Tuple[Sequence[pararealml.operators.ml.pidon.loss.Loss], Sequence[pararealml.operators.ml.pidon.loss.Loss]][source]

Trains a physics-informed DeepONet model on the provided constrained problem, time interval, and initial condition functions using the model and training arguments. It also saves the trained model to use as the predictor for solving IVPs.

Parameters:
  • cp – the constrained problem to train the operator on
  • t_interval – the time interval to train the operator on
  • training_data_args – the training data generation and batch size arguments
  • model_args – the physics-informed DeepONet model arguments
  • optimization_args – the physics-informed DeepONet model optimization arguments
  • test_data_args – the test data generation and batch size arguments
  • secondary_optimization_args – the physics-informed DeepONet model optimization arguments for fine tuning the model parameters using a (quasi) second order optimization method
Returns:

the training loss history and the test loss history