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
Add numerical support of other real types (Float32
)
#1909
base: main
Are you sure you want to change the base?
Conversation
Review checklistThis checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging. Purpose and scope
Code quality
Documentation
Testing
Performance
Verification
Created with ❤️ by the Trixi.jl community. |
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 a lot for your contribution. Please find below some comments/suggestions.
General question here: Is it better to conduct unit testing while making changes, or to perform the tests after completing all the changes? Are there any good examples of testing from this repository? Thanks! |
When you're working on numerical fluxes, you can add some unit tests, e.g., to parts like Lines 633 to 660 in 1745df4
for the compressible Euler equations. Here, you could add additional tests using inputs with eltype(u) == Float32 .
We should also add some full integration tests once something works completely - maybe by adding one or two new example elixirs showing how to run simulations with |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1909 +/- ##
=======================================
Coverage 96.15% 96.15%
=======================================
Files 454 454
Lines 36509 36535 +26
=======================================
+ Hits 35103 35129 +26
Misses 1406 1406
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Hi @ranocha I have revised the code based on our discussion. Please review it once more, and if this version is satisfactory, I will apply similar revisions to the subsequent tasks. For dual numbers, I have no idea whether it will be copied to the GPU and I think CUDA.jl does not directly support this type. If they are to be executed on GPUs, I will explore alternative methods (probably through For documentation, are you referring to a general overview that explains the purpose of using a function like |
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 a lot! I just have some minor suggestions.
For documentation, are you referring to a general overview that explains the purpose of using a function like oftype, or to detailed documentation that points to each specific instance in the code?
I had something in mind like adding a new section to https://trixi-framework.github.io/Trixi.jl/stable/conventions/ where we explain
- why we use
0.5f0 *
instead of0.5 *
- why we use patterns such as
RealT = eltype(x)
andv1_prime = zero(RealT)
orA = convert(RealT, 0.2)
There is no need to point to specific code lines from my point of view.
@sloede Could you please have a look as well? |
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! Let's please wait for a review by @sloede before you start modifying more files.
Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com>
I'm not sure it's worth writing something that can be achieved easily by julia> 0.5 == 0.5f0
true
julia> 0.4 == 0.4f0
false |
Fair enough. If it's properly documented somewhere, this should be sufficient. |
If we want to have a simple rule that's easy to remember, we should just recommend using https://github.com/SciML/OrdinaryDiffEq.jl/blob/438f34ba24bab5a2f6aa478850a267478cc53dea/src/perform_step/low_order_rk_perform_step.jl#L749C6-L749C28 |
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.
Nice, thanks! I just have two comments
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! The files you have changed here should be ready, aren't they? Thus, we can merge this?
I started some benchmarks locally to see whether there is any impact on our standard benchmark examples. I would like to check the results before merging this PR. |
@ranocha Yes and you prefer to break the whole thing into small pieces and merge them step by step? I originally thought this PR is for all the files in src/equations. Please note that this PR depends on another small PR, which is not merged. If you test the type stability, it will fail. Is the benchmark for precision or speed? |
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.
Yes and you prefer to break the whole thing into small pieces and merge them step by step? I originally thought this PR is for all the files in src/equations. Please note that this PR depends on another small PR, which is not merged. If you test the type stability, it will fail.
I prefer smaller PRs with clear scope. Big PRs become very hard to handle and to review. Could you maybe start adding some unit tests for this PR already, please? Everything that does not work since it relies on other changes can be marked as @test_broken
.
Is the benchmark for precision or speed?
Speed
Please wait. The test data normally covers as large range of inputs as possible. Why is a single set of data tested here for each equation? Lines 633 to 660 in 1745df4
|
We don't have infinitely many resources, so we just added some unit tests and checked whether the implementations behave generally well by running more involved simulation setups as a whole. |
Codecov favors my main branch PR here ;) |
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
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.
This also needs to be included in test/runtests.jl
to be picked up by CI.
# Run unit tests for various equations | ||
@testset "Float32 Type Stability" begin | ||
@timed_testset "Acoustic Perturbation 2D" begin | ||
v_mean_global = (0.0f0, 0.0f0) |
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 think it would be nice to test type stability here for both Float32
and Float64
, e.g.,
for RealT in (Float32, Float64)
v_mean_global = (zero(RealT), zero(RealT))
...
end
orientations = [1, 2] | ||
normal_direction = SVector(1.0f0, 1.0f0) | ||
|
||
@test eltype(initial_condition_constant(x, t, equations)) == Float32 |
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.
@test eltype(initial_condition_constant(x, t, equations)) == Float32 | |
@test eltype(@inferred initial_condition_constant(x, t, equations)) == Float32 |
We should also check type stability like this
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.
This is used for something like @test @inferred func(c1, c2, c3, ..) == c
. Not necessary here
(v_normal + sqrt(v_normal^2 + 4 * A * (p_local + B))) | ||
end | ||
|
||
# For the slip wall we directly set the flux as the normal velocity is zero | ||
return SVector(zero(eltype(u_inner)), | ||
return SVector(0, |
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.
Here, we use 0
, but below... 👇
Address parts of #591 and redo #1604.
Tasks: