-
Notifications
You must be signed in to change notification settings - Fork 3
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 macro trixi_include_changeprecision
to make a double precision elixir run with single precision
#35
Conversation
Pull Request Test Coverage Report for Build 12471675311Details
💛 - Coveralls |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #35 +/- ##
==========================================
+ Coverage 95.00% 97.54% +2.54%
==========================================
Files 5 5
Lines 80 163 +83
==========================================
+ Hits 76 159 +83
Misses 4 4 ☔ View full report in Codecov by Sentry. |
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.
Fine by me, though I do not really understand most of the changes 😅. Would be good if @ranocha could give the final green light :-)
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! Why do you need this functionality?
I want to add a macro I could also add this macro to TrixiBase, but so far it will only be used by TrixiParticles. https://github.com/trixi-framework/TrixiParticles.jl/blob/ef/more-gpu-support/src/util.jl#L138-L163 |
This would be nice to have here |
trixi_include
more flexible by allowing a mapping to be passedtrixi_include_changeprecision
to make a double precision elixir run with single precision
I now moved the macro from TrixiParticles to this PR. |
Co-authored-by: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com>
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.
Could you please add a test before we merge this PR?
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.
LGTM in general and is certainly an interesting feature!
Before merging, I second @ranocha in that there should be a test for this - maybe using some temporary Julia file that will return a double floating point value but will then be changed to returning a Float32
value?
Back to @ranocha's question:
I just changed it to first replace assignments and then call trixi_include_changeprecision(Float32, elixir; density=1000.0) will make trixi_include_changeprecision(Float32, elixir; density=ones(nparticles)) Here, I also added tests for this. |
function replace_trixi_include(T, expr) | ||
expr = TrixiBase.walkexpr(expr) do x | ||
if x isa Expr | ||
if x.head === :call && x.args[1] === :trixi_include | ||
x.args[1] = :trixi_include_changeprecision | ||
insert!(x.args, 2, :($T)) | ||
end | ||
end | ||
return x | ||
end | ||
|
||
return expr | ||
end |
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.
One more problem here. This doesn't work when, for some reason, we would include an elixir that looks like this:
using TrixiBase
TrixiBase.trixi_include(...)
It only works when we directly write the elixir as
using TrixiBase
trixi_include(...)
@ranocha any ideas how to fix 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.
Can you special case this with something like Symbol("TrixiBase.trixi_include")?
Alternatively, @vchuravy might have an idea how this can be done?
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 tried, didn't work. Also, we would need to add a special case for each package that re-exports this name.
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 will be a GlobalRef(mod, name)
.
So x.args[1] isa GlobalRef
and then check the name and replace 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.
Doesn't work. x.args[1] isa GlobalRef
is false
.
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.
julia> TrixiBase.trixi_include_changeprecision(Float32, "../TrixiBase.jl/test1.jl")
[ Info: You just called `trixi_include`. Julia may now compile the code, please be patient.
ERROR: LoadError: UndefVarError: `TrixiBase.trixi_include_changeprecision` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
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.
But it looks like TrixiBase.trixi_include_changeprecision
is defined... Does your test file create a module? How does it import trixi_include
?
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.
Idk. The test file just contains this single line:
TrixiBase.trixi_include("test2.jl")
And the error message says we're in Main
.
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 should we merge it as is and discuss this in an issue? I don't feel like wasting more time on this edge case.
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 agree. IMHO if it is possible I'd just hard-code two versions for trixi_include
and TrixiBase.trixi_include
. If that's not feasible, just put it in the docstring that you need to invoke this in a certain way.
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.
LGTM! Let's wait and see if @vchuravy has an easy solution for the open conversation (if not, we can go ahead anyways)
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 merge this as it is and discuss possible improvements in an issue
This is similar to how
Base.include
is defined: