-
-
Notifications
You must be signed in to change notification settings - Fork 82
Add simulation type preservation tests #1198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -383,6 +383,41 @@ end | |
|
|
||
| ### Other Tests ### | ||
|
|
||
| # Checks that solution values have types consistent with their input types. | ||
| # Check that both float types are preserved in the solution (and problems), while integers are | ||
| # promoted to floats. | ||
| # Checks that the time types are correct (`Float64` by default or possibly `Float32`), however, | ||
| # type conversion only occurs in the solution, and integer types are preserved in problems. | ||
| let | ||
| # Create model. Checks when input type is `Float64` the produced values are also `Float64`. | ||
| rn = @reaction_network begin | ||
| (k1,k2), X1 <--> X2 | ||
| end | ||
| u0 = [:X1 => 1.0, :X2 => 3.0] | ||
| ps = [:k1 => 2.0, :k2 => 3.0] | ||
| sprob = SDEProblem(rn, u0, 1.0, ps) | ||
| ssol = solve(sprob, ISSEM()) | ||
| @test eltype(ssol[:X1]) == eltype(ssol[:X2]) == typeof(sprob[:X1]) == typeof(sprob[:X2]) == Float64 | ||
| @test eltype(ssol.t) == typeof(sprob.tspan[1]) == typeof(sprob.tspan[2]) == Float64 | ||
|
|
||
| # Checks that `Int64` values are promoted to `Float64`. | ||
| u0 = [:X1 => 1, :X2 => 3] | ||
| ps = [:k1 => 2, :k2 => 3] | ||
| sprob = SDEProblem(rn, u0, 1, ps) | ||
| ssol = solve(sprob, ISSEM()) | ||
| @test eltype(ssol[:X1]) == eltype(ssol[:X2]) == typeof(sprob[:X1]) == typeof(sprob[:X2]) == Float64 | ||
| @test eltype(ssol.t) == Float64 | ||
| @test typeof(sprob.tspan[1]) == typeof(sprob.tspan[2]) == Int64 | ||
|
||
|
|
||
| # Checks when values are `Float32` (a valid type and should be preserved). | ||
| u0 = [:X1 => 1.0f0, :X2 => 3.0f0] | ||
| ps = [:k1 => 2.0f0, :k2 => 3.0f0] | ||
| sprob = SDEProblem(rn, u0, 1.0f0, ps) | ||
| ssol = solve(sprob, ISSEM()) | ||
| @test eltype(ssol[:X1]) == eltype(ssol[:X2]) == typeof(sprob[:X1]) == typeof(sprob[:X2]) == Float32 | ||
| @test eltype(ssol.t) == typeof(sprob.tspan[1]) == typeof(sprob.tspan[2]) == Float32 | ||
| end | ||
|
|
||
| # Tests simulating a network without parameters. | ||
| let | ||
| no_param_network = @reaction_network begin | ||
|
|
||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we care about these remaining integers? That seems degenerate since at some point they will have to be converted to floating point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is asking for trouble since converting them earlier seems reasonable and could be implemented at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I really don't care what the type is. However I don't like the idea of theses suddenly jumping around (as it is likely non-intentional and a sign something else might be going on. And if it is intentional it is easy to switch here)
I will ask about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So apparently the current policy is for XProblem to not do any type promotion. I'm inclined to adding a comment to the test about the situation, and if how XProblems work changes we change the test (after confirming that it is intentional). The potential drawback seems small.
But if you want to remove I will do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d still prefer to use problem appropriate types. So use Float32/16/64 for such tests. It just seems like we are testing a degenerate case here that they could reasonably decide to promote at any moment (since ultimately it is getting promoted during solves), and could then break this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even use BigFloat if you want a less common type.