Slightly different error when I remove one call back but leave the other call back in place. First I create a dynamic food web, and use the output of the food web as the beginning values of the same differential equations but with species harvesting. I have four different types of harvesting (called clearance in the model). Then I create a new food web and the process repeats.
Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x668eedae -- jl_field_offset at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1020 [inlined]
set_nth_field at /cygdrive/d/buildbot/worker/package_win64/build/src\datatype.c:1067
in expression starting at C:\Users\aw21sodo\Documents\Julia\Julia WD\phd-julia-code\clearance comparison.jl:89
jl_field_offset at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1020 [inlined]
set_nth_field at /cygdrive/d/buildbot/worker/package_win64/build/src\datatype.c:1067
jl_f_tuple at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:725
apply_clearance at C:\Users\aw21sodo\Documents\Julia\Julia WD\phd-julia-code\clearance comparison.jl:37
#24 at .\none:0 [inlined]
iterate at .\generator.jl:47 [inlined]
collect at .\array.jl:665
run_one_foodweb at C:\Users\aw21sodo\Documents\Julia\Julia WD\phd-julia-code\clearance comparison.jl:83
#26 at .\none:0 [inlined]
iterate at .\generator.jl:47 [inlined]
collect_to! at .\array.jl:711
collect_to_with_first! at .\array.jl:689
unknown function (ip: 0000000000EF54EF)
collect at .\array.jl:670
unknown function (ip: 0000000000EAB180)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1700 [inlined]
do_call at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:369
eval_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:458
eval_stmt_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:409 [inlined]
eval_body at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:799
jl_interpret_toplevel_thunk at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:911
jl_toplevel_eval_flex at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:814
jl_parse_eval_all at /cygdrive/d/buildbot/worker/package_win64/build/src\ast.c:872
include_string at .\loading.jl:1080
include_string at C:\Users\aw21sodo\.julia\packages\CodeTools\kosGY\src\eval.jl:30
unknown function (ip: 0000000000EA8BB9)
#206 at C:\Users\aw21sodo\.julia\packages\Atom\9h5Up\src\eval.jl:119
withpath at C:\Users\aw21sodo\.julia\packages\CodeTools\kosGY\src\utils.jl:30
withpath at C:\Users\aw21sodo\.julia\packages\Atom\9h5Up\src\eval.jl:9
#205 at C:\Users\aw21sodo\.julia\packages\Atom\9h5Up\src\eval.jl:118 [inlined]
with_logstate at .\logging.jl:398
with_logger at .\logging.jl:505 [inlined]
#204 at C:\Users\aw21sodo\.julia\packages\Atom\9h5Up\src\eval.jl:117 [inlined]
hideprompt at C:\Users\aw21sodo\.julia\packages\Atom\9h5Up\src\repl.jl:127
macro expansion at C:\Users\aw21sodo\.julia\packages\Atom\9h5Up\src\eval.jl:116 [inlined]
macro expansion at C:\Users\aw21sodo\.julia\packages\Media\ItEPc\src\dynamic.jl:24 [inlined]
eval at C:\Users\aw21sodo\.julia\packages\Atom\9h5Up\src\eval.jl:113
unknown function (ip: 00000000601C4CC3)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1700 [inlined]
do_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:643
jl_f__apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:657 [inlined]
jl_f__apply_latest at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:693
#invokelatest#1 at .\essentials.jl:712
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1700 [inlined]
do_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:643
invokelatest at .\essentials.jl:711
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1700 [inlined]
do_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:643
macro expansion at C:\Users\aw21sodo\.julia\packages\Atom\9h5Up\src\eval.jl:41 [inlined]
#188 at .\task.jl:358
unknown function (ip: 00000000600F4C03)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1700 [inlined]
start_task at /cygdrive/d/buildbot/worker/package_win64/build/src\task.c:687
Allocations: 735090915 (Pool: 735056474; Big: 34441); GC: 186
The running code is
include("Schneider et al 2016 parameters.jl") # list of constants
include("Function set-up.jl") # list of functions
include("Function running.jl") # differential equations
# create the initial conditions for a given network
function create_initial_conditions(target_species)
include("Schneider et al 2016 vectors & biomass.jl") # constants that are randomized per food web
tmax = 50000.0
tspan = (0.0,tmax)
function condition(out, u, t, integrator)
out .= u[1:(end-1)] .- 1e-6
end
function affect!(integrator, event_index)
integrator.u[event_index] = 0.0
end
extinction_cb = VectorContinuousCallback(condition,affect!,length(bioS[1:(end-1)]))
p = (D, S, K, v, r, X, num_nutrient, num_plant, num_animal, num_vessel_types, bm, foodWeb, b, q, ω, c, h, e, target_species, catch_max, b0V, μ, elasticity, clearance_V_type)
prob = ODEProblem(dBdT,bioS,tspan,p)
global base_simulation=solve(prob, alg = CVODE_BDF()) # global so it can be passed to apply_clearance()
return base_simulation[end]
end
# applies a clearance type and a target species
function apply_clearance(bioS, clearance_V_type, target_species)
results = fill(NaN,5) # how ever many values we ar comparing between scenarios
num_extinct_base = sum(base_simulation[end] .<= 0.0)
p = (D, S, K, v, r, X, num_nutrient, num_plant, num_animal, num_vessel_types, bm, foodWeb, b, q, ω, c, h, e, target_species, catch_max, b0V, μ, elasticity, clearance_V_type)
function condition(out, u, t, integrator)
out .= u[1:(end-1)] .- 1e-6
end
function affect!(integrator, event_index)
integrator.u[event_index] = 0.0
end
tmax = 50000.0
tspan = (0.0,tmax)
extinction_cb = VectorContinuousCallback(condition,affect!,length(bioS) - 1)
fishing_prob = ODEProblem(dBdT,bioS,tspan,p, callback=extinction_cb)
fishing_sol = solve(fishing_prob, alg = CVODE_BDF()) # global so we can create a graph
num_extinct_clearance = abs(num_extinct_base-sum(fishing_sol[end] .<= 0.0))
vessel_final = log10(fishing_sol[end][(num_nutrient+num_plant+num_animal+num_vessel_types)])
target_final = log10(fishing_sol[end][target_species])
fishing_sol[target_species,end] num_extinct]
results = [fish_price vessel_final target_final num_extinct_base num_extinct_clearance]
return results
end
# run the 4 different scenarios and store the results in one_foodweb_result:
function run_one_foodweb()
initial = create_initial_conditions(0)
bioS = deepcopy(initial)
# and then continue the simulations with one clearance type
# apply_clearance(bioS, 1, 82)
# or run the 4 different scenarios and store the results in result:
one_foodweb_result = [apply_clearance(bioS, x, 82) for x in 1:4]
return one_foodweb_result
end
# now run however many food webs you want and store it
all_foodweb_result = [run_one_foodweb() for x in 1:20]