@@ -71,82 +71,6 @@ def ints(self, method='absolute'):
7171 gather [f'{ node_path } .{ k } ' if node_path else k ] = v
7272 return gather
7373
74- def child_ds (self , method = 'absolute' , include_self = False ):
75- """Return the children instance of dynamical systems.
76-
77- This is a shortcut function to get all children dynamical system
78- in this object. For example:
79-
80- >>> import brainpy as bp
81- >>>
82- >>> class Net(bp.DynamicalSystem):
83- >>> def __init__(self, **kwargs):
84- >>> super(Net, self).__init__(**kwargs)
85- >>> self.A = bp.NeuGroup(10)
86- >>> self.B = bp.NeuGroup(20)
87- >>>
88- >>> def update(self, _t, _dt):
89- >>> for node in self.child_ds().values():
90- >>> node.update(_t, _dt)
91- >>>
92- >>> net = Net()
93- >>> net.child_ds()
94- {'NeuGroup0': <brainpy.simulation.brainobjects.neuron.NeuGroup object at 0x000001ABD4FF02B0>,
95- 'NeuGroup1': <brainpy.simulation.brainobjects.neuron.NeuGroup object at 0x000001ABD74E5670>}
96-
97- Parameters
98- ----------
99- method : str
100- The method to access the children nodes.
101- include_self : bool
102- Whether include the self dynamical system.
103-
104- Returns
105- -------
106- collector: Collector
107- A Collector includes all children systems.
108- """
109- nodes = self .nodes (method = method ).subset (DynamicalSystem ).unique ()
110- if not include_self :
111- if method == 'absolute' :
112- nodes .pop (self .name )
113- elif method == 'relative' :
114- nodes .pop ('' )
115- else :
116- raise ValueError (f'Unknown access method: { method } ' )
117- return nodes
118-
119- def register_constant_delay (self , key , size , delay , dtype = None ):
120- """Register a constant delay, whose update method will be appended into
121- the ``self.steps`` in this host class.
122-
123- Parameters
124- ----------
125- key : str
126- The delay name.
127- size : int, list of int, tuple of int
128- The delay data size.
129- delay : int, float, ndarray
130- The delay time, with the unit same with `brainpy.math.get_dt()`.
131- dtype : optional
132- The data type.
133-
134- Returns
135- -------
136- delay : ConstantDelay
137- An instance of ConstantDelay.
138- """
139- if not hasattr (self , 'steps' ):
140- raise ModelBuildError ('Please initialize the super class first before '
141- 'registering constant_delay. \n \n '
142- 'super(YourClassName, self).__init__(**kwargs)' )
143- if not key .isidentifier (): raise ValueError (f'{ key } is not a valid identifier.' )
144- cdelay = ConstantDelay (size = size ,
145- delay = delay ,
146- name = f'{ self .name } _delay_{ key } ' ,
147- dtype = dtype )
148- return cdelay
149-
15074 def __call__ (self , * args , ** kwargs ):
15175 """The shortcut to call ``update`` methods."""
15276 return self .update (* args , ** kwargs )
@@ -202,7 +126,8 @@ def update(self, _t, _dt):
202126 In this update function, the update functions in children systems are
203127 iteratively called.
204128 """
205- for node in self .child_ds ().values ():
129+ nodes = self .nodes (level = 1 , include_self = False ).subset (DynamicalSystem ).unique ()
130+ for node in nodes .values ():
206131 node .update (_t , _dt )
207132
208133 def __getattr__ (self , item ):
0 commit comments