# Problem in integrating Agents.jl and DifferentialEquations.jl

**URL:** https://discourse.julialang.org/t/problem-in-integrating-agents-jl-and-differentialequations-jl/114510
**Category:** Modelling & Simulations
**Tags:** question, agents, modelling
**Created:** [May 21, 2024, 1:36pm UTC](https://discourse.julialang.org/t/problem-in-integrating-agents-jl-and-differentialequations-jl/114510 "2024-05-21T13:36:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)
#### Post date: [May 21, 2024, 1:36pm UTC](https://discourse.julialang.org/t/problem-in-integrating-agents-jl-and-differentialequations-jl/114510/1 "2024-05-21T13:36:39Z")

</div>

Hello, Everyone Im running this example from Agents.jl page – [example](https://docs.sciml.ai/Agents/v4.2/examples/diffeq/). I’m getting Error as shown below. It will be really helpful if someone can help me out here as its extracted directly from website. I will expect it to run without error. Did I miss something ?

Thank you 🙂

```julia
using Agents
using Distributions
using CairoMakie
using DifferentialEquations
using Random

mutable struct Fisher <: AbstractAgent
    id::Int
    competence::Int
    yearly_catch::Float64
end

function agent_diffeq_step!(agent, model)

    agent.yearly_catch = rand(model.rng, Poisson(agent.competence))
    
end

function model_diffeq_step!(model)
    # We step 364 days with this call.
    OrdinaryDiffEq.step!(model.i, 364.0, true)
    # Only allow fishing if stocks are high enough
    model.i.p[2] =
        model.i.u[1] > model.min_threshold ? sum(a.yearly_catch for a in allagents(model)) :
        0.0
    # Notify the integrator that conditions may be altered
    OrdinaryDiffEq.u_modified!(model.i, true)
    # Then apply our catch modifier
    OrdinaryDiffEq.step!(model.i, 1.0, true)
    # Store yearly stock in the model for plotting
    model.stock = model.i.u[1]
    # And reset for the next year
    model.i.p[2] = 0.0
    OrdinaryDiffEq.u_modified!(model.i, true)
end

function initialise_diffeq(;
    stock = 400.0, # Initial population of fish (lets move to an equilibrium position)
    max_population = 500.0, # Maximum value of fish stock
    min_threshold = 60.0, # Regulate fishing if population drops below this value
    nagents = 50,
)

    function fish_stock!(ds, s, p, t)
        max_population, h = p
        ds[1] = s[1] * (1 - (s[1] / max_population)) - h
    end

    prob = OrdinaryDiffEq.ODEProblem(fish_stock!, [stock], (0.0, Inf), [max_population, 0.0])
    integrator = OrdinaryDiffEq.init(prob, OrdinaryDiffEq.Tsit5(); advance_to_tstop = true)

    model = ABM(
        Fisher;
        properties = Dict(
            :stock => stock,
            :max_population => max_population,
            :min_threshold => min_threshold,
            :rng => MersenneTwister(1234),
            :i => integrator, # The OrdinaryDiffEq integrator
        ),
    )
    for _ in 1:nagents
        add_agent!(model, floor(rand(model.rng, truncated(LogNormal(), 1, 6))), 0.0)
    end
    model
end

modeldeq = initialise_diffeq()

_, resultsdeq = run!(modeldeq, agent_diffeq_step!, model_diffeq_step!, 20; mdata = [:stock])

```

Error:

```julia
ERROR: MethodError: no method matching should_we_collect(::Int64, ::StandardABM{…}, ::Bool)

Closest candidates are:
  should_we_collect(::Any, ::Any, ::Any, ::Function)
   @ Agents ~/.julia/packages/Agents/8JW8b/src/simulations/collect.jl:197
  should_we_collect(::Any, ::Any, ::Any, ::AbstractVector)
   @ Agents ~/.julia/packages/Agents/8JW8b/src/simulations/collect.jl:196
  should_we_collect(::Any, ::Any, ::Any, ::Real)
   @ Agents ~/.julia/packages/Agents/8JW8b/src/simulations/collect.jl:195

Stacktrace:
 [1] run!(model::StandardABM{…}, agent_step!::typeof(agent_diffeq_step!), model_step!::typeof(model_diffeq_step!), n::Int64; when::Bool, when_model::Bool, mdata::Vector{…}, adata::Nothing, obtainer::Function, agents_first::Bool, showprogress::Bool, warn_deprecation::Bool)
   @ Agents ~/.julia/packages/Agents/8JW8b/src/deprecations.jl:0
 [2] top-level scope
   @ Untitled-2:72
Some type information was truncated. Use `show(err)` to see complete types.

```

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [May 21, 2024, 1:45pm UTC](https://discourse.julialang.org/t/problem-in-integrating-agents-jl-and-differentialequations-jl/114510/2 "2024-05-21T13:45:09Z")

</div>

> [@Sahil\_Khan](#):
>
> as its extracted directly from website

heh, sure, but which website?

Each version of Agents.jl has its own “website”. Have you checked that the version of Agents.jl you have installed matches the version in the “website” you copied the code from? That is one likely source of error.

It is best if you follow the advice here [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757) which includes **reporting the package versions you are using** and **using the latest stable versions**.

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [May 21, 2024, 1:46pm UTC](https://discourse.julialang.org/t/problem-in-integrating-agents-jl-and-differentialequations-jl/114510/3 "2024-05-21T13:46:00Z")

</div>

> [@Sahil\_Khan](#):
>
> `_, resultsdeq = run!(modeldeq, agent_diffeq_step!, model_diffeq_step!, 20; mdata = [:stock])`

From this code you are either using Agents.jl less than v6 or the example in the docs was not updated. THis is incorrect syntax in Agents.jl v6.

EDIT: the docs of v6 are properly updated: [DifferentialEquations.jl · Agents.jl](https://juliadynamics.github.io/Agents.jl/stable/examples/diffeq/)

---

<div class="post-metadata">

### Author: ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)
#### Post date: [May 21, 2024, 1:59pm UTC](https://discourse.julialang.org/t/problem-in-integrating-agents-jl-and-differentialequations-jl/114510/4 "2024-05-21T13:59:55Z")

</div>

Thank you for help. I thought website get updated after update in version. My bad 🥲
