fix rendering part 1

This commit is contained in:
giovanni
2025-03-13 22:31:26 +01:00
committed by Nicola Demo
parent 5d908a291d
commit e0ad4dc8a0
15 changed files with 89 additions and 63 deletions

View File

@@ -23,11 +23,11 @@ class Difference(OperationInterface):
Initialization of the :class:`Difference` class. Initialization of the :class:`Difference` class.
:param list[DomainInterface] geometries: A list of instances of the :param list[DomainInterface] geometries: A list of instances of the
:class:`~pina.domain.DomainInterface` class on which the difference :class:`~pina.domain.domain_interface.DomainInterface` class on
operation is performed. The first domain in the list serves as the which the difference operation is performed. The first domain in the
base from which points are sampled, while the remaining domains list serves as the base from which points are sampled, while the
define the regions to be excluded from the base domain to compute remaining domains define the regions to be excluded from the base
the difference. domain to compute the difference.
:Example: :Example:
>>> # Create two ellipsoid domains >>> # Create two ellipsoid domains

View File

@@ -26,14 +26,14 @@ class EllipsoidDomain(DomainInterface):
.. warning:: .. warning::
Sampling for dimensions greater or equal to 10 could result in a Sampling for dimensions greater or equal to 10 could result in a
shrinkage of the ellipsoid, which degrades the quality of the shrinkage of the ellipsoid, which degrades the quality of the
samples. For dimensions higher than 10, use other sampling samples. For dimensions higher than 10, see the following reference.
algorithms.
.. seealso:: .. seealso::
**Original reference**: Dezert, Jean, and Musso, Christian. **Original reference**: Dezert, Jean, and Musso, Christian.
*An efficient method for generating points uniformly distributed *An efficient method for generating points uniformly distributed
in hyperellipsoids.* in hyperellipsoids.*
Proceedings of the Workshop on Estimation, Tracking and Fusion: Proceedings of the Workshop on Estimation, Tracking and Fusion:
A Tribute to Yaakov Bar-Shalom. 2001. A Tribute to Yaakov Bar-Shalom. 2001.
:Example: :Example:
>>> spatial_domain = Ellipsoid({'x':[-1, 1], 'y':[-1,1]}) >>> spatial_domain = Ellipsoid({'x':[-1, 1], 'y':[-1,1]})

View File

@@ -25,8 +25,8 @@ class Exclusion(OperationInterface):
Initialization of the :class:`Exclusion` class. Initialization of the :class:`Exclusion` class.
:param list[DomainInterface] geometries: A list of instances of the :param list[DomainInterface] geometries: A list of instances of the
:class:`~pina.domain.DomainInterface` class on which the exclusion :class:`~pina.domain.domain_interface.DomainInterface` class on
operation is performed. which the exclusion operation is performed.
:Example: :Example:
>>> # Create two ellipsoid domains >>> # Create two ellipsoid domains

View File

@@ -24,8 +24,8 @@ class Intersection(OperationInterface):
Initialization of the :class:`Intersection` class. Initialization of the :class:`Intersection` class.
:param list[DomainInterface] geometries: A list of instances of the :param list[DomainInterface] geometries: A list of instances of the
:class:`~pina.domain.DomainInterface` class on which the :class:`~pina.domain.domain_interface.DomainInterface` class on
intersection operation is performed. which the intersection operation is performed.
:Example: :Example:
>>> # Create two ellipsoid domains >>> # Create two ellipsoid domains

View File

@@ -15,8 +15,8 @@ class OperationInterface(DomainInterface, metaclass=ABCMeta):
Initialization of the :class:`OperationInterface` class. Initialization of the :class:`OperationInterface` class.
:param list[DomainInterface] geometries: A list of instances of the :param list[DomainInterface] geometries: A list of instances of the
:class:`~pina.domain.DomainInterface` class on which the set :class:`~pina.domain.domain_interface.DomainInterface` class on
operation is performed. which the set operation is performed.
""" """
# check consistency geometries # check consistency geometries
check_consistency(geometries, DomainInterface) check_consistency(geometries, DomainInterface)

