Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to logging #623

Open
wants to merge 17 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions netpyne/analysis/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ def plotData():
out = func(**kwargs) # call function with user arguments

# Print timings
if sim.cfg.timing:
sim.timing('stop', 'plotTime')
logger.timing(' Done; plotting time = %0.2f s' % sim.timingData['plotTime'])

sim.timing('stop', 'totalTime')
sumTime = sum([t for k,t in sim.timingData.items() if k not in ['totalTime']])
if sim.timingData['totalTime'] <= 1.2*sumTime: # Print total time (only if makes sense)
logger.timing('\nTotal time = %0.2f s' % sim.timingData['totalTime'])
sim.timing('stop', 'plotTime')
logger.timing(' Done; plotting time = %0.2f s' % sim.timingData['plotTime'])

sim.timing('stop', 'totalTime')
sumTime = sum([t for k,t in sim.timingData.items() if k not in ['totalTime']])
if sim.timingData['totalTime'] <= 1.2*sumTime: # Print total time (only if makes sense)
logger.timing('\nTotal time = %0.2f s' % sim.timingData['totalTime'])

try:
logger.info('\nEnd time: ', datetime.now())
Expand Down
6 changes: 3 additions & 3 deletions netpyne/sim/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _byteify(data, ignore_dicts = False):
# if it's anything else, return it in its original form
return data

if hasattr(sim, 'cfg') and sim.cfg.timing: sim.timing('start', 'loadFileTime')
if hasattr(sim, 'cfg'): sim.timing('start', 'loadFileTime')
ext = os.path.basename(filename).split('.')[-1]

# load pickle file
Expand Down Expand Up @@ -126,7 +126,7 @@ def _byteify(data, ignore_dicts = False):
logger.warning('Format not recognized for file %s'%(filename))
return

if hasattr(sim, 'rank') and sim.rank == 0 and hasattr(sim, 'cfg') and sim.cfg.timing:
if hasattr(sim, 'rank') and sim.rank == 0 and hasattr(sim, 'cfg'):
sim.timing('stop', 'loadFileTime')
logger.timing(' Done; file loading time = %0.2f s' % sim.timingData['loadFileTime'])

Expand Down Expand Up @@ -339,7 +339,7 @@ def loadNet(filename, data=None, instantiate=True, compactConnFormat=False):
except:
logger.warning('Unable to create NEURON objects...')

if loadNow and sim.cfg.timing: #if sim.rank == 0 and sim.cfg.timing:
if loadNow: #if sim.rank == 0 and sim.cfg.timing:
sim.timing('stop', 'loadNetTime')
logger.timing(' Done; re-instantiate net time = %0.2f s' % sim.timingData['loadNetTime'])
else:
Expand Down
17 changes: 8 additions & 9 deletions netpyne/sim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,17 @@ def timing(mode, processName):
sim.timingData = {}

if hasattr(sim.cfg, 'timing'):
if sim.cfg.timing:
Copy link
Author

@lakesare lakesare Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@salvadord / @joewgraham, from the PR description:

All if sim.cfg.timing: print() are changed to logger.timing().

This change made the code like logger.timing('\nTotal time = %0.2f s' % sim.timingData['totalTime']) fail when we have sim.cfg.timing set to False.

We can either always track time (this is what this commit does, though we'd have to remove hasattr(sim.cfg, 'timing') too and do a couple of other things - I stopped in the middle here to ask for your opinion), or I can revert all timing statements to if sim.cfg.timing: ...log stuff....

However - have we considered using a higher order function, say in this fashion https://stackoverflow.com/a/15136422/3192470?
Then we'd have it all in a single place:

import time

def timeit(f, message):
    def timed(*args, **kw):
        if sim.cfg.timing and sim.rank == 0:
          ts = time.time()
          result = f(*args, **kw)
          te = time.time()

          logger.info(message % (te-ts))
          return result
    return timed

@timeit(message="  Done; cells modification time =")
def modifyCells(self, params, updateMasterAllCells=False):
  ...

(Instead of https://github.com/Neurosim-lab/netpyne/blob/development/netpyne/network/modify.py)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking impressive, but I think we should discuss details at the dev meeting tomorrow. I've added notes to the agenda.

if hasattr(sim, 'rank'):
if sim.rank == 0:
if mode == 'start':
sim.timingData[processName] = time()
elif mode == 'stop':
sim.timingData[processName] = time() - sim.timingData[processName]
else:
if hasattr(sim, 'rank'):
if sim.rank == 0:
if mode == 'start':
sim.timingData[processName] = time()
elif mode == 'stop':
sim.timingData[processName] = time() - sim.timingData[processName]
sim.timingData[processName] = time() - sim.timingData[processName]
else:
if mode == 'start':
sim.timingData[processName] = time()
elif mode == 'stop':
sim.timingData[processName] = time() - sim.timingData[processName]


#------------------------------------------------------------------------------
Expand Down