qewton.graphs.pipelines package

Module contents

Pipelines

Predefined graph templates for common tasks. A pipeline is a qewton.graphs.Graph subclass that builds its nodes and connections in its constructor and is then used like any other graph.

Public API

  • PINNPipeline: Connects a sampler (any DataNode), one or more models and a physics constraint for PINN training. It splits and joins the sampled variables as needed by the models and the constraint (matched by variable name), and adds gradient tracking for every sampled variable a model uses, so the constraint can differentiate the model outputs.

Usage

from qewton.constraints import PINNConstraint
from qewton.graphs.pipelines import PINNPipeline

def residual(u: U, f: F, x: X):
    return u.gradient(x) - f

constraint = PINNConstraint(residual)
pipeline = PINNPipeline(data_loader, [model], constraint)
pipeline.setup()

The pipeline and its constraint are then passed to a trainer, e.g. GraphBasedTrainer(graphs=[pipeline], training_objectives=[constraint], ...).

Submodules

qewton.graphs.pipelines.data_pipeline module

qewton.graphs.pipelines.pinn_pipeline module

Graph template wiring a sampler, models and a physics constraint into a PINN training pipeline.

class qewton.graphs.pipelines.pinn_pipeline.PINNPipeline(sampler: ~qewton.data.dataloaders.base.DataNode, models: list[~qewton.graphs.nodes.Node], constraint: ~qewton.constraints.base.Constraint | None = None, residual: ~typing.Callable | None = None, residual_name: str | None = None, track_residual: bool = True, reduction: ~typing.Callable | None = None, weight=1.0, backend=<class 'qewton.backends.base.DeepLearningBackend'>)[source]

Bases: Graph

Graph connecting a sampler, models and a constraint for PINN training.

The output variables of sampler are split and joined as needed by the models and the constraint, and every sampled variable a model uses passes through a GradientTracking node, so the constraint can differentiate the model outputs with respect to it. Constraint inputs are taken from the sampler outputs and the model outputs. Variables are matched by leaf name. A variable is only split where a consumer needs a finer part of it.

Models (which can also be single parameters) are evaluated independently; a model cannot depend on the output of another model.

Parameters:
  • sampler – The data node providing the input points.

  • models – The models to train.

  • constraint – The physics constraint to train. None (default) builds a PINNConstraint from residual.

  • residual – The residual function of the constraint built when constraint is None.

  • residual_name – The name of the built constraint. None (default) uses the name of the residual function.

  • track_residual – Passed to the built constraint.

  • reduction – The reduction of the built constraint.

  • weight (float, optional) – The weight of the built constraint. Default is 1.0.

  • backend (type[Backend], optional) – The backend of the built constraint. Default is DEFAULT_DL_BACKEND.

Raises:
  • AssertionError – If neither constraint nor residual is given.

  • ValueError – If a variable needed by a model or the constraint is not provided by the sampler or the models.

constraint

The given or built constraint.

Type:

Constraint

get_variables(port, dynamic=False)[source]

Return the variables of the data configuration of port.

Parameters:
  • port (Port) – The port to read.

  • dynamic (bool, optional) – Whether to read the configuration of port in this graph instead of its static one. Default is False.

Returns:

The (composed) variable of the configuration.

Return type:

Variable

split_and_join(from_ports, to_vars, use_dynamic_data_configs=False) → list[OutputPort][source]

Provide one output port per variable in to_vars from from_ports.

A port of from_ports is only split (with SplitVariables) where some variable of to_vars needs a finer part of it; otherwise it is used directly. Pieces are joined (with ConcatVariables) only where a variable of to_vars spans more than one of them. The created nodes are connected in this graph.

Parameters:
  • from_ports (list[OutputPort]) – The ports providing the data.

  • to_vars (list[Variable]) – The variables to provide, matched to from_ports by leaf name.

  • use_dynamic_data_configs (bool, optional) – Whether to read the variables of from_ports from their configurations in this graph instead of the static ones. Default is False.

Returns:

For each variable in to_vars, the port

providing it.

Return type:

list[OutputPort]

Raises:

ValueError – If a variable of to_vars needs a leaf not provided by from_ports.