pyfemtet 0.8.7__py3-none-any.whl → 0.8.8__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.8.7"
1
+ __version__ = "0.8.8"
@@ -16,37 +16,35 @@ class SurrogateModelInterfaceBase(FEMInterface, ABC):
16
16
  def __init__(
17
17
  self,
18
18
  history_path: str = None,
19
- history: History = None,
20
- override_objective: bool = True,
19
+ train_history: History = None,
21
20
  ):
22
21
 
23
- self.history: History
22
+ self.train_history: History
24
23
  self.model: Any
25
24
  self.prm: dict[str, float] = dict()
26
25
  self.obj: dict[str, float] = dict()
27
26
  self.df_prm: pd.DataFrame
28
27
  self.df_obj: pd.DataFrame
29
- self.override_objective: bool = override_objective
30
28
 
31
- # history_path が与えられた場合、history をコンストラクトする
29
+ # history_path が与えられた場合、train_history をコンストラクトする
32
30
  if history_path is not None:
33
- history = History(history_path=history_path)
31
+ train_history = History(history_path=history_path)
34
32
 
35
- # history が与えられるかコンストラクトされている場合
36
- if history is not None:
33
+ # train_history が与えられるかコンストラクトされている場合
34
+ if train_history is not None:
37
35
  # 学習データを準備する
38
- df_prm = history.get_df()[history.prm_names]
39
- df_obj = history.get_df()[history.obj_names]
36
+ df_prm = train_history.get_df()[train_history.prm_names]
37
+ df_obj = train_history.get_df()[train_history.obj_names]
40
38
 
41
39
  # obj の名前を作る
42
- for obj_name in history.obj_names:
40
+ for obj_name in train_history.obj_names:
43
41
  self.obj[obj_name] = np.nan
44
42
 
45
43
  # prm の名前を作る
46
- for prm_name in history.prm_names:
44
+ for prm_name in train_history.prm_names:
47
45
  self.prm[prm_name] = np.nan
48
46
 
49
- self.history = history
47
+ self.train_history = train_history
50
48
 
51
49
  # history から作らない場合、引数チェック
52
50
  else:
@@ -58,8 +56,7 @@ class SurrogateModelInterfaceBase(FEMInterface, ABC):
58
56
 
59
57
  FEMInterface.__init__(
60
58
  self,
61
- history=history, # コンストラクト済み history を渡せば並列計算時も何もしなくてよい
62
- override_objective=self.override_objective
59
+ train_history=train_history, # コンストラクト済み train_history を渡せば並列計算時も何もしなくてよい
63
60
  )
64
61
 
65
62
  def filter_feasible(self, x: np.ndarray, y: np.ndarray, return_feasibility=False):
@@ -73,10 +70,14 @@ class SurrogateModelInterfaceBase(FEMInterface, ABC):
73
70
  return x[feasible_idx], y[feasible_idx]
74
71
 
75
72
  def _setup_after_parallel(self, *args, **kwargs):
76
- if self.override_objective:
77
- opt: AbstractOptimizer = kwargs['opt']
78
- obj: Objective
79
- for obj_name, obj in opt.objectives.items():
73
+ opt: AbstractOptimizer = kwargs['opt']
74
+ obj: Objective
75
+
76
+ # add_objective された目的のうち、
77
+ # training data に含まれる名前で
78
+ # あるものは fun を上書き
79
+ for obj_name, obj in opt.objectives.items():
80
+ if obj_name in self.train_history.obj_names:
80
81
  obj.fun = lambda obj_name_=obj_name: self.obj[obj_name_]
81
82
 
82
83
  def update_parameter(self, parameters: pd.DataFrame, with_warning=False) -> Optional[List[str]]:
@@ -27,7 +27,7 @@ class PolynomialChaosInterface(SurrogateModelInterfaceBase):
27
27
 
28
28
  # train model
29
29
  self.model = PolynomialExpansionModel()
30
- self.model.set_bounds_from_history(self.history)
30
+ self.model.set_bounds_from_history(self.train_history)
31
31
  self.train()
32
32
 
33
33
  def update(self, parameters: pd.DataFrame) -> None:
@@ -37,13 +37,13 @@ class PolynomialChaosInterface(SurrogateModelInterfaceBase):
37
37
  )
38
38
 
39
39
  # history.prm_name 順に並べ替え
40
- x = np.array([self.prm[k] for k in self.history.prm_names])
40
+ x = np.array([self.prm[k] for k in self.train_history.prm_names])
41
41
 
42
42
  # prediction
43
43
  dist_mean, _ = self.model.predict(x)
44
44
 
45
45
  # 目的関数の更新
46
- self.obj = {obj_name: value for obj_name, value in zip(self.history.obj_names, dist_mean)}
46
+ self.obj = {obj_name: value for obj_name, value in zip(self.train_history.obj_names, dist_mean)}
47
47
 
48
48
 
49
49
  if __name__ == '__main__':
@@ -40,12 +40,12 @@ class PoFBoTorchInterface(SurrogateModelInterfaceBase):
40
40
 
