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

Add check to ensure PSUADE is found at FOQUS startup #1226

Merged
merged 2 commits into from
Jun 18, 2024

Conversation

lbianchi-lbl
Copy link
Contributor

Resolves #1142

Summary/Motivation:

  • Avoid situations where PSUADE not being available causes unclear error states

Changes proposed in this PR:

  • Add check for PSUADE executable at FOQUS startup; if not found, exit immediately and display a link to FOQUS documentation
  • Add CLI flag to specify a different PSUADE path, if needed

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the copyright and license terms described in the LICENSE.md file at the top level of this directory.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@lbianchi-lbl
Copy link
Contributor Author

lbianchi-lbl commented Jun 11, 2024

Start from a fresh environment:

# from the root of a local FOQUS repo clone
$ conda create -c conda-forge -n test-foqus-1126 python=3.10 && conda activate test-foqus-1126
$ pip install -r requirements-dev.txt

Case 1: PSUADE not installed

$ foqus -w "$(mktemp -d)"
2024-06-11 12:49:26,323 - CRITICAL - foqus.foqus_lib.foqus - Executable not found for 'psuade'. The application will now exit. For more information about installing PSUADE, refer to the FOQUS documentation at https://foqus.readthedocs.io

Case 2: after installing PSUADE with Conda

Note

plugin errors are to be expected since ML/AI packages are not installed

