3131 )
3232end
3333
34+ # ╔═╡ 23a8503f-3c68-4523-aebe-a4ce4575a02b
35+ import Enzyme: ignore_derivatives
36+
3437# ╔═╡ df72e42f-7eec-476f-8ce5-72b09f620005
3538md """
3639# Reproducing "Stabilizing backpropagation through time to learn complex physics"
116119# ╔═╡ be852753-126d-42fa-a55c-c907f5dce99d
117120plot_gradientfield (N, S, x₀, y, θ₁, θ₂, n)
118121
119- # ╔═╡ 0b6d0456-1f94-479f-b690-89ad7fc61e44
120- begin
121- @noinline function ignore_derivatives (x:: T ) where {T}
122- return Core. inferencebarrier (x):: T
123- end
124-
125- function EnzymeRules. forward (
126- config,
127- :: Const{typeof(ignore_derivatives)} ,
128- A, x:: Duplicated
129- )
130- return Enzyme. make_zero (x. val)
131- end
132-
133- function EnzymeRules. augmented_primal (
134- config,
135- :: Const{typeof(ignore_derivatives)} ,
136- FA, x
137- )
138- primal = EnzymeRules. needs_primal (config) ? x. val : nothing
139- if x isa Active
140- shadow = nothing
141- else
142- shadow = Enzyme. make_zero (x. val)
143- end
144-
145- return EnzymeRules. AugmentedReturn (primal, shadow, nothing )
146- end
147- function EnzymeRules. reverse (
148- config,
149- :: Const{typeof(ignore_derivatives)} ,
150- dret:: Active , tape, x:: Active
151- )
152- return (Enzyme. make_zero (x. val),)
153- end
154-
155- function EnzymeRules. reverse (
156- config,
157- :: Const{typeof(ignore_derivatives)} ,
158- :: Type{<:Duplicated} , tape, x:: Duplicated
159- )
160- return (nothing ,)
161- end
162- end
163-
164122# ╔═╡ 873e7792-99a1-4472-92c2-6fc32e2889fa
165123N_stop (xᵢ, θ) = θ[1 ] * ignore_derivatives (xᵢ^ 2 ) + θ[2 ] * ignore_derivatives (xᵢ)
166124
@@ -170,6 +128,7 @@ plot_gradientfield(N_stop, S, x₀, y, θ₁, θ₂, n)
170128# ╔═╡ Cell order:
171129# ╠═b72e9218-81ba-11f0-1eba-5bd949c7ade4
172130# ╠═9f5c0822-a19a-4c63-95e7-d2f066a7440f
131+ # ╠═23a8503f-3c68-4523-aebe-a4ce4575a02b
173132# ╠═a4453d23-6e31-451f-b2cd-97346accac82
174133# ╠═bd0352c3-1b3c-42f5-ab93-7ca4cb67b9ad
175134# ╟─df72e42f-7eec-476f-8ce5-72b09f620005
@@ -182,6 +141,5 @@ plot_gradientfield(N_stop, S, x₀, y, θ₁, θ₂, n)
182141# ╠═45ee18f4-d6d3-40f4-bbc0-04cbd3b7b840
183142# ╠═ae6a671d-1559-4bff-af6e-78d2b54db020
184143# ╠═be852753-126d-42fa-a55c-c907f5dce99d
185- # ╠═0b6d0456-1f94-479f-b690-89ad7fc61e44
186144# ╠═873e7792-99a1-4472-92c2-6fc32e2889fa
187145# ╠═d71a22cc-c1f3-4425-8a6f-442a0bc4f215
0 commit comments