Library
Spike.Model
— TypeModel
Main structure for creating a model. Note that, for convenience, this structure does not have to be created yourself. If you can provide adequate scope and have called cast_magic
to start the scope, run
will magically created the model for you (and return it after simulation).
INPUTS:
Neurons::Dict{Symbol, NeuronGroup} - All neuron groups in the model. (default = Dict())
Synapses::Dict{Symbol, Synapses} - All synapse groups in the model. (default = Dict())
Operations::Dict{Symbol, Operation} - All operations in the model. (default = Dict())
StateMonitors::Dict{Symbol, StateMonitor} - All state monitors in the model. (default = Dict())
EventMonitors::Dict{Symbol, EventMonitor} - All event monitors in the model. (default = Dict())
verbose::Bool - Verbose updates? (default = true)
Spike.run
— Methodrun(model::Model; T::Float64,
dt::Float64 = 1e-3)::Model
Main entry point for simulations.
INPUTS:
model::Model - The model to run.
T::Float64 - Total time to run the model for.
dt::Float64 - Time step size. (default = 1e-3)
OUTPUTS:
model::Model - Self
Spike.run
— Methodrun(; T::Float64,
dt::Float64 = 1e-3,
magic_obj::DataType = SpikeObject,
magic_tar::Module = Main,
verbose::Bool = true)::Model
Entry point for magic networks. Creates the model and yields it to the simulation entry point.
INPUTS:
T::Float64 - Total time to run the model for.
dt::Float64 - Time step size.
magic_obj::DataType - DataType that identifies magic objects. (default = SpikeObject)
magic_tar::Module - Module where magic is utilised. (default = Main)
verbose::Bool - Verbose updates? (default = true)
OUTPUTS:
model::Model - Self
Spike.status
— Methodstatus(model::Model,
status::String,
e::String = "\n")
Logging function at runtime.
INPUTS:
model::Model - The model object.
status::String - The status.
e::String - End-of-line characters.
Spike.NeuronGroup
— TypeNeuronGroup <: SpikeObject
Main structure for creating neurons. Note that, for convenience, you can often simply use one of the auxiliary functions provided in this file (e.g., LIF
) rather than rewriting expressions yourself (unless that is explicitly required).
INPUTS:
N::Int - Number of neurons in group
eq::Expr - Equation determining the behaviour of neurons in this group.
method::Function - Function to use for solving differential equations. See Spike::Solvers.
parameters::Dict{Symbol, Any} - All parameters for all neurons.
events::Dict{Symbol, Tuple{Expr, Expr}} - Event specifications in the form of events = Dict(:name => (:(condition), :(effect;))).
__built::Bool - (Internal) Has this model been built? (default = false)
__normeqs::Dict{Symbol, Expr} - (Internal) Built equations. (default = Dict())
__diffeqs::Dict{Symbol, Expr} - (Internal) Built differential equations. (default = Dict())
__eventeqs::Dict{Symbol, Dict{Symbol, Expr}} - (Internal) Built event equations. (defualt = Dict())
__eventlog::Dict{Symbol, Vector{Bool}} - (Internal) Events at runtime. (default = Dict())
Spike.LIF
— MethodLIF(; N::Int = 1,
normalised::Bool = false)::NeuronGroup
Shorthand to create standard Leaky Integrate-and-Fire neurons.
INPUTS:
N::Int - Number of neurons (default = 1)
normalised::Bool - Should values be normalised rather than biological (i.e., spanning [0, 1])? (default = false)
OUTPUTS:
neurons::NeuronGroup - LIF-group of neurons
Spike.step
— Methodstep(neurons::NeuronGroup; dt::Float64,
t::Float64)::NeuronGroup
Performs one time step for all the equations specified for a NeuronGroup
. Note that this includes both state updates as well as event checks and logging.
INPUTS:
neuron::NeuronGroup - NeuronGroup to perform a step on.
dt::Float64 - Time step size.
t::Float64 - Current time.
OUTPUTS:
neuron::NeuronGroup - Self
Spike.Synapses
— TypeSynapses <: SpikeObject
Main structure for creating synapses between NeuronGroups. Note that both cond::Expr
and prob::Float64
may be used complemantarily (or left as is to default to full connections).
INPUTS:
pre::NeuronGroup - Presynaptic neuron group.
post::NeuronGroup - Postsynaptic neuron group.
cond::Expr - Conditional expression for building connectivity matrix. (default = :())
prob::Float64 - Probability of realising a potential entry in connectivity matrix. (default = 1.0)
eq::Expr - Equation determining the behaviour of the synapses.
method::Function - Function to use for solving differential equations. See Spike::Solvers.
parameters::Dict{Symbol, Any} - Parameter pre-specifications; either func where func(N) is valid or ::Number.
on_pre::Dict{Symbol, Expr} - Hooks into presynaptic events and their effects (e.g., Dict(:spike => :(post_I = post_I .+ w;))).
on_post::Dict{Symbol, Expr} - Hooks into postsynaptic events and their effects (e.g., Dict(:spike => :(pre_f_t_f = t;))).
__built::Bool - (Internal) Have these synapses been built? (default = false)
__parameters::Dict{Symbol, Any} - (Internal) Full parameters after building model. (default = Dict())
__normeqs::Dict{Symbol, Expr} - (Internal) Built equations. (default = Dict())
__diffeqs::Dict{Symbol, Expr} - (Internal) Built differential equations. (default = Dict())
__preeqs::Dict{Symbol, Dict{Symbol, Expr}} - (Internal) Built presynaptic event equations. (default = Dict())
__posteqs::Dict{Symbol, Dict{Symbol, Expr}} - (Internal) Built postsynaptic event equations. (default = Dict())
__M_pre::Vector{Vector{Int}} - (Internal) Built forwards connectivity matrix. (default = Dict())
__M_post::Vector{Vector{Int}} - (Internal) Built backwards connectivity matrix. (default = Dict())
__N::Int - (Internal) Built number of synapses.
__i::Vector{Int} - (Internal) Built i-th index of every synapse, indicating presynaptic neuron.
__j::Vector{Int} - (Internal) Built j-th index of every synapse, indicating postsynaptic neuron.
Spike.step
— Methodstep(synapses::Synapses; dt::Float64,
t::Float64)::Synapses
Performs one time step for all equations specified for a group of synapses. Note that this also includes state updates as well as event hooks and effects.
INPUTS:
synapses::Synapses - Synapses to perform step on.
dt::Float64 - Time step size.
t::Float64 - Current time.
OUTPUTS:
synapses::Synapses - Self
Spike.Operation
— TypeOperation <: SpikeObject
Wrapper structure for custom operations to be run during simulation.
INPUTS:
op::Function - External function to be called.
every::Float64 - Delay between calls. (default = 1e-3)
cycle::String - Timing within cycle. (default = "pre")
__built::Bool - (Internal) Has this operation been built? (default = false)
__last::Float64 - (Internal) Last operation. (default = -Inf)
Spike.step
— Methodstep(operation::Operation; dt::Float64,
t::Float64,
cycle::String)::Operation
Performs one time step of an operation. This is an internal function and should not be called manually.
INPUTS:
operation::Operation - Operation to perform time step on.
dt::Float64 - Time step size.
t::Float64 - Current time.
cycle::String - Current cycle.
OUTPUTS:
operation::Operation - Self
Spike.EventMonitor
— TypeEventMonitor <: SpikeObject
Main structure for monitoring events.
INPUTS:
obj::NeuronGroup - Object to be monitored.
event::Symbol - Event to be tracked. (default = :spike)
t::Vector{Float64} - (Internal) Time vector. (default = Float64[])
i::Vector{Int} - (Internal) State vectors. (default = Int[])
__built::Bool - (Internal) Has this monitor been built? (default = false)
Spike.StateMonitor
— TypeStateMonitor <: SpikeObject
Main structure for monitoring states of neurons or synapses.
INPUTS:
obj::Any - Object to be monitored.
vars::Vector{Symbol} - Parameters to be monitored in object.
every::Float64 - Delay between calls. (default = 1e-3)
t::Vector{Float64} - (Internal) Time vector. (default = Float64[])
states::Dict{Symbol, Array{Float64, 2}} - (Internal) State vectors. (default = Dict())
__built::Bool - (Internal) Has this monitor been built? (default = false)
__last::Float64 - (Internal) Last check. (default = -Inf)
Spike.step
— Methodstep(monitor::EventMonitor; dt::Float64,
t::Float64)::EventMonitor
Performs one time step of the monitor. This is an internal fuction and should not be called manually.
Spike.step
— Methodstep(monitor::StateMonitor; dt::Float64,
t::Float64)::StateMonitor
Performs one time step of the monitor. This is an internal function and should not be called manually.
INPUTS:
monitor::StateMonitor - StateMonitor to perform time step on.
dt::Float64 - Time step size.
t::Float64 - Current time.
OUTPUTS:
monitor::StateMonitor - Self
Spike.SpikeObject
— TypeSpikeObject
Abstract type definition that enables look-up and matching of magic objects.
Spike.cast_magic
— Methodcast_magic()
Enables creation of a magic network that will be built from the module's global scope. This should always be called when trying to utilise magic networks.
Spike.collect_magic_objects
— Methodcollect_magic_objects(; magic_obj::DataType = SpikeObject,
magic_tar::Module = Main)::Vector{Symbol}
Collects all magic objects from the module. This is an internal function and should not be called manually.
INPUTS:
magic_obj::DataType - DataType that identifies magic objects. (default = SpikeObject)
magic_tar::Module - Module where magic is utilised. (default = Main)
OUTPUTS:
cols::Vector{Symbol} - Vector of symbols of magic objects in module.
Spike.create_magic_model
— Methodcreate_magic_model(; magic_obj::DataType = SpikeObject,
magic_tar::Module = Main)::Model
Creates a model from all available magic objects that have corresponding vectorised forms in the standard model structure. This is an internal function and should not be called manually.
INPUTS:
magic_obj::DataType - DataType that identifies magic objects. (default = SpikeObject)
magic_tar::Module - Module where magic is utilised. (default = Main)
OUTPUTS:
model::Model - The magic network.
Spike.__cast_magic
— Constant__cast_magic::Bool
Internal variable to keep track of whether or not magic has been cast. Do not change this manually. Please use cast_magic
instead.
Spike.categorise_subexpressions
— Methodcategorise_subexpressions(expr::Expr)::Tuple{Dict{Symbol, Expr}, Dict{Symbol, Expr}}
Takes a set of equations formulated as an expression and categorises by whether or not they need to be differentiated at runtime. Currently, all equations are implicitly interpreted with respect to time. Typical syntax of equations should be:
:(I_t = A ./ 2 .+ A ./ 2 .* sin(2 * π * t);
dv_dt = (.-(v .- v_rest) .+ I) ./ 𝜏;
A = rand(N);)
which would create a regular function I(t), a differential equation dv/dt and an assignment of A for the model at runtime.
INPUTS:
expr::Expr - Expression to evaluate
OUTPUTS:
(eqs_norm, eqs_diff)::Tuple{Dict{Symbol, Expr}, Dict{Symbol, Expr}} - Tuple of normal and differential equations.
Spike.interpolate_from_dict
— Methodinterpolate_from_dict(expr::Expr,
dict::Dict{Symbol, Any})::Any
Set of functions to allow for data to be supplied easily for evaluating expressions.
Spike.__regex_subexpression_eq_assi
— Constant__regex_subexpression_eq_assi
Regular expression that defines the syntax of assignments in categorise_subexpressions
. This is an internal variable and should not be changed.
Spike.__regex_subexpression_eq_diff
— Constant__regex_subexpression_eq_diff
Regular expression that defines the syntax of differential equations in categorise_subexpressions
. This is an internal variable and should not be changed.
Spike.__regex_subexpression_eq_norm
— Constant__regex_subexpression_eq_norm
Regular expression that defines the syntax of normal equations in categorise_subexpressions
. This is an internal variable and should not be changed.
Spike.build
— Methodbuild(target::EventMonitor)::EventMonitor
Builds an event monitor into the model that will be updated as events occur. This is an internal function and should not be called manually.
INPUTS:
target::EventMonitor - EventMonitor to build.
OUTPUTS:
target::EventMonitor - Built monitor.
Spike.build
— Methodbuild(target::NeuronGroup)::NeuronGroup
Builds a group of neurons such that their expressions may be evaluated more directly. Also performs safety checks. This is an internal functino and should not be called manually.
INPUTS:
target::NeuronGroup - Group of neurons to build.
OUTPUTS:
target::NeuronGroup - Built group of neurons.
Spike.build
— Methodbuild(target::Operation)::Operation
Builds an operation into the model, which will be executed at prespecified intervals. This is an internal function and should not be called manually.
INPUTS:
target::Operation - Operation to build.
OUTPUTS:
target::Operation - Built operation.
Spike.build
— Methodbuild(target::StateMonitor)::StateMonitor
Builds a state monitor into the model that will be updated periodically. This is an internal function and should not be called manually.
INPUTS:
target::StateMonitor - StateMonitor to build.
OUTPUTS:
target::StateMonitor - Built monitor.
Spike.build
— Methodbuild(target::Synapses)::Synapses
Builds synapses between two groups of neurons such that their equations can be evaluated more directly. Also performs safety checks and handles evaluation of connectivity matrices as well as internal parametrisation. This is an internal function and should not be called manually.
INPUTS:
target::Synapses - Synapses to build.
OUTPUTS:
target::Synapses - Built group of synapses.
Spike.euler
— Methodeuler(; sym::Symbol,
eq::Expr,
par::Dict{Symbol, Any},
dt::Float64,
t::Float64)::Any
Euler's method for differential equations.
INPUTS:
sym::Symbol - Symbol of the parameters to be differentiated.
eq::Expr - Expression of the differential equation.
par::Dict{Symbol, Any} - Paramters for the differential equation.
dt::Float64 - Step size.
t::Float64 - Time at step zero.
OUTPUTS:
phi_n_plus_1::Any - Approximate value at step one.
Spike.heun
— Methodheun(; sym::Symbol,
eq::Expr,
par::Dict{Symbol, Any},
dt::Float64,
t::Float64)::Any
Heun's method for differential equations.
INPUTS:
sym::Symbol - Symbol of the parameters to be differentiated.
eq::Expr - Expression of the differential equation.
par::Dict{Symbol, Any} - Paramters for the differential equation.
dt::Float64 - Step size.
t::Float64 - Time at step zero.
OUTPUTS:
phi_n_plus_1::Any - Approximate value at step one.
Spike.rk2
— Methodrk2(; sym::Symbol,
eq::Expr,
par::Dict{Symbol, Any},
dt::Float64,
t::Float64)::Any
Second order Runge-Kutta time stepper for differential equations.
INPUTS:
sym::Symbol - Symbol of the parameters to be differentiated.
eq::Expr - Expression of the differential equation.
par::Dict{Symbol, Any} - Paramters for the differential equation.
dt::Float64 - Step size.
t::Float64 - Time at step zero.
OUTPUTS:
phi_n_plus_1::Any - Approximate value at step one.