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

pyfemtet/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.5.1"
1
+ __version__ = "0.5.2"
pyfemtet/opt/_femopt.py CHANGED
@@ -12,7 +12,7 @@ from traceback import print_exception
12
12
  # 3rd-party
13
13
  import numpy as np
14
14
  import pandas as pd
15
- from dask.distributed import LocalCluster, Client
15
+ from dask.distributed import LocalCluster, Client, Worker
16
16
 
17
17
  # pyfemtet relative
18
18
  from pyfemtet.opt.interface import FEMInterface, FemtetInterface
@@ -452,10 +452,16 @@ class FEMOpt:
452
452
  else:
453
453
  # ローカルクラスターを構築
454
454
  logger.info('Launching single machine cluster. This may take tens of seconds.')
455
- cluster = LocalCluster(processes=True, n_workers=n_parallel,
456
- threads_per_worker=1) # n_parallel = n_parallel - 1 + 1; main 分減らし、monitor 分増やす
455
+ cluster = LocalCluster(
456
+ processes=True,
457
+ n_workers=n_parallel, # n_parallel = n_parallel - 1 + 1; main 分減らし、monitor 分増やす
458
+ threads_per_worker=1,
459
+ worker_class=Worker,
460
+ )
461
+ logger.info('LocalCluster launched successfully.')
457
462
  self.client = Client(cluster, direct_to_workers=False)
458
463
  self.scheduler_address = self.client.scheduler.address
464
+ logger.info('Client launched successfully.')
459
465
 
460
466
  # 最適化タスクを振り分ける worker を指定
461
467
  subprocess_indices = list(range(n_parallel))[1:]
@@ -487,6 +493,7 @@ class FEMOpt:
487
493
  indexes,
488
494
  directions,
489
495
  )
496
+ logger.info('Femtet loaded successfully.')
490
497
 
491
498
  # actor の設定
492
499
  self.status = OptimizationStatus(_client)
@@ -500,6 +507,7 @@ class FEMOpt:
500
507
  _client,
501
508
  metadata,
502
509
  )
510
+ logger.info('Status Actor initialized successfully.')
503
511
 
504
512
  # launch monitor
505
513
  self.monitor_process_future = _client.submit(
@@ -516,6 +524,7 @@ class FEMOpt:
516
524
  workers=self.monitor_process_worker_name,
517
525
  allow_other_workers=False
518
526
  )
527
+ logger.info('Process monitor initialized successfully.')
519
528
 
520
529
  # fem
521
530
  self.fem._setup_before_parallel(_client)
@@ -150,9 +150,7 @@ def _remove_indent(source: str, indent: int) -> str: # returns source
150
150
  return edited_source
151
151
 
152
152
 
153
- def _check_accsess_femtet_objects(fun, target: str = None):
154
- if target is None:
155
- target = ''
153
+ def _check_access_femtet_objects(fun, target: str = 'Femtet'):
156
154
 
157
155
  # 関数fのソースコードを取得
158
156
  source = inspect.getsource(fun)
@@ -162,36 +160,88 @@ def _check_accsess_femtet_objects(fun, target: str = None):
162
160
  # instanceメソッドなどの場合を想定してインデントを削除
163
161
  source = _remove_indent(source, _get_scope_indent(source))
164
162
  tree = ast.parse(source)
165
- except:
163
+
164
+ except Exception:
166
165
  return False # パースに失敗するからと言ってエラーにするまででもない
167
166
 
168
- # 関数定義を見つける
167
+ # if function or staticmethod, 1st argument is Femtet. Find the name.
168
+ varname_contains_femtet = '' # invalid variable name
169
169
  for node in ast.walk(tree):
170
170
  if isinstance(node, ast.FunctionDef):
