Skip to content

Commit

Permalink
read delay list
Browse files Browse the repository at this point in the history
  • Loading branch information
Weina Ji committed Oct 22, 2024
1 parent f84a5d5 commit 8900dc4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
6 changes: 5 additions & 1 deletion neurodamus/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class _SimConfig(object):
reports = None
configures = None
modifications = None
modification_times = []

# Hoc objects used
_config_parser = None
Expand Down Expand Up @@ -272,7 +273,7 @@ def init(cls, config_file, cli_options):
cls.injects = compat.Map(cls._config_parser.parsedInjects)
cls.reports = compat.Map(cls._config_parser.parsedReports)
cls.configures = compat.Map(cls._config_parser.parsedConfigures or {})
cls.modifications = compat.Map(cls._config_parser.parsedModifications or {})
cls.modifications = cls._config_parser.parsedModifications or {}
cls.cli_options = CliOptions(**(cli_options or {}))
cls.dry_run = cls.cli_options.dry_run
cls.crash_test_mode = cls.cli_options.crash_test
Expand Down Expand Up @@ -516,9 +517,12 @@ def _stimulus_params(config: _SimConfig, run_conf):

@SimConfig.validator
def _modification_params(config: _SimConfig, run_conf):
times = set()
required_fields = ("Target", "Type",)
for name, mod_block in config.modifications.items():
_check_params("Modification " + name, compat.Map(mod_block), required_fields, ())
times.add(mod_block["Delay"])
config.modification_times = sorted(times)


def _make_circuit_config(config_dict, req_morphology=True):
Expand Down
64 changes: 37 additions & 27 deletions neurodamus/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def _enable_replay(self, source, target, stim_conf, tshift=.0, delay=.0,
# -
@mpi_no_errors
@timeit(name="Enable Modifications")
def enable_modifications(self):
def enable_modifications(self, time=0.0):
"""Iterate over any Modification blocks read from the config file and apply them to the
network. The steps needed are more complex than NeuronConfigures, so the user should not be
expected to write the hoc directly, but rather access a library of already available mods.
Expand All @@ -798,11 +798,12 @@ def enable_modifications(self):
log_stage("Enabling modifications...")

mod_manager = ModificationManager(self._target_manager)
for name, mod in SimConfig.modifications.items():
mod_info = compat.Map(mod)
target_spec = TargetSpec(mod_info["Target"])
logging.info(" * [MOD] %s: %s -> %s", name, mod_info["Type"], target_spec)
mod_manager.interpret(target_spec, mod_info)
for name, mod in SimConfig.modifications.copy().items():
if mod["Delay"] == time:
target_spec = TargetSpec(mod["Target"])
logging.info(" * [MOD] %s: %s -> %s", name, mod["Type"], target_spec)
mod_manager.interpret(target_spec, mod)
del SimConfig.modifications[name]

# Reporting
ReportParams = namedtuple("ReportParams", "name, rep_type, report_on, unit, format, dt, "
Expand Down Expand Up @@ -868,8 +869,8 @@ def enable_reports(self):
continue

# Custom reporting. TODO: Move `_report_setup` to cellManager.enable_report
target_population = target_spec.population or self._target_spec.population
cell_manager = self._circuits.get_node_manager(target_population)
# target_population = target_spec.population or self._target_spec.population
# cell_manager = self._circuits.get_node_manager(target_population)
# cell_manager.enable_report(report, target, SimConfig.use_coreneuron)

if report:
Expand Down Expand Up @@ -1319,23 +1320,29 @@ def run_all(self):
self.sim_init()

timings = None
for tstop in [15, 20]:
if SimConfig.use_neuron:
timings = self._run_neuron(tstop)
if tstop == 15:
self.enable_modifications()
if tstop == 20:
self.sonata_spikes()
if SimConfig.use_coreneuron:
print_mem_usage()
if not SimConfig.coreneuron_direct_mode:
self.clear_model(avoid_clearing_queues=False)
self._run_coreneuron(tstop)
Nd.t=tstop
if tstop == 15:
self.enable_modifications()
if SimConfig.coreneuron_direct_mode and tstop == 20:
self.sonata_spikes()

for t in SimConfig.modification_times:
if t >= Nd.tstop:
continue
timings = self._run_interval(t)
Nd.t = t
self.enable_modifications(t)

timings = self._run_interval()
if SimConfig.use_neuron or SimConfig.coreneuron_direct_mode:
self.sonata_spikes()

return timings

def _run_interval(self, tstop=None):
timings = None
if SimConfig.use_neuron:
timings = self._run_neuron(tstop)
if SimConfig.use_coreneuron:
print_mem_usage()
if not SimConfig.coreneuron_direct_mode:
self.clear_model(avoid_clearing_queues=False)
self._run_coreneuron(tstop)
return timings

# -
Expand Down Expand Up @@ -1555,7 +1562,8 @@ def cleanup(self):
print_mem_usage()

# Coreneuron runs clear the model before starting
if not SimConfig.use_coreneuron or SimConfig.coreneuron_direct_mode or SimConfig.simulate_model is False:
if not SimConfig.use_coreneuron or SimConfig.coreneuron_direct_mode \
or SimConfig.simulate_model is False:
self.clear_model(avoid_creating_objs=True)

if SimConfig.delete_corenrn_data and not SimConfig.dry_run:
Expand Down Expand Up @@ -1674,7 +1682,9 @@ def init(self):

self.enable_stimulus()
print_mem_usage()
# self.enable_modifications()
if SimConfig.modification_times[0] == 0:
self.enable_modifications(time=0)
SimConfig.modification_times.remove(0)

if self._run_conf["EnableReports"]:
self.enable_reports()
Expand Down

0 comments on commit 8900dc4

Please sign in to comment.