Skip to content

Commit

Permalink
Merge pull request #246 from NeuroML/experimental
Browse files Browse the repository at this point in the history
 allow netpyne runner to also return command output
  • Loading branch information
pgleeson authored Aug 9, 2023
2 parents ee2e091 + 6736406 commit c7a7f39
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions pyneuroml/pynml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,8 +1461,9 @@ def run_lems_with_jneuroml_netpyne(
only_generate_json: bool = False,
verbose: bool = DEFAULTS["v"],
exit_on_fail: bool = True,
return_string: bool = False,
cleanup: bool = False,
) -> typing.Union[bool, typing.Union[dict, tuple[dict, dict]]]:
) -> typing.Union[bool, tuple[bool, str], typing.Union[dict, tuple[dict, dict]]]:
"""Run LEMS file with the NEURON simulator
Tip: set `skip_run=True` to only parse the LEMS file but not run the simulation.
Expand Down Expand Up @@ -1495,8 +1496,15 @@ def run_lems_with_jneuroml_netpyne(
:type verbose: bool
:param exit_on_fail: toggle whether command should exit if jnml fails
:type exit_on_fail: bool
:param return_string: toggle whether command output string should be returned
:type return_string: bool
:param cleanup: toggle whether the directory should be cleaned of generated files after run completion
:type cleanup: bool
:returns: either a bool, or a Tuple (bool, str) depending on the value of
return_string: True of jnml ran successfully, False if not; along with the
output of the command. If load_saved_data is True, it returns a dict
with the data
"""

logger.info(
Expand All @@ -1519,17 +1527,32 @@ def run_lems_with_jneuroml_netpyne(
if skip_run:
success = True
else:
success = run_jneuroml(
"",
lems_file_name,
post_args,
max_memory=max_memory,
exec_in_dir=exec_in_dir,
verbose=verbose,
exit_on_fail=exit_on_fail,
)
if return_string is True:
(success, output_string) = run_jneuroml(
"",
lems_file_name,
post_args,
max_memory=max_memory,
exec_in_dir=exec_in_dir,
verbose=verbose,
exit_on_fail=exit_on_fail,
return_string=True
)
else:
success = run_jneuroml(
"",
lems_file_name,
post_args,
max_memory=max_memory,
exec_in_dir=exec_in_dir,
verbose=verbose,
exit_on_fail=exit_on_fail,
return_string=False
)

if not success:
if not success and return_string is True:
return False, output_string
if not success and return_string is False:
return False

if load_saved_data:
Expand All @@ -1543,8 +1566,11 @@ def run_lems_with_jneuroml_netpyne(
reload_events=reload_events,
remove_dat_files_after_load=cleanup,
)
else:
return True

if return_string is True:
return True, output_string

return True


# TODO: need to enable run with Brian2!
Expand Down Expand Up @@ -2272,7 +2298,9 @@ def run_jneuroml(
:param return_string: toggle whether the output string should be returned
:type return_string: bool
:returns: either a bool, or a Tuple (bool, str) depending on the value of return_string: True of jnml ran successfully, False if not; along with the output of the command
:returns: either a bool, or a Tuple (bool, str) depending on the value of
return_string: True of jnml ran successfully, False if not; along with the
output of the command
"""
logger.debug(
Expand Down

0 comments on commit c7a7f39

Please sign in to comment.