Skip to content

[Pylib] add at_tsim case for simulation callbacks#1894

Draft
tdavidcl wants to merge 3 commits into
Shamrock-code:mainfrom
tdavidcl:at_tile_callback
Draft

[Pylib] add at_tsim case for simulation callbacks#1894
tdavidcl wants to merge 3 commits into
Shamrock-code:mainfrom
tdavidcl:at_tile_callback

Conversation

@tdavidcl

Copy link
Copy Markdown
Member

No description provided.

@tdavidcl tdavidcl added the draft label Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks @tdavidcl for opening this PR!

You can do multiple things directly here:
1 - Comment pre-commit.ci run to run pre-commit checks.
2 - Comment pre-commit.ci autofix to apply fixes.
3 - Add label autofix.ci to fix authorship & pre-commit for every commit made.
4 - Add label light-ci to only trigger a reduced & faster version of the CI (need the full one before merge).
5 - Add label trigger-ci to create an empty commit to trigger the CI.

Once the workflow completes a message will appear displaying informations related to the run.

Also the PR gets automatically reviewed by gemini, you can:
1 - Comment /gemini review to trigger a review
2 - Comment /gemini summary for a summary
3 - Tag it using @gemini-code-assist either in the PR or in review comments on files

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an at_tsim parameter to the @callback decorator in SimulationRunner.py, enabling callbacks to trigger at exact simulation times. The review feedback identifies two issues: a regression in CallbackState where tsim_interval callbacks no longer trigger at the start of the simulation (tsim_start) and exact times equal to tsim_start are skipped, and a parsing bug where a single string argument for at_tsim is incorrectly iterated over as individual characters. Suggestions are provided to address both issues.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +183 to +190
candidates = []
if info.tsim_interval is not None:
candidates.append(tsim_start + info.tsim_interval)
if info.at_tsim is not None:
future = [t for t in info.at_tsim if t > tsim_start]
if future:
candidates.append(min(future))
self.next_tsim = min(candidates) if candidates else None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

This change introduces a regression where tsim_interval callbacks are no longer triggered at the start of the simulation (tsim_start). In the original code, self.next_tsim was initialized to tsim_start, allowing the callback to run at t = 0.0 before any simulation steps. By changing it to tsim_start + info.tsim_interval, the initial callback is skipped.

Additionally, if at_tsim contains tsim_start (e.g., 0.0), it will also be skipped because of the strict inequality t > tsim_start.

To fix both issues and preserve the original behavior, we should initialize candidates with tsim_start for tsim_interval, and use t >= tsim_start for at_tsim.

Suggested change
candidates = []
if info.tsim_interval is not None:
candidates.append(tsim_start + info.tsim_interval)
if info.at_tsim is not None:
future = [t for t in info.at_tsim if t > tsim_start]
if future:
candidates.append(min(future))
self.next_tsim = min(candidates) if candidates else None
candidates = []
if info.tsim_interval is not None:
candidates.append(tsim_start)
if info.at_tsim is not None:
future = [t for t in info.at_tsim if t >= tsim_start]
if future:
candidates.append(min(future))
self.next_tsim = min(candidates) if candidates else None

Comment on lines +50 to +54
if at_tsim is not None:
if isinstance(at_tsim, (int, float)):
at_tsim = [float(at_tsim)]
else:
at_tsim = sorted(float(t) for t in at_tsim)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If at_tsim is passed as a string (e.g., "10"), it is not an instance of (int, float), so the code falls back to the else block and attempts to iterate over it. Since strings are iterable in Python, this will silently parse "10" as ['1', '0'] and convert them to [1.0, 0.0], leading to unexpected behavior.

To prevent this, we should include str in the isinstance check so that single string values are correctly converted to a single float (or raise a ValueError if the string is not a valid number).

Suggested change
if at_tsim is not None:
if isinstance(at_tsim, (int, float)):
at_tsim = [float(at_tsim)]
else:
at_tsim = sorted(float(t) for t in at_tsim)
if at_tsim is not None:
if isinstance(at_tsim, (int, float, str)):
at_tsim = [float(at_tsim)]
else:
at_tsim = sorted(float(t) for t in at_tsim)

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Workflow report

workflow report corresponding to commit 4563eb6
Commiter email is timothee.davidcleris@proton.me
GitHub page artifact URL GitHub page artifact link (can expire)

Pre-commit check report

Pre-commit check: ✅

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check for merge conflicts................................................Passed
check that executables have shebangs.....................................Passed
check that scripts with shebangs are executable..........................Passed
check for added large files..............................................Passed
check for case conflicts.................................................Passed
check for broken symlinks................................................Passed
check yaml...............................................................Passed
detect private key.......................................................Passed
No-tabs checker..........................................................Passed
Tabs remover.............................................................Passed
cmake-format.............................................................Passed
Validate GitHub Workflows................................................Passed
clang-format.............................................................Passed
ruff check...............................................................Passed
ruff format..............................................................Passed
Check doxygen headers....................................................Passed
Check license headers....................................................Passed
Check #pragma once.......................................................Passed
Check SYCL #include......................................................Passed
No ssh in git submodules remote..........................................Passed
No UTF-8 in files (except for authors)...................................Passed

Test pipeline can run.

Clang-tidy diff report

No relevant changes found.
Well done!

