Here is the switch template::
import Physical_simulation_functions
- import numpy, logging
+ import numpy, logging, codecs, pickle
+ def loads( data ):
+ return pickle.loads(codecs.decode(data.encode(), "base64"))
#
method = ""
for param in computation["specificParameters"]:
if param["name"] == "method":
- method = param["value"]
+ method = loads(param["value"])
if method not in ["Direct", "Tangent", "Adjoint"]:
raise ValueError("No valid computation method is given")
logging.info("Found method is \'%s\'"%method)
"*AdjointOperator*" comme précédemment. Voici le squelette d'aiguillage::
import Physical_simulation_functions
- import numpy, logging
+ import numpy, logging, codecs, pickle
+ def loads( data ):
+ return pickle.loads(codecs.decode(data.encode(), "base64"))
#
method = ""
for param in computation["specificParameters"]:
if param["name"] == "method":
- method = param["value"]
+ method = loads(param["value"])
if method not in ["Direct", "Tangent", "Adjoint"]:
raise ValueError("No valid computation method is given")
logging.info("Found method is \'%s\'"%method)
<type name="long" kind="int"/>
<struct name="SALOME_TYPES/Parameter">
<member type="string" name="name"></member>
- <member type="pyobj" name="value"></member>
+ <member type="string" name="value"></member>
</struct>
<sequence content="SALOME_TYPES/Parameter" name="SALOME_TYPES/ParameterList"></sequence>
<sequence content="double" name="SALOME_TYPES/Variable"></sequence>
</inline>
<inline name="ReadForSwitchNode">
- <script><code><![CDATA[import sys, logging
+ <script><code><![CDATA[import sys, logging, codecs, pickle
if sys.version_info.major > 2: import adao
+def loads( data ):
+ return pickle.loads(codecs.decode(data.encode(), "base64"))
logging.debug("CREATE YI Entering in ReadForSwitchNode")
-logging.debug(" with input data : ",list(data["specificParameters"]))
+# logging.debug(" with input data : ",list(data["specificParameters"]))
switch_value = -1
for param in data["specificParameters"]:
+ # logging.debug(" ReadForSwitchNode specificParameters : ",param)
if param["name"] == "switch_value":
- switch_value = int(param["value"])
+ switch_value = int(loads(param["value"]))
logging.debug(" switching to value : "+str(switch_value))
]]></code></script>
<inport name="data" type="SALOME_TYPES/ParametricInput"/>
</inline>
<inline name="ExtractDataNode">
- <script><code><![CDATA[import sys, logging
+ <script><code><![CDATA[import sys, logging, codecs, pickle
if sys.version_info.major > 2: import adao
-logging.debug("TERMINATE Entering in ExtractDataNode")
+def loads( data ):
+ return pickle.loads(codecs.decode(data.encode(), "base64"))
+logging.debug("TERMINATE Entering in ExtractData/Node")
from daCore.AssimilationStudy import AssimilationStudy
var = None
info = None
for param in data["specificParameters"]:
if param["name"] == "var":
- var = param["value"]
+ var = loads(param["value"])
if param["name"] == "info":
- info = param["value"]
+ info = loads(param["value"])
]]></code></script>
<inport name="data" type="SALOME_TYPES/ParametricInput"/>
<outport name="var" type="pyobj"/>
import threading
import sys
import traceback
+import codecs
# Pour disposer des classes dans l'espace de nommage lors du pickle
from daCore.AssimilationStudy import AssimilationStudy
from daYacsIntegration import daStudy
+def dumps( data ):
+ return str(codecs.encode(pickle.dumps(data), "base64").decode())
+def loads( data ):
+ return pickle.loads(codecs.decode(data.encode(), "base64"))
+
class OptimizerHooks:
def __init__(self, optim_algo, switch_value=-1):
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")
- if sys.version_info.major < 3:
- method_name.setEltAtRank("value", method)
- else:
- method_name.setEltAtRank("value", pickle.dumps(method))
+ method_name.setEltAtRank("value", dumps(method))
specificParameters.pushBack(method_name)
# print self.optim_algo.has_observer
if self.optim_algo.has_observer:
obs_switch = pilot.StructAny_New(self.optim_algo.runtime.getTypeCode('SALOME_TYPES/Parameter'))
obs_switch.setEltAtRank("name", "switch_value")
- if sys.version_info.major < 3:
- obs_switch.setEltAtRank("value", "1")
- else:
- obs_switch.setEltAtRank("value", pickle.dumps("1"))
+ obs_switch.setEltAtRank("value", dumps("1"))
specificParameters.pushBack(obs_switch)
if self.optim_algo.has_evolution_model:
obs_switch = pilot.StructAny_New(self.optim_algo.runtime.getTypeCode('SALOME_TYPES/Parameter'))
obs_switch.setEltAtRank("name", "switch_value")
- if sys.version_info.major < 3:
- obs_switch.setEltAtRank("value", self.switch_value)
- else:
- obs_switch.setEltAtRank("value", pickle.dumps(self.switch_value))
+ obs_switch.setEltAtRank("value", dumps(self.switch_value))
specificParameters.pushBack(obs_switch)
sample.setEltAtRank("specificParameters", specificParameters)
# Switch Value
obs_switch = pilot.StructAny_New(self.runtime.getTypeCode('SALOME_TYPES/Parameter'))
obs_switch.setEltAtRank("name", "switch_value")
- if sys.version_info.major < 3:
- obs_switch.setEltAtRank("value", self.da_study.observers_dict[info]["number"])
- else:
- obs_switch.setEltAtRank("value", pickle.dumps(self.da_study.observers_dict[info]["number"]))
+ obs_switch.setEltAtRank("value", dumps(self.da_study.observers_dict[info]["number"]))
specificParameters.pushBack(obs_switch)
# Var
# Remove Data Observer, so you can ...
var.removeDataObserver(self.obs)
# Pickle then ...
- var_struct.setEltAtRank("value", pickle.dumps(var))
+ var_struct.setEltAtRank("value", dumps(var))
specificParameters.pushBack(var_struct)
# Add Again Data Observer
if self.da_study.observers_dict[info]["scheduler"] != "":
# Info
info_struct = pilot.StructAny_New(self.runtime.getTypeCode('SALOME_TYPES/Parameter'))
info_struct.setEltAtRank("name", "info")
- if sys.version_info.major < 3:
- info_struct.setEltAtRank("value", self.da_study.observers_dict[info]["info"])
- else:
- info_struct.setEltAtRank("value", pickle.dumps(self.da_study.observers_dict[info]["info"]))
+ info_struct.setEltAtRank("value", dumps(self.da_study.observers_dict[info]["info"]))
specificParameters.pushBack(info_struct)
sample.setEltAtRank("specificParameters", specificParameters)
except:
raise ValueError("Exception in opening function script file: " + script_filename)
node_script = "#-*- coding: utf-8 -*-\n"
- node_script += "import sys, os, numpy, logging\n"
+ node_script += "import sys, os, numpy, logging, pickle, codecs\n"
+ node_script += "def loads( data ):\n"
+ node_script += " return pickle.loads(codecs.decode(data.encode(), 'base64'))\n"
node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n"
node_script += "filename = \"" + os.path.basename(script_filename) + "\"\n"
node_script += "if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):\n"
node_script += """# ==============================================\n"""
node_script += """__method = None\n"""
node_script += """for param in computation["specificParameters"]:\n"""
- node_script += """ if param["name"] == "method": __method = param["value"]\n"""
+ node_script += """ if param["name"] == "method": __method = loads(param["value"])\n"""
node_script += """if __method not in ["Direct", "Tangent", "Adjoint"]:\n"""
node_script += """ raise ValueError("ComputationFunctionNode: no valid computation method is given, it has to be Direct, Tangent or Adjoint (\'%s\' given)."%__method)\n"""
node_script += """logging.debug("ComputationFunctionNode: Found method is \'%s\'"%__method)\n"""
except:
raise ValueError("Exception in opening function script file: " + script_filename)
node_script = "#-*- coding: utf-8 -*-\n"
- node_script += "import sys, os, numpy, logging\n"
+ node_script += "import sys, os, numpy, logging, pickle, codecs\n"
+ node_script += "def loads( data ):\n"
+ node_script += " return pickle.loads(codecs.decode(data.encode(), 'base64'))\n"
node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n"
node_script += "filename = \"" + os.path.basename(script_filename) + "\"\n"
node_script += "if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):\n"
node_script += """# ==============================================\n"""
node_script += """__method = None\n"""
node_script += """for param in computation["specificParameters"]:\n"""
- node_script += """ if param["name"] == "method": __method = param["value"]\n"""
+ node_script += """ if param["name"] == "method": __method = loads(param["value"])\n"""
node_script += """if __method not in ["Direct", "Tangent", "Adjoint"]:\n"""
node_script += """ raise ValueError("ComputationFunctionNode: no valid computation method is given, it has to be Direct, Tangent or Adjoint (\'%s\' given)."%__method)\n"""
node_script += """logging.debug("ComputationFunctionNode: Found method is \'%s\'"%__method)\n"""
except:
raise ValueError("Exception in opening function script file: " + script_filename)
node_script = "#-*- coding: utf-8 -*-\n"
- node_script += "import sys, os, numpy, logging\n"
+ node_script += "import sys, os, numpy, logging, pickle, codecs\n"
+ node_script += "def loads( data ):\n"
+ node_script += " return pickle.loads(codecs.decode(data.encode(), 'base64'))\n"
node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n"
node_script += "filename = \"" + os.path.basename(script_filename) + "\"\n"
node_script += "if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):\n"
node_script += """# ==============================================\n"""
node_script += """__method = None\n"""
node_script += """for param in computation["specificParameters"]:\n"""
- node_script += """ if param["name"] == "method": __method = param["value"]\n"""
+ node_script += """ if param["name"] == "method": __method = loads(param["value"])\n"""
node_script += """if __method not in ["Direct", "Tangent", "Adjoint"]:\n"""
node_script += """ raise ValueError("ComputationFunctionNode: no valid computation method is given, it has to be Direct, Tangent or Adjoint (\'%s\' given)."%__method)\n"""
node_script += """logging.debug("ComputationFunctionNode: Found method is \'%s\'"%__method)\n"""
except:
raise ValueError("Exception in opening function script file: " + script_filename)
node_script = "#-*- coding: utf-8 -*-\n"
- node_script += "import sys, os, numpy, logging\n"
+ node_script += "import sys, os, numpy, logging, pickle, codecs\n"
+ node_script += "def loads( data ):\n"
+ node_script += " return pickle.loads(codecs.decode(data.encode(), 'base64'))\n"
node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n"
node_script += "filename = \"" + os.path.basename(script_filename) + "\"\n"
node_script += "if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):\n"
node_script += """# ==============================================\n"""
node_script += """__method = None\n"""
node_script += """for param in computation["specificParameters"]:\n"""
- node_script += """ if param["name"] == "method": __method = param["value"]\n"""
+ node_script += """ if param["name"] == "method": __method = loads(param["value"])\n"""
node_script += """if __method not in ["Direct", "Tangent", "Adjoint"]:\n"""
node_script += """ raise ValueError("ComputationFunctionNode: no valid computation method is given, it has to be Direct, Tangent or Adjoint (\'%s\' given)."%__method)\n"""
node_script += """logging.debug("ComputationFunctionNode: Found method is \'%s\'"%__method)\n"""