Base Problem#

Module for the BaseProblem class.

class BaseProblem[source]#

Bases: ProblemInterface

Base class for all problems, implementing common functionality.

A problem is defined by core components, including input and output variables, a set of conditions to be satisfied, and optionally the domains on which these conditions are defined.

All problems must inherit from this class and implement abstract methods defined in ProblemInterface.

This class is not meant to be instantiated directly.

Initialization of the BaseProblem class.

discretise_domain(n=None, mode='random', domains=None, sample_rules=None)[source]#

Discretise the problem’s domains by sampling a specified number of points according to the selected sampling mode.

Parameters:
  • n (int) – The number of points to sample. This is ignored if sample_rules is provided. Default is None.

  • mode (str) – The sampling method. Available modes include: "random" for random sampling, "latin" or "lh" for latin hypercube sampling, "chebyshev" for Chebyshev sampling, and "grid" for grid sampling. Default is "random".

  • domains (str | list[str]) – The domains from which to sample. If None, all domains are considered for sampling. Default is None.

  • sample_rules (dict) – The dictionary specifying custom sampling rules for each input variable. When provided, it overrides the global n and mode arguments. Each key in the dictionary must match one of the variables defined in input_variables(), and each value must be a dictionary containing two keys: n for the number of points to sample for that variable, and mode for the sampling method to use. If None, the global n and mode parameters are used for all variables. Default is None.

Raises:
  • ValueError – If sample_rules is provided but it is not a dictionary.

  • ValueError – If sample_rules is provided but its keys do not match the input variables of the problem.

  • ValueError – If sample_rules is provided but any of its rules is not a dictionary containing both n and mode keys, with n being a positive integer and mode being a string.

  • AssertionError – If n is not a positive integer.

  • ValueError – If mode is not a string

  • ValueError – If domains is provided by it is neither a string nor a list of strings.

Warning

"random" is the only supported mode across all geometries: CartesianDomain, EllipsoidDomain, and SimplexDomain. Sampling modes such as "latin", "chebyshev", and "grid" are only implemented for CartesianDomain. When custom discretisation is specified via sample_rules, the domain to be discretised must be an instance of CartesianDomain.

Example:
>>> problem.discretise_domain(n=10, mode="random")
>>> problem.discretise_domain(n=10, mode="lh", domains=["boundary"])
>>> problem.discretise_domain(
...     sample_rules={
...         'x': {'n': 10, 'mode': 'grid'},
...         'y': {'n': 100, 'mode': 'grid'}
...     },
... )
add_points(new_points_dict)[source]#

Append additional points to an already discretised domain.

Parameters:

new_points_dict (dict) – The dictionary mapping each domain to the corresponding set of new points to be added. Each key in the dictionary must match one of the domains defined in domains, and each value must be a LabelTensor containing the new points to be added to that domain. The labels of the points to be added must correspond to those of the domain to which they are being added.

Raises:
  • ValueError – If new_points_dict is not a dictionary.

  • ValueError – If any of the values in new_points_dict is not a LabelTensor.

  • ValueError – If any of the keys in new_points_dict does not match any of the domains defined in domains.

  • ValueError – If any of the domains in new_points_dict has not been discretised yet.

Example:
>>> additional_points = {
...     "boundary": LabelTensor(torch.rand(5, 2), labels=["x", "y"])
... }
>>> problem.add_points(additional_points)
move_discretisation_into_conditions()[source]#

Move the sampled points from the discretised domains into their corresponding conditions. This ensures that the conditions are evaluated on the correct set of points after discretisation.

property input_variables#

The input variables of the problem.

Returns:

The input variables of the problem.

Return type:

list[str]

property discretised_domains#

The dictionary containing the discretised domains of the problem. Each key corresponds to a domain defined in domains, and each value is a LabelTensor containing the sampled points for that domain.

Returns:

The discretised domains.

Return type:

dict

property are_all_domains_discretised#

Whether all domains of the problem have been discretised.

Returns:

True if all domains are discretised, False otherwise.

Return type:

bool