Fix rendering and codacy

This commit is contained in:
FilippoOlivo
2025-03-14 15:05:16 +01:00
committed by Nicola Demo
parent 05105dd517
commit 001d1fc9cf
8 changed files with 98 additions and 96 deletions

View File

@@ -244,7 +244,7 @@ class PinaSampler:
class PinaDataModule(LightningDataModule):
"""
This class extends :class:`lightning.pytorch.LightningDataModule`,
This class extends :class:`~lightning.pytorch.core.LightningDataModule`,
allowing proper creation and management of different types of datasets
defined in PINA.
"""
@@ -268,24 +268,24 @@ class PinaDataModule(LightningDataModule):
:param AbstractProblem problem: The problem containing the data on which
to create the datasets and dataloaders.
:param float train_size: Fraction of elements in the training split. It
must be in the range [0, 1].
must be in the range [0, 1].
:param float test_size: Fraction of elements in the test split. It must
be in the range [0, 1].
be in the range [0, 1].
:param float val_size: Fraction of elements in the validation split. It
must be in the range [0, 1].
must be in the range [0, 1].
:param batch_size: The batch size used for training. If ``None``, the
entire dataset is returned in a single batch.
:type batch_size: int | None
entire dataset is returned in a single batch. Default is ``None``.
:type batch_size: int
:param bool shuffle: Whether to shuffle the dataset before splitting.
Default True.
Default ``Tru``e.
:param bool repeat: Whether to repeat the dataset indefinitely.
Default False.
Default ``False``.
:param automatic_batching: Whether to enable automatic batching.
Default False.
Default ``False``.
:param int num_workers: Number of worker threads for data loading.
Default 0 (serial loading).
Default ``0`` (serial loading).
:param bool pin_memory: Whether to use pinned memory for faster data
transfer to GPU. Default False.
transfer to GPU. Default ``False``.
:raises ValueError: If at least one of the splits is negative.
:raises ValueError: If the sum of the splits is different from 1.
@@ -643,7 +643,7 @@ class PinaDataModule(LightningDataModule):
Return all the input points coming from all the datasets.
:return: The input points for training.
:rtype dict
:rtype: dict
"""
to_return = {}

View File

@@ -12,12 +12,13 @@ class PinaDatasetFactory:
"""
Factory class for the PINA dataset.
Depending on the type inside the conditions, it creates a different dataset
object:
Depending on the data type inside the conditions, it instanciate an object
belonging to the appropriate subclass of
:class:`~pina.data.dataset.PinaDataset`. The possible subclasses are:
- :class:`~pina.data.dataset.PinaTensorDataset` for handling
- :class:`~pina.data.dataset.PinaTensorDataset`, for handling \
:class:`torch.Tensor` and :class:`~pina.label_tensor.LabelTensor` data.
- :class:`~pina.data.dataset.PinaGraphDataset` for handling
- :class:`~pina.data.dataset.PinaGraphDataset`, for handling \
:class:`~pina.graph.Graph` and :class:`~torch_geometric.data.Data` data.
"""
@@ -33,8 +34,7 @@ class PinaDatasetFactory:
:param dict conditions_dict: Dictionary containing all the conditions
to be included in the dataset instance.
:return: A subclass of :class:`~pina.data.dataset.PinaDataset`.
:rtype: pina.data.dataset.PinaTensorDataset |
pina.data.dataset.PinaGraphDataset
:rtype: PinaTensorDataset | PinaGraphDataset
:raises ValueError: If an empty dictionary is provided.
"""
@@ -74,8 +74,9 @@ class PinaDatasetFactory:
class PinaDataset(Dataset, ABC):
"""
Abstract class for the PINA dataset. It defines the common interface for
:class:`~pina.data.dataset.PinaTensorDataset` and
Abstract class for the PINA dataset which extends the PyTorch
:class:`~torch.utils.data.Dataset` class. It defines the common interface
for :class:`~pina.data.dataset.PinaTensorDataset` and
:class:`~pina.data.dataset.PinaGraphDataset` classes.
"""
@@ -83,13 +84,15 @@ class PinaDataset(Dataset, ABC):
self, conditions_dict, max_conditions_lengths, automatic_batching
):
"""
Initialize :class:`~pina.data.dataset.PinaDataset` instance by storing
the provided conditions dictionary, and the automatic batching flag.
Initialize the instance by storing the conditions dictionary, the
maximum number of items per conditions to consider, and the automatic
batching flag.
:param dict conditions_dict: Dictionary containing the conditions with
data.
:param dict max_conditions_lengths: Specifies the maximum number of data
points to include in a single batch for each condition.
:param dict conditions_dict: A dictionary mapping condition names to
their respective data. Each key represents a condition name, and the
corresponding value is a dictionary containing the associated data.
:param dict max_conditions_lengths: Maximum number of data points that
can be included in a single batch per condition.
:param bool automatic_batching: Indicates whether PyTorch automatic
batching is enabled in
:class:`~pina.data.data_module.PinaDataModule`.
@@ -258,8 +261,8 @@ class PinaGraphDataset(PinaDataset):
Reshape properly ``data`` tensor to be processed handle by the graph
based models.
:param data: torch.Tensor object of shape (N, ...) where N is the
number of data points.
:param data: torch.Tensor object of shape ``(N, ...)`` where ``N`` is
the number of data objects.
:type data: torch.Tensor | LabelTensor
:return: Reshaped tensor object.
:rtype: torch.Tensor | LabelTensor
@@ -275,7 +278,7 @@ class PinaGraphDataset(PinaDataset):
:param data: List of items to collate in a single batch.
:type data: list[Data] | list[Graph]
:return: Batch object.
:rtype: Batch | PinaBatch
:rtype: Batch | LabelBatch
"""
if isinstance(data[0], Data):