1- function simplify_simulation (sys, time)
1+
2+ # for now, fallback to ODESystem conversion
3+ function ModelingToolkit. ODESystem (sys:: AbstractConductorSystem ; simplify = true )
24 odesys = convert (ODESystem, sys)
3- t_val = ustrip (Float64, ms, time)
4- return t_val, structural_simplify (odesys)
5+ return simplify ? structural_simplify (odesys) : odesys
56end
67
8+ # simplified = settunable(simplified, tunable)
9+
710"""
811$(TYPEDSIGNATURES)
912
@@ -12,16 +15,11 @@ duration, `time`.
1215
1316If `return_system == true`, returns a simplified `ODESystem` instead.
1417"""
15- function Simulation (neuron:: AbstractCompartmentSystem , time:: Time ; return_system = false ,
16- jac = false , sparse = false ,
17- parallel = Symbolics. SerialForm ())
18- t_val, simplified = simplify_simulation (neuron, time)
19- if return_system
20- return simplified
21- else
22- @info repr (" text/plain" , simplified)
23- return ODEProblem (simplified, [], (0.0 , t_val), []; jac, sparse, parallel)
24- end
18+ function Simulation (neuron:: AbstractCompartmentSystem , tspan;
19+ simplify = true , parallel = Symbolics. SerialForm (), kwargs... )
20+ simplified = ODESystem (neuron; simplify)
21+ tstart, tstop = time_span (tspan)
22+ return ODEProblem (simplified, [], (tstart, tstop), []; parallel, kwargs... )
2523end
2624
2725struct NetworkParameters{T}
3129
3230Base. getindex (x:: NetworkParameters , i) = x. ps[i]
3331topology (x:: NetworkParameters ) = getfield (x, :topology )
32+
3433function get_weights (integrator, model)
3534 topo = topology (integrator. p)
3635 return graph (topo)[model]
3736end
38- function Simulation (network:: NeuronalNetworkSystem , time:: Time ; return_system = false ,
39- jac = false , sparse = false , parallel = Symbolics. SerialForm (), continuous_events = false ,
40- refractory = true )
41- t_val, simplified = simplify_simulation (network, time)
42- return_system && return simplified
37+
38+ function Simulation (network:: NeuronalNetworkSystem , tspan; simplify = true ,
39+ parallel = Symbolics. SerialForm (), continuous_events = false ,
40+ refractory = true , kwargs... )
41+ odesys = ODESystem (network; simplify)
42+ tstart, tstop = time_span (tspan)
4343 if ! any (iseventbased .(synaptic_systems (network)))
44- return ODEProblem (simplified , [], (0.0 , t_val ), []; jac, sparse, parallel )
44+ return ODEProblem (odesys , [], (tstart, tstop ), []; parallel, kwargs ... )
4545 else
46- cb = generate_callback (network, simplified; continuous_events, refractory)
47- prob = ODEProblem (simplified, [], (0.0 , t_val), []; callback = cb, jac, sparse, parallel)
48- remake (prob; p = NetworkParameters (prob. p, get_topology (network) ))
46+ cb = generate_callback (network, odesys; continuous_events, refractory)
47+ prob = ODEProblem (odesys, [], (tstart, tstop), [];
48+ callback = cb, parallel, kwargs... )
49+ remake (prob; p = NetworkParameters (prob. p, get_topology (network)))
4950 end
5051end
5152
5253# if continuous, condition has vector cb signature: cond(out, u, t, integrator)
53- function generate_callback_condition (network, simplified ; continuous_events, refractory)
54- voltage_indices = map_voltage_indices (network, simplified ; roots_only = true )
54+ function generate_callback_condition (network, odesys ; continuous_events, refractory)
55+ voltage_indices = map_voltage_indices (network, odesys ; roots_only = true )
5556 if continuous_events
5657 return ContinuousSpikeDetection (voltage_indices)
5758 else # discrete condition for each compartment
5859 return [DiscreteSpikeDetection (voltage_index, refractory) for voltage_index in voltage_indices]
5960 end
6061end
6162
62- function generate_callback_affects (network, simplified )
63+ function generate_callback_affects (network, odesys )
6364 spike_affects = []
6465 for sys in synaptic_systems (network)
65- push! (spike_affects, SpikeAffect (sys, network, simplified ))
66+ push! (spike_affects, SpikeAffect (sys, network, odesys ))
6667 end
6768 tailcall = nothing # placeholder for voltage reset
6869 return NetworkAffects (spike_affects, tailcall)
6970end
7071
71- function generate_callback (network, simplified ; continuous_events, refractory)
72- cb_condition = generate_callback_condition (network, simplified ; continuous_events, refractory)
73- cb_affect = generate_callback_affects (network, simplified )
72+ function generate_callback (network, odesys ; continuous_events, refractory)
73+ cb_condition = generate_callback_condition (network, odesys ; continuous_events, refractory)
74+ cb_affect = generate_callback_affects (network, odesys )
7475 if continuous_events
7576 return VectorContinuousCallback (cb_condition, cb_affect,
7677 length (cb_condition. voltage_indices))
0 commit comments