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

Surrogate Plugin ML/AI Documentation #1181

Merged
merged 37 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6755609
Add MVP for ML/AI surrogate plugin
franflame Sep 5, 2023
a7a1841
Add copy of data file for testing
franflame Sep 5, 2023
39eda3b
Formatting changes
franflame Sep 5, 2023
183549a
Resolve pylint error
franflame Sep 5, 2023
bc5c7df
Initial implementation of GUI tests for surrogate plugins
lbianchi-lbl Sep 6, 2023
a6061f1
Skip tests if tensorflow not available
lbianchi-lbl Sep 6, 2023
323520c
Add utility method to export input and output vars directly as dataframe
lbianchi-lbl Sep 21, 2023
f48ce3b
Add utility method to get currently selected input and output vars data
lbianchi-lbl Sep 21, 2023
b0452e1
Add example code for accessing selected input and output vars and data
lbianchi-lbl Sep 21, 2023
e06bc5a
Format
lbianchi-lbl Sep 21, 2023
8dd598a
Remove f-string syntax incompatible with Python 3.7
lbianchi-lbl Sep 21, 2023
7c536f5
Updated to use variables from flowsheet
franflame Sep 22, 2023
f1e218c
Remove unused and/or redundant local variables for training data
lbianchi-lbl Sep 22, 2023
13ef5f5
Intercept stdout so that training output can be shown in GUI
lbianchi-lbl Sep 22, 2023
6787716
Change model serialization file format to resolve deprecation warning
lbianchi-lbl Sep 22, 2023
7274501
Use flowsheet for pytorch_nn.py and scikit_nn.py
franflame Sep 30, 2023
ab4cdd2
Formatting
franflame Sep 30, 2023
88dea3a
Displays pytorch_nn.py output in FOQUS GUI
franflame Oct 4, 2023
ff2eb1f
Handle pylint error
franflame Oct 10, 2023
9c3fd3a
Generalize importorskip using parametrization
lbianchi-lbl Oct 13, 2023
f60cb84
Use different session file for NN training
lbianchi-lbl Oct 13, 2023
df8828e
Add variable selection before executing
lbianchi-lbl Oct 13, 2023
6735cbb
Format code
lbianchi-lbl Oct 13, 2023
dace1e6
Draft description for pytorch_nn.py and scikit_nn.py
franflame Oct 18, 2023
91f1917
Merge remote-tracking branch 'origin/surrogate-plugin-ml-ai' into sur…
franflame Oct 18, 2023
3680e52
Added input validation and custom file name option
franflame Nov 19, 2023
72858da
Merge branch 'master' into surrogate-plugin-ml-ai
ksbeattie Nov 21, 2023
c7b1a34
Add ml_ai subdirectory to default path for output file
franflame Nov 22, 2023
f2bf3eb
Merge remote-tracking branch 'origin/surrogate-plugin-ml-ai' into sur…
franflame Nov 22, 2023
b1531c3
Merge branch 'master' into surrogate-plugin-ml-ai
bpaul4 Nov 27, 2023
e44a301
Fix typos identified by Spell Checker
bpaul4 Nov 27, 2023
14a0e66
Initial documentation for keras_nn plugin
bpaul4 Dec 8, 2023
12653c5
Fix doc issues
bpaul4 Dec 8, 2023
cf4d59c
Make docs generic to include pytorch and sci-kit learn
bpaul4 Dec 8, 2023
807b5b5
Add note mentioning planned updates
bpaul4 Dec 8, 2023
11b15c8
Merge branch 'surrogate-plugin-ml-ai-docs' of https://github.com/bpau…
bpaul4 Dec 8, 2023
194aa20
Merge branch 'master' into surrogate-plugin-ml-ai-docs
lbianchi-lbl Dec 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
446 changes: 446 additions & 0 deletions docs/source/chapt_surrogates/figs/kerasnn_settings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions docs/source/chapt_surrogates/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ The following surrogate modeling tools are currently available:
Neural Networks. It contains special features specifically designed
for working with CFDs.

- Keras Neural Networks (keras_nn) – Surrogate models leveraging neural networks in
TensorFlow Keras, a high-level machine learning library that supports training sequential or interconnected graph-based models.

