Skip to content

anypinn.core.types

Core type aliases, constants, and protocols for PINN.

Activations: TypeAlias = Literal['tanh', 'relu', 'leaky_relu', 'sigmoid', 'selu', 'softplus', 'identity'] module-attribute

Supported activation functions.

CollocationStrategies: TypeAlias = Literal['uniform', 'random', 'latin_hypercube', 'log_uniform_1d', 'adaptive'] module-attribute

Supported collocation sampling strategies.

Criteria: TypeAlias = Literal['mse', 'huber', 'l1'] module-attribute

Supported loss criteria.

DataBatch: TypeAlias = tuple[Tensor, Tensor] module-attribute

Type alias for data batch: (x, y).

LOSS_KEY = 'loss' module-attribute

Key used for logging the total loss.

PredictionBatch: TypeAlias = tuple[Tensor, Tensor] module-attribute

Prediction batch tuple: (x_data, y_data).

Predictions: TypeAlias = tuple[DataBatch, dict[str, Tensor], dict[str, Tensor] | None] module-attribute

Type alias for model predictions: (input_batch, predictions_dictionary, true_values_dictionary) where predictions_dictionary is a dictionary of {[field_name | param_name]: prediction} and where true_values_dictionary is a dictionary of {[field_name | param_name]: true_value}. If no validation source is configured, true_values_dictionary is None.

TrainingBatch: TypeAlias = tuple[DataBatch, Tensor] module-attribute

Training batch tuple: ((x_data, y_data), x_coll).

LogFn

Bases: Protocol

A function that logs a value to a dictionary.

Source code in src/anypinn/core/types.py
class LogFn(Protocol):
    """
    A function that logs a value to a dictionary.
    """

    def __call__(self, name: str, value: Tensor, progress_bar: bool = False) -> None:
        """
        Log a value.

        Args:
            name: The name to log the value under.
            value: The value to log.
            progress_bar: Whether the value should be logged to the progress bar.
        """
        ...

__call__(name: str, value: Tensor, progress_bar: bool = False) -> None

Log a value.

Parameters:

Name Type Description Default
name str

The name to log the value under.

required
value Tensor

The value to log.

required
progress_bar bool

Whether the value should be logged to the progress bar.

False
Source code in src/anypinn/core/types.py
def __call__(self, name: str, value: Tensor, progress_bar: bool = False) -> None:
    """
    Log a value.

    Args:
        name: The name to log the value under.
        value: The value to log.
        progress_bar: Whether the value should be logged to the progress bar.
    """
    ...