Skip to content

Commit

Permalink
Alfoa/generic codeinterface fix (#844)
Browse files Browse the repository at this point in the history
* dai

* oky

* fix generic code interface (parsing)

* ok

* removed trailingspaces

* Update test_BasicStatistics.xml

* addrressed comments

* fixed test
  • Loading branch information
alfoa authored and PaulTalbot-INL committed Nov 16, 2018
1 parent 82ce63a commit f31a0a4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 42 deletions.
2 changes: 1 addition & 1 deletion framework/CodeInterfaces/Generic/GenericCodeInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,5 @@ def createNewInput(self,currentInputFiles,origInputFiles,samplerType,**Kwargs):
origfiles.append(inputFile)
parser = GenericParser.GenericParser(infiles)
parser.modifyInternalDictionary(**Kwargs)
parser.writeNewInput(currentInputFiles,origfiles)
parser.writeNewInput(infiles,origfiles)
return currentInputFiles
4 changes: 2 additions & 2 deletions framework/Models/Code.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,8 @@ def submit(self, myInput, samplerType, jobHandler, **kwargs):
a mandatory key is the sampledVars'that contains a dictionary {'name variable':value}
@ Out, None
"""
prefix = kwargs['prefix'] if 'prefix' in kwargs else None
uniqueHandler = kwargs['uniqueHandler'] if 'uniqueHandler' in kwargs.keys() else 'any'
prefix = kwargs.get("prefix")
uniqueHandler = kwargs.get("uniqueHandler",'any')

## These two are part of the current metadata, so they will be added before
## the job is started, so that they will be captured in the metadata and match
Expand Down
37 changes: 4 additions & 33 deletions framework/Models/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,9 @@ def submit(self, myInput, samplerType, jobHandler, **kwargs):
a mandatory key is the sampledVars'that contains a dictionary {'name variable':value}
@ Out, None
"""
prefix = kwargs['prefix'] if 'prefix' in kwargs else None
uniqueHandler = kwargs['uniqueHandler'] if 'uniqueHandler' in kwargs.keys() else 'any'
prefix = kwargs.get("prefix")
uniqueHandler = kwargs.get("uniqueHandler",'any')
forceThreads = kwargs.get("forceThreads",False)

## These kwargs are updated by createNewInput, so the job either should not
## have access to the metadata, or it needs to be updated from within the
Expand All @@ -382,37 +383,7 @@ def submit(self, myInput, samplerType, jobHandler, **kwargs):
## works, we are unable to pass a member function as a job because the
## pp library loses track of what self is, so instead we call it from the
## class and pass self in as the first parameter
jobHandler.addJob((self, myInput, samplerType, kwargs), self.__class__.evaluateSample, prefix, metadata=metadata, modulesToImport=self.mods, uniqueHandler=uniqueHandler)

def submitAsClient(self, myInput, samplerType, jobHandler, **kwargs):
"""
This will submit an individual sample to be evaluated by this model to a
specified jobHandler as a client job. Note, some parameters are needed
by createNewInput and thus descriptions are copied from there.
@ In, myInput, list, the inputs (list) to start from to generate the new
one
@ In, samplerType, string, is the type of sampler that is calling to
generate a new input
@ In, jobHandler, JobHandler instance, the global job handler instance
@ In, **kwargs, dict, is a dictionary that contains the information
coming from the sampler, a mandatory key is the sampledVars' that
contains a dictionary {'name variable':value}
@ Out, None
"""
prefix = kwargs['prefix'] if 'prefix' in kwargs else None
uniqueHandler = kwargs['uniqueHandler'] if 'uniqueHandler' in kwargs.keys() else 'any'

## These kwargs are updated by createNewInput, so the job either should not
## have access to the metadata, or it needs to be updated from within the
## evaluateSample function, which currently is not possible since that
## function does not know about the job instance.
metadata = kwargs

## This may look a little weird, but due to how the parallel python library
## works, we are unable to pass a member function as a job because the
## pp library loses track of what self is, so instead we call it from the
## class and pass self in as the first parameter
jobHandler.addClientJob((self, myInput, samplerType, kwargs), self.__class__.evaluateSample, prefix, metadata=metadata, modulesToImport=self.mods, uniqueHandler=uniqueHandler)
jobHandler.addJob((self, myInput, samplerType, kwargs), self.__class__.evaluateSample, prefix, metadata=metadata, modulesToImport=self.mods, uniqueHandler=uniqueHandler, forceUseThreads=forceThreads)

def addOutputFromExportDictionary(self,exportDict,output,options,jobIdentifier):
"""
Expand Down
8 changes: 2 additions & 6 deletions framework/Models/PostProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,8 @@ def submit(self,myInput,samplerType,jobHandler,**kwargs):
a mandatory key is the sampledVars'that contains a dictionary {'name variable':value}
@ Out, None
"""

## This may look a little weird, but due to how the parallel python library
## works, we are unable to pass a member function as a job because the
## pp library loses track of what self is, so instead we call it from the
## class and pass self in as the first parameter
jobHandler.addJob((self, myInput, samplerType, kwargs), self.__class__.evaluateSample, str(0), modulesToImport=self.mods, forceUseThreads=True)
kwargs['forceThreads'] = True
Model.submit(self,myInput, samplerType, jobHandler,**kwargs)

def evaluateSample(self, myInput, samplerType, kwargs):
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/framework/CodeInterfaceTests/GenericInterface/inp.three
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" ?>
<properties>
<x>10</x>
<z>1</z>
</properties>
3 changes: 3 additions & 0 deletions tests/framework/CodeInterfaceTests/test_generic_interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<Files>
<Input name="one.xml" type="">one.xml</Input>
<Input name="inp.two" type="">inp.two</Input>
<Input name="inp.three" type="">inp.three</Input>
<Input name="mesh" type="">dummy.e</Input>
<Input name="a_dummy_file_for_subdirectory" type="" subDirectory="testSubDirectory">dummy_file_for_subdirectory.dummy</Input>
</Files>
Expand All @@ -36,6 +37,7 @@
<clargs arg="python" type="prepend"/>
<clargs arg="-i" extension=".xml" type="input"/>
<clargs arg="-a" extension=".two" type="input"/>
<clargs arg="-a" extension=".three" type="input"/>
<clargs arg="-o" type="output"/>
</Code>
</Models>
Expand Down Expand Up @@ -68,6 +70,7 @@
<MultiRun name="sample">
<Input class="Files" type="">inp.two</Input>
<Input class="Files" type="">one.xml</Input>
<Input class="Files" type="">inp.three</Input>
<Input class="Files" type="">mesh</Input>
<Input class="Files" type="">a_dummy_file_for_subdirectory</Input>
<Model class="Models" type="Code">poly</Model>
Expand Down

0 comments on commit f31a0a4

Please sign in to comment.