From 8afe9099865523fbb41a7c841ed4ae739a421681 Mon Sep 17 00:00:00 2001 From: Sanchit2662 Date: Wed, 25 Mar 2026 16:56:23 +0530 Subject: [PATCH] Warn when NetworkOperation is present during Network.store() Signed-off-by: Sanchit2662 --- brian2/core/network.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/brian2/core/network.py b/brian2/core/network.py index 77d0cb459..81cff80c1 100644 --- a/brian2/core/network.py +++ b/brian2/core/network.py @@ -18,6 +18,7 @@ from brian2.core.base import BrianObject, BrianObjectException from brian2.core.clocks import defaultclock +from brian2.core.operations import NetworkOperation from brian2.core.names import Nameable from brian2.core.namespace import get_local_namespace from brian2.core.preferences import BrianPreference, prefs @@ -643,6 +644,17 @@ def store(self, name="default", filename=None): for clock in clocks: clock._set_t_update_dt(target_t=self.t) + for obj in _get_all_objects(self.objects): + if isinstance(obj, NetworkOperation): + logger.warn( + f"NetworkOperation '{obj.name}' is present in the network but " + "its state (e.g. closure variables) cannot be stored or " + "restored. If this operation maintains internal state across " + "timesteps, that state will not be reset by restore().", + name_suffix="network_operation_store", + once=True, + ) + state = self._full_state() # Store the state of the random number generator dev = get_device()