Skip to content

Commit 6904cfd

Browse files
committed
add nice mode helper params, and allow users to change reference current
1 parent d865f4e commit 6904cfd

File tree

5 files changed

+36
-38
lines changed

5 files changed

+36
-38
lines changed

waveform_editor/gui/shape_editor.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ def __init__(self):
6262
button_start.disabled = (
6363
(
6464
self.plasma_shape.param.has_shape.rx.not_()
65-
& (
66-
self.nice_settings.param.mode.rx()
67-
== self.nice_settings.INVERSE_MODE
68-
)
65+
& self.nice_settings.param.is_inverse_mode.rx()
6966
)
7067
| self.plasma_properties.param.has_properties.rx.not_()
7168
| self.nice_settings.param.are_required_filled.rx.not_()
@@ -88,8 +85,7 @@ def __init__(self):
8885
self.plasma_shape,
8986
"Plasma Shape",
9087
is_valid=self.plasma_shape.param.has_shape,
91-
visible=self.nice_settings.param.mode.rx()
92-
== self.nice_settings.INVERSE_MODE,
88+
visible=self.nice_settings.param.is_inverse_mode.rx(),
9389
),
9490
self._create_card(
9591
pn.Column(self.plasma_properties, self.nice_plotter.profiles_pane),
@@ -191,7 +187,7 @@ def _create_equilibrium(self):
191187
equilibrium.vacuum_toroidal_field.b0.resize(1)
192188

193189
# Only fill plasma shape for NICE inverse mode
194-
if self.nice_settings.mode == self.nice_settings.INVERSE_MODE:
190+
if self.nice_settings.is_inverse_mode:
195191
equilibrium.time_slice[0].boundary.outline.r = self.plasma_shape.outline_r
196192
equilibrium.time_slice[0].boundary.outline.z = self.plasma_shape.outline_z
197193

@@ -216,7 +212,7 @@ async def submit(self, event=None):
216212
description IDSs and an input equilibrium IDS."""
217213

218214
self.coil_currents.fill_pf_active(self.pf_active)
219-
if self.nice_settings.mode == self.nice_settings.DIRECT_MODE:
215+
if self.nice_settings.is_direct_mode:
220216
xml_params = self.xml_params_dir
221217
else:
222218
xml_params = self.xml_params_inv
@@ -227,9 +223,7 @@ async def submit(self, event=None):
227223
equilibrium = self._create_equilibrium()
228224
if not self.communicator.running:
229225
await self.communicator.run(
230-
is_direct_mode=(
231-
self.nice_settings.mode == self.nice_settings.DIRECT_MODE
232-
)
226+
is_direct_mode=self.nice_settings.is_direct_mode
233227
)
234228
await self.communicator.submit(
235229
ET.tostring(xml_params, encoding="unicode"),

waveform_editor/settings.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ class NiceSettings(param.Parameterized):
4747
objects=[INVERSE_MODE, DIRECT_MODE], default=INVERSE_MODE, precedence=-1
4848
)
4949
are_required_filled = param.Boolean(precedence=-1)
50+
is_direct_mode = param.Boolean(precedence=-1)
51+
is_inverse_mode = param.Boolean(precedence=-1)
52+
53+
@param.depends("mode", watch=True, on_init=True)
54+
def set_mode_flags(self):
55+
if self.mode == self.INVERSE_MODE:
56+
self.is_direct_mode = False
57+
self.is_inverse_mode = True
58+
else:
59+
self.is_direct_mode = True
60+
self.is_inverse_mode = False
5061

5162
@param.depends(
5263
*BASE_REQUIRED, "inv_executable", "dir_executable", "mode", watch=True
@@ -72,8 +83,14 @@ def apply_settings(self, params):
7283
self.param.update(**params)
7384

7485
def to_dict(self):
75-
"""Returns a dictionary representation of current parameter values."""
76-
return {p: getattr(self, p) for p in self.param if p != "name"}
86+
"""Returns a dictionary representation of current parameter values, excluding
87+
params with a precendence of -1."""
88+
result = {}
89+
for p in self.param:
90+
param_obj = self.param[p]
91+
if p != "name" and param_obj.precedence != -1:
92+
result[p] = getattr(self, p)
93+
return result
7794

7895
def panel(self):
7996
items = []
@@ -83,8 +100,8 @@ def panel(self):
83100
continue
84101

85102
# Add warning indicator if required parameter is not filled
86-
is_inv_required = p == "inv_executable" and self.mode == self.INVERSE_MODE
87-
is_dir_required = p == "dir_executable" and self.mode == self.DIRECT_MODE
103+
is_inv_required = p == "inv_executable" and self.is_inverse_mode
104+
is_dir_required = p == "dir_executable" and self.is_direct_mode
88105
is_base_required = p in self.BASE_REQUIRED
89106

90107
row_content = [pn.Param(self.param[p], show_name=False)]

waveform_editor/shape_editor/coil_currents.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,13 @@ def create_ui(self, pf_active):
4949
coil_current = coil.current
5050
checkbox = pn.widgets.Checkbox(
5151
margin=(30, 10, 10, 10),
52-
disabled=self.nice_settings.param.mode.rx()
53-
== self.nice_settings.DIRECT_MODE,
52+
disabled=self.nice_settings.param.is_direct_mode.rx(),
5453
)
5554
slider = pn.widgets.EditableFloatSlider(
5655
name=f"{coil.name} Current [{coil_current.metadata.units}]",
5756
value=coil_current.data[0] if coil_current.data.has_value else 0.0,
5857
start=-5e4,
5958
end=5e4,
60-
disabled=checkbox.param.value.rx.not_()
61-
& (
62-
self.nice_settings.param.mode.rx()
63-
== self.nice_settings.INVERSE_MODE
64-
),
6559
format="0",
6660
width=450,
6761
)
@@ -78,12 +72,8 @@ def fill_pf_active(self, pf_active):
7872
pf_active: pf_active IDS to update the coil currents for.
7973
"""
8074
for i, coil_ui in enumerate(self.coil_ui):
81-
checkbox, slider = coil_ui.objects
82-
if (
83-
checkbox.value
84-
or self.nice_settings.mode == self.nice_settings.DIRECT_MODE
85-
):
86-
pf_active.coil[i].current.data = np.array([slider.value])
75+
_, slider = coil_ui.objects
76+
pf_active.coil[i].current.data = np.array([slider.value])
8777

8878
def sync_ui_with_pf_active(self, pf_active):
8979
"""Synchronize UI sliders with the current values from the pf_active IDS.

waveform_editor/shape_editor/nice_integration.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,11 @@ async def run(self, is_direct_mode=False):
151151

152152
self.xml_config_file = tempfile.NamedTemporaryFile() # noqa: SIM115
153153

154-
# Select configuration based on mode
155-
config_str = (
156-
_muscle3_dir_configuration if is_direct_mode else _muscle3_inv_configuration
157-
)
158-
159154
# MUSCLE manager
160155
self.manager_pipe, pipe = multiprocessing.Pipe()
161156
self.manager = multiprocessing.Process(
162157
target=run_muscle_manager,
163-
args=[pipe, self.xml_config_file.name, config_str],
158+
args=[pipe, self.xml_config_file.name, is_direct_mode],
164159
name="MUSCLE Manager",
165160
)
166161
self.manager.start()
@@ -346,9 +341,12 @@ def run_muscle3_communicator(
346341

347342

348343
def run_muscle_manager(
349-
pipe: multiprocessing.connection.Connection, xml_path: str, config_str: str
344+
pipe: multiprocessing.connection.Connection, xml_path: str, is_direct_mode: bool
350345
):
351346
"""Run the muscle_manager with a given configuration."""
347+
config_str = (
348+
_muscle3_dir_configuration if is_direct_mode else _muscle3_inv_configuration
349+
)
352350
config = ymmsl.load(config_str.format(xml_path=xml_path))
353351
manager = Manager(config)
354352
server_location = manager.get_server_location()

waveform_editor/shape_editor/nice_plotter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ def __init__(self, **params):
9494
show_name=False,
9595
widgets={
9696
"show_desired_shape": {
97-
"visible": self.nice_settings.param.mode.rx()
98-
== self.nice_settings.INVERSE_MODE
97+
"visible": self.nice_settings.param.is_inverse_mode.rx()
9998
}
10099
},
101100
)
@@ -138,7 +137,7 @@ def _plot_profiles(self):
138137
)
139138
def _plot_plasma_shape(self):
140139
if (
141-
self.nice_settings.mode == self.nice_settings.DIRECT_MODE
140+
self.nice_settings.is_direct_mode
142141
or not self.show_desired_shape
143142
or not self.plasma_shape.has_shape
144143
):

0 commit comments

Comments
 (0)