Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add adaptive optimizers for all mappings #315

Merged
merged 83 commits into from
Sep 12, 2024

Conversation

nghi-truyen
Copy link
Member

@nghi-truyen nghi-truyen commented Sep 10, 2024

Suggested reviewer order: FC, PAG.
Adaptive optimizers (i.e. adam, adagrad, sgd, and rmsprop) are now possible for all mappings. This PR results in the following important changes:

  • Key "epoch" for optimization with ANN is deprecated and replaced by "maxiter" (since the optim process can be stopped before the maximum number of iterations using early stopping method) for the consistency with other optimizers
  • The verbose of the cost and projected gradient are changed to a scientific presentation (i.e. using the "e" format instead of "f") + update documentation
  • Fix the display of the cost value at the last iteration in case of SBS. The last iteration was displayed inconsistant value in case of having convergence using SBS optimizer
  • Split between tools and principal functions in the optimize.py file
  • Remove smash/fcore/external/lbfgsb.f
  • Merge regionalization NN parameters into the control vector return
  • Keys iter_cost and iter_projg are deprecated. The idea is to keep the consistency for all mappings by returning the optimization results only at the last optimization process. To access to intermediate results, the next PR would address this issue Add a callback signature into the optimization methods to get intermediate results #252
  • Add new tests for optimization with various optimizers and mappings
  • The baseline is regenerated. The changes for the return of control vector value is due to the fact that the control vector is now directly returned by the Python routine, rather than being passed to the Fortran wrapper that causes precision problems (e.g. ret["control_vector"] = res.x instead of ret["control_vector"] =model._parameters.control.x.copy())

@nghi-truyen nghi-truyen added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request labels Sep 10, 2024
@nghi-truyen nghi-truyen added this to the Release v1.1.0 milestone Sep 10, 2024
@nghi-truyen nghi-truyen linked an issue Sep 10, 2024 that may be closed by this pull request
Copy link
Member

@inoelloc inoelloc left a comment

Choose a reason for hiding this comment

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

Voila une première passe de relecture. On peut attendre la review de @pag13 pour après échanger sur Skype pour finaliser tout ca !

smash/_constant.py Outdated Show resolved Hide resolved
smash/_constant.py Outdated Show resolved Hide resolved
smash/_constant.py Outdated Show resolved Hide resolved
smash/core/simulation/_doc.py Outdated Show resolved Hide resolved
smash/factory/net/_loss.py Outdated Show resolved Hide resolved
@@ -532,94 +531,111 @@ def _fit_d2p(
random_state=random_state,
)

# % First evaluation
# calculate the gradient of J wrt rr_parameters (output of the regionalization NN)
Copy link
Member

Choose a reason for hiding this comment

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

pas que rr_parameters en soit ?

Copy link
Member Author

Choose a reason for hiding this comment

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

# calculate the gradient of J wrt rr_parameters (output of the regionalization NN)
# and get the gradient of the parameterization NN if used
        
init_cost_grad, nn_parameters_b = _hcost_prime(
            self, x_train, model_params_states, instance, parameters, wrap_options, wrap_returns
)

J'ai fait pour les deux gradients en fait.

Copy link
Member

Choose a reason for hiding this comment

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

JE voulais dire, aussi rr_initial_states non ?

smash/factory/net/net.py Outdated Show resolved Hide resolved
smash/factory/net/net.py Show resolved Hide resolved
smash/fcore/routine/mwd_parameters_manipulation.f90 Outdated Show resolved Hide resolved
@DassHydro DassHydro deleted a comment from inoelloc Sep 11, 2024
Copy link
Collaborator

@pag13 pag13 left a comment

Choose a reason for hiding this comment

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

Travail impressionnant et très rigoureux Truyen, bravo ! Merci pour la bonne review François.

smash/_constant.py Outdated Show resolved Hide resolved
smash/_constant.py Show resolved Hide resolved
smash/_constant.py Outdated Show resolved Hide resolved
smash/_constant.py Outdated Show resolved Hide resolved
smash/core/simulation/optimize/optimize.py Outdated Show resolved Hide resolved
smash/core/simulation/optimize/optimize.py Outdated Show resolved Hide resolved
smash/factory/net/_loss.py Outdated Show resolved Hide resolved
smash/factory/net/net.py Outdated Show resolved Hide resolved
smash/fcore/routine/mwd_parameters_manipulation.f90 Outdated Show resolved Hide resolved
Copy link
Member

@inoelloc inoelloc left a comment

Choose a reason for hiding this comment

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

Tu as fait un commit pdt la review. Je sais pas vraiment ce qui va s'afficher ^^"
Le seul point de modification important c'est sur le suffix _reg. On en rediscute

smash/core/simulation/_doc.py Outdated Show resolved Hide resolved
smash/core/simulation/optimize/_tools.py Outdated Show resolved Hide resolved
smash/core/simulation/optimize/optimize.py Outdated Show resolved Hide resolved
smash/core/simulation/optimize/optimize.py Outdated Show resolved Hide resolved
smash/core/simulation/optimize/optimize.py Show resolved Hide resolved
smash/factory/net/_loss.py Outdated Show resolved Hide resolved
smash/core/simulation/estimate/_tools.py Show resolved Hide resolved
@@ -532,94 +531,111 @@ def _fit_d2p(
random_state=random_state,
)

# % First evaluation
# calculate the gradient of J wrt rr_parameters (output of the regionalization NN)
Copy link
Member

Choose a reason for hiding this comment

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

JE voulais dire, aussi rr_initial_states non ?

Copy link
Member

@inoelloc inoelloc left a comment

Choose a reason for hiding this comment

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

Bon pour moi merci !

Comment on lines +535 to +537
# calculate the gradient of J wrt rr_parameters and rr_initial_states
# that are the output of the descriptors-to-parameters (d2p) NN
# and get the gradient of the pmtz NN (pmtz) if used
Copy link
Member

Choose a reason for hiding this comment

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

Top

@nghi-truyen nghi-truyen merged commit 61ad424 into DassHydro:main Sep 12, 2024
22 checks passed
@nghi-truyen nghi-truyen deleted the enh-adaptive-optimizers branch September 12, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Combine all optimizers from Fortran and Python
3 participants