-
-
Notifications
You must be signed in to change notification settings - Fork 104
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: adjoints through observable functions #689
Merged
Merged
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
92ad6a8
feat: adjoints through observable functions
DhairyaLGandhi 22dc7ec
Update ext/SciMLBaseZygoteExt.jl
DhairyaLGandhi 0c2b69d
feat: allow observables in collections
DhairyaLGandhi c61e08c
chore: handle no observables in collection
DhairyaLGandhi 8600a8d
fix: typo
DhairyaLGandhi a69d087
Merge branch 'master' into dg/obsfn
DhairyaLGandhi 785b052
test: add test for observable functions
DhairyaLGandhi adee4f0
test: add AD testset
DhairyaLGandhi 2197a30
Update test/downstream/observables_autodiff.jl
ChrisRackauckas 9172014
test: add a simple DAE example; disable till sensitivities are turned on
DhairyaLGandhi 95cf416
test: add missing imports
DhairyaLGandhi 4ce8257
chore: format
DhairyaLGandhi 839bd63
chore: rm unwanted adjoint
DhairyaLGandhi 2474a8d
test: check failures with SciMLSensitivity + SII
DhairyaLGandhi f68cb05
ci(SciMLSensitivity): checkout SII branch
DhairyaLGandhi 9ab29d9
ci(SciMLSensitivity): use correct path
DhairyaLGandhi a417cdd
ci: revert changes
DhairyaLGandhi ff9bb2c
chore: revert literal_getproperty adjoint
DhairyaLGandhi 032b927
chore: try to avoid returning object
DhairyaLGandhi 44bfc91
build: add MSL to test deps
DhairyaLGandhi de2d6cd
chore: don't return structural tangent
DhairyaLGandhi c63dfbf
chore: fix imports
DhairyaLGandhi 940ea78
test: add MSL to downstream env
DhairyaLGandhi 8e48f1c
test: rm MSL from test env
DhairyaLGandhi d061ce4
chore: format
DhairyaLGandhi f817b52
Update CI.yml
ChrisRackauckas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using ModelingToolkit, OrdinaryDiffEq | ||
using Zygote | ||
|
||
@parameters σ ρ β | ||
ChrisRackauckas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@variables x(t) y(t) z(t) w(t) | ||
|
||
eqs = [D(D(x)) ~ σ * (y - x), | ||
D(y) ~ x * (ρ - z) - y, | ||
D(z) ~ x * y - β * z, | ||
w ~ x + y + z + 2 * β] | ||
|
||
@mtkbuild sys = ODESystem(eqs, t) | ||
|
||
u0 = [D(x) => 2.0, | ||
x => 1.0, | ||
y => 0.0, | ||
z => 0.0] | ||
|
||
p = [σ => 28.0, | ||
ρ => 10.0, | ||
β => 8 / 3] | ||
|
||
tspan = (0.0, 100.0) | ||
prob = ODEProblem(sys, u0, tspan, p, jac = true) | ||
sol = solve(prob, Tsit5()) | ||
|
||
@testset "AutoDiff Observable Functions" begin | ||
gs, = gradient(sol) do sol | ||
sum(sol[sys.w]) | ||
end | ||
du_ = [0., 1., 1., 1.] | ||
du = [du_ for _ = sol.u] | ||
@test du == gs.u | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is this removed?
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.
It was returning the
ODESolution
as the adjoint. It is also an issue because it shortcuts the gradients through parameters and instead replaces it with thesol.prob
, whereas we need to accumulate the gradients 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.
Can you add a unit test in the downstream set which shows this is fine?
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.
Happy to. In fact, that's why I asked if anything was relying on this behavior previously. Could you suggest what kind of test you have in mind?
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 seems to be the root cause of many of the test failures? So that means it's caught by the tests already.
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 don't think this is what the error is referring to. I am missing a branch https://github.com/DhairyaLGandhi/RecursiveArrayTools.jl/tree/dg/noproj which removes an extra projection rule.
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.
It does refer to projecting to a
VectorOfArray
, and that rule wasn't defined forTangent
. Removing it gets us the expected results. If we want to project back to aVectorOfArray
type, then that needs to be handled elsewhere.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.
now that we have restored the adjoint, I believe this can be resolved