From 6292e52c833ff08cf9d59360735a64fab6d02cac Mon Sep 17 00:00:00 2001 From: Paul Talbot Date: Wed, 12 Jun 2024 14:56:52 -0600 Subject: [PATCH] Arbitrary Custom Input in InputSpec (#2332) * added custom arbitrary input extention to inputspecs and unit test * removing internalParallel for adaptsobol cluster test --- ravenframework/utils/InputData.py | 14 +++-- .../test_adapt_sobol_parallel.xml | 13 ++--- .../unit_tests/utils/testInputData.py | 51 ++++++++++++++++++- 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/ravenframework/utils/InputData.py b/ravenframework/utils/InputData.py index 040d54c8a4..c4aeca69ba 100644 --- a/ravenframework/utils/InputData.py +++ b/ravenframework/utils/InputData.py @@ -148,9 +148,13 @@ def __init__(self): create new instance. @ Out, None """ - self.parameterValues = {} - self.subparts = [] - self.value = "" + self.parameterValues = {} # attributes of the hierarchal input, attached to nodes, but not nodes themselves + self.subparts = [] # pre-defined nodes that are children of this node + self.value = "" # non-hierarchal value associated with this node + # addtionalInput is a List of raven.utils.TreeStructure.InputNode instances. Unlike subparts, these do not have + # a predefined structure, and will not directly be parsed as part of the spec. Only used when + # strictMode is set to False for this node. + self.additionalInput = [] @classmethod def createClass(cls, name, ordered=False, contentType=None, baseNode=None, @@ -464,10 +468,12 @@ def handleError(s): subs = self.subs # read in subnodes subNames = set() + # loop over each of the nodes in the input and find matches in the defined spec for child in node: childName = child.tag subsSet = self._subDict.get(childName,set()) foundSubs = 0 + # loop over defined spec subs and see if there's a match for the input node for sub in subsSet: if sub._checkCanRead is None: subInstance = sub() @@ -482,6 +488,8 @@ def handleError(s): elif self.strictMode: allowed = [s.getName() for s in subs] handleError(f'Unrecognized input node "{childName}"! Allowed: [{", ".join(allowed)}], tried [{", ".join(subsSet)}]') + else: + self.additionalInput.append(child) if self.strictMode: nodeNames = set([child.tag for child in node]) if nodeNames != subNames: diff --git a/tests/cluster_tests/AdaptiveSobol/test_adapt_sobol_parallel.xml b/tests/cluster_tests/AdaptiveSobol/test_adapt_sobol_parallel.xml index a3f919569f..e8024edb2d 100644 --- a/tests/cluster_tests/AdaptiveSobol/test_adapt_sobol_parallel.xml +++ b/tests/cluster_tests/AdaptiveSobol/test_adapt_sobol_parallel.xml @@ -4,8 +4,7 @@ workdir make,train,print 3 - True - 00:10:00 + 00:20:00 test_qsub mpi @@ -14,8 +13,8 @@ - - dummyIN + + placeholder poly sobol solns @@ -65,7 +64,6 @@ - x1,x2,x3,x4 ans,ans2 @@ -80,10 +78,7 @@ - - x1,x2,x3,x4 - OutputPlaceHolder - + x1,x2,x3,x4 ans,ans2 diff --git a/tests/framework/unit_tests/utils/testInputData.py b/tests/framework/unit_tests/utils/testInputData.py index 94f39a61ba..96dbb132a3 100644 --- a/tests/framework/unit_tests/utils/testInputData.py +++ b/tests/framework/unit_tests/utils/testInputData.py @@ -18,19 +18,66 @@ ravenPath = os.path.join(os.path.dirname(__file__), *(['..']*4)) sys.path.append(ravenPath) -from ravenframework.utils import InputData +from ravenframework.utils import InputData, TreeStructure +import xml.etree.ElementTree as ET print('Testing:', InputData) results = {'pass':0, 'fail':0} + + #################################### -# Test InputData creating LaTeX +# Test arbitrary XML spec # +# Write the spec +ASpec = InputData.parameterInputFactory('A', descr='first') +BSpec = InputData.parameterInputFactory('B', descr='second') +BSpec.setStrictMode(False) +ASpec.addSub(BSpec) +# Write the tree +# +# +# unknown +# 42 +# +# +ANode = TreeStructure.InputNode('A') +BNode = TreeStructure.InputNode('B') +TQNode = TreeStructure.InputNode('TheQuestion', attrib={'really': 'True'}, text='unknown') +BNode.append(TQNode) +TANode = TreeStructure.InputNode('TheAnswer', text='42') +BNode.append(TANode) +ANode.append(BNode) +# parse and check +A = ASpec() +A.parseNode(ANode) +B = A.findFirst('B') + +if B.additionalInput[0].tag == 'TheQuestion' and \ + B.additionalInput[0].attrib['really'] == 'True' and\ + B.additionalInput[0].text == 'unknown': + results['pass'] += 1 +else: + print('InputData Arbitrary Custom XML 0 did not match!') + results['fail'] += 1 + +if B.additionalInput[1].tag == 'TheAnswer' and \ + B.additionalInput[1].text == '42': + results['pass'] += 1 +else: + print('InputData Arbitrary Custom XML 1 did not match!') + results['fail'] += 1 + + +#################################### # load libraries for all of RAVEN from ravenframework.CustomDrivers import DriverUtils DriverUtils.doSetup() DriverUtils.setupBuiltins() +#################################### +# Test InputData creating LaTeX +# # test MultiRun Step from ravenframework import Steps