Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.cfg


!*template*

Expand All @@ -7,13 +7,17 @@
*.gexf.gz
*.h5
*.mat
*.mp4
*.log
*.png
*.pyc
*.sh
*.swp
*.zip
.ipynb_checkpoints
*/.ipynb_checkpoints/*

*.DS_Store
**/.DS_Store

!examples/image1.mat

Expand Down
58 changes: 0 additions & 58 deletions examples/photoreceptor_demo/run_photoreceptor_demo.sh

This file was deleted.

60 changes: 0 additions & 60 deletions examples/retina_demo/run_retina_demo.sh

This file was deleted.

Binary file added examples/retina_demo_RPM/larger_squido.mp4
Binary file not shown.
802 changes: 802 additions & 0 deletions examples/retina_demo_RPM/retina_data_visualization.ipynb

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions examples/retina_demo_RPM/retina_demo_video.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[General]
dt = 5e-4
log = 'none'
steps = 2000

[Retina]
rings = 22
screentype = 'Sphere'
intype = 'Video'
model = 'retina_model_template_RPM_3d_dumb'

[InputType]
[[Video]]
video_file = 'larger_squido.mp4'
steps = 2000 # the same as the one in Gerernal
scale = 100000

[Screen]
[[SphereScreen]]
radius = 5

187 changes: 187 additions & 0 deletions examples/retina_demo_RPM/retina_demo_video_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#!/usr/bin/env python

import os, resource, sys
import argparse

import networkx as nx
import numpy as np

import neurokernel.core_gpu as core
from neurokernel.pattern import Pattern
from neurokernel.tools.logging import setup_logger
from neurokernel.tools.timing import Timer
from neurokernel.LPU.LPU import LPU

import retina.retina as ret
import retina.geometry.hexagon as hx

from retina.InputProcessors.RetinaInputProcessor import RetinaInputProcessor
from neurokernel.LPU.InputProcessors.FileInputProcessor import FileInputProcessor
from neurokernel.LPU.OutputProcessors.FileOutputProcessor import FileOutputProcessor
from retina.screen.map.mapimpl import AlbersProjectionMap
from retina.configreader import ConfigReader
from retina.NDComponents.MembraneModels.PhotoreceptorModel import PhotoreceptorModel
from retina.NDComponents.MembraneModels.ReducedPhotoreceptorModel import ReducedPhotoreceptorModel
from retina.NDComponents.MembraneModels.RPM_Microvilli import RPM_Microvilli
from retina.NDComponents.MembraneModels.RPM_Microvilli_dumb import RPM_Microvilli_dumb
from retina.NDComponents.MembraneModels.RPM_3d_dumb import RPM_3d_dumb
from retina.NDComponents.MembraneModels.BufferPhoton import BufferPhoton

dtype = np.double
RECURSION_LIMIT = 80000


def setup_logging(config):
log = config['General']['log']
file_name = None
screen = False

if log in ['file', 'both']:
file_name = 'neurokernel.log'
if log in ['screen', 'both']:
screen = True
logger = setup_logger(file_name=file_name, screen=screen)

def get_retina_id(i):
return 'retina{}'.format(i)

# number of neurons of `j`th worker out of `worker_num`
# with `total_neurons` neurons overall
def get_worker_num_neurons(j, total_neurons, worker_num):
num_neurons = (total_neurons-1) // worker_num + 1
return min(num_neurons, total_neurons - j*num_neurons)


def add_retina_LPU(config, i, retina, manager):
T = config['General']['dt']
debug = config['Retina']['debug']
time_sync = config['Retina']['time_sync']

input_filename = config['Retina']['input_file']
output_filename = config['Retina']['output_file']
gexf_filename = config['Retina']['gexf_file']
suffix = config['General']['file_suffix']

output_file = '{}{}{}.h5'.format(output_filename, i, suffix)
gexf_file = '{}{}{}.gexf.gz'.format(gexf_filename, i, suffix)

inputmethod = config['Retina']['inputmethod']
if inputmethod == 'read':

print('Reading from previously generated input')
print('The configuration must stay the same.')
input_processor = FileInputProcessor('{}.h5'.format(config['Retina']['input_file']))
else:
print('Using input generating function')
input_processor = RetinaInputProcessor(config, retina)

output_processor = FileOutputProcessor([('V',None)], output_file, sample_interval=1)

G = retina.get_worker_nomaster_graph()
nx.write_gexf(G, gexf_file)

(comp_dict, conns) = LPU.graph_to_dicts(G)
retina_id = get_retina_id(i)

extra_comps = [RPM_3d_dumb, BufferPhoton]

manager.add(LPU, retina_id, T, comp_dict, conns,
device = i, input_processors = [input_processor],
output_processors = [output_processor],
debug=debug, time_sync=time_sync, extra_comps = extra_comps)


def start_simulation(config, manager):
steps = config['General']['steps']
with Timer('retina simulation'):
manager.spawn()
print('Manager spawned')
manager.start(steps=steps)
manager.wait()


def change_config(config, index):
'''
Useful if one wants to run the same simulation
with a few parameters changing based on index value

Need to modify else part

Parameters
----------
config: configuration object
index: simulation index
'''
if index < 0:
pass
else:
suffixes = ['__{}'.format(i) for i in range(4)]
values = range(1, 5)

index %= len(values)
config['General']['file_suffix'] = suffixes[index]
config['Retina']['worker_num'] = values[index]


def get_config_obj(args):
conf_name = args.config

# append file extension if not exist
conf_filename = conf_name if '.' in conf_name else ''.join(
[conf_name, '.cfg'])
conf_specname = os.path.join('..', 'template_spec.cfg')

return ConfigReader(conf_filename, conf_specname)


def main():
import neurokernel.mpi_relaunch
# default limit is low for pickling
# the data structures passed through mpi
sys.setrecursionlimit(RECURSION_LIMIT)
resource.setrlimit(resource.RLIMIT_STACK,
(resource.RLIM_INFINITY, resource.RLIM_INFINITY))

parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', default='default',
help='configuration file')
parser.add_argument('-v', '--value', type=int, default=-1,
help='Value that can overwrite configuration '
'by changing this script accordingly. '
'It is useful when need to run this script '
'repeatedly for different configuration')

args = parser.parse_args()

with Timer('getting configuration'):
conf_obj = get_config_obj(args)
config = conf_obj.conf
change_config(config, args.value)

setup_logging(config)

num_rings = config['Retina']['rings']
radius = config['Retina']['radius']
eulerangles = config['Retina']['eulerangles']

manager = core.Manager()

with Timer('instantiation of retina'):
transform = AlbersProjectionMap(radius, eulerangles).invmap
hexagon = hx.HexagonArray(num_rings=num_rings, radius=radius,
transform=transform)

retina = ret.RetinaArray(hexagon, config)

# sets retina attribute which is required for the generation of
# receptive fields
#if generator is not None:
# generator.generate_datafiles(0, retina)

add_retina_LPU(config, 0, retina, manager)

start_simulation(config, manager)


if __name__ == '__main__':
main()
Binary file added examples/retina_demo_full/larger_squido.mp4
Binary file not shown.
Loading