Skip to content

Add correctness tests for Euler/RK4 integration - #120

Closed
anar-rzayev wants to merge 3 commits into
prism-science:mainfrom
anar-rzayev:test/58-integration-correctness
Closed

anar-rzayev wants to merge 3 commits into
prism-science:mainfrom
anar-rzayev:test/58-integration-correctness

Conversation

@anar-rzayev

@anar-rzayev anar-rzayev commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

test_euler_integrate / test_rk4_integrate only check shapes and keys. These
drive both integrators with analytic velocity fields (model swapped for a mock)
and compare against closed-form solutions:

  • v = c — straight line, total displacement exactly c, both methods
  • v = -x — coarse RK4 matches 2000-step Euler, and beats Euler at equal steps
  • v = a*t — pins down the times each stage is evaluated at
  • two graphs, 5 and 3 waters — per-graph result splitting (the batched
    scripts/inference.py path, previously untested)

Tests only; tests/test_flow.py is the one file changed.

anar-rzayev and others added 2 commits August 31, 2026 17:02
The existing test_euler_integrate / test_rk4_integrate only assert output
shapes and dict keys. Add numerical-correctness tests that drive the
integrators with analytic velocity fields (via a mocked model) and check
against closed-form solutions:

- Constant field v = c: the trajectory must be a straight line with total
  displacement exactly c over t in [0, 1], for both Euler and RK4 and
  independent of step count.
- Decay field v = -x: coarse RK4 (21 steps) must converge to the same
  solution as fine-step Euler (2000 steps), and be more accurate than
  Euler at the same step count -- exercising RK4's higher order.

Tests use a trivial stub model so they are fast (not marked slow) and are
seeded so Euler and RK4 start from identical prior noise.

Closes prism-science#58

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DG3ZwCtLWBcmULcWeV5gf7
Copilot AI lite review requested due to automatic review settings August 31, 2026 20:23
@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

Next included review available in 53 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 387a1123-9664-4531-9720-4277cb18b1de

📥 Commits

Reviewing files that changed from the base of the PR and between ec47286 and 80cccd4.

📒 Files selected for processing (1)
  • tests/test_flow.py

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: d4310d2f-a17c-40cb-b3f9-1d277efd0380

📥 Commits

Reviewing files that changed from the base of the PR and between 8a6b6bb and ec47286.

📒 Files selected for processing (1)
  • tests/test_flow.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds FlowMatcher integration tests for Euler and RK4 methods. The tests cover analytical trajectories, RK4 timing and accuracy, reproducible initial noise, time-dependent fields, and batched graph output splitting.

Changes

Flow integration validation

Layer / File(s) Summary
Velocity-field test fixtures
tests/test_flow.py
Adds mock velocity fields for constant, linear-decay, time-dependent, and graph-scaled dynamics.
Euler and RK4 correctness checks
tests/test_flow.py
Validates trajectories, RK4 accuracy, stage timing, Euler left-endpoint behavior, and reproducible initial noise.
Batched graph integration outputs
tests/test_flow.py
Validates unequal water counts, graph-specific displacements, trajectory shapes, and per-graph result splitting.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to ec472

This change adds numerical and batching correctness tests without altering production behavior or runtime configuration, so no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: vratins

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The tests satisfy issue #58. They verify constant-field linear trajectories and RK4 convergence against higher-step-count Euler results. The additional timing and batching tests support integration co…
Out of Scope Changes check ✅ Passed The pull request contains only integration correctness tests in tests/test_flow.py. The changes directly support issue #58 and introduce no unrelated code changes.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding numerical correctness tests for Euler and RK4 integration.
Full details: Linked Issues check

Explanation

The tests satisfy issue #58. They verify constant-field linear trajectories and RK4 convergence against higher-step-count Euler results. The additional timing and batching tests support integration correctness.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI 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.

Pull request overview

Adds numerically meaningful integration correctness tests to ensure FlowMatcher.euler_integrate and FlowMatcher.rk4_integrate produce correct trajectories (not just correctly shaped outputs), using lightweight analytic/mock velocity fields to keep runtime low.

Changes:

  • Introduces analytic velocity-field mock modules (constant, linear decay, time-ramp, per-graph) to drive integrators deterministically.
  • Adds closed-form correctness checks for constant-field trajectories and time-dependent stage timing behavior.
  • Adds a convergence test (coarse RK4 vs fine Euler) and a batched multi-graph splitting test to validate per-graph masking/splitting.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings August 31, 2026 20:30

Copilot AI 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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

tests/test_flow.py:902

  • test_rk4_matches_euler_with_more_steps uses a 2000-step Euler run as the reference. This makes the test slower than necessary and the reference itself is still a numerical approximation even though this ODE has a closed-form solution (x(1)=x(0)*exp(-k)). Using the analytic solution makes the test faster and verifies absolute correctness directly.
        seed = 1234
        euler_fine = run("euler", num_steps=2000, seed=seed)
        rk4_coarse = run("rk4", num_steps=21, seed=seed)
        euler_coarse = run("euler", num_steps=21, seed=seed)

        # Identical initial noise across the three runs (guards the comparison).
        np.testing.assert_allclose(
            rk4_coarse["trajectory"][0], euler_fine["trajectory"][0], atol=1e-5
        )
        np.testing.assert_allclose(
            euler_coarse["trajectory"][0], euler_fine["trajectory"][0], atol=1e-5
        )

        reference = euler_fine["water_pred"]
        # Coarse RK4 converges to the fine-step Euler solution.
        np.testing.assert_allclose(
            rk4_coarse["water_pred"], reference, rtol=2e-2, atol=2e-2
        )
        # RK4 is closer to the reference than Euler at the same step count.
        rk4_err = np.linalg.norm(rk4_coarse["water_pred"] - reference)
        euler_err = np.linalg.norm(euler_coarse["water_pred"] - reference)
        assert rk4_err < euler_err

@anar-rzayev
anar-rzayev deleted the test/58-integration-correctness branch August 31, 2026 20:55
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