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