Model Graphs

At the highest level, a Neuroblox model consists of a weighted directed graph (represented as a MetaDiGraph) whose nodes are Blox representing neurons and populations of neurons, and whose edges are connectors dictating how the dynamics of the Blox affect each other. The weights of the edges represent the strengths of synaptic connections. The model graph is used to generate a system of ordinary differential equations that can be solved using Julia's differential equations solvers.

Users can also save/load a graph model and/or an ODE problem that contains the model in addition to simulation parameters like a timespan, initial conditions, etc.

Building a model from a graph

NeurobloxBase.@graph — Macro
@graph

Helper macro that returns a GraphSystem whose nodes are Blox and whose edges are connections. Nodes should be declared within the block starting with @nodes, and connections should be declared within the block starting with @connections. Connections should be declared as Pairs, with an optional vector of keyword arguments coming after.

Example:

cortical = @graph name begin
    @nodes begin
        ASC1 = NextGenerationEI(; ...)
        Layer_2_3_A = Cortical(; density = 0.03)
        Layer_2_3_B = Cortical(; density = 0.03), (position = (1, 2))
    end

    @connections begin
        ASC1 => Layer_2_3_A, (weight = 20)
        ASC1 => Layer_2_3_A, BasicConnection(20.0), (color = :red)
    end

    @graph_metadata begin
        :solver_settings => Dict(:solver => stiff)
        :datafiles => ["image_example.csv"]
    end
end
NeurobloxBase.@graph! — Macro
@graph! g expr

Like the @graph macro, except it takes an existing graph g as its first argument and mutates it by adding additional nodes and connections.

NeurobloxBase.@nodes — Macro
@nodes name expr

Convenience macro equivalent to @graph where the body is an implicit @nodes block. It creates a new graph named name, assigns it to the variable name, and populates it with the nodes declared in expr.

Example:

@nodes g begin
    ASC1 = NextGenerationEI(; ...)
    Layer_2_3 = Cortical(; density = 0.03)
end

is equivalent to

@graph g begin
    @nodes begin
        ASC1 = NextGenerationEI(; ...)
        Layer_2_3 = Cortical(; density = 0.03)
    end
end
NeurobloxBase.@nodes! — Macro
@nodes! g expr

Convenience macro equivalent to @graph! where the body is an implicit @nodes block. It takes an existing graph g and mutates it by adding the nodes declared in expr.

Example:

@nodes! g begin
    ASC1 = NextGenerationEI(; ...)
    Layer_2_3 = Cortical(; density = 0.03)
end
NeurobloxBase.@connections — Macro
@connections name expr

Convenience macro equivalent to @graph where the body is an implicit @connections block. It creates a new graph named name, assigns it to the variable name, and populates it with the connections declared in expr.

Example:

@connections g begin
    ASC1 => Layer_2_3, (weight = 20)
end

is equivalent to

@graph g begin
    @connections begin
        ASC1 => Layer_2_3, (weight = 20)
    end
end
NeurobloxBase.@connections! — Macro
@connections! g expr

Convenience macro equivalent to @graph! where the body is an implicit @connections block. It takes an existing graph g and mutates it by adding the connections declared in expr.

Example:

@connections! g begin
    ASC1 => Layer_2_3, (weight = 20)
end

Looking up nodes by name

A node is identified within a graph by its full namespaced name, e.g. g₊cortex₊wta1₊exci1.

Missing docstring.

Missing docstring for has_node. Check Documenter's build log for details.

Missing docstring.

Missing docstring for get_node. Check Documenter's build log for details.

Missing docstring.

Missing docstring for find_nodes. Check Documenter's build log for details.

Missing docstring.

Missing docstring for get_or_add_node!. Check Documenter's build log for details.

NeurobloxBase.check_params — Function
check_params(node, kwargs)

Throw an ArgumentError if any parameter of node named in kwargs (a NamedTuple, Dict, or other collection of name => value pairs) has a different value in node. Keys of kwargs that are not parameters of node (name, namespace, tags, constructor-only options, …) are ignored, as are parameters that kwargs does not mention.

Use it after get_or_add_node! when the caller passes parameters for a node that may already have been built by an earlier caller, e.g. a transmitter shared by every connection out of one neuron:

trans = get_or_add_node!(g, Symbol(get_name(src), :₊, :da_trans)) do
    DA_Neurotransmitter(src, dst; transmitter_kwargs...)
end
check_params(trans, transmitter_kwargs)

Only the first caller's build ever runs, so without the check a later caller's parameters would be silently ignored. Note that which caller is first depends on the order in which connections are added.

Missing docstring.

Missing docstring for NodeNotFoundError. Check Documenter's build log for details.

Saving/loading a model

NeurobloxBase.save_graph — Function
save_graph(path::String, g::GraphSystem; save_manifest = true)

Save a GraphSystem as a jld2 file. If save_manifest is set, then the current Manifest.toml of the active project will also be saved as a string.

NeurobloxBase.load_graph — Function
load_graph(path::String)

Load a GraphSystem from a saved GraphSystem or ODEProblem as a jld2 file.

NeurobloxBase.@save_graph — Macro
@save_graph "file_name.jld2" @graph g begin
    ...
end

Insert this macrocall before the DSL definition of a graph to save both the graph, as well as the DSL code used to generate it. This is useful to ensure that the model is reproducible between versions.

IMPORTANT: the reconstructed graph may have slightly different connections if random numbers are used when flattening a composite (like a Cortical blox). Do not rely on the topology being the exact same.

NeurobloxBase.save_problem — Function
save_problem(path::String, prob::ODEProblem)

Save an ODEProblem as a jld2 file. This saves the graph, initial condition, tspan, and parameters.