11import json
22
3- from ngclearn import Component , Compartment
3+ from ngclearn import Component , Compartment , transition
44from ngclearn import numpy as np
5- #from ngcsimlib.utils import add_component_resolver, add_resolver_meta, \
65from ngcsimlib .utils import get_current_path
76from ngcsimlib .logger import warn , critical
7+
88import matplotlib .pyplot as plt
99
1010
@@ -44,9 +44,16 @@ class Base_Monitor(Component):
4444 """
4545 auto_resolve = False
4646
47+ @staticmethod
48+ def build_reset (component ):
49+ return Base_Monitor .reset (component )
50+
51+ @staticmethod
52+ def build_advance_state (component ):
53+ return Base_Monitor .record (component )
4754
4855 @staticmethod
49- def build_advance (compartments ):
56+ def _record_internal (compartments ):
5057 """
5158 A method to build the method to advance the stored values.
5259
@@ -61,8 +68,9 @@ def build_advance(compartments):
6168 "monitor found in ngclearn.components or "
6269 "ngclearn.components.lava (If using lava)" )
6370
71+ @transition (None , True )
6472 @staticmethod
65- def build_reset (component ):
73+ def reset (component ):
6674 """
6775 A method to build the method to reset the stored values.
6876 Args:
@@ -87,15 +95,16 @@ def _reset(**kwargs):
8795 # pure func, output compartments, args, params, input compartments
8896 return _reset , output_compartments , [], [], output_compartments
8997
98+ @transition (None , True )
9099 @staticmethod
91- def build_advance_state (component ):
100+ def record (component ):
92101 output_compartments = []
93102 compartments = []
94103 for comp in component .compartments :
95104 output_compartments .append (comp .split ("/" )[- 1 ] + "*store" )
96105 compartments .append (comp .split ("/" )[- 1 ])
97106
98- _advance = component .build_advance (compartments )
107+ _advance = component ._record_internal (compartments )
99108
100109 return _advance , output_compartments , [], [], compartments + output_compartments
101110
@@ -124,8 +133,15 @@ def watch(self, compartment, window_length):
124133 """
125134 cs , end = self ._add_path (compartment .path )
126135
127- dtype = compartment .value .dtype
128- shape = compartment .value .shape
136+ if hasattr (compartment .value , "dtype" ):
137+ dtype = compartment .value .dtype
138+ else :
139+ dtype = type (compartment .value )
140+
141+ if hasattr (compartment .value , "shape" ):
142+ shape = compartment .value .shape
143+ else :
144+ shape = (1 ,)
129145 new_comp = Compartment (np .zeros (shape , dtype = dtype ))
130146 new_comp_store = Compartment (np .zeros ((window_length , * shape ), dtype = dtype ))
131147
@@ -268,7 +284,7 @@ def load(self, directory, **kwargs):
268284 setattr (self , compartment_path , new_comp )
269285 self .compartments .append (new_comp .path )
270286
271- self ._update_resolver ()
287+ # self._update_resolver()
272288
273289 def make_plot (self , compartment , ax = None , ylabel = None , xlabel = None , title = None , n = None , plot_func = None ):
274290 vals = self .view (compartment )
0 commit comments