View File

@@ -23,8 +23,8 @@ class Union(OperationInterface):
Initialization of the :class:`Union` class. Initialization of the :class:`Union` class.
:param list[DomainInterface] geometries: A list of instances of the :param list[DomainInterface] geometries: A list of instances of the
:class:`~pina.domain.DomainInterface` class on which the union :class:`~pina.domain.domain_interface.DomainInterface` class on
operation is performed. which the union operation is performed.
:Example: :Example:
>>> # Create two ellipsoid domains >>> # Create two ellipsoid domains

View File

@@ -6,8 +6,9 @@ from .equation_interface import EquationInterface
class Equation(EquationInterface): class Equation(EquationInterface):
""" """
Implementation of the Equation class. Every ``equation`` passed to a Implementation of the Equation class. Every ``equation`` passed to a
:class:`~pina.condition.Condition` object must be either a :class:`Equation` :class:`~pina.condition.condition.Condition` object must be either an
or a :class:`~pina.equation.SystemEquation` instance. instance of :class:`Equation` or
:class:`~pina.equation.system_equation.SystemEquation`.
""" """
def __init__(self, equation): def __init__(self, equation):
@@ -32,10 +33,11 @@ class Equation(EquationInterface):
:param LabelTensor input_: Input points where the equation is evaluated. :param LabelTensor input_: Input points where the equation is evaluated.
:param LabelTensor output_: Output tensor, eventually produced by a :param LabelTensor output_: Output tensor, eventually produced by a
:class:`~torch.nn.Module` instance. :class:`torch.nn.Module` instance.
:param dict params_: Dictionary of unknown parameters, associated with a :param dict params_: Dictionary of unknown parameters, associated with a
:class:`~pina.problem.InverseProblem` instance. If the equation is :class:`~pina.problem.inverse_problem.InverseProblem` instance.
not related to a :class:`~pina.problem.InverseProblem` instance, the If the equation is not related to a
:class:`~pina.problem.inverse_problem.InverseProblem` instance, the
parameters must be initialized to ``None``. Default is ``None``. parameters must be initialized to ``None``. Default is ``None``.
:return: The computed residual of the equation. :return: The computed residual of the equation.
:rtype: LabelTensor :rtype: LabelTensor

View File

@@ -28,7 +28,7 @@ class FixedValue(Equation):
:param LabelTensor input_: Input points where the equation is :param LabelTensor input_: Input points where the equation is
evaluated. evaluated.
:param LabelTensor output_: Output tensor, eventually produced by a :param LabelTensor output_: Output tensor, eventually produced by a
:class:`~torch.nn.Module` instance. :class:`torch.nn.Module` instance.
:return: The computed residual of the equation. :return: The computed residual of the equation.
:rtype: LabelTensor :rtype: LabelTensor
""" """
@@ -66,7 +66,7 @@ class FixedGradient(Equation):
:param LabelTensor input_: Input points where the equation is :param LabelTensor input_: Input points where the equation is
evaluated. evaluated.
:param LabelTensor output_: Output tensor, eventually produced by a :param LabelTensor output_: Output tensor, eventually produced by a
:class:`~torch.nn.Module` instance. :class:`torch.nn.Module` instance.
:return: The computed residual of the equation. :return: The computed residual of the equation.
:rtype: LabelTensor :rtype: LabelTensor
""" """
@@ -101,7 +101,7 @@ class FixedFlux(Equation):
:param LabelTensor input_: Input points where the equation is :param LabelTensor input_: Input points where the equation is
evaluated. evaluated.
:param LabelTensor output_: Output tensor, eventually produced by a :param LabelTensor output_: Output tensor, eventually produced by a
:class:`~torch.nn.Module` instance. :class:`torch.nn.Module` instance.
:return: The computed residual of the equation. :return: The computed residual of the equation.
:rtype: LabelTensor :rtype: LabelTensor
""" """
@@ -136,7 +136,7 @@ class Laplace(Equation):
:param LabelTensor input_: Input points where the equation is :param LabelTensor input_: Input points where the equation is
evaluated. evaluated.
:param LabelTensor output_: Output tensor, eventually produced by a :param LabelTensor output_: Output tensor, eventually produced by a
:class:`~torch.nn.Module` instance. :class:`torch.nn.Module` instance.
:return: The computed residual of the equation. :return: The computed residual of the equation.
:rtype: LabelTensor :rtype: LabelTensor
""" """

