pyfemtet 1.1.0__py3-none-any.whl → 1.1.1__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/_util/df_util.py CHANGED
@@ -1,3 +1,4 @@
1
+ from typing import TypeAlias, Literal
1
2
  from math import isnan
2
3
  import pandas as pd
3
4
 
@@ -8,7 +9,10 @@ __all__ = [
8
9
  ]
9
10
 
10
11
 
11
- def get_index(df, equality_filters):
12
+ _Method: TypeAlias = Literal['all', 'any', 'all-exclude']
13
+
14
+
15
+ def get_index(df, equality_filters, method: _Method = 'all'):
12
16
  # 値渡しに変換
13
17
  equality_filters = equality_filters.copy()
14
18
 
@@ -24,17 +28,25 @@ def get_index(df, equality_filters):
24
28
 
25
29
  # na 以外の比較
26
30
  # noinspection PyUnresolvedReferences
27
- out: pd.Series = (df[list(equality_filters.keys())] == pd.Series(equality_filters)).all(axis=1)
31
+ if 'all' in method.lower():
32
+ out: pd.Series = (df[list(equality_filters.keys())] == pd.Series(equality_filters)).all(axis=1)
33
+ elif 'any' in method.lower():
34
+ out: pd.Series = (df[list(equality_filters.keys())] == pd.Series(equality_filters)).any(axis=1)
35
+ else:
36
+ raise NotImplementedError(f'Unknown method: {method}')
28
37
 
29
38
  # na との比較
30
39
  for key in want_na_keys:
31
40
  out = out & df[key].isna()
32
41
 
42
+ if 'exclude' in method:
43
+ out = ~out
44
+
33
45
  return out
34
46
 
35
47
 
36
- def get_partial_df(df: pd.DataFrame, equality_filters: dict):
37
- return df[get_index(df, equality_filters)]
48
+ def get_partial_df(df: pd.DataFrame, equality_filters: dict, method: _Method = 'all'):
49
+ return df[get_index(df, equality_filters, method=method)]
38
50
 
39
51
 
40
52
  def apply_partial_df(df: pd.DataFrame, partial_df: pd.DataFrame, equality_filters: dict):
@@ -17,8 +17,9 @@ from pyfemtet.opt.prediction._model import *
17
17
  from pyfemtet.opt.prediction._helper import *
18
18
  from pyfemtet.opt.visualization.plotter.pm_graph_creator import plot2d, plot3d
19
19
  from pyfemtet.opt.visualization.history_viewer._base_application import AbstractPage, logger
20
- from pyfemtet.opt.visualization.history_viewer._helper import has_full_bound
20
+ from pyfemtet.opt.visualization.history_viewer._helper import has_full_bound, control_visibility_by_style
21
21
  from pyfemtet._i18n import Msg, _
22
+ from pyfemtet._util.df_util import *
22
23
 
23
24
 
24
25
  __all__ = [
@@ -144,6 +145,22 @@ class PredictionModelGraph(AbstractPage):
144
145
  value=[],
145
146
  )
146
147
 
148
+ # consider sub sampling or not
149
+ self.SUB_SAMPLING_CHECKED = 'sub_sampling_checked'
150
+ self.switch_about_sub_sampling = dbc.Checklist(
151
+ options=[
152
+ dict(
153
+ label=_('Consider sub sampling when the model re-calc', 'モデル再計算時にサブサンプリングのみを考慮'),
154
+ value=self.SUB_SAMPLING_CHECKED, # チェックされたら value (list) の要素に "sub_sampling_checked" が入る
155
+ )
156
+ ],
157
+ switch=True,
158
+ value=[], # 初期状態ではチェックされている値なし
159
+ style=control_visibility_by_style(
160
+ visible=False, current_style={}
161
+ ),
162
+ )
163
+
147
164
  # alert region subpage
148
165
  self.alert_region: AlertRegion = AlertRegion()
149
166
  self.add_subpage(self.alert_region)
@@ -200,7 +217,10 @@ class PredictionModelGraph(AbstractPage):
200
217
  self.command_manager
201
218
  ],
202
219
  direction='horizontal', gap=2),
