Пример #1
0
def _generate_functions(net_id):

    functions = ""
    if len(Global._objects['functions']) == 0:
        return functions

    for name, func in Global._objects['functions']:
        functions += LatexParser._process_functions(func) + "\n"

    return functions_template % {'parameters': functions, 'firstfunction': "\hdr{1}{G}{Functions}\\\\ \\hline"}
Пример #2
0
def _generate_functions(net_id):

    functions = ""
    if len(Global._objects['functions']) == 0:
        return functions

    for name, func in Global._objects['functions']:
        functions += LatexParser._process_functions(func) + "\n"

    return functions_template % {'parameters': functions, 'firstfunction': "\hdr{1}{G}{Functions}\\\\ \\hline"}
Пример #3
0
def _generate_summary(net_id):

    txt = """
# Structure of the network
"""

    # General information
    backend = 'default'
    if Global.config['paradigm'] == 'cuda':
        backend = "CUDA"
    elif Global.config['paradigm'] == "openmp" and Global.config['num_threads'] > 1:
        backend = "OpenMP"
    txt +="""
* ANNarchy %(version)s using the %(backend)s backend.
* Numerical step size: %(dt)s ms.
""" % {'version': ANNarchy.__release__, 'backend': backend, 'dt': Global.config['dt']}

    # Populations
    if len(Global._network[net_id]['populations']) > 0:
        headers = ["Population", "Size", "Neuron type"]
        populations = []
        for pop in Global._network[net_id]['populations']:
            # Find a name for the neuron
            neuron_name = "Neuron " + str(pop.neuron_type._rk_neurons_type) if pop.neuron_type.name in Neuron._default_names.values() \
                else pop.neuron_type.name

            populations.append([
                pop.name, 
                pop.geometry if len(pop.geometry)>1 else pop.size, 
                neuron_name])

        txt += """
## Populations

"""
        txt += _make_table(headers, populations)


    # Projections
    if len(Global._network[net_id]['projections']) > 0 :
        headers = ["Source", "Destination", "Target", "Synapse type", "Pattern"]
        projections = []
        for proj in Global._network[net_id]['projections']:
            # Find a name for the synapse
            synapse_name = "Synapse " + str(proj.synapse_type._rk_synapses_type) if proj.synapse_type.name in Synapse._default_names.values() \
                else proj.synapse_type.name

            projections.append([
                proj.pre.name, 
                proj.post.name, 
                LatexParser._format_list(proj.target, ' / '),
                synapse_name,
                proj.connector_description
                ])

        txt += """
## Projections

"""
        txt += _make_table(headers, projections)

    # Monitors
    if len(Global._network[net_id]['monitors']) > 0:
        headers = ["Object", "Variables", "Period"]
        monitors = []
        for monitor in Global._network[net_id]['monitors']:
            monitors.append([
                monitor.object.name + (" (subset)" if isinstance(monitor.object, PopulationView) else ""), 
                LatexParser._format_list(monitor.variables, ', '),
                monitor.period
                ])

        txt += """
## Monitors

"""
        txt += _make_table(headers, monitors)

    # Functions
    if len(Global._objects['functions']) > 0 :
        txt += """## Functions

"""
        for name, func in Global._objects['functions']:
            txt += LatexParser._process_functions(func, begin="$$", end="$$\n\n")

    return txt
Пример #4
0
def _generate_neuron_models(net_id):
    txt = """
# Neuron models
"""
    for idx, neuron in enumerate(Global._objects['neurons']):

        # Name
        if neuron.name in Neuron._default_names.values(): # name not set
            neuron_name = "Neuron " + str(neuron._rk_neurons_type)
        else:
            neuron_name = neuron.name

        # Description
        description = neuron.short_description
        if description == None:
            description = "Spiking neuron." if neuron.type == 'spike' else 'Rate-coded neuron'

        # Parameters
        parameters = extract_parameters(neuron.parameters, neuron.extra_values)
        parameters_list = [
            ["$" + LatexParser._latexify_name(param['name'], []) + "$", param['init'], 
                _adapt_locality_neuron(param['locality']), param['ctype']] 
                    for param in parameters]

        parameters_headers = ["Name", "Default value", "Locality", "Type"]
        parameters_table = _make_table(parameters_headers, parameters_list)

        if len(parameters) == 0:
            parameters_table = "$$\\varnothing$$"

        # Generate the code for the equations
        variables, spike_condition, spike_reset = LatexParser._process_neuron_equations(neuron)
        
        eqs = _process_variables(variables, neuron=True)

        # Spiking neurons
        if neuron.type == 'spike':

            reset_txt = "* Emit a spike a time $t$.\n"
            for r in spike_reset:
                reset_txt += "* $" + r + "$\n"

            eqs += """
**Spike emission:**

if $%(condition)s$ :

%(reset)s
""" % {'condition': spike_condition, 'reset': reset_txt}


        # Possible function
        if not neuron.functions == None:
            eqs += """
**Functions**

%(functions)s
""" % {'functions': LatexParser._process_functions(neuron.functions, begin="$$", end="$$\n\n")}

        # Finalize the template
        txt += neuron_tpl % {   'name': neuron_name, 
                                'description': description, 
                                'parameters': parameters_table,
                                'eqs': eqs}

    return txt
Пример #5
0
def _generate_synapse_models(net_id):
    firstsynapse = ""
    synapses = ""

    firstsynapse = "\\hdr{2}{E}{Synapse Models}\\\\ \\hline"

    synapse_tpl = """
\\noindent
\\begin{tabularx}{\\linewidth}{|p{0.15\\linewidth}|X|}\\hline
%(firstsynapse)s
\\textbf{Name} & %(name)s \\\\ \\hline
\\textbf{Type} & %(description)s\\\\ \\hline
%(psp)s
%(variables)s
%(preevent)s
%(postevent)s
%(functions)s
\\end{tabularx}
\\vspace{2ex}
"""
    for idx, synapse in enumerate(Global._objects['synapses']):
        # Do not document default synapses
        if synapse.name == "-":
            continue

        # Find a name for the synapse
        if synapse.name in Synapse._default_names.values(): # name not set
            synapse_name = "Synapse " + str(synapse._rk_synapses_type)
        else:
            synapse_name = synapse.name

        # Generate the code for the equations
        psp, variables, pre_desc, post_desc = LatexParser._process_synapse_equations(synapse)

        eqs = ""
        for var in variables:
            eqs += """
\\begin{dmath*}
%(eq)s
\\end{dmath*}
""" % {'eq': var['latex']}

        variables_eqs = """
%(eqs)s
\\\\ \\hline
""" % {'eqs': eqs}

        # Synaptic variables
        variables = """
\\textbf{Equations} & %(variables)s  
\\\\ \\hline""" % {'variables':eqs} if eqs != "" else ""

        # PSP
        if psp != "":
            psp_code = """
\\textbf{PSP} & \\begin{dmath*}
%(psp)s
\\end{dmath*}
\\\\ \\hline""" % {'psp': psp}
        else:
            psp_code = ""

        # Spiking neurons have extra fields for the event-driven
        if synapse.type == 'spike':
            if len(pre_desc) > 0:
                txt_pre = ""
                for l in pre_desc:
                    txt_pre += """
\\begin{dmath*}
%(eq)s
\\end{dmath*}
""" % {'eq': l}
                preevent = """
\\textbf{Pre-synaptic event} &
%(preevent)s
\\\\ \\hline
""" % {'preevent': txt_pre}
            else:
                preevent = ""

            if len(post_desc) > 0:
                txt_post = ""
                for l in post_desc:
                    txt_post += """
\\begin{dmath*}
%(eq)s
\\end{dmath*}
""" % {'eq': l}
                postevent = """
\\textbf{Post-synaptic event} &
%(postevent)s
\\\\ \\hline
""" % {'postevent': txt_post}
            else:
                postevent = ""
        else:
            preevent = ""
            postevent = ""

        # Possible functions
        functions = ""
        if not synapse.functions == None:
            functions = """
\\textbf{Functions} &
%(functions)s
\\\\ \\hline
""" % {'functions': LatexParser._process_functions(synapse.functions)}

        # Build the dictionary
        desc = {
            'name': synapse_name,
            'description': synapse.short_description,
            'firstsynapse': firstsynapse if idx == 0 else "",
            'variables': variables,
            'psp': psp_code,
            'preevent': preevent,
            'postevent': postevent,
            'functions': functions
        }

        # Generate the code
        synapses += synapse_tpl % desc

    return synapses
Пример #6
0
def _generate_neuron_models(net_id):
    neurons = ""

    firstneuron = "\\hdr{2}{D}{Neuron Models}\\\\ \\hline"

    neuron_tpl = """
\\noindent
\\begin{tabularx}{\\linewidth}{|p{0.15\\linewidth}|X|}\\hline
%(firstneuron)s
\\textbf{Name} & %(name)s \\\\ \\hline
\\textbf{Type} & %(description)s\\\\ \\hline
\\textbf{%(equation_type)s} &
%(variables)s
%(spike)s
%(functions)s
\\end{tabularx}
\\vspace{2ex}
"""
    for idx, neuron in enumerate(Global._objects['neurons']):

        # Name
        if neuron.name in Neuron._default_names.values(): # name not set
            neuron_name = "Neuron " + str(neuron._rk_neurons_type)
        else:
            neuron_name = neuron.name

        # Generate the code for the equations
        variables, spike_condition, spike_reset = LatexParser._process_neuron_equations(neuron)

        eqs = ""
        for var in variables:
            eqs += """
\\begin{dmath*}
%(eq)s
\\end{dmath*}
""" % {'eq': var['latex']}

        variables_eqs = """
%(eqs)s
\\\\ \\hline
""" % {'eqs': eqs}

        # Spiking neurons have an extra field for the spike condition
        spike_extra = ""
        if neuron.type == 'spike':
            spike_code = "If $" + spike_condition + "$ or $t \leq t^* + t_{\\text{refractory}}$:"

            # Reset
            spike_code += """
            \\begin{enumerate}
                \\item Emit a spike at time $t^*$"""

            for var in spike_reset:
                spike_code += """
            \\item $""" + var + "$"

            spike_code += """
        \\end{enumerate}"""


            spike_extra = """
\\textbf{Spiking} &
%(spike)s
\\\\ \\hline
""" % {'spike': spike_code}

        # Possible function
        functions = ""
        if not neuron.functions == None:
            functions = """
\\textbf{Functions} &
%(functions)s
\\\\ \\hline
""" % {'functions': LatexParser._process_functions(neuron.functions)}

        # Build the dictionary
        desc = {
            'name': neuron_name,
            'description': neuron.short_description,
            'firstneuron': firstneuron if idx ==0 else "",
            'variables': variables_eqs,
            'spike': spike_extra,
            'functions': functions,
            'equation_type': "Subthreshold dynamics" if neuron.type == 'spike' else 'Equations'
        }

        # Generate the code depending on the neuron position
        neurons += neuron_tpl % desc

    return neurons
Пример #7
0
def _generate_synapse_models(net_id):
    firstsynapse = ""
    synapses = ""

    firstsynapse = "\\hdr{2}{E}{Synapse Models}\\\\ \\hline"

    synapse_tpl = """
\\noindent
\\begin{tabularx}{\\linewidth}{|p{0.15\\linewidth}|X|}\\hline
%(firstsynapse)s
\\textbf{Name} & %(name)s \\\\ \\hline
\\textbf{Type} & %(description)s\\\\ \\hline
%(psp)s
%(variables)s
%(preevent)s
%(postevent)s
%(functions)s
\\end{tabularx}
\\vspace{2ex}
"""
    for idx, synapse in enumerate(Global._objects['synapses']):
        # Do not document default synapses
        if synapse.name == "-":
            continue

        # Find a name for the synapse
        if synapse.name in Synapse._default_names.values(): # name not set
            synapse_name = "Synapse " + str(synapse._rk_synapses_type)
        else:
            synapse_name = synapse.name

        # Generate the code for the equations
        psp, variables, pre_desc, post_desc = LatexParser._process_synapse_equations(synapse)

        eqs = ""
        for var in variables:
            eqs += """
\\begin{dmath*}
%(eq)s
\\end{dmath*}
""" % {'eq': var['latex']}

        variables_eqs = """
%(eqs)s
\\\\ \\hline
""" % {'eqs': eqs}

        # Synaptic variables
        variables = """
\\textbf{Equations} & %(variables)s  
\\\\ \\hline""" % {'variables':eqs} if eqs != "" else ""

        # PSP
        if psp != "":
            psp_code = """
\\textbf{PSP} & \\begin{dmath*}
%(psp)s
\\end{dmath*}
\\\\ \\hline""" % {'psp': psp}
        else:
            psp_code = ""

        # Spiking neurons have extra fields for the event-driven
        if synapse.type == 'spike':
            if len(pre_desc) > 0:
                txt_pre = ""
                for l in pre_desc:
                    txt_pre += """
\\begin{dmath*}
%(eq)s
\\end{dmath*}
""" % {'eq': l}
                preevent = """
\\textbf{Pre-synaptic event} &
%(preevent)s
\\\\ \\hline
""" % {'preevent': txt_pre}
            else:
                preevent = ""

            if len(post_desc) > 0:
                txt_post = ""
                for l in post_desc:
                    txt_post += """
\\begin{dmath*}
%(eq)s
\\end{dmath*}
""" % {'eq': l}
                postevent = """
\\textbf{Post-synaptic event} &
%(postevent)s
\\\\ \\hline
""" % {'postevent': txt_post}
            else:
                postevent = ""
        else:
            preevent = ""
            postevent = ""

        # Possible functions
        functions = ""
        if not synapse.functions == None:
            functions = """
\\textbf{Functions} &
%(functions)s
\\\\ \\hline
""" % {'functions': LatexParser._process_functions(synapse.functions)}

        # Build the dictionary
        desc = {
            'name': synapse_name,
            'description': synapse.short_description,
            'firstsynapse': firstsynapse if idx == 0 else "",
            'variables': variables,
            'psp': psp_code,
            'preevent': preevent,
            'postevent': postevent,
            'functions': functions
        }

        # Generate the code
        synapses += synapse_tpl % desc

    return synapses
Пример #8
0
def _generate_neuron_models(net_id):
    neurons = ""

    firstneuron = "\\hdr{2}{D}{Neuron Models}\\\\ \\hline"

    neuron_tpl = """
\\noindent
\\begin{tabularx}{\\linewidth}{|p{0.15\\linewidth}|X|}\\hline
%(firstneuron)s
\\textbf{Name} & %(name)s \\\\ \\hline
\\textbf{Type} & %(description)s\\\\ \\hline
\\textbf{%(equation_type)s} &
%(variables)s
%(spike)s
%(functions)s
\\end{tabularx}
\\vspace{2ex}
"""

    first_neuron = True
    for neuron in Global._objects['neurons']:

        # skip bold models
        if isinstance(neuron, BoldModel):
            continue

        # Name
        if neuron.name in Neuron._default_names.values(): # name not set
            neuron_name = "Neuron " + str(neuron._rk_neurons_type)
        else:
            neuron_name = neuron.name

        # Generate the code for the equations
        variables, spike_condition, spike_reset = LatexParser._process_neuron_equations(neuron)

        eqs = ""
        for var in variables:
            eqs += """
\\begin{dmath*}
%(eq)s
\\end{dmath*}
""" % {'eq': var['latex']}

        variables_eqs = """
%(eqs)s
\\\\ \\hline
""" % {'eqs': eqs}

        # Spiking neurons have an extra field for the spike condition
        spike_extra = ""
        if neuron.type == 'spike':
            spike_code = "If $" + spike_condition + "$ or $t \leq t^* + t_{\\text{refractory}}$:"

            # Reset
            spike_code += """
            \\begin{enumerate}
                \\item Emit a spike at time $t^*$"""

            for var in spike_reset:
                spike_code += """
            \\item $""" + var + "$"

            spike_code += """
        \\end{enumerate}"""


            spike_extra = """
\\textbf{Spiking} &
%(spike)s
\\\\ \\hline
""" % {'spike': spike_code}

        # Possible function
        functions = ""
        if not neuron.functions == None:
            functions = """
\\textbf{Functions} &
%(functions)s
\\\\ \\hline
""" % {'functions': LatexParser._process_functions(neuron.functions)}

        # Build the dictionary
        desc = {
            'name': neuron_name,
            'description': neuron.short_description,
            'firstneuron': firstneuron if first_neuron else "",
            'variables': variables_eqs,
            'spike': spike_extra,
            'functions': functions,
            'equation_type': "Subthreshold dynamics" if neuron.type == 'spike' else 'Equations'
        }

        # Generate the code depending on the neuron position
        neurons += neuron_tpl % desc

        # first_neuron = False, to prevent multiple header
        first_neuron = False

    return neurons