View File

@@ -6,6 +6,18 @@ from abc import ABCMeta, abstractmethod
class EquationInterface(metaclass=ABCMeta): class EquationInterface(metaclass=ABCMeta):
""" """
Abstract base class for equations. Abstract base class for equations.
Equations in PINA simplify the training process. When defining a problem,
each equation passed to a :class:`~pina.condition.condition.Condition`
object must be either an :class:`~pina.equation.equation.Equation` or a
:class:`~pina.equation.system_equation.SystemEquation` instance.
An :class:`~pina.equation.equation.Equation` is a wrapper for a callable
function, while :class:`~pina.equation.system_equation.SystemEquation`
wraps a list of callable functions. To streamline code writing, PINA
provides a diverse set of pre-implemented equations, such as
:class:`~pina.equation.equation_factory.FixedValue`,
:class:`~pina.equation.equation_factory.FixedGradient`, and many others.
""" """
@abstractmethod @abstractmethod
@@ -15,9 +27,9 @@ class EquationInterface(metaclass=ABCMeta):
:param LabelTensor input_: Input points where the equation is evaluated. :param LabelTensor input_: Input points where the equation is evaluated.
:param LabelTensor output_: Output tensor, eventually produced by a :param LabelTensor output_: Output tensor, eventually produced by a
:class:`~torch.nn.Module` instance. :class:`torch.nn.Module` instance.
:param dict params_: Dictionary of unknown parameters, associated with a :param dict params_: Dictionary of unknown parameters, associated with a
:class:`~pina.problem.InverseProblem` instance. :class:`~pina.problem.inverse_problem.InverseProblem` instance.
:return: The computed residual of the equation. :return: The computed residual of the equation.
:rtype: LabelTensor :rtype: LabelTensor
""" """

View File

@@ -9,8 +9,9 @@ from ..utils import check_consistency
class SystemEquation(EquationInterface): class SystemEquation(EquationInterface):
""" """
Implementation of the System of Equations. Every ``equation`` passed to a Implementation of the System of Equations. Every ``equation`` passed to a
:class:`~pina.condition.Condition` object must be either a :class:`Equation` :class:`~pina.condition.condition.Condition` object must be either a
or a :class:`~pina.equation.SystemEquation` instance. :class:`~pina.equation.equation.Equation` or a
:class:`~pina.equation.system_equation.SystemEquation` instance.
""" """
def __init__(self, list_equation, reduction=None): def __init__(self, list_equation, reduction=None):
@@ -56,10 +57,11 @@ class SystemEquation(EquationInterface):
:param LabelTensor input_: Input points where each equation of the :param LabelTensor input_: Input points where each equation of the
system is evaluated. system is evaluated.
:param LabelTensor output_: Output tensor, eventually produced by a :param LabelTensor output_: Output tensor, eventually produced by a
:class:`~torch.nn.Module` instance. :class:`torch.nn.Module` instance.
:param dict params_: Dictionary of unknown parameters, associated with a :param dict params_: Dictionary of unknown parameters, associated with a
:class:`~pina.problem.InverseProblem` instance. If the equation is :class:`~pina.problem.inverse_problem.InverseProblem` instance.
not related to a :class:`~pina.problem.InverseProblem` instance, the If the equation is not related to a
:class:`~pina.problem.inverse_problem.InverseProblem` instance, the
parameters must be initialized to ``None``. Default is ``None``. parameters must be initialized to ``None``. Default is ``None``.
:return: The aggregated residuals of the system of equations. :return: The aggregated residuals of the system of equations.

View File

