Skip to content

Commit

Permalink
[BBPBGLIB-1134] Move ShowProgress.hoc to python (#131)
Browse files Browse the repository at this point in the history
## Context
Addresses BBPBGLIB-1134.
Neuron simulation progress hoc file was moved to python.

## Review
* [x] PR description is complete
* [x] Coding style (imports, function length, New functions, classes or
files) are good
* [ ] Unit/Scientific test added
* [ ] Updated Readme, in-code, developer documentation
  • Loading branch information
jorblancoa authored Feb 29, 2024
1 parent e46d7c2 commit 84f4049
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 54 deletions.
50 changes: 0 additions & 50 deletions core/hoc/ShowProgress.hoc

This file was deleted.

31 changes: 30 additions & 1 deletion neurodamus/core/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from __future__ import absolute_import
import time
from array import array
from datetime import timedelta
from functools import wraps
from inspect import Signature, signature
from ._mpi import MPI
from ..utils import progressbar
from . import NeurodamusCore as Nd


class ProgressBarRank0(progressbar.Progress):
Expand Down Expand Up @@ -67,8 +69,35 @@ def rank0_wrapper(*args, **kw):
return rank0_wrapper


class SimulationProgress:
def __init__(self):
"""
Class which will set up a timer to perioducally check the amount of time lapsed
in the simulation compared to the final tstop value. This is converted into a percentage
of the job complete which is then printed to the console.
"""
self.last_time_check = time.time()
self.sim_start = self.last_time_check
self.update_progress()

def update_progress(self):
"""
Callback function that refreshes the progress value (if enough time has elapsed) and then
inserts the next call into the event queue.
"""
current_time = time.time()
sim_t = Nd.t
sim_tstop = Nd.tstop
if (current_time - self.last_time_check > 0.75) and (sim_t > 0):
self.last_time_check = current_time
sec_remain = (self.last_time_check - self.sim_start) * (sim_tstop / sim_t - 1)
print(f"\r[t={sim_t:5.2f}] Completed {sim_t*100/sim_tstop:2.0f}%"
f" ETA: {timedelta(seconds=int(sec_remain))} ", end='', flush=True)
Nd.cvode.event(sim_t + 1, self.update_progress)


def return_neuron_timings(f):
"""Decorator to collect and return timings on a neuron run
"""Decorator to collect, return timings and show the progress on a neuron run
"""
@wraps(f)
def timings_wrapper(*args, **kw):
Expand Down
6 changes: 3 additions & 3 deletions neurodamus/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from collections import namedtuple, defaultdict
from contextlib import contextmanager

from .core import MPI, mpi_no_errors, return_neuron_timings, run_only_rank0
from .core import MPI, mpi_no_errors, return_neuron_timings, run_only_rank0, SimulationProgress
from .core import NeurodamusCore as Nd
from .core.configuration import CircuitConfig, Feature, GlobalConfig, SimConfig
from .core._engine import EngineBase
Expand Down Expand Up @@ -1301,8 +1301,8 @@ def run_all(self):
# -
@return_neuron_timings
def _run_neuron(self):
Nd.load_hoc("ShowProgress") # TODO: Drop this
_ = Nd.ShowProgress(Nd.cvode, MPI.rank)
if MPI.rank == 0:
_ = SimulationProgress()
self.solve()
logging.info("Simulation finished.")

Expand Down

0 comments on commit 84f4049

Please sign in to comment.