<base>pyobj</base>
</objref>
+ <!-- Types for parametric computations -->
+ <!-- TODO On devrait pouvoir le lire depuis le KERNEL !!!-->
+ <type name="long" kind="int"/>
+ <struct name="SALOME_TYPES/Parameter">
+ <member type="string" name="name"></member>
+ <member type="string" name="value"></member>
+ </struct>
+ <sequence content="SALOME_TYPES/Parameter" name="SALOME_TYPES/ParameterList"></sequence>
+ <sequence content="double" name="Value1D"></sequence>
+ <sequence content="Value1D" name="SALOME_TYPES/Value"></sequence>
+ <sequence content="string" name="SALOME_TYPES/VarList"></sequence>
+ <sequence content="SALOME_TYPES/Value" name="SALOME_TYPES/ValueList"></sequence>
+ <struct name="SALOME_TYPES/ParametricInput">
+ <member type="SALOME_TYPES/VarList" name="inputVarList"></member>
+ <member type="SALOME_TYPES/VarList" name="outputVarList"></member>
+ <member type="SALOME_TYPES/ValueList" name="inputValues"></member>
+ <member type="SALOME_TYPES/ParameterList" name="specificParameters"></member>
+ </struct>
+ <struct name="SALOME_TYPES/ParametricOutput">
+ <member type="SALOME_TYPES/ValueList" name="outputValues"></member>
+ <member type="SALOME_TYPES/ParameterList" name="specificOutputInfos"></member>
+ <member type="long" name="returnCode"></member>
+ <member type="string" name="errorMessage"></member>
+ </struct>
+
+
<inline name="CreateAssimilationStudy">
<script><code>
print "Entering in FakeOptimizerLoopNode"
result = None
]]></code></script>
- <inport name="computation" type="pyobj"/>
+ <inport name="computation" type="SALOME_TYPES/ParametricInput"/>
<outport name="result" type="pyobj"/>
</inline>
#-*- coding: utf-8 -*-
import SALOMERuntime
+import pilot
import pickle
import numpy
import threading
self.sample_counter = 0
self.counter_lock = threading.Lock()
+ def create_sample(self, data, method):
+ sample = pilot.StructAny_New(self.optim_algo.runtime.getTypeCode('SALOME_TYPES/ParametricInput'))
+
+ # TODO Input, Output VarList
+ inputVarList = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("string"))
+ outputVarList = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("string"))
+ inputVarList.pushBack("adao_default")
+ outputVarList.pushBack("adao_default")
+ sample.setEltAtRank("inputVarList", inputVarList)
+ sample.setEltAtRank("outputVarList", outputVarList)
+
+ # Les parametres specifiques à ADAO
+ specificParameters = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("SALOME_TYPES/Parameter"))
+ method_name = pilot.StructAny_New(self.optim_algo.runtime.getTypeCode('SALOME_TYPES/Parameter'))
+ method_name.setEltAtRank("name", "method")
+ method_name.setEltAtRank("value", method)
+ specificParameters.pushBack(method_name)
+ sample.setEltAtRank("specificParameters", specificParameters)
+
+ # Les données
+ # TODO à faire
+ parameter_1D = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("double"))
+ #print data
+ #print data.ndim
+ #print data.shape
+ #print data[:,0]
+ #print data.flatten()
+ #print data.flatten().shape
+ it = data.flat
+ for val in it:
+ print val
+ parameter_1D.pushBack(val)
+ parameter_2D = pilot.SequenceAny_New(parameter_1D.getType())
+ parameter_2D.pushBack(parameter_1D)
+ parameters_3D = pilot.SequenceAny_New(parameter_2D.getType())
+ parameters_3D.pushBack(parameter_2D)
+ sample.setEltAtRank("inputValues", parameters_3D)
+
+ return sample
+
def Direct(self, X, sync = 1):
print "Call Direct OptimizerHooks"
if sync == 1:
local_counter = self.sample_counter
# 2: Put sample in the job pool
- computation = {}
- computation["method"] = "Direct"
- computation["data"] = X
- computation = pickle.dumps(computation)
- self.optim_algo.pool.pushInSample(local_counter, computation)
+ sample = self.create_sample(X, "Direct")
+ self.optim_algo.pool.pushInSample(local_counter, sample)
# 3: Wait
while 1:
self.runtime = SALOMERuntime.getSALOMERuntime()
# Definission des types d'entres et de sorties pour le code de calcul
- self.tin = self.runtime.getTypeCode("pyobj")
+ self.tin = self.runtime.getTypeCode("SALOME_TYPES/ParametricInput")
self.tout = self.runtime.getTypeCode("pyobj")
self.optim_hooks = OptimizerHooks(self)
def getTCForOut(self):
return self.tout
def getTCForAlgoInit(self):
- return self.tin
+ return self.tout
def getTCForAlgoResult(self):
return self.tout
runtime = pilot.getRuntime()
try:
catalogAd = runtime.loadCatalog("proc", os.environ["ADAO_ROOT_DIR"] + "/share/salome/resources/adao/ADAOSchemaCatalog.xml")
+ runtime.addCatalog(catalogAd)
except:
logging.fatal("Exception in loading DataAssim YACS catalog")
traceback.print_exc()
# Starting creating proc
proc = runtime.createProc("proc")
proc.setTypeCode("pyobj", runtime.getTypeCode("pyobj"))
+ proc.setTypeCode("SALOME_TYPES/ParametricInput", catalogAd._typeMap["SALOME_TYPES/ParametricInput"])
t_pyobj = proc.getTypeCode("pyobj")
t_string = proc.getTypeCode("string")
-
+ t_param_input = proc.getTypeCode("SALOME_TYPES/ParametricInput")
repertory = False
base_repertory = ""
if "Repertory" in study_config.keys():
traceback.print_exc()
sys.exit(1)
opt_script_node.setScript(script_str.read())
- opt_script_node.edAddInputPort("computation", t_pyobj)
+ opt_script_node.edAddInputPort("computation", t_param_input)
opt_script_node.edAddOutputPort("result", t_pyobj)
# Add it
import numpy
import pickle
-print computation["method"]
+print computation
+method = ""
+for param in computation["specificParameters"]:
+ if param["name"] == "method":
+ method = param["value"]
+print "Method found is", method
dimension = 300
-
H = numpy.matrix(numpy.core.identity(dimension))
def FunctionH( X ):
def AdjointH( (X, Y) ):
return H.T * Y
-if computation["method"] == "Direct":
+if method == "Direct":
result = FunctionH(computation["data"])
-if computation["method"] == "Tangent":
+if method == "Tangent":
result = FunctionH(computation["data"])
-if computation["method"] == "Adjoint":
+if method == "Adjoint":
result = AdjointH(computation["data"])
print "Computation end"