Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions agentlib/modules/simulation/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +592 to +595

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

full_comm_step relies on exact float equality ((current_time - self._last_communication_time) == 0). With env.time advancing via floating-point additions, this can fail due to rounding and prevent inputs from being logged at communication boundaries (leaving the most recent output row’s inputs as None). Consider using a tolerant comparison (e.g., math.isclose with an abs_tol) or a step-index based check (e.g., i == 0 for the first sub-step of each communication interval).

Suggested change
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)
# Track if this is the first simulation sub-step within the current
# communication interval. At communication boundaries, the inputs are
# always saved to ensure they are associated with the correct outputs.
full_comm_step = (i == 0)

Copilot uses AI. Check for mistakes.
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,
Expand Down Expand Up @@ -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
return var_dict_list