pyfemtet 0.9.4__py3-none-any.whl → 1.0.0a0__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 (272) hide show
  1. pyfemtet/__init__.py +6 -1
  2. pyfemtet/_i18n/1. make_pot_and_update_po.bat +8 -0
  3. pyfemtet/_i18n/2. build_mo.bat +5 -0
  4. pyfemtet/_i18n/__init__.py +4 -0
  5. pyfemtet/_i18n/babel.cfg +2 -0
  6. pyfemtet/_i18n/i18n.py +37 -0
  7. pyfemtet/_i18n/locales/ja/LC_MESSAGES/messages.mo +0 -0
  8. pyfemtet/_i18n/locales/ja/LC_MESSAGES/messages.po +1020 -0
  9. pyfemtet/_i18n/locales/messages.pot +987 -0
  10. pyfemtet/{_message → _i18n}/messages.py +128 -41
  11. pyfemtet/_util/closing.py +19 -0
  12. pyfemtet/_util/dask_util.py +89 -7
  13. pyfemtet/_util/df_util.py +29 -0
  14. pyfemtet/_util/excel_macro_util.py +8 -3
  15. pyfemtet/_util/excel_parse_util.py +43 -23
  16. pyfemtet/_util/femtet_access_inspection.py +120 -0
  17. pyfemtet/{_femtet_config_util/autosave.py → _util/femtet_autosave.py} +7 -0
  18. pyfemtet/_util/femtet_exit.py +105 -0
  19. pyfemtet/_util/femtet_version.py +20 -0
  20. pyfemtet/_util/helper.py +94 -0
  21. pyfemtet/_util/process_util.py +107 -0
  22. pyfemtet/_util/str_enum.py +44 -0
  23. pyfemtet/core.py +15 -47
  24. pyfemtet/dispatch_extensions/__init__.py +8 -11
  25. pyfemtet/dispatch_extensions/_impl.py +42 -198
  26. pyfemtet/logger/__init__.py +8 -1
  27. pyfemtet/logger/_impl.py +5 -6
  28. pyfemtet/opt/__init__.py +3 -19
  29. pyfemtet/opt/exceptions.py +45 -0
  30. pyfemtet/opt/femopt.py +602 -0
  31. pyfemtet/opt/history/__init__.py +11 -0
  32. pyfemtet/opt/history/_history.py +1404 -0
  33. pyfemtet/opt/history/_hypervolume.py +169 -0
  34. pyfemtet/opt/history/_optimality.py +79 -0
  35. pyfemtet/opt/interface/__init__.py +17 -24
  36. pyfemtet/opt/interface/_base_interface.py +222 -0
  37. pyfemtet/opt/interface/_excel_interface/__init__.py +3 -0
  38. pyfemtet/opt/interface/_excel_interface/debug-excel-interface.xlsm +0 -0
  39. pyfemtet/opt/interface/_excel_interface/excel_interface.py +999 -0
  40. pyfemtet/opt/interface/_femtet_interface/__init__.py +3 -0
  41. pyfemtet/opt/interface/{_femtet_parametric.py → _femtet_interface/_femtet_parametric.py} +20 -12
  42. pyfemtet/opt/interface/{_femtet.py → _femtet_interface/femtet_interface.py} +490 -348
  43. pyfemtet/opt/interface/_femtet_with_nx_interface/__init__.py +5 -0
  44. pyfemtet/opt/interface/_femtet_with_nx_interface/femtet_with_nx_interface.py +230 -0
  45. pyfemtet/opt/interface/_femtet_with_nx_interface/model1.prt +0 -0
  46. pyfemtet/opt/interface/_femtet_with_nx_interface/model1.x_t +98 -0
  47. pyfemtet/opt/interface/{_femtet_with_nx → _femtet_with_nx_interface}/update_model.py +1 -3
  48. pyfemtet/opt/interface/_femtet_with_solidworks/__init__.py +5 -0
  49. pyfemtet/opt/interface/_femtet_with_solidworks/femtet_with_solidworks_interface.py +122 -0
  50. pyfemtet/opt/interface/_solidworks_interface/__init__.py +5 -0
  51. pyfemtet/opt/interface/_solidworks_interface/solidworks_interface.py +206 -0
  52. pyfemtet/opt/interface/_surrogate/_base.py +0 -129
  53. pyfemtet/opt/interface/_surrogate_model_interface/__init__.py +8 -0
  54. pyfemtet/opt/interface/_surrogate_model_interface/base_surrogate_interface.py +59 -0
  55. pyfemtet/opt/interface/_surrogate_model_interface/botorch_interface.py +271 -0
  56. pyfemtet/opt/interface/_surrogate_model_interface/debug-pof-botorch.reccsv +18 -0
  57. pyfemtet/opt/interface/_with_excel_settings/__init__.py +61 -0
  58. pyfemtet/opt/interface/_with_excel_settings/with_excel_settings.py +134 -0
  59. pyfemtet/opt/meta_script/YAML_Generator.xlsm +0 -0
  60. pyfemtet/opt/meta_script/__main__.py +58 -36
  61. pyfemtet/opt/optimizer/__init__.py +7 -9
  62. pyfemtet/opt/optimizer/_base_optimizer.py +876 -0
  63. pyfemtet/opt/optimizer/optuna_optimizer/__init__.py +9 -0
  64. pyfemtet/opt/optimizer/optuna_optimizer/_optuna_attribute.py +73 -0
  65. pyfemtet/opt/optimizer/optuna_optimizer/_optuna_optimizer.py +678 -0
  66. pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/__init__.py +7 -0
  67. pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/debug-pof-botorch.reccsv +18 -0
  68. pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/enable_nonlinear_constraint.py +244 -0
  69. pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/pof_botorch_sampler.py +1249 -0
  70. pyfemtet/opt/optimizer/optuna_optimizer/wat_ex14_parametric_jp.femprj +0 -0
  71. pyfemtet/opt/optimizer/scipy_optimizer/__init__.py +1 -0
  72. pyfemtet/opt/optimizer/scipy_optimizer/_scipy_optimizer.py +364 -0
  73. pyfemtet/opt/prediction/__init__.py +7 -0
  74. pyfemtet/opt/prediction/_botorch_utils.py +133 -0
  75. pyfemtet/opt/prediction/_gpytorch_modules_extension.py +142 -0
  76. pyfemtet/opt/prediction/_helper.py +155 -0
  77. pyfemtet/opt/prediction/_model.py +118 -0
  78. pyfemtet/opt/problem/problem.py +304 -0
  79. pyfemtet/opt/problem/variable_manager/__init__.py +20 -0
  80. pyfemtet/opt/problem/variable_manager/_string_as_expression.py +115 -0
  81. pyfemtet/opt/problem/variable_manager/_variable_manager.py +295 -0
  82. pyfemtet/opt/visualization/history_viewer/__main__.py +5 -0
  83. pyfemtet/opt/visualization/{_base.py → history_viewer/_base_application.py} +18 -13
  84. pyfemtet/opt/visualization/history_viewer/_common_pages.py +150 -0
  85. pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/alert_region.py +10 -5
  86. pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/control_femtet.py +16 -13
  87. pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/main_graph.py +117 -47
  88. pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/pm_graph.py +159 -138
  89. pyfemtet/opt/visualization/history_viewer/_process_monitor/_application.py +173 -0
  90. pyfemtet/opt/visualization/history_viewer/_process_monitor/_pages.py +291 -0
  91. pyfemtet/opt/visualization/{_wrapped_components → history_viewer/_wrapped_components}/dbc.py +1 -1
  92. pyfemtet/opt/visualization/{_wrapped_components → history_viewer/_wrapped_components}/dcc.py +1 -1
  93. pyfemtet/opt/visualization/{_wrapped_components → history_viewer/_wrapped_components}/html.py +1 -1
  94. pyfemtet/opt/visualization/history_viewer/result_viewer/__main__.py +5 -0
  95. pyfemtet/opt/visualization/{result_viewer/application.py → history_viewer/result_viewer/_application.py} +6 -6
  96. pyfemtet/opt/visualization/{result_viewer/pages.py → history_viewer/result_viewer/_pages.py} +106 -82
  97. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08.csv +18 -0
  98. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08.db +0 -0
  99. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8.jpg +0 -0
  100. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8.log +45 -0
  101. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8.pdt +0 -0
  102. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_1.jpg +0 -0
  103. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_1.pdt +0 -0
  104. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_10.jpg +0 -0
  105. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_10.pdt +0 -0
  106. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_11.jpg +0 -0
  107. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_11.pdt +0 -0
  108. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_12.jpg +0 -0
  109. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_12.pdt +0 -0
  110. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_13.jpg +0 -0
  111. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_13.pdt +0 -0
  112. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_14.jpg +0 -0
  113. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_14.pdt +0 -0
  114. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_15.jpg +0 -0
  115. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_15.pdt +0 -0
  116. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_16.jpg +0 -0
  117. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_16.pdt +0 -0
  118. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_17.jpg +0 -0
  119. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_17.pdt +0 -0
  120. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_18.jpg +0 -0
  121. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_18.pdt +0 -0
  122. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_19.jpg +0 -0
  123. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_19.pdt +0 -0
  124. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_2.jpg +0 -0
  125. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_2.pdt +0 -0
  126. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_20.jpg +0 -0
  127. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_20.pdt +0 -0
  128. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_3.jpg +0 -0
  129. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_3.pdt +0 -0
  130. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.bgr +0 -0
  131. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.bnd +0 -0
  132. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.btr +0 -0
  133. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.jpg +0 -0
  134. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.mtl +0 -0
  135. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.pdt +0 -0
  136. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.prm +0 -0
  137. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_5.jpg +0 -0
  138. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_5.pdt +0 -0
  139. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_6.jpg +0 -0
  140. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_6.pdt +0 -0
  141. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_7.jpg +0 -0
  142. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_7.pdt +0 -0
  143. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_8.jpg +0 -0
  144. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_8.pdt +0 -0
  145. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_9.jpg +0 -0
  146. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_9.pdt +0 -0
  147. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.femprj +0 -0
  148. pyfemtet/opt/visualization/plotter/main_figure_creator.py +536 -0
  149. pyfemtet/opt/visualization/plotter/pm_graph_creator.py +359 -0
  150. pyfemtet/opt/worker_status.py +120 -0
  151. {pyfemtet-0.9.4.dist-info → pyfemtet-1.0.0a0.dist-info}/METADATA +22 -24
  152. pyfemtet-1.0.0a0.dist-info/RECORD +173 -0
  153. pyfemtet-1.0.0a0.dist-info/entry_points.txt +3 -0
  154. pyfemtet/_femtet_config_util/exit.py +0 -59
  155. pyfemtet/_message/1. make_pot.bat +0 -11
  156. pyfemtet/_message/2. make_mo.bat +0 -6
  157. pyfemtet/_message/__init__.py +0 -5
  158. pyfemtet/_message/babel.cfg +0 -2
  159. pyfemtet/_message/locales/ja/LC_MESSAGES/messages.mo +0 -0
  160. pyfemtet/_message/locales/ja/LC_MESSAGES/messages.po +0 -570
  161. pyfemtet/_message/locales/messages.pot +0 -551
  162. pyfemtet/_warning.py +0 -87
  163. pyfemtet/brep/_impl.py +0 -18
  164. pyfemtet/opt/_femopt.py +0 -1007
  165. pyfemtet/opt/_femopt_core.py +0 -1169
  166. pyfemtet/opt/_test_utils/control_femtet.py +0 -39
  167. pyfemtet/opt/_test_utils/hyper_sphere.py +0 -24
  168. pyfemtet/opt/_test_utils/record_history.py +0 -130
  169. pyfemtet/opt/advanced_samples/excel_ui/(ref) original_project.femprj +0 -0
  170. pyfemtet/opt/advanced_samples/excel_ui/femtet-macro.xlsm +0 -0
  171. pyfemtet/opt/advanced_samples/excel_ui/pyfemtet-core.py +0 -291
  172. pyfemtet/opt/advanced_samples/excel_ui/test-pyfemtet-core.cmd +0 -22
  173. pyfemtet/opt/advanced_samples/restart/gal_ex13_parametric.femprj +0 -0
  174. pyfemtet/opt/advanced_samples/restart/gal_ex13_parametric_restart.py +0 -99
  175. pyfemtet/opt/advanced_samples/restart/gal_ex13_parametric_restart_jp.py +0 -102
  176. pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_create_training_data.py +0 -60
  177. pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_create_training_data_jp.py +0 -57
  178. pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_optimize_with_surrogate.py +0 -100
  179. pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_optimize_with_surrogate_jp.py +0 -90
  180. pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_parametric.femprj +0 -0
  181. pyfemtet/opt/interface/_base.py +0 -101
  182. pyfemtet/opt/interface/_excel_interface.py +0 -984
  183. pyfemtet/opt/interface/_femtet_excel.py +0 -141
  184. pyfemtet/opt/interface/_femtet_with_nx/__init__.py +0 -3
  185. pyfemtet/opt/interface/_femtet_with_nx/_interface.py +0 -178
  186. pyfemtet/opt/interface/_femtet_with_sldworks.py +0 -298
  187. pyfemtet/opt/interface/_surrogate/__init__.py +0 -5
  188. pyfemtet/opt/interface/_surrogate/_chaospy.py +0 -71
  189. pyfemtet/opt/interface/_surrogate/_singletaskgp.py +0 -71
  190. pyfemtet/opt/interface/_surrogate_excel.py +0 -102
  191. pyfemtet/opt/optimizer/_base.py +0 -376
  192. pyfemtet/opt/optimizer/_optuna/_botorch_patch/enable_nonlinear_constraint.py +0 -220
  193. pyfemtet/opt/optimizer/_optuna/_optuna.py +0 -434
  194. pyfemtet/opt/optimizer/_optuna/_pof_botorch.py +0 -1914
  195. pyfemtet/opt/optimizer/_scipy.py +0 -159
  196. pyfemtet/opt/optimizer/_scipy_scalar.py +0 -127
  197. pyfemtet/opt/optimizer/parameter.py +0 -113
  198. pyfemtet/opt/prediction/_base.py +0 -61
  199. pyfemtet/opt/prediction/single_task_gp.py +0 -119
  200. pyfemtet/opt/samples/femprj_sample/ParametricIF.femprj +0 -0
  201. pyfemtet/opt/samples/femprj_sample/ParametricIF.py +0 -29
  202. pyfemtet/opt/samples/femprj_sample/ParametricIF_test_result.reccsv +0 -13
  203. pyfemtet/opt/samples/femprj_sample/cad_ex01_NX.femprj +0 -0
  204. pyfemtet/opt/samples/femprj_sample/cad_ex01_NX.prt +0 -0
  205. pyfemtet/opt/samples/femprj_sample/cad_ex01_NX.py +0 -135
  206. pyfemtet/opt/samples/femprj_sample/cad_ex01_NX_test_result.reccsv +0 -23
  207. pyfemtet/opt/samples/femprj_sample/cad_ex01_SW.SLDPRT +0 -0
  208. pyfemtet/opt/samples/femprj_sample/cad_ex01_SW.femprj +0 -0
  209. pyfemtet/opt/samples/femprj_sample/cad_ex01_SW.py +0 -131
  210. pyfemtet/opt/samples/femprj_sample/cad_ex01_SW_test_result.reccsv +0 -23
  211. pyfemtet/opt/samples/femprj_sample/constrained_pipe.femprj +0 -0
  212. pyfemtet/opt/samples/femprj_sample/constrained_pipe.py +0 -96
  213. pyfemtet/opt/samples/femprj_sample/constrained_pipe_test_result.reccsv +0 -13
  214. pyfemtet/opt/samples/femprj_sample/gal_ex58_parametric.femprj +0 -0
  215. pyfemtet/opt/samples/femprj_sample/gal_ex58_parametric.py +0 -74
  216. pyfemtet/opt/samples/femprj_sample/gal_ex58_parametric_test_result.reccsv +0 -13
  217. pyfemtet/opt/samples/femprj_sample/gau_ex08_parametric.femprj +0 -0
  218. pyfemtet/opt/samples/femprj_sample/gau_ex08_parametric.py +0 -58
  219. pyfemtet/opt/samples/femprj_sample/gau_ex08_parametric_test_result.reccsv +0 -23
  220. pyfemtet/opt/samples/femprj_sample/gau_ex12_parametric.femprj +0 -0
  221. pyfemtet/opt/samples/femprj_sample/gau_ex12_parametric.py +0 -52
  222. pyfemtet/opt/samples/femprj_sample/her_ex40_parametric.femprj +0 -0
  223. pyfemtet/opt/samples/femprj_sample/her_ex40_parametric.py +0 -138
  224. pyfemtet/opt/samples/femprj_sample/her_ex40_parametric_test_result.reccsv +0 -18
  225. pyfemtet/opt/samples/femprj_sample/paswat_ex1_parametric.femprj +0 -0
  226. pyfemtet/opt/samples/femprj_sample/paswat_ex1_parametric.py +0 -60
  227. pyfemtet/opt/samples/femprj_sample/paswat_ex1_parametric_parallel.py +0 -61
  228. pyfemtet/opt/samples/femprj_sample/paswat_ex1_parametric_test_result.reccsv +0 -18
  229. pyfemtet/opt/samples/femprj_sample/wat_ex14_parametric.femprj +0 -0
  230. pyfemtet/opt/samples/femprj_sample/wat_ex14_parametric.py +0 -58
  231. pyfemtet/opt/samples/femprj_sample/wat_ex14_parametric_parallel.py +0 -58
  232. pyfemtet/opt/samples/femprj_sample/wat_ex14_parametric_test_result.reccsv +0 -18
  233. pyfemtet/opt/samples/femprj_sample_jp/ParametricIF_jp.femprj +0 -0
  234. pyfemtet/opt/samples/femprj_sample_jp/ParametricIF_jp.py +0 -29
  235. pyfemtet/opt/samples/femprj_sample_jp/cad_ex01_NX_jp.femprj +0 -0
  236. pyfemtet/opt/samples/femprj_sample_jp/cad_ex01_NX_jp.py +0 -129
  237. pyfemtet/opt/samples/femprj_sample_jp/cad_ex01_SW_jp.femprj +0 -0
  238. pyfemtet/opt/samples/femprj_sample_jp/cad_ex01_SW_jp.py +0 -125
  239. pyfemtet/opt/samples/femprj_sample_jp/constrained_pipe_jp.py +0 -93
  240. pyfemtet/opt/samples/femprj_sample_jp/gal_ex58_parametric_jp.femprj +0 -0
  241. pyfemtet/opt/samples/femprj_sample_jp/gal_ex58_parametric_jp.py +0 -70
  242. pyfemtet/opt/samples/femprj_sample_jp/gau_ex08_parametric_jp.femprj +0 -0
  243. pyfemtet/opt/samples/femprj_sample_jp/gau_ex08_parametric_jp.py +0 -57
  244. pyfemtet/opt/samples/femprj_sample_jp/gau_ex12_parametric_jp.py +0 -52
  245. pyfemtet/opt/samples/femprj_sample_jp/her_ex40_parametric_jp.femprj +0 -0
  246. pyfemtet/opt/samples/femprj_sample_jp/her_ex40_parametric_jp.py +0 -138
  247. pyfemtet/opt/samples/femprj_sample_jp/paswat_ex1_parametric_jp.femprj +0 -0
  248. pyfemtet/opt/samples/femprj_sample_jp/paswat_ex1_parametric_jp.py +0 -58
  249. pyfemtet/opt/samples/femprj_sample_jp/paswat_ex1_parametric_parallel_jp.py +0 -59
  250. pyfemtet/opt/samples/femprj_sample_jp/wat_ex14_parametric_jp.py +0 -56
  251. pyfemtet/opt/samples/femprj_sample_jp/wat_ex14_parametric_parallel_jp.py +0 -56
  252. pyfemtet/opt/visualization/_complex_components/main_figure_creator.py +0 -332
  253. pyfemtet/opt/visualization/_complex_components/pm_graph_creator.py +0 -201
  254. pyfemtet/opt/visualization/_process_monitor/application.py +0 -226
  255. pyfemtet/opt/visualization/_process_monitor/pages.py +0 -406
  256. pyfemtet/opt/visualization/_wrapped_components/__init__.py +0 -0
  257. pyfemtet/opt/visualization/result_viewer/__init__.py +0 -0
  258. pyfemtet-0.9.4.dist-info/RECORD +0 -158
  259. pyfemtet-0.9.4.dist-info/entry_points.txt +0 -3
  260. /pyfemtet/{_femtet_config_util → opt/problem}/__init__.py +0 -0
  261. /pyfemtet/{brep → opt/visualization/history_viewer}/__init__.py +0 -0
  262. /pyfemtet/opt/{_test_utils → visualization/history_viewer/_complex_components}/__init__.py +0 -0
  263. /pyfemtet/opt/{optimizer/_optuna → visualization/history_viewer/_process_monitor}/__init__.py +0 -0
  264. /pyfemtet/opt/{optimizer/_optuna/_botorch_patch → visualization/history_viewer/_wrapped_components}/__init__.py +0 -0
  265. /pyfemtet/opt/visualization/{_wrapped_components → history_viewer/_wrapped_components}/str_enum.py +0 -0
  266. /pyfemtet/opt/visualization/{result_viewer → history_viewer/result_viewer}/.gitignore +0 -0
  267. /pyfemtet/opt/visualization/{_complex_components → history_viewer/result_viewer}/__init__.py +0 -0
  268. /pyfemtet/opt/visualization/{_process_monitor → plotter}/__init__.py +0 -0
  269. /pyfemtet/opt/{samples/femprj_sample_jp/wat_ex14_parametric_jp.femprj → wat_ex14_parametric_jp.femprj} +0 -0
  270. {pyfemtet-0.9.4.dist-info → pyfemtet-1.0.0a0.dist-info}/LICENSE +0 -0
  271. {pyfemtet-0.9.4.dist-info → pyfemtet-1.0.0a0.dist-info}/LICENSE_THIRD_PARTY.txt +0 -0
  272. {pyfemtet-0.9.4.dist-info → pyfemtet-1.0.0a0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,206 @@
1
+ from __future__ import annotations
2
+
3
+ from time import sleep
4
+ from typing import TYPE_CHECKING
5
+
6
+ import os
7
+ import re
8
+
9
+ from win32com.client import DispatchEx, CDispatch
10
+ # noinspection PyUnresolvedReferences
11
+ from pythoncom import CoInitialize, CoUninitialize, com_error
12
+
13
+ from pyfemtet._util.dask_util import *
14
+ from pyfemtet.opt.exceptions import *
15
+ from pyfemtet.opt.interface._base_interface import COMInterface
16
+ from pyfemtet._i18n import _
17
+ from pyfemtet.opt.problem.variable_manager import SupportedVariableTypes
18
+ from pyfemtet.logger import get_module_logger
19
+
20
+ if TYPE_CHECKING:
21
+ from pyfemtet.opt.optimizer import AbstractOptimizer
22
+
23
+
24
+ logger = get_module_logger('opt.interface', False)
25
+
26
+
27
+ # 定数の宣言
28
+ swThisConfiguration = 1 # https://help.solidworks.com/2023/english/api/swconst/SOLIDWORKS.Interop.swconst~SOLIDWORKS.Interop.swconst.swInConfigurationOpts_e.html
29
+ swAllConfiguration = 2
30
+ swSpecifyConfiguration = 3 # use with ConfigName argument
31
+ swSaveAsCurrentVersion = 0
32
+ swSaveAsOptions_Copy = 2 #
33
+ swSaveAsOptions_Silent = 1 # https://help.solidworks.com/2021/english/api/swconst/solidworks.interop.swconst~solidworks.interop.swconst.swsaveasoptions_e.html
34
+ swSaveWithReferencesOptions_None = 0 # https://help-solidworks-com.translate.goog/2023/english/api/swconst/SolidWorks.Interop.swconst~SolidWorks.Interop.swconst.swSaveWithReferencesOptions_e.html?_x_tr_sl=auto&_x_tr_tl=ja&_x_tr_hl=ja&_x_tr_pto=wapp
35
+ swDocPART = 1 # https://help.solidworks.com/2023/english/api/swconst/SOLIDWORKS.Interop.swconst~SOLIDWORKS.Interop.swconst.swDocumentTypes_e.html
36
+
37
+
38
+ class FileNotOpenedError(Exception):
39
+ pass
40
+
41
+
42
+ # noinspection PyPep8Naming
43
+ class SolidworksInterface(COMInterface):
44
+
45
+ swApp: CDispatch
46
+ com_members = {'swApp': 'SLDWORKS.Application'}
47
+ _access_sw_lock_name = 'access_sw'
48
+
49
+ def __init__(
50
+ self,
51
+ sldprt_path,
52
+ close_solidworks_on_terminate=False,
53
+ visible=True,
54
+ ):
55
+ self.sldprt_path = os.path.abspath(sldprt_path)
56
+ self.quit_solidworks_on_terminate = close_solidworks_on_terminate
57
+ self.solidworks_visible = visible
58
+
59
+ assert os.path.isfile(self.sldprt_path)
60
+ self._original_sldprt_path = self.sldprt_path
61
+
62
+ def connect_sw(self):
63
+ logger.info(_(
64
+ en_message='Connecting to Solidworks...',
65
+ jp_message='Solidworks に接続しています...'
66
+ ))
67
+ try:
68
+ self.swApp = DispatchEx('SLDWORKS.Application')
69
+ except com_error:
70
+ raise Exception(_(
71
+ en_message='Failed to instantiate Solidworks. '
72
+ 'Please check installation and enabling macro.',
73
+ jp_message='Solidworks のインスタンス化に失敗しました。'
74
+ 'Solidworks がインストールされており、'
75
+ 'Solidworks マクロが有効であることを確認してください。'))
76
+ self.swApp.Visible = self.solidworks_visible
77
+
78
+ def _setup_before_parallel(self):
79
+ self._distribute_files([self.sldprt_path])
80
+
81
+ def _setup_after_parallel(self, opt: AbstractOptimizer = None):
82
+
83
+ # get suffix
84
+ suffix = self._get_worker_index_from_optimizer(opt)
85
+
86
+ # rename and get worker path
87
+ self.sldprt_path = self._rename_and_get_path_on_worker_space(
88
+ self._original_sldprt_path,
89
+ suffix,
90
+ )
91
+
92
+ # connect solidworks
93
+ CoInitialize()
94
+ with Lock(self._access_sw_lock_name):
95
+ self.connect_sw()
96
+
97
+ # open it
98
+ self.swApp.OpenDoc(self.sldprt_path, swDocPART)
99
+
100
+ @property
101
+ def swModel(self) -> CDispatch:
102
+ return _get_model_by_basename(self.swApp, os.path.basename(self.sldprt_path))
103
+
104
+ def update(self) -> None:
105
+ raise NotImplementedError
106
+
107
+ def update_parameter(self, x: dict[str, SupportedVariableTypes]) -> None:
108
+
109
+ COMInterface.update_parameter(self, x)
110
+
111
+ # sw はプロセスが一つなので Lock
112
+ with Lock(self._access_sw_lock_name):
113
+
114
+ sleep(0.2)
115
+
116
+ # ===== model を取得 =====
117
+ swModel = self.swModel
118
+
119
+ # ===== equation manager を取得 =====
120
+ swEqnMgr = swModel.GetEquationMgr
121
+ nEquation = swEqnMgr.GetCount
122
+
123
+ # プロパティを退避
124
+ buffer_aso = swEqnMgr.AutomaticSolveOrder
125
+ buffer_ar = swEqnMgr.AutomaticRebuild
126
+ swEqnMgr.AutomaticSolveOrder = False
127
+ swEqnMgr.AutomaticRebuild = False
128
+
129
+ # 値を更新
130
+ for i in range(nEquation):
131
+ # name, equation の取得
132
+ eq = swEqnMgr.Equation(i)
133
+ prm_name = _get_name_from_equation(eq)
134
+ # 対象なら処理
135
+ if prm_name in self.current_prm_values:
136
+ new_equation = f'"{prm_name}" = {self.current_prm_values[prm_name]}'
137
+ swEqnMgr.Equation(i, new_equation)
138
+
139
+ # 式の計算
140
+ # noinspection PyStatementEffect
141
+ swEqnMgr.EvaluateAll # always returns -1
142
+
143
+ # プロパティをもとに戻す
144
+ swEqnMgr.AutomaticSolveOrder = buffer_aso
145
+ swEqnMgr.AutomaticRebuild = buffer_ar
146
+
147
+ def update_model(self):
148
+ """Update .sldprt"""
149
+
150
+ # sw はプロセスが一つなので Lock
151
+ with Lock(self._access_sw_lock_name):
152
+
153
+ sleep(0.2)
154
+
155
+ # ===== model を取得 =====
156
+ swModel = self.swModel
157
+
158
+ # モデル再構築
159
+ result = swModel.EditRebuild3 # モデル再構築
160
+ if not result:
161
+ raise ModelError(_(
162
+ en_message='Failed to update the model on Solidworks.',
163
+ jp_message='Solidworks モデルの更新に失敗しました。'
164
+ ))
165
+
166
+ def close(self):
167
+ if not hasattr(self, 'swApp'):
168
+ return
169
+
170
+ if self.swApp is None:
171
+ return
172
+
173
+ with Lock(self._access_sw_lock_name):
174
+ model_name = os.path.basename(self.sldprt_path)
175
+ logger.info(_(
176
+ en_message='Closing {model_name} ...',
177
+ jp_message='モデル {model_name} を閉じています...',
178
+ model_name=model_name,
179
+ ))
180
+
181
+ # 最後の Doc ならばプロセスを落とす仕様?
182
+ self.swApp.QuitDoc(os.path.basename(self.sldprt_path))
183
+ # logger.info(Msg.F_SW_MODEL_CLOSED(model_name))
184
+ logger.info(_(
185
+ en_message='Successfully closed {model_name}.',
186
+ jp_message='モデル {model_name} を閉じました。',
187
+ model_name=model_name,
188
+ ))
189
+ sleep(3)
190
+
191
+
192
+ # noinspection PyPep8Naming
193
+ def _get_model_by_basename(swApp, basename):
194
+ swModel = swApp.ActivateDoc(basename)
195
+ if swModel is None:
196
+ raise FileNotOpenedError(f'Model {basename} is not opened.')
197
+ return swModel
198
+
199
+
200
+ def _get_name_from_equation(equation: str):
201
+ pattern = r'^\s*"(.+?)"\s*$'
202
+ matched = re.match(pattern, equation.split('=')[0])
203
+ if matched:
204
+ return matched.group(1)
205
+ else:
206
+ return None
@@ -1,129 +0,0 @@
1
- from typing import Optional, List, Any
2
- from abc import ABC
3
-
4
- import numpy as np
5
- import pandas as pd
6
-
7
- from pyfemtet.logger import get_module_logger
8
- from pyfemtet.opt._femopt_core import History, Objective
9
- from pyfemtet.opt.interface._base import FEMInterface
10
- from pyfemtet.opt.optimizer._base import AbstractOptimizer
11
-
12
- logger = get_module_logger('opt.interface', __name__)
13
-
14
-
15
- class SurrogateModelInterfaceBase(FEMInterface, ABC):
16
- def __init__(
17
- self,
18
- history_path: str = None,
19
- train_history: History = None,
20
- _output_directions: dict[int, str | float] | list[str | float] = None,
21
- ):
22
-
23
- self.train_history: History
24
- self.model: Any
25
- self.prm: dict[str, float] = dict()
26
- self.obj: dict[str, float] = dict()
27
- self.df_prm: pd.DataFrame
28
- self.df_obj: pd.DataFrame
29
- self._output_directions = _output_directions
30
-
31
- # history_path が与えられた場合、train_history をコンストラクトする
32
- if history_path is not None:
33
- train_history = History(history_path=history_path)
34
-
35
- # train_history が与えられるかコンストラクトされている場合
36
- if train_history is not None:
37
- # 学習データを準備する
38
- df_prm = train_history.get_df()[train_history.prm_names]
39
- df_obj = train_history.get_df()[train_history.obj_names]
40
-
41
- # obj の名前を作る
42
- for obj_name in train_history.obj_names:
43
- self.obj[obj_name] = np.nan
44
-
45
- # prm の名前を作る
46
- for prm_name in train_history.prm_names:
47
- self.prm[prm_name] = np.nan
48
-
49
- self.train_history = train_history
50
-
51
- # history から作らない場合、引数チェック
52
- else:
53
- # assert len(train_x) == len(train_y)
54
- raise NotImplementedError
55
-
56
- self.df_prm = df_prm
57
- self.df_obj = df_obj
58
-
59
- # _output_directions が与えられている場合、
60
- # history から objective の設定を読み込む
61
- if self._output_directions is not None:
62
- self._load_problem_from_me: bool = True
63
-
64
- FEMInterface.__init__(
65
- self,
66
- train_history=train_history, # コンストラクト済み train_history を渡せば並列計算時も何もしなくてよい
67
- )
68
-
69
-
70
- def load_objective(self, opt) -> None:
71
- from pyfemtet.opt._femopt_core import Objective
72
-
73
- assert self._output_directions is not None
74
-
75
- if isinstance(self._output_directions, dict):
76
-
77
- for index, direction in self._output_directions:
78
- obj_name = self.train_history.obj_names[index]
79
- opt.objectives[obj_name] = Objective(
80
- lambda obj_name_=obj_name: self.obj[obj_name_],
81
- name=obj_name,
82
- direction=direction,
83
- args=(),
84
- kwargs={},
85
- )
86
-
87
- elif isinstance(self._output_directions, list) \
88
- or isinstance(self._output_directions, tuple):
89
-
90
- obj_names = self.train_history.obj_names
91
- assert len(self._output_directions) == len(obj_names)
92
-
93
- for obj_name, direction in zip(obj_names, self._output_directions):
94
- opt.objectives[obj_name] = Objective(
95
- lambda obj_name_=obj_name: self.obj[obj_name_],
96
- name=obj_name,
97
- direction=direction,
98
- args=(),
99
- kwargs={},
100
- )
101
-
102
- else:
103
- raise ValueError('Invalid _output_directions')
104
-
105
- def filter_feasible(self, x: np.ndarray, y: np.ndarray, return_feasibility=False):
106
- feasible_idx = np.where(~np.isnan(y.sum(axis=1)))
107
- if return_feasibility:
108
- # calculated or not
109
- feas = np.zeros((len(y), 1), dtype=float)
110
- feas[feasible_idx] = 1.
111
- return x, feas
112
- else:
113
- return x[feasible_idx], y[feasible_idx]
114
-
115
- def _setup_after_parallel(self, *args, **kwargs):
116
- opt: AbstractOptimizer = kwargs['opt']
117
- obj: Objective
118
-
119
- # add_objective された目的のうち、
120
- # training data に含まれる名前で
121
- # あるものは fun を上書き
122
- for obj_name, obj in opt.objectives.items():
123
- if obj_name in self.train_history.obj_names:
124
- obj.fun = lambda obj_name_=obj_name: self.obj[obj_name_]
125
-
126
- def update_parameter(self, parameters: pd.DataFrame, with_warning=False) -> Optional[List[str]]:
127
- for i, row in parameters.iterrows():
128
- name, value = row['name'], row['value']
129
- self.prm[name] = value
@@ -0,0 +1,8 @@
1
+ from .base_surrogate_interface import AbstractSurrogateModelInterfaceBase
2
+ from .botorch_interface import BoTorchInterface, PoFBoTorchInterface
3
+
4
+ __all__ = [
5
+ 'AbstractSurrogateModelInterfaceBase',
6
+ 'BoTorchInterface',
7
+ 'PoFBoTorchInterface',
8
+ ]
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ from pyfemtet.opt.history import *
6
+
7
+ from pyfemtet.opt.interface import AbstractFEMInterface
8
+
9
+ if TYPE_CHECKING:
10
+ from pyfemtet.opt.optimizer import AbstractOptimizer
11
+
12
+
13
+ __all__ = [
14
+ 'AbstractSurrogateModelInterfaceBase',
15
+ ]
16
+
17
+
18
+ class AbstractSurrogateModelInterfaceBase(AbstractFEMInterface):
19
+ current_obj_values: dict[str, float]
20
+ train_history: History
21
+
22
+ def __init__(
23
+ self,
24
+ history_path: str = None,
25
+ train_history: History = None,
26
+ ):
27
+
28
+ # history_path が与えられた場合、train_history をコンストラクトする
29
+ if history_path is not None:
30
+ train_history = History()
31
+ train_history.load_csv(history_path, with_finalize=True)
32
+
33
+ assert train_history is not None
34
+
35
+ self.train_history = train_history
36
+
37
+ self.current_obj_values = {}
38
+
39
+ def load_objectives(self, opt: AbstractOptimizer):
40
+ # add_objective された目的のうち、
41
+ # training data に含まれる名前ならば
42
+ # fun を「その時点の current_obj_values を返す関数」で
43
+ # 上書き
44
+ for obj_name, obj in opt.objectives.items():
45
+ if obj_name in self.train_history.obj_names:
46
+ obj.fun = lambda obj_name_=obj_name: self.current_obj_values[obj_name_]
47
+
48
+ def load_variables(self, opt: AbstractOptimizer):
49
+ # opt の変数が充分であるかのチェックのみ
50
+ parameters = opt.variable_manager.get_variables()
51
+ assert len(set(self.train_history.prm_names) - set(parameters.keys())) == 0
52
+
53
+ def _check_using_fem(self, fun: callable) -> bool:
54
+ return False
55
+
56
+ def _check_param_and_raise(self, prm_name) -> None:
57
+ if prm_name not in self.train_history.prm_names:
58
+ raise KeyError(f'Parameter name {prm_name} is not in '
59
+ f'training input {self.train_history.prm_names}.')
@@ -0,0 +1,271 @@
1
+ import numpy as np
2
+ from scipy.stats.distributions import norm
3
+
4
+ # from gpytorch.priors.torch_priors import GammaPrior
5
+
6
+ from pyfemtet._i18n import _
7
+ from pyfemtet.opt.history import *
8
+ from pyfemtet.opt.exceptions import *
9
+
10
+ from pyfemtet.opt.prediction._model import PyFemtetModel, SingleTaskGPModel
11
+
12
+ from pyfemtet.opt.interface._surrogate_model_interface.base_surrogate_interface import AbstractSurrogateModelInterfaceBase
13
+
14
+ from pyfemtet.logger import get_module_logger
15
+
16
+ logger = get_module_logger('opt.interface', False)
17
+
18
+
19
+ __all__ = [
20
+ 'BoTorchInterface',
21
+ 'PoFBoTorchInterface',
22
+ ]
23
+
24
+
25
+ class BoTorchInterface(AbstractSurrogateModelInterfaceBase):
26
+
27
+ def __init__(self, history_path: str = None, train_history: History = None):
28
+ AbstractSurrogateModelInterfaceBase.__init__(self, history_path, train_history)
29
+
30
+ self.model = SingleTaskGPModel()
31
+ self.pyfemtet_model = PyFemtetModel()
32
+
33
+ # get main only
34
+ df = self.train_history.get_df(MAIN_FILTER)
35
+
36
+ # filter succeeded only
37
+ df = df[df['state'] == TrialState.succeeded]
38
+
39
+ # training
40
+ self.pyfemtet_model.update_model(self.model)
41
+ self.pyfemtet_model.fit(
42
+ history=self.train_history,
43
+ df=df,
44
+ observation_noise='no',
45
+ )
46
+
47
+ def update(self) -> None:
48
+ # update current objective values
49
+ x = np.array([self.current_prm_values.values()])
50
+
51
+ y, _ = self.pyfemtet_model.predict(x)
52
+ y = y[0]
53
+
54
+ for obj_name, obj_value in zip(self.train_history.obj_names, y):
55
+ self.current_obj_values.update({obj_name: obj_value})
56
+
57
+
58
+ class PoFBoTorchInterface(BoTorchInterface, AbstractSurrogateModelInterfaceBase):
59
+
60
+ _debug: bool = False
61
+
62
+ def __init__(
63
+ self,
64
+ history_path: str,
65
+ observation_noise: float | str | None = None,
66
+ feasibility_noise: float | str | None = None,
67
+ feasibility_cdf_threshold: float | str = 0.5, # or 'sample_mean'
68
+ ):
69
+ AbstractSurrogateModelInterfaceBase.__init__(self, history_path, None)
70
+
71
+ self.model = SingleTaskGPModel()
72
+ self.pyfemtet_model = PyFemtetModel()
73
+ self.model_c = SingleTaskGPModel()
74
+ self.pyfemtet_model_c = PyFemtetModel()
75
+ self.train_history_c = History()
76
+ self.train_history_c.load_csv(history_path, with_finalize=True)
77
+ self.pof_threshold = 0.5
78
+ self.feasibility_cdf_threshold = feasibility_cdf_threshold
79
+
80
+ # use feasibility as a single objective
81
+ self.train_history_c.obj_names = ['feasibility']
82
+
83
+ # get main only
84
+ df = self.train_history.get_df(MAIN_FILTER)
85
+ df_c = self.train_history_c.get_df(MAIN_FILTER)
86
+
87
+ # filter succeeded only for main
88
+ df = df[df['state'] == TrialState.succeeded]
89
+
90
+ # convert type bool to float
91
+ df_c = df_c.astype({'feasibility': float})
92
+
93
+ # training main
94
+ self.pyfemtet_model.update_model(self.model)
95
+ self.pyfemtet_model.fit(
96
+ history=self.train_history,
97
+ df=df,
98
+ observation_noise=observation_noise,
99
+ )
100
+
101
+ # training model_c
102
+ self.pyfemtet_model_c.update_model(self.model_c)
103
+ self.pyfemtet_model_c.fit(
104
+ history=self.train_history_c,
105
+ df=df_c,
106
+ # observation_noise=None,
107
+ # observation_noise='no',
108
+ # observation_noise=0.001,
109
+ observation_noise=feasibility_noise,
110
+ # covar_module_settings=dict(
111
+ # name='matern_kernel_with_gamma_prior',
112
+ # nu=2.5,
113
+ # lengthscale_prior=GammaPrior(1.0, 9.0), # default: 3, 6
114
+ # outputscale_prior=GammaPrior(1.0, 0.15), # default: 2, 0.15
115
+ # )
116
+ covar_module_settings=dict(
117
+ name='get_covar_module_with_dim_scaled_prior_extension',
118
+ loc_coef=0.01,
119
+ scale_coef=0.01,
120
+ )
121
+ )
122
+
123
+ # set auto feasibility_cdf_threshold
124
+ if self.feasibility_cdf_threshold == 'sample_mean':
125
+ self.feasibility_cdf_threshold = df_c['feasibility'].mean()
126
+
127
+ if self._debug:
128
+ self._debug_df_c = df_c
129
+
130
+ def calc_pof(self):
131
+
132
+ if self._debug:
133
+ import plotly.graph_objects as go
134
+
135
+ df = self._debug_df_c
136
+
137
+ x_list = []
138
+ prm_names = self.train_history_c.prm_names
139
+ for prm_name in prm_names:
140
+ x_list.append(np.linspace(
141
+ df[prm_name + '_lower_bound'].values[0],
142
+ df[prm_name + '_upper_bound'].values[0],
143
+ 20
144
+ ))
145
+
146
+ for i in range(len(x_list)):
147
+ for j in range(i, len(x_list)):
148
+ if i == j:
149
+ continue
150
+
151
+ # i=0
152
+ # j=1
153
+
154
+ xx = np.meshgrid(x_list[i], x_list[j])
155
+
156
+ x_plot = np.array([[x[0]] * 400 for x in x_list]).T
157
+ x_plot[:, i] = xx[0].ravel()
158
+ x_plot[:, j] = xx[1].ravel()
159
+
160
+ y_mean, y_std = self.pyfemtet_model_c.predict(x_plot)
161
+ # feasibility_cdf_threshold = self.feasibility_cdf_threshold
162
+ # feasibility_cdf_threshold = 0.5
163
+ cdf_threshold = 0.25 # 不明なところは pof が 1 近くにすればあとは ACQF がうまいことやってくれる
164
+ # feasibility_cdf_threshold = self.feasibility_cdf_threshold * 0.5
165
+ pof = 1 - norm.cdf(cdf_threshold, y_mean, y_std)
166
+
167
+ x1 = x_list[i]
168
+ x2 = x_list[j]
169
+ xx1 = xx[0]
170
+ xx2 = xx[1]
171
+
172
+ fig = go.Figure()
173
+ fig.add_trace(
174
+ go.Contour(
175
+ x0=x1[0],
176
+ y0=x2[0],
177
+ dx=np.diff(x1)[0],
178
+ dy=np.diff(x2)[0],
179
+ z=pof.reshape(xx1.shape),
180
+ )
181
+ )
182
+ fig.add_trace(
183
+ go.Scatter(
184
+ x=self._debug_df_c[prm_names[i]],
185
+ y=self._debug_df_c[prm_names[j]],
186
+ mode='markers',
187
+ marker=dict(
188
+ color=self._debug_df_c['feasibility'],
189
+ colorscale='greens',
190
+ ),
191
+ )
192
+ )
193
+ fig.show()
194
+
195
+ fig = go.Figure()
196
+ fig.add_trace(
197
+ go.Surface(
198
+ x=xx1,
199
+ y=xx2,
200
+ z=y_mean.reshape(xx1.shape),
201
+ )
202
+ )
203
+ fig.add_trace(
204
+ go.Surface(
205
+ x=xx1,
206
+ y=xx2,
207
+ z=(y_mean + y_std).reshape(xx1.shape),
208
+ opacity=0.3,
209
+ )
210
+ )
211
+ fig.add_trace(
212
+ go.Surface(
213
+ x=xx1,
214
+ y=xx2,
215
+ z=(y_mean - y_std).reshape(xx1.shape),
216
+ opacity=0.3,
217
+ )
218
+ )
219
+ fig.add_trace(
220
+ go.Scatter3d(
221
+ x=self._debug_df_c[prm_names[i]],
222
+ y=self._debug_df_c[prm_names[j]],
223
+ z=self._debug_df_c['feasibility'],
224
+ mode='markers',
225
+ )
226
+ )
227
+ fig.show()
228
+
229
+ return
230
+
231
+ x = np.array([self.current_prm_values.values()])
232
+
233
+ f_mean, f_std = self.pyfemtet_model_c.predict(x)
234
+ f_mean, f_std = f_mean[0][0], f_std[0][0]
235
+
236
+ if isinstance(self.feasibility_cdf_threshold, float):
237
+ cdf_threshold = self.feasibility_cdf_threshold
238
+ else:
239
+ raise NotImplementedError(
240
+ f'self.cdf_threshold must be float, '
241
+ f'passed {self.feasibility_cdf_threshold}'
242
+ )
243
+
244
+ pof = 1 - norm.cdf(cdf_threshold, f_mean, f_std)
245
+
246
+ return pof
247
+
248
+ def update(self) -> None:
249
+
250
+ # BoTorchInterface.update() の前に PoF を計算する
251
+ pof = self.calc_pof()
252
+ if pof < self.pof_threshold:
253
+ logger.info(
254
+ _(
255
+ en_message='The surrogate model estimated '
256
+ 'that the probability of '
257
+ 'feasibility (PoF) is {pof}. '
258
+ 'This is under {thresh}. '
259
+ 'So this trial is processed as '
260
+ 'a constraint violation.',
261
+ jp_message='サロゲートモデルは解の実行可能確率(PoF)が'
262
+ '{pof} であると予測しました。'
263
+ 'これは閾値 {thresh} を下回っているので、'
264
+ '最適化試行においては拘束違反であると扱います。',
265
+ pof=pof,
266
+ thresh=self.pof_threshold,
267
+ )
268
+ )
269
+ raise _HiddenConstraintViolation(f'PoF < {self.pof_threshold}')
270
+
271
+ BoTorchInterface.update(self)
@@ -0,0 +1,18 @@
1
+ ,prm,prm_lower_bound,prm_upper_bound,prm,prm_choices,obj,obj_direction,,,,,,
2
+ ,,,,,,,,,,,,,
3
+ trial,x1,x1_lower_bound,x1_upper_bound,x2,x2_choices,obj,obj_direction,state,datetime_start,datetime_end,message,feasibility,optimality
4
+ 0,85.63019613,50,100,A,"['A', 'B', 'C']",85.63019613,minimize,Success,48:10.2,48:10.2,,TRUE,FALSE
5
+ 1,76.66824027,50,100,B,"['A', 'B', 'C']",76.66824027,minimize,Hidden constraint violation,48:11.7,48:11.7,,FALSE,FALSE
6
+ 2,62.68444915,50,100,C,"['A', 'B', 'C']",62.68444915,minimize,Hidden constraint violation,48:16.6,48:16.6,,FALSE,FALSE
7
+ 3,63.08476439,50,100,A,"['A', 'B', 'C']",63.08476439,minimize,Success,48:20.2,48:20.2,,TRUE,FALSE
8
+ 4,78.95677052,50,100,B,"['A', 'B', 'C']",78.95677052,minimize,Hidden constraint violation,48:23.5,48:23.5,,FALSE,FALSE
9
+ 5,79.90834979,50,100,C,"['A', 'B', 'C']",79.90834979,minimize,Hidden constraint violation,48:27.2,48:27.2,,FALSE,FALSE
10
+ 6,97.4442698,50,100,A,"['A', 'B', 'C']",97.4442698,minimize,Success,48:29.8,48:29.8,,TRUE,FALSE
11
+ 7,87.12500776,50,100,B,"['A', 'B', 'C']",87.12500776,minimize,Hidden constraint violation,03:52.7,03:52.7,,FALSE,FALSE
12
+ 8,69.56378151,50,100,C,"['A', 'B', 'C']",69.56378151,minimize,Hidden constraint violation,04:00.1,04:00.1,,FALSE,FALSE
13
+ 9,80.49012367,50,100,A,"['A', 'B', 'C']",80.49012367,minimize,Success,04:06.2,04:06.2,,TRUE,FALSE
14
+ 10,87.55804836,50,100,B,"['A', 'B', 'C']",87.55804836,minimize,Hidden constraint violation,04:13.1,04:13.1,,FALSE,FALSE
15
+ 11,59.55103039,50,100,C,"['A', 'B', 'C']",59.55103039,minimize,Hidden constraint violation,04:19.3,04:19.3,,FALSE,FALSE
16
+ 12,97.91995423,50,100,A,"['A', 'B', 'C']",97.91995423,minimize,Success,04:24.6,04:24.6,,TRUE,FALSE
17
+ 13,91.01111473,50,100,B,"['A', 'B', 'C']",91.01111473,minimize,Hidden constraint violation,04:31.3,04:31.3,,FALSE,FALSE
18
+ 14,53.36556413,50,100,C,"['A', 'B', 'C']",53.36556413,minimize,Hidden constraint violation,04:36.6,04:36.6,,FALSE,FALSE