From d9e5815cd046316685559ec5c3bd4413e059e709 Mon Sep 17 00:00:00 2001 From: Eran Date: Wed, 21 Feb 2024 10:49:43 -0500 Subject: [PATCH] correct emit_time for the global_time_precision to avoid floating point rounding errors --- vivarium/core/engine.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vivarium/core/engine.py b/vivarium/core/engine.py index 61a71701..65f50690 100644 --- a/vivarium/core/engine.py +++ b/vivarium/core/engine.py @@ -922,6 +922,8 @@ def run_for( """ end_time = self.global_time + interval emit_time = self.global_time + self.emit_step + if self.global_time_precision is not None: + emit_time = round(emit_time, self.global_time_precision) while self.global_time < end_time or force_complete: full_step = math.inf @@ -1024,6 +1026,8 @@ def run_for( while emit_time <= self.global_time: self._emit_store_data() emit_time += self.emit_step + if self.global_time_precision is not None: + emit_time = round(emit_time, self.global_time_precision) else: # all processes have run past the interval