Skip to content

Commit

Permalink
add hack for more stack space in spectral DCM tests (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonProtter authored and david-hofmann committed Jul 26, 2024
1 parent 62e68ac commit 890be6e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions test/datafitting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,26 @@ hyperpriors = (Πλ_pr = vars["ihC"]*ones(1, 1), # prior metaparameter precisi
csdsetup = (p = 8, freq = vec(vars["Hz"]), dt = vars["dt"]);

(state, setup) = setup_sDCM(data, neuronmodel, initcond, csdsetup, priors, hyperpriors, indices);
for iter in 1:max_iter
state.iter = iter
run_sDCM_iteration!(state, setup)
print("iteration: ", iter, " - F:", state.F[end] - state.F[2], " - dF predicted:", state.dF[end], "\n")
if iter >= 4
criterion = state.dF[end-3:end] .< setup.tolerance
if all(criterion)
print("convergence\n")
break

# HACK: on machines with very small amounts of RAM, Julia can run out of stack space while compiling the code called in this loop
# this should be rewritten to abuse the compiler less, but for now, an easy solution is just to run it with more allocated stack space.
with_stack(f, n) = fetch(schedule(Task(f,n)))

with_stack(5_000_000) do # 5MB of stack space
for iter in 1:max_iter
state.iter = iter
run_sDCM_iteration!(state, setup)
print("iteration: ", iter, " - F:", state.F[end] - state.F[2], " - dF predicted:", state.dF[end], "\n")
if iter >= 4
criterion = state.dF[end-3:end] .< setup.tolerance
if all(criterion)
print("convergence\n")
break
end
end
end
end

print("maxixmum iterations reached\n")

### COMPARE RESULTS WITH MATLAB RESULTS ###
Expand Down

0 comments on commit 890be6e

Please sign in to comment.