Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/shixnya/bmtk into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
shixnya committed May 17, 2024
2 parents 479c6dc + 316314f commit a9fe157
Show file tree
Hide file tree
Showing 60 changed files with 53,814 additions and 28,965 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ docs/tutorial/sim_ch*
docs/tutorial/sim_dyn_syn
examples/**/output*/**
examples/bio_simulated_annealing/updated_weights/*
examples/filter_movie/boc/*
examples/filter_movie/bob_images/*
examples/filter_movie/movies/*
/.eggs
benchmarks/.asv
**/x86_64/**
Expand Down
2 changes: 1 addition & 1 deletion bmtk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
__version__ = '1.0.8'
__version__ = '1.1.0'
264 changes: 171 additions & 93 deletions bmtk/simulator/bionet/modules/comsol.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bmtk/simulator/bionet/modules/iclamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(self, input_type, **mod_args):
def initialize(self, sim):
# Get select node gids, but only for those nodes that are on the current rank (if running on multiple cores)
select_gids = list(sim.net.get_node_set(self._node_set).gids())
gids_on_rank = list(set(select_gids) & set(select_gids))
gids_on_rank = list(set(select_gids) & set(sim.local_gids))

for gid in gids_on_rank:
cell = sim.net.get_cell_gid(gid)
Expand Down
6 changes: 1 addition & 5 deletions bmtk/simulator/filternet/default_setters/cell_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,7 @@ def default_cell_loader(node, template_name, dynamics_params):
cell = sep_ts_onoff_cell

elif model_name == 'LGNOnOFFCell':
wts = [node['weight_dom_0'], node['weight_dom_1']]
kpeaks = [node['kpeaks_dom_0'], node['kpeaks_dom_1']]
delays = [node['delay_dom_0'], node['delay_dom_1']]
# transfer_function = ScalarTransferFunction('s')
temporal_filter = TemporalFilterCosineBump(wts, kpeaks, delays)
temporal_filter = TemporalFilterCosineBump(t_weights, t_kpeaks, t_delays)

spatial_filter_on = GaussianSpatialFilter(sigma=node['sigma_on'], origin=origin, translate=translate)
on_linear_filter = SpatioTemporalFilter(spatial_filter_on, temporal_filter, amplitude=20)
Expand Down
17 changes: 12 additions & 5 deletions bmtk/simulator/pointnet/modules/record_spikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,23 @@ def _get_path(file_name):
self._tmp_file_base = 'tmp_spike_times'
self._spike_labels = os.path.join(self._tmp_dir, self._tmp_file_base)

self._spike_writer = SpikeTrains(cache_dir=tmp_dir, cache_to_disk=cache_to_disk)
self._spike_writer.delimiter = '\t'
self._spike_writer.gid_col = 0
self._spike_writer.time_col = 1
self._spike_writer.compression = compression
# saving them to initialize SpikeTrains in initialize()
self._tmp_dir = tmp_dir
self._cache_to_disk = cache_to_disk
self._compression = compression

self._sort_order = sort_order.none if not spikes_sort_order else sort_order_lu[spikes_sort_order]

self._spike_detector = None

def initialize(self, sim):
# Now this function takes care of initializing the spike_writer.
self._spike_writer = SpikeTrains(cache_dir=self._tmp_dir, cache_to_disk=self._cache_to_disk)
self._spike_writer.delimiter = '\t'
self._spike_writer.gid_col = 0
self._spike_writer.time_col = 1
self._spike_writer.compression = self._compression

self._spike_detector = create_spike_detector(self._spike_labels)
nest.Connect(sim.net.gid_map.gids, self._spike_detector)

Expand Down
4 changes: 4 additions & 0 deletions bmtk/tests/simulator/bionet/test_iclamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def __init__(self):
self.cell = None
self.vm = None

@property
def local_gids(self):
return [0]

def get_node_set(self, _):
return self

Expand Down
30 changes: 21 additions & 9 deletions bmtk/tests/utils/reports/spike_trains/test_spikes_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,29 @@ def test_psg_variable():
times = np.linspace(0.0, 3.0, 1000)
fr = np.exp(-np.power(times - 1.0, 2) / (2*np.power(.5, 2)))*5

psg = PoissonSpikeGenerator(population='test', seed=0.0)
psg = PoissonSpikeGenerator(population='test', seed=100)
psg.add(node_ids=range(10), firing_rate=fr, times=times)

assert(psg.populations == ['test'])
assert(np.all(psg.node_ids() == list(range(10))))
assert(psg.n_spikes() == 59)
assert(np.allclose(psg.time_range(), (139.32107933711294, 2901.3003727909172)))
assert(psg.to_dataframe().shape == (59, 3))
assert(np.allclose(psg.get_times(node_id=0), [442.8378, 520.3624, 640.3880, 1099.0661, 1393.0794, 1725.6109],
atol=1.0e-3))
assert(np.allclose(psg.get_times(node_id=9), [729.6267, 885.2469, 1047.7728, 1276.3554, 1543.6557, 1669.9070,
1881.3605], atol=1.0e-3))
assert(psg.n_spikes() == 54)
assert(np.allclose(psg.time_range(), (170.22331575431056, 2004.337420574704)))
assert(psg.to_dataframe().shape == (54, 3))
assert(np.allclose(psg.get_times(node_id=0), [268.2470, 519.8341, 963.7072, 1004.7012, 1054.3159, 1388.2418, 1727.0501], atol=1.0e-3))
assert(np.allclose(psg.get_times(node_id=9), [302.6400, 706.5132, 719.6730, 897.8392, 1192.0589, 1201.5878, 2004.3374], atol=1.0e-3))


def test_psg_none_seed():
times = np.linspace(0.0, 3.0, 1000)
fr = np.exp(-np.power(times - 1.0, 2) / (2*np.power(.5, 2)))*5

psg0 = PoissonSpikeGenerator(population='test', seed=0)
psg0.add(node_ids=range(10), firing_rate=fr, times=times)

psg_none = PoissonSpikeGenerator(population='test', seed=None)
psg_none.add(node_ids=range(10), firing_rate=fr, times=times)

assert(psg0.n_spikes() != psg_none.n_spikes() and not np.allclose(psg0.n_spikes(), psg_none.n_spikes()))


def test_equals():
Expand Down Expand Up @@ -78,7 +89,8 @@ def test_subset():


if __name__ == '__main__':
test_psg_fixed()
# test_psg_fixed()
# test_psg_variable()
test_psg_none_seed()
# test_equals()
# test_subset()
2 changes: 2 additions & 0 deletions bmtk/utils/reports/compartment/compartment_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ def merge(self):
barrier()
if self._mpi_size > 1 and self._mpi_rank == 0:
h5final = h5py.File(self._final_fpath, 'w')
add_hdf5_version(h5final)
add_hdf5_magic(h5final)

tmp_reports = [CompartmentReader(name) for name in self.temp_files if os.path.exists(name)]
populations = set()
Expand Down
2 changes: 1 addition & 1 deletion bmtk/utils/reports/spike_trains/spike_trains.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self, population=None, seed=None, output_units='ms', **kwargs):
if population is not None and 'default_population' not in kwargs:
kwargs['default_population']= population

if seed:
if seed is not None:
np.random.seed(seed)

super(SpikeGenerator, self).__init__(units=output_units, **kwargs)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/autodocs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'numpydoc',
'sphinx.ext.autosummary',
'nbsphinx',
'IPython.sphinxext.ipython_console_highlighting'
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
4 changes: 3 additions & 1 deletion docs/autodocs/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ Main Tutorials
BioNet: Multiple Nodes with single cell-type <tutorial_single_pop>
BioNet: Heterogeneous network <tutorial_multi_pop>
PointNet: Point-neuron modeling <tutorial_pointnet_modeling>
PopNet: Population-based firing rate models <tutorial_population_modeling>
FilterNet: Full-field flashing movie <tutorial_filter_models>
Auditory FilterNet: Generating stimuli from auditory input <tutorial_auditory_filternet>
PopNet: Population-based firing rate models <tutorial_population_modeling>



Also check out the tutorial series from our `annual workshop <workshop>`_.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
563 changes: 563 additions & 0 deletions docs/tutorial/auditory_filternet.ipynb

Large diffs are not rendered by default.

Binary file added docs/tutorial/sim_aud/audio/sa1.wav
Binary file not shown.
20 changes: 20 additions & 0 deletions docs/tutorial/sim_aud/circuit_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"manifest": {
"$BASE_DIR": "${configdir}",
"$NETWORK_DIR": "$BASE_DIR/network",
"$COMPONENTS_DIR": "$BASE_DIR/components"
},
"components": {
"filter_models_dir": "$COMPONENTS_DIR/filter_models"
},
"networks": {
"nodes": [
{
"nodes_file": "$NETWORK_DIR/aud_nodes.h5",
"node_types_file": "$NETWORK_DIR/aud_node_types.csv"
}
],
"edges": [],
"gap_juncs": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"b_t": 7,
"order_t": 3,
"psi": "-pi/2",
"amplitude": 150,
"direction": 0,
"sigma_f": 1.0
}
4 changes: 4 additions & 0 deletions docs/tutorial/sim_aud/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"network": "./circuit_config.json",
"simulation": "./simulation_config.json"
}
8 changes: 8 additions & 0 deletions docs/tutorial/sim_aud/node_sets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"biophysical_nodes": {
"model_type": "biophysical"
},
"point_nodes": {
"model_type": "point_process"
}
}
22 changes: 22 additions & 0 deletions docs/tutorial/sim_aud/run_filternet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-

"""Simulates an example network of 14 cell receiving two kinds of exernal input as defined in configuration file"""

import os, sys
from bmtk.simulator import filternet


def run(config_file):
config = filternet.Config.from_json(config_file)
config.build_env()

net = filternet.FilterNetwork.from_config(config)
sim = filternet.FilterSimulator.from_config(config, net)
sim.run()


if __name__ == '__main__':
if __file__ != sys.argv[-1]:
run(sys.argv[-1])
else:
run('${CONFIG}')
32 changes: 32 additions & 0 deletions docs/tutorial/sim_aud/simulation_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"manifest": {
"$BASE_DIR": "${configdir}",
"$OUTPUT_DIR": "$BASE_DIR/output"
},
"target_simulator": "LGNModel",
"run": {
"tstart": 0.0,
"tstop": 3000.0,
"dt": 0.001
},
"inputs": {
"movie": {
"input_type": "audio",
"module": "wav_file",
"data_file": "$BASE_DIR/audio/sa1.wav",
"normalize": "full",
"interp_to_freq": true,
"padding": "edge"
}
},
"output": {
"log_file": "log.txt",
"output_dir": "$OUTPUT_DIR",
"spikes_file": "spikes.h5",
"rates_file_csv": "rates.csv",
"spikes_file_csv": "spikes.csv",
"spikes_file_h5": "spikes.h5"
},
"reports": {},
"node_sets_file": "$BASE_DIR/node_sets.json"
}
Loading

0 comments on commit a9fe157

Please sign in to comment.