Skip to content

Parametrize sim tests over integrators - #142

Merged
amacati merged 4 commits into
learnsyslab:mainfrom
alirezanaseri548:tests/parametrize-integrators
Oct 23, 2026
Merged

amacati merged 4 commits into
learnsyslab:mainfrom
alirezanaseri548:tests/parametrize-integrators

Conversation

@alirezanaseri548

@alirezanaseri548 alirezanaseri548 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #106

Summary

Adds integrator coverage to the test suite following the approach sketched in #122. #102 showed that a broken symplectic integrator went unnoticed because the tests only exercised the default integrator.

  • New tests/unit/test_integrators.py compares the complete sim.data pytree of every dynamics x integrator combination against a separately stepped default-integrator Sim after two simulation steps: tree structures must match, PRNG key data is compared exactly, floating-point arrays with rtol=2e-2, atol=1e-4 (rotor speeds differ by several percent between Euler and RK4), everything else exactly. Parametrizing over dynamics keeps the so_rpy families where the Add clipping to rotor_vel #102 bug lived inside the comparison.
  • 12 fast variants (~13 s on CPU); no changes to existing tests.

Testing

  • pytest tests/unit: 713 passed, 0 failed, 43 skipped, on CPU.
  • ruff format and ruff check pass.

Extend the test suite to cover the different integrators, as requested in learnsyslab#106:
- test_sim_step now runs the full pipeline for every integrator
- test_floor_penetration now runs for every integrator
- add test_free_fall_convergence, which verifies that the trajectory under
  every integrator converges to a 10x higher frequency reference sim in free
  fall. This catches integration breakage like the broken symplectic
  integrators observed in learnsyslab#102

@amacati amacati left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I left some comments and linked a reference PR. Thanks for working on this!

Comment thread tests/unit/test_sim.py Outdated
Comment thread tests/unit/test_sim.py Outdated
Comment thread tests/unit/test_sim.py Outdated


@pytest.mark.unit
@pytest.mark.parametrize("integrator", Integrator)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How many variants does this add? While I'm in favor of sanity-checking all combinations at least once, this is likely going to massively increase the number of tests we run and thereby the test duration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It added 240 variants (40 -> 280 in test_sim.py), roughly doubling the unit test duration on CPU (~+100 s locally). Resolved in 4b48be4 by reverting the parametrization and moving the integrator coverage into a dedicated tests/unit/test_integrators.py following the approach of #122: 12 variants (4 dynamics x 3 integrators), ~13 s on CPU.

Per the review, rework the approach to follow the one sketched in learnsyslab#122:
- Revert the integrator parametrization of test_sim_step and
  test_floor_penetration, and drop the free-fall convergence test. The
  parametrized test_sim_step alone added 240 test variants (40 -> 280) and
  roughly doubled the unit test duration on CPU.
- Add tests/unit/test_integrators.py instead, which compares the complete
  sim.data pytree of every dynamics x integrator combination against a
  separately stepped default-integrator Sim after two steps. This adds 12
  fast variants (~13 s on CPU) and covers the so_rpy families where the
  broken symplectic integrator from learnsyslab#102 lived.

@amacati amacati left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One minor thing I realized, otherwise this looks good to go

Comment on lines +17 to +20
sim = Sim(dynamics=dynamics, integrator=integrator, device=device)
default_sim = Sim(dynamics=dynamics, device=device)
sim.step(2)
default_sim.step(2)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One more thing: Could you spawn the drones in the air and then do all the checks below? With the floor clipping, it's likely that we would not see a difference in the dynamics

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in bc7776c — both sims now spawn at z=2.0 before stepping, so the floor clipping can no longer mask differences between the integration schemes.

alirezanaseri548 and others added 2 commits October 23, 2026 13:38
At the default spawn on the floor, floor clipping masks any difference in
the dynamics between integrators. Spawn both sims at z=2.0 instead.
@amacati
amacati merged commit f250730 into learnsyslab:main Oct 23, 2026
amacati added a commit that referenced this pull request Oct 23, 2026
---------

Co-authored-by: Martin Schuck <57562633+amacati@users.noreply.github.com>
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.

Parametrize tests over integrators

2 participants