-
Notifications
You must be signed in to change notification settings - Fork 135
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
Fix defect ensemble model (with Code) and genetic algorithm #2317
Merged
Merged
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a0ea3b5
Closes #2304
alfoa e9feed6
added test
alfoa 336bae3
Update tests/framework/Optimizers/GeneticAlgorithms/continuous/uncons…
alfoa da32086
removed trailing
alfoa 70a5354
Merge branch 'alfoa/genetic_ensemble_model' of github.com:idaholab/ra…
alfoa 6077f56
added missing input file
alfoa c7f27bf
Update tests/framework/Optimizers/GeneticAlgorithms/continuous/uncons…
alfoa af23869
isinstance
alfoa ee2f53f
fixed parallel execution
alfoa 7fba807
readded heron and baycal?
alfoa 9f077b8
removed trailing spaces
alfoa ab60b73
some cleaning
alfoa 54f43a4
fixed test name and rook error message
alfoa a522493
module ensemble doc
alfoa 5856f6b
Apply suggestions from code review
alfoa f83fb30
removed trailing whitespaces
alfoa 91a23d9
Merge branch 'devel' into alfoa/genetic_ensemble_model
alfoa d3c7069
fix for 'cvxpy'...this is not a very maintainable way to handle such …
alfoa 7ff7659
changed approach
alfoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ticAlgorithms/continuous/unconstrained/metaModelWithCodeAndFunctionsAndGenetic/ABCDsum.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2017 Battelle Energy Alliance, LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
def run(self, Input): | ||
self.sum = self.A + self.B + self.C + self.D |
5 changes: 5 additions & 0 deletions
5
...rithms/continuous/unconstrained/metaModelWithCodeAndFunctionsAndGenetic/decayConstantB.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright Nucube Energy, Inc. | ||
|
||
def evaluate(self): | ||
return self.decay_A+0.0001 | ||
|
39 changes: 39 additions & 0 deletions
39
...ithms/continuous/unconstrained/metaModelWithCodeAndFunctionsAndGenetic/referenceInput.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" ?> | ||
<AnalyticalBateman> | ||
<totalTime>300</totalTime> | ||
<powerHistory>1 1 1</powerHistory> | ||
<flux>1e14 1e14 1e14</flux> | ||
<stepDays>0 100 200 400</stepDays> | ||
<timeSteps>100 100 100</timeSteps> | ||
<nuclides> | ||
<A> | ||
<equationType>N1</equationType> | ||
<initialMass>1.0</initialMass> | ||
<decayConstant>$RAVEN-decay_A|10$</decayConstant> | ||
<sigma>$RAVEN-sigma-A|10$</sigma> | ||
<ANumber>230</ANumber> | ||
</A> | ||
<B> | ||
<equationType>N2</equationType> | ||
<initialMass>1.0</initialMass> | ||
<decayConstant>$RAVEN-decay_B:0.000000006$</decayConstant> | ||
<sigma>$RAVEN-sigma-B:5$</sigma> | ||
<ANumber>200</ANumber> | ||
</B> | ||
<C> | ||
<equationType>N3</equationType> | ||
<initialMass>1.0</initialMass> | ||
<decayConstant>$RAVEN-decay-C:0.000000008$</decayConstant> | ||
<sigma>$RAVEN-sigma-C:3$</sigma> | ||
<ANumber>150</ANumber> | ||
</C> | ||
<D> | ||
<equationType>N4</equationType> | ||
<initialMass>1.0</initialMass> | ||
<decayConstant>$RAVEN-decay-D:0.000000009$</decayConstant> | ||
<sigma>$RAVEN-sigma-D:1$</sigma> | ||
<ANumber>100</ANumber> | ||
</D> | ||
</nuclides> | ||
</AnalyticalBateman> | ||
|
181 changes: 181 additions & 0 deletions
181
...neticAlgorithms/continuous/unconstrained/test_ensembleModel_withGA_Code_and_Functions.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<?xml version="1.0" ?> | ||
<Simulation verbosity="debug"> | ||
<TestInfo> | ||
<name>framework/Optimizers/GeneticAlgorithms.GAwithEnsembleModelIncludingCode</name> | ||
<author>alfoa</author> | ||
<created>2024-05-07</created> | ||
<classesTested>Models.EnsembleModel, Optimizers.GeneticAlgorithm</classesTested> | ||
<description> | ||
This test is aimed to test the usage of the GeneticAlgorithm with an EnsembleModel, including | ||
a model Code. This test has been created to test the modifications performed to address issue | ||
#2304 (see \\url{https://github.com/idaholab/raven/issues/2304}). | ||
</description> | ||
</TestInfo> | ||
|
||
<RunInfo> | ||
<JobName>metaModelWithCodeAndFunctionsAndGenetic</JobName> | ||
<Sequence> | ||
optimize | ||
</Sequence> | ||
<WorkingDir>metaModelWithCodeAndFunctionsAndGenetic</WorkingDir> | ||
<batchSize>1</batchSize> | ||
</RunInfo> | ||
|
||
<Files> | ||
<Input name="referenceInput.xml" type="input">referenceInput.xml</Input> | ||
</Files> | ||
|
||
<Models> | ||
<Code name="testModel" subType="GenericCode"> | ||
<executable>../../../../user_guide/physicalCode/analyticalbateman/AnalyticalDplMain.py</executable> | ||
<clargs arg="python" type="prepend"/> | ||
<clargs arg="" extension=".xml" type="input"/> | ||
<clargs arg=" " extension=".csv" type="output"/> | ||
<prepend>python</prepend> | ||
</Code> | ||
<ExternalModel ModuleToLoad="ABCDsum" name="sumOfABCD" subType=""> | ||
<inputs>A,B,C,D</inputs> | ||
<outputs>sum</outputs> | ||
</ExternalModel> | ||
<EnsembleModel name="codeAndExtModel" subType=""> | ||
<Model class="Models" type="ExternalModel"> | ||
sumOfABCD | ||
<Input class="DataObjects" type="PointSet">inputPlaceHolderForInternalObjects</Input> | ||
<TargetEvaluation class="DataObjects" type="PointSet">sumData</TargetEvaluation> | ||
</Model> | ||
<Model class="Models" type="Code"> | ||
testModel | ||
<Input class="Files" type="">referenceInput.xml</Input> | ||
<TargetEvaluation class="DataObjects" type="PointSet">samplesMC</TargetEvaluation> | ||
</Model> | ||
</EnsembleModel> | ||
</Models> | ||
|
||
<Distributions> | ||
<Uniform name="sigma"> | ||
<lowerBound>0</lowerBound> | ||
<upperBound>1000</upperBound> | ||
</Uniform> | ||
<Uniform name="decayConstant"> | ||
<lowerBound>0.00000001</lowerBound> | ||
<upperBound>0.0000001</upperBound> | ||
</Uniform> | ||
</Distributions> | ||
|
||
<Optimizers> | ||
<GeneticAlgorithm name="GAopt"> | ||
<samplerInit> | ||
<limit>20</limit> | ||
<initialSeed>42</initialSeed> | ||
<writeSteps>every</writeSteps> | ||
</samplerInit> | ||
|
||
<GAparams> | ||
<populationSize>2</populationSize> | ||
<parentSelection>rouletteWheel</parentSelection> | ||
<reproduction> | ||
<crossover type="onePointCrossover"> | ||
<crossoverProb>0.8</crossoverProb> | ||
</crossover> | ||
<mutation type="swapMutator"> | ||
<mutationProb>0.9</mutationProb> | ||
</mutation> | ||
</reproduction> | ||
<fitness type="feasibleFirst"></fitness> | ||
<survivorSelection>fitnessBased</survivorSelection> | ||
</GAparams> | ||
|
||
<convergence> | ||
<AHDp>0.0</AHDp> | ||
</convergence> | ||
|
||
<variable name="sigma-A"> | ||
<distribution>sigma</distribution> | ||
</variable> | ||
<variable name="decay_A"> | ||
<distribution>decayConstant</distribution> | ||
</variable> | ||
<variable name="sigma-B"> | ||
<distribution>sigma</distribution> | ||
</variable> | ||
<variable name="decay_B"> | ||
<function>decayConstantB</function> | ||
</variable> | ||
|
||
<objective>sum</objective> | ||
<TargetEvaluation class="DataObjects" type="PointSet">finalResponses</TargetEvaluation> | ||
<Sampler class="Samplers" type="MonteCarlo">MC_samp</Sampler> | ||
</GeneticAlgorithm> | ||
</Optimizers> | ||
|
||
<Functions> | ||
<External file="decayConstantB.py" name="decayConstantB"> | ||
<variables>decay_A</variables> | ||
</External> | ||
</Functions> | ||
|
||
<Samplers> | ||
<MonteCarlo name="MC_samp"> | ||
<samplerInit> | ||
<limit>2</limit> | ||
<initialSeed>20021986</initialSeed> | ||
</samplerInit> | ||
<variable name="sigma-A"> | ||
<distribution>sigma</distribution> | ||
</variable> | ||
<variable name="decay_A"> | ||
<distribution>decayConstant</distribution> | ||
</variable> | ||
<variable name="sigma-B"> | ||
<distribution>sigma</distribution> | ||
</variable> | ||
<variable name="decay_B"> | ||
<function>decayConstantB</function> | ||
</variable> | ||
</MonteCarlo> | ||
</Samplers> | ||
|
||
<Steps> | ||
<MultiRun name="optimize"> | ||
<Input class="Files" type="">referenceInput.xml</Input> | ||
<Input class="DataObjects" type="PointSet">inputPlaceHolderForInternalObjects</Input> | ||
<Model class="Models" type="EnsembleModel">codeAndExtModel</Model> | ||
<Optimizer class="Optimizers" type="GeneticAlgorithm">GAopt</Optimizer> | ||
<SolutionExport class="DataObjects" type="PointSet">opt_export</SolutionExport> | ||
<Output class="DataObjects" type="PointSet">finalResponses</Output> | ||
<Output class="OutStreams" type="Print">opt_export</Output> | ||
</MultiRun> | ||
</Steps> | ||
|
||
<OutStreams> | ||
<Print name="opt_export"> | ||
<type>csv</type> | ||
<source>opt_export</source> | ||
<what>input,output</what> | ||
</Print> | ||
</OutStreams> | ||
|
||
<DataObjects> | ||
<PointSet name="samplesMC"> | ||
<Input>sigma-A,sigma-B,decay_A,decay_B</Input> | ||
<Output>A,B,C,D</Output> | ||
</PointSet> | ||
<PointSet name="inputPlaceHolderForInternalObjects"> | ||
<Input>A,B,C,D</Input> | ||
<Output>OutputPlaceHolder</Output> | ||
</PointSet> | ||
<PointSet name="sumData"> | ||
<Input>A,B,C,D</Input> | ||
<Output>sum</Output> | ||
</PointSet> | ||
<PointSet name="finalResponses"> | ||
<Input>sigma-A,sigma-B,decay_A,decay_B</Input> | ||
<Output>A,B,C,D,sum</Output> | ||
</PointSet> | ||
<PointSet name="opt_export"> | ||
<Input>trajID</Input> | ||
<Output>sigma-A,sigma-B,decay_A,decay_B,sum,age,batchId,fitness,iteration,accepted,AHDp,conv_AHDp</Output> | ||
</PointSet> | ||
</DataObjects> | ||
|
||
</Simulation> |
39 changes: 39 additions & 0 deletions
39
...thms/gold/continuous/unconstrained/metaModelWithCodeAndFunctionsAndGenetic/opt_export.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
trajID,sigma-A,sigma-B,decay_A,decay_B,sum,age,batchId,fitness,iteration,accepted,AHDp,conv_AHDp | ||
0,812.997460787,464.508307042,1.255650268e-08,0.000100012556503,3.15760954156,0,1,-3.15760954156,0,first,,False | ||
0,759.507928453,912.545952926,8.14640085566e-08,0.000100081464009,2.90476176926,0,1,-2.90476176926,0,first,,False | ||
0,912.545952926,812.997460787,1.255650268e-08,0.000100012556503,3.15873736407,0,2,-3.15873736407,1,accepted,299.428022512,False | ||
0,464.508307042,759.507928453,8.14640085566e-08,0.000100081464009,2.83929690449,0,2,-2.83929690449,1,accepted,299.428022512,False | ||
0,794.044539517,912.545952926,5.18057476338e-08,0.000100051805748,2.98393998882,1,3,-2.98393998882,2,accepted,261.653404312,False | ||
0,794.044539517,759.507928453,7.83557135608e-08,0.000100078355714,2.9174761674,1,3,-2.9174761674,2,accepted,261.653404312,False | ||
0,912.545952926,464.508307042,8.14640085566e-08,0.000100081464009,2.93136915288,2,4,-2.93136915288,3,accepted,379.964041465,False | ||
0,759.507928453,759.507928453,8.14640085566e-08,0.000100081464009,2.90491165751,2,4,-2.90491165751,3,accepted,379.964041465,False | ||
0,464.508307042,912.545952926,8.14640085566e-08,0.000100081464009,2.83915821533,3,5,-2.83915821533,4,accepted,154.98621892,False | ||
0,794.044539517,759.507928453,7.83557135608e-08,0.000100078355714,2.9174761674,3,5,-2.9174761674,4,accepted,154.98621892,False | ||
0,912.545952926,464.508307042,8.14640085566e-08,0.000100081464009,2.93136915288,3,6,-2.93136915288,5,accepted,484.155218746,False | ||
0,759.507928453,464.508307042,8.14640085566e-08,0.000100081464009,2.90520071484,3,6,-2.90520071484,5,accepted,484.155218746,False | ||
0,912.545952926,464.508307042,8.14640085566e-08,0.000100081464009,2.93136915288,4,7,-2.93136915288,6,accepted,484.155218746,False | ||
0,759.507928453,464.508307042,8.14640085566e-08,0.000100081464009,2.90520071484,4,7,-2.90520071484,6,accepted,484.155218746,False | ||
0,794.044539517,759.507928453,5.18057476338e-08,0.000100051805748,2.98410104597,5,8,-2.98410104597,7,accepted,329.536232476,False | ||
0,794.044539517,912.545952926,5.18057476338e-08,0.000100051805748,2.98393998882,5,8,-2.98393998882,7,accepted,329.536232476,False | ||
0,794.044539517,759.507928453,5.18057476338e-08,0.000100051805748,2.98410104597,6,9,-2.98410104597,8,accepted,261.553081047,False | ||
0,464.508307042,912.545952926,8.14640085566e-08,0.000100081464009,2.83915821533,6,9,-2.83915821533,8,accepted,261.553081047,False | ||
0,794.044539517,912.545952926,5.18057476338e-08,0.000100051805748,2.98393998882,4,10,-2.98393998882,9,accepted,329.536232476,False | ||
0,794.044539517,912.545952926,5.18057476338e-08,0.000100051805748,2.98393998882,4,10,-2.98393998882,9,accepted,329.536232476,False | ||
0,464.508307042,794.044539517,9.21291357633e-08,0.000100092129136,2.81925891819,5,11,-2.81925891819,10,accepted,118.501413408,False | ||
0,464.508307042,794.044539517,9.21291357633e-08,0.000100092129136,2.81925891819,5,11,-2.81925891819,10,accepted,118.501413408,False | ||
0,464.508307042,912.545952926,8.14640085566e-08,0.000100081464009,2.83915821533,0,12,-2.83915821533,11,accepted,118.501413408,False | ||
0,464.508307042,912.545952926,8.14640085566e-08,0.000100081464009,2.83915821533,0,12,-2.83915821533,11,accepted,118.501413408,False | ||
0,464.508307042,794.044539517,9.21291357633e-08,0.000100092129136,2.81925891819,1,13,-2.81925891819,12,accepted,94.054634152,False | ||
0,464.508307042,912.545952926,8.14640085566e-08,0.000100081464009,2.83915821533,1,13,-2.83915821533,12,accepted,94.054634152,False | ||
0,912.545952926,794.044539517,5.18057476338e-08,0.000100051805748,3.00110960171,2,14,-3.00110960171,13,accepted,448.037645884,False | ||
0,912.545952926,794.044539517,5.18057476338e-08,0.000100051805748,3.00110960171,2,14,-3.00110960171,13,accepted,448.037645884,False | ||
0,912.545952926,794.044539517,5.18057476338e-08,0.000100051805748,3.00110960171,3,15,-3.00110960171,14,accepted,448.037645884,False | ||
0,912.545952926,794.044539517,5.18057476338e-08,0.000100051805748,3.00110960171,3,15,-3.00110960171,14,accepted,448.037645884,False | ||
0,794.044539517,464.508307042,9.21291357633e-08,0.000100092129136,2.89183632446,4,16,-2.89183632446,15,accepted,369.891914497,False | ||
0,464.508307042,794.044539517,9.21291357633e-08,0.000100092129136,2.81925891819,4,16,-2.81925891819,15,accepted,369.891914497,False | ||
0,794.044539517,464.508307042,9.21291357633e-08,0.000100092129136,2.89183632446,3,17,-2.89183632446,16,accepted,466.03460926,False | ||
0,794.044539517,464.508307042,9.21291357633e-08,0.000100092129136,2.89183632446,3,17,-2.89183632446,16,accepted,466.03460926,False | ||
0,794.044539517,464.508307042,9.21291357633e-08,0.000100092129136,2.89183632446,4,18,-2.89183632446,17,accepted,466.03460926,False | ||
0,794.044539517,464.508307042,9.21291357633e-08,0.000100092129136,2.89183632446,4,18,-2.89183632446,17,accepted,466.03460926,False | ||
0,464.508307042,912.545952926,8.14640085566e-08,0.000100081464009,2.83915821533,5,19,-2.83915821533,18,accepted,94.054634152,False | ||
0,464.508307042,794.044539517,9.21291357633e-08,0.000100092129136,2.81925891819,5,19,-2.81925891819,18,accepted,94.054634152,False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested it with different batch size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ops. Not yet. let me test it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wangcj05 I fixed the parallel execution and converted the test into a parallel (batchSize > 1) to test it.
Ready for re-review