- PyTorch Neural Networks (pytorch_nn) – Surrogate models leveraging neural networks in
PyTorch, an optimized tensor library for deep learning that supports training sequential or interconnected graph-based models.

- Scikit-learn Neural Networks (scikit_nn) – Surrogate models leveraging neural networks in
Scikit-learn, a predictive data analysis and surrogate modeling library that supports multi-layer regression and classification.

Data Selection
--------------

Expand Down
1 change: 1 addition & 0 deletions docs/source/chapt_surrogates/tutorial/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Tutorial
bssanova
uq_model
flowsheet
neural_networks
66 changes: 66 additions & 0 deletions docs/source/chapt_surrogates/tutorial/neural_networks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
.. _(sec.surrogate.nn):

Tutorial 6: Neural Networks
===========================

This tutorial covers the TensorFlow Keras Neural Network surrogate modeling method via the plugin "keras_nn". The Surrogates module also supports
PyTorch and Scikit-learn Neural Network surrogate modeling methods, which follow the workflow below using the "pytorch_nn" and "scikit_nn" plugins, respectively.

More information on TensorFlow Keras model building is described by :ref:`(Wu et al. 2020)<Wu_2020>`.
Users may follow the recommended workflow to install and use TensorFlow in a Python environment, as described in the TensorFlow documentation:
https://www.tensorflow.org/install.

Users may obtain a great deal of usage standards and best practices information as described in the PyTorch documentation:
https://pytorch.org/docs/stable/index.html.

Users may find further information on the Scikit-learn package in the documentation:
https://scikit-learn.org/stable/index.html and further information on deep learning capabilities as well:
https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html#sklearn.neural_network.MLPRegressor.

The FOQUS file for this tutorial is **Simple_flow.foqus**, and
this file is located in: **examples/tutorial_files/Flowsheets/Tutorial_4**

.. note:: |examples_reminder_text|

The Python package `tensorflow` must be installed to use this surrogate plugin.
Before starting this tutorial, you will need to install the package by referring to
the installation instructions in the TensorFlow documentation.

#. Load the "Simple_flow.foqus" file from the examples/tutorial_files/Flowsheets/Tutorial_4 folder.

#. Click the **Surrogates** button from the Home window (Figure
:ref:`fig.kerasnn.settings`).

#. Select “keras_nn” in the **Tool** drop-down list. For PyTorch, select "pytorch_nn". For Scikit-learn, select "scikit_nn".

#. Select the **Variables** tab and select the desired input and output variables. Note that "graph.error" should not be selected.

#. Select the **Method Settings** tab.

#. Set “Initial Data Filter” to “All”.

#. Set "n_hidden" to "1", "n_neurons" to "12", "layer_act" to "relu", and "out_act" to "sigmoid".

#. Ensure there are values present for "numpy_seed", "random_seed", and "tensorflow_seed" so results are reproducible.

#. Set "epoch" to "500", "verbose" to "0" (i.e. epoch results will not print during training) and ensure "output_file" has a file name of the form "user_ml_ai_models/[NAME].keras". NAME may be changed, if desired. The model will be saved to the working directory folder user_ml_ai_models. For PyTorch, the file extension should be ".pt". For Scikit-learn, the file extension should be ".pkl".

#. Click the **Run** icon (Figure
:ref:`fig.kerasnn.settings`).

.. figure:: ../figs/kerasnn_settings.svg
:alt: Keras Neural Network Session Set Up
:name: fig.kerasnn.settings

Keras Neural Network Session Set Up

10. The execution window will automatically display. While the regression training is finished running, TensorFlow Keras will display some information on the model size and shape.

11. When the run completes, the script produces a saved model file which is compatible with the Machine Learning & Artificial Intelligence Plugin. (See Section :ref:`mlaiplugin`.)

In the future, these plugins will support additional items yielding enhanced surrogate modeling capabilities.

- Expanded data normalization options
- Offline data loading from a file, e.g. CSV, Excel, PSUADE
- Support for regression of multi-output neural networks
- Automatic regression parameter selection during model training from user-supplied parameter options
Loading