203
- self.switch_3d,
220
+ dbc.Row((
221
+ dbc.Col(self.switch_3d),
222
+ dbc.Col(self.switch_about_sub_sampling)
223
+ )),
204
224
  *dropdown_rows,
205
225
  self.slider_container,
206
226
  self.slider_stack_data,
@@ -276,9 +296,10 @@ class PredictionModelGraph(AbstractPage):
276
296
  Output(self.command_manager, self.command_manager_prop, allow_duplicate=True),
277
297
  Output(self.graph, 'figure', allow_duplicate=True), # for show spinner during calculation
278
298
  Input(self.command_manager, self.command_manager_prop),
299
+ State(self.switch_about_sub_sampling, 'value'),
279
300
  prevent_initial_call=True,
280
301
  )
281
- def recalculate_rsm(command):
302
+ def recalculate_rsm(command, is_sub_sampling):
282
303
  # just in case
283
304
  if callback_context.triggered_id is None:
284
305
  raise PreventUpdate
@@ -295,12 +316,29 @@ class PredictionModelGraph(AbstractPage):
295
316
  if len(self.application.get_df()) == 0:
296
317
  return self.CommandState.redraw.value, no_update # error handling in the next `redraw_graph()` callback
297
318
 
319
+ # switch the consideration of sub_sampling
320
+ df = self.application.get_df()
321
+ equality_filters = {'sub_sampling': float('nan')}
322
+
323
+ if self.SUB_SAMPLING_CHECKED in is_sub_sampling:
324
+ df = get_partial_df(
325
+ df,
326
+ equality_filters=equality_filters,
327
+ method='all-exclude', # nan 以外 = sampling のみ
328
+ )
329
+ else:
330
+ df = get_partial_df(
331
+ df,
332
+ equality_filters=equality_filters,
333
+ method='all', # nan のみ全て
334
+ )
335
+
298
336
  # create model
299
337
  model = SingleTaskGPModel()
300
338
  self.pyfemtet_model.update_model(model)
301
339
  self.pyfemtet_model.fit(
302
340
  self.application.history,
303
- self.application.get_df(),
341
+ df,
304
342
  **{}
305
343
  )
306
344
 
@@ -475,10 +513,12 @@ class PredictionModelGraph(AbstractPage):
475
513
  Output(self.axis3_obj_dropdown, 'children'),
476
514
  Output(self.slider_container, 'children'),
477
515
  Output(self.slider_stack_data, self.slider_stack_data_prop, allow_duplicate=True),
516
+ Output(self.switch_about_sub_sampling, 'style'),
478
517
  Input(self.location, self.location.Prop.pathname),
518
+ State(self.switch_about_sub_sampling, 'style'),
479
519
  prevent_initial_call=True,
480
520
  )
481
- def setup_dropdown_and_sliders(*_):
521
+ def setup_dropdown_and_sliders(_, current_style):
482
522
  # just in case
483
523
  if callback_context.triggered_id is None:
484
524
  raise PreventUpdate
@@ -578,7 +618,20 @@ class PredictionModelGraph(AbstractPage):
578
618
  )
579
619
  sliders.append(stack)
580
620
 
581
- return axis1_dropdown_items, axis2_dropdown_items, axis3_dropdown_items, sliders, slider_values
621
+ # ひとつでも sub sampling があれば visible=True
622
+ visible = (~df['sub_sampling'].isna()).any()
623
+ switch_style = control_visibility_by_style(
624
+ visible, current_style
625
+ )
626
+
627
+ return (
628
+ axis1_dropdown_items,
629
+ axis2_dropdown_items,
630
+ axis3_dropdown_items,
631
+ sliders,
632
+ slider_values,
633
+ switch_style,
634
+ )
582
635
 
583
636
  # ===== control dropdown and slider visibility =====
