示例#1
0
def run(config_file):
    conf = config.from_json(config_file)
    io.setup_output_dir(conf)
    nrn.load_neuron_modules(conf)
    graph = BioGraph.from_config(conf, property_schema=AIPropertySchema)
    net = BioNetwork.from_config(conf, graph)
    sim = Simulation.from_config(conf, network=net)
    sim.run()
    nrn.quit_execution()
示例#2
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    graph = BioGraph.from_config(conf,
                                 network_format=TabularNetwork_AI,
                                 property_schema=AIPropertySchema)

    net = BioNetwork.from_config(conf, graph)  # create network of in NEURON
    sim = Simulation(conf, network=net)  # initialize a simulation
    sim.attach_current_clamp()
    sim.set_recordings(
    )  # set recordings of relevant variables to be saved as an ouput
    sim.run()  # run simulation

    nrn.quit_execution()  # exit
示例#3
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    nrn.load_py_modules(
        cell_models=set_cell_params,  # load custom Python modules
        syn_models=set_syn_params,
        syn_weights=set_weights)

    graph = BioGraph.from_config(
        conf,  # create network graph containing parameters of the model
        network_format=TabularNetwork_AI,
        property_schema=AIPropertySchema)

    net = BioNetwork.from_config(
        conf, graph
    )  # create netwosim = Simulation.from_config(conf, network=net)  rk of in NEURON
    sim = Simulation.from_config(conf, network=net)  # initialize a simulation
    sim.run()  # run simulation

    if MPI_RANK == 0:
        try:
            # Check spikes
            print2log0('Checking spike times')
            assert (os.path.exists(conf['output']['spikes_ascii_file']))
            assert (spike_files_equal(conf['output']['spikes_ascii_file'],
                                      'expected/spikes.txt'))
            print2log0('Spikes passed!')

            # Check extracellular recordings
            print2log0('Checking ECP output')
            check_ecp()
            print2log0('ECP passed!')

            # Check saved variables
            print2log0('Checking NEURON saved variables')
            for saved_gids in conf['node_id_selections']['save_cell_vars']:
                check_cellvars(saved_gids, conf)
            print2log0('variables passed!')
        except AssertionError:
            _, _, tb = sys.exc_info()
            traceback.print_tb(tb)

    pc.barrier()
    nrn.quit_execution()  # exit
示例#4
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    nrn.load_py_modules(
        cell_models=set_cell_params,  # load custom Python modules
        syn_models=set_syn_params,
        syn_weights=set_weights)

    graph = BioGraph.from_config(
        conf)  # create network graph containing parameters of the model

    net = BioNetwork.from_config(conf, graph)  # create network of in NEURON
    sim = Simulation.from_config(conf, net)  # initialize a simulation
    # sim.set_recordings()                        # set recordings of relevant variables to be saved as an ouput
    sim.run()  # run simulation

    assert (os.path.exists(conf['output']['spikes_ascii_file']))
    assert (spike_files_equal(conf['output']['spikes_ascii_file'],
                              'expected/spikes.txt'))
    nrn.quit_execution()  # exit
示例#5
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    nrn.load_py_modules(
        cell_models=set_cell_params,  # load custom Python modules
        syn_models=set_syn_params,
        syn_weights=set_weights)

    graph = BioGraph.from_config(
        conf,  # create network graph containing parameters of the model
        network_format=TabularNetwork_AI,
        property_schema=AIPropertySchema)

    net = BioNetwork.from_config(
        conf, graph
    )  # create netwosim = Simulation.from_config(conf, network=net)  rk of in NEURON
    sim = Simulation.from_config(conf, network=net)  # initialize a simulation
    # sim.set_recordings()                        # set recordings of relevant variables to be saved as an ouput
    sim.run()  # run simulation

    assert (os.path.exists(conf['output']['spikes_ascii_file']))
    assert (spike_files_equal(conf['output']['spikes_ascii_file'],
                              'expected/spikes.txt'))

    # Test the results of the ecp
    SAMPLE_SIZE = 100
    expected_h5 = h5py.File('expected/ecp.h5', 'r')
    nrows, ncols = expected_h5['ecp'].shape
    expected_mat = np.matrix(expected_h5['ecp'])
    results_h5 = h5py.File('output/ecp.h5', 'r')
    assert ('ecp' in results_h5.keys())
    results_mat = np.matrix(results_h5['ecp'][:])

    assert (results_h5['ecp'].shape == (nrows, ncols))
    for i, j in zip(randint(0, nrows, size=SAMPLE_SIZE),
                    randint(0, ncols, size=SAMPLE_SIZE)):
        assert (results_mat[i, j] == expected_mat[i, j])

    nrn.quit_execution()  # exit