41
41
  # model training
42
42
  self.model = SingleTaskGPModel()
43
- self.model.set_bounds_from_history(self.history)
43
+ self.model.set_bounds_from_history(self.train_history)
44
44
  self.train()
45
45
 
46
46
  # model_f training
47
47
  self.model_f = SingleTaskGPModel(is_noise_free=False)
48
- self.model_f.set_bounds_from_history(self.history)
48
+ self.model_f.set_bounds_from_history(self.train_history)
49
49
  self.train_f()
50
50
 
51
51
  def update(self, parameters: pd.DataFrame) -> None:
@@ -54,8 +54,8 @@ class PoFBoTorchInterface(SurrogateModelInterfaceBase):
54
54
  self, parameters
55
55
  )
56
56
 
57
- # history.prm_name 順に並べ替え
58
- x = np.array([self.prm[k] for k in self.history.prm_names])
57
+ # train_history.prm_name 順に並べ替え
58
+ x = np.array([self.prm[k] for k in self.train_history.prm_names])
59
59
 
60
60
  # feasibility の計算
61
61
  mean_f, std_f = self.model_f.predict(np.array([x]))
@@ -63,9 +63,9 @@ class PoFBoTorchInterface(SurrogateModelInterfaceBase):
63
63
  if pof < self.threshold:
64
64
  raise SolveError(Msg.INFO_POF_IS_LESS_THAN_THRESHOLD)
65
65
 
66
- # 実際の計算(mean は history.obj_names 順)
66
+ # 実際の計算(現時点で mean は train_history.obj_names 順)
67
67
  _mean, _std = self.model.predict(np.array([x]))
68
68
  mean = _mean[0]
69
69
 
70
70
  # 目的関数の更新
71
- self.obj = {obj_name: value for obj_name, value in zip(self.history.obj_names, mean)}
71
+ self.obj = {obj_name: value for obj_name, value in zip(self.train_history.obj_names, mean)}
@@ -206,7 +206,7 @@ class OptunaOptimizer(AbstractOptimizer):
206
206
  """Create storage, study and set initial parameter."""
207
207
 
208
208
  # create storage
209
- self.study_name = os.path.basename(self.history.path)
209
+ self.study_name = 'pyfemtet-study'
210
210
  storage_path = self.history.path.replace('.csv', '.db') # history と同じところに保存
211
211
  if self.is_cluster: # remote cluster なら scheduler の working dir に保存
212
212
  storage_path = os.path.basename(self.history.path).replace('.csv', '.db')
@@ -374,6 +374,17 @@ class OptunaOptimizer(AbstractOptimizer):
374
374
  sampler._pyfemtet_optimizer = self
375
375
 
376
376
  # load study