@@ -15,8 +15,8 @@ class TorchOptimizer(Optimizer):
""" """
Initialization of the :class:`TorchOptimizer` class. Initialization of the :class:`TorchOptimizer` class.
:param torch.optim.Optimizer optimizer_class: The PyTorch optimizer :param torch.optim.Optimizer optimizer_class: A
class. :class:`torch.optim.Optimizer` class.
:param dict kwargs: Additional parameters passed to `optimizer_class`, :param dict kwargs: Additional parameters passed to `optimizer_class`,
see more: <https://pytorch.org/docs/stable/optim.html#algorithms>_. see more: <https://pytorch.org/docs/stable/optim.html#algorithms>_.
""" """

View File

@@ -21,8 +21,8 @@ class TorchScheduler(Scheduler):
""" """
Initialization of the :class:`TorchScheduler` class. Initialization of the :class:`TorchScheduler` class.
:param torch.optim.LRScheduler scheduler_class: The PyTorch scheduler :param torch.optim.LRScheduler scheduler_class: A
class. :class:`torch.optim.LRScheduler` class.
:param dict kwargs: Additional parameters passed to `scheduler_class`, :param dict kwargs: Additional parameters passed to `scheduler_class`,
see more: <https://pytorch.org/docs/stable/optim.html#algorithms>_. see more: <https://pytorch.org/docs/stable/optim.html#algorithms>_.
""" """

View File

@@ -188,11 +188,15 @@ class AbstractProblem(metaclass=ABCMeta):
.. warning:: .. warning::
``random`` is currently the only implemented ``mode`` for all ``random`` is currently the only implemented ``mode`` for all
geometries, i.e. ``EllipsoidDomain``, ``CartesianDomain``, geometries, i.e. :class:`~pina.domain.ellipsoid.EllipsoidDomain`,
``SimplexDomain``, and geometry compositions ``Union``, :class:`~pina.domain.cartesian.CartesianDomain`,
``Difference``, ``Exclusion``, ``Intersection``. The :class:`~pina.domain.simplex.SimplexDomain`, and geometry
modes ``latin`` or ``lh``, ``chebyshev``, ``grid`` are only compositions :class:`~pina.domain.union_domain.Union`,
implemented for ``CartesianDomain``. :class:`~pina.domain.difference_domain.Difference`,
:class:`~pina.domain.exclusion_domain.Exclusion`, and
:class:`~pina.domain.intersection_domain.Intersection`.
The modes ``latin`` or ``lh``, ``chebyshev``, ``grid`` are only
implemented for :class:`~pina.domain.cartesian.CartesianDomain`.
""" """
# check consistecy n, mode, variables, locations # check consistecy n, mode, variables, locations

View File

