return sample
+ def get_data_from_any(self, any_data):
+ error = any_data["returnCode"].getIntValue()
+ if error != 0:
+ self.optim_algo.setError(any_data["errorMessage"].getStringValue())
+
+ data = []
+ outputValues = any_data["outputValues"]
+ for param in outputValues[0]:
+ for i in range(param.size()):
+ data.append(param[i].getDoubleValue())
+
+ matrix = numpy.matrix(data).T
+ return matrix
+
def Direct(self, X, sync = 1):
print "Call Direct OptimizerHooks"
if sync == 1:
sample_id = self.optim_algo.pool.getCurrentId()
if sample_id == local_counter:
# 4: Data is ready
- matrix_from_pool = self.optim_algo.pool.getOutSample(local_counter).getStringValue()
+ any_data = self.optim_algo.pool.getOutSample(local_counter)
+ Y = self.get_data_from_any(any_data)
# 5: Release lock
# Have to be done before but need a new implementation
# of the optimizer loop
self.counter_lock.release()
-
- # 6: return results
- Y = pickle.loads(matrix_from_pool)
return Y
else:
print "sync false is not yet implemented"
sample_id = self.optim_algo.pool.getCurrentId()
if sample_id == local_counter:
# 4: Data is ready
- matrix_from_pool = self.optim_algo.pool.getOutSample(local_counter).getStringValue()
+ any_data = self.optim_algo.pool.getOutSample(local_counter)
+ Y = self.get_data_from_any(any_data)
# 5: Release lock
# Have to be done before but need a new implementation
# of the optimizer loop
self.counter_lock.release()
-
- # 6: return results
- Y = pickle.loads(matrix_from_pool)
return Y
else:
print "sync false is not yet implemented"
sample_id = self.optim_algo.pool.getCurrentId()
if sample_id == local_counter:
# 4: Data is ready
- matrix_from_pool = self.optim_algo.pool.getOutSample(local_counter).getStringValue()
+ any_data = self.optim_algo.pool.getOutSample(local_counter)
+ Z = self.get_data_from_any(any_data)
# 5: Release lock
# Have to be done before but need a new implementation
# of the optimizer loop
self.counter_lock.release()
-
- # 6: return results
- Z = pickle.loads(matrix_from_pool)
return Z
else:
print "sync false is not yet implemented"
self.runtime = SALOMERuntime.getSALOMERuntime()
# Definission des types d'entres et de sorties pour le code de calcul
- self.tin = self.runtime.getTypeCode("SALOME_TYPES/ParametricInput")
- self.tout = self.runtime.getTypeCode("pyobj")
+ self.tin = self.runtime.getTypeCode("SALOME_TYPES/ParametricInput")
+ self.tout = self.runtime.getTypeCode("SALOME_TYPES/ParametricOutput")
+ self.pyobject = self.runtime.getTypeCode("pyobj")
self.optim_hooks = OptimizerHooks(self)
def getTCForOut(self):
return self.tout
def getTCForAlgoInit(self):
- return self.tout
+ return self.pyobject
def getTCForAlgoResult(self):
- return self.tout
+ return self.pyobject
proc = runtime.createProc("proc")
proc.setTypeCode("pyobj", runtime.getTypeCode("pyobj"))
proc.setTypeCode("SALOME_TYPES/ParametricInput", catalogAd._typeMap["SALOME_TYPES/ParametricInput"])
+ proc.setTypeCode("SALOME_TYPES/ParametricOutput", catalogAd._typeMap["SALOME_TYPES/ParametricOutput"])
t_pyobj = proc.getTypeCode("pyobj")
t_string = proc.getTypeCode("string")
- t_param_input = proc.getTypeCode("SALOME_TYPES/ParametricInput")
+ t_param_input = proc.getTypeCode("SALOME_TYPES/ParametricInput")
+ t_param_output = proc.getTypeCode("SALOME_TYPES/ParametricOutput")
repertory = False
base_repertory = ""
if "Repertory" in study_config.keys():
sys.exit(1)
opt_script_node.setScript(script_str.read())
opt_script_node.edAddInputPort("computation", t_param_input)
- opt_script_node.edAddOutputPort("result", t_pyobj)
+ opt_script_node.edAddOutputPort("result", t_param_output)
# Add it
computation_bloc = runtime.createBloc("computation_bloc")
return H.T * Y
if method == "Direct":
- result = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T)
+ data = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T)
if method == "Tangent":
- result = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T)
+ data = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T)
if method == "Adjoint":
- result = AdjointH((numpy.matrix(computation["inputValues"][0][0]).T, numpy.matrix(computation["inputValues"][0][1]).T))
+ data = AdjointH((numpy.matrix(computation["inputValues"][0][0]).T, numpy.matrix(computation["inputValues"][0][1]).T))
+
+outputValues = [[[]]]
+it = data.flat
+for val in it:
+ outputValues[0][0].append(val)
+
+print outputValues
+
+result = {}
+result["outputValues"] = outputValues
+result["specificOutputInfos"] = []
+result["returnCode"] = 0
+result["errorMessage"] = ""
+
+print result
print "Computation end"