diff --git a/agentlib/modules/simulation/simulator.py b/agentlib/modules/simulation/simulator.py index 164657e9..10d1d2c8 100644 --- a/agentlib/modules/simulation/simulator.py +++ b/agentlib/modules/simulation/simulator.py @@ -584,11 +584,16 @@ def process(self): dt_sim = float(t_samples[i + 1] - t_samples[i]) # 2. Check for Input Changes (Pre-Step) - # If inputs changed since the last step (or during the yield), we log them now. + # If inputs changed since the last step (or during the yield), + # we log them now. # This ensures the new inputs are recorded at the current timestamp, # separate from the outputs of the *previous* step (which were logged at # the end of the last loop). - if self._inputs_changed_since_last_results_saving: + current_time = self.env.time + # Track if a communication step is reached. + # At communication times, the inputs are always saved + full_comm_step = ((current_time - self._last_communication_time) == 0) + if self._inputs_changed_since_last_results_saving or full_comm_step: if self.config.save_results: # Create row: [t=Current, Out=NaN, In=New] self._log_inputs(self.env.time, @@ -744,4 +749,4 @@ def convert_agent_vars_to_list_of_dicts(var: AgentVariables) -> List[Dict]: agent_var.dict(exclude={"source", "alias", "shared", "rdf_class"}) for agent_var in var ] - return var_dict_list \ No newline at end of file + return var_dict_list