-
Notifications
You must be signed in to change notification settings - Fork 4
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
Careful handling of data types (Float32 & units) #108
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #108 +/- ##
==========================================
+ Coverage 98.24% 98.26% +0.02%
==========================================
Files 7 7
Lines 1538 1556 +18
==========================================
+ Hits 1511 1529 +18
Misses 27 27 ☔ View full report in Codecov by Sentry. |
The code linsolve.A = P3
@show linsolve.A
@show linsolve.b
A_tmp = Matrix(linsolve.A)
b_tmp = linsolve.b
linres = solve!(linsolve)
@show linres
@show A_tmp\b_tmp
integrator.stats.nsolve += 1
σ .= linres
@show ("6",σ) provides linsolve.A = sparse([1, 2, 1, 2, 3, 2, 3, 4, 3, 4], [1, 1, 2, 2, 2, 3, 3, 3, 4, 4], [1.0, -0.0, -0.0001306202464031375, 1.000130620246403, -0.0, -6.4983581002939935e59, 6.4983581002939935e59, -0.0, -3.400386856217244e261, 3.400386856217244e261], 4, 4)
linsolve.b = [2.2436232870583095, 4.756376712918744, 3.6441102462903125e-43, 0.0]
linres = [2.244244485015507, 4.755755514961547, -5.861544385515315e-76, 0.0]
A_tmp \ b_tmp = [2.244244485015507, 4.755755514961547, 5.60773997069421e-103, 0.0]
("6", σ) = ("6", [2.244244485015507, 4.755755514961547, -5.861544385515315e-76, 0.0]) So the problem is indeed a linear solve which introduces a negative element in the solution. |
@ranocha How shall we deal with this? It is clear on the analytical level that the solutions of the linear system should be nonnegative, since the matrix A is an M-matrix and the right hand side b is nonnegative. But I wonder if this is actually guaranteed on the numerical level? |
I don't think there is a simple way to guarantee this at the numerical level. Even small floating point errors can change a value that is zero to something slightly negative. In your example above, |
We could try to play with |
Setting |
The test below shows that for almost all schemes the constants have the same type as the algorithm input parameters. So all computations in The only exception is @testset "Float32" begin
algs = (MPRK22(0.5f0), MPRK22(1.0f0), MPRK22(2.0f0), MPRK43I(1.0f0, 0.5f0),
MPRK43I(0.5f0, 0.75f0), MPRK43II(0.5f0), MPRK43II(2.0f0 / 3.0f0),
SSPMPRK22(0.5f0, 1.0f0), SSPMPRK43())
@testset "$i" for (i, alg) in enumerate(algs)
@test eltype(PositiveIntegrators.get_constant_parameters(alg)) == Float32
end
algs = (MPRK22(0.5), MPRK22(1.0), MPRK22(2.0), MPRK43I(1.0, 0.5),
MPRK43I(0.5, 0.75), MPRK43II(0.5), MPRK43II(2.0 / 3.0),
SSPMPRK22(0.5, 1.0), SSPMPRK43())
@testset "$i" for (i, alg) in enumerate(algs)
@test eltype(PositiveIntegrators.get_constant_parameters(alg)) == Float64
end
end Test Summary: | Pass Fail Total Time
Float32 | 17 1 18 0.1s
1 | 1 1 0.0s
2 | 1 1 0.0s
3 | 1 1 0.0s
4 | 1 1 0.0s
5 | 1 1 0.0s
6 | 1 1 0.0s
7 | 1 1 0.0s
8 | 1 1 0.0s
9 | 1 1 0.0s
1 | 1 1 0.0s
2 | 1 1 0.0s
3 | 1 1 0.0s
4 | 1 1 0.1s
5 | 1 1 0.0s
6 | 1 1 0.0s
7 | 1 1 0.0s
8 | 1 1 0.0s
9 | 1 1 0.0s |
We call function get_constant_parameters(alg::MPRK22, ::Type{Tu}, ::Type{Tt}) where {Tu, Tt}
# ...
a21 = convert(Tu, alg.alpha)
b2 = convert(T0, 1 / (2 * a21))
b1 = convert(Tu, 1 - b2) instead of function get_constant_parameters(alg::MPRK22)
# ...
a21 = alg.alpha
b2 = 1 / (2 * a21)
b1 = 1 - b2 for |
What's the thinking behind this? Why would we want |
It's likely not something that we will use here, but OrdinaryDiffEq.jl allows using types with units or complex numbers for |
I think we can simplify it here and just pass |
…)PDSProblems and units
I came across https://discourse.julialang.org/t/unitful-jl-and-differentialequations-jl-compatibility/68594, where it is discussed that The post also mentions |
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.
Thanks! Please find below some suggestions
The Downgrade tests fail. Do you have an idea why? |
Is there a way to reproduce these locally? |
You can create Project.toml files with the versions of the direct dependencies listed in https://github.com/SKopecz/PositiveIntegrators.jl/actions/runs/10580596414/job/29315860050?pr=108#step:6:11 |
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
The downgrade tests didn't accept |
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.
Thanks!
perform_step