Exemple #1
0
def test_coba_synapse():
    nineml_component = TestableComponent('coba_synapse')()
    if not nineml_component:
        raise RuntimeError('Cannot load NineML component')

    timeHorizon = 1
    reportingInterval = 0.001
    parameters = {
        'CobaSyn.q': 4.0E-9,
        'CobaSyn.tau': 0.005,
        'CobaSyn.vrev': 0.0
    }
    initial_conditions = {
        'CobaSyn.g': 1E-8,
    }
    analog_ports_expressions = {'CobaSyn.V': -0.050}
    event_ports_expressions = {
        'CobaSyn.spikeinput':
        ''  #'0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90'
    }
    active_regimes = {'CobaSyn': 'cobadefaultregime'}
    variables_to_report = {'CobaSyn.I': True}

    inspector = nineml_component_inspector()
    inspector.inspect(nineml_component,
                      timeHorizon=timeHorizon,
                      reportingInterval=reportingInterval,
                      parameters=parameters,
                      initial_conditions=initial_conditions,
                      active_regimes=active_regimes,
                      analog_ports_expressions=analog_ports_expressions,
                      event_ports_expressions=event_ports_expressions,
                      variables_to_report=variables_to_report)
    results = inspector.showQtGUI()
    return results, inspector
Exemple #2
0
def test_iaf():
    nineml_component = TestableComponent('iaf')()
    if not nineml_component:
        raise RuntimeError('Cannot load NineML component')

    timeHorizon = 1
    reportingInterval = 0.001
    parameters = {
        'iaf.cm': 0.2E-9,
        'iaf.gl': 1E-8,
        'iaf.taurefrac': 0.001,
        'iaf.vreset': -0.060,
        'iaf.vrest': -0.060,
        'iaf.vthresh': -0.040
    }
    initial_conditions = {'iaf.V': -0.050, 'iaf.tspike': -1.0}
    analog_ports_expressions = {'iaf.ISyn': 0.0}
    event_ports_expressions = {}
    active_regimes = {'iaf': 'subthresholdregime'}
    variables_to_report = {'iaf.V': True}

    inspector = nineml_component_inspector()
    inspector.inspect(nineml_component,
                      timeHorizon=timeHorizon,
                      reportingInterval=reportingInterval,
                      parameters=parameters,
                      initial_conditions=initial_conditions,
                      active_regimes=active_regimes,
                      analog_ports_expressions=analog_ports_expressions,
                      event_ports_expressions=event_ports_expressions,
                      variables_to_report=variables_to_report)
    results = inspector.showQtGUI()
    return results, inspector
Exemple #3
0
def test_Izhikevich():
    nineml_component = TestableComponent('izhikevich')()
    if not nineml_component:
        raise RuntimeError('Cannot load NineML component')

    timeHorizon = 1
    reportingInterval = 0.001
    parameters = {
        "Izhikevich.a": 0.02,
        "Izhikevich.b": 0.2,
        "Izhikevich.c": -0.05,
        "Izhikevich.d": 2.0,
        "Izhikevich.theta": 0.03
    }
    initial_conditions = {"Izhikevich.U": 0.0, "Izhikevich.V": -0.07}
    analog_ports_expressions = {"Izhikevich.Isyn": "0.1"}
    event_ports_expressions = {}
    active_regimes = {}
    variables_to_report = {'Izhikevich.U': True, 'Izhikevich.V': True}

    inspector = nineml_component_inspector()
    inspector.inspect(nineml_component,
                      timeHorizon=timeHorizon,
                      reportingInterval=reportingInterval,
                      parameters=parameters,
                      initial_conditions=initial_conditions,
                      active_regimes=active_regimes,
                      analog_ports_expressions=analog_ports_expressions,
                      event_ports_expressions=event_ports_expressions,
                      variables_to_report=variables_to_report)
    results = inspector.showQtGUI()
    return results, inspector
def main(src=None):

    build_dir = 'build/'
    output_dir = 'output/'

    print 'Clearing output directory: %s' % output_dir
    clear_and_recreate_dir(output_dir)

    # single_file_mode = os.path.isfile(src)
    if src:
        print ' Testing Component: %s' % src
        src_files = [src]
    else:
        print ' Testing all Components.'
        src_files = TestableComponent.list_available()
        # src_files = glob.glob( src + '/*.py')

    for src_file in src_files:

        # Clear the build-dir
        clear_and_recreate_dir(build_dir)
        clear_and_recreate_dir('nineml_mechanisms')

        # Load the file:
        print '  -- Loading from file: %s' % src_file
        t = TestableComponent(src_file)

        # Run some tests:
        TestXMLWriteReadWrite.test(t, build_dir=build_dir)
        TestWriteDot.test(t, build_dir=build_dir)

        if t.has_metadata():
            if t.metadata.is_neuron_model:
                test_write_mod(t)

            if src:
                flg = 'supports_test_pynn_neuron_std'
                if t.metadata.__dict__.get(flg, False):
                    test_pynn_neuron_std(t)

        # Save all the output files:

        shutil.move(build_dir, output_dir)
        shutil.move(os.path.join(output_dir, build_dir),
                    os.path.join(output_dir, src_file.replace('.py', '')))
        print '  Everything Ran Fine'
        print '  -------------------'
Exemple #5
0
def test_other(component_name):
    nineml_component = TestableComponent(component_name)()
    if not nineml_component:
        raise RuntimeError(
            'Cannot load NineML component {0}'.format(component_name))

    inspector = nineml_component_inspector()
    inspector.inspect(nineml_component)
    results = inspector.showQtGUI()
    return results, inspector
Exemple #6
0
def test_hierachical_iaf_1coba():
    nineml_component = TestableComponent('hierachical_iaf_1coba')()
    if not nineml_component:
        raise RuntimeError('Cannot load NineML component')

    timeHorizon = 1.0
    reportingInterval = 0.001
    initial_conditions = {
        "iaf_1coba.iaf.tspike": -1.0,
        "iaf_1coba.iaf.V": -0.060,
        "iaf_1coba.cobaExcit.g": 0.0
    }
    parameters = {
        "iaf_1coba.iaf.gl": 1E-8,
        "iaf_1coba.iaf.vreset": -0.060,
        "iaf_1coba.iaf.taurefrac": 0.001,
        "iaf_1coba.iaf.vthresh": -0.040,
        "iaf_1coba.iaf.vrest": -0.060,
        "iaf_1coba.iaf.cm": 0.2E-9,
        "iaf_1coba.cobaExcit.vrev": 0.0,
        "iaf_1coba.cobaExcit.q": 4.0E-9,
        "iaf_1coba.cobaExcit.tau": 0.005
    }
    variables_to_report = {
        "iaf_1coba.cobaExcit.I": True,
        "iaf_1coba.iaf.V": True
    }
    event_ports_expressions = {
        "iaf_1coba.cobaExcit.spikeinput":
        "0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90"
    }
    active_regimes = {
        "iaf_1coba.cobaExcit": "cobadefaultregime",
        "iaf_1coba.iaf": "subthresholdregime"
    }
    analog_ports_expressions = {}

    inspector = nineml_component_inspector()
    inspector.inspect(nineml_component,
                      timeHorizon=timeHorizon,
                      reportingInterval=reportingInterval,
                      parameters=parameters,
                      initial_conditions=initial_conditions,
                      active_regimes=active_regimes,
                      analog_ports_expressions=analog_ports_expressions,
                      event_ports_expressions=event_ports_expressions,
                      variables_to_report=variables_to_report)
    results = inspector.showQtGUI()
    return results, inspector
Exemple #7
0

"""

#import nineml.abstraction_layer as nineml
#import os
from nineml.abstraction_layer.testing_utils import TestableComponent
from nineml.abstraction_layer.flattening import flatten
#from nineml.abstraction_layer.flattening import ComponentFlattener
from nineml.abstraction_layer.component_modifiers import ComponentModifier
from nineml.utility import LocationMgr
#from nineml.abstraction_layer.visitors import RenameSymbol

LocationMgr.StdAppendToPath()

comp_data = TestableComponent('nestequivalent_iaf_cond_exp')

# Build the component:
component = comp_data()
component = flatten(component)
component.backsub_all()
ComponentModifier.close_all_reduce_ports(component=component)

# Copy the descriptive strings:
component.short_description = comp_data.metadata.short_description
component.long_description = comp_data.metadata.long_description

# Get the initial regime. If this component comes from an flattened component,
# then we should look up the new regime from the locations in the old
# components, hence the nedd for this code:
initial_regime = comp_data.metadata.initial_regime
            .format(outdir, texFile))
        res = os.system(
            '/usr/bin/pdflatex -interaction=nonstopmode -output-directory {0} {1}'
            .format(outdir, texFile))
    else:
        res = os.system(
            '/usr/bin/pdflatex -interaction=nonstopmode {0}'.format(texFile))
        res = os.system(
            '/usr/bin/pdflatex -interaction=nonstopmode {0}'.format(texFile))

    return res


def showFile(pdf):
    if os.name == 'nt':
        os.filestart(pdf)
    elif os.name == 'posix':
        os.system('/usr/bin/xdg-open ' + pdf)


if __name__ == "__main__":
    component = 'hierachical_iaf_1coba'
    tex = component + '.tex'
    pdf = component + '.pdf'
    nineml_component = TestableComponent(component)()
    inspector = nineml_component_inspector()
    inspector.inspect(nineml_component)
    createLatexReport(inspector, [], 'nineml-tex-template.tex', tex)
    res = createPDF(tex)
    showFile(pdf)
Exemple #9
0
        "iaf_1coba.cobaExcit.I": True,
        "iaf_1coba.iaf.V": True
    }
    spike_times = [str(t) for t in numpy.arange(0, 0.20, 0.005)]
    #print(spike_times)
    event_ports_expressions = {
        "iaf_1coba.cobaExcit.spikeinput": ''  #', '.join(spike_times)
    }
    active_regimes = {
        "iaf_1coba.cobaExcit": "cobadefaultregime",
        "iaf_1coba.iaf": "subthresholdregime"
    }
    analog_ports_expressions = {}

    # Load the Component:
    nineml_comp = TestableComponent('hierachical_iaf_1coba')()
    if not nineml_comp:
        raise RuntimeError('Cannot load NineML component')

    # Create Log, Solver, DataReporter and Simulation object
    log = daeBaseLog()
    daesolver = daeIDAS()

    #from daetools.solvers import pySuperLU as superlu
    #lasolver = superlu.daeCreateSuperLUSolver()
    #daesolver.SetLASolver(lasolver)

    model = nineml_daetools_bridge(nineml_comp.name, nineml_comp, None, '')
    simulation = nineml_daetools_simulation(
        model,
        timeHorizon=timeHorizon,
Exemple #10
0
"""
Example of using a cell type defined in 9ML with pyNN.neuron
"""

#from std_pynn_simulation import std_pynn_simulation, RecordValue

from nineml.abstraction_layer.testing_utils import TestableComponent
from nineml.abstraction_layer.testing_utils import std_pynn_simulation, RecordValue

test_component = TestableComponent('hierachical_iaf_2coba')()

parameters = {
    'iaf.cm': 1.0,
    'iaf.gl': 50.0,
    'iaf.taurefrac': 5.0,
    'iaf.vrest': -65.0,
    'iaf.vreset': -65.0,
    'iaf.vthresh': -50.0,
    'cobaExcit.tau': 2.0,
    'cobaInhib.tau': 5.0,
    'cobaExcit.vrev': 0.0,
    'cobaInhib.vrev': -70.0,
}

initial_values = {
    'iaf_V': parameters['iaf.vrest'],
    'tspike': -1e99,
    'regime': 1002,
}

synapse_components = [
Exemple #11
0
def run(plot_and_show=True):
    import sys
    from os.path import abspath, realpath, join
    import numpy
    import nineml

    root = abspath(join(realpath(nineml.__path__[0]), "../../.."))
    sys.path.append(join(root, "lib9ml/python/examples/AL"))
    sys.path.append(join(root, "code_generation/nmodl"))
    sys.path.append(join(root, "code_generation/nest2"))

    #from nineml.abstraction_layer.example_models import  get_hierachical_iaf_3coba
    from nineml.abstraction_layer.testing_utils import TestableComponent
    from nineml.abstraction_layer.flattening import ComponentFlattener

    import pyNN.neuron as sim
    import pyNN.neuron.nineml as pyNNml

    from pyNN.utility import init_logging

    init_logging(None, debug=True)
    sim.setup(timestep=0.1, min_delay=0.1)

    #test_component = get_hierachical_iaf_3coba()
    test_component = TestableComponent('hierachical_iaf_3coba')()

    from nineml.abstraction_layer.writers import DotWriter
    DotWriter.write(test_component, 'test1.dot')

    from nineml.abstraction_layer.writers import XMLWriter
    XMLWriter.write(test_component, 'iaf_3coba.xml')

    celltype_cls = pyNNml.nineml_celltype_from_model(
        name="iaf_3coba",
        nineml_model=test_component,
        synapse_components=[
            pyNNml.CoBaSyn(namespace='AMPA', weight_connector='q'),
            pyNNml.CoBaSyn(namespace='GABAa', weight_connector='q'),
            pyNNml.CoBaSyn(namespace='GABAb', weight_connector='q'),
        ])

    parameters = {
        'iaf.cm': 1.0,
        'iaf.gl': 50.0,
        'iaf.taurefrac': 5.0,
        'iaf.vrest': -65.0,
        'iaf.vreset': -65.0,
        'iaf.vthresh': -50.0,
        'AMPA.tau': 2.0,
        'GABAa.tau': 5.0,
        'GABAb.tau': 50.0,
        'AMPA.vrev': 0.0,
        'GABAa.vrev': -70.0,
        'GABAb.vrev': -95.0,
    }

    parameters = ComponentFlattener.flatten_namespace_dict(parameters)

    cells = sim.Population(1, celltype_cls, parameters)
    cells.initialize('iaf_V', parameters['iaf_vrest'])
    cells.initialize('tspike', -1e99)  # neuron not refractory at start
    cells.initialize('regime', 1002)  # temporary hack

    input = sim.Population(3, sim.SpikeSourceArray)

    numpy.random.seed(12345)
    input[0].spike_times = numpy.add.accumulate(
        numpy.random.exponential(1000.0 / 100.0, size=1000))
    input[1].spike_times = numpy.add.accumulate(
        numpy.random.exponential(1000.0 / 20.0, size=1000))
    input[2].spike_times = numpy.add.accumulate(
        numpy.random.exponential(1000.0 / 50.0, size=1000))

    connector = sim.OneToOneConnector(weights=1.0, delays=0.5)

    conn = [
        sim.Projection(input[0:1], cells, connector, target='AMPA'),
        sim.Projection(input[1:2], cells, connector, target='GABAa'),
        sim.Projection(input[2:3], cells, connector, target='GABAb')
    ]

    cells._record('iaf_V')
    cells._record('AMPA_g')
    cells._record('GABAa_g')
    cells._record('GABAb_g')
    cells.record()

    sim.run(100.0)

    cells.recorders['iaf_V'].write("Results/nineml_neuron.V",
                                   filter=[cells[0]])
    cells.recorders['AMPA_g'].write("Results/nineml_neuron.g_exc",
                                    filter=[cells[0]])
    cells.recorders['GABAa_g'].write("Results/nineml_neuron.g_gabaA",
                                     filter=[cells[0]])
    cells.recorders['GABAb_g'].write("Results/nineml_neuron.g_gagaB",
                                     filter=[cells[0]])

    t = cells.recorders['iaf_V'].get()[:, 1]
    v = cells.recorders['iaf_V'].get()[:, 2]
    gInhA = cells.recorders['GABAa_g'].get()[:, 2]
    gInhB = cells.recorders['GABAb_g'].get()[:, 2]
    gExc = cells.recorders['AMPA_g'].get()[:, 2]

    if plot_and_show:
        import pylab
        pylab.subplot(211)
        pylab.plot(t, v)
        pylab.ylabel('voltage [mV]')
        pylab.suptitle("AMPA, GABA_A, GABA_B")
        pylab.subplot(212)
        pylab.plot(t, gInhA, label='GABA_A')
        pylab.plot(t, gInhB, label='GABA_B')
        pylab.plot(t, gExc, label='AMPA')
        pylab.ylabel('conductance [nS]')
        pylab.xlabel('t [ms]')
        pylab.legend()

        pylab.show()

    sim.end()
Exemple #12
0
def test_generator():
    testable_components = [TestableComponent(source_file)
                       for source_file in TestableComponent.list_available()]
    nrn_components = [tc() for tc in testable_components] #  if (tc.has_metadata() and tc.metadata.is_neuron_model)]
    for tc in nrn_components:
        yield write_and_compile_nmodl, tc
#import pyNN.neuron.nineml as pyNNml

import pyNN.nest as sim
import pyNN.nest.nineml as pyNNml
from pyNN.nest import simulator
from pyNN import common, recording
common.simulator = simulator
recording.simulator = simulator

from pyNN.utility import init_logging

init_logging(None, debug=True)
sim.setup(timestep=0.01, min_delay=0.1)

#testModel = get_hierachical_iaf_3coba()
testModel = TestableComponent('hierachical_iaf_3coba')

celltype_cls = pyNNml.nineml_celltype_from_model(
    name="iaf_3coba",
    nineml_model=testModel,
    synapse_components=[
        pyNNml.CoBaSyn(namespace='AMPA', weight_connector='q'),
        pyNNml.CoBaSyn(namespace='GABAa', weight_connector='q'),
        pyNNml.CoBaSyn(namespace='GABAb', weight_connector='q'),
    ])

parameters = {
    'iaf.cm': 1.0,
    'iaf.gl': 50.0,
    'iaf.taurefrac': 5.0,
    'iaf.vrest': -65.0,
"""

"""

from nineml.abstraction_layer.testing_utils import RecordValue, TestableComponent
from nineml.abstraction_layer import ComponentClass, flattening, writers
from nineml.abstraction_layer.testing_utils import std_pynn_simulation

# Load the Component:
coba1_base = TestableComponent('hierachical_iaf_1coba')
coba1 = coba1_base()

# Write the component back out to XML
writers.XMLWriter.write(coba1, 'TestOut_Coba1.xml')
writers.DotWriter.write(coba1, 'TestOut_Coba1.dot')
writers.DotWriter.build('TestOut_Coba1.dot')

# Simulate the Neuron:
records = [
    RecordValue(what='iaf_V', tag='V', label='V'),
    RecordValue(what='regime', tag='Regime', label='Regime'),
]

parameters = flattening.ComponentFlattener.flatten_namespace_dict({
    'cobaExcit_tau':
    5.0,
    'cobaExcit_vrev':
    0,
    'iaf_cm':
    1,
    'iaf_gl':
def test_other(component_name):
    nineml_component = TestableComponent(component_name)()
    if not nineml_component:
        raise RuntimeError('Cannot load NineML component {0}'.format(component_name))

    inspector = nineml_component_inspector()
    inspector.inspect(nineml_component)
    results = inspector.showQtGUI()
    return results, inspector

if __name__ == "__main__":
    tests_data = []
    tmpFolder = tempfile.gettempdir()
    
    app = QtGui.QApplication(sys.argv)
    components = sorted(TestableComponent.list_available())
    component_name, ok = QtGui.QInputDialog.getItem(None, "nineml_desktop_app", "Select the testable component name", components, 0, False)
    if not ok:
       exit(0) 

    component_name = str(component_name)
    if(component_name == 'iaf'):
        results, inspector = test_iaf()
    elif(component_name == 'coba_synapse'):
        results, inspector = test_coba_synapse()
    elif(component_name == 'hierachical_iaf_1coba'):
        results, inspector = test_hierachical_iaf_1coba()
    else:
        results, inspector = test_other(component_name)
    
    if results:
Exemple #16
0
    if not nineml_component:
        raise RuntimeError(
            'Cannot load NineML component {0}'.format(component_name))

    inspector = nineml_component_inspector()
    inspector.inspect(nineml_component)
    results = inspector.showQtGUI()
    return results, inspector


if __name__ == "__main__":
    tests_data = []
    tmpFolder = tempfile.gettempdir()

    app = QtGui.QApplication(sys.argv)
    components = sorted(TestableComponent.list_available())
    component_name, ok = QtGui.QInputDialog.getItem(
        None, "nineml_desktop_app", "Select the testable component name",
        components, 0, False)
    if not ok:
        exit(0)

    component_name = str(component_name)
    if (component_name == 'iaf'):
        results, inspector = test_iaf()
    elif (component_name == 'coba_synapse'):
        results, inspector = test_coba_synapse()
    elif (component_name == 'hierachical_iaf_1coba'):
        results, inspector = test_hierachical_iaf_1coba()
    else:
        results, inspector = test_other(component_name)