-
Notifications
You must be signed in to change notification settings - Fork 136
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
base: development
Are you sure you want to change the base?
Switch to logging #623
Conversation
This line was NOT needed until I updated my environment (I installed the packages I'm developing locally & installed+deleted a few packages - interesting that it affected the root logger!).
if sim.rank == 0 should be handled too - if our rank is not 0, we'll get an error when we try to sim.timingData['totalTime'], and I don't think we always checked it (?)
netpyne/sim/utils.py
Outdated
@@ -140,18 +140,17 @@ def timing(mode, processName): | |||
sim.timingData = {} | |||
|
|||
if hasattr(sim.cfg, 'timing'): | |||
if sim.cfg.timing: |
There was a problem hiding this comment.
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 tologger.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)
There was a problem hiding this comment.
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.
Hi @joewgraham! |
Hey @lakesare , that's awesome you'd like to wrap this up! Yeah, let's not worry about the timing right now and just get the basic functionality working. Whenever you're ready, I'm glad to give it a thorough review. |
@joewgraham, I reviewed it myself & fixed the remaining issues, it looks good to merge 👍 |
consider also an ability to use only the root MPI node for some of logs |
Fixes #619
To whomever will be reviewing this PR (Joe?) - please go through it line by line, these are the kind of changes where we need some fresh eyes.
What this PR will do
The default logging level (user doesn't set anything):
Users sets
logging.getLogger('netpyne').setLevel(logging.DEBUG)
:Users sets
logging.getLogger('netpyne').setLevel(logging.WARNING)
:Changes
print()
statements are changed tologger.info()
.print("Warning: hi")
,print("WARNING: hi")
andprint("NOTE: hi")
. All of these arelogger.warning("hi")
(without the "Warning/Note/etc." text) now.if sim.cfg.verbose: print()
are changed tologger.debug()
. Thecfg.verbose
option is removed.if sim.cfg.timing: print()
are changed tologger.timing()
.print(())
[must have appeared when netpyne was moving from python2 to python3].from __future__ import print_function
, we don't need these as we don't useprint
statements anymore.Notes
print("Error: ...")
. All of these arelogger.warning("Error: ...")
now - I didn't want to change the way netpyne handles errors.You can ctrl+f
logger.warning
s, and change some of those tologger.exception
so that the stack trace is logged (or you could throw an actual error!).logger.info(' ...')
can be changed tologger.infoS('...')
(where S stands for 2 spaces). Search foroffset = ' ' * 4
for previous attempts at space standardisation.sim.rank == 0
andsim.rank==0
if sim.rank == 0: logger.timing(' Done; cell stims creation time = %0.2f s.' % sim.timingData['stimsTime'])
. Would it make sense to check whether the rank is 0 indef timing()
?sim.rank == 0
? Does it maybe check whether we run a number of simulations concurrently? Would it make sense to simply setlogging.getLogger('netpyne').setLevel(logging.WARNING)
if we run a lot of simulations at a time, and remove allif sim.rank==0: logger.info('Adding stims...')
conditionals?print
statement - we could use the logger in tests too (say changeif self.verboseFlag: print(" *** Finish loading tests *** "
) tologger.info(" *** Finish loading tests *** ")
).Running simulation for 500.0 ms...
example:We can either change all
logger.info('\nHi')
tologger.info(''); logger.info('Hi')
, or remove the newlines completely. It looks good to me without the newlines, but you should know better - will the debugging be any harder without the newlines?