Skip to content

new solvers structure#777

Open
ndem0 wants to merge 11 commits into
0.3from
0.3-solver
Open

new solvers structure#777
ndem0 wants to merge 11 commits into
0.3from
0.3-solver

Conversation

@ndem0
Copy link
Copy Markdown
Member

@ndem0 ndem0 commented Mar 19, 2026

Description

This PR fixes #782

Checklist

  • Code follows the project’s Code Style Guidelines
  • Tests have been added or updated
  • Documentation has been updated if necessary
  • Pull request is linked to an open issue

@ndem0 ndem0 changed the title 0.3 solver new generation solvers Mar 19, 2026
Comment on lines +103 to +105
condition_losses[condition_name] = self._apply_reduction(
condition_loss_tensor
)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add weighting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not forget weightings!

@dario-coscia dario-coscia changed the title new generation solvers new solvers structure Mar 27, 2026
@dario-coscia
Copy link
Copy Markdown
Collaborator

Just changed the title, cuz generation was making me think about generative models

@ndem0 ndem0 added the 0.3 Related to 0.3 release label Apr 8, 2026
@GiovanniCanali GiovanniCanali mentioned this pull request Apr 14, 2026
4 tasks
@ndem0 ndem0 marked this pull request as ready for review May 8, 2026 08:26
@ndem0 ndem0 requested a review from a team as a code owner May 8, 2026 08:26
Copy link
Copy Markdown
Collaborator

@GiovanniCanali GiovanniCanali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ndem0 for implementing this substantial refactor of the solver logic. The overall direction looks good to me, and the change is definitely significant.

Before proceeding with the merge, though, I think there are still a few points that should be addressed. Some are minor, while others seem blocking to ensure consistency and compatibility with the current API. I am reporting here the ones I consider the most important; the remaining review comments are still useful for completeness.

  • Several solvers are still missing, especially PINN-related ones (CausalPINN, CompetitivePINN, GradientPINN, RBAPINN, SelfAdaptivePINN). We can reintroduce them in a later phase, but they should still be restored before the 0.3 release.

  • The same applies to the .rst documentation files, which currently do not yet reflect the new structure.

  • There are also a couple of files that do not appear to be used anywhere. I think we should clarify whether they are meant to be integrated into the new flow or removed to avoid dead code.

  • Regarding the new solver logic, I still see a few critical issues:

    • loss aggregation weights currently seem to be missing;
    • More importantly, condition.evaluate is not supported by all Condition types. At the moment, it is defined for TimeSeriesCondition and InputTargetCondition, but not for the other condition classes. In its current state, the logic inside optimization_cycle will break as soon as a different condition type is encountered. I noticed that BaseEquationCondition exists, but currently no condition inherits from it. This could perhaps be used to centralize the evaluate logic for equation-based conditions, although DataCondition would still remain uncovered.
    • Finally, I thought we had agreed to remove the optimization_cycle / _optimization_cycle duality in favor of a unified logic shared across train/validation/test. If we instead want to keep both, I would still suggest revisiting the naming, because in the current form it may easily become confusing.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To delete: this file has been split into test_data/test_graph_data_manager.py and test_data/test_tensor_data_manager.py.

Abstract interface for all losses.
"""

def __init__(self, reduction="mean"):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove __init__: interfaces should not implement methods. This is already declared and defined in the respective base class.



class LossInterface(_Loss, metaclass=ABCMeta):
class DualLossInterface(_Loss, metaclass=ABCMeta):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, rename the file and update the import statements in the __init__.py file according to PINA conventions. The file should be renamed to dual_loss_interface.py.

from pina._src.core.label_tensor import LabelTensor
from pina._src.core.utils import check_consistency
from pina._src.loss.loss_interface import LossInterface
from pina._src.loss.loss_interface import DualLossInterface as LossInterface
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, import DualLossInterface without aliasing.

from pina._src.solver.physics_informed_solver.pinn_interface import (
PINNInterface,
)
from pina._src.solver.pinn import PINN as PINNInterface
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, import PINN without aliasing.

self.forward = ( # noqa: E731
lambda x, _idx=idx: self.models[_idx].forward(x)
)
from pina._src.core.utils import labelize_forward
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to import section

Comment thread pina/_src/core/trainer.py
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete commented lines if they are unnecessary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore the following: AbstractProblem -> BaseProblem, Scheduler -> SchedulerInterface, Optimizer -> OptimizerInterface in the docs

print('dio setup')
return super(PINN, self).setup(stage)

def validation_step(self, batch, **kwargs):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See PINNs for both validation and test steps

condition = self.problem.conditions[condition_name]
condition_data = dict(data)

condition_loss_tensor = condition.evaluate(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instruction condition.evaluate is not supported by all Condition types: it is defined for InputTargetCondition and TimeSeriesCondition, but it does not appear to be available for all other condition types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.3 Related to 0.3 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants