pyfemtet 0.9.5__py3-none-any.whl → 1.0.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.

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 +46 -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 +103 -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 -17
  29. pyfemtet/opt/exceptions.py +45 -0
  30. pyfemtet/opt/femopt.py +621 -0
  31. pyfemtet/opt/history/__init__.py +11 -0
  32. pyfemtet/opt/history/_history.py +1416 -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 +997 -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} +508 -353
  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 +142 -0
  50. pyfemtet/opt/interface/_solidworks_interface/__init__.py +5 -0
  51. pyfemtet/opt/interface/_solidworks_interface/solidworks_interface.py +227 -0
  52. pyfemtet/opt/interface/_surrogate_model_interface/__init__.py +8 -0
  53. pyfemtet/opt/interface/_surrogate_model_interface/base_surrogate_interface.py +150 -0
  54. pyfemtet/opt/interface/_surrogate_model_interface/botorch_interface.py +298 -0
  55. pyfemtet/opt/interface/_surrogate_model_interface/debug-pof-botorch.reccsv +18 -0
  56. pyfemtet/opt/interface/_with_excel_settings/__init__.py +61 -0
  57. pyfemtet/opt/interface/_with_excel_settings/with_excel_settings.py +134 -0
  58. pyfemtet/opt/meta_script/YAML_Generator.xlsm +0 -0
  59. pyfemtet/opt/meta_script/__main__.py +58 -36
  60. pyfemtet/opt/optimizer/__init__.py +7 -9
  61. pyfemtet/opt/optimizer/_base_optimizer.py +911 -0
  62. pyfemtet/opt/optimizer/optuna_optimizer/__init__.py +9 -0
  63. pyfemtet/opt/optimizer/optuna_optimizer/_optuna_attribute.py +63 -0
  64. pyfemtet/opt/optimizer/optuna_optimizer/_optuna_optimizer.py +796 -0
  65. pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/__init__.py +7 -0
  66. pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/debug-pof-botorch.reccsv +18 -0
  67. pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/enable_nonlinear_constraint.py +244 -0
  68. pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/pof_botorch_sampler.py +1249 -0
  69. pyfemtet/opt/optimizer/optuna_optimizer/wat_ex14_parametric_jp.femprj +0 -0
  70. pyfemtet/opt/optimizer/scipy_optimizer/__init__.py +1 -0
  71. pyfemtet/opt/optimizer/scipy_optimizer/_scipy_optimizer.py +383 -0
  72. pyfemtet/opt/prediction/__init__.py +7 -0
  73. pyfemtet/opt/prediction/_botorch_utils.py +133 -0
  74. pyfemtet/opt/prediction/_gpytorch_modules_extension.py +142 -0
  75. pyfemtet/opt/prediction/_helper.py +155 -0
  76. pyfemtet/opt/prediction/_model.py +118 -0
  77. pyfemtet/opt/problem/problem.py +304 -0
  78. pyfemtet/opt/problem/variable_manager/__init__.py +20 -0
  79. pyfemtet/opt/problem/variable_manager/_string_as_expression.py +115 -0
  80. pyfemtet/opt/problem/variable_manager/_variable_manager.py +295 -0
  81. pyfemtet/opt/visualization/history_viewer/__main__.py +5 -0
  82. pyfemtet/opt/visualization/{_base.py → history_viewer/_base_application.py} +18 -13
  83. pyfemtet/opt/visualization/history_viewer/_common_pages.py +150 -0
  84. pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/alert_region.py +10 -5
  85. pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/control_femtet.py +16 -13
  86. pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/main_graph.py +117 -47
  87. pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/pm_graph.py +159 -138
  88. pyfemtet/opt/visualization/history_viewer/_process_monitor/_application.py +173 -0
  89. pyfemtet/opt/visualization/history_viewer/_process_monitor/_pages.py +291 -0
  90. pyfemtet/opt/visualization/{_wrapped_components → history_viewer/_wrapped_components}/dbc.py +1 -1
  91. pyfemtet/opt/visualization/{_wrapped_components → history_viewer/_wrapped_components}/dcc.py +1 -1
  92. pyfemtet/opt/visualization/{_wrapped_components → history_viewer/_wrapped_components}/html.py +1 -1
  93. pyfemtet/opt/visualization/history_viewer/result_viewer/__main__.py +5 -0
  94. pyfemtet/opt/visualization/{result_viewer/application.py → history_viewer/result_viewer/_application.py} +6 -6
  95. pyfemtet/opt/visualization/{result_viewer/pages.py → history_viewer/result_viewer/_pages.py} +106 -82
  96. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08.csv +18 -0
  97. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08.db +0 -0
  98. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8.jpg +0 -0
  99. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8.log +45 -0
  100. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8.pdt +0 -0
  101. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_1.jpg +0 -0
  102. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_1.pdt +0 -0
  103. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_10.jpg +0 -0
  104. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_10.pdt +0 -0
  105. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_11.jpg +0 -0
  106. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_11.pdt +0 -0
  107. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_12.jpg +0 -0
  108. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_12.pdt +0 -0
  109. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_13.jpg +0 -0
  110. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_13.pdt +0 -0
  111. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_14.jpg +0 -0
  112. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_14.pdt +0 -0
  113. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_15.jpg +0 -0
  114. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_15.pdt +0 -0
  115. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_16.jpg +0 -0
  116. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_16.pdt +0 -0
  117. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_17.jpg +0 -0
  118. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_17.pdt +0 -0
  119. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_18.jpg +0 -0
  120. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_18.pdt +0 -0
  121. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_19.jpg +0 -0
  122. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_19.pdt +0 -0
  123. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_2.jpg +0 -0
  124. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_2.pdt +0 -0
  125. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_20.jpg +0 -0
  126. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_20.pdt +0 -0
  127. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_3.jpg +0 -0
  128. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_3.pdt +0 -0
  129. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.bgr +0 -0
  130. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.bnd +0 -0
  131. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.btr +0 -0
  132. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.jpg +0 -0
  133. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.mtl +0 -0
  134. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.pdt +0 -0
  135. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.prm +0 -0
  136. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_5.jpg +0 -0
  137. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_5.pdt +0 -0
  138. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_6.jpg +0 -0
  139. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_6.pdt +0 -0
  140. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_7.jpg +0 -0
  141. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_7.pdt +0 -0
  142. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_8.jpg +0 -0
  143. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_8.pdt +0 -0
  144. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_9.jpg +0 -0
  145. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_9.pdt +0 -0
  146. pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.femprj +0 -0
  147. pyfemtet/opt/visualization/plotter/main_figure_creator.py +536 -0
  148. pyfemtet/opt/visualization/plotter/pm_graph_creator.py +359 -0
  149. pyfemtet/opt/worker_status.py +120 -0
  150. {pyfemtet-0.9.5.dist-info → pyfemtet-1.0.0.dist-info}/METADATA +23 -24
  151. pyfemtet-1.0.0.dist-info/RECORD +172 -0
  152. pyfemtet-1.0.0.dist-info/entry_points.txt +3 -0
  153. pyfemtet/_femtet_config_util/exit.py +0 -59
  154. pyfemtet/_message/1. make_pot.bat +0 -11
  155. pyfemtet/_message/2. make_mo.bat +0 -6
  156. pyfemtet/_message/__init__.py +0 -5
  157. pyfemtet/_message/babel.cfg +0 -2
  158. pyfemtet/_message/locales/ja/LC_MESSAGES/messages.mo +0 -0
  159. pyfemtet/_message/locales/ja/LC_MESSAGES/messages.po +0 -570
  160. pyfemtet/_message/locales/messages.pot +0 -551
  161. pyfemtet/_warning.py +0 -87
  162. pyfemtet/brep/_impl.py +0 -18
  163. pyfemtet/opt/_femopt.py +0 -1007
  164. pyfemtet/opt/_femopt_core.py +0 -1169
  165. pyfemtet/opt/_test_utils/control_femtet.py +0 -39
  166. pyfemtet/opt/_test_utils/hyper_sphere.py +0 -24
  167. pyfemtet/opt/_test_utils/record_history.py +0 -130
  168. pyfemtet/opt/advanced_samples/excel_ui/(ref) original_project.femprj +0 -0
  169. pyfemtet/opt/advanced_samples/excel_ui/femtet-macro.xlsm +0 -0
  170. pyfemtet/opt/advanced_samples/excel_ui/pyfemtet-core.py +0 -291
  171. pyfemtet/opt/advanced_samples/excel_ui/test-pyfemtet-core.cmd +0 -22
  172. pyfemtet/opt/advanced_samples/restart/gal_ex13_parametric.femprj +0 -0
  173. pyfemtet/opt/advanced_samples/restart/gal_ex13_parametric_restart.py +0 -99
  174. pyfemtet/opt/advanced_samples/restart/gal_ex13_parametric_restart_jp.py +0 -102
  175. pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_create_training_data.py +0 -60
  176. pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_create_training_data_jp.py +0 -57
  177. pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_optimize_with_surrogate.py +0 -100
  178. pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_optimize_with_surrogate_jp.py +0 -90
  179. pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_parametric.femprj +0 -0
  180. pyfemtet/opt/interface/_base.py +0 -101
  181. pyfemtet/opt/interface/_excel_interface.py +0 -984
  182. pyfemtet/opt/interface/_femtet_excel.py +0 -141
  183. pyfemtet/opt/interface/_femtet_with_nx/__init__.py +0 -3
  184. pyfemtet/opt/interface/_femtet_with_nx/_interface.py +0 -178
  185. pyfemtet/opt/interface/_femtet_with_sldworks.py +0 -298
  186. pyfemtet/opt/interface/_surrogate/__init__.py +0 -5
  187. pyfemtet/opt/interface/_surrogate/_base.py +0 -129
  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.5.dist-info/RECORD +0 -158
  259. pyfemtet-0.9.5.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.5.dist-info → pyfemtet-1.0.0.dist-info}/LICENSE +0 -0
  271. {pyfemtet-0.9.5.dist-info → pyfemtet-1.0.0.dist-info}/LICENSE_THIRD_PARTY.txt +0 -0
  272. {pyfemtet-0.9.5.dist-info → pyfemtet-1.0.0.dist-info}/WHEEL +0 -0
