-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Update to using SII and SciMLStructures #1057
Conversation
This uses the SciMLStructures Tunable interface https://github.com/SciML/SciMLStructures.jl in order to allow more generalized definitions of `p`. - [ ] Ensure Lux.jl is well supported (componentarrays extension in SciMLStructures - [ ] Add a test for a custom SciMLStructure
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.
Just minor things
src/forward_sensitivity.jl
Outdated
@@ -158,7 +158,7 @@ function ODEForwardSensitivityProblem(f::F, args...; kwargs...) where {F} | |||
end | |||
|
|||
function ODEForwardSensitivityProblem(prob::ODEProblem, alg; kwargs...) | |||
ODEForwardSensitivityProblem(prob.f, prob.u0, prob.tspan, prob.p, alg; kwargs...) | |||
ODEForwardSensitivityProblem(symbolic_container(prob), state_values(prob), prob.tspan, parameter_values(prob), alg; kwargs...) |
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.
symbolic_container
technically does returns prob.f
, however semantically it isn't guaranteed to do so and in such cases where you explicitly wand the function, I'd still use prob.f
.
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 has been addressed
Co-authored-by: Aayush Sabharwal <[email protected]>
…into dg/structures
src/concrete_solve.jl
Outdated
@@ -354,14 +361,15 @@ function DiffEqBase._concrete_solve_adjoint( | |||
sol = solve(_prob, alg, args...; save_noise = true, save_start = true, | |||
save_end = true, kwargs_fwd...) | |||
end | |||
time = current_time(sol) |
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.
what's current time from?
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.
src/concrete_solve.jl
Outdated
ts = sol.t | ||
ts = time |
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 change the standard naming? Naming an array time
instead of a scalar value is weird and not grammatically correct...
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 used it where there were multiple calls to sol.t
. I wanted to avoid multiple calls to current_time
when something like sol.t
was referenced multiple times, since field access might be free, function calls potentially may not be.
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 can change the naming or potentially if there's a better solution, can implement that
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.
That's fine, it could still be called ts
. If you want to write it, times
. But I don't understand why syntactic changes are mixed with a feature 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.
I can change it to be ts
- being shorter to write.
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.
…into dg/structures
…into dg/structures
The shadowing tests are passing now as well. The MWE for the DiffEqFlux failures is: julia> ca = ComponentVector((x = rand(3), y = rand(4),)) # start with a component array
ComponentVector{Float64}(x = [0.2755239169592659, 0.2144463395930084, 0.9085629964224934], y = [0.122401457810142, 0.498989539972836, 0.7718946152650026, 0.9715871491699061]
)
julia> tr = Tracker.param(ca) # use Tracker as the backend
ComponentVector{Float64, TrackedVector{Float64, Vector{Float64}}, Tuple{Axis{(x = 1:3, y = 4:7)}}}(x = [0.2755239169592659, 0.2144463395930084, 0.9085629964224934] (tracked), y = [0.122401457810142, 0.498989539972836, 0.7718946152650026, 0.9715871491699061] (tracked))
julia> convert(typeof(ca), tr) # convert call masks the type of the underlying array
Tracked 7-element ComponentVector{Float64, Vector{Float64}, Tuple{Axis{(x = 1:3, y = 4:7)}}} with indices 1:1:7:
0.2755239169592659
0.2144463395930084
0.9085629964224934
0.122401457810142
0.498989539972836
0.7718946152650026
0.9715871491699061
julia> Float64.(tr)
Tracked 7-element ComponentVector{Float64, Vector{Float64}, Tuple{Axis{(x = 1:3, y = 4:7)}}} with indices 1:1:7:
0.2755239169592659
0.2144463395930084
0.9085629964224934
0.122401457810142
0.498989539972836
0.7718946152650026
0.9715871491699061 The specific convert method is https://github.com/jonniedie/ComponentArrays.jl/blob/554a9c03373680af84586762f68ebd32b6d34abe/src/similar_convert_copy.jl#L55 which seems to be missing a case where function Base.convert(::Type{ComponentArray{T,N,A1,Ax1}}, x::ComponentArray{T,N,A2,Ax2}) where {T,N,A1,A2,Ax1,Ax2}
return x
end |
Can you PR that? If @jonniedie has a quick turnaround then I think we're close to done here. |
|
||
if !isautojacvec | ||
if DiffEqBase.has_paramjac(f) | ||
f.paramjac(pJ, y, p, t) # Calculate the parameter Jacobian into pJ | ||
else | ||
pf.t = t | ||
pf.u = y |
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.
While working through this PR, I found this path which was not updating the caches. I have added this here, but wanted to highlight for correctness
@wsmoses we're seeing something odd with the latest Enzyme release as well. |
@ChrisRackauckas how so, what’s the failure ? |
same as @avik-pal is mentioning is seen in CI here Continuous and discrete costs: Error During Test at /home/runner/.julia/packages/SafeTestsets/raUNr/src/SafeTestsets.jl:30
Got exception outside of a @test
LoadError: MethodError: no method matching cpu_features!(::LLVM.ModulePassManager)
Closest candidates are:
cpu_features!(::LLVM.Module)
@ GPUCompiler ~/.julia/packages/GPUCompiler/05oYT/src/optim.jl:606
Stacktrace:
[1] (::Enzyme.Compiler.var"#28472#28473"{LLVM.Module, LLVM.TargetMachine})(pm::LLVM.ModulePassManager)
@ Enzyme.Compiler ~/.julia/packages/Enzyme/qd8AI/src/compiler/optimize.jl:1941
[2] LLVM.ModulePassManager(::Enzyme.Compiler.var"#28472#28473"{LLVM.Module, LLVM.TargetMachine}; kwargs::@Kwargs{})
@ LLVM ~/.julia/packages/LLVM/5DlHM/src/passmanager.jl:33
[3] LLVM.ModulePassManager(::Function)
@ LLVM ~/.julia/packages/LLVM/5DlHM/src/passmanager.jl:30
[4] optimize!(mod::LLVM.Module, tm::LLVM.TargetMachine) |
Hm odd, post that backtrace as an issue and I’ll try to solve it tomorrow
…On Thu, Jun 27, 2024 at 10:58 PM Christopher Rackauckas < ***@***.***> wrote:
same as @avik-pal <https://github.com/avik-pal> is mentioning is seen in
CI here
Continuous and discrete costs: Error During Test at /home/runner/.julia/packages/SafeTestsets/raUNr/src/SafeTestsets.jl:30
Got exception outside of a @test
LoadError: MethodError: no method matching cpu_features!(::LLVM.ModulePassManager)
Closest candidates are:
cpu_features!(::LLVM.Module)
@ GPUCompiler ~/.julia/packages/GPUCompiler/05oYT/src/optim.jl:606
Stacktrace:
[1] (::Enzyme.Compiler.var"#28472#28473"{LLVM.Module, LLVM.TargetMachine})(pm::LLVM.ModulePassManager)
@ Enzyme.Compiler ~/.julia/packages/Enzyme/qd8AI/src/compiler/optimize.jl:1941
[2] LLVM.ModulePassManager(::Enzyme.Compiler.var"#28472#28473"{LLVM.Module, LLVM.TargetMachine}; ***@***.***{})
@ LLVM ~/.julia/packages/LLVM/5DlHM/src/passmanager.jl:33
[3] LLVM.ModulePassManager(::Function)
@ LLVM ~/.julia/packages/LLVM/5DlHM/src/passmanager.jl:30
[4] optimize!(mod::LLVM.Module, tm::LLVM.TargetMachine)
—
Reply to this email directly, view it on GitHub
<#1057 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJTUXCEIZE6D3KWULVVK3TZJR4I3AVCNFSM6AAAAABIDDSPO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJVGY2TKOJWHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Oh I think this is the llvm.jl bump changing api (it was done properly with
a change which did semver but it passed ci so I assume we didn’t hit).
…On Thu, Jun 27, 2024 at 10:59 PM Billy Moses ***@***.***> wrote:
Hm odd, post that backtrace as an issue and I’ll try to solve it tomorrow
On Thu, Jun 27, 2024 at 10:58 PM Christopher Rackauckas <
***@***.***> wrote:
> same as @avik-pal <https://github.com/avik-pal> is mentioning is seen in
> CI here
>
> Continuous and discrete costs: Error During Test at /home/runner/.julia/packages/SafeTestsets/raUNr/src/SafeTestsets.jl:30
> Got exception outside of a @test
> LoadError: MethodError: no method matching cpu_features!(::LLVM.ModulePassManager)
>
> Closest candidates are:
> cpu_features!(::LLVM.Module)
> @ GPUCompiler ~/.julia/packages/GPUCompiler/05oYT/src/optim.jl:606
>
> Stacktrace:
> [1] (::Enzyme.Compiler.var"#28472#28473"{LLVM.Module, LLVM.TargetMachine})(pm::LLVM.ModulePassManager)
> @ Enzyme.Compiler ~/.julia/packages/Enzyme/qd8AI/src/compiler/optimize.jl:1941
> [2] LLVM.ModulePassManager(::Enzyme.Compiler.var"#28472#28473"{LLVM.Module, LLVM.TargetMachine}; ***@***.***{})
> @ LLVM ~/.julia/packages/LLVM/5DlHM/src/passmanager.jl:33
> [3] LLVM.ModulePassManager(::Function)
> @ LLVM ~/.julia/packages/LLVM/5DlHM/src/passmanager.jl:30
> [4] optimize!(mod::LLVM.Module, tm::LLVM.TargetMachine)
>
> —
> Reply to this email directly, view it on GitHub
> <#1057 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAJTUXCEIZE6D3KWULVVK3TZJR4I3AVCNFSM6AAAAABIDDSPO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJVGY2TKOJWHA>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
On enzyme CI it installed v7 so didn't really check the correct thing. Really wish there was a way to remove old deps in CompatHelper PRs and push another change with the old deps inplace once tests pass. (I would have guessed the force_latest_versions kwarg in test does this) |
@ChrisRackauckas @avik-pal does this fix? |
src/adjoint_common.jl
Outdated
@@ -34,12 +34,14 @@ function adjointdiffcache(g::G, sensealg, discrete, sol, dgdu::DG1, dgdp::DG2, f | |||
prob = sol.prob | |||
u0 = state_values(prob) | |||
p = parameter_values(prob) | |||
if p === nothing || p isa SciMLBase.NullParameters | |||
if p === nothing || p === DiffEqBase.NullParameters() |
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 the change to DiffEq? Should be SciML
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.
Got it
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Moves SciMLSensitivity to use the SII and SciMLStructures' interface.
Add any other context about the problem here.