Skip to content

Commit

Permalink
Change CLI option name to --coreneuron-direct-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Weina Ji committed Mar 22, 2024
1 parent 153c8e5 commit 38dfd85
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 43 deletions.
3 changes: 2 additions & 1 deletion neurodamus/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def neurodamus(args=None):
--model-stats Show model stats in CoreNEURON simulations [default: False]
--dry-run Dry-run simulation to estimate memory usage [default: False]
--num-target-ranks=<number> Number of ranks to target for dry-run load balancing
--skip-write-model Run CoreNeuron in direct mode, without writing model data to disk
--coreneuron-direct-mode Run CoreNeuron in direct memory mode transfered from Neuron,
without writing model data to disk.
"""
options = docopt_sanitize(docopt(neurodamus.__doc__, args))
config_file = options.pop("ConfigFile")
Expand Down
25 changes: 7 additions & 18 deletions neurodamus/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ class CliOptions(ConfigT):
model_stats = False
simulator = None
dry_run = False
<<<<<<< HEAD
num_target_ranks = None
=======
skip_write_model = False
>>>>>>> a8a10a6... Cli option
coreneuron_direct_mode = False

# Restricted Functionality support, mostly for testing

Expand Down Expand Up @@ -240,11 +237,8 @@ class _SimConfig(object):
spike_location = "soma"
spike_threshold = -30
dry_run = False
<<<<<<< HEAD
num_target_ranks = None
=======
skip_write_model = False
>>>>>>> a8a10a6... Cli option
coreneuron_direct_mode = False

_validators = []
_requisitors = []
Expand Down Expand Up @@ -280,11 +274,8 @@ def init(cls, config_file, cli_options):
cls.modifications = compat.Map(cls._config_parser.parsedModifications or {})
cls.cli_options = CliOptions(**(cli_options or {}))
cls.dry_run = cls.cli_options.dry_run
<<<<<<< HEAD
cls.num_target_ranks = cls.cli_options.num_target_ranks
=======
cls.skip_write_model = cls.cli_options.skip_write_model
>>>>>>> a8a10a6... Cli option
cls.coreneuron_direct_mode = cls.cli_options.coreneuron_direct_mode
# change simulator by request before validator and init hoc config
if cls.cli_options.simulator:
cls._parsed_run["Simulator"] = cls.cli_options.simulator
Expand Down Expand Up @@ -1020,15 +1011,13 @@ def _spikes_sort_order(config: _SimConfig, run_conf):


@SimConfig.validator
def _skip_write_coreneuron_model(config: _SimConfig, run_conf):
if config.skip_write_model:
def _coreneuron_direct_mode(config: _SimConfig, run_conf):
if config.coreneuron_direct_mode:
if config.use_coreneuron:
logging.info("Run CORENEURON without writing model data to disk")
# config.use_neuron = True
# config.use_coreneuron = False
else:
logging.warning("--skip-write-model not valid for NEURON, continue as usual")
config.skip_write_model = False
logging.warning("--coreneuron-direct-mode not valid for NEURON, continue with NEURON")
config.coreneuron_direct_mode = False


def get_debug_cell_gid(cli_options):
Expand Down
25 changes: 10 additions & 15 deletions neurodamus/core/coreneuron_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pathlib import Path
from ._utils import run_only_rank0
from . import NeurodamusCore as Nd
from ..utils.logging import log_verbose


class CompartmentMapping:
Expand Down Expand Up @@ -207,25 +206,21 @@ def write_spike_filename(self, filename):
fp.write(filename)
fp.write("\n")

def psolve_core(self, save_path=None, restore_path=None, skip_write_model=False):
def psolve_core(self, save_path=None, restore_path=None, coreneuron_direct_mode=False):
from neuron import coreneuron
from . import NeurodamusCore as Nd

Nd.cvode.cache_efficient(1)
coreneuron.enable = True
if not skip_write_model:
coreneuron.file_mode = True
coreneuron.sim_config = f"{self.output_root}/{self.sim_config_file}"
if save_path:
coreneuron.save_path = save_path
if restore_path:
coreneuron.restore_path = restore_path
# Model is already written to disk by calling pc.nrncore_write()
coreneuron.skip_write_model_to_disk = True
coreneuron.model_path = f"{self.datadir}"
else:
log_verbose("Run CORENEURON direct mode")
coreneuron.sim_config = f"{self.output_root}/{self.sim_config_file}"
coreneuron.file_mode = not coreneuron_direct_mode
coreneuron.sim_config = f"{self.output_root}/{self.sim_config_file}"
if save_path:
coreneuron.save_path = save_path
if restore_path:
coreneuron.restore_path = restore_path
# Model is already written to disk by calling pc.nrncore_write()
coreneuron.skip_write_model_to_disk = True
coreneuron.model_path = f"{self.datadir}"
Nd.pc.psolve(Nd.tstop)


Expand Down
16 changes: 8 additions & 8 deletions neurodamus/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def __init__(self, config_file, options=None):
self._run_conf = SimConfig.run_conf
self._target_manager = TargetManager(self._run_conf)
self._target_spec = TargetSpec(self._run_conf.get("CircuitTarget"))
if SimConfig.use_neuron or SimConfig.skip_write_model:
if SimConfig.use_neuron or SimConfig.coreneuron_direct_mode:
self._sonatareport_helper = Nd.SonataReportHelper(Nd.dt, True)
self._base_circuit: CircuitConfig = SimConfig.base_circuit
self._extra_circuits = SimConfig.extra_circuits
Expand Down Expand Up @@ -772,7 +772,7 @@ def _enable_replay(self, source, target, stim_conf, tshift=.0, delay=.0,

logging.info("=> Population pathway %s -> %s. Source offset: %d",
src_pop_str, dst_pop_str, src_pop_offset)
if SimConfig.use_coreneuron and not SimConfig.skip_write_model:
if SimConfig.use_coreneuron and not SimConfig.coreneuron_direct_mode:
self._coreneuron_replay_append(spike_manager, src_pop_offset)
else:
conn_manager.replay(spike_manager, source, target, delay)
Expand Down Expand Up @@ -1092,7 +1092,7 @@ def sim_init(self, corenrn_gen=None, **sim_opts):
if corenrn_gen:
self._sim_corenrn_write_config()

if SimConfig.use_neuron or SimConfig.skip_write_model:
if SimConfig.use_neuron or SimConfig.coreneuron_direct_mode:
self._sim_init_neuron()

if ospath.isfile("debug_gids.txt"):
Expand Down Expand Up @@ -1276,11 +1276,11 @@ def _sim_corenrn_write_config(self, corenrn_restore=False):

if not corenrn_restore:
CompartmentMapping(self._circuits.global_manager).register_mapping()
if not SimConfig.skip_write_model:
if not SimConfig.coreneuron_direct_mode:
with self._coreneuron_ensure_all_ranks_have_gids(CoreConfig.datadir):
self._pc.nrnbbcore_write(CoreConfig.datadir)
MPI.barrier() # wait for all ranks to finish corenrn data generation

CoreConfig.write_sim_config(
Nd.tstop,
Nd.dt,
Expand Down Expand Up @@ -1311,10 +1311,10 @@ def run_all(self):
self.sonata_spikes()
if SimConfig.use_coreneuron:
print_mem_usage()
if not SimConfig.skip_write_model:
if not SimConfig.coreneuron_direct_mode:
self.clear_model(avoid_clearing_queues=False)
self._run_coreneuron()
if SimConfig.skip_write_model:
if SimConfig.coreneuron_direct_mode:
self.sonata_spikes()
return timings

Expand All @@ -1332,7 +1332,7 @@ def _run_coreneuron(self):
CoreConfig.psolve_core(
getattr(SimConfig, "save", None),
getattr(SimConfig, "restore", None),
SimConfig.skip_write_model
SimConfig.coreneuron_direct_mode
)

#
Expand Down
2 changes: 1 addition & 1 deletion tests/integration-e2e/test_coreneuron_directmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_coreneuron_no_write_model(USECASE3):
nd = Neurodamus(
str(USECASE3 / "simulation_sonata_coreneuron.json"),
keep_build=True,
skip_write_model=True
coreneuron_direct_mode=True
)
nd.run()
coreneuron_data = SimConfig.coreneuron_datadir
Expand Down

0 comments on commit 38dfd85

Please sign in to comment.