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 capability to handle interdependent functions in samplers/optimizers #2319

Merged
merged 34 commits into from
Jun 7, 2024

Conversation

alfoa
Copy link
Collaborator

@alfoa alfoa commented May 15, 2024


Pull Request Description

What issue does this change request address? (Use "#" before the issue to link it, i.e., #42.)

Closes #2302

What are the significant changes in functionality due to this change request?

Added the possibility to specify in Optimizers/Samplers variables (defined through functions) that are interdependent.

For example, lets assume we sample the variables

  • #_Eggs,
  • grams_Pancetta_or_Guanciale(I know we should use only guanciale but it is difficult to find it),
  • grams_Pecorino_Cheese;
  • #_tomatos;

the variable what_dish_do_we_cook depends solely on these variables (and it is defined through a RAVEN <function>) and depending on the values of #_tomatos and #_Eggs the result of this function can be either be Carbonara or Amatriciana.

the variable which_pasta_should_we_use depends on the variable what_dish_do_we_cook:
if

  • what_dish_do_we_cook == Carbonara, which_pasta_should_we_use == Rigatoni
    else
  • what_dish_do_we_cook == Amatriciana, which_pasta_should_we_use == Bucatini

Based on this example, RAVEN will first sample #_Eggs, grams_Pancetta_or_Guanciale, grams_Pecorino_Cheese and #_tomatos; Then it evaluates the function that computes the variable
what_dish_do_we_cook and finally it computes the variable which_pasta_should_we_use depending on the
value of the variable what_dish_do_we_cook.

In addition to this capability, also a new test for the ensemble model testing/showing how to use it to transfer string variables from a model to the other using RAVEN variables has been added.


For Change Control Board: Change Request Review

The following review must be completed by an authorized member of the Change Control Board.

  • 1. Review all computer code.
  • 2. If any changes occur to the input syntax, there must be an accompanying change to the user manual and xsd schema. If the input syntax change deprecates existing input files, a conversion script needs to be added (see Conversion Scripts).
  • 3. Make sure the Python code and commenting standards are respected (camelBack, etc.) - See on the wiki for details.
  • 4. Automated Tests should pass, including run_tests, pylint, manual building and xsd tests. If there are changes to Simulation.py or JobHandler.py the qsub tests must pass.
  • 5. If significant functionality is added, there must be tests added to check this. Tests should cover all possible options. Multiple short tests are preferred over one large test. If new development on the internal JobHandler parallel system is performed, a cluster test must be added setting, in XML block, the node <internalParallel> to True.
  • 6. If the change modifies or adds a requirement or a requirement based test case, the Change Control Board's Chair or designee also needs to approve the change. The requirements and the requirements test shall be in sync.
  • 7. The merge request must reference an issue. If the issue is closed, the issue close checklist shall be done.
  • 8. If an analytic test is changed/added is the the analytic documentation updated/added?
  • 9. If any test used as a basis for documentation examples (currently found in raven/tests/framework/user_guide and raven/docs/workshop) have been changed, the associated documentation must be reviewed and assured the text matches the example.

@@ -0,0 +1,154 @@
<?xml version="1.0" ?>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Jimmy-INL This is the show case/example you asked about.

@alfoa alfoa requested review from wangcj05 and mandd May 15, 2024 15:02
@alfoa
Copy link
Collaborator Author

alfoa commented May 15, 2024

@wangcj05 @joshua-cogliati-inl @mandd

Unfortunately new issue

... Activating environment ...
... Installing libraries from PIP-ONLY ...
...pip-only command: pip install netcdf4==1.6.* tensorflow==2.13.* grpcio dask[complete] ray[default]==2.6.* imageio==2.22.* python-sensors numdifftools==0.9.* xmlschema fmpy==0.3.16.*
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f54cfab2cb0>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /simple/netcdf4/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f54cfc26bc0>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /simple/netcdf4/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f54cfc25ab0>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /simple/netcdf4/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f54cfc26080>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /simple/netcdf4/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f54cfab30d0>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /simple/netcdf4/
ERROR: Could not find a version that satisfies the requirement netcdf4==1.6.* (from versions: none)
ERROR: No matching distribution found for netcdf4==1.6.*

ERROR: exiting with code 1

@moosebuild
Copy link

All jobs on d6e0159 : invalidated by @wangcj05

@moosebuild
Copy link

Job Mingw Test on 74e6708 : invalidated by @alfoa

@alfoa
Copy link
Collaborator Author

alfoa commented May 29, 2024

@wangcj05 @joshua-cogliati-inl the windows machine seems to be down since days. Can we merge this without that test?

@moosebuild
Copy link

Job Mingw Test on 0fd2726 : invalidated by @wangcj05

Copy link
Collaborator

@wangcj05 wangcj05 left a comment

Choose a reason for hiding this comment

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

Some comments for you to consider. @alfoa

Comment on lines 34 to 35
Method to evaluate the function execution order using graph theory
The order is stored in self.variableFunctionExecutionList
Copy link
Collaborator

Choose a reason for hiding this comment

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

These two lines need to be updated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

Comment on lines 323 to 333
#self.ensembleModelGraph = graphStructure.graphObject(modelsToOutputModels)
self.ensembleModelGraph = modelsGraph #graphStructure.graphObject(modelsToOutputModels)
# make some checks
if not self.ensembleModelGraph.isConnectedNet():
isolatedModels = self.ensembleModelGraph.findIsolatedVertices()
self.raiseAnError(IOError, "Some models are not connected. Possible candidates are: "+' '.join(isolatedModels))
# get all paths
allPath = self.ensembleModelGraph.findAllUniquePaths(self.initialStartModels)
#allPath = self.ensembleModelGraph.findAllUniquePaths(self.initialStartModels)
###################################################
# to be removed once executionList can be handled #
self.orderList = self.ensembleModelGraph.createSingleListOfVertices(allPath)
#self.ensembleModelGraph.createSingleListOfVertices(allPath)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you want to keep the commented lines?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

@moosebuild
Copy link

Job Mingw Test on 0fd2726 : invalidated by @joshua-cogliati-inl

restarted civet

1 similar comment
@moosebuild
Copy link

Job Mingw Test on 0fd2726 : invalidated by @joshua-cogliati-inl

restarted civet

@moosebuild
Copy link

Job Mingw Test on 0fd2726 : invalidated by @alfoa

@alfoa
Copy link
Collaborator Author

alfoa commented May 31, 2024

@wangcj05 @joshua-cogliati-inl Unfortunately windows machine still has issues... (now with the set environment).

@moosebuild
Copy link

Job Mingw Test on 62194cc : invalidated by @joshua-cogliati-inl

failed trying to download icu-73.2-h63175ca_0.conda

@moosebuild
Copy link

Job Mingw Test on 62194cc : invalidated by @joshua-cogliati-inl

updated conda

@moosebuild
Copy link

Job Mingw Test on 7b55395 : invalidated by @joshua-cogliati-inl

Failed in set python evnvironment (warning libmamba Could not parse mod/etag header)

@alfoa
Copy link
Collaborator Author

alfoa commented Jun 7, 2024

Is this good to be merged? @wangcj05 @joshua-cogliati-inl ?

Copy link
Collaborator

@wangcj05 wangcj05 left a comment

Choose a reason for hiding this comment

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

changes are good.

@wangcj05
Copy link
Collaborator

wangcj05 commented Jun 7, 2024

PR is good, and checklist is satisfied.

@wangcj05 wangcj05 merged commit dec9c70 into devel Jun 7, 2024
12 checks passed
@wangcj05 wangcj05 deleted the alfoa/functions_graph_theory branch June 7, 2024 14:37
Jimmy-INL pushed a commit that referenced this pull request Jul 7, 2024
…ers (#2319)

* moved samplers-optimizers function tests in their own folder for clarity

* renamed

* modified test names and revisions

* moved subfolders

* Closes #2302

* usage base class function evaluation method in ensembleForward

* added error msg for detection of loop in function system

* added test for ensemble model passing strings (restart file paths) around

* removed trailing spaces

* Update ravenframework/Samplers/EnsembleForward.py

* Update ravenframework/Samplers/Sampler.py

* Update ravenframework/Samplers/Sampler.py

* Update ravenframework/Samplers/Sampler.py

* fixed comment

* we always check for isolated functions

* updated model.tex

* changed order to reflect order of appearance in the introduction of the Model sections

* modified test description to make them latex compatible

* specialization for EnsembleForward and CustomSampler

* Apply suggestions from code review

addressed Congjian's comments

* Apply suggestions from code review

* Apply suggestions from code review

* Update ravenframework/Samplers/Sampler.py

* updated setuptools dep

* updated to simply ver 69

* added utility function as Congjian's request

* plot entity

* model order

* added starting models

* Apply suggestions from code review

* Update ravenframework/utils/graphStructure.py

---------

Co-authored-by: Congjian Wang - INL <congjian.wang@inl.gov>
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.

[TASK] Sampler/Optimizer function execution order
3 participants