You should now go back to your normal life and enjoy a hopefully sunny day while waiting for the review.

Doxygen diff with main

Removed warnings : 35
New warnings : 36
Warnings count : 8006 → 8007 (0.0%)

Detailed changes :
- src/pylib/shamrock/utils/SimulationRunner.py:131: warning: Member _declared_callbacks (variable) of class shamrock.utils.SimulationRunner.SimulationMeta is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:132: warning: Member _setup (variable) of class shamrock.utils.SimulationRunner.SimulationMeta is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:146: warning: Compound shamrock::utils::SimulationRunner::CallbackInfo is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:150: warning: Member tsim_interval (variable) of class shamrock.utils.SimulationRunner.CallbackInfo is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:151: warning: Member iter_count_interval (variable) of class shamrock.utils.SimulationRunner.CallbackInfo is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:152: warning: Member walltime_interval (variable) of class shamrock.utils.SimulationRunner.CallbackInfo is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:153: warning: Member _declared_callbacks (variable) of class shamrock.utils.SimulationRunner.SimulationMeta is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:154: warning: Member _setup (variable) of class shamrock.utils.SimulationRunner.SimulationMeta is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:155: warning: Compound shamrock::utils::SimulationRunner::CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:156: warning: Member __init__(self, CallbackInfo info, float tsim_start) (function) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:157: warning: Member info (variable) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:158: warning: Member counter (variable) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:159: warning: Member next_tsim (variable) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:160: warning: Member next_iter_count (variable) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:161: warning: Member next_walltime (variable) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:163: warning: Member advance(self, float t_model, int iter_count, float walltime) (function) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:168: warning: Compound shamrock::utils::SimulationRunner::CallbackInfo is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:172: warning: Member tsim_interval (variable) of class shamrock.utils.SimulationRunner.CallbackInfo is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:173: warning: Member iter_count_interval (variable) of class shamrock.utils.SimulationRunner.CallbackInfo is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:174: warning: Member walltime_interval (variable) of class shamrock.utils.SimulationRunner.CallbackInfo is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:175: warning: Member at_tsim (variable) of class shamrock.utils.SimulationRunner.CallbackInfo is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:178: warning: Compound shamrock::utils::SimulationRunner::CallbackState is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:179: warning: Member __init__(self, CallbackInfo info, float tsim_start) (function) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:180: warning: Member info (variable) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:181: warning: Member counter (variable) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:181: warning: Member should_trigger(self, float t_model, int iter_count, float walltime) (function) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:190: warning: Member next_tsim (variable) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:192: warning: Member next_iter_count (variable) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:193: warning: Member next_walltime (variable) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:195: warning: Member advance(self, float t_model, int iter_count, float walltime) (function) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:207: warning: Member to_dict(self) (function) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:215: warning: Member from_dict(self, dict data) (function) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:220: warning: Member should_trigger(self, float t_model, int iter_count, float walltime) (function) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:246: warning: Member t_end (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:246: warning: Member to_dict(self) (function) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:247: warning: Member dump_prefix (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:249: warning: Member cur_t (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:250: warning: Member cur_iter_count (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:254: warning: Member from_dict(self, dict data) (function) of class shamrock.utils.SimulationRunner.CallbackState is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:255: warning: Member __init__(self, model) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:256: warning: Member model (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:258: warning: Member _callbacks (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:271: warning: Member _callbacks_state (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:274: warning: Member dump_helper (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:287: warning: Member do_checkpoint(self, int icheckpoint, **kwargs) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:290: warning: Member t_end (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:291: warning: Member dump_prefix (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:293: warning: Member cur_t (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:294: warning: Member cur_iter_count (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:299: warning: Member __init__(self, model) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:300: warning: Member model (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:302: warning: Member _callbacks (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:304: warning: Member run_setup(self) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:316: warning: Member _callbacks_state (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:319: warning: Member dump_helper (variable) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:321: warning: Member restore_from_checkpoint(self, dict metadata) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:332: warning: Member do_checkpoint(self, int icheckpoint, **kwargs) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:343: warning: Member evolve_until(self, float next_time, int|None next_iter_count, float|None next_walltime) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:349: warning: Member run_setup(self) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:366: warning: Member restore_from_checkpoint(self, dict metadata) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:368: warning: Member trigger_and_advance_callbacks(self) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:387: warning: Member goto_run_next_callback(self) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:388: warning: Member evolve_until(self, float next_time, int|None next_iter_count, float|None next_walltime) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:413: warning: Member trigger_and_advance_callbacks(self) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:424: warning: Member run(self) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:432: warning: Member goto_run_next_callback(self) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:469: warning: Member run(self) (function) of class shamrock.utils.SimulationRunner.SimulationRunner is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:67: warning: Compound shamrock::utils::SimulationRunner::SimulationMeta is not documented.
- src/pylib/shamrock/utils/SimulationRunner.py:68: warning: Member __new__(mcls, name, bases, namespace) (function) of class shamrock.utils.SimulationRunner.SimulationMeta is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:89: warning: Compound shamrock::utils::SimulationRunner::SimulationMeta is not documented.
+ src/pylib/shamrock/utils/SimulationRunner.py:90: warning: Member __new__(mcls, name, bases, namespace) (function) of class shamrock.utils.SimulationRunner.SimulationMeta is not documented.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant