/
test_suiteBuilder.py
80 lines (66 loc) · 2.63 KB
/
test_suiteBuilder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright 2019 TerraPower, 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.
"""
Unit tests for the SuiteBuilder
"""
import os
import unittest
from armi import cases, settings
from armi.cases.inputModifiers.inputModifiers import SamplingInputModifier
from armi.cases.suiteBuilder import LatinHyperCubeSuiteBuilder
cs = settings.Settings(
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"..",
"..",
"tests",
"tutorials",
"anl-afci-177.yaml",
)
)
case = cases.Case(cs)
class LatinHyperCubeModifier(SamplingInputModifier):
def __init__(self, name, paramType: str, bounds: list, independentVariable=None):
super().__init__(
name, paramType, bounds, independentVariable=independentVariable
)
self.value = None
def __call__(self, cs, bp, geom):
cs = cs.modified(newSettings={self.name: self.value})
return cs, bp, geom
class TestLatinHyperCubeSuiteBuilder(unittest.TestCase):
"""Class to test LatinHyperCubeSuiteBuilder."""
def testInitialize(self):
builder = LatinHyperCubeSuiteBuilder(case, size=20)
assert builder.modifierSets == []
def test_buildSuite(self):
builder = LatinHyperCubeSuiteBuilder(case, size=20)
powerMod = LatinHyperCubeModifier("power", "continuous", [0, 1e6])
availabilityMod = LatinHyperCubeModifier(
"availabilityFactor", "discrete", [0.0, 0.2, 0.4, 0.6, 0.8]
)
builder.addDegreeOfFreedom([powerMod, availabilityMod])
builder.buildSuite()
assert len(builder.modifierSets) == 20
for mod in builder.modifierSets:
assert 0 < mod[0].value < 1e6
assert mod[1].value in [0.0, 0.2, 0.4, 0.6, 0.8]
def test_addDegreeOfFreedom(self):
builder = LatinHyperCubeSuiteBuilder(case, size=20)
powerMod = LatinHyperCubeModifier("power", "continuous", [0, 1e6])
morePowerMod = LatinHyperCubeModifier("power", "continuous", [1e3, 1e5])
with self.assertRaises(ValueError):
builder.addDegreeOfFreedom([powerMod, morePowerMod])
if __name__ == "__main__":
unittest.main()