Skip to content

Commit

Permalink
Fix scaling issue in DataSet when Grid sampler is used as restart. (#730
Browse files Browse the repository at this point in the history
)

* fix std in data comparison

* add test to test restart with constant variables, test issue #690

* rename folder name, since 'con' is not acceptable in windows
  • Loading branch information
wangcj05 authored and alfoa committed Aug 26, 2018
1 parent ff22bb1 commit 66cb533
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
4 changes: 4 additions & 0 deletions framework/DataObjects/DataSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,10 @@ def _getRealizationFromDataByValue(self,match, tol=1e-15, unpackXArray=False):
# variable doesn't have a scale factor (yet? Why not?)
loc = 0.0
scale = 1.0
if scale == 0:
# TODO: Seem to me, we need to find a better way to compare data
# The scale will be zero if Grid Sampler is used, reset to 1.0
scale = 1.0
scaleVal = (val-loc)/scale
# create mask of where the dataarray matches the desired value
mask *= abs((self._data[var]-loc)/scale - scaleVal) < tol
Expand Down
3 changes: 3 additions & 0 deletions tests/framework/Samplers/Restart/gold/constant/coarse.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x1,x2,ans
1.0,2.0,1.0
2.0,2.0,1.0
10 changes: 10 additions & 0 deletions tests/framework/Samplers/Restart/gold/constant/restart.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
x1,x2,ans
1.0,2.0,1.0
1.0,2.5,2.0
1.0,3.0,2.0
1.5,2.0,2.0
1.5,2.5,2.0
1.5,3.0,2.0
2.0,2.0,1.0
2.0,2.5,2.0
2.0,3.0,2.0
113 changes: 113 additions & 0 deletions tests/framework/Samplers/Restart/test_restart_constant.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" ?>
<Simulation verbosity="debug">
<TestInfo>
<name>framework/Samplers/Restart.Constant</name>
<author>wangc</author>
<created>2018-08-04</created>
<classesTested>Samplers.Grid</classesTested>
<description>
The essence of this test is to demonstrate the restart capability with constant variable,
i.e. test the scaling factor for constant samples as mentioned in issue #690
</description>
</TestInfo>

<RunInfo>
<WorkingDir>constant</WorkingDir>
<Sequence>makeCoarse, makeFineRestart,print</Sequence>
<batchSize>1</batchSize>
</RunInfo>

<Steps>
<MultiRun name="makeCoarse">
<Input class="DataObjects" type="PointSet">dummyIN</Input>
<Model class="Models" type="ExternalModel">coarsemod</Model>
<Sampler class="Samplers" type="Grid">coarse</Sampler>
<Output class="DataObjects" type="PointSet">solns</Output>
</MultiRun>
<MultiRun name="makeFineRestart">
<Input class="DataObjects" type="PointSet">solns</Input>
<Model class="Models" type="ExternalModel">finemod</Model>
<Sampler class="Samplers" type="Grid">fineRestart</Sampler>
<Output class="DataObjects" type="PointSet">solnsRestart</Output>
</MultiRun>
<IOStep name="print">
<Input class="DataObjects" type="PointSet">solns</Input>
<Input class="DataObjects" type="PointSet">solnsRestart</Input>
<Output class="OutStreams" type="Print">coarse</Output>
<Output class="OutStreams" type="Print">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>
<Grid name="coarse">
<variable name="x1">
<distribution>u1</distribution>
<grid construction="equal" steps="1" type="CDF">0.0 1.0</grid>
</variable>
<constant name="x2">2.0</constant>
</Grid>
<Grid name="fineRestart">
<variable name="x1">
<distribution>u1</distribution>
<grid construction="equal" steps="2" type="CDF">0.0 1.0</grid>
</variable>
<variable name="x2">
<distribution>u2</distribution>
<grid construction="equal" steps="2" type="CDF">0.0 1.0</grid>
</variable>
<Restart class="DataObjects" type="PointSet">solns</Restart>
</Grid>
</Samplers>

<Models>
<Dummy name="MyDummy" subType=""/>
<!-- The "coarsemod" model will output a reponse of 1.0, while "finemod" gives 2.0.
This allows the test to distinguish which samples originated in "coarse" and which in "fine".-->
<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="solnsRestart">
<Input>x1,x2</Input>
<Output>ans</Output>
</PointSet>
</DataObjects>

<OutStreams>
<Print name="coarse">
<type>csv</type>
<source>solns</source>
<what>input,output</what>
</Print>
<Print name="restart">
<type>csv</type>
<source>solnsRestart</source>
<what>input,output</what>
</Print>
</OutStreams>

</Simulation>
7 changes: 7 additions & 0 deletions tests/framework/Samplers/Restart/tests
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@
output = 'large/large_restart.xml'
UnorderedCsv = 'large/large_restart.csv'
[../]

[./Constant]
type = 'RavenFramework'
input = 'test_restart_constant.xml'
UnorderedCsv = 'constant/coarse.csv constant/restart.csv'
remove_unicode_identifier = true
[../]
[]

0 comments on commit 66cb533

Please sign in to comment.