# Parameter Estimation of ODE system where the response variables are not the state variables

**URL:** <https://discourse.julialang.org/t/parameter-estimation-of-ode-system-where-the-response-variables-are-not-the-state-variables/86171>\
**Category:** Optimization (Mathematical)\
**Tags:** question, diffeq\
**Created:** [August 23, 2022, 3:46am UTC](https://discourse.julialang.org/t/parameter-estimation-of-ode-system-where-the-response-variables-are-not-the-state-variables/86171 "2022-08-23T03:46:03Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![jonlym](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonlym/32/20007_2.png) [@jonlym](https://discourse.julialang.org/u/jonlym)\
**Post date:** [August 24, 2022, 7:01pm UTC](https://discourse.julialang.org/t/parameter-estimation-of-ode-system-where-the-response-variables-are-not-the-state-variables/86171/4 "2022-08-24T19:01:00Z")

</div>

So I modified my code based on these examples:

- [Optimization of Ordinary Differential Equations · SciMLSensitivity.jl](https://sensitivity.sciml.ai/dev/ode_fitting/optimization_ode/)
- [Parameter Estimation on Highly Stiff Systems · SciMLSensitivity.jl](https://sensitivity.sciml.ai/dev/ode_fitting/stiff_ode_fit/)

But when I run it, it throws an error (see code and complete traceback at the bottom of the post). My guess is this section is the most relevant:

```julia
warning: Linking two modules of different target triples: 'bcloader' is 'x86_64-w64-windows-gnu' whereas 'text' is 'x86_64-w64-mingw32'

warning: Linking two modules of different target triples: 'bcloader' is 'x86_64-w64-windows-gnu' whereas 'text' is 'x86_64-w64-mingw32'

warning: Linking two modules of different target triples: 'bcloader' is 'x86_64-w64-windows-gnu' whereas 'text' is 'x86_64-w64-mingw32'

┌ Warning: Using fallback BLAS replacements, performance may be degraded
└ @ Enzyme.Compiler C:\Users\Jon\.julia\packages\GPUCompiler\jVY4I\src\utils.jl:35
ERROR: LoadError: Compiling Tuple{Type{Dict}, Base.Generator{Base.Iterators.Enumerate{Vector{Symbol}}, SciMLBase.var"#516#517"}}: try/catch is not supported.
Refer to the Zygote documentation for fixes.
https://fluxml.ai/Zygote.jl/latest/limitations

```

My code doesn’t use any try/catch statements, so I think I need to resolve the two modules having different target triples? I’m not sure what that means. Do you have any advice?

**Code**

```julia
using CSV
using DataFrames
using DifferentialEquations
using DiffEqParamEstim
using Optimization
using OptimizationOptimJL
using LinearAlgebra
using OptimizationPolyalgorithms
using SciMLSensitivity

"""ODE representing steady-state, isothermal, isobaric 1D PFR""" 
function pfr_ode!(dζ_dz, ζ, logk, z, v_mat, Fj0)
    # Calculate rate constants
    k = 10.0.^logk;
    # Calculate molar flow rate
    Fj = Fj0 .+ ζ * v_mat;
    # Calculate mole fractions
    xj = Fj / sum(Fj);
    # Calculate derivatives
    dζ_dz[1] = k[1] * xj[1] * xj[2];
    dζ_dz[2] = k[2] * (xj[1]^2.0);
    return nothing;
end

"""Custom loss function for pfr_ode by calculating L2 norm of Fj"""
function pfr_loss_func(p, prob, z_vec, Fj_obs, v_mat, Fj0)
    sol = DifferentialEquations.solve(prob, Tsit5(), p=p, saveat=z_vec)

    tot_loss = 0.0;
    if (sol.retcode != :Success)
        tot_loss = Inf;
    else
        # Calculate molar flow rates
        ζ_df = DataFrame(sol);
        rename!(ζ_df, ["z", "ζ1", "ζ2"]);
        ζ = Matrix(ζ_df[:, ["ζ1", "ζ2"]]);
        Fj = repeat(Fj0, size(ζ)[1]) .+ ζ * v_mat;

        tot_loss = LinearAlgebra.norm(Fj .- Fj_obs, 2);
    end
    return tot_loss;
end

"""Callback function to observe training"""
function callback(p, l, pred)
    println("Loss: $l");
    println("Parameters: $p");
    println("-")
    return false;
end

function main()
    # Read CSV file for response variables
    Fj_obs_df = CSV.read("./pfr_results.csv", DataFrame);
    z_vec = convert(Array, Fj_obs_df[:, "z"]);
    Fj_obs = Matrix(Fj_obs_df[:, r"F_"]);

    ζ0 = [0. 0.]; # Initial extent of reaction in mol/s. (The initial condition)
    zspan = (0.0,1.0); # Dimensionless axial position
    species_names = ["A" "B" "C" "D"];

    # Experimental settings
    Fj0 = [10. 20. 0. 0.]; # Feed molar flow rate (mol/s)

    # Stoichiometric matrix
    # A B C D
    v_mat = [-1. -1. 1. 0.; # A + B -> C
             -2. 0. 0. 1]; # 2A -> D
    logk0 = [1.5, 1.5]; # Initial parameter guesses. True logk0 is [1., 2.]

    # Assigning variables that will be known when doing parameter estimation

    pfr_ode1!(dζ_dz, ζ, logk, z) = pfr_ode!(dζ_dz, ζ, logk, z, v_mat, Fj0);

    # Define the ODE
    prob = DifferentialEquations.ODEProblem(pfr_ode1!, ζ0, zspan, logk0);

    # Assign values to loss function
    pfr_loss_func1(p) = pfr_loss_func(p, prob, z_vec, Fj_obs, v_mat, Fj0);

    # Optimize parameters
    adtype = Optimization.AutoZygote();
    optf = Optimization.OptimizationFunction((x,p)->pfr_loss_func1(x), adtype);
    optprob = Optimization.OptimizationProblem(optf, logk0)

    result_ode = Optimization.solve(optprob,
                                    OptimizationPolyalgorithms.PolyOpt(),
                                    callback=callback,
                                    maxiters=100);
    return nothing;
end

main();

```

**Julia Version and Installed Packages**

```julia
julia> VERSION
v"1.8.0"

julia> Pkg.status()
Status `C:\Users\Jon\.julia\environments\v1.8\Project.toml`
  [336ed68f] CSV v0.10.4
  [a93c6f00] DataFrames v1.3.4
  [1130ab10] DiffEqParamEstim v1.26.0
  [0c46a032] DifferentialEquations v7.2.0
  [7f7a1694] Optimization v3.8.2
  [36348300] OptimizationOptimJL v0.1.2
  [500b13db] OptimizationPolyalgorithms v0.1.0
  [91a5bcdd] Plots v1.31.7
  [1ed8b502] SciMLSensitivity v7.6.1
  [37e2e46d] LinearAlgebra

```

**Full Traceback**

```julia
PS C:\Users\Jon\Downloads\toy_julia_model\toy_julia_model> julia .\PfrParamEstMWE.jl 
warning: Linking two modules of different target triples: 'bcloader' is 'x86_64-w64-windows-gnu' whereas 'text' is 'x86_64-w64-mingw32'

warning: Linking two modules of different target triples: 'bcloader' is 'x86_64-w64-windows-gnu' whereas 'text' is 'x86_64-w64-mingw32'

warning: Linking two modules of different target triples: 'bcloader' is 'x86_64-w64-windows-gnu' whereas 'text' is 'x86_64-w64-mingw32'

┌ Warning: Using fallback BLAS replacements, performance may be degraded
└ @ Enzyme.Compiler C:\Users\Jon\.julia\packages\GPUCompiler\jVY4I\src\utils.jl:35
ERROR: LoadError: Compiling Tuple{Type{Dict}, Base.Generator{Base.Iterators.Enumerate{Vector{Symbol}}, SciMLBase.var"#516#517"}}: try/catch is not supported.
Refer to the Zygote documentation for fixes.
https://fluxml.ai/Zygote.jl/latest/limitations

Stacktrace:
  [1] error(s::String)
    @ Base .\error.jl:35
  [2] instrument(ir::IRTools.Inner.IR)
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\reverse.jl:121
  [3] #Primal#23
    @ C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\reverse.jl:205 [inlined]
  [4] Zygote.Adjoint(ir::IRTools.Inner.IR; varargs::Nothing, normalise::Bool)
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\reverse.jl:330
  [5] _generate_pullback_via_decomposition(T::Type)
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\emit.jl:101
  [6] #s2772#1066
    @ C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface2.jl:28 [inlined]
  [7] var"#s2772#1066"(::Any, ctx::Any, f::Any, args::Any)
    @ Zygote .\none:0
  [8] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any})
    @ Core .\boot.jl:582
  [9] _pullback
    @ C:\Users\Jon\.julia\packages\SciMLBase\DPsGA\src\tabletraits.jl:13 [inlined]
 [10] _pullback(::Zygote.Context{false}, ::Type{SciMLBase.AbstractTimeseriesSolutionRows}, ::Vector{Symbol}, ::Vector{Type}, ::Vector{Float64}, ::Vector{Matrix{Float64}})
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface2.jl:0
 [11] _pullback
    @ C:\Users\Jon\.julia\packages\SciMLBase\DPsGA\src\tabletraits.jl:40 [inlined]
 [12] _pullback(ctx::Zygote.Context{false}, f::typeof(Tables.rows), args::ODESolution{Float64, 3, Vector{Matrix{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Matrix{Float64}}}, ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Vector{Matrix{Float64}}, Vector{Float64}, Vector{Vector{Matrix{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats})
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface2.jl:0
 [13] _pullback
    @ C:\Users\Jon\.julia\packages\SciMLBase\DPsGA\src\tabletraits.jl:2 [inlined]
 [14] _pullback(ctx::Zygote.Context{false}, f::typeof(Tables.columns), args::ODESolution{Float64, 3, Vector{Matrix{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Matrix{Float64}}}, ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Vector{Matrix{Float64}}, Vector{Float64}, Vector{Vector{Matrix{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats})
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface2.jl:0
 [15] _pullback
    @ C:\Users\Jon\.julia\packages\DataFrames\zqFGs\src\other\tables.jl:58 [inlined]
 [16] _pullback(::Zygote.Context{false}, ::DataFrames.var"##DataFrame#796", ::Nothing, ::Type{DataFrame}, ::ODESolution{Float64, 3, Vector{Matrix{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Matrix{Float64}}}, ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Vector{Matrix{Float64}}, Vector{Float64}, Vector{Vector{Matrix{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats})
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface2.jl:0
 [17] _pullback
    @ C:\Users\Jon\.julia\packages\DataFrames\zqFGs\src\other\tables.jl:48 [inlined]
 [18] _pullback(ctx::Zygote.Context{false}, f::Type{DataFrame}, args::ODESolution{Float64, 3, Vector{Matrix{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Matrix{Float64}}}, ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Vector{Matrix{Float64}}, Vector{Float64}, Vector{Vector{Matrix{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats})
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface2.jl:0
 [19] _pullback
    @ C:\Users\Jon\Downloads\toy_julia_model\toy_julia_model\PfrParamEstMWE.jl:34 [inlined]
 [20] _pullback(::Zygote.Context{false}, ::typeof(pfr_loss_func), ::Vector{Float64}, ::ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, ::Vector{Float64}, ::Matrix{Float64}, ::Matrix{Float64}, ::Matrix{Float64})
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface2.jl:0
 [21] _pullback
    @ C:\Users\Jon\Downloads\toy_julia_model\toy_julia_model\PfrParamEstMWE.jl:79 [inlined]
 [22] _pullback
    @ C:\Users\Jon\Downloads\toy_julia_model\toy_julia_model\PfrParamEstMWE.jl:83 [inlined]
 [23] _pullback(::Zygote.Context{false}, ::var"#1#4"{var"#pfr_loss_func1#3"{ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, Vector{Float64}}}, ::Vector{Float64}, ::SciMLBase.NullParameters)
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface2.jl:0
 [24] _apply(::Function, ::Vararg{Any})
    @ Core .\boot.jl:816
 [25] adjoint
    @ C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\lib\lib.jl:203 [inlined]
 [26] _pullback
    @ C:\Users\Jon\.julia\packages\ZygoteRules\AIbCs\src\adjoint.jl:65 [inlined]
 [27] _pullback
    @ C:\Users\Jon\.julia\packages\SciMLBase\DPsGA\src\scimlfunctions.jl:3024 [inlined]
 [28] _pullback(::Zygote.Context{false}, ::OptimizationFunction{true, Optimization.AutoZygote, var"#1#4"{var"#pfr_loss_func1#3"{ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, Vector{Float64}}}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, ::Vector{Float64}, ::SciMLBase.NullParameters)
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface2.jl:0
 [29] _apply(::Function, ::Vararg{Any})
    @ Core .\boot.jl:816
 [30] adjoint
    @ C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\lib\lib.jl:203 [inlined]
 [31] _pullback
    @ C:\Users\Jon\.julia\packages\ZygoteRules\AIbCs\src\adjoint.jl:65 [inlined]
 [32] _pullback
    @ C:\Users\Jon\.julia\packages\Optimization\6nIwk\src\function\zygote.jl:30 [inlined]
 [33] _pullback(ctx::Zygote.Context{false}, f::Optimization.var"#136#146"{OptimizationFunction{true, Optimization.AutoZygote, var"#1#4"{var"#pfr_loss_func1#3"{ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, Vector{Float64}}}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, SciMLBase.NullParameters}, args::Vector{Float64})
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface2.jl:0
 [34] _apply(::Function, ::Vararg{Any})
    @ Core .\boot.jl:816
 [35] adjoint
    @ C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\lib\lib.jl:203 [inlined]
 [36] _pullback
    @ C:\Users\Jon\.julia\packages\ZygoteRules\AIbCs\src\adjoint.jl:65 [inlined]
 [37] _pullback
    @ C:\Users\Jon\.julia\packages\Optimization\6nIwk\src\function\zygote.jl:32 [inlined]
 [38] _pullback(ctx::Zygote.Context{false}, f::Optimization.var"#139#149"{Tuple{}, Optimization.var"#136#146"{OptimizationFunction{true, Optimization.AutoZygote, var"#1#4"{var"#pfr_loss_func1#3"{ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, Vector{Float64}}}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, SciMLBase.NullParameters}}, args::Vector{Float64})
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface2.jl:0
 [39] pullback(f::Function, cx::Zygote.Context{false}, args::Vector{Float64})
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface.jl:44
 [40] pullback
    @ C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface.jl:42 [inlined]
 [41] gradient(f::Function, args::Vector{Float64})
    @ Zygote C:\Users\Jon\.julia\packages\Zygote\qGFGD\src\compiler\interface.jl:96
 [42] (::Optimization.var"#137#147"{Optimization.var"#136#146"{OptimizationFunction{true, Optimization.AutoZygote, var"#1#4"{var"#pfr_loss_func1#3"{ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, Vector{Float64}}}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, SciMLBase.NullParameters}})(::Vector{Float64}, ::Vector{Float64})
    @ Optimization C:\Users\Jon\.julia\packages\Optimization\6nIwk\src\function\zygote.jl:32
 [43] macro expansion
    @ C:\Users\Jon\.julia\packages\OptimizationOptimisers\XLPqT\src\OptimizationOptimisers.jl:35 [inlined]
 [44] macro expansion
    @ C:\Users\Jon\.julia\packages\Optimization\6nIwk\src\utils.jl:35 [inlined]
 [45] __solve(prob::OptimizationProblem{true, OptimizationFunction{true, Optimization.AutoZygote, var"#1#4"{var"#pfr_loss_func1#3"{ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, Vector{Float64}}}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, SciMLBase.NullParameters, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, opt::Optimisers.Adam{Float64}, data::Base.Iterators.Cycle{Tuple{Optimization.NullData}}; maxiters::Int64, callback::Function, progress::Bool, save_best::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ OptimizationOptimisers C:\Users\Jon\.julia\packages\OptimizationOptimisers\XLPqT\src\OptimizationOptimisers.jl:33
 [46] #solve#509
    @ C:\Users\Jon\.julia\packages\SciMLBase\DPsGA\src\solve.jl:71 [inlined]
 [47] __solve(::OptimizationProblem{true, OptimizationFunction{true, Optimization.AutoZygote, var"#1#4"{var"#pfr_loss_func1#3"{ODEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, var"#pfr_ode1!#2"{Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, Vector{Float64}}}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, SciMLBase.NullParameters, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, ::PolyOpt; maxiters::Int64, kwargs::Base.Pairs{Symbol, typeof(callback), Tuple{Symbol}, NamedTuple{(:callback,), Tuple{typeof(callback)}}})
    @ OptimizationPolyalgorithms C:\Users\Jon\.julia\packages\OptimizationPolyalgorithms\5gDHf\src\OptimizationPolyalgorithms.jl:25
 [48] #solve#509
    @ C:\Users\Jon\.julia\packages\SciMLBase\DPsGA\src\solve.jl:71 [inlined]
 [49] main()
    @ Main C:\Users\Jon\Downloads\toy_julia_model\toy_julia_model\PfrParamEstMWE.jl:86
 [50] top-level scope
    @ C:\Users\Jon\Downloads\toy_julia_model\toy_julia_model\PfrParamEstMWE.jl:93
in expression starting at C:\Users\Jon\Downloads\toy_julia_model\toy_julia_model\PfrParamEstMWE.jl:93

```

---

_[View the full topic](https://discourse.julialang.org/t/parameter-estimation-of-ode-system-where-the-response-variables-are-not-the-state-variables/86171)._
