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

[RomApp] Adding training routine for neural networks to be used in ANN-PROM #11988

Merged
merged 19 commits into from
May 6, 2024

Conversation

NicolasSR
Copy link
Contributor

@NicolasSR NicolasSR commented Jan 26, 2024

📝 Description
This pull request is the first one in the path to incorporate ANN-PROM into the ROM Application. Here we just deal with the training of the neural networks via Tensorflow.

These neural networks use a certain amount of modes from the POD as input, and learn to predict the next few ones.
The data used for training the net is the same as the one for training POD, except that in this case also the singular values are needed along with an additional dataset of snapshots for the validation.
Once trained, the neural network files (architecture configuration and weights) are saved so that they can be used later.

The usage is via de RomManager by calling:

  • rom_manager.FitNeuralNetwork(mu_train, mu_test): To create the training and validation datasets (based on the parameters in mu_train and mu_test) and then train the NN itself.
  • rom_manager.TestNeuralNetwork(): To evaluate an already-existing NN.

And needs some configuration to be added in the general_rom_manager_parameters json:

  • "rom_stages_nn_fit" : To define which tasks we want to perform in the FitNeuralNetwork() method
  • "neural_network" : To define the root path for the NN model files, the architecture to be used, and the hyperparameters for the training in tensorflow.
    An example of these configuration parameters will be added in the examples repository

🆕 Changelog
Added RomNeuralNetworkTrainer class.
In rom_manager.py:

  • Added FitNeuralNetwork(mu_train, mu_test) and TestNeuralNetwork() methods
  • Added __LaunchTrainNeuralNetwork()and __LaunchTestNeuralNetwork() methods
  • Modified RunFOM() and __LaunchRunFOM to enable saving the produced snapshot matrix

In calculate_rom_basis_output_process.py, modified _PrintRomBasis(snapshots_matrix) to save singular values in a npy file

NicolasSR and others added 4 commits January 29, 2024 11:54
Done in order to properly follow the Kratos Style Guide

Co-authored-by: Rubén Zorrilla <rubenzorrillamartinez@hotmail.com>
Co-authored-by: Rubén Zorrilla <rubenzorrillamartinez@hotmail.com>
@NicolasSR
Copy link
Contributor Author

I corrected naming mistakes and the check routine for the Rom Manager parameters, as pointed out in the comments.
Then I also added the possibility for the user to name the directory for the neural network as they want, an exception for the cases when the number of modes specified by the user is higher than the total number of modes available, and I replaced the 'os' module by the 'pathlib' one.

applications/RomApplication/python_scripts/rom_manager.py Outdated Show resolved Hide resolved
class TestNeuralNetworkTrainerClass(KratosUnittest.TestCase):

def setUp(self):
self.reference_relative_error = 0.0009752321235806322
Copy link
Member

Choose a reason for hiding this comment

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

too hardcoded?

@Rbravo555
Copy link
Member

@roigcarlo Could you check this PR? in particular the test for Tensorflow

@roigcarlo
Copy link
Member

From my side no problem with the TF test 👍

@NicolasSR NicolasSR merged commit 3d8201e into master May 6, 2024
11 checks passed
@NicolasSR NicolasSR deleted the RomApp_RomManager_TrainNN branch May 6, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants