Skip to content

Commit

Permalink
Add a temporary progress indicator to have some feedback for long-run…
Browse files Browse the repository at this point in the history
…ning simulations
  • Loading branch information
Marcel Stimberg committed Jul 10, 2013
1 parent 3f7a50e commit 7f75ec0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions brian2/core/network.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import weakref
import time

from brian2.utils.logger import get_logger
from brian2.core.names import Nameable
Expand Down Expand Up @@ -344,9 +345,18 @@ def run(self, duration, report=None, report_period=60*second,

# Find the first clock to be updated (see note below)
clock, curclocks = self._nextclocks()
start = time.time()
next_report_time = start + 10
while clock.running and not self._stopped and not Network._globally_stopped:
# update the network time to this clocks time
self.t_ = clock.t_
current = time.time()
if current > next_report_time:
report = '{t} simulated ({percent}%), estimated {remaining} s remaining.'
remaining = int(round((current - start)/self.t*(duration-self.t)))
print report.format(t=self.t, percent=int(round(100*self.t/duration)),
remaining=remaining)
next_report_time = current + 10
# update the objects with this clock
for obj in self.objects:
if obj.clock in curclocks and obj.active:
Expand Down

0 comments on commit 7f75ec0

Please sign in to comment.