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
|
@@ -1,984 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
from time import sleep
|
|
4
|
-
import gc
|
|
5
|
-
from typing import Optional, List
|
|
6
|
-
|
|
7
|
-
import pandas as pd
|
|
8
|
-
import numpy as np
|
|
9
|
-
from dask.distributed import get_worker
|
|
10
|
-
|
|
11
|
-
from win32com.client import DispatchEx, Dispatch
|
|
12
|
-
from win32com.client.dynamic import CDispatch
|
|
13
|
-
from femtetutils import util
|
|
14
|
-
|
|
15
|
-
# noinspection PyUnresolvedReferences
|
|
16
|
-
from pythoncom import CoInitialize, CoUninitialize
|
|
17
|
-
# noinspection PyUnresolvedReferences
|
|
18
|
-
from pywintypes import com_error
|
|
19
|
-
|
|
20
|
-
# pyfemtet.core
|
|
21
|
-
from pyfemtet.core import SolveError
|
|
22
|
-
|
|
23
|
-
# pyfemtet._util
|
|
24
|
-
from pyfemtet._femtet_config_util.exit import _exit_or_force_terminate
|
|
25
|
-
from pyfemtet._util.excel_macro_util import watch_excel_macro_error
|
|
26
|
-
from pyfemtet._util.dask_util import lock_or_no_lock
|
|
27
|
-
from pyfemtet._util.excel_parse_util import *
|
|
28
|
-
from pyfemtet._warning import show_experimental_warning
|
|
29
|
-
from pyfemtet._message.messages import Message as Msg
|
|
30
|
-
|
|
31
|
-
# dispatch extension
|
|
32
|
-
from pyfemtet.dispatch_extensions import _get_pid, dispatch_specific_femtet
|
|
33
|
-
|
|
34
|
-
# interface
|
|
35
|
-
from pyfemtet.opt.interface._base import FEMInterface, logger
|
|
36
|
-
|
|
37
|
-
# expression
|
|
38
|
-
from pyfemtet.opt.optimizer.parameter import Parameter, Expression
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class ExcelInterface(FEMInterface):
|
|
42
|
-
"""Excel を計算コアとして利用するためのクラス。
|
|
43
|
-
|
|
44
|
-
通常の有限要素法を Excel に
|
|
45
|
-
置き換えて使用することが可能です。
|
|
46
|
-
|
|
47
|
-
すでに Excel マクロと Femtet を
|
|
48
|
-
連携させた自動解析システムを
|
|
49
|
-
構築している場合、このクラスは
|
|
50
|
-
それをラップします。これにより、
|
|
51
|
-
PyFemtet を用いた最適化を
|
|
52
|
-
行う際に便利な機能を提供します。
|
|
53
|
-
|
|
54
|
-
Args:
|
|
55
|
-
input_xlsm_path (str or Path):
|
|
56
|
-
設計変数の定義を含む Excel ファイルのパスを指定
|
|
57
|
-
します。
|
|
58
|
-
|
|
59
|
-
input_sheet_name (str):
|
|
60
|
-
設計変数の定義を含むシートの名前を指定します。
|
|
61
|
-
|
|
62
|
-
output_xlsm_path (str or Path, optional):
|
|
63
|
-
目的関数の定義を含む Excel ファイルのパスを指定
|
|
64
|
-
します。指定しない場合は ``input_xlsm_path`` と
|
|
65
|
-
同じと見做します。
|
|
66
|
-
|
|
67
|
-
output_sheet_name (str, optional):
|
|
68
|
-
目的関数の定義を含む含むシートの名前を指定します。
|
|
69
|
-
指定しない場合は ``input_sheet_name`` と同じと見
|
|
70
|
-
做します。
|
|
71
|
-
|
|
72
|
-
procedure_name (str, optional):
|
|
73
|
-
Excel マクロ関数名を指定します。指定しない場合は
|
|
74
|
-
``FemtetMacro.FemtetMain`` と見做します。
|
|
75
|
-
|
|
76
|
-
procedure_args (list or tuple, optional):
|
|
77
|
-
Excel マクロ関数に渡す引数をリストまたはタプルで
|
|
78
|
-
指定します。
|
|
79
|
-
|
|
80
|
-
connect_method (str, optional):
|
|
81
|
-
Excel との接続方法を指定します。 'auto' または
|
|
82
|
-
'new' が利用可能です。デフォルトは 'new' です。
|
|
83
|
-
|
|
84
|
-
procedure_timeout (float or None, optional):
|
|
85
|
-
Excel マクロ関数のタイムアウト時間を秒単位で指定
|
|
86
|
-
します。 None の場合はタイムアウトなしとなります。
|
|
87
|
-
|
|
88
|
-
setup_xlsm_path (str or Path, optional):
|
|
89
|
-
セットアップ時に呼ぶ関数を含む xlsm のパスです。
|
|
90
|
-
指定しない場合は ``input_xlsm_path`` と
|
|
91
|
-
同じと見做します。
|
|
92
|
-
|
|
93
|
-
setup_procedure_name (str, optional):
|
|
94
|
-
セットアップ時に呼ぶマクロ関数名です。
|
|
95
|
-
指定しない場合、セットアップ時に何もしません。
|
|
96
|
-
|
|
97
|
-
setup_procedure_args (list or tuple, optional):
|
|
98
|
-
セットアップ時に呼ぶマクロ関数の引数です。
|
|
99
|
-
|
|
100
|
-
teardown_xlsm_path (str or Path, optional):
|
|
101
|
-
終了時に呼ぶ関数を含む xlsm のパスです。
|
|
102
|
-
指定しない場合は ``input_xlsm_path`` と
|
|
103
|
-
同じと見做します。
|
|
104
|
-
|
|
105
|
-
teardown_procedure_name (str, optional):
|
|
106
|
-
終了時に呼ぶマクロ関数名です。
|
|
107
|
-
指定しない場合、終了時に何もしません。
|
|
108
|
-
|
|
109
|
-
teardown_procedure_args (list or tuple, optional):
|
|
110
|
-
終了時に呼ぶマクロ関数の引数です。
|
|
111
|
-
|
|
112
|
-
visible (bool):
|
|
113
|
-
excel を可視化するかどうかです。
|
|
114
|
-
ただし、 True を指定した場合でもマクロの実行中は
|
|
115
|
-
不可視になります。
|
|
116
|
-
デフォルトは False です。
|
|
117
|
-
|
|
118
|
-
display_alerts (bool):
|
|
119
|
-
excel ダイアログを表示するかどうかです。
|
|
120
|
-
デバッグ目的の場合以外は True にしないでください。
|
|
121
|
-
デフォルトは False です。
|
|
122
|
-
|
|
123
|
-
terminate_excel_when_quit (bool):
|
|
124
|
-
終了時に Excel を終了するかどうかです。
|
|
125
|
-
指定しない場合、 connect_method が 'new' の場合
|
|
126
|
-
True とふるまい 'auto' の場合 False と振舞います。
|
|
127
|
-
|
|
128
|
-
interactive (bool):
|
|
129
|
-
excel を対話モードにするかどうかです。
|
|
130
|
-
False にすると、 visible == True であっても
|
|
131
|
-
自動化プロセス中にユーザーが誤って
|
|
132
|
-
Excel 本体を操作できないようにします。
|
|
133
|
-
デフォルトは True です。
|
|
134
|
-
|
|
135
|
-
Attributes:
|
|
136
|
-
input_xlsm_path (Path):
|
|
137
|
-
設計変数の定義を含む Excel ファイルのパス。
|
|
138
|
-
|
|
139
|
-
input_sheet_name (str):
|
|
140
|
-
設計変数の定義を含むシートの名前。
|
|
141
|
-
|
|
142
|
-
output_xlsm_path (Path):
|
|
143
|
-
目的関数の定義を含む Excel ファイルのパス。
|
|
144
|
-
|
|
145
|
-
output_sheet_name (str):
|
|
146
|
-
目的関数の定義を含む含むシートの名前。
|
|
147
|
-
|
|
148
|
-
procedure_name (str):
|
|
149
|
-
実行する Excel マクロ関数名。
|
|
150
|
-
|
|
151
|
-
procedure_args (list or tuple):
|
|
152
|
-
Excel マクロ関数に渡す引数のリストまたはタプル。
|
|
153
|
-
|
|
154
|
-
connect_method (str):
|
|
155
|
-
接続方法。'new' または 'auto'。
|
|
156
|
-
|
|
157
|
-
procedure_timeout (float or None):
|
|
158
|
-
Excel マクロ関数の実行タイムアウト。
|
|
159
|
-
Noneの場合は無制限。
|
|
160
|
-
|
|
161
|
-
terminate_excel_when_quit (bool):
|
|
162
|
-
プログラム終了時に Excel を終了するかどうか。
|
|
163
|
-
connect_method が 'new' の場合 True,
|
|
164
|
-
'auto' の場合 False。
|
|
165
|
-
|
|
166
|
-
excel (CDispatch):
|
|
167
|
-
Excel の COM オブジェクト。
|
|
168
|
-
|
|
169
|
-
input_sheet (CDispatch):
|
|
170
|
-
設計変数を含むシートの COM オブジェクト。
|
|
171
|
-
|
|
172
|
-
output_sheet (CDispatch):
|
|
173
|
-
目的関数を含むシートの COM オブジェクト。
|
|
174
|
-
|
|
175
|
-
input_workbook (CDispatch):
|
|
176
|
-
設計変数を含む xlsm ファイルの COM オブジェクト。
|
|
177
|
-
|
|
178
|
-
output_workbook (CDispatch):
|
|
179
|
-
設計変数を含む xlsm ファイルの COM オブジェクト。
|
|
180
|
-
|
|
181
|
-
"""
|
|
182
|
-
|
|
183
|
-
input_xlsm_path: str # 操作対象の xlsm パス
|
|
184
|
-
input_sheet_name: str # 変数セルを定義しているシート名
|
|
185
|
-
output_xlsm_path: str # 操作対象の xlsm パス (指定しない場合、input と同一)
|
|
186
|
-
output_sheet_name: str # 計算結果セルを定義しているシート名 (指定しない場合、input と同一)
|
|
187
|
-
constraint_xlsm_path: str # 操作対象の xlsm パス (指定しない場合、input と同一)
|
|
188
|
-
constraint_sheet_name: str # 拘束関数セルを定義しているシート名 (指定しない場合、input と同一)
|
|
189
|
-
|
|
190
|
-
related_file_paths: list[str] # 並列時に個別に並列プロセスの space にアップロードする必要のあるパス
|
|
191
|
-
|
|
192
|
-
procedure_name: str # マクロ関数名(or モジュール名.関数名)
|
|
193
|
-
procedure_args: list # マクロ関数の引数
|
|
194
|
-
|
|
195
|
-
excel: CDispatch # Excel Application
|
|
196
|
-
wb_input: CDispatch # システムを構成する Workbook
|
|
197
|
-
sh_input: CDispatch # 変数の定義された WorkSheet
|
|
198
|
-
wb_output: CDispatch # システムを構成する Workbook
|
|
199
|
-
sh_output: CDispatch # 計算結果の定義された WorkSheet (sh_input と同じでもよい)
|
|
200
|
-
wb_constraint: CDispatch # システムを構成する Workbook
|
|
201
|
-
sh_constraint: CDispatch # 計算結果の定義された WorkSheet (sh_input と同じでもよい)
|
|
202
|
-
wb_setup: CDispatch # システムを構成する Workbook
|
|
203
|
-
wb_teardown: CDispatch # システムを構成する Workbook
|
|
204
|
-
|
|
205
|
-
visible: bool # excel を可視化するかどうか
|
|
206
|
-
display_alerts: bool # ダイアログを表示するかどうか
|
|
207
|
-
terminate_excel_when_quit: bool # 終了時に Excel を終了するかどうか
|
|
208
|
-
interactive: bool # excel を対話モードにするかどうか
|
|
209
|
-
|
|
210
|
-
_load_problem_from_me: bool = True
|
|
211
|
-
_excel_pid: int
|
|
212
|
-
_excel_hwnd: int
|
|
213
|
-
_with_femtet_autosave_setting: bool = True # Femtet の自動保存機能の自動設定を行うかどうか。Femtet がインストールされていない場合はオフにする。クラス変数なので、インスタンス化前に設定する。
|
|
214
|
-
_femtet_autosave_buffer: bool # Femtet の自動保存機能の一時退避場所。最適化中はオフにする。
|
|
215
|
-
|
|
216
|
-
setup_xlsm_path: str
|
|
217
|
-
setup_procedure_name: str
|
|
218
|
-
setup_procedure_args: list or tuple
|
|
219
|
-
teardown_xlsm_path: str
|
|
220
|
-
teardown_procedure_name: str
|
|
221
|
-
teardown_procedure_args: list or tuple
|
|
222
|
-
|
|
223
|
-
use_named_range: bool # input を定義したシートにおいて input の値を名前付き範囲で指定するかどうか。
|
|
224
|
-
|
|
225
|
-
force_override_when_load: bool = False # .py で add_... されている変数などを Excel の内容で上書きするかどうか。
|
|
226
|
-
|
|
227
|
-
def __init__(
|
|
228
|
-
self,
|
|
229
|
-
input_xlsm_path: str or Path,
|
|
230
|
-
input_sheet_name: str,
|
|
231
|
-
output_xlsm_path: str or Path = None,
|
|
232
|
-
output_sheet_name: str = None,
|
|
233
|
-
constraint_xlsm_path: str or Path = None,
|
|
234
|
-
constraint_sheet_name: str = None,
|
|
235
|
-
procedure_name: str = None,
|
|
236
|
-
procedure_args: list or tuple = None,
|
|
237
|
-
connect_method: str = 'new', # or 'auto'
|
|
238
|
-
procedure_timeout: float or None = None,
|
|
239
|
-
setup_xlsm_path: str or Path = None,
|
|
240
|
-
setup_procedure_name: str = None,
|
|
241
|
-
setup_procedure_args: list or tuple = None,
|
|
242
|
-
teardown_xlsm_path: str or Path = None,
|
|
243
|
-
teardown_procedure_name: str = None,
|
|
244
|
-
teardown_procedure_args: list or tuple = None,
|
|
245
|
-
related_file_paths: list[str or Path] = None,
|
|
246
|
-
visible: bool = False,
|
|
247
|
-
display_alerts: bool = False,
|
|
248
|
-
terminate_excel_when_quit: bool = None,
|
|
249
|
-
interactive: bool = True,
|
|
250
|
-
use_named_range: bool = True,
|
|
251
|
-
):
|
|
252
|
-
|
|
253
|
-
show_experimental_warning("ExcelInterface")
|
|
254
|
-
|
|
255
|
-
# 初期化
|
|
256
|
-
self.input_xlsm_path = str(input_xlsm_path) # あとで再取得する
|
|
257
|
-
self.input_sheet_name = input_sheet_name
|
|
258
|
-
self.output_xlsm_path = str(input_xlsm_path) if output_xlsm_path is None else str(output_xlsm_path)
|
|
259
|
-
self.output_sheet_name = output_sheet_name if output_sheet_name is not None else input_sheet_name
|
|
260
|
-
self.constraint_xlsm_path = str(input_xlsm_path) if constraint_xlsm_path is None else str(constraint_xlsm_path)
|
|
261
|
-
self.constraint_sheet_name = constraint_sheet_name or self.input_sheet_name
|
|
262
|
-
self.procedure_name = procedure_name
|
|
263
|
-
self.procedure_args = procedure_args or []
|
|
264
|
-
assert connect_method in ['new', 'auto']
|
|
265
|
-
self.excel_connect_method = connect_method
|
|
266
|
-
self.procedure_timeout = procedure_timeout
|
|
267
|
-
if terminate_excel_when_quit is None:
|
|
268
|
-
self.terminate_excel_when_quit = self.excel_connect_method == 'new'
|
|
269
|
-
else:
|
|
270
|
-
self.terminate_excel_when_quit = terminate_excel_when_quit
|
|
271
|
-
|
|
272
|
-
self.setup_xlsm_path = str(input_xlsm_path) if setup_xlsm_path is None else str(setup_xlsm_path) # あとで取得する
|
|
273
|
-
self.setup_procedure_name = setup_procedure_name
|
|
274
|
-
self.setup_procedure_args = setup_procedure_args or []
|
|
275
|
-
|
|
276
|
-
self.teardown_xlsm_path = str(input_xlsm_path) if teardown_xlsm_path is None else str(
|
|
277
|
-
teardown_xlsm_path) # あとで取得する
|
|
278
|
-
self.teardown_procedure_name = teardown_procedure_name
|
|
279
|
-
self.teardown_procedure_args = teardown_procedure_args or []
|
|
280
|
-
|
|
281
|
-
self.related_file_paths = [str(p) for p in related_file_paths] if related_file_paths is not None else []
|
|
282
|
-
|
|
283
|
-
self.visible = visible
|
|
284
|
-
self.interactive = interactive
|
|
285
|
-
self.display_alerts = display_alerts
|
|
286
|
-
|
|
287
|
-
self.use_named_range = use_named_range
|
|
288
|
-
|
|
289
|
-
# dask サブプロセスのときは space 直下の input_xlsm_path を参照する
|
|
290
|
-
try:
|
|
291
|
-
worker = get_worker()
|
|
292
|
-
space = os.path.abspath(worker.local_directory)
|
|
293
|
-
self.input_xlsm_path = os.path.join(space, os.path.basename(self.input_xlsm_path))
|
|
294
|
-
self.output_xlsm_path = os.path.join(space, os.path.basename(self.output_xlsm_path))
|
|
295
|
-
self.constraint_xlsm_path = os.path.join(space, os.path.basename(self.constraint_xlsm_path))
|
|
296
|
-
self.setup_xlsm_path = os.path.join(space, os.path.basename(self.setup_xlsm_path))
|
|
297
|
-
self.teardown_xlsm_path = os.path.join(space, os.path.basename(self.teardown_xlsm_path))
|
|
298
|
-
self.related_file_paths = [os.path.join(space, os.path.basename(p)) for p in self.related_file_paths]
|
|
299
|
-
|
|
300
|
-
# main プロセスの場合は絶対パスを参照する
|
|
301
|
-
except ValueError:
|
|
302
|
-
self.input_xlsm_path = os.path.abspath(self.input_xlsm_path)
|
|
303
|
-
self.output_xlsm_path = os.path.abspath(self.output_xlsm_path)
|
|
304
|
-
self.constraint_xlsm_path = os.path.abspath(self.constraint_xlsm_path)
|
|
305
|
-
self.setup_xlsm_path = os.path.abspath(self.setup_xlsm_path)
|
|
306
|
-
self.teardown_xlsm_path = os.path.abspath(self.teardown_xlsm_path)
|
|
307
|
-
self.related_file_paths = [os.path.abspath(p) for p in self.related_file_paths]
|
|
308
|
-
|
|
309
|
-
# サブプロセスでの restore のための情報保管
|
|
310
|
-
kwargs = dict(
|
|
311
|
-
input_xlsm_path=self.input_xlsm_path,
|
|
312
|
-
input_sheet_name=self.input_sheet_name,
|
|
313
|
-
output_xlsm_path=self.output_xlsm_path,
|
|
314
|
-
output_sheet_name=self.output_sheet_name,
|
|
315
|
-
constraint_xlsm_path=self.constraint_xlsm_path,
|
|
316
|
-
constraint_sheet_name=self.constraint_sheet_name,
|
|
317
|
-
procedure_name=self.procedure_name,
|
|
318
|
-
procedure_args=self.procedure_args,
|
|
319
|
-
connect_method='new', # subprocess で connect する際は new を強制する
|
|
320
|
-
terminate_excel_when_quit=True, # なので終了時は破棄する
|
|
321
|
-
procedure_timeout=self.procedure_timeout,
|
|
322
|
-
setup_xlsm_path=self.setup_xlsm_path,
|
|
323
|
-
setup_procedure_name=self.setup_procedure_name,
|
|
324
|
-
setup_procedure_args=self.setup_procedure_args,
|
|
325
|
-
teardown_xlsm_path=self.teardown_xlsm_path,
|
|
326
|
-
teardown_procedure_name=self.teardown_procedure_name,
|
|
327
|
-
teardown_procedure_args=self.teardown_procedure_args,
|
|
328
|
-
related_file_paths=self.related_file_paths,
|
|
329
|
-
visible=self.visible,
|
|
330
|
-
interactive=self.interactive,
|
|
331
|
-
display_alerts=self.display_alerts,
|
|
332
|
-
use_named_range=self.use_named_range,
|
|
333
|
-
)
|
|
334
|
-
FEMInterface.__init__(self, **kwargs)
|
|
335
|
-
|
|
336
|
-
def __del__(self):
|
|
337
|
-
pass
|
|
338
|
-
|
|
339
|
-
def _setup_before_parallel(self, client) -> None:
|
|
340
|
-
# メインプロセスで、並列プロセスを開始する前に行う前処理
|
|
341
|
-
|
|
342
|
-
client.upload_file(self.input_xlsm_path, False)
|
|
343
|
-
|
|
344
|
-
if not is_same_path(self.input_xlsm_path, self.output_xlsm_path):
|
|
345
|
-
client.upload_file(self.output_xlsm_path, False)
|
|
346
|
-
|
|
347
|
-
if not is_same_path(self.input_xlsm_path, self.constraint_xlsm_path):
|
|
348
|
-
client.upload_file(self.constraint_xlsm_path, False)
|
|
349
|
-
|
|
350
|
-
if not is_same_path(self.input_xlsm_path, self.setup_xlsm_path):
|
|
351
|
-
client.upload_file(self.setup_xlsm_path, False)
|
|
352
|
-
|
|
353
|
-
if not is_same_path(self.input_xlsm_path, self.teardown_xlsm_path):
|
|
354
|
-
client.upload_file(self.setup_xlsm_path, False)
|
|
355
|
-
|
|
356
|
-
for path in self.related_file_paths:
|
|
357
|
-
client.upload_file(path, False)
|
|
358
|
-
|
|
359
|
-
def _setup_after_parallel(self, *args, **kwargs):
|
|
360
|
-
"""サブプロセス又はメインプロセスのサブスレッドで、最適化を開始する前の前処理"""
|
|
361
|
-
|
|
362
|
-
# kwargs で space_dir が与えられている場合、そちらを使用する
|
|
363
|
-
# メインプロセスで呼ばれることを想定
|
|
364
|
-
if 'space_dir' in kwargs.keys():
|
|
365
|
-
space = kwargs['space_dir']
|
|
366
|
-
if space is not None:
|
|
367
|
-
self.input_xlsm_path = os.path.join(space, os.path.basename(self.input_xlsm_path))
|
|
368
|
-
self.output_xlsm_path = os.path.join(space, os.path.basename(self.output_xlsm_path))
|
|
369
|
-
self.constraint_xlsm_path = os.path.join(space, os.path.basename(self.constraint_xlsm_path))
|
|
370
|
-
self.setup_xlsm_path = os.path.join(space, os.path.basename(self.setup_xlsm_path))
|
|
371
|
-
self.teardown_xlsm_path = os.path.join(space, os.path.basename(self.teardown_xlsm_path))
|
|
372
|
-
self.related_file_paths = [os.path.join(space, os.path.basename(p)) for p in self.related_file_paths]
|
|
373
|
-
|
|
374
|
-
# connect_method が auto でかつ使用中のファイルを開こうとする場合に備えて excel のファイル名を変更
|
|
375
|
-
subprocess_idx = kwargs['opt'].subprocess_idx
|
|
376
|
-
|
|
377
|
-
def proc_path(path, ignore_no_exists):
|
|
378
|
-
exclude_ext, ext = os.path.splitext(path)
|
|
379
|
-
new_path = exclude_ext + f'{subprocess_idx}' + ext
|
|
380
|
-
if os.path.exists(path): # input と output が同じの場合など。input がないのはおかしい
|
|
381
|
-
os.rename(path, new_path)
|
|
382
|
-
elif not ignore_no_exists:
|
|
383
|
-
raise FileNotFoundError(f'{path} が見つかりません。')
|
|
384
|
-
return new_path
|
|
385
|
-
|
|
386
|
-
self.input_xlsm_path = proc_path(self.input_xlsm_path, False)
|
|
387
|
-
self.output_xlsm_path = proc_path(self.output_xlsm_path, True)
|
|
388
|
-
self.constraint_xlsm_path = proc_path(self.constraint_xlsm_path, True)
|
|
389
|
-
self.setup_xlsm_path = proc_path(self.setup_xlsm_path, True)
|
|
390
|
-
self.teardown_xlsm_path = proc_path(self.teardown_xlsm_path, True)
|
|
391
|
-
|
|
392
|
-
# スレッドが変わっているかもしれないので win32com の初期化
|
|
393
|
-
CoInitialize()
|
|
394
|
-
|
|
395
|
-
# 最適化中は femtet の autosave を無効にする
|
|
396
|
-
if self._with_femtet_autosave_setting:
|
|
397
|
-
from pyfemtet._femtet_config_util.autosave import _set_autosave_enabled, _get_autosave_enabled
|
|
398
|
-
self._femtet_autosave_buffer = _get_autosave_enabled()
|
|
399
|
-
_set_autosave_enabled(False)
|
|
400
|
-
|
|
401
|
-
# excel に繋ぐ
|
|
402
|
-
with lock_or_no_lock('connect-excel'):
|
|
403
|
-
self.connect_excel(self.excel_connect_method)
|
|
404
|
-
sleep(1)
|
|
405
|
-
|
|
406
|
-
# load_objective は 1 回目に呼ばれたのが main thread なので
|
|
407
|
-
# subprocess に入った後でもう一度 load objective を行う
|
|
408
|
-
from pyfemtet.opt.optimizer import AbstractOptimizer
|
|
409
|
-
from pyfemtet.opt._femopt_core import Objective, Constraint
|
|
410
|
-
opt: AbstractOptimizer = kwargs['opt']
|
|
411
|
-
obj: Objective
|
|
412
|
-
for obj_name, obj in opt.objectives.items():
|
|
413
|
-
if isinstance(obj.fun, ScapeGoatObjective):
|
|
414
|
-
opt.objectives[obj_name].fun = self.objective_from_excel
|
|
415
|
-
|
|
416
|
-
cns: Constraint
|
|
417
|
-
for cns_name, cns in opt.constraints.items():
|
|
418
|
-
if isinstance(cns.fun, ScapeGoatObjective):
|
|
419
|
-
opt.constraints[cns_name].fun = self.constraint_from_excel
|
|
420
|
-
|
|
421
|
-
# excel の setup 関数を必要なら実行する
|
|
422
|
-
if self.setup_procedure_name is not None:
|
|
423
|
-
with lock_or_no_lock('excel_setup_procedure'):
|
|
424
|
-
try:
|
|
425
|
-
with watch_excel_macro_error(self.excel, timeout=self.procedure_timeout, restore_book=False):
|
|
426
|
-
self.excel.Run(
|
|
427
|
-
f'{self.setup_procedure_name}',
|
|
428
|
-
*self.setup_procedure_args
|
|
429
|
-
)
|
|
430
|
-
|
|
431
|
-
# 再計算
|
|
432
|
-
self.excel.CalculateFull()
|
|
433
|
-
sleep(1)
|
|
434
|
-
|
|
435
|
-
except com_error as e:
|
|
436
|
-
raise RuntimeError(f'Failed to run macro {self.setup_procedure_name}. The original message is: {e}')
|
|
437
|
-
|
|
438
|
-
def connect_excel(self, connect_method):
|
|
439
|
-
|
|
440
|
-
# ===== 新しい excel instance を起動 =====
|
|
441
|
-
# 起動
|
|
442
|
-
if connect_method == 'auto':
|
|
443
|
-
self.excel = Dispatch('Excel.Application')
|
|
444
|
-
else:
|
|
445
|
-
self.excel = DispatchEx('Excel.Application')
|
|
446
|
-
|
|
447
|
-
# FemtetRef を追加する
|
|
448
|
-
self.open_femtet_ref_xla()
|
|
449
|
-
sleep(0.5)
|
|
450
|
-
|
|
451
|
-
# 起動した excel の pid を記憶する
|
|
452
|
-
self._excel_hwnd = self.excel.hWnd
|
|
453
|
-
self._excel_pid = 0
|
|
454
|
-
while self._excel_pid == 0:
|
|
455
|
-
sleep(0.5)
|
|
456
|
-
self._excel_pid = _get_pid(self.excel.hWnd)
|
|
457
|
-
|
|
458
|
-
# 可視性の設定
|
|
459
|
-
self.excel.Visible = self.visible
|
|
460
|
-
self.excel.DisplayAlerts = self.display_alerts
|
|
461
|
-
self.excel.Interactive = self.interactive
|
|
462
|
-
sleep(0.5)
|
|
463
|
-
|
|
464
|
-
# ===== input =====
|
|
465
|
-
# 開く
|
|
466
|
-
self.excel.Workbooks.Open(str(self.input_xlsm_path))
|
|
467
|
-
for wb in self.excel.Workbooks:
|
|
468
|
-
if wb.Name == os.path.basename(self.input_xlsm_path):
|
|
469
|
-
self.wb_input = wb
|
|
470
|
-
break
|
|
471
|
-
else:
|
|
472
|
-
raise RuntimeError(f'Cannot open {self.input_xlsm_path}')
|
|
473
|
-
|
|
474
|
-
# シートを特定する
|
|
475
|
-
for sh in self.wb_input.WorkSheets:
|
|
476
|
-
if sh.Name == self.input_sheet_name:
|
|
477
|
-
self.sh_input = sh
|
|
478
|
-
break
|
|
479
|
-
else:
|
|
480
|
-
raise RuntimeError(f'Sheet {self.input_sheet_name} does not exist in the book {self.wb_input.Name}.')
|
|
481
|
-
|
|
482
|
-
# ===== output =====
|
|
483
|
-
# 開く (output)
|
|
484
|
-
if is_same_path(self.input_xlsm_path, self.output_xlsm_path):
|
|
485
|
-
self.wb_output = self.wb_input
|
|
486
|
-
else:
|
|
487
|
-
self.excel.Workbooks.Open(str(self.output_xlsm_path))
|
|
488
|
-
for wb in self.excel.Workbooks:
|
|
489
|
-
if wb.Name == os.path.basename(self.output_xlsm_path):
|
|
490
|
-
self.wb_output = wb
|
|
491
|
-
break
|
|
492
|
-
else:
|
|
493
|
-
raise RuntimeError(f'Cannot open {self.output_xlsm_path}')
|
|
494
|
-
|
|
495
|
-
# シートを特定する (output)
|
|
496
|
-
for sh in self.wb_output.WorkSheets:
|
|
497
|
-
if sh.Name == self.output_sheet_name:
|
|
498
|
-
self.sh_output = sh
|
|
499
|
-
break
|
|
500
|
-
else:
|
|
501
|
-
raise RuntimeError(f'Sheet {self.output_sheet_name} does not exist in the book {self.wb_output.Name}.')
|
|
502
|
-
|
|
503
|
-
# ===== constraint =====
|
|
504
|
-
# 開く (constraint)
|
|
505
|
-
if is_same_path(self.input_xlsm_path, self.constraint_xlsm_path):
|
|
506
|
-
self.wb_constraint = self.wb_input
|
|
507
|
-
else:
|
|
508
|
-
self.excel.Workbooks.Open(str(self.constraint_xlsm_path))
|
|
509
|
-
for wb in self.excel.Workbooks:
|
|
510
|
-
if wb.Name == os.path.basename(self.constraint_xlsm_path):
|
|
511
|
-
self.wb_constraint = wb
|
|
512
|
-
break
|
|
513
|
-
else:
|
|
514
|
-
raise RuntimeError(f'Cannot open {self.constraint_xlsm_path}')
|
|
515
|
-
|
|
516
|
-
# シートを特定する (constraint)
|
|
517
|
-
for sh in self.wb_constraint.WorkSheets:
|
|
518
|
-
if sh.Name == self.constraint_sheet_name:
|
|
519
|
-
self.sh_constraint = sh
|
|
520
|
-
break
|
|
521
|
-
else:
|
|
522
|
-
raise RuntimeError(
|
|
523
|
-
f'Sheet {self.constraint_sheet_name} does not exist in the book {self.wb_constraint.Name}.')
|
|
524
|
-
|
|
525
|
-
# ===== setup =====
|
|
526
|
-
# 開く (setup)
|
|
527
|
-
if is_same_path(self.input_xlsm_path, self.setup_xlsm_path):
|
|
528
|
-
self.wb_setup = self.wb_input
|
|
529
|
-
else:
|
|
530
|
-
self.excel.Workbooks.Open(self.setup_xlsm_path)
|
|
531
|
-
for wb in self.excel.Workbooks:
|
|
532
|
-
if wb.Name == os.path.basename(self.setup_xlsm_path):
|
|
533
|
-
self.wb_setup = wb
|
|
534
|
-
break
|
|
535
|
-
else:
|
|
536
|
-
raise RuntimeError(f'Cannot open {self.setup_xlsm_path}')
|
|
537
|
-
|
|
538
|
-
# ===== teardown =====
|
|
539
|
-
# 開く (teardown)
|
|
540
|
-
if is_same_path(self.input_xlsm_path, self.teardown_xlsm_path):
|
|
541
|
-
self.wb_teardown = self.wb_input
|
|
542
|
-
else:
|
|
543
|
-
self.excel.Workbooks.Open(self.teardown_xlsm_path)
|
|
544
|
-
for wb in self.excel.Workbooks:
|
|
545
|
-
if wb.Name == os.path.basename(self.teardown_xlsm_path):
|
|
546
|
-
self.wb_teardown = wb
|
|
547
|
-
break
|
|
548
|
-
else:
|
|
549
|
-
raise RuntimeError(f'Cannot open {self.teardown_xlsm_path}')
|
|
550
|
-
|
|
551
|
-
# book に参照設定を追加する
|
|
552
|
-
self.add_femtet_macro_reference(self.wb_input)
|
|
553
|
-
self.add_femtet_macro_reference(self.wb_output)
|
|
554
|
-
self.add_femtet_macro_reference(self.wb_setup)
|
|
555
|
-
self.add_femtet_macro_reference(self.wb_teardown)
|
|
556
|
-
self.add_femtet_macro_reference(self.wb_constraint)
|
|
557
|
-
|
|
558
|
-
def open_femtet_ref_xla(self):
|
|
559
|
-
|
|
560
|
-
# get 64 bit
|
|
561
|
-
xla_file_path = r'C:\Program Files\Microsoft Office\root\Office16\XLSTART\FemtetRef.xla'
|
|
562
|
-
|
|
563
|
-
# if not exist, get 32bit
|
|
564
|
-
if not os.path.exists(xla_file_path):
|
|
565
|
-
xla_file_path = r'C:\Program Files (x86)\Microsoft Office\root\Office16\XLSTART\FemtetRef.xla'
|
|
566
|
-
|
|
567
|
-
# certify
|
|
568
|
-
if not os.path.exists(xla_file_path):
|
|
569
|
-
raise FileNotFoundError(f'{xla_file_path} not found. Please check the "Enable Macros" command was fired.')
|
|
570
|
-
|
|
571
|
-
# self.excel.Workbooks.Add(xla_file_path)
|
|
572
|
-
self.excel.Workbooks.Open(xla_file_path, ReadOnly=True)
|
|
573
|
-
|
|
574
|
-
def add_femtet_macro_reference(self, wb):
|
|
575
|
-
|
|
576
|
-
# search
|
|
577
|
-
ref_file_2 = os.path.abspath(util._get_femtetmacro_dllpath())
|
|
578
|
-
contain_2 = False
|
|
579
|
-
for ref in wb.VBProject.References:
|
|
580
|
-
if ref.Description is not None:
|
|
581
|
-
if ref.Description == 'FemtetMacro': # FemtetMacro
|
|
582
|
-
contain_2 = True
|
|
583
|
-
break
|
|
584
|
-
# add
|
|
585
|
-
if not contain_2:
|
|
586
|
-
wb.VBProject.References.AddFromFile(ref_file_2)
|
|
587
|
-
|
|
588
|
-
def remove_femtet_ref_xla(self, wb):
|
|
589
|
-
# search
|
|
590
|
-
for ref in wb.VBProject.References:
|
|
591
|
-
if ref.Description is not None:
|
|
592
|
-
if ref.Description == 'FemtetMacro': # FemtetMacro
|
|
593
|
-
wb.VBProject.References.Remove(ref)
|
|
594
|
-
|
|
595
|
-
def update_parameter(self, parameters: pd.DataFrame, with_warning=False) -> Optional[List[str]]:
|
|
596
|
-
# params を作成
|
|
597
|
-
params = dict()
|
|
598
|
-
for _, row in parameters.iterrows():
|
|
599
|
-
params[row['name']] = row['value']
|
|
600
|
-
|
|
601
|
-
# excel シートの変数更新
|
|
602
|
-
if self.use_named_range:
|
|
603
|
-
for key, value in params.items():
|
|
604
|
-
try:
|
|
605
|
-
self.sh_input.Range(key).value = value
|
|
606
|
-
except com_error:
|
|
607
|
-
logger.warn('The cell address specification by named range is failed. '
|
|
608
|
-
'The process changes the specification way to table based method.')
|
|
609
|
-
self.use_named_range = False
|
|
610
|
-
break
|
|
611
|
-
|
|
612
|
-
if not self.use_named_range: # else にしないこと
|
|
613
|
-
for name, value in params.items():
|
|
614
|
-
r = 1 + search_r(self.input_xlsm_path, self.input_sheet_name, name)
|
|
615
|
-
c = 1 + search_c(self.input_xlsm_path, self.input_sheet_name, ParseAsParameter.value)
|
|
616
|
-
self.sh_input.Cells(r, c).value = value
|
|
617
|
-
|
|
618
|
-
# 再計算
|
|
619
|
-
self.excel.CalculateFull()
|
|
620
|
-
|
|
621
|
-
def update(self, parameters: pd.DataFrame) -> None:
|
|
622
|
-
self.update_parameter(parameters)
|
|
623
|
-
|
|
624
|
-
# マクロ実行
|
|
625
|
-
if self.procedure_name is not None:
|
|
626
|
-
try:
|
|
627
|
-
with watch_excel_macro_error(self.excel, timeout=self.procedure_timeout):
|
|
628
|
-
self.excel.Run(
|
|
629
|
-
f'{self.procedure_name}',
|
|
630
|
-
*self.procedure_args
|
|
631
|
-
)
|
|
632
|
-
|
|
633
|
-
# 再計算
|
|
634
|
-
self.excel.CalculateFull()
|
|
635
|
-
|
|
636
|
-
except com_error as e:
|
|
637
|
-
raise SolveError(f'Failed to run macro {self.procedure_name}. The original message is: {e}')
|
|
638
|
-
|
|
639
|
-
def quit(self):
|
|
640
|
-
if self.terminate_excel_when_quit:
|
|
641
|
-
|
|
642
|
-
already_terminated = not hasattr(self, 'excel')
|
|
643
|
-
if already_terminated:
|
|
644
|
-
return
|
|
645
|
-
|
|
646
|
-
logger.info(Msg.INFO_TERMINATING_EXCEL)
|
|
647
|
-
|
|
648
|
-
# 参照設定解除の前に終了処理を必要なら実施する
|
|
649
|
-
# excel の setup 関数を必要なら実行する
|
|
650
|
-
if self.teardown_procedure_name is not None:
|
|
651
|
-
with lock_or_no_lock('excel_teardown_procedure'):
|
|
652
|
-
try:
|
|
653
|
-
with watch_excel_macro_error(self.excel, timeout=self.procedure_timeout, restore_book=False):
|
|
654
|
-
self.excel.Run(
|
|
655
|
-
f'{self.teardown_procedure_name}',
|
|
656
|
-
*self.teardown_procedure_args
|
|
657
|
-
)
|
|
658
|
-
|
|
659
|
-
# 再計算
|
|
660
|
-
self.excel.CalculateFull()
|
|
661
|
-
|
|
662
|
-
except com_error as e:
|
|
663
|
-
raise RuntimeError(
|
|
664
|
-
f'Failed to run macro {self.teardown_procedure_args}. The original message is: {e}')
|
|
665
|
-
|
|
666
|
-
# 不具合の原因になる場合があるので参照設定は解除しないこと
|
|
667
|
-
# self.remove_femtet_ref_xla(self.wb_input)
|
|
668
|
-
# self.remove_femtet_ref_xla(self.wb_output)
|
|
669
|
-
# self.remove_femtet_ref_xla(self.wb_constraint)
|
|
670
|
-
# self.remove_femtet_ref_xla(self.wb_setup)
|
|
671
|
-
# self.remove_femtet_ref_xla(self.wb_teardown)
|
|
672
|
-
|
|
673
|
-
# シートの COM オブジェクト変数を削除する
|
|
674
|
-
del self.sh_input
|
|
675
|
-
del self.sh_output
|
|
676
|
-
del self.sh_constraint
|
|
677
|
-
|
|
678
|
-
# workbook を閉じる
|
|
679
|
-
with watch_excel_macro_error(self.excel, timeout=10, restore_book=False):
|
|
680
|
-
self.wb_input.Close(SaveChanges := False)
|
|
681
|
-
|
|
682
|
-
if not is_same_path(self.input_xlsm_path, self.output_xlsm_path):
|
|
683
|
-
with watch_excel_macro_error(self.excel, timeout=10, restore_book=False):
|
|
684
|
-
self.wb_output.Close(SaveChanges := False)
|
|
685
|
-
|
|
686
|
-
if not is_same_path(self.input_xlsm_path, self.constraint_xlsm_path):
|
|
687
|
-
with watch_excel_macro_error(self.excel, timeout=10, restore_book=False):
|
|
688
|
-
self.wb_constraint.Close(SaveChanges := False)
|
|
689
|
-
|
|
690
|
-
if not is_same_path(self.input_xlsm_path, self.setup_xlsm_path):
|
|
691
|
-
with watch_excel_macro_error(self.excel, timeout=10, restore_book=False):
|
|
692
|
-
self.wb_setup.Close(SaveChanges := False)
|
|
693
|
-
|
|
694
|
-
if not is_same_path(self.input_xlsm_path, self.teardown_xlsm_path):
|
|
695
|
-
with watch_excel_macro_error(self.excel, timeout=10, restore_book=False):
|
|
696
|
-
self.wb_teardown.Close(SaveChanges := False)
|
|
697
|
-
|
|
698
|
-
del self.wb_input
|
|
699
|
-
del self.wb_output
|
|
700
|
-
del self.wb_constraint
|
|
701
|
-
del self.wb_setup
|
|
702
|
-
del self.wb_teardown
|
|
703
|
-
|
|
704
|
-
# excel の終了
|
|
705
|
-
with watch_excel_macro_error(self.excel, timeout=10, restore_book=False):
|
|
706
|
-
self.excel.Quit()
|
|
707
|
-
del self.excel
|
|
708
|
-
|
|
709
|
-
# ここで Excel のプロセスが残らず落ちる
|
|
710
|
-
gc.collect()
|
|
711
|
-
logger.info(Msg.INFO_TERMINATED_EXCEL)
|
|
712
|
-
|
|
713
|
-
if self._with_femtet_autosave_setting:
|
|
714
|
-
from pyfemtet._femtet_config_util.autosave import _set_autosave_enabled
|
|
715
|
-
logger.info(Msg.INFO_RESTORING_FEMTET_AUTOSAVE)
|
|
716
|
-
_set_autosave_enabled(self._femtet_autosave_buffer)
|
|
717
|
-
|
|
718
|
-
# 直接アクセスしてもよいが、ユーザーに易しい名前にするためだけのプロパティ
|
|
719
|
-
@property
|
|
720
|
-
def output_sheet(self) -> CDispatch:
|
|
721
|
-
return self.sh_output
|
|
722
|
-
|
|
723
|
-
@property
|
|
724
|
-
def input_sheet(self) -> CDispatch:
|
|
725
|
-
return self.sh_input
|
|
726
|
-
|
|
727
|
-
@property
|
|
728
|
-
def output_workbook(self) -> CDispatch:
|
|
729
|
-
return self.wb_output
|
|
730
|
-
|
|
731
|
-
@property
|
|
732
|
-
def input_workbook(self) -> CDispatch:
|
|
733
|
-
return self.wb_input
|
|
734
|
-
|
|
735
|
-
def load_parameter(self, opt, raise_if_no_keyword=True) -> None:
|
|
736
|
-
from pyfemtet.opt.optimizer import AbstractOptimizer, logger
|
|
737
|
-
opt: AbstractOptimizer
|
|
738
|
-
|
|
739
|
-
df = ParseAsParameter.parse(
|
|
740
|
-
self.input_xlsm_path,
|
|
741
|
-
self.input_sheet_name,
|
|
742
|
-
raise_if_no_keyword,
|
|
743
|
-
)
|
|
744
|
-
|
|
745
|
-
for i, row in df.iterrows():
|
|
746
|
-
|
|
747
|
-
# use(optional)
|
|
748
|
-
use = True
|
|
749
|
-
if ParseAsParameter.use in df.columns:
|
|
750
|
-
_use = row[ParseAsParameter.use]
|
|
751
|
-
use = False if is_cell_value_empty(_use) else bool(_use) # bool or NaN
|
|
752
|
-
|
|
753
|
-
# name
|
|
754
|
-
name = str(row[ParseAsParameter.name])
|
|
755
|
-
|
|
756
|
-
# if the variable is already added by
|
|
757
|
-
# add_parameter or add_expression,
|
|
758
|
-
# use it.
|
|
759
|
-
if not self.force_override_when_load:
|
|
760
|
-
if name in opt.variables.get_variables():
|
|
761
|
-
continue
|
|
762
|
-
|
|
763
|
-
# value
|
|
764
|
-
value = float(row[ParseAsParameter.value])
|
|
765
|
-
|
|
766
|
-
# lb (optional)
|
|
767
|
-
lb = None
|
|
768
|
-
if ParseAsParameter.lb in df.columns:
|
|
769
|
-
lb = row[ParseAsParameter.lb]
|
|
770
|
-
lb = None if is_cell_value_empty(lb) else float(lb)
|
|
771
|
-
|
|
772
|
-
# ub (optional)
|
|
773
|
-
ub = None
|
|
774
|
-
if ParseAsParameter.ub in df.columns:
|
|
775
|
-
ub = row[ParseAsParameter.ub]
|
|
776
|
-
ub = None if is_cell_value_empty(ub) else float(ub)
|
|
777
|
-
|
|
778
|
-
# step (optional)
|
|
779
|
-
step = None
|
|
780
|
-
if ParseAsParameter.step in df.columns:
|
|
781
|
-
step = row[ParseAsParameter.step]
|
|
782
|
-
step = None if is_cell_value_empty(step) else float(step)
|
|
783
|
-
|
|
784
|
-
if use:
|
|
785
|
-
prm = Parameter(
|
|
786
|
-
name=name,
|
|
787
|
-
value=value,
|
|
788
|
-
lower_bound=lb,
|
|
789
|
-
upper_bound=ub,
|
|
790
|
-
step=step,
|
|
791
|
-
pass_to_fem=True,
|
|
792
|
-
properties=None,
|
|
793
|
-
)
|
|
794
|
-
opt.variables.add_parameter(prm)
|
|
795
|
-
|
|
796
|
-
else:
|
|
797
|
-
# noinspection PyTypeChecker
|
|
798
|
-
fixed_prm = Expression(
|
|
799
|
-
name=name,
|
|
800
|
-
fun=lambda: value,
|
|
801
|
-
value=None,
|
|
802
|
-
pass_to_fem=True,
|
|
803
|
-
properties=dict(
|
|
804
|
-
lower_bound=lb,
|
|
805
|
-
upper_bound=ub,
|
|
806
|
-
),
|
|
807
|
-
kwargs=dict(),
|
|
808
|
-
)
|
|
809
|
-
opt.variables.add_expression(fixed_prm)
|
|
810
|
-
|
|
811
|
-
def load_objective(self, opt, raise_if_no_keyword=True):
|
|
812
|
-
from pyfemtet.opt.optimizer import AbstractOptimizer
|
|
813
|
-
from pyfemtet.opt._femopt_core import Objective
|
|
814
|
-
opt: AbstractOptimizer
|
|
815
|
-
|
|
816
|
-
df = ParseAsObjective.parse(
|
|
817
|
-
self.output_xlsm_path,
|
|
818
|
-
self.output_sheet_name,
|
|
819
|
-
raise_if_no_keyword,
|
|
820
|
-
)
|
|
821
|
-
|
|
822
|
-
for i, row in df.iterrows():
|
|
823
|
-
|
|
824
|
-
# use(optional)
|
|
825
|
-
use = True
|
|
826
|
-
if ParseAsObjective.use in df.columns:
|
|
827
|
-
_use = row[ParseAsObjective.use]
|
|
828
|
-
use = False if is_cell_value_empty(_use) else bool(_use) # bool or NaN
|
|
829
|
-
|
|
830
|
-
# name
|
|
831
|
-
name = str(row[ParseAsObjective.name])
|
|
832
|
-
|
|
833
|
-
# if the objective is already added by
|
|
834
|
-
# add_objective, use it.
|
|
835
|
-
if not self.force_override_when_load:
|
|
836
|
-
if name in opt.objectives.keys():
|
|
837
|
-
continue
|
|
838
|
-
|
|
839
|
-
# direction
|
|
840
|
-
direction = row[ParseAsObjective.direction]
|
|
841
|
-
assert not is_cell_value_empty(direction), 'direction is empty.'
|
|
842
|
-
try:
|
|
843
|
-
direction = float(direction)
|
|
844
|
-
except ValueError:
|
|
845
|
-
direction = str(direction).lower()
|
|
846
|
-
assert direction in ['minimize', 'maximize']
|
|
847
|
-
|
|
848
|
-
if use:
|
|
849
|
-
# objective を作る
|
|
850
|
-
opt.objectives[name] = Objective(
|
|
851
|
-
fun=ScapeGoatObjective(),
|
|
852
|
-
name=name,
|
|
853
|
-
direction=direction,
|
|
854
|
-
args=(name,),
|
|
855
|
-
kwargs=dict(),
|
|
856
|
-
)
|
|
857
|
-
|
|
858
|
-
def load_constraint(self, opt, raise_if_no_keyword=False):
|
|
859
|
-
from pyfemtet.opt.optimizer import AbstractOptimizer
|
|
860
|
-
from pyfemtet.opt._femopt_core import Constraint
|
|
861
|
-
opt: AbstractOptimizer
|
|
862
|
-
|
|
863
|
-
# constraint は optional であるが
|
|
864
|
-
# __init__ で input_sheet_name を入れられるので
|
|
865
|
-
# ここで constraint が実際に与えられているか判断する
|
|
866
|
-
df = ParseAsConstraint.parse(
|
|
867
|
-
self.constraint_xlsm_path,
|
|
868
|
-
self.constraint_sheet_name,
|
|
869
|
-
raise_if_no_keyword=raise_if_no_keyword,
|
|
870
|
-
)
|
|
871
|
-
|
|
872
|
-
for i, row in df.iterrows():
|
|
873
|
-
|
|
874
|
-
# use(optional)
|
|
875
|
-
use = True
|
|
876
|
-
if ParseAsConstraint.use in df.columns:
|
|
877
|
-
_use = row[ParseAsConstraint.use]
|
|
878
|
-
use = False if is_cell_value_empty(_use) else bool(_use) # bool or NaN
|
|
879
|
-
|
|
880
|
-
# name
|
|
881
|
-
name = str(row[ParseAsConstraint.name])
|
|
882
|
-
|
|
883
|
-
# if the constraint is already added by
|
|
884
|
-
# add_constraint, use it.
|
|
885
|
-
if not self.force_override_when_load:
|
|
886
|
-
if name in opt.constraints.keys():
|
|
887
|
-
continue
|
|
888
|
-
|
|
889
|
-
# lb (optional)
|
|
890
|
-
lb = None
|
|
891
|
-
if ParseAsConstraint.lb in df.columns:
|
|
892
|
-
lb = row[ParseAsConstraint.lb]
|
|
893
|
-
lb = None if is_cell_value_empty(lb) else float(lb)
|
|
894
|
-
|
|
895
|
-
# ub (optional)
|
|
896
|
-
ub = None
|
|
897
|
-
if ParseAsConstraint.ub in df.columns:
|
|
898
|
-
ub = row[ParseAsConstraint.ub]
|
|
899
|
-
ub = None if is_cell_value_empty(ub) else float(ub)
|
|
900
|
-
|
|
901
|
-
# strict (optional)
|
|
902
|
-
strict = True
|
|
903
|
-
if ParseAsConstraint.strict in df.columns:
|
|
904
|
-
_strict = row[ParseAsConstraint.strict]
|
|
905
|
-
strict = True if is_cell_value_empty(_strict) else bool(_strict) # bool or NaN
|
|
906
|
-
|
|
907
|
-
# using_fem (optional)
|
|
908
|
-
calc_before_solve = True
|
|
909
|
-
if ParseAsConstraint.calc_before_solve in df.columns:
|
|
910
|
-
_calc_before_solve = row[ParseAsConstraint.calc_before_solve]
|
|
911
|
-
calc_before_solve = True if is_cell_value_empty(_calc_before_solve) else bool(
|
|
912
|
-
_calc_before_solve) # bool or NaN
|
|
913
|
-
|
|
914
|
-
if use:
|
|
915
|
-
# constraint を作る
|
|
916
|
-
opt.constraints[name] = Constraint(
|
|
917
|
-
fun=ScapeGoatObjective(),
|
|
918
|
-
name=name,
|
|
919
|
-
lb=lb,
|
|
920
|
-
ub=ub,
|
|
921
|
-
strict=strict,
|
|
922
|
-
args=(name,),
|
|
923
|
-
kwargs=dict(),
|
|
924
|
-
using_fem=not calc_before_solve,
|
|
925
|
-
)
|
|
926
|
-
|
|
927
|
-
# TODO: femopt_core.Function の仕様を変えたらここも変える
|
|
928
|
-
def objective_from_excel(self, name: str):
|
|
929
|
-
r = 1 + search_r(self.output_xlsm_path, self.output_sheet_name, name)
|
|
930
|
-
c = 1 + search_c(self.output_xlsm_path, self.output_sheet_name, ParseAsObjective.value)
|
|
931
|
-
v = self.sh_output.Cells(r, c).value
|
|
932
|
-
return float(v)
|
|
933
|
-
|
|
934
|
-
def constraint_from_excel(self, name: str):
|
|
935
|
-
r = 1 + search_r(self.constraint_xlsm_path, self.constraint_sheet_name, name)
|
|
936
|
-
c = 1 + search_c(self.constraint_xlsm_path, self.constraint_sheet_name, ParseAsConstraint.value)
|
|
937
|
-
v = self.sh_constraint.Cells(r, c).value
|
|
938
|
-
return float(v)
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
def wait_femtet():
|
|
942
|
-
Femtet = Dispatch('FemtetMacro.Femtet')
|
|
943
|
-
while Femtet.hWnd <= 0:
|
|
944
|
-
sleep(1)
|
|
945
|
-
Femtet = Dispatch('FemtetMacro.Femtet')
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
def _terminate_femtet(femtet_pid_):
|
|
949
|
-
CoInitialize()
|
|
950
|
-
Femtet, caught_pid = dispatch_specific_femtet(femtet_pid_)
|
|
951
|
-
_exit_or_force_terminate(timeout=3, Femtet=Femtet, force=True)
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
# main thread で作成した excel への参照を含む関数を
|
|
955
|
-
# 直接 thread や process に渡すと機能しない
|
|
956
|
-
class ScapeGoatObjective:
|
|
957
|
-
# def __call__(self, *args, fem: ExcelInterface or None = None, **kwargs):
|
|
958
|
-
# fem.objective_from_excel(*args, **kwargs)
|
|
959
|
-
|
|
960
|
-
@property
|
|
961
|
-
def __globals__(self):
|
|
962
|
-
return tuple()
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
def is_same_path(p1, p2):
|
|
966
|
-
_p1 = os.path.abspath(p1).lower()
|
|
967
|
-
_p2 = os.path.abspath(p2).lower()
|
|
968
|
-
return _p1 == _p2
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
def is_cell_value_empty(cell_value):
|
|
972
|
-
if isinstance(cell_value, str):
|
|
973
|
-
return cell_value == ''
|
|
974
|
-
elif isinstance(cell_value, int) \
|
|
975
|
-
or isinstance(cell_value, float):
|
|
976
|
-
return np.isnan(cell_value)
|
|
977
|
-
elif cell_value is None:
|
|
978
|
-
return True
|
|
979
|
-
else:
|
|
980
|
-
return False
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
if __name__ == '__main__':
|
|
984
|
-
ExcelInterface(..., ...)
|