phlower.nn.EdgeDifference

class phlower.nn.EdgeDifference(support_name, with_norm=False, nodes=None)[source]

Bases: IGenericPhlowerCoreModule[IPhlowerLayerParameters, PhlowerTensor], Module

EdgeDifference computes the difference between the nodal features of the two endpoints of each edge: e_k = h_j - h_i for the k-th edge (i, j). Self-loop edges are ignored.

input: ([t,] n_nodes, …, f) output: ([t,] n_edges, …, f) t is optional.

When with_norm is True, the L2 norm of the difference is concatenated to the output, which then has shape ([t,] n_edges, f + 1).

Applied to node positions, this yields the relative position and distance edge features used in MeshGraphNets.

Parameters:
  • support_name (str) – Name of the support tensor defining the edges.

  • with_norm (bool) – Whether to concatenate the L2 norm of the difference to the output. Only available for rank-0 tensors. Defaults to False.

  • nodes (list[int] | None)

Examples

>>> edge_difference = EdgeDifference(
...     support_name="support", with_norm=True
... )
>>> edge_difference(data, field_data=field_data)

Methods

forward(data, *, field_data, **kwards)

forward function which overloads torch.nn.Module

from_setting(setting)

Create EdgeDifference from setting object

get_nn_name()

Return neural network name

Attributes

T_destination

call_super_init

dump_patches

training

forward(data, *, field_data, **kwards)[source]

forward function which overloads torch.nn.Module

Parameters:
  • data (IPhlowerTensorCollections) – IPhlowerTensorCollections data which receives from predecessors

  • field_data (ISimulationField) – ISimulationField | None Constant information through training or prediction

Returns:

Tensor object

Return type:

PhlowerTensor

classmethod from_setting(setting)[source]

Create EdgeDifference from setting object

Parameters:

setting (EdgeDifferenceSetting) – setting object

Returns:

EdgeDifference object

Return type:

EdgeDifference

classmethod get_nn_name()[source]

Return neural network name

Returns:

name

Return type:

str