pyfemtet/opt/femopt.py ADDED
@@ -0,0 +1,621 @@
1
+ from __future__ import annotations
2
+ from typing import Callable, Sequence
3
+
4
+ import os
5
+ import sys
6
+ from time import sleep, time
7
+ from contextlib import nullcontext
8
+ from concurrent.futures import ThreadPoolExecutor
9
+
10
+ import sympy
11
+
12
+ import pyfemtet
13
+ from pyfemtet._i18n.messages import _
14
+ from pyfemtet._util.dask_util import *
15
+ from pyfemtet.opt.worker_status import *
16
+ from pyfemtet.opt.problem.problem import *
17
+ from pyfemtet.opt.problem.variable_manager import *
18
+ from pyfemtet.opt.interface import *
19
+ from pyfemtet.opt.optimizer import *
20
+ from pyfemtet.opt.optimizer._base_optimizer import DIRECTION
21
+ from pyfemtet.logger import get_module_logger
22
+ from pyfemtet.opt.visualization.history_viewer._process_monitor._application import (
23
+ process_monitor_main,
24
+ MonitorHostRecord
25
+ )
26
+
27
+
28
+ logger = get_module_logger('opt.femopt', False)
29
+
30
+
31
+ class FEMOpt:
32
+ """
33
+ A class to manage finite element method (FEM) optimization using a specified optimizer and FEM interface.
34
+
35
+ Attributes:
36
+ opt (AbstractOptimizer): The optimizer instance to be used for optimization.
37
+ monitor_info (dict[str, str | int | None]): Dictionary to store monitoring information such as host and port.
38
+
39
+ Args:
40
+ fem (AbstractFEMInterface, optional): An instance of a FEM interface. Defaults to None, in which case a FemtetInterface is used.
41
+ opt (AbstractOptimizer, optional): An optimizer instance. Defaults to None, in which case OptunaOptimizer is used.
42
+
43
+ """
44
+
45
+ opt: AbstractOptimizer
46
+
47
+ def __init__(
48
+ self,
49
+ fem: AbstractFEMInterface = None,
50
+ opt: AbstractOptimizer = None,
51
+ ):
52
+ self.opt: AbstractOptimizer = opt or OptunaOptimizer()
53
+ self.opt.fem = fem or FemtetInterface()
54
+ self.monitor_info: dict[str, str | int | None] = dict(
55
+ host=None, port=None,
56
+ )
57
+
58
+ def add_constant_value(
59
+ self,
60
+ name: str,
61
+ value: SupportedVariableTypes,
62
+ properties: dict[str, ...] | None = None,
63
+ *,
64
+ pass_to_fem: bool = True,
65
+ ):
66
+ self.opt.add_constant_value(name, value, properties, pass_to_fem=pass_to_fem)
67
+
68
+ def add_parameter(
69
+ self,
70
+ name: str,
71
+ initial_value: float | None = None,
72
+ lower_bound: float | None = None,
73
+ upper_bound: float | None = None,
74
+ step: float | None = None,
75
+ properties: dict[str, ...] | None = None,
76
+ *,
77
+ pass_to_fem: bool = True,
78
+ fix: bool = False,
79
+ ) -> None:
80
+ self.opt.add_parameter(name, initial_value, lower_bound, upper_bound, step, properties, pass_to_fem=pass_to_fem, fix=fix)
81
+
82
+ def add_expression_string(
83
+ self,
84
+ name: str,
85
+ expression_string: str,
86
+ properties: dict[str, ...] | None = None,
87
+ *,
88
+ pass_to_fem: bool = True,
89
+ ) -> None:
90
+ self.opt.add_expression_string(name, expression_string, properties, pass_to_fem=pass_to_fem)
91
+
92
+ def add_expression_sympy(
93
+ self,
94
+ name: str,
95
+ sympy_expr: sympy.Expr,
96
+ properties: dict[str, ...] | None = None,
97
+ *,
98
+ pass_to_fem: bool = True,
99
+ ) -> None:
100
+ self.opt.add_expression_sympy(name, sympy_expr, properties, pass_to_fem=pass_to_fem)
101
+
102
+ def add_expression(
103
+ self,
104
+ name: str,
105
+ fun: Callable[..., float],
106
+ properties: dict[str, ...] | None = None,
107
+ args: tuple | None = None,
108
+ kwargs: dict | None = None,
109
+ *,
110
+ pass_to_fem: bool = True,
111
+ ) -> None:
112
+ self.opt.add_expression(name, fun, properties, args, kwargs, pass_to_fem=pass_to_fem)
113
+
114
+ def add_categorical_parameter(
115
+ self,
116
+ name: str,
117
+ initial_value: str | None = None,
118
+ choices: list[str] | None = None,
119
+ properties: dict[str, ...] | None = None,
120
+ *,
121
+ pass_to_fem: bool = True,
122
+ fix: bool = False,
123
+ ) -> None:
124
+ self.opt.add_categorical_parameter(name, initial_value, choices, properties, pass_to_fem=pass_to_fem, fix=fix)
125
+
126
+ def add_objective(
127
+ self,
128
+ name: str,
129
+ fun: Callable[..., float],
130
+ direction: DIRECTION = 'minimize',
131
+ args: tuple | None = None,
132
+ kwargs: dict | None = None,
133
+ ) -> None:
134
+ self.opt.add_objective(name, fun, direction, args, kwargs)
135
+
136
+ def add_objectives(
137
+ self,
138
+ names: str | list[str],
139
+ fun: Callable[..., Sequence[float]],
140
+ n_return: int,
141
+ directions: DIRECTION | Sequence[DIRECTION] = None,
142
+ args: tuple | None = None,
143
+ kwargs: dict | None = None,
144
+ ):
145
+ self.opt.add_objectives(names, fun, n_return, directions, args, kwargs)
146
+
147
+ def add_constraint(
148
+ self,
149
+ name: str,
150
+ fun: Callable[..., float],
151
+ lower_bound: float | None = None,
152
+ upper_bound: float | None = None,
153
+ args: tuple | None = None,
154
+ kwargs: dict | None = None,
155
+ strict: bool = True,
156
+ using_fem: bool | None = None,
157
+ ):
158
+ self.opt.add_constraint(name, fun, lower_bound, upper_bound, args, kwargs, strict, using_fem)
159
+
160
+ def add_sub_fidelity_model(
161
+ self,
162
+ name: str,
163
+ sub_fidelity_model: SubFidelityModel,
164
+ fidelity: Fidelity,
165
+ ):
166
+ self.opt.add_sub_fidelity_model(name, sub_fidelity_model, fidelity)
167
+
168
+ def set_monitor_host(self, host: str = None, port: int = None):
169
+ """Sets the host IP address and the port of the process monitor.
170
+
171
+ Args:
172
+ host (str):
173
+ The hostname or IP address of the monitor server.
174
+ port (int, optional):
175
+ The port number of the monitor server.
176
+ If None, ``8080`` will be used.
177
+ Defaults to None.
178
+
179
+ Tip:
180
+ Specifying host ``0.0.0.0`` allows viewing monitor
181
+ from all computers on the local network.
182
+
183
+ If no hostname is specified, the monitor server
184
+ will be hosted on ``localhost``.
185
+
186
+ We can access process monitor by accessing
187
+ ```localhost:8080``` on our browser by default.
188
+
189
+ """
190
+ if host is not None:
191
+ self.monitor_info.update(host=host)
192
+ if port is not None:
193
+ self.monitor_info.update(port=port)
194
+
195
+ def set_random_seed(self, seed: int):
196
+ self.opt.seed = seed
197
+
198
+ def optimize(
199
+ self,
200
+ n_trials: int = None,
201
+ n_parallel: int = 1,
202
+ timeout: float = None,
203
+ wait_setup: bool = True,
204
+ confirm_before_exit: bool = True,
205
+ history_path: str = None,
206
+ with_monitor: bool = True,
207
+ scheduler_address: str = None,
208
+ ):
209
+
210
+ # ===== show initialize info =====
211
+ logger.info(
212
+ _(
213
+ '===== pyfemtet version {ver} =====',
214
+ ver=pyfemtet.__version__,
215
+ )
216
+ )
217
+ client: Client
218
+
219
+ # set arguments
220
+ self.opt.n_trials = n_trials or self.opt.n_trials
221
+ self.opt.timeout = timeout or self.opt.timeout
222
+ self.opt.history.path = history_path or self.opt.history.path
223
+
224
+ # construct opt workers
225
+ n_using_cluster_workers = n_parallel # workers excluding main
226
+ if scheduler_address is None:
227
+ n_using_cluster_workers = n_using_cluster_workers - 1
228
+ worker_name_base = 'Sub'
229
+ if n_parallel == 1:
230
+ cluster = nullcontext()
231
+ # noinspection PyTypeChecker
232
+ client = DummyClient()
233
+
234
+ else:
235
+ logger.info(_('Launching processes...'))
236
+ cluster = LocalCluster(
237
+ n_workers=n_parallel - 1,
238
+ threads_per_worker=1 if n_parallel > 1 else None,
239
+ processes=True if n_parallel > 1 else False,
240
+ )
241
+
242
+ logger.info(_('Connecting cluster...'))
243
+ client = Client(
244
+ cluster,
245
+ )
246
+ else:
247
+ worker_name_base = 'Remote Worker'
248
+ cluster = nullcontext()
249
+ client = Client(scheduler_address)
250
+
251
+ # construct other workers
252
+ main_worker_names = list()
253
+ logger.info(_('Launching threads...'))
254
+ executor_workers = 2 # save_history, watch_status
255
+ if with_monitor:
256
+ executor_workers += 1 # monitor
257
+ if scheduler_address is None:
258
+ executor_workers += 1 # main
259
+ main_worker_names.append('Main')
260
+ executor = ThreadPoolExecutor(
261
+ max_workers=executor_workers,
262
+ thread_name_prefix='thread_worker'
263
+ )
264
+
265
+ with cluster, client, self.opt.history, executor:
266
+
267
+ logger.info(_('Setting up...'))
268
+
269
+ # finalize history
270
+ self.opt._load_problem_from_fem()
271
+ self.opt._finalize_history()
272
+
273
+ # optimizer-specific setup after history finalized
274
+ self.opt._setup_before_parallel()
275
+
276
+ # setup FEM (mainly for distributing files)
277
+ self.opt.fem._setup_before_parallel()
278
+
279
+ # create worker status list
280
+ entire_status = WorkerStatus(ENTIRE_PROCESS_STATUS_KEY)
281
+ assert n_parallel == len(main_worker_names) + n_using_cluster_workers
282
+
283
+ worker_status_list = []
284
+ for i in range(n_parallel):
285
+ worker_status = WorkerStatus(f'worker-status-{i}')
286
+ worker_status.value = WorkerStatus.initializing
287
+ worker_status_list.append(worker_status)
288
+ entire_status.value = WorkerStatus.initializing
289
+
290
+ # Get workers and Assign roles
291
+ opt_worker_addresses = list(client.scheduler_info()['workers'].keys())[:n_using_cluster_workers]
292
+ opt_worker_names = [f'{worker_name_base} {i+1}' for i in range(n_using_cluster_workers)]
293
+
294
+ # Setting up monitor
295
+ if with_monitor:
296
+ logger.info(_('Launching Monitor...'))
297
+
298
+ monitor_host_record = MonitorHostRecord()
299
+
300
+ # noinspection PyTypeChecker,PyUnusedLocal
301
+ monitor_future = executor.submit(
302
+ process_monitor_main,
303
+ history=self.opt.history,
304
+ status=entire_status,
305
+ worker_addresses=main_worker_names + opt_worker_addresses,
306
+ worker_names=main_worker_names + opt_worker_names,
307
+ worker_status_list=worker_status_list,
308
+ host=self.monitor_info['host'],
309
+ port=self.monitor_info['port'],
310
+ host_record=monitor_host_record,
311
+ )
312
+
313
+ else:
314
+ monitor_future = None
315
+ monitor_host_record = None
316
+
317
+ logger.info(_('Setting up optimization problem...'))
318
+ entire_status.value = WorkerStatus.running
319
+
320
+ # Run on cluster
321
+ futures = client.map(
322
+ self.opt._run,
323
+ # Arguments of func
324
+ range(n_using_cluster_workers), # worker_index
325
+ opt_worker_names, # worker_name
326
+ [self.opt.history] * n_using_cluster_workers, # history
327
+ [entire_status] * n_using_cluster_workers, # entire_status
328
+ worker_status_list[:n_using_cluster_workers], # worker_status
329
+ [worker_status_list] * n_using_cluster_workers, # worker_status_list
330
+ [wait_setup] * n_using_cluster_workers, # wait_other_process_setup
331
+ # Arguments of map
332
+ workers=opt_worker_addresses,
333
+ allow_other_workers=False,
334
+ )
335
+
336
+ # Run on main process
337
+ assert len(main_worker_names) == 0 or len(main_worker_names) == 1
338
+ if len(main_worker_names) == 1:
339
+ # noinspection PyTypeChecker
340
+ future = executor.submit(
341
+ self.opt._run,
342
+ main_worker_names[0],
343
+ main_worker_names[0],
344
+ self.opt.history,
345
+ entire_status,
346
+ worker_status_list[n_using_cluster_workers:][0],
347
+ worker_status_list,
348
+ wait_setup
349
+ )
350
+ else:
351
+ class DummyFuture:
352
+ def result(self):
353
+ pass
354
+
355
+ future = DummyFuture()
356
+
357
+ # Saving history
358
+ def save_history():
359
+ while True:
360
+ sleep(2)
361
+ try:
362
+ self.opt.history.save()
363
+ logger.debug('History saved!')
364
+ except PermissionError:
365
+ logger.error(
366
+ _('Cannot save history. '
367
+ 'The most common reason is '
368
+ 'that the csv is opened by '
369
+ 'another program (such as Excel). '
370
+ 'Please free {path} or lost the '
371
+ 'optimization history.',
372
+ path=self.opt.history.path)
373
+ )
374
+ if entire_status.value >= WorkerStatus.finished:
375
+ break
376
+ logger.debug('History save thread finished!')
377
+ future_saving = executor.submit(save_history, )
378
+
379
+ # Watching
380
+ def watch_worker_status():
381
+ while True:
382
+ sleep(1)
383
+ logger.debug([s.value for s in worker_status_list])
384
+ if all([s.value >= WorkerStatus.finished for s in worker_status_list]):
385
+ break
386
+ if entire_status.value < WorkerStatus.finished:
387
+ entire_status.value = WorkerStatus.finished
388
+ logger.debug('All workers finished!')
389
+ future_watching = executor.submit(watch_worker_status, )
390
+
391
+ if monitor_host_record is not None:
392
+ # update additional_data of history
393
+ # to notify how to emit interruption
394
+ # signal by external processes
395
+ monitor_record_wait_start = time()
396
+ while len(monitor_host_record.get()) == 0:
397
+ sleep(0.1)
398
+ if time() - monitor_record_wait_start > 30:
399
+ logger.warning(_(
400
+ en_message='Getting monitor host information is '
401
+ 'failed within 30 seconds. '
402
+ 'It can not be able to terminate by '
403
+ 'requesting POST '
404
+ '`<host>:<port>/interrupt` '
405
+ 'by an external process.',
406
+ jp_message='モニターの情報取得が 30 秒以内に'
407
+ '終わりませんでした。最適化プロセスは、'
408
+ '外部プロセスから '
409
+ '`<host>:<port>/interrupt` に POST を'
410
+ 'リクエストしても終了できない可能性が'
411
+ 'あります。'
412
+ ))
413
+ break
414
+ if len(monitor_host_record.get()) > 0:
415
+ self.opt.history.additional_data.update(
416
+ monitor_host_record.get()
417
+ )
418
+
419
+ # Terminating monitor even if exception is raised
420
+ class TerminatingMonitor:
421
+
422
+ def __init__(self, monitor_future_):
423
+ self.monitor_future_ = monitor_future_
424
+
425
+ def __enter__(self):
426
+ pass
427
+
428
+ def __exit__(self, exc_type, exc_val, exc_tb):
429
+ # Send termination signal to monitor
430
+ # and wait to finish
431
+ # noinspection PyTypeChecker
432
+ entire_status.value = WorkerStatus.terminated
433
+ if self.monitor_future_ is not None:
434
+ self.monitor_future_.result()
435
+
436
+ with TerminatingMonitor(monitor_future):
437
+ # Wait to finish optimization
438
+ client.gather(futures)
439
+ future.result()
440
+ future_saving.result()
441
+ future_watching.result()
442
+
443
+ if confirm_before_exit:
444
+ confirm_msg = _(
445
+ en_message='The optimization is now complete. '
446
+ 'You can view the results on the monitor '
447
+ 'until you press Enter to exit the program.',
448
+ jp_message='最適化が終了しました。'
449
+ 'プログラムを終了するまで、'
450
+ '結果をプロセスモニターで確認できます。'
451
+ )
452
+ result_viewer_msg = _(
453
+ en_message='After the program ends, '
454
+ 'you can check the optimization results '
455
+ 'using the result viewer.\n'
456
+ 'The result viewer can be launched by '
457
+ 'performing one of the following actions:\n'
458
+ '- (Windows only) Launch the `pyfemtet-opt-result-viewer` '
459
+ 'shortcut on your desktop if exists.\n'
460
+ '- (Windows only) Launch {path}.\n'
461
+ '- Execute "py -m pyfemtet.opt.visualization.history_viewer" '
462
+ 'in the command line',
463
+ jp_message='プログラム終了後も、結果ビューワを使って最適化結果を'
464
+ '確認することができます。'
465
+ '結果ビューワは以下のいずれかを実施すると起動できます。\n'
466
+ '- (Windows のみ)デスクトップの pyfemtet-opt-result-viewer '
467
+ 'ショートカットを起動する\n'
468
+ '- (Windows のみ){dir} にある {filename} を起動する\n'
469
+ '- コマンドラインで「py -m pyfemtet.opt.visualization.history_viewer」'
470
+ 'を実行する',
471
+ dir=os.path.abspath(os.path.dirname(sys.executable)),
472
+ filename='pyfemtet-opt-result-viewer.exe (or .cmd)',
473
+ )
474
+ print("====================")
475
+ print(confirm_msg)
476
+ print(result_viewer_msg)
477
+ print(_(
478
+ en_message='Press Enter to quit...',
479
+ jp_message='終了するには Enter を押してください...',
480
+ ))
481
+ input()
482
+
483
+ df = self.opt.history.get_df()
484
+
485
+ logger.info(_('All processes are terminated.'))
486
+
487
+ return df
488
+
489
+
490
+ def debug_1():
491
+ # noinspection PyUnresolvedReferences
492
+ from time import sleep
493
+ # from pyfemtet.opt.optimizer import InterruptOptimization
494
+ import optuna
495
+ from pyfemtet.opt.interface import AbstractFEMInterface, NoFEM
496
+
497
+ def _parabola(_fem: AbstractFEMInterface, _opt: AbstractOptimizer):
498
+ x = _opt.get_variables('values')
499
+ # print(os.getpid())
500
+ # raise RuntimeError
501
+ # raise Interrupt
502
+ # if get_worker() is None:
503
+ # raise RuntimeError
504
+ return (x ** 2).sum()
505
+
506
+ def _cns(_fem: AbstractFEMInterface, _opt: AbstractOptimizer):
507
+ x = _opt.get_variables('values')
508
+ return x[0]
509
+
510
+ _opt = OptunaOptimizer()
511
+ _opt.sampler = optuna.samplers.TPESampler(seed=42)
512
+ _opt.n_trials = 10
513
+
514
+ _fem = NoFEM()
515
+ _opt.fem = _fem
516
+
517
+ _args = (_opt,)
518
+
519
+ _opt.add_parameter('x1', 1, -1, 1, step=0.2)
520
+ _opt.add_parameter('x2', 1, -1, 1, step=0.2)
521
+
522
+ _opt.add_constraint('cns', _cns, lower_bound=-0.5, args=_args)
523
+
524
+ _opt.add_objective('obj', _parabola, args=_args)
525
+
526
+ _femopt = FEMOpt(fem=_fem, opt=_opt)
527
+ _femopt.opt = _opt
528
+ # _femopt.opt.history.path = 'v1test/femopt-restart-test.csv'
529
+ _femopt.optimize(n_parallel=2)
530
+
531
+ print(os.path.abspath(_femopt.opt.history.path))
532
+
533
+
534
+ def substrate_size(Femtet):
535
+ """基板のXY平面上での専有面積を計算します。"""
536
+ substrate_w = Femtet.GetVariableValue('substrate_w')
537
+ substrate_d = Femtet.GetVariableValue('substrate_d')
538
+
539
+ # assert get_worker() is not None
540
+
541
+ return substrate_w * substrate_d # 単位: mm2
542
+
543
+
544
+ def debug_2():
545
+ from pyfemtet.opt.interface import FemtetInterface
546
+ from pyfemtet.opt.optimizer import OptunaOptimizer
547
+
548
+ fem = FemtetInterface(
549
+ femprj_path=os.path.join(os.path.dirname(__file__), 'wat_ex14_parametric_jp.femprj'),
550
+ )
551
+
552
+ opt = OptunaOptimizer()
553
+
554
+ opt.fem = fem
555
+
556
+ opt.add_parameter(name="substrate_w", initial_value=40, lower_bound=22, upper_bound=60)
557
+ opt.add_parameter(name="substrate_d", initial_value=60, lower_bound=34, upper_bound=60)
558
+ opt.add_objective(name='基板サイズ(mm2)', fun=substrate_size)
559
+ opt.add_objective(name='obj2', fun=substrate_size)
560
+ opt.add_objective(name='obj3', fun=substrate_size)
561
+
562
+ opt.n_trials = 10
563
+ # opt.history.path = os.path.join(os.path.dirname(__file__), 'femtet-test.csv')
564
+
565
+ femopt = FEMOpt()
566
+
567
+ femopt.opt = opt
568
+
569
+ femopt.optimize(n_parallel=1)
570
+
571
+
572
+ def debug_3():
573
+ # noinspection PyUnresolvedReferences
574
+ from time import sleep
575
+ # from pyfemtet.opt.optimizer import InterruptOptimization
576
+ import optuna
577
+ from pyfemtet.opt.interface import AbstractFEMInterface, NoFEM
578
+
579
+ def _parabola(_fem: AbstractFEMInterface, _opt: AbstractOptimizer):
580
+ x = _opt.get_variables('values')
581
+ # print(os.getpid())
582
+ # raise RuntimeError
583
+ # raise Interrupt
584
+ # if get_worker() is None:
585
+ # raise RuntimeError
586
+ return (x ** 2).sum()
587
+
588
+ def _cns(_fem: AbstractFEMInterface, _opt: AbstractOptimizer):
589
+ x = _opt.get_variables('values')
590
+ return x[0]
591
+
592
+ _opt = OptunaOptimizer()
593
+ _opt.sampler = optuna.samplers.TPESampler(seed=42)
594
+
595
+ _fem = NoFEM()
596
+ _opt.fem = _fem
597
+
598
+ _args = (_opt,)
599
+
600
+ _opt.add_parameter('x1', 1, -1, 1, step=0.2)
601
+ _opt.add_parameter('x2', 1, -1, 1, step=0.2)
602
+
603
+ _opt.add_constraint('cns', _cns, lower_bound=-0.5, args=_args)
604
+
605
+ _opt.add_objective('obj', _parabola, args=_args)
606
+
607
+ _femopt = FEMOpt(fem=_fem, opt=_opt)
608
+ _femopt.optimize(
609
+ scheduler_address='<dask scheduler で起動したスケジューラの tcp をここに入力>',
610
+ n_trials=80,
611
+ n_parallel=6,
612
+ with_monitor=True,
613
+ confirm_before_exit=False,
614
+ )
615
+
616
+
617
+ if __name__ == '__main__':
618
+ # for i in range(1):
619
+ debug_1()
620
+ # debug_2()
621
+ # debug_3()
@@ -0,0 +1,11 @@
1
+ from ._history import *
2
+
3
+ __all__ = [
4
+ 'TrialState',
5
+ 'History',
6
+ 'ColumnOrderMode',
7
+ 'Record',
8
+ 'create_err_msg_from_exception',
9
+ 'CorrespondingColumnNameRuler',
10
+ 'MAIN_FILTER',
11
+ ]