示例#6
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    nrn.load_py_modules(
        cell_models=set_cell_params,  # load custom Python modules
        syn_models=set_syn_params,
        syn_weights=set_weights)

    graph = BioGraph.from_config(
        conf,  # create network graph containing parameters of the model
        network_format=TabularNetwork_AI,
        property_schema=AIPropertySchema)

    net = BioNetwork.from_config(conf, graph)
    sim = Simulation.from_config(conf, network=net)
    sim.run()

    assert (os.path.exists(conf['output']['spikes_ascii_file']))
    assert (spike_files_equal(conf['output']['spikes_ascii_file'],
                              'expected/spikes.txt'))
    nrn.quit_execution()  # exit
示例#7
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    nrn.load_py_modules(
        cell_models=set_cell_params,  # load custom Python modules
        syn_models=set_syn_params,
        syn_weights=set_weights)

    graph = BioGraph.from_config(
        conf,  # create network graph containing parameters of the model
        #network_format=TabularNetwork_AI,
        property_schema=AIPropertySchema)
    '''
    graph = BioGraph.from_config(conf)
    '''

    net = BioNetwork.from_config(conf, graph)  # create network of in NEURON
    sim = Simulation(conf, network=net)  # initialize a simulation
    sim.set_recordings(
    )  # set recordings of relevant variables to be saved as an ouput
    sim.run()  # run simulation

    nrn.quit_execution()  # exit
示例#8
0
import os, sys

import bmtk.simulator.bionet.config as config
import bmtk.analyzer.spikes_loader as spkload
import bmtk.analyzer.spikes_analyzer as spkan
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

import time
import numpy as np


config_file = "config.json"     # Get config from the command line argument
conf = config.from_json(config_file)

spikes_file_name = conf["output"]["spikes_hdf5_file"]
#spikes_file_name = conf["output"]["spikes_ascii"]

t1=time.time()
spikes_v1 = spkload.load_spikes(spikes_file_name)
t2=time.time()
print "load time:",t2-t1

tstop = conf["run"]["tstop"]

ncells=14
node_ids = np.arange(ncells)

示例#9
0
    def from_config(cls, config_file, graph):
        """A method for building a network from a config file.

        :param config_file: A json file (or object) with simulation parameters for loading NEURON network.
        :param graph: A BioGraph object that has already been loaded.
        :return: A BioNetwork object with nodes and connections that can be ran in a NEURON simulator.
        """
        io.print2log0('Number of processors: {}'.format(nhost))
        io.print2log0('Setting up network...')

        # load the json file or object
        if isinstance(config_file, basestring):
            config = cfg.from_json(config_file, validate=True)
        elif isinstance(config_file, dict):
            config = config_file
        else:
            raise Exception('Could not convert {} (type "{}") to json.'.format(
                config_file, type(config_file)))
        network = cls(graph)

        if 'run' not in config:
            raise Exception(
                'Json file is missing "run" entry. Unable to build Bionetwork.'
            )
        run_dict = config['run']

        # Overwrite default network parameters if they exists in the config file
        if 'spike_threshold' in run_dict:
            network.spike_threshold = run_dict['spike_threshold']
        if 'dL' in run_dict:
            network.dL = run_dict['dL']
        if 'calc_ecp' in run_dict:
            network.calc_ecp = run_dict['calc_ecp']

        # build the cells
        network.save_connections = config['output'].get('save_synapses', False)
        io.print2log('Building cells...')
        network.build_cells()

        # list of cells who parameters will be saved to h5
        if 'node_id_selections' in config and 'save_cell_vars' in config[
                'node_id_selections']:
            network.save_gids(config['node_id_selections']['save_cell_vars'])
        # Find and save network stimulation. Do this before loading external/internal connections.

        if 'input' in config:
            for netinput in config['input']:
                if netinput['type'] == 'external_spikes' and netinput[
                        'format'] == 'nwb':
                    # Load external network spike trains from an NWB file.
                    # io.print2log0('Load input for {}'.format(netinput['network']))
                    network.add_spikes_nwb(netinput['source_nodes'],
                                           netinput['file'], netinput['trial'])

                elif netinput['type'] == 'external_spikes' and netinput[
                        'format'] == 'csv':
                    network.add_spikes_csv(netinput['source_nodes'],
                                           netinput['file'])

                # TODO: Allow for external spike trains from csv file or user function
                # TODO: Add Iclamp code.

            io.print2log0('    Setting up external cells...')
            network.make_stims()
        io.print2log0('Cells are built!')

        for netname in graph.external_networks():
            network.set_external_connections(netname)

        network.set_recurrent_connections()
        io.print2log0('Network is built!')

        if network.save_connections:
            io.print2log0('Saving synaptic connections:')
            network.write_connections(config['output']['output_dir'])
            io.print2log0('    Synaptic connections saved to {}.'.format(
                config['output']['output_dir']))

        return network
示例#10
0
 def _from_json(self, file_name):
     return cfg.from_json(file_name, validate=True)