171
- # Femtet という名前の引数を取得
172
- first_arg_name = 'Femtet'
173
-
174
- # 関数内の全ての属性アクセスをチェック
175
- for sub_node in ast.walk(node):
176
- if isinstance(sub_node, ast.Attribute):
177
- # Femtet に対してアクセスがあるかチェック
178
- conditions = [isinstance(sub_node.value, ast.Name)]
179
- conditions.append(sub_node.value.id == first_arg_name) # Femtet にアクセスしている
180
- if target == 'Gogh':
181
- conditions.append(sub_node.attr == 'Gogh') # Femtet.Gogh にアクセスしている
182
- if all(conditions):
183
- return True
184
-
185
- # ここまできてもなければアクセスしてない
186
- return False
171
+ all_arguments: ast.arguments = node.args
172
+
173
+ args: list[ast.arg] = all_arguments.args
174
+ # args.extend(all_arguments.posonlyargs) # 先にこっちを入れるべきかも
175
+
176
+ target_arg = args[0]
177
+
178
+ # if class method or instance method, 2nd argument is it.
179
+ # In this implementation, we cannot detect the FunctionDef is
180
+ # method or not because the part of source code is unindented and parsed.
181
+ if target_arg.arg == 'self' or target_arg.arg == 'cls':
182
+ if len(args) > 1:
183
+ target_arg = args[1]
184
+ else:
185
+ target_arg = None
186
+
187
+ if target_arg is not None:
188
+ varname_contains_femtet = target_arg.arg
189
+
190
+ # check Femtet access
191
+ if target == 'Femtet':
192
+ for node in ast.walk(tree):
193
+
194
+ # by accessing argument directory
195
+ if isinstance(node, ast.Name):
196
+ # found local variables
197
+ node: ast.Name
198
+ if node.id == varname_contains_femtet:
199
+ # found Femtet
200
+ return True
201
+
202
+ # by accessing inside method
203
+ elif isinstance(node, ast.Attribute):
204
+ # found attribute of something
205
+ node: ast.Attribute
206
+ if node.attr == 'Femtet':
207
+ # found **.Femtet.**
208
+ return True
209
+
210
+ # check Gogh access
211
+ elif target == 'Gogh':
212
+ for node in ast.walk(tree):
213
+ if isinstance(node, ast.Attribute):
214
+ if node.attr == 'Gogh':
215
+ # found **.Gogh.**
216
+ node: ast.Attribute
217
+ parent = node.value
218
+
219
+ # by accessing argument directory
220
+ if isinstance(parent, ast.Name):
221
+ # found *.Gogh.**
222
+ parent: ast.Name
223
+ if parent.id == varname_contains_femtet:
224
+ # found Femtet.Gogh.**
225
+ return True
226
+
227
+ # by accessing inside method
228
+ if isinstance(parent, ast.Attribute):
229
+ # found **.*.Gogh.**
230
+ parent: ast.Attribute
231
+ if parent.attr == 'Femtet':
232
+ # found **.Femtet.Gogh.**
233
+ return True
234
+
235
+ # ここまで来たならば target へのアクセスはおそらくない
236
+ return False
187
237
 
188
238
 
189
239
  def _is_access_gogh(fun):
190
- return _check_accsess_femtet_objects(fun, target='Gogh')
240
+ return _check_access_femtet_objects(fun, target='Gogh')
191
241
 
192
242
 
193
243
  def _is_access_femtet(fun):
194
- return _check_accsess_femtet_objects(fun)
244
+ return _check_access_femtet_objects(fun, target='Femtet')
195
245
 
196
246
 
197
247
  def is_feasible(value, lb, ub):
