Skip to content

Commit 78737a0

Browse files
Fix missing default n_trials when loading network from GUI (#1216)
* Fix missing default n_trials when loading network from GUI * Fix GUI test for missing n_trials * Format GUI test with ruff * fix: set default N_trials in net._params when missing
1 parent d0e9818 commit 78737a0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

hnn_core/dipole.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def simulate_dipole(
6969
_BACKEND = JoblibBackend(n_jobs=1)
7070

7171
if n_trials is None:
72-
n_trials = net._params["N_trials"]
72+
n_trials = net._params.get("N_trials", 1)
73+
net._params["N_trials"] = n_trials
74+
7375
if n_trials < 1:
7476
raise ValueError("Invalid number of simulations: %d" % n_trials)
7577

hnn_core/tests/test_gui.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,35 @@ def test_gui_upload_drives():
263263
plt.close("all")
264264

265265

266+
def test_gui_rerun_saved_network_without_n_trials():
267+
"""Test rerunning a GUI-saved network without N_trials defined.
268+
Ensures simulate_dipole defaults correctly instead of raising KeyError.
269+
"""
270+
271+
gui = HNNGUI()
272+
gui.compose()
273+
274+
gui.widget_tstop.value = 20
275+
gui.widget_dt.value = 0.5
276+
gui.widget_ntrials.value = 1
277+
278+
gui.run_button.click()
279+
280+
sim_name = gui.widget_simulation_name.value
281+
net = gui.simulation_data[sim_name]["net"]
282+
283+
cfg_path = Path("saved_network.json")
284+
net.write_configuration(cfg_path)
285+
286+
loaded_net = read_network_configuration(cfg_path)
287+
loaded_net._params.pop("N_trials", None)
288+
289+
dpls = simulate_dipole(loaded_net, tstop=20.0, dt=0.5)
290+
291+
assert isinstance(dpls, list)
292+
assert len(dpls) == 1
293+
294+
266295
def test_gui_upload_data():
267296
"""Test if gui handles uploaded data"""
268297
gui = HNNGUI()

0 commit comments

Comments
 (0)