Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove convert type piracy from Reactant extension#5713

Merged
giordano merged 2 commits into
mainfrom
mg/rm-pirates
Jun 23, 2026
Merged

Remove convert type piracy from Reactant extension#5713
giordano merged 2 commits into
mainfrom
mg/rm-pirates

Conversation

@giordano

@giordano giordano commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Currently we have

julia> using Reactant

julia> convert(Float64, ConcretePJRTNumber(1.0))
1.0

julia> using Oceananigans

julia> convert(Float64, ConcretePJRTNumber(1.0))
ConcretePJRTNumber{Float64, 1}(1.0)

These methods are type piracy (behaviour of Reactant changes after you load Oceananigans) and not a good idea anyway (convert(T, x) should return an instance of T, otherwise why calling convert in the first place).

Ref: #5570 (comment).

@glwagner glwagner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder why we added these? cc @wsmoses

@wsmoses

wsmoses commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Huh yeah these are bad we should remove

@giordano

Copy link
Copy Markdown
Collaborator Author

wonder why we added these?

These were added by @dkytezab in #5570.

I see all the Reactant tests are failing now, I'll need to figure out how to adapt the code, but in any case these methods should be here around.

@glwagner

Copy link
Copy Markdown
Member

Looks like tests are failing on an attempt to call Float64(::Reactant.TracedRNumber{Float64})

@giordano

Copy link
Copy Markdown
Collaborator Author

That's coming from

return (time = convert(KT, clock.time),
last_Δt = convert(DT, clock.last_Δt),
last_stage_Δt = convert(DT, clock.last_stage_Δt),
iteration = clock.iteration,
stage = clock.stage)

@glwagner

Copy link
Copy Markdown
Member

So perhaps we need a different adapt_structure in the extension, or we need to extend the clock constructor so that DT = Reactant.TracedRNumber{Float64} ?

@wsmoses

wsmoses commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

who is calling Float(TracedRFloat) because that's definitely invalid

@giordano

Copy link
Copy Markdown
Collaborator Author

who is calling Float(TracedRFloat) because that's definitely invalid

#5713 (comment)

@wsmoses

wsmoses commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

oh sorry missed that

@giordano

Copy link
Copy Markdown
Collaborator Author

Should we just use a different function which isn't convert here?

@dkytezab

Copy link
Copy Markdown
Collaborator

sorry yes this is my fault! could we regress to the initial clock soln, storing kernel time as three separate args? Unless there is another way to demote that doesn't involve calling convert

This allows us to adapt `Clock`'s internal fields, without doing type piracy.
@glwagner

Copy link
Copy Markdown
Member

sorry yes this is my fault! could we regress to the initial clock soln, storing kernel time as three separate args? Unless there is another way to demote that doesn't involve calling convert

What if we use Reactant.TracedRNumber{Float64} for the "kernel time type" ?

@giordano

Copy link
Copy Markdown
Collaborator Author

Am I good to go with the current implementation? It does address the piracy issue, and it's minimally invasive, it doesn't change any data structure. Things like changing the kernel type may be done in follow up PRs, if that's a viable option.

@glwagner

Copy link
Copy Markdown
Member

Am I good to go with the current implementation? It does address the piracy issue, and it's minimally invasive, it doesn't change any data structure. Things like changing the kernel type may be done in follow up PRs, if that's a viable option.

yes, this is acceptable to me

@giordano giordano merged commit 78db36f into main Jun 23, 2026
86 of 87 checks passed
@giordano giordano deleted the mg/rm-pirates branch June 23, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants