Skip to content
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

feat: add doc example for implementing the interface #28

Merged
merged 4 commits into from
Nov 18, 2024

Conversation

AayushSabharwal
Copy link
Member

@AayushSabharwal AayushSabharwal commented Oct 17, 2024

Close #23

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Add any other context about the problem here.

@AayushSabharwal
Copy link
Member Author

AayushSabharwal commented Oct 17, 2024

Runs into

ERROR: MethodError: no method matching length(::Parameters{Vector{SubproblemParameters{Float64, Float64, Float64}}, Matrix{Float64}})
The function `length` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  length(::Base.MethodSpecializations)
   @ Base reflection.jl:1317
  length(::LLVM.VectorType)
   @ LLVM ~/.julia/packages/LLVM/joxPv/src/core/type.jl:382
  length(::DataStructures.SparseIntSet)
   @ DataStructures ~/.julia/packages/DataStructures/95DJa/src/sparse_int_set.jl:61
  ...

Stacktrace:
  [1] (::SciMLSensitivity.var"#330#339"{})()
    @ SciMLSensitivity ~/.julia/packages/SciMLSensitivity/XCu1T/src/concrete_solve.jl:838
  [2] unthunk
    @ ~/.julia/packages/ChainRulesCore/6Pucz/src/tangent_types/thunks.jl:205 [inlined]
  [3] wrap_chainrules_output
    @ ~/.julia/packages/Zygote/NRp5C/src/compiler/chainrules.jl:110 [inlined]
  [4] map
    @ ./tuple.jl:357 [inlined]
  [5] map (repeats 3 times)
    @ ./tuple.jl:358 [inlined]
  [6] wrap_chainrules_output
    @ ~/.julia/packages/Zygote/NRp5C/src/compiler/chainrules.jl:111 [inlined]
  [7] ZBack
    @ ~/.julia/packages/Zygote/NRp5C/src/compiler/chainrules.jl:212 [inlined]
  [8] #294
    @ ~/.julia/packages/Zygote/NRp5C/src/lib/lib.jl:206 [inlined]
  [9] (::Zygote.var"#2276#back#296"{})(Δ::ODESolution{…})
    @ Zygote ~/.julia/packages/ZygoteRules/M4xmc/src/adjoint.jl:72
 [10] #solve#51
    @ ~/.julia/packages/DiffEqBase/ODi5x/src/solve.jl:1015 [inlined]
 [11] (::Zygote.Pullback{…})(Δ::ODESolution{…})
    @ Zygote ~/.julia/packages/Zygote/NRp5C/src/compiler/interface2.jl:0
 [12] #294
    @ ~/.julia/packages/Zygote/NRp5C/src/lib/lib.jl:206 [inlined]
 [13] #2276#back
    @ ~/.julia/packages/ZygoteRules/M4xmc/src/adjoint.jl:72 [inlined]
 [14] solve
    @ ~/.julia/packages/DiffEqBase/ODi5x/src/solve.jl:1005 [inlined]
 [15] (::Zygote.Pullback{…})(Δ::ODESolution{…})
    @ Zygote ~/.julia/packages/Zygote/NRp5C/src/compiler/interface2.jl:0
 [16] #68
    @ ./REPL[58]:3 [inlined]
 [17] (::Zygote.Pullback{Tuple{…}, Tuple{…}})(Δ::Float64)
    @ Zygote ~/.julia/packages/Zygote/NRp5C/src/compiler/interface2.jl:0
 [18] (::Zygote.var"#78#79"{Zygote.Pullback{Tuple{}, Tuple{}}})(Δ::Float64)
    @ Zygote ~/.julia/packages/Zygote/NRp5C/src/compiler/interface.jl:91
 [19] gradient(f::Function, args::Parameters{Vector{SubproblemParameters{Float64, Float64, Float64}}, Matrix{Float64}})
    @ Zygote ~/.julia/packages/Zygote/NRp5C/src/compiler/interface.jl:148
 [20] top-level scope
    @ REPL[58]:1
Some type information was truncated. Use `show(err)` to see complete types.

@ChrisRackauckas
Copy link
Member

@DhairyaLGandhi can you look into this?

@DhairyaLGandhi
Copy link
Member

Yes, let me take a look

@albertomercurio
Copy link

albertomercurio commented Nov 13, 2024

Hello, is it possible to add an example that also includes Constants, Caches and Discrete? How do we use the repack and replace functions for any of them? Is it exactly the same as for Tunable parts?

Moreover, what if I have different Caches like a Vector and a Matrix? Should I canonicalize them as a vector? Also for the Discrete I may have many different types.

@AayushSabharwal
Copy link
Member Author

AayushSabharwal commented Nov 14, 2024

is it possible to add an example that also includes Constants, Caches and Discrete?

I'll add Constants here, and mention that caches and discrete are identical.

How do we use the repack and replace functions for any of them? Is it exactly the same as for Tunable parts?

Basically yeah. repack is basically just replace. canonicalize, replace and replace! effectively agree on an implicit ordering for all elements of a portion. canonicalize takes the parameter object and outputs the array in that order. Given an array in said order, replace (replace!) creates a new parameter object (resp. writes back to the same object) assuming the array passed to it is in the correct order.

Moreover, what if I have different Caches like a Vector and a Matrix? Should I canonicalize them as a vector?

Yes, they need to be flattened and concatenated.

Also for the Discrete I may have many different types.

They need to be concatenated into one type-unstable array

@ChrisRackauckas
Copy link
Member

What's left here?

@AayushSabharwal
Copy link
Member Author

I have the doc changes ready, SciMLSensitivity needs a tag

@ChrisRackauckas
Copy link
Member

All of the SciMLStructures changes that were ready were tagged last week?

@ChrisRackauckas ChrisRackauckas merged commit b13c3a3 into SciML:main Nov 18, 2024
2 of 4 checks passed
@ChrisRackauckas
Copy link
Member

🎉

@AayushSabharwal AayushSabharwal deleted the as/doc-example branch November 19, 2024 05:48
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.

Examples in docs or ReadMe?
4 participants