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,8 @@ class Base_Monitor(Component):
4444 """
4545 auto_resolve = False
4646
47-
4847 @staticmethod
49- def build_advance (compartments ):
48+ def _record_internal (compartments ):
5049 """
5150 A method to build the method to advance the stored values.
5251
@@ -61,8 +60,9 @@ def build_advance(compartments):
6160 "monitor found in ngclearn.components or "
6261 "ngclearn.components.lava (If using lava)" )
6362
63+ @transition (None , True )
6464 @staticmethod
65- def build_reset (component ):
65+ def reset (component ):
6666 """
6767 A method to build the method to reset the stored values.
6868 Args:
@@ -87,15 +87,16 @@ def _reset(**kwargs):
8787 # pure func, output compartments, args, params, input compartments
8888 return _reset , output_compartments , [], [], output_compartments
8989
90+ @transition (None , True )
9091 @staticmethod
91- def build_advance_state (component ):
92+ def record (component ):
9293 output_compartments = []
9394 compartments = []
9495 for comp in component .compartments :
9596 output_compartments .append (comp .split ("/" )[- 1 ] + "*store" )
9697 compartments .append (comp .split ("/" )[- 1 ])
9798
98- _advance = component .build_advance (compartments )
99+ _advance = component ._record_internal (compartments )
99100
100101 return _advance , output_compartments , [], [], compartments + output_compartments
101102
@@ -124,8 +125,15 @@ def watch(self, compartment, window_length):
124125 """
125126 cs , end = self ._add_path (compartment .path )
126127
127- dtype = compartment .value .dtype
128- shape = compartment .value .shape
128+ if hasattr (compartment .value , "dtype" ):
129+ dtype = compartment .value .dtype
130+ else :
131+ dtype = type (compartment .value )
132+
133+ if hasattr (compartment .value , "shape" ):
134+ shape = compartment .value .shape
135+ else :
136+ shape = (1 ,)
129137 new_comp = Compartment (np .zeros (shape , dtype = dtype ))
130138 new_comp_store = Compartment (np .zeros ((window_length , * shape ), dtype = dtype ))
131139
0 commit comments