timedelta for total running time#1164
Conversation
📝 WalkthroughWalkthroughModified the time-tracking and output formatting logic in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pyphare/pyphare/simulator/simulator.py (1)
219-224: Computedeltaonly on rank 0 to avoid per-rank overhead.
deltais only used in the rank-0 print path, so Line 219 can be moved inside that branch.Based on learnings: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working.♻️ Proposed micro-optimization
- delta = datetime.timedelta(seconds=tot) if cpp.mpi_rank() == 0: + delta = datetime.timedelta(seconds=tot) print( f"t = {t:8.5f} - {ticktock:6.5f}sec - total {delta}", end=self.print_eol, )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pyphare/pyphare/simulator/simulator.py` around lines 219 - 224, Move the computation of delta (currently created via datetime.timedelta(seconds=tot)) into the rank-0 branch so it is only constructed when needed: inside the if cpp.mpi_rank() == 0: block right before the print call that uses delta. Update references to delta accordingly and keep tot as-is; this eliminates per-rank overhead by computing datetime.timedelta(seconds=tot) only on the process that prints.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pyphare/pyphare/simulator/simulator.py`:
- Around line 219-224: Move the computation of delta (currently created via
datetime.timedelta(seconds=tot)) into the rank-0 branch so it is only
constructed when needed: inside the if cpp.mpi_rank() == 0: block right before
the print call that uses delta. Update references to delta accordingly and keep
tot as-is; this eliminates per-rank overhead by computing
datetime.timedelta(seconds=tot) only on the process that prints.
43ba2a6 to
869eebd
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pyphare/pyphare/simulator/simulator.py (1)
227-228: Consider timezone-aware ISO timestamps for logs.Using UTC ISO-8601 timestamps makes logs easier to correlate across machines and parsers.
💡 Optional refactor
- print_rank0("Starting at ", datetime.datetime.now()) + started_at = datetime.datetime.now(datetime.timezone.utc) + print_rank0("Starting at", started_at.isoformat()) ... - print_rank0("Finished at ", datetime.datetime.now()) + finished_at = datetime.datetime.now(datetime.timezone.utc) + print_rank0("Finished at", finished_at.isoformat())🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pyphare/pyphare/simulator/simulator.py` around lines 227 - 228, Replace the naive timestamp print with a timezone-aware ISO-8601 UTC timestamp: update the print_rank0 call that currently uses datetime.datetime.now() to call datetime.datetime.now(datetime.timezone.utc).isoformat() (or equivalently use datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()), so the line referencing print_rank0 and datetime.datetime.now becomes a UTC ISO timestamp; keep the total advance time print using datetime.timedelta as-is or convert/label it if you want it explicitly tied to UTC.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pyphare/pyphare/simulator/simulator.py`:
- Around line 227-228: Replace the naive timestamp print with a timezone-aware
ISO-8601 UTC timestamp: update the print_rank0 call that currently uses
datetime.datetime.now() to call
datetime.datetime.now(datetime.timezone.utc).isoformat() (or equivalently use
datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()),
so the line referencing print_rank0 and datetime.datetime.now becomes a UTC ISO
timestamp; keep the total advance time print using datetime.timedelta as-is or
convert/label it if you want it explicitly tied to UTC.
| tot += ticktock | ||
| t = self.cpp_sim.currentTime() | ||
| if cpp.mpi_rank() == 0: | ||
| out = f"t = {t:8.5f} - {ticktock:6.5f}sec - total {np.sum(perf):7.4}sec" |
There was a problem hiding this comment.
np.sum(perf) seems like a bad idea in terms of imbalance during advances
No description provided.