-
Notifications
You must be signed in to change notification settings - Fork 136
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
Extend Restart to Adaptive samplers #1283
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
43c2919
extraneous tracked file?
PaulTalbot-INL a36cbdb
Merge branch 'devel' of github.com:PaulTalbot-INL/raven into devel
PaulTalbot-INL 857faa0
Merge branch 'devel' of github.com:PaulTalbot-INL/raven into devel
PaulTalbot-INL 148adb6
matching remote devel
PaulTalbot-INL 311a4a1
Merge branch 'devel' of https://github.com/idaholab/raven into devel
PaulTalbot-INL 0883db4
Merge branch 'devel' of https://github.com/idaholab/raven into devel
PaulTalbot-INL c7f3f82
Merge branch 'devel' of https://github.com/idaholab/raven into devel
PaulTalbot-INL bf48a5c
implemented and tested
PaulTalbot-INL 85c537c
accidental inclusion
PaulTalbot-INL 39fe944
reverted heron version
PaulTalbot-INL 5bb0ca3
right heron version for devel currently
PaulTalbot-INL b5a941b
typo
PaulTalbot-INL 3c1f0e2
add restart to adaptive MC xsd
PaulTalbot-INL bec534c
review comments
PaulTalbot-INL a148fc1
Merge branch 'devel' of https://github.com/idaholab/raven into devel
PaulTalbot-INL 6d44d82
pulled devel
PaulTalbot-INL 6b67311
review comments
PaulTalbot-INL 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
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,89 @@ | ||
# 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. | ||
""" | ||
Created on July 17, 2020 | ||
""" | ||
#for future compatibility with Python 3-------------------------------------------------------------- | ||
from __future__ import division, print_function, unicode_literals, absolute_import | ||
#End compatibility block for Python 3---------------------------------------------------------------- | ||
|
||
import numpy as np | ||
from .Runner import Runner | ||
|
||
class PassthroughRunner(Runner): | ||
""" | ||
A runner for when we already have the answer, but need to go through the mechanics. | ||
""" | ||
def __init__(self, messageHandler, data, metadata=None, uniqueHandler="any", profile=False): | ||
""" | ||
Init method | ||
@ In, messageHandler, MessageHandler object, the global RAVEN message | ||
handler object | ||
@ In, data, dict, fully-evaluated realization | ||
@ In, metadata, dict, optional, dictionary of metadata associated with | ||
this run | ||
@ In, uniqueHandler, string, optional, it is a special keyword attached to | ||
this runner. For example, if present, to retrieve this runner using the | ||
method jobHandler.getFinished, the uniqueHandler needs to be provided. | ||
If uniqueHandler == 'any', every "client" can get this runner | ||
@ In, profile, bool, optional, if True then at deconstruction timing statements will be printed | ||
@ Out, None | ||
""" | ||
super(PassthroughRunner, self).__init__(messageHandler, metadata=metadata, uniqueHandler=uniqueHandler, profile=profile) | ||
self._data = data # realization with completed data | ||
self.returnCode = 0 # passthrough was born successful | ||
|
||
def isDone(self): | ||
""" | ||
Method to check if the calculation associated with this Runner is finished | ||
@ In, None | ||
@ Out, isDone, bool, is it finished? | ||
""" | ||
return True # passthrough was born done | ||
|
||
def getReturnCode(self): | ||
""" | ||
Returns the return code from "running the code." | ||
@ In, None | ||
@ Out, returnCode, int, the return code of this evaluation | ||
""" | ||
return self.returnCode | ||
|
||
def getEvaluation(self): | ||
""" | ||
Return solution. | ||
@ In, None | ||
@ Out, result, dict, results | ||
""" | ||
result = {} | ||
result.update(dict((key, np.atleast_1d(value)) for key, value in self._data['inputs'].items())) | ||
result.update(dict((key, np.atleast_1d(value)) for key, value in self._data['outputs'].items())) | ||
result.update(dict((key, np.atleast_1d(value)) for key, value in self._data['metadata'].items())) | ||
return result | ||
|
||
def start(self): | ||
""" | ||
Method to start the job associated to this Runner | ||
@ In, None | ||
@ Out, None | ||
""" | ||
pass # passthrough was born done | ||
|
||
def kill(self): | ||
""" | ||
Method to kill the job associated to this Runner | ||
@ In, None | ||
@ Out, None | ||
""" | ||
pass # passthrough was born done; you can't kill it |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
<?xml version="1.0" ?> | ||
<Simulation verbosity="debug"> | ||
<TestInfo> | ||
<name>framework/Samplers/Restart.AMC</name> | ||
<author>talbpaul</author> | ||
<created>2020-07-16</created> | ||
<classesTested>Samplers.AdaptiveMonteCarlo</classesTested> | ||
<description> | ||
Tests restarting an Adaptive Monte Carlo sampling from restart. \texttt{makeCoarse} samples initial data, then \texttt{makeRestart} | ||
makes additional samples, restarting from the first set of samples. \texttt{makeFine} does all the samples without restart | ||
for comparison. The model for \texttt{coarse} always returns a value of 1, while the model for \texttt{restart} returns a value of 2, so | ||
you can tell which samples came from which sampling strategy. Further, the solution export for | ||
the restart should contain all the sample points, not merely the newly-sampled points. | ||
</description> | ||
</TestInfo> | ||
|
||
<RunInfo> | ||
<WorkingDir>AMC</WorkingDir> | ||
<Sequence>makeCoarse,makeRestart,makeFine,print</Sequence> | ||
</RunInfo> | ||
|
||
<Steps> | ||
<MultiRun name="makeCoarse"> | ||
<Input class="DataObjects" type="PointSet">dummyIN</Input> | ||
<Model class="Models" type="ExternalModel">coarsemod</Model> | ||
<Sampler class="Samplers" type="AdaptiveMonteCarlo">coarse</Sampler> | ||
<SolutionExport class="DataObjects" type="PointSet">exportCoarse</SolutionExport> | ||
<Output class="DataObjects" type="PointSet">solns</Output> | ||
</MultiRun> | ||
<MultiRun name="makeFine"> | ||
<Input class="DataObjects" type="PointSet">dummyIN</Input> | ||
<Model class="Models" type="ExternalModel">finemod</Model> | ||
<Sampler class="Samplers" type="AdaptiveMonteCarlo">fine</Sampler> | ||
<SolutionExport class="DataObjects" type="PointSet">exportFine</SolutionExport> | ||
<Output class="DataObjects" type="PointSet">solnsFine</Output> | ||
</MultiRun> | ||
<MultiRun name="makeRestart"> | ||
<Input class="DataObjects" type="PointSet">solns</Input> | ||
<Model class="Models" type="ExternalModel">finemod</Model> | ||
<Sampler class="Samplers" type="AdaptiveMonteCarlo">restart</Sampler> | ||
<SolutionExport class="DataObjects" type="PointSet">exportRestart</SolutionExport> | ||
<Output class="DataObjects" type="PointSet">solnsRestart</Output> | ||
</MultiRun> | ||
<IOStep name="print"> | ||
<Input class="DataObjects" type="PointSet">solns</Input> | ||
<Input class="DataObjects" type="PointSet">solnsFine</Input> | ||
<Input class="DataObjects" type="PointSet">solnsRestart</Input> | ||
<Input class="DataObjects" type="PointSet">exportCoarse</Input> | ||
<Input class="DataObjects" type="PointSet">exportFine</Input> | ||
<Input class="DataObjects" type="PointSet">exportRestart</Input> | ||
<Output class="OutStreams" type="Print">coarse</Output> | ||
<Output class="OutStreams" type="Print">fine</Output> | ||
<Output class="OutStreams" type="Print">restart</Output> | ||
<Output class="OutStreams" type="Print">exp_coarse</Output> | ||
<Output class="OutStreams" type="Print">exp_fine</Output> | ||
<Output class="OutStreams" type="Print">exp_restart</Output> | ||
</IOStep> | ||
</Steps> | ||
|
||
<Distributions> | ||
<Uniform name="u1"> | ||
<lowerBound>1</lowerBound> | ||
<upperBound>2</upperBound> | ||
</Uniform> | ||
<Uniform name="u2"> | ||
<lowerBound>2</lowerBound> | ||
<upperBound>3</upperBound> | ||
</Uniform> | ||
</Distributions> | ||
|
||
<Samplers> | ||
<AdaptiveMonteCarlo name="coarse"> | ||
<TargetEvaluation class="DataObjects" type="PointSet">solns</TargetEvaluation> | ||
<Convergence> | ||
<limit>50</limit> | ||
<persistence>5</persistence> | ||
<forceIteration>False</forceIteration> | ||
<expectedValue prefix="mean" tol="5e-1">x1</expectedValue> | ||
</Convergence> | ||
<initialSeed>42</initialSeed> | ||
<variable name="x1"> | ||
<distribution>u1</distribution> | ||
</variable> | ||
<variable name="x2"> | ||
<distribution>u2</distribution> | ||
</variable> | ||
</AdaptiveMonteCarlo> | ||
<AdaptiveMonteCarlo name="restart"> | ||
<TargetEvaluation class="DataObjects" type="PointSet">solnsRestart</TargetEvaluation> | ||
<Convergence> | ||
<limit>50</limit> | ||
<persistence>5</persistence> | ||
<forceIteration>False</forceIteration> | ||
<expectedValue prefix="mean" tol="1e-1">x1</expectedValue> | ||
</Convergence> | ||
<initialSeed>42</initialSeed> | ||
<variable name="x1"> | ||
<distribution>u1</distribution> | ||
</variable> | ||
<variable name="x2"> | ||
<distribution>u2</distribution> | ||
</variable> | ||
<Restart class="DataObjects" type="PointSet">solns</Restart> | ||
</AdaptiveMonteCarlo> | ||
<AdaptiveMonteCarlo name="fine"> | ||
<TargetEvaluation class="DataObjects" type="PointSet">solnsFine</TargetEvaluation> | ||
<Convergence> | ||
<limit>50</limit> | ||
<persistence>5</persistence> | ||
<forceIteration>False</forceIteration> | ||
<expectedValue prefix="mean" tol="1e-1">x1</expectedValue> | ||
</Convergence> | ||
<initialSeed>42</initialSeed> | ||
<variable name="x1"> | ||
<distribution>u1</distribution> | ||
</variable> | ||
<variable name="x2"> | ||
<distribution>u2</distribution> | ||
</variable> | ||
</AdaptiveMonteCarlo> | ||
</Samplers> | ||
|
||
<Models> | ||
<Dummy name="MyDummy" subType=""/> | ||
<ExternalModel ModuleToLoad="../coarse" name="coarsemod" subType=""> | ||
<variables>x1,x2,ans</variables> | ||
</ExternalModel> | ||
<ExternalModel ModuleToLoad="../fine" name="finemod" subType=""> | ||
<variables>x1,x2,ans</variables> | ||
</ExternalModel> | ||
</Models> | ||
|
||
<DataObjects> | ||
<PointSet name="dummyIN"> | ||
<Input>x1,x2</Input> | ||
<Output>OutputPlaceHolder</Output> | ||
</PointSet> | ||
<PointSet name="solns"> | ||
<Input>x1,x2</Input> | ||
<Output>ans</Output> | ||
</PointSet> | ||
<PointSet name="solnsFine"> | ||
<Input>x1,x2</Input> | ||
<Output>ans</Output> | ||
</PointSet> | ||
<PointSet name="solnsRestart"> | ||
<Input>x1,x2</Input> | ||
<Output>ans</Output> | ||
</PointSet> | ||
<PointSet name="exportCoarse"> | ||
<Input>solutionUpdate</Input> | ||
<Output>mean_x1,mean_ste_x1</Output> | ||
</PointSet> | ||
<PointSet name="exportFine"> | ||
<Input>solutionUpdate</Input> | ||
<Output>mean_x1,mean_ste_x1</Output> | ||
</PointSet> | ||
<PointSet name="exportRestart"> | ||
<Input>solutionUpdate</Input> | ||
<Output>mean_x1,mean_ste_x1</Output> | ||
</PointSet> | ||
</DataObjects> | ||
|
||
<OutStreams> | ||
<Print name="coarse"> | ||
<type>csv</type> | ||
<source>solns</source> | ||
<what>input,output</what> | ||
</Print> | ||
<Print name="fine"> | ||
<type>csv</type> | ||
<source>solnsFine</source> | ||
<what>input,output</what> | ||
</Print> | ||
<Print name="restart"> | ||
<type>csv</type> | ||
<source>solnsRestart</source> | ||
<what>input,output</what> | ||
</Print> | ||
<Print name="exp_coarse"> | ||
<type>csv</type> | ||
<source>exportCoarse</source> | ||
<what>input,output</what> | ||
</Print> | ||
<Print name="exp_fine"> | ||
<type>csv</type> | ||
<source>exportFine</source> | ||
<what>input,output</what> | ||
</Print> | ||
<Print name="exp_restart"> | ||
<type>csv</type> | ||
<source>exportRestart</source> | ||
<what>input,output</what> | ||
</Print> | ||
</OutStreams> | ||
|
||
</Simulation> |
Oops, something went wrong.
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.
I think we do not need this import anymore.
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.
I believe the linter will error if it doesn't find this. We should change this globally, as a separate action.
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.
@alfoa I think you are trying to remove the
__future__
import, right?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.
I think we removed the check on that because it is not needed anymore... @joshua-cogliati-inl ???
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.
Yes we removed it. we can remove the "future" (I know we need to do that to the other files too...I will take care of it)