377
+ self.storage: optuna.storages.BaseStorage
378
+ studies = self.storage.get_all_studies()
379
+ if self.study_name in [s.study_name for s in studies]:
380
+ pass
381
+
382
+ elif len(studies) >= 1:
383
+ self.study_name = studies[-1].study_name
384
+
385
+ else:
386
+ raise ValueError('An empty db is passed.')
387
+
377
388
  study = optuna.load_study(
378
389
  study_name=self.study_name,
379
390
  storage=self.storage,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pyfemtet
3
- Version: 0.8.7
3
+ Version: 0.8.8
4
4
  Summary: Design parameter optimization using Femtet.
5
5
  License: BSD-3-Clause
6
6
  Author: kazuma.naito
@@ -1,4 +1,4 @@
1
- pyfemtet/__init__.py,sha256=04WO81p8xrQAHiTKqHaDkKWih6M2Y3Hy-UCNVwih4Zc,21
1
+ pyfemtet/__init__.py,sha256=c6aqZCQlw_39oSCH27ZXK8D1ktjy9L8kQ5LAj1IEYHs,21
2
2
  pyfemtet/_femtet_config_util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  pyfemtet/_femtet_config_util/autosave.py,sha256=dNirA9XGuFehas8_Jkj2BW9GOzMbPyhnt1WHcH_ObSU,2070
4
4
  pyfemtet/_femtet_config_util/exit.py,sha256=0BWID-tjOkmZwmgPFkcJMkWW39voccz5ARIBWvZbHaw,1877
@@ -49,15 +49,15 @@ pyfemtet/opt/interface/_femtet_with_nx/_interface.py,sha256=LkaODUSpBLq05uz5Jf-J
49
49
  pyfemtet/opt/interface/_femtet_with_nx/update_model.py,sha256=P7VH0i_o-X9OUe6AGaLF1fACPeHNrMjcrOBCA3MMrI4,3092
50
50
  pyfemtet/opt/interface/_femtet_with_sldworks.py,sha256=rjEgebuP1w1eAFVWw4eRJUq3lsyBcmXlkMjZKIpD0kw,11019
51
51
  pyfemtet/opt/interface/_surrogate/__init__.py,sha256=2UT5NuBylyWQJNjg1zsBRCV-MzNCUswTUt6ZuSrYFUM,120
52
- pyfemtet/opt/interface/_surrogate/_base.py,sha256=bQMoztVq1b-3BW5Z1V-dSROplMHutrblDI289j0cC-E,3001
53
- pyfemtet/opt/interface/_surrogate/_chaospy.py,sha256=gL72bCgs1AY_EZdJtcifSC-apwsZzp4zsWYxcpVKvtw,1969
54
- pyfemtet/opt/interface/_surrogate/_singletaskgp.py,sha256=ojZHsxGxSc8ZJqJQ_uMHvpK98TPUsHzXP0q4tmM0YPQ,2471
52
+ pyfemtet/opt/interface/_surrogate/_base.py,sha256=_mVjoxrGEWL-PydjzEYXIgsOJ9zPmntoRHY3dXR2HGo,3098
53
+ pyfemtet/opt/interface/_surrogate/_chaospy.py,sha256=Bqej89Mo0zgdJq1OK7YKRqHOcuyN0wL4ZQUQXdJtYJ8,1987
54
+ pyfemtet/opt/interface/_surrogate/_singletaskgp.py,sha256=bHzY5QIjA9zhLxweexz259XQMZLgkHWfrIDW7f3q-2k,2520
55
55
  pyfemtet/opt/optimizer/__init__.py,sha256=Ia6viowECkG0IFXtFef0tJ4jDKsoDzJLqMJ9xLFH2LQ,543
56
56
  pyfemtet/opt/optimizer/_base.py,sha256=j8aQc3fGehZTJT9ETf9cr3VWYs2FYk1F8fO3f7QyKAU,13099
57
57
  pyfemtet/opt/optimizer/_optuna/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
58
  pyfemtet/opt/optimizer/_optuna/_botorch_patch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
59
59
  pyfemtet/opt/optimizer/_optuna/_botorch_patch/enable_nonlinear_constraint.py,sha256=b2-PP2HM46kJS4cJkBWnxnW9AS9JfeVkEjmkoKK_ziE,8949
60
- pyfemtet/opt/optimizer/_optuna/_optuna.py,sha256=5Bjn8LrWpIFWH3lRq6Ke5XYzKQNwoGWNHz59HNMEALA,17093
60
+ pyfemtet/opt/optimizer/_optuna/_optuna.py,sha256=7CpgfetCSNAdO8ppe7uKr0gyXNu0Nn6BILYTv25LEeo,17410
61
61
  pyfemtet/opt/optimizer/_optuna/_pof_botorch.py,sha256=FLx9p6IH8xcZl_SZYvs8grMqLEidj5YaBD8urDD88Pk,73768
62
62
  pyfemtet/opt/optimizer/_scipy.py,sha256=_2whhMNq6hC1lr5PlYhpZ8Zlh6-DkAjz8SVB5qHIpYg,4766
63
63
  pyfemtet/opt/optimizer/_scipy_scalar.py,sha256=rGvrLjrgfYzxK9GA0-r2Hhoaqt6A0TQsT_1M3moyklc,3615
@@ -137,8 +137,8 @@ pyfemtet/opt/visualization/result_viewer/.gitignore,sha256=ryvb4aqbbsHireHWlPQfx
137
137
  pyfemtet/opt/visualization/result_viewer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
138
138
  pyfemtet/opt/visualization/result_viewer/application.py,sha256=WcHBx_J5eNLKSaprpk9BGifwhO04oN8FiNGYTWorrXA,1691
139
139
  pyfemtet/opt/visualization/result_viewer/pages.py,sha256=MZAjzbuq0toZrR-iJhElM3A12_jHVCTt65gz1kdNPbw,32193
140
- pyfemtet-0.8.7.dist-info/LICENSE,sha256=sVQBhyoglGJUu65-BP3iR6ujORI6YgEU2Qm-V4fGlOA,1485
141
- pyfemtet-0.8.7.dist-info/METADATA,sha256=uy1fm6IKQ5OXU8kZ7bowgMIyCbyaQ9NTgaxz0r1DoV0,3509
142
- pyfemtet-0.8.7.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
143
- pyfemtet-0.8.7.dist-info/entry_points.txt,sha256=ZfYqRaoiPtuWqFi2_msccyrVF0LurMn-IHlYamAegZo,104
144
- pyfemtet-0.8.7.dist-info/RECORD,,
140
+ pyfemtet-0.8.8.dist-info/LICENSE,sha256=sVQBhyoglGJUu65-BP3iR6ujORI6YgEU2Qm-V4fGlOA,1485
141
+ pyfemtet-0.8.8.dist-info/METADATA,sha256=AVeQJlDibc-xh4Lsz20Y3KiNqrmN7TWR7cgIg0Kp3a4,3509
142
+ pyfemtet-0.8.8.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
143
+ pyfemtet-0.8.8.dist-info/entry_points.txt,sha256=ZfYqRaoiPtuWqFi2_msccyrVF0LurMn-IHlYamAegZo,104
144
+ pyfemtet-0.8.8.dist-info/RECORD,,