584
637
  @app.callback(
@@ -26,3 +26,16 @@ def has_full_bound(history: History, prm_name, df: pd.DataFrame = None) -> bool:
26
26
  return False
27
27
 
28
28
  return True
29
+
30
+
31
+ def control_visibility_by_style(visible: bool, current_style: dict):
32
+
33
+ visibility = 'inline' if visible else 'none'
34
+ part = {'display': visibility}
35
+
36
+ if current_style is None:
37
+ return part
38
+
39
+ else:
40
+ current_style.update(part)
41
+ return current_style
@@ -14,6 +14,7 @@ from pyfemtet.opt.visualization.history_viewer._base_application import *
14
14
  from pyfemtet.opt.visualization.history_viewer._complex_components.main_graph import *
15
15
  from pyfemtet.opt.visualization.history_viewer._complex_components.control_femtet import *
16
16
  from pyfemtet.opt.visualization.history_viewer._complex_components.alert_region import *
17
+ from pyfemtet.opt.visualization.history_viewer._helper import control_visibility_by_style
17
18
 
18
19
  from pyfemtet._i18n import Msg, _
19
20
 
@@ -752,13 +753,4 @@ class Tutorial(AbstractPage):
752
753
 
753
754
  @staticmethod
754
755
  def control_visibility_by_style(visible: bool, current_style: dict):
755
-
756
- visibility = 'inline' if visible else 'none'
757
- part = {'display': visibility}
758
-
759
- if current_style is None:
760
- return part
761
-
762
- else:
763
- current_style.update(part)
764
- return current_style
756
+ return control_visibility_by_style(visible, current_style)
@@ -6,6 +6,7 @@ from pyfemtet._util.df_util import *
6
6
  from pyfemtet.opt.history import *
7
7
  from pyfemtet.opt.prediction._model import *
8
8
  from pyfemtet.opt.prediction._helper import *
9
+ from pyfemtet.opt.problem.problem import MAIN_FIDELITY_NAME
9
10
 
10
11
 
11
12
  __all__ = [
@@ -217,6 +218,32 @@ def _plot(
217
218
  name='trial',
218
219
  ))
219
220
 
221
+ # sub sampling
222
+ buff = get_partial_df(
223
+ df,
224
+ {'sub_fidelity_name': MAIN_FIDELITY_NAME},
225
+ )
226
+ df_main_sub_sampling = get_partial_df(
227
+ buff,
228
+ {'sub_sampling': float('nan')},
229
+ method='all-exclude',
230
+ )
231
+ fig.add_trace(go.Scatter3d(
232
+ x=df_main_sub_sampling[prm_name1],
233
+ y=df_main_sub_sampling[prm_name2],
234
+ z=df_main_sub_sampling[obj_name],
235
+ mode='markers',
236
+ marker=dict(
237
+ size=3,
238
+ line=dict(
239
+ width=1,
240
+ color='gray',
241
+ ),
242
+ symbol='square-open'
243
+ ),
244
+ name='trial (sub sampling)',
245
+ ))
246
+
220
247
  # sub fidelity
221
248
  for (
222
249
  sub_fidelity_name,
@@ -228,7 +255,7 @@ def _plot(
228
255
  # px.colors.qualitative.G10[::-1]
229
256
  ):
230
257
 
231
- if sub_fidelity_name == MAIN_FILTER:
258
+ if sub_fidelity_name == MAIN_FIDELITY_NAME:
232
259
  continue
233
260
  df_sub = get_partial_df(df, equality_filters=dict(sub_fidelity_name=sub_fidelity_name))
234
261
 
@@ -239,7 +266,7 @@ def _plot(
239
266
  size=3,
240
267
  line=dict(
241
268
  width=1,
242
- color='white',
269
+ color='green',
243
270
  ),
244
271
  symbol='square-open', # TODO: sequence 化
245
272
  ),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pyfemtet
3
- Version: 1.1.0
3
+ Version: 1.1.1
4
4
  Summary: Design parameter optimization using Femtet.
5
5
  License: MIT
6
6
  Author: pyfemtet
@@ -11,7 +11,7 @@ pyfemtet/_i18n/messages.py,sha256=mzTARnpZPZ-Pmcq8RdOyy5a4XGCCSxwxuoHjN_HJ0TM,17
11
11
  pyfemtet/_util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  pyfemtet/_util/closing.py,sha256=JPcgHDbW249YF20bMOX6UX-LquWoCWA14KhX-qFouR4,502
13
13
  pyfemtet/_util/dask_util.py,sha256=Wm_1p_LR1yhhZNaGgazf-yQ-eialLfmqtgBjxha6qWk,2159
14
- pyfemtet/_util/df_util.py,sha256=V38c5avzKEvLiSEDLpdo6eTXxDgasCXn3RB1IUF-bNU,1431
14
+ pyfemtet/_util/df_util.py,sha256=UVJZcTqVe_98aGAqF9Sp4b6BC5c_c3ADRsZ2RUJcN0Y,1889
15
15
  pyfemtet/_util/excel_macro_util.py,sha256=pUCpENpM1q6AbC7wH7rMXwnQ7nIFnabQ4xlbsli9VzM,8028
16
16
  pyfemtet/_util/excel_parse_util.py,sha256=k8Y5EI9r0txwkieKUzlZqQ93b-9SMXldNIfq5ksWg28,5525
17
17
  pyfemtet/_util/femtet_access_inspection.py,sha256=91E-7wzQTZum1UIsccW26717GnTM2jxf3HeOOR7-lv0,3999
@@ -97,9 +97,9 @@ pyfemtet/opt/visualization/history_viewer/_complex_components/alert_region.py,sh
97
97
  pyfemtet/opt/visualization/history_viewer/_complex_components/control_femtet.py,sha256=FQUR9bYtMoj_3bvHXfzAhYMoYpbIWcDP8j7M2EwnYQM,6253
98
98
  pyfemtet/opt/visualization/history_viewer/_complex_components/detail_graphs.py,sha256=friaHAJOG5BEUAkoy7ukpO-vUhJ0DlJFwMB2ayNJ4so,19134
99
99
  pyfemtet/opt/visualization/history_viewer/_complex_components/main_graph.py,sha256=dMphOHbSV2R3oQvPlIQj7GwtV0phPiBwKniblxTAxMY,25978
100
- pyfemtet/opt/visualization/history_viewer/_complex_components/pm_graph.py,sha256=WtdEogjDl-RxXzw53_N_gyrFHHl6KaJ1ieKBMrFcpcs,27725
100
+ pyfemtet/opt/visualization/history_viewer/_complex_components/pm_graph.py,sha256=-fihXFDe_RdUTjaPepiVMWM4zVYAf6oD8QrPVdvA_wA,29840
101
101
  pyfemtet/opt/visualization/history_viewer/_detail_page.py,sha256=2LdCFSCcxZkAH6QMa9q6QX-KLYhVrRf-iTh7jNPrnnA,3406
102
- pyfemtet/opt/visualization/history_viewer/_helper.py,sha256=b3Tlo2_qAdbe7Hqs520BpVHjYy6jygCn1DFR5B0Ru1M,727
102
+ pyfemtet/opt/visualization/history_viewer/_helper.py,sha256=276488eouQEo-haK4XXCVM1Vy8_28Vyp5g0l7zt4Sfc,1009
103
103
  pyfemtet/opt/visualization/history_viewer/_process_monitor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
104
104
  pyfemtet/opt/visualization/history_viewer/_process_monitor/_application.py,sha256=sP2oOIy5u4gtyMq428NKBFECsYxHCJthMFHJkqyWZcI,5956
105
105
  pyfemtet/opt/visualization/history_viewer/_process_monitor/_pages.py,sha256=v6ytmJgtBql0pKn7O0UAeyX0P_V_nFX1KW4esBzHdJg,10921
@@ -112,7 +112,7 @@ pyfemtet/opt/visualization/history_viewer/result_viewer/.gitignore,sha256=ryvb4a
112
112
  pyfemtet/opt/visualization/history_viewer/result_viewer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
113
113
  pyfemtet/opt/visualization/history_viewer/result_viewer/__main__.py,sha256=5bskvqYMxmgktfoakI19zgy08XlKOkuVhID6MNZNIyE,154
114
114
  pyfemtet/opt/visualization/history_viewer/result_viewer/_application.py,sha256=iq9Eyj0G7vtz-SGmkr8n4tVjmyARz5_qKd3UGZH7gTQ,1764
115
- pyfemtet/opt/visualization/history_viewer/result_viewer/_pages.py,sha256=bJIq-Spp9C7EkUH7re0HqWPLdvwXYf3sX30sVshRrKE,33352
115
+ pyfemtet/opt/visualization/history_viewer/result_viewer/_pages.py,sha256=vUZXg1uKPyGeXpnz_uUOFfIjWlRObYKWa7cutGy7RPc,33270
116
116
  pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08.csv,sha256=O-6cGVjr4xMYgpkGUDyfm02ccE42cE9DyLl7ioeGbL0,3319
117
117
  pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08.db,sha256=4WWrvxgWAFdL36Kk7XxK02RvZbOgGkVMerrRfoF_oJw,122880
118
118
  pyfemtet/opt/visualization/history_viewer/result_viewer/tutorial_files/tutorial_gau_ex08_parametric.Results/ex8.jpg,sha256=yC5EAxhDCB2Vm0eKH1Ufjp7vdt1GPQWr9Y3rlay-U2E,49141
@@ -168,12 +168,12 @@ pyfemtet/opt/visualization/plotter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQe
168
168
  pyfemtet/opt/visualization/plotter/contour_creator.py,sha256=bvGGWNBLZawHq0fAIHfZOUAXw0f9GTlNROiJThoXZ2A,3043
169
169
  pyfemtet/opt/visualization/plotter/main_figure_creator.py,sha256=a_HK6EUruQBncI8vEIZnrDorPr2EdPICLKU4Er97WtQ,17761
170
170
  pyfemtet/opt/visualization/plotter/parallel_plot_creator.py,sha256=VRhT0CUG1mCHDoVO8e6LR_-FiD0QB3GsB95016iXmYc,802
171
- pyfemtet/opt/visualization/plotter/pm_graph_creator.py,sha256=V26HIbPF1jEVAZ9r1Izsi2zcVz84l4RhZUTJV9jPqp8,11019
171
+ pyfemtet/opt/visualization/plotter/pm_graph_creator.py,sha256=7EwmoJlnHwDrpw65NchiA63FIjgGTLq6vTcpTzrSnJo,11841
172
172
  pyfemtet/opt/wat_ex14_parametric_jp.femprj,sha256=dMwQMt6yok_PbZLyxPYdmg5wJQwgQDZ4RhS76zdGLGk,177944
173
173
  pyfemtet/opt/worker_status.py,sha256=xSVW9lcw5jzYBwnmlVzk-1zCCyvmXVOH6EoRjqVbE9M,3605
174
- pyfemtet-1.1.0.dist-info/LICENSE,sha256=LWUL5LlMGjSRTvsalS8_fFuwS4VMw18fJSNWFwDK8pc,1060
175
- pyfemtet-1.1.0.dist-info/LICENSE_THIRD_PARTY.txt,sha256=8_9-cgzTpmeuCqItPZb9-lyAZcH2Qp9sZTU_hYuOZIQ,191
176
- pyfemtet-1.1.0.dist-info/METADATA,sha256=U-_Mn8IbOEgQjZ6IGa85S6pccNEW6Mq_t8XtkW2svVY,3503
177
- pyfemtet-1.1.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
178
- pyfemtet-1.1.0.dist-info/entry_points.txt,sha256=Tsb_l_8Z6pyyq2tRfuKiwfJUV3nq_cHoLS61foALtsg,134
179
- pyfemtet-1.1.0.dist-info/RECORD,,
174
+ pyfemtet-1.1.1.dist-info/LICENSE,sha256=LWUL5LlMGjSRTvsalS8_fFuwS4VMw18fJSNWFwDK8pc,1060
175
+ pyfemtet-1.1.1.dist-info/LICENSE_THIRD_PARTY.txt,sha256=8_9-cgzTpmeuCqItPZb9-lyAZcH2Qp9sZTU_hYuOZIQ,191
176
+ pyfemtet-1.1.1.dist-info/METADATA,sha256=S8YJfsDcQoxdsbLRUw8e_oaz8NXCc76t4dXpi_kpc58,3503
177
+ pyfemtet-1.1.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
178
+ pyfemtet-1.1.1.dist-info/entry_points.txt,sha256=Tsb_l_8Z6pyyq2tRfuKiwfJUV3nq_cHoLS61foALtsg,134
179
+ pyfemtet-1.1.1.dist-info/RECORD,,