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.
- pyfemtet/__init__.py +6 -1
- pyfemtet/_i18n/1. make_pot_and_update_po.bat +8 -0
- pyfemtet/_i18n/2. build_mo.bat +5 -0
- pyfemtet/_i18n/__init__.py +4 -0
- pyfemtet/_i18n/babel.cfg +2 -0
- pyfemtet/_i18n/i18n.py +37 -0
- pyfemtet/_i18n/locales/ja/LC_MESSAGES/messages.mo +0 -0
- pyfemtet/_i18n/locales/ja/LC_MESSAGES/messages.po +1020 -0
- pyfemtet/_i18n/locales/messages.pot +987 -0
- pyfemtet/{_message → _i18n}/messages.py +128 -41
- pyfemtet/_util/closing.py +19 -0
- pyfemtet/_util/dask_util.py +89 -7
- pyfemtet/_util/df_util.py +29 -0
- pyfemtet/_util/excel_macro_util.py +8 -3
- pyfemtet/_util/excel_parse_util.py +43 -23
- pyfemtet/_util/femtet_access_inspection.py +120 -0
- pyfemtet/{_femtet_config_util/autosave.py → _util/femtet_autosave.py} +7 -0
- pyfemtet/_util/femtet_exit.py +105 -0
- pyfemtet/_util/femtet_version.py +20 -0
- pyfemtet/_util/helper.py +94 -0
- pyfemtet/_util/process_util.py +107 -0
- pyfemtet/_util/str_enum.py +44 -0
- pyfemtet/core.py +15 -47
- pyfemtet/dispatch_extensions/__init__.py +8 -11
- pyfemtet/dispatch_extensions/_impl.py +42 -198
- pyfemtet/logger/__init__.py +8 -1
- pyfemtet/logger/_impl.py +5 -6
- pyfemtet/opt/__init__.py +3 -17
- pyfemtet/opt/exceptions.py +45 -0
- pyfemtet/opt/femopt.py +608 -0
- pyfemtet/opt/history/__init__.py +11 -0
- pyfemtet/opt/history/_history.py +1404 -0
- pyfemtet/opt/history/_hypervolume.py +169 -0
- pyfemtet/opt/history/_optimality.py +79 -0
- pyfemtet/opt/interface/__init__.py +17 -24
- pyfemtet/opt/interface/_base_interface.py +222 -0
- pyfemtet/opt/interface/_excel_interface/__init__.py +3 -0
- pyfemtet/opt/interface/_excel_interface/debug-excel-interface.xlsm +0 -0
- pyfemtet/opt/interface/_excel_interface/excel_interface.py +999 -0
- pyfemtet/opt/interface/_femtet_interface/__init__.py +3 -0
- pyfemtet/opt/interface/{_femtet_parametric.py → _femtet_interface/_femtet_parametric.py} +20 -12
- pyfemtet/opt/interface/{_femtet.py → _femtet_interface/femtet_interface.py} +505 -349
- pyfemtet/opt/interface/_femtet_with_nx_interface/__init__.py +5 -0
- pyfemtet/opt/interface/_femtet_with_nx_interface/femtet_with_nx_interface.py +230 -0
- pyfemtet/opt/interface/_femtet_with_nx_interface/model1.prt +0 -0
- pyfemtet/opt/interface/_femtet_with_nx_interface/model1.x_t +98 -0
- pyfemtet/opt/interface/{_femtet_with_nx → _femtet_with_nx_interface}/update_model.py +1 -3
- pyfemtet/opt/interface/_femtet_with_solidworks/__init__.py +5 -0
- pyfemtet/opt/interface/_femtet_with_solidworks/femtet_with_solidworks_interface.py +122 -0
- pyfemtet/opt/interface/_solidworks_interface/__init__.py +5 -0
- pyfemtet/opt/interface/_solidworks_interface/solidworks_interface.py +206 -0
- pyfemtet/opt/interface/_surrogate_model_interface/__init__.py +8 -0
- pyfemtet/opt/interface/_surrogate_model_interface/base_surrogate_interface.py +150 -0
- pyfemtet/opt/interface/_surrogate_model_interface/botorch_interface.py +298 -0
- pyfemtet/opt/interface/_surrogate_model_interface/debug-pof-botorch.reccsv +18 -0
- pyfemtet/opt/interface/_with_excel_settings/__init__.py +61 -0
- pyfemtet/opt/interface/_with_excel_settings/with_excel_settings.py +134 -0
- pyfemtet/opt/meta_script/YAML_Generator.xlsm +0 -0
- pyfemtet/opt/meta_script/__main__.py +58 -36
- pyfemtet/opt/optimizer/__init__.py +7 -9
- pyfemtet/opt/optimizer/_base_optimizer.py +885 -0
- pyfemtet/opt/optimizer/optuna_optimizer/__init__.py +9 -0
- pyfemtet/opt/optimizer/optuna_optimizer/_optuna_attribute.py +73 -0
- pyfemtet/opt/optimizer/optuna_optimizer/_optuna_optimizer.py +678 -0
- pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/__init__.py +7 -0
- pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/debug-pof-botorch.reccsv +18 -0
- pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/enable_nonlinear_constraint.py +244 -0
- pyfemtet/opt/optimizer/optuna_optimizer/_pof_botorch/pof_botorch_sampler.py +1249 -0
- pyfemtet/opt/optimizer/optuna_optimizer/wat_ex14_parametric_jp.femprj +0 -0
- pyfemtet/opt/optimizer/scipy_optimizer/__init__.py +1 -0
- pyfemtet/opt/optimizer/scipy_optimizer/_scipy_optimizer.py +364 -0
- pyfemtet/opt/prediction/__init__.py +7 -0
- pyfemtet/opt/prediction/_botorch_utils.py +133 -0
- pyfemtet/opt/prediction/_gpytorch_modules_extension.py +142 -0
- pyfemtet/opt/prediction/_helper.py +155 -0
- pyfemtet/opt/prediction/_model.py +118 -0
- pyfemtet/opt/problem/problem.py +304 -0
- pyfemtet/opt/problem/variable_manager/__init__.py +20 -0
- pyfemtet/opt/problem/variable_manager/_string_as_expression.py +115 -0
- pyfemtet/opt/problem/variable_manager/_variable_manager.py +295 -0
- pyfemtet/opt/visualization/history_viewer/__main__.py +5 -0
- pyfemtet/opt/visualization/{_base.py → history_viewer/_base_application.py} +18 -13
- pyfemtet/opt/visualization/history_viewer/_common_pages.py +150 -0
- pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/alert_region.py +10 -5
- pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/control_femtet.py +16 -13
- pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/main_graph.py +117 -47
- pyfemtet/opt/visualization/{_complex_components → history_viewer/_complex_components}/pm_graph.py +159 -138
- pyfemtet/opt/visualization/history_viewer/_process_monitor/_application.py +173 -0
- pyfemtet/opt/visualization/history_viewer/_process_monitor/_pages.py +291 -0
- pyfemtet/opt/visualization/{_wrapped_components → history_viewer/_wrapped_components}/dbc.py +1 -1
- pyfemtet/opt/visualization/{_wrapped_components → history_viewer/_wrapped_components}/dcc.py +1 -1
- pyfemtet/opt/visualization/{_wrapped_components → history_viewer/_wrapped_components}/html.py +1 -1
- pyfemtet/opt/visualization/history_viewer/result_viewer/__main__.py +5 -0
- pyfemtet/opt/visualization/{result_viewer/application.py → history_viewer/result_viewer/_application.py} +6 -6
- pyfemtet/opt/visualization/{result_viewer/pages.py → history_viewer/result_viewer/_pages.py} +106 -82
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08.csv +18 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08.db +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8.log +45 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_1.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_1.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_10.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_10.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_11.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_11.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_12.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_12.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_13.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_13.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_14.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_14.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_15.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_15.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_16.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_16.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_17.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_17.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_18.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_18.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_19.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_19.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_2.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_2.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_20.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_20.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_3.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_3.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.bgr +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.bnd +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.btr +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.mtl +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_4.prm +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_5.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_5.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_6.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_6.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_7.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_7.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_8.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_8.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_9.jpg +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8_trial_9.pdt +0 -0
- pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.femprj +0 -0
- pyfemtet/opt/visualization/plotter/main_figure_creator.py +536 -0
- pyfemtet/opt/visualization/plotter/pm_graph_creator.py +359 -0
- pyfemtet/opt/worker_status.py +120 -0
- {pyfemtet-0.9.5.dist-info → pyfemtet-1.0.0b0.dist-info}/METADATA +23 -24
- pyfemtet-1.0.0b0.dist-info/RECORD +172 -0
- pyfemtet-1.0.0b0.dist-info/entry_points.txt +3 -0
- pyfemtet/_femtet_config_util/exit.py +0 -59
- pyfemtet/_message/1. make_pot.bat +0 -11
- pyfemtet/_message/2. make_mo.bat +0 -6
- pyfemtet/_message/__init__.py +0 -5
- pyfemtet/_message/babel.cfg +0 -2
- pyfemtet/_message/locales/ja/LC_MESSAGES/messages.mo +0 -0
- pyfemtet/_message/locales/ja/LC_MESSAGES/messages.po +0 -570
- pyfemtet/_message/locales/messages.pot +0 -551
- pyfemtet/_warning.py +0 -87
- pyfemtet/brep/_impl.py +0 -18
- pyfemtet/opt/_femopt.py +0 -1007
- pyfemtet/opt/_femopt_core.py +0 -1169
- pyfemtet/opt/_test_utils/control_femtet.py +0 -39
- pyfemtet/opt/_test_utils/hyper_sphere.py +0 -24
- pyfemtet/opt/_test_utils/record_history.py +0 -130
- pyfemtet/opt/advanced_samples/excel_ui/(ref) original_project.femprj +0 -0
- pyfemtet/opt/advanced_samples/excel_ui/femtet-macro.xlsm +0 -0
- pyfemtet/opt/advanced_samples/excel_ui/pyfemtet-core.py +0 -291
- pyfemtet/opt/advanced_samples/excel_ui/test-pyfemtet-core.cmd +0 -22
- pyfemtet/opt/advanced_samples/restart/gal_ex13_parametric.femprj +0 -0
- pyfemtet/opt/advanced_samples/restart/gal_ex13_parametric_restart.py +0 -99
- pyfemtet/opt/advanced_samples/restart/gal_ex13_parametric_restart_jp.py +0 -102
- pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_create_training_data.py +0 -60
- pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_create_training_data_jp.py +0 -57
- pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_optimize_with_surrogate.py +0 -100
- pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_optimize_with_surrogate_jp.py +0 -90
- pyfemtet/opt/advanced_samples/surrogate_model/gal_ex13_parametric.femprj +0 -0
- pyfemtet/opt/interface/_base.py +0 -101
- pyfemtet/opt/interface/_excel_interface.py +0 -984
- pyfemtet/opt/interface/_femtet_excel.py +0 -141
- pyfemtet/opt/interface/_femtet_with_nx/__init__.py +0 -3
- pyfemtet/opt/interface/_femtet_with_nx/_interface.py +0 -178
- pyfemtet/opt/interface/_femtet_with_sldworks.py +0 -298
- pyfemtet/opt/interface/_surrogate/__init__.py +0 -5
- pyfemtet/opt/interface/_surrogate/_base.py +0 -129
- pyfemtet/opt/interface/_surrogate/_chaospy.py +0 -71
- pyfemtet/opt/interface/_surrogate/_singletaskgp.py +0 -71
- pyfemtet/opt/interface/_surrogate_excel.py +0 -102
- pyfemtet/opt/optimizer/_base.py +0 -376
- pyfemtet/opt/optimizer/_optuna/_botorch_patch/enable_nonlinear_constraint.py +0 -220
- pyfemtet/opt/optimizer/_optuna/_optuna.py +0 -434
- pyfemtet/opt/optimizer/_optuna/_pof_botorch.py +0 -1914
- pyfemtet/opt/optimizer/_scipy.py +0 -159
- pyfemtet/opt/optimizer/_scipy_scalar.py +0 -127
- pyfemtet/opt/optimizer/parameter.py +0 -113
- pyfemtet/opt/prediction/_base.py +0 -61
- pyfemtet/opt/prediction/single_task_gp.py +0 -119
- pyfemtet/opt/samples/femprj_sample/ParametricIF.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample/ParametricIF.py +0 -29
- pyfemtet/opt/samples/femprj_sample/ParametricIF_test_result.reccsv +0 -13
- pyfemtet/opt/samples/femprj_sample/cad_ex01_NX.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample/cad_ex01_NX.prt +0 -0
- pyfemtet/opt/samples/femprj_sample/cad_ex01_NX.py +0 -135
- pyfemtet/opt/samples/femprj_sample/cad_ex01_NX_test_result.reccsv +0 -23
- pyfemtet/opt/samples/femprj_sample/cad_ex01_SW.SLDPRT +0 -0
- pyfemtet/opt/samples/femprj_sample/cad_ex01_SW.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample/cad_ex01_SW.py +0 -131
- pyfemtet/opt/samples/femprj_sample/cad_ex01_SW_test_result.reccsv +0 -23
- pyfemtet/opt/samples/femprj_sample/constrained_pipe.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample/constrained_pipe.py +0 -96
- pyfemtet/opt/samples/femprj_sample/constrained_pipe_test_result.reccsv +0 -13
- pyfemtet/opt/samples/femprj_sample/gal_ex58_parametric.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample/gal_ex58_parametric.py +0 -74
- pyfemtet/opt/samples/femprj_sample/gal_ex58_parametric_test_result.reccsv +0 -13
- pyfemtet/opt/samples/femprj_sample/gau_ex08_parametric.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample/gau_ex08_parametric.py +0 -58
- pyfemtet/opt/samples/femprj_sample/gau_ex08_parametric_test_result.reccsv +0 -23
- pyfemtet/opt/samples/femprj_sample/gau_ex12_parametric.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample/gau_ex12_parametric.py +0 -52
- pyfemtet/opt/samples/femprj_sample/her_ex40_parametric.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample/her_ex40_parametric.py +0 -138
- pyfemtet/opt/samples/femprj_sample/her_ex40_parametric_test_result.reccsv +0 -18
- pyfemtet/opt/samples/femprj_sample/paswat_ex1_parametric.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample/paswat_ex1_parametric.py +0 -60
- pyfemtet/opt/samples/femprj_sample/paswat_ex1_parametric_parallel.py +0 -61
- pyfemtet/opt/samples/femprj_sample/paswat_ex1_parametric_test_result.reccsv +0 -18
- pyfemtet/opt/samples/femprj_sample/wat_ex14_parametric.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample/wat_ex14_parametric.py +0 -58
- pyfemtet/opt/samples/femprj_sample/wat_ex14_parametric_parallel.py +0 -58
- pyfemtet/opt/samples/femprj_sample/wat_ex14_parametric_test_result.reccsv +0 -18
- pyfemtet/opt/samples/femprj_sample_jp/ParametricIF_jp.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample_jp/ParametricIF_jp.py +0 -29
- pyfemtet/opt/samples/femprj_sample_jp/cad_ex01_NX_jp.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample_jp/cad_ex01_NX_jp.py +0 -129
- pyfemtet/opt/samples/femprj_sample_jp/cad_ex01_SW_jp.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample_jp/cad_ex01_SW_jp.py +0 -125
- pyfemtet/opt/samples/femprj_sample_jp/constrained_pipe_jp.py +0 -93
- pyfemtet/opt/samples/femprj_sample_jp/gal_ex58_parametric_jp.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample_jp/gal_ex58_parametric_jp.py +0 -70
- pyfemtet/opt/samples/femprj_sample_jp/gau_ex08_parametric_jp.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample_jp/gau_ex08_parametric_jp.py +0 -57
- pyfemtet/opt/samples/femprj_sample_jp/gau_ex12_parametric_jp.py +0 -52
- pyfemtet/opt/samples/femprj_sample_jp/her_ex40_parametric_jp.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample_jp/her_ex40_parametric_jp.py +0 -138
- pyfemtet/opt/samples/femprj_sample_jp/paswat_ex1_parametric_jp.femprj +0 -0
- pyfemtet/opt/samples/femprj_sample_jp/paswat_ex1_parametric_jp.py +0 -58
- pyfemtet/opt/samples/femprj_sample_jp/paswat_ex1_parametric_parallel_jp.py +0 -59
- pyfemtet/opt/samples/femprj_sample_jp/wat_ex14_parametric_jp.py +0 -56
- pyfemtet/opt/samples/femprj_sample_jp/wat_ex14_parametric_parallel_jp.py +0 -56
- pyfemtet/opt/visualization/_complex_components/main_figure_creator.py +0 -332
- pyfemtet/opt/visualization/_complex_components/pm_graph_creator.py +0 -201
- pyfemtet/opt/visualization/_process_monitor/application.py +0 -226
- pyfemtet/opt/visualization/_process_monitor/pages.py +0 -406
- pyfemtet/opt/visualization/_wrapped_components/__init__.py +0 -0
- pyfemtet/opt/visualization/result_viewer/__init__.py +0 -0
- pyfemtet-0.9.5.dist-info/RECORD +0 -158
- pyfemtet-0.9.5.dist-info/entry_points.txt +0 -3
- /pyfemtet/{_femtet_config_util → opt/problem}/__init__.py +0 -0
- /pyfemtet/{brep → opt/visualization/history_viewer}/__init__.py +0 -0
- /pyfemtet/opt/{_test_utils → visualization/history_viewer/_complex_components}/__init__.py +0 -0
- /pyfemtet/opt/{optimizer/_optuna → visualization/history_viewer/_process_monitor}/__init__.py +0 -0
- /pyfemtet/opt/{optimizer/_optuna/_botorch_patch → visualization/history_viewer/_wrapped_components}/__init__.py +0 -0
- /pyfemtet/opt/visualization/{_wrapped_components → history_viewer/_wrapped_components}/str_enum.py +0 -0
- /pyfemtet/opt/visualization/{result_viewer → history_viewer/result_viewer}/.gitignore +0 -0
- /pyfemtet/opt/visualization/{_complex_components → history_viewer/result_viewer}/__init__.py +0 -0
- /pyfemtet/opt/visualization/{_process_monitor → plotter}/__init__.py +0 -0
- /pyfemtet/opt/{samples/femprj_sample_jp/wat_ex14_parametric_jp.femprj → wat_ex14_parametric_jp.femprj} +0 -0
- {pyfemtet-0.9.5.dist-info → pyfemtet-1.0.0b0.dist-info}/LICENSE +0 -0
- {pyfemtet-0.9.5.dist-info → pyfemtet-1.0.0b0.dist-info}/LICENSE_THIRD_PARTY.txt +0 -0
- {pyfemtet-0.9.5.dist-info → pyfemtet-1.0.0b0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
from optuna.distributions import (
|
|
5
|
+
FloatDistribution,
|
|
6
|
+
CategoricalDistribution,
|
|
7
|
+
BaseDistribution,
|
|
8
|
+
CategoricalChoiceType
|
|
9
|
+
)
|
|
10
|
+
from optuna._transform import _SearchSpaceTransform
|
|
11
|
+
|
|
12
|
+
from pyfemtet.opt.history import *
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
'get_bounds_containing_entire_bounds',
|
|
16
|
+
'get_choices_containing_entire_bounds',
|
|
17
|
+
'get_params_list',
|
|
18
|
+
'get_params_list_from_ndarray',
|
|
19
|
+
'get_search_space',
|
|
20
|
+
'get_transform_0_1',
|
|
21
|
+
'get_transformed_params',
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_bounds_containing_entire_bounds(df: pd.DataFrame, prm_name) -> tuple[float, float]:
|
|
26
|
+
"""Get param bounds with all bounds"""
|
|
27
|
+
|
|
28
|
+
lb_name = CorrespondingColumnNameRuler.prm_lower_bound_name(prm_name)
|
|
29
|
+
lb = df[lb_name].dropna().min()
|
|
30
|
+
|
|
31
|
+
ub_name = CorrespondingColumnNameRuler.prm_upper_bound_name(prm_name)
|
|
32
|
+
ub = df[ub_name].dropna().max()
|
|
33
|
+
|
|
34
|
+
return float(lb), float(ub)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_choices_containing_entire_bounds(df: pd.DataFrame, prm_name) -> set[CategoricalChoiceType]:
|
|
38
|
+
"""Get param bounds with all choices"""
|
|
39
|
+
|
|
40
|
+
choices_name = CorrespondingColumnNameRuler.prm_choices_name(prm_name)
|
|
41
|
+
choices_values = df[choices_name].values
|
|
42
|
+
choices = set()
|
|
43
|
+
for choices_ in choices_values:
|
|
44
|
+
for c in choices_:
|
|
45
|
+
choices.add(c)
|
|
46
|
+
return choices
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get_params_list(df: pd.DataFrame, history: History) -> list[dict[str, ...]]:
|
|
50
|
+
# get search space and parameters
|
|
51
|
+
params_list: list[dict[str, ...]] = []
|
|
52
|
+
|
|
53
|
+
# update params_list
|
|
54
|
+
for i, row in df.iterrows():
|
|
55
|
+
|
|
56
|
+
# create search space and parameter values
|
|
57
|
+
params = dict()
|
|
58
|
+
|
|
59
|
+
# inspect each parameter
|
|
60
|
+
for prm_name in history.prm_names:
|
|
61
|
+
|
|
62
|
+
# parameter value
|
|
63
|
+
params.update({prm_name: row[prm_name]})
|
|
64
|
+
|
|
65
|
+
# append params_list
|
|
66
|
+
params_list.append(params)
|
|
67
|
+
|
|
68
|
+
return params_list
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def get_params_list_from_ndarray(x: np.ndarray, history: History) -> list[dict[str, ...]]:
|
|
72
|
+
# get search space and parameters
|
|
73
|
+
params_list: list[dict[str, ...]] = []
|
|
74
|
+
|
|
75
|
+
# update params_list
|
|
76
|
+
for prm_values in x:
|
|
77
|
+
|
|
78
|
+
# create search space and parameter values
|
|
79
|
+
params = dict()
|
|
80
|
+
|
|
81
|
+
# parameter value
|
|
82
|
+
params.update(
|
|
83
|
+
{name: value for name, value
|
|
84
|
+
in zip(history.prm_names, prm_values)}
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# append params_list
|
|
88
|
+
params_list.append(params)
|
|
89
|
+
|
|
90
|
+
return params_list
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def get_search_space(df: pd.DataFrame, history: History) -> dict[str, BaseDistribution]:
|
|
94
|
+
# get search_space
|
|
95
|
+
search_space = dict()
|
|
96
|
+
for prm_name in history.prm_names:
|
|
97
|
+
if history._records.column_manager.is_numerical_parameter(prm_name):
|
|
98
|
+
lb, ub = get_bounds_containing_entire_bounds(df, prm_name)
|
|
99
|
+
search_space.update({
|
|
100
|
+
prm_name: FloatDistribution(
|
|
101
|
+
low=lb, high=ub,
|
|
102
|
+
)
|
|
103
|
+
})
|
|
104
|
+
elif history._records.column_manager.is_categorical_parameter(prm_name):
|
|
105
|
+
choices: set = get_choices_containing_entire_bounds(df, prm_name)
|
|
106
|
+
search_space.update({
|
|
107
|
+
prm_name: CategoricalDistribution(
|
|
108
|
+
choices=tuple(choices)
|
|
109
|
+
)
|
|
110
|
+
})
|
|
111
|
+
else:
|
|
112
|
+
raise NotImplementedError
|
|
113
|
+
return search_space
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def get_transform_0_1(df: pd.DataFrame, history: History) -> _SearchSpaceTransform:
|
|
117
|
+
# get search_space
|
|
118
|
+
search_space = get_search_space(df, history)
|
|
119
|
+
|
|
120
|
+
# get transform
|
|
121
|
+
trans = _SearchSpaceTransform(search_space, transform_0_1=True)
|
|
122
|
+
|
|
123
|
+
return trans
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def get_transformed_params(
|
|
127
|
+
df_or_x: pd.DataFrame | np.ndarray, history: History, trans: _SearchSpaceTransform
|
|
128
|
+
) -> np.ndarray:
|
|
129
|
+
|
|
130
|
+
out = np.empty(
|
|
131
|
+
(
|
|
132
|
+
0,
|
|
133
|
+
len(trans.encoded_column_to_column) # ここ。choices ぶん増やす
|
|
134
|
+
),
|
|
135
|
+
dtype=float
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# get list of params
|
|
139
|
+
if isinstance(df_or_x, pd.DataFrame):
|
|
140
|
+
params_list = get_params_list(df_or_x, history)
|
|
141
|
+
elif isinstance(df_or_x, np.ndarray):
|
|
142
|
+
params_list = get_params_list_from_ndarray(df_or_x, history)
|
|
143
|
+
else:
|
|
144
|
+
raise NotImplementedError
|
|
145
|
+
|
|
146
|
+
# calc transformed value
|
|
147
|
+
for params in params_list:
|
|
148
|
+
trans_prm_values: np.ndarray = trans.transform(params)
|
|
149
|
+
out = np.concatenate(
|
|
150
|
+
[out, [trans_prm_values]],
|
|
151
|
+
dtype=float,
|
|
152
|
+
axis=0,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
return out
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
from optuna._transform import _SearchSpaceTransform
|
|
5
|
+
import torch
|
|
6
|
+
from botorch.models import SingleTaskGP
|
|
7
|
+
|
|
8
|
+
from pyfemtet.opt.history import *
|
|
9
|
+
from pyfemtet.opt.prediction._helper import *
|
|
10
|
+
from pyfemtet.opt.prediction._botorch_utils import *
|
|
11
|
+
from pyfemtet.opt.prediction._gpytorch_modules_extension import get_covar_module_with_dim_scaled_prior_extension
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
'PyFemtetModel',
|
|
16
|
+
'AbstractModel',
|
|
17
|
+
'SingleTaskGPModel',
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class AbstractModel:
|
|
22
|
+
|
|
23
|
+
def fit(self, x: np.ndarray, y: np.ndarray, bounds: np.ndarray = None, **kwargs): ...
|
|
24
|
+
def predict(self, x: np.ndarray) -> tuple[np.ndarray, np.ndarray]: ...
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class SingleTaskGPModel(AbstractModel):
|
|
28
|
+
|
|
29
|
+
KWARGS = dict(dtype=torch.float64, device='cpu')
|
|
30
|
+
gp: SingleTaskGP
|
|
31
|
+
|
|
32
|
+
def fit(
|
|
33
|
+
self,
|
|
34
|
+
x: np.ndarray,
|
|
35
|
+
y: np.ndarray,
|
|
36
|
+
bounds: np.ndarray = None,
|
|
37
|
+
observation_noise=None,
|
|
38
|
+
likelihood_class=None,
|
|
39
|
+
covar_module_settings: dict = None,
|
|
40
|
+
):
|
|
41
|
+
|
|
42
|
+
covar_module = None
|
|
43
|
+
|
|
44
|
+
X = torch.tensor(x, **self.KWARGS)
|
|
45
|
+
Y = torch.tensor(y, **self.KWARGS)
|
|
46
|
+
B = torch.tensor(bounds, **self.KWARGS).transpose(1, 0) if bounds is not None else None
|
|
47
|
+
|
|
48
|
+
if covar_module_settings is not None:
|
|
49
|
+
if covar_module_settings['name'] == 'matern_kernel_with_gamma_prior':
|
|
50
|
+
covar_module_settings.pop('name')
|
|
51
|
+
covar_module = get_matern_kernel_with_gamma_prior_as_covar_module(
|
|
52
|
+
X, Y,
|
|
53
|
+
**covar_module_settings,
|
|
54
|
+
)
|
|
55
|
+
elif covar_module_settings['name'] == 'get_covar_module_with_dim_scaled_prior_extension':
|
|
56
|
+
covar_module_settings.pop('name')
|
|
57
|
+
|
|
58
|
+
_input_batch_shape, _aug_batch_shape = SingleTaskGP.get_batch_dimensions(X, Y)
|
|
59
|
+
batch_shape = _aug_batch_shape
|
|
60
|
+
|
|
61
|
+
covar_module = get_covar_module_with_dim_scaled_prior_extension(
|
|
62
|
+
ard_num_dims=X.shape[-1],
|
|
63
|
+
batch_shape=batch_shape,
|
|
64
|
+
**covar_module_settings,
|
|
65
|
+
)
|
|
66
|
+
else:
|
|
67
|
+
raise NotImplementedError(f'{covar_module_settings["name"]=}')
|
|
68
|
+
|
|
69
|
+
self.gp = setup_gp(X, Y, B, observation_noise, likelihood_class, covar_module)
|
|
70
|
+
|
|
71
|
+
def predict(self, x: np.ndarray):
|
|
72
|
+
assert hasattr(self, 'gp')
|
|
73
|
+
X = torch.tensor(x, **self.KWARGS)
|
|
74
|
+
post = self.gp.posterior(X)
|
|
75
|
+
with torch.no_grad():
|
|
76
|
+
mean = post.mean.numpy()
|
|
77
|
+
std = post.variance.sqrt().numpy()
|
|
78
|
+
return mean, std
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class PyFemtetModel:
|
|
82
|
+
|
|
83
|
+
current_trans: _SearchSpaceTransform
|
|
84
|
+
current_model: AbstractModel
|
|
85
|
+
history: History
|
|
86
|
+
|
|
87
|
+
def update_model(self, model: AbstractModel):
|
|
88
|
+
self.current_model = model
|
|
89
|
+
|
|
90
|
+
def fit(self, history: History, df: pd.DataFrame, **kwargs):
|
|
91
|
+
assert hasattr(self, 'current_model')
|
|
92
|
+
assert 'x' not in kwargs
|
|
93
|
+
assert 'y' not in kwargs
|
|
94
|
+
assert 'bounds' not in kwargs
|
|
95
|
+
|
|
96
|
+
self.history = history
|
|
97
|
+
|
|
98
|
+
# remove nan from df
|
|
99
|
+
df = df.dropna(subset=history.obj_names + history.prm_names, how='any')
|
|
100
|
+
|
|
101
|
+
# set current trans
|
|
102
|
+
self.current_trans = get_transform_0_1(df, history)
|
|
103
|
+
|
|
104
|
+
# transform all values
|
|
105
|
+
transformed_x = get_transformed_params(df, history, self.current_trans)
|
|
106
|
+
|
|
107
|
+
# bounds as setup maximum range
|
|
108
|
+
bounds = self.current_trans.bounds
|
|
109
|
+
|
|
110
|
+
y = df[history.obj_names].values
|
|
111
|
+
self.current_model.fit(transformed_x, y, bounds, **kwargs)
|
|
112
|
+
|
|
113
|
+
def predict(self, x: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
|
|
114
|
+
assert hasattr(self, 'history')
|
|
115
|
+
assert hasattr(self, 'current_trans')
|
|
116
|
+
|
|
117
|
+
transformed_x = get_transformed_params(x, self.history, self.current_trans)
|
|
118
|
+
return self.current_model.predict(transformed_x)
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Callable, TYPE_CHECKING, TypeAlias, Sequence
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
# noinspection PyUnresolvedReferences
|
|
7
|
+
from pythoncom import CoInitialize, CoUninitialize
|
|
8
|
+
from win32com.client import Dispatch, Constants, constants
|
|
9
|
+
except ModuleNotFoundError:
|
|
10
|
+
# noinspection PyPep8Naming
|
|
11
|
+
def CoInitialize(): ...
|
|
12
|
+
# noinspection PyPep8Naming
|
|
13
|
+
def CoUninitialize(): ...
|
|
14
|
+
Dispatch = type('NoDispatch', (object,), {})
|
|
15
|
+
Constants = type('NoConstants', (object,), {})
|
|
16
|
+
constants = Constants()
|
|
17
|
+
|
|
18
|
+
from pyfemtet._i18n import _
|
|
19
|
+
from pyfemtet._util.helper import *
|
|
20
|
+
|
|
21
|
+
from .variable_manager import *
|
|
22
|
+
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
from pyfemtet.opt.optimizer import AbstractOptimizer
|
|
25
|
+
from pyfemtet.opt.interface import AbstractFEMInterface
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
'TrialInput',
|
|
29
|
+
'TrialOutput',
|
|
30
|
+
'TrialConstraintOutput',
|
|
31
|
+
'Function',
|
|
32
|
+
'Functions',
|
|
33
|
+
'Objective',
|
|
34
|
+
'ObjectiveResult',
|
|
35
|
+
'Objectives',
|
|
36
|
+
'ObjectivesFunc',
|
|
37
|
+
'Constraint',
|
|
38
|
+
'ConstraintResult',
|
|
39
|
+
'Constraints',
|
|
40
|
+
'Fidelity',
|
|
41
|
+
'SubSampling',
|
|
42
|
+
'MAIN_FIDELITY_NAME',
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
MAIN_FIDELITY_NAME = ''
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Function:
|
|
49
|
+
_fun: Callable[..., float]
|
|
50
|
+
args: tuple
|
|
51
|
+
kwargs: dict
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def fun(self) -> Callable[..., float]:
|
|
55
|
+
self._ScapeGoat.restore_constants(self._fun)
|
|
56
|
+
return self._fun
|
|
57
|
+
|
|
58
|
+
@fun.setter
|
|
59
|
+
def fun(self, f: Callable[..., float]):
|
|
60
|
+
self._fun = f
|
|
61
|
+
|
|
62
|
+
def __getstate__(self):
|
|
63
|
+
"""Pickle 時に _fun が参照する constants を _ScapeGoat にする"""
|
|
64
|
+
state = self.__dict__
|
|
65
|
+
if '_fun' in state:
|
|
66
|
+
self._ScapeGoat.remove_constants(state['_fun'])
|
|
67
|
+
return state
|
|
68
|
+
|
|
69
|
+
def __setstate__(self, state):
|
|
70
|
+
"""Pickle 時に _fun が参照する _ScapeGoat を constants にする"""
|
|
71
|
+
CoInitialize()
|
|
72
|
+
if '_fun' in state:
|
|
73
|
+
self._ScapeGoat.restore_constants(state['_fun'])
|
|
74
|
+
self.__dict__.update(state)
|
|
75
|
+
|
|
76
|
+
class _ScapeGoat:
|
|
77
|
+
|
|
78
|
+
@classmethod
|
|
79
|
+
def restore_constants(cls, f: ...):
|
|
80
|
+
"""f の存在する global スコープの _Scapegoat 変数を constants に変更"""
|
|
81
|
+
if not hasattr(f, '__globals__'):
|
|
82
|
+
return
|
|
83
|
+
|
|
84
|
+
for name, var in f.__globals__.items():
|
|
85
|
+
if isinstance(var, cls):
|
|
86
|
+
# try 不要
|
|
87
|
+
# fun の定義がこのファイル上にある場合、つまりデバッグ時のみ
|
|
88
|
+
# remove_constants がこのスコープの constants を消すので
|
|
89
|
+
# constants を再インポートする必要がある
|
|
90
|
+
from win32com.client import constants
|
|
91
|
+
f.__globals__[name] = constants
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def remove_constants(cls, f: ...):
|
|
95
|
+
"""f の存在する global スコープの Constants 変数を _Scapegoat に変更"""
|
|
96
|
+
|
|
97
|
+
if not hasattr(f, '__globals__'):
|
|
98
|
+
return
|
|
99
|
+
|
|
100
|
+
for name, var in f.__globals__.items():
|
|
101
|
+
if isinstance(var, Constants):
|
|
102
|
+
f.__globals__[name] = cls()
|
|
103
|
+
|
|
104
|
+
def eval(self, fem: AbstractFEMInterface) -> float:
|
|
105
|
+
return float(self.fun(fem.object_pass_to_fun, *self.args, **self.kwargs))
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class Functions(dict[str, Function]):
|
|
109
|
+
pass
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class Objective(Function):
|
|
113
|
+
direction: str | float
|
|
114
|
+
|
|
115
|
+
@staticmethod
|
|
116
|
+
def _convert(value, direction) -> float:
|
|
117
|
+
|
|
118
|
+
direction: float | str | None = float_(direction)
|
|
119
|
+
|
|
120
|
+
if value is None or direction is None:
|
|
121
|
+
value_as_minimize = float('nan')
|
|
122
|
+
|
|
123
|
+
elif isinstance(direction, str):
|
|
124
|
+
if direction.lower() == 'minimize':
|
|
125
|
+
value_as_minimize = value
|
|
126
|
+
elif direction.lower() == 'maximize':
|
|
127
|
+
value_as_minimize = -value
|
|
128
|
+
else:
|
|
129
|
+
raise NotImplementedError
|
|
130
|
+
|
|
131
|
+
else:
|
|
132
|
+
# if value is nan, return nan
|
|
133
|
+
value_as_minimize = (value - direction) ** 2
|
|
134
|
+
|
|
135
|
+
return value_as_minimize
|
|
136
|
+
|
|
137
|
+
def convert(self, value) -> float:
|
|
138
|
+
return self._convert(value, self.direction)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class ObjectiveResult:
|
|
142
|
+
|
|
143
|
+
def __init__(self, obj: Objective, fem: AbstractFEMInterface, obj_value: float = None):
|
|
144
|
+
|
|
145
|
+
self.value: float = obj_value if obj_value is not None else obj.eval(fem)
|
|
146
|
+
self.direction: str | float = obj.direction
|
|
147
|
+
|
|
148
|
+
def __repr__(self):
|
|
149
|
+
return str(self.value)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class ObjectivesFunc:
|
|
153
|
+
"""複数の値を返す関数を単一の float を返す関数に分割する。"""
|
|
154
|
+
|
|
155
|
+
def __init__(self, fun: Callable[..., Sequence[float]], n_return: int):
|
|
156
|
+
# Optimizer に追加される数と一致することを保証したいので
|
|
157
|
+
# n_returns が必要
|
|
158
|
+
self._called: list[bool] | None = None
|
|
159
|
+
self._values: list[bool] | None = None
|
|
160
|
+
self.fun: Callable[..., Sequence[float]] = fun
|
|
161
|
+
self.n_return: int = n_return
|
|
162
|
+
|
|
163
|
+
def get_fun_that_returns_ith_value(self, i):
|
|
164
|
+
|
|
165
|
+
if i not in range(self.n_return):
|
|
166
|
+
raise IndexError(
|
|
167
|
+
_(
|
|
168
|
+
en_message='Index {i} is over n_return={n_return}.',
|
|
169
|
+
jp_message='インデックス {i} は n_return={n_return} を超えています。',
|
|
170
|
+
i=i, n_return=self.n_return
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
# iter として提供する callable オブジェクト
|
|
175
|
+
# self の情報にもアクセスする必要があり
|
|
176
|
+
# それぞれが iter された時点での i 番目という
|
|
177
|
+
# 情報も必要なのでこのスコープで定義する必要がある
|
|
178
|
+
# noinspection PyMethodParameters
|
|
179
|
+
class NthFunc:
|
|
180
|
+
|
|
181
|
+
def __init__(self_, i_):
|
|
182
|
+
# 何番目の要素であるかを保持
|
|
183
|
+
self_.i = i_
|
|
184
|
+
|
|
185
|
+
def __call__(self_, *args, **kwargs) -> float:
|
|
186
|
+
# 何番目の要素であるか
|
|
187
|
+
i_ = self_.i
|
|
188
|
+
|
|
189
|
+
# 一度も呼ばれていなければ評価する
|
|
190
|
+
if self._called is None:
|
|
191
|
+
self._values = self.fun(*args, **kwargs)
|
|
192
|
+
self._called = [False for __ in self._values]
|
|
193
|
+
|
|
194
|
+
assert len(self._values) == self.n_return, _(
|
|
195
|
+
en_message='The number of return values of {fun_name} is {n_values}. '
|
|
196
|
+
'This is inconsistent with the specified n_return; {n_return}.',
|
|
197
|
+
jp_message='{fun_name} の実行結果の値の数は {n_values} でした。'
|
|
198
|
+
'これは指定された n_return={n_return} と一致しません。',
|
|
199
|
+
fun_name=self.fun.__name__,
|
|
200
|
+
n_values=len(self._values),
|
|
201
|
+
n_return=self.n_return,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
# i_ が呼ばれたのでフラグを立てる
|
|
205
|
+
self._called[i_] = True
|
|
206
|
+
value = self._values[i_]
|
|
207
|
+
|
|
208
|
+
# すべてのフラグが立ったならクリアする
|
|
209
|
+
if all(self._called):
|
|
210
|
+
self._called = None
|
|
211
|
+
self._values = None
|
|
212
|
+
|
|
213
|
+
# 値を返す
|
|
214
|
+
return value
|
|
215
|
+
|
|
216
|
+
# noinspection PyPropertyDefinition
|
|
217
|
+
@property
|
|
218
|
+
def __globals__(self_):
|
|
219
|
+
# ScapeGoat 実装への対処
|
|
220
|
+
if hasattr(self.fun, '__globals__'):
|
|
221
|
+
return self.fun.__globals__
|
|
222
|
+
else:
|
|
223
|
+
return {}
|
|
224
|
+
|
|
225
|
+
# N 番目の値を返す関数を返す
|
|
226
|
+
f = NthFunc(i)
|
|
227
|
+
|
|
228
|
+
return f
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class Objectives(dict[str, Objective]):
|
|
232
|
+
pass
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class Constraint(Function):
|
|
236
|
+
lower_bound: float | None
|
|
237
|
+
upper_bound: float | None
|
|
238
|
+
hard: bool
|
|
239
|
+
_using_fem: bool | None = None
|
|
240
|
+
_opt: AbstractOptimizer
|
|
241
|
+
|
|
242
|
+
@property
|
|
243
|
+
def using_fem(self) -> bool:
|
|
244
|
+
if self._using_fem is None:
|
|
245
|
+
return self._opt.fem._check_using_fem(self.fun)
|
|
246
|
+
else:
|
|
247
|
+
return self._using_fem
|
|
248
|
+
|
|
249
|
+
@using_fem.setter
|
|
250
|
+
def using_fem(self, value: bool | None):
|
|
251
|
+
self._using_fem = value
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
class ConstraintResult:
|
|
255
|
+
|
|
256
|
+
def __init__(
|
|
257
|
+
self,
|
|
258
|
+
cns: Constraint,
|
|
259
|
+
fem: AbstractFEMInterface,
|
|
260
|
+
cns_value: float = None,
|
|
261
|
+
constraint_enhancement: float = None, # offset により scipy.minimize が拘束違反の解を返す問題を回避する
|
|
262
|
+
constraint_scaling: float = None, # scaling により scipy.minimize が拘束違反の解を返す問題を回避する
|
|
263
|
+
):
|
|
264
|
+
|
|
265
|
+
self.value: float = cns_value if cns_value is not None else cns.eval(fem)
|
|
266
|
+
self.lower_bound: float | None = cns.lower_bound
|
|
267
|
+
self.upper_bound: float | None = cns.upper_bound
|
|
268
|
+
self.hard: bool = cns.hard
|
|
269
|
+
self.ce = constraint_enhancement or 0.
|
|
270
|
+
self.cs = constraint_scaling or 1.
|
|
271
|
+
|
|
272
|
+
def __repr__(self):
|
|
273
|
+
return str(self.value)
|
|
274
|
+
|
|
275
|
+
def calc_violation(self) -> dict[str, float]:
|
|
276
|
+
value = self.value
|
|
277
|
+
out = {}
|
|
278
|
+
if self.lower_bound is not None:
|
|
279
|
+
out.update({'lower_bound': self.cs * (self.lower_bound - value) + self.ce})
|
|
280
|
+
if self.upper_bound is not None:
|
|
281
|
+
out.update({'upper_bound': self.cs * (value - self.upper_bound) + self.ce})
|
|
282
|
+
return out
|
|
283
|
+
|
|
284
|
+
def check_violation(self) -> str | None:
|
|
285
|
+
violation = self.calc_violation()
|
|
286
|
+
for l_or_u, value in violation.items():
|
|
287
|
+
if value > 0:
|
|
288
|
+
return l_or_u
|
|
289
|
+
return None
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
class Constraints(dict[str, Constraint]):
|
|
293
|
+
pass
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
Fidelity: TypeAlias = float | str | None
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
SubSampling: TypeAlias = int
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
TrialInput: TypeAlias = dict[str, Variable]
|
|
303
|
+
TrialOutput: TypeAlias = dict[str, ObjectiveResult]
|
|
304
|
+
TrialConstraintOutput: TypeAlias = dict[str, ConstraintResult]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from ._variable_manager import *
|
|
2
|
+
from ._string_as_expression import *
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
'SupportedVariableTypes',
|
|
6
|
+
'Parameter',
|
|
7
|
+
'Variable',
|
|
8
|
+
'NumericVariable',
|
|
9
|
+
'NumericParameter',
|
|
10
|
+
'CategoricalVariable',
|
|
11
|
+
'CategoricalParameter',
|
|
12
|
+
'Expression',
|
|
13
|
+
'ExpressionFromFunction',
|
|
14
|
+
# 'NumericExpressionFromFunction',
|
|
15
|
+
# 'CategoricalExpressionFromFunction',
|
|
16
|
+
'ExpressionFromString',
|
|
17
|
+
'VariableManager',
|
|
18
|
+
'SympifyError',
|
|
19
|
+
'InvalidExpression',
|
|
20
|
+
]
|