pydefx 9.14.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mpmcn.py +154 -0
- pydefx/__init__.py +32 -0
- pydefx/allpurposebuilder.py +56 -0
- pydefx/configuration.py +120 -0
- pydefx/defaultschemabuilder.py +55 -0
- pydefx/localbuilder.py +37 -0
- pydefx/localstudy.py +78 -0
- pydefx/multijobbuilder.py +33 -0
- pydefx/multijobstudy.py +84 -0
- pydefx/parameters.py +169 -0
- pydefx/plugins/jobexecutor.py +130 -0
- pydefx/plugins/lightexecutor.py +40 -0
- pydefx/plugins/localexecutor.py +81 -0
- pydefx/plugins/mainjob.py +56 -0
- pydefx/plugins/pointeval.py +39 -0
- pydefx/plugins/srunexecutor.py +87 -0
- pydefx/pyscript.py +110 -0
- pydefx/pystudy.py +327 -0
- pydefx/salome_proxy.py +88 -0
- pydefx/sample.py +263 -0
- pydefx/samplecsviterator.py +191 -0
- pydefx/samplecsvmanager.py +136 -0
- pydefx/schemas/idefix_pyschema.xml +106 -0
- pydefx/schemas/plugin.py +81 -0
- pydefx/slurmbuilder.py +33 -0
- pydefx/slurmstudy.py +77 -0
- pydefx/studyexception.py +41 -0
- pydefx/studyresult.py +54 -0
- pydefx-9.14.0.dist-info/METADATA +22 -0
- pydefx-9.14.0.dist-info/RECORD +45 -0
- pydefx-9.14.0.dist-info/WHEEL +4 -0
- salome/bin/salome/test/CTestTestfile.cmake +28 -0
- salome/bin/salome/test/cpp/CTestTestfile.cmake +36 -0
- salome/bin/salome/test/cpp/SampleTest +0 -0
- salome/bin/salome/test/cpp/StudyGeneralTest +0 -0
- salome/bin/salome/test/cpp/StudyRestartTest +0 -0
- salome/bin/salome/test/pyexample/CTestTestfile.cmake +25 -0
- salome/bin/salome/test/pyexample/insitu/insituiterator.py +48 -0
- salome/bin/salome/test/pyexample/insitu/insitumanager.py +46 -0
- salome/bin/salome/test/pyexample/runUnitTest.sh +26 -0
- salome/bin/salome/test/pyexample/test_default.py +79 -0
- salome/bin/salome/test/pyexample/test_insitu.py +60 -0
- salome/bin/salome/test/pyexample/test_mpmcn.py +40 -0
- salome/bin/salome/test/pyexample/test_prescript.py +52 -0
- salome/bin/salome/test/pyexample/test_ydefx_base.py +79 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import insitu.insitumanager
|
|
3
|
+
import os
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestYdefx(unittest.TestCase):
|
|
8
|
+
def test_insitu(self):
|
|
9
|
+
"""
|
|
10
|
+
This test shows how to use insitu processing.
|
|
11
|
+
"""
|
|
12
|
+
import pydefx
|
|
13
|
+
|
|
14
|
+
myParams = pydefx.Parameters()
|
|
15
|
+
myParams.configureResource("localhost")
|
|
16
|
+
mywd = os.path.join(myParams.salome_parameters.work_directory,
|
|
17
|
+
"insitu_test" +
|
|
18
|
+
time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()))
|
|
19
|
+
myParams.salome_parameters.work_directory = mywd
|
|
20
|
+
myParams.createResultDirectory("/tmp")
|
|
21
|
+
|
|
22
|
+
pyScript = """
|
|
23
|
+
def _exec(x):
|
|
24
|
+
with open("mydata.txt") as f:
|
|
25
|
+
mydata = f.read()
|
|
26
|
+
intdata = int(mydata)
|
|
27
|
+
y = x + intdata
|
|
28
|
+
return y"""
|
|
29
|
+
|
|
30
|
+
myScript = pydefx.PyScript()
|
|
31
|
+
myScript.loadString(pyScript)
|
|
32
|
+
|
|
33
|
+
mySample = myScript.CreateEmptySample()
|
|
34
|
+
mydata = {"x":list(range(10))}
|
|
35
|
+
mySample.setInputValues(mydata)
|
|
36
|
+
|
|
37
|
+
# pre-processing script called before the first evaluation
|
|
38
|
+
myPrescript = """
|
|
39
|
+
with open("mydata.txt", "w") as f:
|
|
40
|
+
f.write("1")
|
|
41
|
+
"""
|
|
42
|
+
mySchemaBuilder = pydefx.DefaultSchemaBuilder(myPrescript)
|
|
43
|
+
|
|
44
|
+
mySampleManager = insitu.insitumanager.InsituManager()
|
|
45
|
+
|
|
46
|
+
myStudy = pydefx.PyStudy(sampleManager=mySampleManager,
|
|
47
|
+
schemaBuilder=mySchemaBuilder)
|
|
48
|
+
myStudy.createNewJob(myScript, mySample, myParams)
|
|
49
|
+
|
|
50
|
+
myStudy.launch()
|
|
51
|
+
myStudy.wait()
|
|
52
|
+
myStudy.getResult()
|
|
53
|
+
expected = """Exit code : 0
|
|
54
|
+
Error message : None
|
|
55
|
+
Result:
|
|
56
|
+
55.0"""
|
|
57
|
+
self.assertEqual(str(myStudy.global_result),expected)
|
|
58
|
+
|
|
59
|
+
if __name__ == '__main__':
|
|
60
|
+
unittest.main()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
#!/usr/bin/env python3
|
|
3
|
+
# -*- coding: utf-8 -*-
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
# multiple processes on multiple compute nodes
|
|
7
|
+
|
|
8
|
+
def f(x):
|
|
9
|
+
return x*x*x
|
|
10
|
+
|
|
11
|
+
def f2(x):
|
|
12
|
+
if x==3:
|
|
13
|
+
raise RuntimeError("lllll")
|
|
14
|
+
return x*x*x
|
|
15
|
+
|
|
16
|
+
import mpmcn
|
|
17
|
+
|
|
18
|
+
def gg():
|
|
19
|
+
# case 0 : normal behavior with no raise
|
|
20
|
+
params = mpmcn.init("localhost")
|
|
21
|
+
with mpmcn.Pool(params) as p:
|
|
22
|
+
res = p.map(f,list(range(10)))
|
|
23
|
+
# getResultDirectory : for advanced users
|
|
24
|
+
p.getResultDirectory()
|
|
25
|
+
if res != [0.0, 1.0, 8.0, 27.0, 64.0, 125.0, 216.0, 343.0, 512.0, 729.0]:
|
|
26
|
+
raise RuntimeError("Test Failed !")
|
|
27
|
+
# case 1 : behavior with raise
|
|
28
|
+
params = mpmcn.init("localhost")
|
|
29
|
+
with mpmcn.Pool(params) as p2:
|
|
30
|
+
try:
|
|
31
|
+
res = p2.map(f2,list(range(10)))
|
|
32
|
+
raise RuntimeError("Exception not thrown -> Error !")
|
|
33
|
+
except RuntimeError as e:
|
|
34
|
+
strExpected = "Error for sample # 3 : \'lllll\'"
|
|
35
|
+
# tmp_dir attr of e returns the ResultDirectory to dive into
|
|
36
|
+
if str(e)[:len(strExpected)] != strExpected or not hasattr(e,"tmp_dir"):
|
|
37
|
+
raise RuntimeError("Test Failed 2 !")
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
gg()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import os
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
class TestYdefx(unittest.TestCase):
|
|
6
|
+
def test_prescript(self):
|
|
7
|
+
"""
|
|
8
|
+
This test shows how to use an initialization script which is called one time
|
|
9
|
+
before any evaluation of the study function.
|
|
10
|
+
"""
|
|
11
|
+
import pydefx
|
|
12
|
+
|
|
13
|
+
myParams = pydefx.Parameters()
|
|
14
|
+
myParams.configureResource("localhost")
|
|
15
|
+
mywd = os.path.join(myParams.salome_parameters.work_directory,
|
|
16
|
+
"prescript_test" +
|
|
17
|
+
time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()))
|
|
18
|
+
myParams.salome_parameters.work_directory = mywd
|
|
19
|
+
myParams.createResultDirectory("/tmp")
|
|
20
|
+
|
|
21
|
+
pyScript = """
|
|
22
|
+
def _exec(name):
|
|
23
|
+
with open("mydata.txt") as f:
|
|
24
|
+
mydata = f.read()
|
|
25
|
+
message = mydata + name
|
|
26
|
+
return message"""
|
|
27
|
+
|
|
28
|
+
myScript = pydefx.PyScript()
|
|
29
|
+
myScript.loadString(pyScript)
|
|
30
|
+
|
|
31
|
+
mySample = myScript.CreateEmptySample()
|
|
32
|
+
mydata = {"name":["Jean", "Toto", "Titi", "Zizi"]}
|
|
33
|
+
mySample.setInputValues(mydata)
|
|
34
|
+
|
|
35
|
+
myPrescript = """
|
|
36
|
+
with open("mydata.txt", "w") as f:
|
|
37
|
+
f.write("Hello ")
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
mySchemaBuilder = pydefx.DefaultSchemaBuilder(myPrescript)
|
|
41
|
+
|
|
42
|
+
myStudy = pydefx.PyStudy(schemaBuilder=mySchemaBuilder)
|
|
43
|
+
myStudy.createNewJob(myScript, mySample, myParams)
|
|
44
|
+
|
|
45
|
+
myStudy.launch()
|
|
46
|
+
myStudy.wait()
|
|
47
|
+
myStudy.getResult()
|
|
48
|
+
expected = "name,message,messages\n'Jean','Hello Jean',\n'Toto','Hello Toto',\n'Titi','Hello Titi',\n'Zizi','Hello Zizi',\n"
|
|
49
|
+
self.assertEqual(str(myStudy.sample),expected)
|
|
50
|
+
|
|
51
|
+
if __name__ == '__main__':
|
|
52
|
+
unittest.main()
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright (C) 2024 CEA, EDF
|
|
3
|
+
#
|
|
4
|
+
# This library is free software; you can redistribute it and/or
|
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
6
|
+
# License as published by the Free Software Foundation; either
|
|
7
|
+
# version 2.1 of the License, or (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+
# Lesser General Public License for more details.
|
|
13
|
+
#
|
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
|
15
|
+
# License along with this library; if not, write to the Free Software
|
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17
|
+
#
|
|
18
|
+
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
|
19
|
+
#
|
|
20
|
+
|
|
21
|
+
from salome.kernel import salome_utils
|
|
22
|
+
import unittest
|
|
23
|
+
import os
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
import pydefx
|
|
26
|
+
|
|
27
|
+
class TestYdefxBase(unittest.TestCase):
|
|
28
|
+
def test0(self):
|
|
29
|
+
"""
|
|
30
|
+
See EDF31521
|
|
31
|
+
"""
|
|
32
|
+
myParams = pydefx.Parameters("localhost", 4)
|
|
33
|
+
myParams.salome_parameters.work_directory = "{}".format(Path( myParams.salome_parameters.work_directory ) / "my_base_case" )
|
|
34
|
+
myParams.salome_parameters.verbose_py_log_level = "ERROR" # ERROR - WARNING - INFO - DEBUG
|
|
35
|
+
myParams.createResultDirectory("/tmp")
|
|
36
|
+
myParams.salome_parameters.in_files = []
|
|
37
|
+
salome_utils.logger.info( f"ressource de calcul: {myParams.salome_parameters.resource_required.name}")
|
|
38
|
+
salome_utils.logger.info( f"nombre d'évaluations parallèles: {myParams.nb_branches}")
|
|
39
|
+
salome_utils.logger.info( f"nombre de coeurs demandés: {myParams.salome_parameters.resource_required.nb_proc}" )
|
|
40
|
+
salome_utils.logger.info( f"nombre de noeuds demandés: {myParams.salome_parameters.resource_required.nb_node}" )
|
|
41
|
+
salome_utils.logger.info( f"répertoire de travail: {myParams.salome_parameters.work_directory}" )
|
|
42
|
+
salome_utils.logger.info( f"répertoire local de gestion: {myParams.salome_parameters.result_directory}" )
|
|
43
|
+
myScript = pydefx.PyScript()
|
|
44
|
+
myScript.loadString("""from salome.kernel import salome_utils
|
|
45
|
+
def _exec(x, y):
|
|
46
|
+
from salome.kernel import KernelBasis
|
|
47
|
+
cst = 1.28
|
|
48
|
+
salome_utils.logger.info("Je suis une info")
|
|
49
|
+
KernelBasis.HeatMarcel(cst*1.0,1)
|
|
50
|
+
d = y / x
|
|
51
|
+
t = "{} / {} = {}".format(x, y, d)
|
|
52
|
+
print(f"****** {x}")
|
|
53
|
+
return d, t
|
|
54
|
+
""")
|
|
55
|
+
salome_utils.logger.info( f"Inputs : {myScript.getInputNames()}")
|
|
56
|
+
salome_utils.logger.info( f"Outputs : {myScript.getOutputNames()}")
|
|
57
|
+
mySample = myScript.CreateEmptySample()
|
|
58
|
+
mySample.setInputValues({ "x":[ 10, 20, 30, 40],
|
|
59
|
+
"y":[ 20, 60, 120, 200]})
|
|
60
|
+
myStudy = pydefx.PyStudy()
|
|
61
|
+
myStudy.createNewJob(myScript, mySample, myParams)
|
|
62
|
+
myStudy.launch()
|
|
63
|
+
salome_utils.logger.info( f"Avancement: {myStudy.getProgress()}")
|
|
64
|
+
salome_utils.logger.info( f"Etat: {myStudy.getJobState()}" )
|
|
65
|
+
|
|
66
|
+
# Attendre la fin des calculs
|
|
67
|
+
myStudy.wait()
|
|
68
|
+
|
|
69
|
+
salome_utils.logger.info( f"Etat: {myStudy.getJobState()}" )
|
|
70
|
+
salome_utils.logger.info( f"Etat: {myStudy.getJobState()}" )
|
|
71
|
+
res = myStudy.getResult()
|
|
72
|
+
self.assertEqual(res.result.getOutput("d"), [ 2.0, 3.0, 4.0, 5.0 ] )
|
|
73
|
+
self.assertEqual( res.result.getOutput("t"), [ '10.0 / 20.0 = 2.0', '20.0 / 60.0 = 3.0', '30.0 / 120.0 = 4.0', '40.0 / 200.0 = 5.0' ] )
|
|
74
|
+
|
|
75
|
+
if __name__ == '__main__':
|
|
76
|
+
import KernelBasis
|
|
77
|
+
KernelBasis.SetVerbosityLevel("WARNING")
|
|
78
|
+
salome_utils.positionVerbosityOfLoggerRegardingState()
|
|
79
|
+
unittest.main()
|