new solvers structure#777
Conversation
| condition_losses[condition_name] = self._apply_reduction( | ||
| condition_loss_tensor | ||
| ) |
There was a problem hiding this comment.
Do not forget weightings!
|
Just changed the title, cuz generation was making me think about generative models |
GiovanniCanali
left a comment
There was a problem hiding this comment.
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
.rstdocumentation 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.evaluateis not supported by allConditiontypes. At the moment, it is defined forTimeSeriesConditionandInputTargetCondition, but not for the other condition classes. In its current state, the logic insideoptimization_cyclewill break as soon as a different condition type is encountered. I noticed thatBaseEquationConditionexists, but currently no condition inherits from it. This could perhaps be used to centralize theevaluatelogic for equation-based conditions, althoughDataConditionwould still remain uncovered. - Finally, I thought we had agreed to remove the
optimization_cycle/_optimization_cycleduality 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.
There was a problem hiding this comment.
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"): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Move to import section
There was a problem hiding this comment.
Delete commented lines if they are unnecessary.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
See PINNs for both validation and test steps
| condition = self.problem.conditions[condition_name] | ||
| condition_data = dict(data) | ||
|
|
||
| condition_loss_tensor = condition.evaluate( |
There was a problem hiding this comment.
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.
Description
This PR fixes #782
Checklist