@@ -4,7 +4,7 @@ In this tutorial we will implement the SciMLStructures.jl interface for a parame
44object. This is useful when differentiating through ODE solves using SciMLSensitivity.jl
55and only part of the parameters are differentiable.
66
7- ``` @example
7+ ``` @example basic_tutorial
88using OrdinaryDiffEqTsit5
99using LinearAlgebra
1010
@@ -41,7 +41,7 @@ solve(prob, Tsit5())
4141
4242The ODE solves fine. Now let's try to differentiate with respect to the tunable parameters.
4343
44- ``` @example
44+ ``` @example basic_tutorial
4545using Zygote
4646using SciMLSensitivity
4747
@@ -60,7 +60,7 @@ SciMLSensitivity does not know how to handle the parameter object, because it do
6060implement the SciMLStructures interface. The bare minimum necessary for SciMLSensitivity
6161is the ` Tunable ` portion.
6262
63- ``` @example
63+ ``` @example basic_tutorial
6464import SciMLStructures as SS
6565
6666# Mark the struct as a SciMLStructure
112112
113113Now, we should be able to differentiate through the ODE solve.
114114
115- ``` @example
115+ ``` @example basic_tutorial
116116Zygote.gradient(0.1ones(length(SS.canonicalize(SS.Tunable(), p)[1]))) do tunables
117117 newp = SS.replace(SS.Tunable(), p, tunables)
118118 newprob = remake(prob; p = newp)
123123
124124We can also implement a ` Constants ` portion to store the rest of the values:
125125
126- ``` @example
126+ ``` @example basic_tutorial
127127SS.hasportion(::SS.Constants, ::Parameters) = true
128128
129129function SS.canonicalize(::SS.Constants, p::Parameters)
@@ -156,15 +156,15 @@ buf, repack, alias = SS.canonicalize(SS.Constants(), p)
156156buf
157157```
158158
159- ``` @example
159+ ``` @example basic_tutorial
160160repack(ones(length(buf)))
161161```
162162
163- ``` @example
163+ ``` @example basic_tutorial
164164SS.replace(SS.Constants(), p, ones(length(buf)))
165165```
166166
167- ``` @example
167+ ``` @example basic_tutorial
168168SS.replace!(SS.Constants(), p, ones(length(buf)))
169169p
170170```
0 commit comments