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

Sl/dependent machines #100

Merged

Conversation

slwu89
Copy link
Member

@slwu89 slwu89 commented Apr 9, 2022

@slibkind I'm adding a simplest possible example of the RM ODE model with an InstantaneousContinuousMachine; the composed dynamical system should be the exact same as the existing ODE model there. The oapply is running into some problems when composing however, if you have a minute can you help me take a look? The composition pattern is ok so it must be an error in how I'm setting up the InstantaneousContinuousMachine.

The dyn sys should be:
EIR = maZ
\kappa = c*X

\dot{Z} = a*\kappa*(e^{-gn} - Z) - gZ

\dot{X} = bEIR(1-X) - rX

@slwu89
Copy link
Member Author

slwu89 commented Apr 9, 2022

oapply works for me after changing the induced_dynamics and induced_readout methods to be less parametrically constrained, that is, where {T,I, M<:AbstractMachine{T,I}} to where {M<:AbstractMachine} in both those methods. Still encounter an error when running the ODE solver though!

@slwu89
Copy link
Member Author

slwu89 commented Apr 16, 2022

Update, trying out the example again after merging the latest (today) updates to the sl/dependent_machines branch. Error when calling solve:

ERROR: type Float64 has no field c
Stacktrace:
  [1] getproperty
    @ ./Base.jl:42 [inlined]
  [2] (::var"#5#6")(u::Vector{Float64}, x::LArray{Real, 1, Vector{Real}, (:a, :b, :c, :g, :n, :r, :m)}, p::Float64, t::Int64)
    @ Main ./REPL[15]:4
  [3] readout(m::AlgebraicDynamics.DWDDynam.Machine{Float64, AlgebraicDynamics.DWDDynam.InstantaneousDirectedInterface{Float64}, AlgebraicDynamics.DWDDynam.ContinuousDirectedSystem{Float64}}, u::Vector{Float64}, x::LArray{Real, 1, Vector{Real}, (:a, :b, :c, :g, :n, :r, :m)}, p::Float64, t::Int64) (repeats 2 times)
    @ AlgebraicDynamics.DWDDynam ~/Desktop/git/AlgebraicDynamics.jl/src/dwd_dynam.jl:261
  [4] (::AlgebraicDynamics.DWDDynam.var"#102#103"{Vector{Vector{Float64}}, LArray{Real, 1, Vector{Real}, (:a, :b, :c, :g, :n, :r, :m)}, Float64})(::Tuple{Int64, AlgebraicDynamics.DWDDynam.Machine{Float64, AlgebraicDynamics.DWDDynam.InstantaneousDirectedInterface{Float64}, AlgebraicDynamics.DWDDynam.ContinuousDirectedSystem{Float64}}})
    @ AlgebraicDynamics.DWDDynam ~/Desktop/git/AlgebraicDynamics.jl/src/dwd_dynam.jl:590

So the issue is here in dwd_dynam:

get_readouts(ms::AbstractArray{M}, states, p, t) where {M <: AbstractMachine} = map(enumerate(ms)) do (i, m)
readout(m, states[i], p, t)
end
which calls
readout(m::Machine{T,I,S}, u::AbstractVector, x::AbstractVector, p=nothing, t=0) where {T, I<:InstantaneousDirectedInterface{T}, S} =
readout(m)(u,x,p,t)

Somehow the wrong args are getting passed to the readout function, such that the time is getting sent into the spot where parameters should be passed.

@slibkind
Copy link
Collaborator

I think the problem comes from the fact that you are composing and InstantaneousContinuousMachine with two ContinuousMachine. A good addition to PR #99 would be to explicitly enable this.

In the meantime a quick solution would be to write the mosquito and host models as instantaneous machines with trivial input/output dependency. For example, instead of

mosquito_model = ContinuousMachine{Float64}(1, 1, 1, dZdt, (u,p,t) -> u)

try

mosquito_model = InstantaneousContinuousMachine{Float64}(1, 1 ,1, dZdt, (u,x,p,t) -> u, [])

Another good addition to PR #99 would be to have a method which turns ContinuousMachines into InstantaneousContinuousMachines.

@slibkind
Copy link
Collaborator

Lastest commit on PR #99 adds a constructor for InstantaneousMachine from an ordinary machine. Now you should be able to write the above as:

mosquito_model = ContinuousMachine{Float64}(1, 1, 1, dZdt, (u,p,t) -> u)
instantaneous_mosquito_model = InstantaneousContinuousMachine{Float64}(mosquito_model)

@slibkind slibkind merged commit cd5f10b into AlgebraicJulia:sl/dependent_machines May 6, 2022
@slwu89 slwu89 deleted the sl/dependent_machines branch May 6, 2022 01:24
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.

2 participants