Clarify ConstantStepSize finite-interval step semantics#764
Open
Whning0513 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses #757 by aligning Diffrax’s documentation with the current ConstantStepSize behavior on finite intervals, and adds tests to lock in both the observed step locations and the clarified wording.
Changes:
- Updates
ConstantStepSizeanddiffeqsolve(dt0=...)documentation to describe finite-interval step placement that lands exactly ont1. - Updates the getting-started guide to describe
ConstantStepSizeas fixed-step behavior on finite intervals. - Adds a regression test asserting the step timestamps for a representative finite-interval
ConstantStepSizesolve, plus a docstring-content test.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
test/test_saveat_solution.py |
Adds a regression test for finite-interval step locations and a docstring wording test. |
docs/usage/getting-started.md |
Adjusts tutorial wording to describe finite-interval fixed-step semantics. |
diffrax/_step_size_controller/constant.py |
Updates ConstantStepSize docstring to describe finite-interval behavior. |
diffrax/_integrate.py |
Updates diffeqsolve’s dt0 docstring text to match finite-interval fixed-step behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+23
to
28
| """Use a fixed number of constant steps determined by the `dt0` argument of | ||
| [`diffrax.diffeqsolve`][]. | ||
|
|
||
| On finite intervals this chooses `ceil((t1 - t0) / dt0)` steps and rescales the | ||
| later fixed steps to hit `t1` exactly. | ||
| """ |
Comment on lines
+932
to
+936
| - `dt0`: The step size to use for the first step. If using | ||
| [`diffrax.ConstantStepSize`][] on a finite interval then this determines the | ||
| number of fixed steps via `ceil((t1 - t0) / dt0)`, and rescales the remaining | ||
| fixed steps to land exactly on `t1`. If set as `None` then the initial step | ||
| size will be determined automatically. |
| - Step sizes and locations can be changed. | ||
| - The initial step size can be selected adaptively by setting `dt0=None`. | ||
| - A constant step size can be used by setting `stepsize_controller = ConstantStepSize()`. (This is also the default choice for `stepsize_controller` if you do not pass one at all.) | ||
| - Fixed steps can be used by setting `stepsize_controller = ConstantStepSize()`. On finite intervals this uses `dt0` to determine how many steps to take, then spaces those steps so the solve lands exactly on `t1`. (This is also the default choice for `stepsize_controller` if you do not pass one at all.) |
Comment on lines
+265
to
+267
| expected_ts = jnp.concatenate( | ||
| [jnp.array([0.0, 0.1]), jnp.linspace(2 * 1.05 / 11, 1.05, 10)] | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #757.
This updates the finite-interval documentation for
ConstantStepSizeanddiffeqsolve(dt0=...)to match the current implementation:dt0determines the number of fixed steps viaceil((t1 - t0) / dt0)t1It also adds a regression test that locks in the current step locations for a representative finite-interval solve, plus a docstring test for the clarified wording.
Tested with:
uv run python -m pytest -q test/test_saveat_solution.py