@@ -39,12 +39,22 @@ def do_patch(
39
39
  opt (OptunaOptimizer): OptunaOptimizer.
40
40
  """
41
41
  import optuna_integration
42
- target_fun = optuna_integration.botorch.optimize_acqf
42
+
43
+ from optuna_integration import version
44
+ if int(version.__version__.split('.')[0]) >= 4:
45
+ target_fun = optuna_integration.botorch.botorch.optimize_acqf
46
+ else:
47
+ target_fun = optuna_integration.botorch.optimize_acqf
48
+
43
49
  new_fun: callable = OptimizeReplacedACQF(target_fun)
44
50
  new_fun.set_constraints(list(constraints.values()))
45
51
  new_fun.set_study(study)
46
52
  new_fun.set_opt(opt)
47
- optuna_integration.botorch.optimize_acqf = new_fun
53
+
54
+ if int(version.__version__.split('.')[0]) >= 4:
55
+ optuna_integration.botorch.botorch.optimize_acqf = new_fun
56
+ else:
57
+ optuna_integration.botorch.optimize_acqf = new_fun
48
58
 
49
59
 
50
60
  class GeneralFunctionWithForwardDifference(torch.autograd.Function):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyfemtet
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Design parameter optimization using Femtet.
5
5
  Home-page: https://github.com/pyfemtet/pyfemtet
6
6
  License: BSD-3-Clause
@@ -22,8 +22,8 @@ Requires-Dist: distributed (>=2023.12.1,<2024.0.0)
22
22
  Requires-Dist: femtetutils (>=1.0.0,<2.0.0)
23
23
  Requires-Dist: numpy (>=1.26.2,<2.0.0)
24
24
  Requires-Dist: openpyxl (>=3.1.2,<4.0.0)
25
- Requires-Dist: optuna (>=3.4.0,<4.0.0)
26
- Requires-Dist: optuna-integration (>=3.6.0,<4.0.0)
25
+ Requires-Dist: optuna (>=3.4.0,<5.0.0)
26
+ Requires-Dist: optuna-integration (>=3.6.0,<5.0.0)
27
27
  Requires-Dist: pandas (>=2.1.3,<3.0.0)
28
28
  Requires-Dist: plotly (>=5.22.0,<6.0.0)
29
29
  Requires-Dist: psutil (>=5.9.6,<6.0.0)
@@ -1,4 +1,4 @@
1
- pyfemtet/__init__.py,sha256=PQu9BZ4UZrI--6Rc-s0RhFPPEWVTqddrgsWkwYl87dI,21
1
+ pyfemtet/__init__.py,sha256=wlmBF5A1gVspskZOpqNe0Xi1AY5ZRYF38SMV3fRd_LA,21
2
2
  pyfemtet/core.py,sha256=3lqfBGJ5IuKz2Nqj5pRo7YQqKwx_0ZDL72u95Ur_1p0,1386
3
3
  pyfemtet/dispatch_extensions.py,sha256=XVZajbjh7mb6NG4Hq8qff2TJWab75r4Hd59cIvCRsVg,16213
4
4
  pyfemtet/logger.py,sha256=JYD0FvzijMS2NvZN7VT7vZA5hqtHEkvS93AHlIMDePw,2507
@@ -11,8 +11,8 @@ pyfemtet/message/locales/ja/LC_MESSAGES/messages.po,sha256=f8rimJEqmLdlrE7JBwETm
11
11
  pyfemtet/message/locales/messages.pot,sha256=_gVMy6qaSU7Qu6zIY8KQizb1XpTZ0ijLKbnnk4lAAdg,13635
12
12
  pyfemtet/message/messages.py,sha256=i0cOOV8NnBeT1gG-tqgnu_3dIym1hZG8Hzg38sh_Qeo,13187
13
13
  pyfemtet/opt/__init__.py,sha256=MPrUWeLZLrJ-ApVckn8dsn3QmRH13aPzit5JgaoshG8,696
14
- pyfemtet/opt/_femopt.py,sha256=V1D0n8WgzDRE6NbvRzJdhxXiqHh7GGRAmvS7jyQDGfA,26611
15
- pyfemtet/opt/_femopt_core.py,sha256=ocn7qOMCDRXuS-3DRXgGIo1hGnewUYSUxE7BuvqCXMY,27858
14
+ pyfemtet/opt/_femopt.py,sha256=_WxsnCk22UnnFPeGxVOrVDyWnuOOVUwRLvUL9xSxwuQ,26998
15
+ pyfemtet/opt/_femopt_core.py,sha256=jla01evKNA3sOR-BDuMM-JN5xgh1jwtRd_0JMes4_Qc,29608
16
16
  pyfemtet/opt/_test_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  pyfemtet/opt/_test_utils/control_femtet.py,sha256=Oy2MmNS-LhUXF9rKLa8AXAfJhppIQI8Nha8LmEZflmk,1169
18
18
  pyfemtet/opt/_test_utils/hyper_sphere.py,sha256=nQhw8EIY0DwvcTqrbKhkxiITLZifr4-nG77E-_6ggmA,700
@@ -28,7 +28,7 @@ pyfemtet/opt/interface/_femtet_with_sldworks.py,sha256=Ldr8Esa5xZ-D_E5uIXBTF2DHs
28
28
  pyfemtet/opt/optimizer/__init__.py,sha256=wdz7PXkcSJ9Z2OHoegfGvYrnj_OAyU39BvDyiy3QnVw,407
29
29
  pyfemtet/opt/optimizer/_base.py,sha256=lKCDGoAtOLwqNaP7qfqYJ69AHxq9YZVivTP14VHYxZU,12136
30
30
  pyfemtet/opt/optimizer/_optuna.py,sha256=MojfB0oQCjSzS-hJNiD_Wn-vPDJbsMUydMq2ht6Ww9g,11570
31
- pyfemtet/opt/optimizer/_optuna_botorchsampler_parameter_constraint_helper.py,sha256=6um5tdhpMirzwAPmp_K_YluguP0W9dWPwHJIqWICeOM,11908
31
+ pyfemtet/opt/optimizer/_optuna_botorchsampler_parameter_constraint_helper.py,sha256=dJsQIbPeAI9N46iavTB6PDpoZ_Ol7WFVEOPN6Pdx7KM,12223
32
32
  pyfemtet/opt/optimizer/_scipy.py,sha256=M3q25VuRazDzXUWC25z7hGbNq2Qg9158NjTSNBvi2pk,4347
33
33
  pyfemtet/opt/optimizer/_scipy_scalar.py,sha256=YmErX4s_ywVIn861-D06d-TvDWi0rp843Jit3x80qtU,3202
34
34
  pyfemtet/opt/parameter.py,sha256=YLE9lmYRaZA8isnTPJnbYXpUn6zsJFW4xg03QaSWey8,3950
@@ -108,8 +108,8 @@ pyfemtet/opt/visualization/wrapped_components/dbc.py,sha256=wzR1ZMOb4uwPNTMFn5up
108
108
  pyfemtet/opt/visualization/wrapped_components/dcc.py,sha256=hcW7SR6VIMn4S4-JMyohvOzdc0Aw8A4chIeHqQEUbFU,17499
109
109
  pyfemtet/opt/visualization/wrapped_components/html.py,sha256=sE2XHTDY1GvA1NW7y6SKWf-WglVXFKKvXhU9h3z53_g,95652
110
110
  pyfemtet/opt/visualization/wrapped_components/str_enum.py,sha256=NZqbh2jNEAckvJyZv__MWeRs2F2Q-dkJCWo30rU2rrM,1383
111
- pyfemtet-0.5.1.dist-info/LICENSE,sha256=sVQBhyoglGJUu65-BP3iR6ujORI6YgEU2Qm-V4fGlOA,1485
112
- pyfemtet-0.5.1.dist-info/METADATA,sha256=PLu9EtBr3EFxUh2vMonVk6klrI_tyaS_h9hfXO9qfRE,3287
113
- pyfemtet-0.5.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
114
- pyfemtet-0.5.1.dist-info/entry_points.txt,sha256=ZfYqRaoiPtuWqFi2_msccyrVF0LurMn-IHlYamAegZo,104
115
- pyfemtet-0.5.1.dist-info/RECORD,,
111
+ pyfemtet-0.5.2.dist-info/LICENSE,sha256=sVQBhyoglGJUu65-BP3iR6ujORI6YgEU2Qm-V4fGlOA,1485
112
+ pyfemtet-0.5.2.dist-info/METADATA,sha256=jdH1UdFRexWUeZ9saoDfjoFmw55OkOlGp6fLDxHJyTg,3287
113
+ pyfemtet-0.5.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
114
+ pyfemtet-0.5.2.dist-info/entry_points.txt,sha256=ZfYqRaoiPtuWqFi2_msccyrVF0LurMn-IHlYamAegZo,104
115
+ pyfemtet-0.5.2.dist-info/RECORD,,