@@ -34,8 +34,9 @@ class Trainer(lightning.pytorch.Trainer):
""" """
Initialization of the :class:`Trainer` class. Initialization of the :class:`Trainer` class.
:param SolverInterface solver: A :class:`~pina.solver.SolverInterface` :param SolverInterface solver: A
solver used to solve a :class:`~pina.problem.AbstractProblem`. :class:`~pina.solver.solver.SolverInterface` solver used to solve a
:class:`~pina.problem.abstract_problem.AbstractProblem`.
:param int batch_size: The number of samples per batch to load. :param int batch_size: The number of samples per batch to load.
If ``None``, all samples are loaded and data is not batched. If ``None``, all samples are loaded and data is not batched.
Default is ``None``. Default is ``None``.
@@ -56,11 +57,10 @@ class Trainer(lightning.pytorch.Trainer):
transfer to GPU. Default is ``False``. transfer to GPU. Default is ``False``.
:param bool shuffle: Whether to shuffle the data during training. :param bool shuffle: Whether to shuffle the data during training.
Default is ``True``. Default is ``True``.
:param dict kwargs: Additional keyword arguments that specify the
:Keyword Arguments: training setup. These can be selected from the `pytorch-lightning
Additional keyword arguments that specify the training setup. Trainer API
These can be selected from the pytorch-lightning Trainer API <https://lightning.ai/docs/pytorch/stable/common/trainer.html#trainer-class-api>`_.
<https://lightning.ai/docs/pytorch/stable/common/trainer.html#trainer-class-api>_.
""" """
# check consistency for init types # check consistency for init types
self._check_input_consistency( self._check_input_consistency(
@@ -132,7 +132,8 @@ class Trainer(lightning.pytorch.Trainer):
def _move_to_device(self): def _move_to_device(self):
""" """
Moves the ``unknown_parameters`` of an instance of Moves the ``unknown_parameters`` of an instance of
:class:`~pina.problem.AbstractProblem` to the :class:`Trainer` device. :class:`~pina.problem.abstract_problem.AbstractProblem` to the
:class:`Trainer` device.
""" """
device = self._accelerator_connector._parallel_devices[0] device = self._accelerator_connector._parallel_devices[0]
# move parameters to device # move parameters to device
@@ -205,12 +206,16 @@ class Trainer(lightning.pytorch.Trainer):
def train(self, **kwargs): def train(self, **kwargs):
""" """
Manage the training process of the solver. Manage the training process of the solver.
:param dict kwargs: Additional keyword arguments.
""" """
return super().fit(self.solver, datamodule=self.data_module, **kwargs) return super().fit(self.solver, datamodule=self.data_module, **kwargs)
def test(self, **kwargs): def test(self, **kwargs):
""" """
Manage the test process of the solver. Manage the test process of the solver.
:param dict kwargs: Additional keyword arguments.
""" """
return super().test(self.solver, datamodule=self.data_module, **kwargs) return super().test(self.solver, datamodule=self.data_module, **kwargs)

View File

@@ -60,14 +60,14 @@ def check_consistency(object_, object_instance, subclass=False):
def labelize_forward(forward, input_variables, output_variables): def labelize_forward(forward, input_variables, output_variables):
""" """
Decorator to enable or disable the use of :class:`~pina.LabelTensor` Decorator to enable or disable the use of
during the forward pass. :class:`~pina.label_tensor.LabelTensor` during the forward pass.
:param Callable forward: The forward function of a :class:`torch.nn.Module`. :param Callable forward: The forward function of a :class:`torch.nn.Module`.
:param list[str] input_variables: The names of the input variables of a :param list[str] input_variables: The names of the input variables of a
:class:`~pina.problem.AbstractProblem`. :class:`~pina.problem.abstract_problem.AbstractProblem`.
:param list[str] output_variables: The names of the output variables of a :param list[str] output_variables: The names of the output variables of a
:class:`~pina.problem.AbstractProblem`. :class:`~pina.problem.abstract_problem.AbstractProblem`.
:return: The decorated forward function. :return: The decorated forward function.
:rtype: Callable :rtype: Callable
""" """
@@ -95,9 +95,9 @@ def labelize_forward(forward, input_variables, output_variables):
def merge_tensors(tensors): def merge_tensors(tensors):
""" """
Merge a list of :class:`~pina.LabelTensor` instances into a single Merge a list of :class:`~pina.label_tensor.LabelTensor` instances into a
:class:`~pina.LabelTensor` tensor, by applying iteratively the cartesian single :class:`~pina.label_tensor.LabelTensor` tensor, by applying
product. iteratively the cartesian product.
:param list[LabelTensor] tensors: The list of tensors to merge. :param list[LabelTensor] tensors: The list of tensors to merge.
:raises ValueError: If the list of tensors is empty. :raises ValueError: If the list of tensors is empty.
@@ -111,8 +111,9 @@ def merge_tensors(tensors):
def merge_two_tensors(tensor1, tensor2): def merge_two_tensors(tensor1, tensor2):
""" """
Merge two :class:`~pina.LabelTensor` instances into a single Merge two :class:`~pina.label_tensor.LabelTensor` instances into a single
:class:`~pina.LabelTensor` tensor, by applying the cartesian product. :class:`~pina.label_tensor.LabelTensor` tensor, by applying the cartesian
product.
:param LabelTensor tensor1: The first tensor to merge. :param LabelTensor tensor1: The first tensor to merge.
:param LabelTensor tensor2: The second tensor to merge. :param LabelTensor tensor2: The second tensor to merge.