Condition Interface#

Module for the Condition interface.

class ConditionInterface[source]#

Bases: object

Abstract interface for all conditions.

Refer to pina.condition.condition.Condition for a thorough description of all available conditions and how to instantiate them.

abstract store_data(**kwargs)[source]#

Store the data for the condition in a suitable format.

Parameters:

kwargs (dict) – The keyword arguments containing the data to be stored.

Returns:

The stored data in a suitable format.

Return type:

Any

abstract create_dataloader(dataset, batch_size, automatic_batching, **kwargs)[source]#

Create the DataLoader for the condition.

Parameters:
  • dataset (_ConditionSubset) – The dataset for the DataLoader.

  • batch_size (int) – The batch size for the DataLoader.

  • automatic_batching (bool) – Whether to use automatic batching.

  • kwargs (dict) – Additional keyword arguments for the DataLoader.

Returns:

The DataLoader for the condition.

Return type:

torch.utils.data.DataLoader

abstract evaluate(batch, solver)[source]#

Evaluate the residual of the condition on the given batch using the solver.

This method computes the non-aggregated, element-wise residual of the condition. A forward pass of the solver’s model is performed on the input samples, and the condition residual is evaluated accordingly.

The returned tensor is not reduced, preserving the per-sample residual values.

Parameters:
  • batch (dict) – The batch containing the data required by the condition evaluation.

  • solver (BaseSolver) – The solver used to perform the forward pass and compute the residual. The solver provides access to the model and its parameters, which may be necessary for evaluating the condition residual.

Returns:

The non-aggregated residual tensor.

Return type:

torch.Tensor | LabelTensor

abstract switch_dataloader_fn(create_dataloader_fn)[source]#

Switch the dataloader function for the condition.

Parameters:

create_dataloader_fn (Callable) – The new dataloader function to use for the condition.

Returns:

The new dataloader function for the condition.

Return type:

Callable

abstract classmethod automatic_batching_collate_fn(batch)[source]#

Collate function for automatic batching to be used in the DataLoader.

Parameters:

batch (list) – A list of items from the dataset.

Returns:

A collated batch.

Return type:

dict

abstract static collate_fn(batch, condition)[source]#

Collate function for custom batching to be used in the DataLoader.

Parameters:
  • batch (list) – A list of items from the dataset.

  • condition (BaseCondition) – The condition instance.

Returns:

A collated batch.

Return type:

dict

abstract property problem#

The problem associated with this condition.

Returns:

The problem associated with this condition.

Return type:

BaseProblem