From 2ccc3f4c8af5be645c2de87abf81b022ee008015 Mon Sep 17 00:00:00 2001 From: anilbey Date: Wed, 12 Apr 2023 14:24:31 +0200 Subject: [PATCH] Add more verbosity for thalamus protocols (#86) * set default CLI verbosity to 1, logger.INFO * add extra verbosity with progress bars to thalamus RatSSCxMainProtocol * update unit test: test_get_parser_args * fix unit test: test_get_parser_args * update argparse to store int for verbosity with default=1 --- emodelrunner/parsing_utilities.py | 2 +- emodelrunner/protocols/thalamus_protocols.py | 13 +++++++++++-- emodelrunner/run.py | 4 ---- emodelrunner/run_pairsim.py | 3 --- emodelrunner/run_synplas.py | 3 --- setup.py | 1 + tests/unit_tests/test_parsing_utilities.py | 16 ++++++++-------- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/emodelrunner/parsing_utilities.py b/emodelrunner/parsing_utilities.py index e0a8403..5aa0e5d 100644 --- a/emodelrunner/parsing_utilities.py +++ b/emodelrunner/parsing_utilities.py @@ -30,7 +30,7 @@ def get_parser_args(): default=None, help="the path to the config file.", ) - parser.add_argument("-v", "--verbose", action="count", dest="verbosity", default=0) + parser.add_argument("-v", "--verbose", type=int, dest="verbosity", default=1) return parser.parse_args() diff --git a/emodelrunner/protocols/thalamus_protocols.py b/emodelrunner/protocols/thalamus_protocols.py index c9666ee..59984c3 100644 --- a/emodelrunner/protocols/thalamus_protocols.py +++ b/emodelrunner/protocols/thalamus_protocols.py @@ -20,7 +20,9 @@ import copy import logging import numpy as np + from bluepyopt import ephys +from tqdm import tqdm from emodelrunner.protocols.protocols_func import CurrentOutputKeyMixin @@ -124,12 +126,14 @@ def run(self, cell_model, param_values, sim=None, isolate=None): cell_model.freeze(param_values) # Find resting membrane potential + logger.info("Running RMP protocol") rmp_response = self.rmp_protocol.run(cell_model, {}, sim=sim) responses.update(rmp_response) rmp = self.rmp_efeature.calculate_feature(rmp_response) # Find Rin and holding current if hasattr(self, "rinhold_protocol_dep"): + logger.info("Running Rinhold protocol (depolarizing)") rinhold_response_dep = self.rinhold_protocol_dep.run( cell_model, {}, sim=sim, rmp=rmp ) @@ -138,6 +142,7 @@ def run(self, cell_model, param_values, sim=None, isolate=None): rin_dep = self.rin_efeature_dep.calculate_feature(rinhold_response_dep) responses.update(rinhold_response_dep) + logger.info("Running Rinhold protocol (hyperpolarizing)") rinhold_response_hyp = self.rinhold_protocol_hyp.run( cell_model, {}, sim=sim, rmp=rmp ) @@ -148,6 +153,7 @@ def run(self, cell_model, param_values, sim=None, isolate=None): responses.update(rinhold_response_hyp) if hasattr(self, "thdetect_protocol_dep"): + logger.info("Running threshold detection protocol (depolarizing)") responses.update( self.thdetect_protocol_dep.run( cell_model, @@ -159,6 +165,7 @@ def run(self, cell_model, param_values, sim=None, isolate=None): ) ) + logger.info("Running threshold detection protocol (hyperpolarizing)") responses.update( self.thdetect_protocol_hyp.run( cell_model, @@ -180,13 +187,15 @@ def run(self, cell_model, param_values, sim=None, isolate=None): def _run_pre_protocols(self, cell_model, sim, responses): """Runs the pre_protocols and updates responses dict.""" - for pre_protocol in self.pre_protocols: + logger.info("Running pre-protocols") + for pre_protocol in tqdm(self.pre_protocols): response = pre_protocol.run(cell_model, {}, sim=sim) responses.update(response) def _run_other_protocols(self, cell_model, sim, responses): """Runs the other_protocols and updates responses dict.""" - for other_protocol in self.other_protocols: + logger.info("Running other protocols") + for other_protocol in tqdm(self.other_protocols): response = other_protocol.run(cell_model, {}, sim=sim) responses.update(response) diff --git a/emodelrunner/run.py b/emodelrunner/run.py index 7ae37a6..ae13f58 100644 --- a/emodelrunner/run.py +++ b/emodelrunner/run.py @@ -31,10 +31,6 @@ logger = logging.getLogger(__name__) -# if logger.level is unset, then set it to INFO -if logger.level == logging.NOTSET: - logger.setLevel(logging.INFO) - def main(config_path): """Main. diff --git a/emodelrunner/run_pairsim.py b/emodelrunner/run_pairsim.py index 4a608e7..20f8120 100644 --- a/emodelrunner/run_pairsim.py +++ b/emodelrunner/run_pairsim.py @@ -31,9 +31,6 @@ # Configure logger logger = logging.getLogger(__name__) -# if logger.level is unset, then set it to INFO -if logger.level == logging.NOTSET: - logger.setLevel(logging.INFO) def run( diff --git a/emodelrunner/run_synplas.py b/emodelrunner/run_synplas.py index 4e229f9..e5058d5 100644 --- a/emodelrunner/run_synplas.py +++ b/emodelrunner/run_synplas.py @@ -31,9 +31,6 @@ # Configure logger logger = logging.getLogger(__name__) -# if logger.level is unset, then set it to INFO -if logger.level == logging.NOTSET: - logger.setLevel(logging.INFO) # taken from glusynapse.simulation.simulator diff --git a/setup.py b/setup.py index 76b18f4..7103022 100644 --- a/setup.py +++ b/setup.py @@ -50,6 +50,7 @@ "schema", "Pebble>=4.3.10", "importlib_metadata; python_version<'3.8'", + "tqdm>=4.65.0", ], packages=find_packages(exclude=["tests"]), python_requires=">=3.7", diff --git a/tests/unit_tests/test_parsing_utilities.py b/tests/unit_tests/test_parsing_utilities.py index 6cdc4bb..c8d399d 100644 --- a/tests/unit_tests/test_parsing_utilities.py +++ b/tests/unit_tests/test_parsing_utilities.py @@ -28,25 +28,25 @@ def test_get_parser_args(): args = get_parser_args() assert args.config_path == "mock/config/path" - assert args.verbosity == 0 + assert args.verbosity == 1 # --verbose case - sys.argv = "run.py --config_path mock/config/path --verbose".split() + sys.argv = "run.py --config_path mock/config/path --verbose=0".split() args = get_parser_args() - assert args.verbosity == 1 + assert args.verbosity == 0 # -v case - sys.argv = "run.py --config_path mock/config/path -v".split() + sys.argv = "run.py --config_path mock/config/path -v=2".split() args = get_parser_args() - assert args.verbosity == 1 + assert args.verbosity == 2 - # -vv case - sys.argv = "run.py --config_path mock/config/path -vv".split() + # space separated case + sys.argv = "run.py --config_path mock/config/path --verbose 3".split() args = get_parser_args() - assert args.verbosity == 2 + assert args.verbosity == 3 @patch("logging.basicConfig")