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