def test_logger_can_record_attributes_from_an_object(): obj = ObjToLog() logger = log.Logger(obj, ["a"]) obj.a = 3 logger.record() obj.a = 4 logger.record() expected = pd.DataFrame.from_dict({"a": [3, 4]}) assert logger.to_df().equals(expected)
def test_logger_can_record_attributes_from_an_object() -> None: obj = ObjToLog("obj") logger = log.Logger(obj, ["unit0_act", "unit1_act", "avg_act"]) logger.record() expected = pd.DataFrame.from_dict({ "act": [0.3, 0.5, None], "avg_act": [None, None, 0.4], "unit": [0, 1, None] }) expected["time"] = 0 assert logger.to_df().equals(expected)
def _add_loggers(self, obj: log.ObservableMixin) -> None: """Instantiates loggers for an observable object. We assume the object has a "spec" attribute that specifies which attributes to log at each frequency, as well as a "name" attribute. """ for freq_name, freq in events.Frequency.registry.items(): attrs_to_log = obj.spec.attrs_to_log(freq) if attrs_to_log: logger = log.Logger(obj, attrs_to_log, freq) self.loggers.append(logger) self.objs["{0}_{1}_logger".format(obj.name, freq_name)] = logger
def new_layer(self, name: str, size: int, spec: specs.LayerSpec = None) -> None: """Adds a new layer to the network. Args: name: The name of the layer. size: How many units the layer should have. spec: The layer specification. Raises: spec.ValidationError: If the spec contains an invalid parameter value. """ if spec is not None: spec.validate() lr = layer.Layer(name, size, spec) self.layers.append(lr) self.objs[lr.name] = lr if lr.spec.log_on_cycle != (): self.cycle_loggers.append(log.Logger(lr, lr.spec.log_on_cycle))
def test_logger_has_a_name_property(): obj = ObjToLog() logger = log.Logger(obj, ["a"]) logger.name = "obj" assert logger.name == "obj"