$ conda install -c conda-forge -c CCSI-Toolset psuade-lite=1.9
$ foqus -w "$(mktemp -d)"
2024-06-11 12:50:24,234 - INFO - foqus.foqus_lib.foqus - PSUADE executable found at '/opt/conda/envs/test-foqus-1142/bin/psuade'
2024-06-11 12:50:24,533 - DEBUG - foqus.foqus_lib.foqus - Working directory set to /tmp/tmp.TehetuQts9
2024-06-11 12:50:24,535 - DEBUG - foqus.foqus_lib.foqus - Create Flowsheet Session
2024-06-11 12:50:24,537 - DEBUG - foqus.foqus_lib.framework.session.session - Initializing session, Log file: /tmp/tmp.TehetuQts9/logs/foqus.log, Position: 0
2024-06-11 12:50:24,537 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/pytorch_nn.py
2024-06-11 12:50:24,542 - ERROR - foqus.foqus_lib.framework.plugins.pluginSearch - Error Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/pytorch_nn.py
Traceback (most recent call last):
  File "/home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/plugins/pluginSearch.py", line 89, in importPlugins
    self.plugins[mname[0]] = importlib.import_module(
  File "/opt/conda/envs/test-foqus-1142/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/pytorch_nn.py", line 44, in <module>
    import torch  # pylint: disable=import-error
ModuleNotFoundError: No module named 'torch'
2024-06-11 12:50:24,543 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/BSS-ANOVA.py
2024-06-11 12:50:24,544 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/ACOSSO.py
2024-06-11 12:50:24,544 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/scikit_nn.py
2024-06-11 12:50:24,547 - ERROR - foqus.foqus_lib.framework.plugins.pluginSearch - Error Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/scikit_nn.py
Traceback (most recent call last):
  File "/home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/plugins/pluginSearch.py", line 89, in importPlugins
    self.plugins[mname[0]] = importlib.import_module(
  File "/opt/conda/envs/test-foqus-1142/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/scikit_nn.py", line 46, in <module>
    from sklearn.neural_network import MLPRegressor  # pylint: disable=import-error
ModuleNotFoundError: No module named 'sklearn'
2024-06-11 12:50:24,548 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/keras_nn.py
2024-06-11 12:50:24,550 - ERROR - foqus.foqus_lib.framework.plugins.pluginSearch - Error Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/keras_nn.py
Traceback (most recent call last):
  File "/home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/plugins/pluginSearch.py", line 89, in importPlugins
    self.plugins[mname[0]] = importlib.import_module(
  File "/opt/conda/envs/test-foqus-1142/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/keras_nn.py", line 46, in <module>
    import tensorflow as tf  # pylint: disable=import-error
ModuleNotFoundError: No module named 'tensorflow'
2024-06-11 12:50:24,551 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/surrogate/ALAMO.py
2024-06-11 12:50:24,560 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: BSS-ANOVA
2024-06-11 12:50:24,560 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: ACOSSO
2024-06-11 12:50:24,560 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: ALAMO
2024-06-11 12:50:24,561 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/optimizer/BFGS.py
2024-06-11 12:50:24,646 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/optimizer/Snobfit.py
2024-06-11 12:50:24,647 - INFO - foqus.Snobfit - Failed to import SQSnobFit and SQCommon packages used to access the snobfit solver
2024-06-11 12:50:24,647 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/optimizer/OptCMA.py
2024-06-11 12:50:25,204 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/optimizer/SLSQP.py
2024-06-11 12:50:25,205 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/optimizer/Sample.py
2024-06-11 12:50:25,206 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/optimizer/NLopt.py
2024-06-11 12:50:25,206 - INFO - foqus.NLopt - Failed to import the nlopt package
2024-06-11 12:50:25,207 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/optimizer/SM_Optimizer.py
2024-06-11 12:50:25,209 - INFO - foqus.SM_Optimizer - Failed to import the required packages for SM Optimizer solver
2024-06-11 12:50:25,209 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/optimizer/PSUADE.py
2024-06-11 12:50:25,210 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: BFGS
2024-06-11 12:50:25,210 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: Snobfit
2024-06-11 12:50:25,210 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Removing plugin, due to missing dependency: Snobfit
2024-06-11 12:50:25,210 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: OptCMA
2024-06-11 12:50:25,210 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: SLSQP
2024-06-11 12:50:25,210 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: Sample
2024-06-11 12:50:25,210 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: NLopt
2024-06-11 12:50:25,210 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Removing plugin, due to missing dependency: NLopt
2024-06-11 12:50:25,210 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: SM_Optimizer
2024-06-11 12:50:25,210 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Removing plugin, due to missing dependency: SM_Optimizer
2024-06-11 12:50:25,210 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: PSUADE
2024-06-11 12:50:25,211 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/pymodel/pymodel_test.py
2024-06-11 12:50:25,213 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/pymodel/heat_integration.py
2024-06-11 12:50:25,219 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/pymodel/matlab_fs.py
2024-06-11 12:50:25,220 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Loading Plugin: /home/ludo/lbl/ccsi/FOQUS/foqus_lib/framework/pymodel/steam_cycle.py
2024-06-11 12:50:25,221 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: pymodel_test
2024-06-11 12:50:25,221 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: heat_integration
2024-06-11 12:50:25,221 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: matlab_fs
2024-06-11 12:50:25,221 - INFO - foqus.foqus_lib.framework.plugins.pluginSearch - Removing plugin, due to missing dependency: matlab_fs
2024-06-11 12:50:25,221 - DEBUG - foqus.foqus_lib.framework.plugins.pluginSearch - check plugin available: steam_cycle
2024-06-11 12:50:25,227 - DEBUG - foqus.foqus_lib.framework.sim.turbineConfiguration - turbine configuration="turbine.cfg"
2024-06-11 12:50:25,228 - DEBUG - foqus.foqus_lib.framework.sim.turbineConfiguration - turbine configuration application url="http://localhost:8000/TurbineLite/application/"
2024-06-11 12:50:25,228 - DEBUG - foqus.foqus_lib.framework.sim.turbineConfiguration - turbine configuration url="http://localhost:8000/TurbineLite"
2024-06-11 12:50:25,229 - DEBUG - foqus.foqus_lib.foqus - Load Flowsheet Session: None
2024-06-11 12:50:25,229 - DEBUG - foqus.foqus_lib.foqus - LoadValues Flowsheet: None
2024-06-11 12:50:25,229 - DEBUG - foqus.foqus_lib.foqus - Run Option: None
2024-06-11 12:50:25,229 - DEBUG - foqus.foqus_lib.foqus - Starting GUI

Case 3: using the --psuade-path CLI flag

$ foqus -w "$(mktemp -d)" --psuade-path=/tmp/does-not-exist
2024-06-11 12:51:54,561 - CRITICAL - foqus.foqus_lib.foqus - PSUADE executable not found for '/tmp/does-not-exist'. The application will now exit. For more information about installing PSUADE, refer to the FOQUS documentation at https://foqus.readthedocs.io

@ksbeattie ksbeattie added the Priority:High High Priority Issue or PR label Jun 11, 2024
@ksbeattie ksbeattie requested review from ksbeattie and sotorrio1 June 11, 2024 19:46
@ksbeattie ksbeattie marked this pull request as ready for review June 11, 2024 19:59
Copy link
Member

@ksbeattie ksbeattie left a comment

Choose a reason for hiding this comment

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

Tested as described.

Copy link
Member

@sotorrio1 sotorrio1 left a comment

Choose a reason for hiding this comment

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

LGTM

@ksbeattie ksbeattie merged commit 38c546b into CCSI-Toolset:master Jun 18, 2024
55 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:High High Priority Issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Psuade-Lite Requirement
3 participants