Пример #9
0
def _generate_summary(net_id):

    txt = """
# Structure of the network
"""

    # General information
    backend = 'default'
    if Global.config['paradigm'] == 'cuda':
        backend = "CUDA"
    elif Global.config['paradigm'] == "openmp" and Global.config['num_threads'] > 1:
        backend = "OpenMP"
    txt +="""
* ANNarchy %(version)s using the %(backend)s backend.
* Numerical step size: %(dt)s ms.
""" % {'version': ANNarchy.__release__, 'backend': backend, 'dt': Global.config['dt']}

    # Populations
    if len(Global._network[net_id]['populations']) > 0:
        headers = ["Population", "Size", "Neuron type"]
        populations = []
        for pop in Global._network[net_id]['populations']:
            # Find a name for the neuron
            neuron_name = "Neuron " + str(pop.neuron_type._rk_neurons_type) if pop.neuron_type.name in Neuron._default_names.values() \
                else pop.neuron_type.name

            populations.append([
                pop.name, 
                pop.geometry if len(pop.geometry)>1 else pop.size, 
                neuron_name])

        txt += """
## Populations

"""
        txt += _make_table(headers, populations)


    # Projections
    if len(Global._network[net_id]['projections']) > 0 :
        headers = ["Source", "Destination", "Target", "Synapse type", "Pattern"]
        projections = []
        for proj in Global._network[net_id]['projections']:
            # Find a name for the synapse
            synapse_name = "Synapse " + str(proj.synapse_type._rk_synapses_type) if proj.synapse_type.name in Synapse._default_names.values() \
                else proj.synapse_type.name

            projections.append([
                proj.pre.name, 
                proj.post.name, 
                LatexParser._format_list(proj.target, ' / '),
                synapse_name,
                proj.connector_description
                ])

        txt += """
## Projections

"""
        txt += _make_table(headers, projections)

    # Monitors
    if len(Global._network[net_id]['monitors']) > 0:
        headers = ["Object", "Variables", "Period"]
        monitors = []
        for monitor in Global._network[net_id]['monitors']:
            monitors.append([
                monitor.object.name + (" (subset)" if isinstance(monitor.object, PopulationView) else ""), 
                LatexParser._format_list(monitor.variables, ', '),
                monitor.period
                ])

        txt += """
## Monitors

"""
        txt += _make_table(headers, monitors)

    # Functions
    if len(Global._objects['functions']) > 0 :
        txt += """## Functions

"""
        for name, func in Global._objects['functions']:
            txt += LatexParser._process_functions(func, begin="$$", end="$$\n\n")

    return txt
Пример #10
0
def _generate_neuron_models(net_id):
    txt = """
# Neuron models
"""
    for idx, neuron in enumerate(Global._objects['neurons']):

        # Name
        if neuron.name in Neuron._default_names.values(): # name not set
            neuron_name = "Neuron " + str(neuron._rk_neurons_type)
        else:
            neuron_name = neuron.name

        # Description
        description = neuron.short_description
        if description == None:
            description = "Spiking neuron." if neuron.type == 'spike' else 'Rate-coded neuron'

        # Parameters
        parameters = extract_parameters(neuron.parameters, neuron.extra_values)
        parameters_list = [
            ["$" + LatexParser._latexify_name(param['name'], []) + "$", param['init'], 
                _adapt_locality_neuron(param['locality']), param['ctype']] 
                    for param in parameters]

        parameters_headers = ["Name", "Default value", "Locality", "Type"]
        parameters_table = _make_table(parameters_headers, parameters_list)

        if len(parameters) == 0:
            parameters_table = "$$\\varnothing$$"

        # Generate the code for the equations
        variables, spike_condition, spike_reset = LatexParser._process_neuron_equations(neuron)
        
        eqs = _process_variables(variables, neuron=True)

        # Spiking neurons
        if neuron.type == 'spike':

            reset_txt = "* Emit a spike a time $t$.\n"
            for r in spike_reset:
                reset_txt += "* $" + r + "$\n"

            eqs += """
**Spike emission:**

if $%(condition)s$ :

%(reset)s
""" % {'condition': spike_condition, 'reset': reset_txt}


        # Possible function
        if not neuron.functions == None:
            eqs += """
**Functions**

%(functions)s
""" % {'functions': LatexParser._process_functions(neuron.functions, begin="$$", end="$$\n\n")}

        # Finalize the template
        txt += neuron_tpl % {   'name': neuron_name, 
                                'description': description, 
                                'parameters': parameters_table,
                                'eqs': eqs}

    return txt