Skip to content

Replace assert with ValueError in load_physical_aiavdataset()#73

Merged
super-anova merged 1 commit intoNVlabs:mainfrom
lonexreb:fix/replace-assert-with-valueerror-in-loader
May 1, 2026
Merged

Replace assert with ValueError in load_physical_aiavdataset()#73
super-anova merged 1 commit intoNVlabs:mainfrom
lonexreb:fix/replace-assert-with-valueerror-in-loader

Conversation

@lonexreb
Copy link
Copy Markdown
Contributor

@lonexreb lonexreb commented May 1, 2026

Summary

Replace the assert statement in load_physical_aiavdataset() with a ValueError, mirroring the pattern of merged PR #50 (which made the same change in helper.create_message()).

Why

assert statements are stripped when Python runs with -O (optimization mode), so the t0_us validation would silently disappear and downstream timestamp arithmetic would produce confusing failures (negative offsets, out-of-range queries) instead of a clear input-validation error.

ValueError is the correct exception type for invalid argument values and is always raised regardless of optimization flags.

Change

src/alpamayo_r1/load_physical_aiavdataset.py:

-    assert t0_us > num_history_steps * time_step * 1_000_000, (
-        "t0_us must be greater than the history time range"
-    )
+    history_time_range_us = num_history_steps * time_step * 1_000_000
+    if t0_us <= history_time_range_us:
+        raise ValueError(
+            f"{t0_us=} must be greater than the history time range "
+            f"({history_time_range_us=} us)"
+        )

The error message now includes the actual computed threshold so the caller can see which value they violated.

Test plan

  • python -c "import ast; ast.parse(open('src/alpamayo_r1/load_physical_aiavdataset.py').read())" — syntax OK
  • Behavior preserved: passing t0_us greater than num_history_steps * time_step * 1_000_000 proceeds as before; smaller/equal values now raise ValueError with a descriptive message instead of AssertionError.
  • Reviewer: confirm the message format f"{name=}" is consistent with the project style (already used in helper.py after Replace assert with ValueError in create_message() #50).

References

Assert statements can be disabled with python -O flag, which would
silently skip the t0_us validation. Using ValueError ensures the check
always runs and provides a clear exception type for callers to handle.

Mirrors the pattern of NVlabs#50 (replace assert with ValueError in
create_message). Also includes the computed history_time_range in the
error message so callers can see the threshold they violated.

Signed-off-by: lonexreb <[email protected]>
@super-anova super-anova self-requested a review May 1, 2026 21:48
@super-anova super-anova merged commit e6aefbc into NVlabs:main May 1, 2026
@super-anova
Copy link
Copy Markdown
Collaborator

Thanks for creating the PR!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants