pyfemtet 0.1.12__py3-none-any.whl → 0.2.1__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.

Potentially problematic release.


This version of pyfemtet might be problematic. Click here for more details.

Files changed (33) hide show
  1. pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.femprj +0 -0
  2. pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.prt +0 -0
  3. pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.py +69 -32
  4. pyfemtet/FemtetPJTSample/gau_ex08_parametric.femprj +0 -0
  5. pyfemtet/FemtetPJTSample/gau_ex08_parametric.py +37 -25
  6. pyfemtet/FemtetPJTSample/her_ex40_parametric.py +57 -35
  7. pyfemtet/FemtetPJTSample/wat_ex14_parallel_parametric.py +62 -0
  8. pyfemtet/FemtetPJTSample/wat_ex14_parametric.femprj +0 -0
  9. pyfemtet/FemtetPJTSample/wat_ex14_parametric.py +61 -0
  10. pyfemtet/__init__.py +1 -1
  11. pyfemtet/opt/_FemtetWithNX/update_model.py +6 -2
  12. pyfemtet/opt/__init__.py +1 -1
  13. pyfemtet/opt/base.py +457 -86
  14. pyfemtet/opt/core.py +77 -17
  15. pyfemtet/opt/interface.py +217 -137
  16. pyfemtet/opt/monitor.py +181 -98
  17. pyfemtet/opt/{_optuna.py → optimizer.py} +70 -30
  18. pyfemtet/tools/DispatchUtils.py +46 -44
  19. {pyfemtet-0.1.12.dist-info → pyfemtet-0.2.1.dist-info}/LICENSE +1 -1
  20. pyfemtet-0.2.1.dist-info/METADATA +42 -0
  21. pyfemtet-0.2.1.dist-info/RECORD +31 -0
  22. pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01 - original.x_t +0 -359
  23. pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.x_t +0 -359
  24. pyfemtet/FemtetPJTSample/fem4 = Femtet(femprj_path=None, model_name=None, connect_method='catch').femprj +0 -0
  25. pyfemtet/FemtetPJTSample/gal_ex11_parametric.femprj +0 -0
  26. pyfemtet/FemtetPJTSample/gal_ex11_parametric.py +0 -54
  27. pyfemtet/FemtetPJTSample/pas_ex1_parametric.femprj +0 -0
  28. pyfemtet/FemtetPJTSample/pas_ex1_parametric.py +0 -66
  29. pyfemtet/FemtetPJTSample/pas_ex1_parametric2.py +0 -68
  30. pyfemtet/tools/FemtetClassConst.py +0 -9
  31. pyfemtet-0.1.12.dist-info/METADATA +0 -205
  32. pyfemtet-0.1.12.dist-info/RECORD +0 -37
  33. {pyfemtet-0.1.12.dist-info → pyfemtet-0.2.1.dist-info}/WHEEL +0 -0
pyfemtet/opt/core.py CHANGED
@@ -1,31 +1,98 @@
1
+ import os
2
+ import threading
3
+ import ctypes
1
4
  import ray
5
+ from win32com.client import constants
6
+
7
+
8
+ os.environ['RAY_DEDUP_LOGS'] = '0'
9
+
10
+
11
+ class Scapegoat:
12
+ """Helper class for parallelize Femtet."""
13
+ # constants を含む関数を並列化するために
14
+ # メイン処理で一時的に constants への参照を
15
+ # このオブジェクトにして、後で restore する
16
+ pass
17
+
18
+
19
+ def restore_constants_from_scapegoat(function: 'Function'):
20
+ """Helper function for parallelize Femtet."""
21
+ fun = function.fun
22
+ for varname in fun.__globals__:
23
+ if isinstance(fun.__globals__[varname], Scapegoat):
24
+ fun.__globals__[varname] = constants
25
+
26
+
27
+ class TerminatableThread(threading.Thread):
28
+ """A terminatable class that inherits from :class:`threading.Thread`."""
29
+
30
+ def __init__(self, *args, **kwargs):
31
+ super().__init__(*args, **kwargs)
32
+ self._run = self.run
33
+ self.run = self.set_id_and_run
34
+
35
+ def set_id_and_run(self):
36
+ self.id = threading.get_native_id()
37
+ self._run()
38
+
39
+ def get_id(self):
40
+ return self.id
41
+
42
+ def force_terminate(self):
43
+ res = ctypes.pythonapi.PyThreadState_SetAsyncExc(
44
+ ctypes.c_long(self.get_id()),
45
+ ctypes.py_object(SystemExit)
46
+ )
47
+ if res > 1:
48
+ ctypes.pythonapi.PyThreadState_SetAsyncExc(
49
+ ctypes.c_long(self.get_id()),
50
+ 0
51
+ )
2
52
 
3
53
 
4
54
  class ModelError(Exception):
55
+ """Exception raised for errors in the model update.
56
+
57
+ If this exception is thrown during an optimization calculation, the process attempts to skip that attempt if possible.
58
+
59
+ """
5
60
  pass
6
61
 
7
62
 
8
63
  class MeshError(Exception):
64
+ """Exception raised for errors in the meshing.
65
+
66
+ If this exception is thrown during an optimization calculation, the process attempts to skip that attempt if possible.
67
+
68
+ """
9
69
  pass
10
70
 
11
71
 
12
72
  class SolveError(Exception):
73
+ """Exception raised for errors in the solve.
74
+
75
+ If this exception is thrown during an optimization calculation, the process attempts to skip that attempt if possible.
76
+
77
+ """
13
78
  pass
14
79
 
15
80
 
16
- class PostError(Exception):
17
- pass
81
+ # class PostError(Exception):
82
+ # pass
18
83
 
19
84
 
20
- class FEMCrash(Exception):
21
- pass
85
+ # class FEMCrash(Exception):
86
+ # pass
22
87
 
23
88
 
24
89
  class FemtetAutomationError(Exception):
90
+ """Exception raised for errors in automating Femtet."""
25
91
  pass
26
92
 
27
93
 
28
94
  class UserInterruption(Exception):
95
+ """Exception raised for errors in interruption by user."""
29
96
  pass
30
97
 
31
98
 
@@ -34,7 +101,7 @@ class _InterprocessVariables:
34
101
 
35
102
  def __init__(self):
36
103
  self.state = 'undefined'
37
- self.history = []
104
+ self.history = [] # #16295
38
105
  self.allowed_idx = 0
39
106
 
40
107
  def set_state(self, state):
@@ -43,12 +110,6 @@ class _InterprocessVariables:
43
110
  def get_state(self) -> 'ObjectRef':
44
111
  return self.state
45
112
 
46
- def append_history(self, row):
47
- self.history.append(row)
48
-
49
- def get_history(self) -> 'ObjectRef':
50
- return self.history
51
-
52
113
  def set_allowed_idx(self, idx):
53
114
  self.allowed_idx = idx
54
115
 
@@ -57,27 +118,26 @@ class _InterprocessVariables:
57
118
 
58
119
 
59
120
  class InterprocessVariables:
121
+ """An interface for variables shared between parallel processes."""
60
122
 
61
123
  def __init__(self):
62
124
  self.ns = _InterprocessVariables.remote()
63
125
 
64
126
  def set_state(self, state):
127
+ """Sets the state of entire optimization processes."""
65
128
  print(f'---{state}---')
66
129
  self.ns.set_state.remote(state)
67
130
 
68
131
  def get_state(self):
132
+ """Gets the state of entire optimization processes."""
69
133
  return ray.get(self.ns.get_state.remote())
70
134
 
71
- def append_history(self, row):
72
- self.ns.append_history.remote(row)
73
-
74
- def get_history(self):
75
- return ray.get(self.ns.get_history.remote())
76
-
77
135
  def set_allowed_idx(self, idx):
136
+ """Sets the allowed subprocess index for exclusive process."""
78
137
  self.ns.set_allowed_idx.remote(idx)
79
138
 
80
139
  def get_allowed_idx(self):
140
+ """Gets the allowed subprocess index for exclusive process."""
81
141
  return ray.get(self.ns.get_allowed_idx.remote())
82
142
 
83
143