Simple profiling through decorator functions. (counting and timing of functions decorated with @count and @timeIt that have a SimPEG.utils.Counter)

e.g. output:
‘’’
Counters:
  InexactGaussNewton.doEndIteration       :        6
  InexactGaussNewton.printIter            :        7
  InexactGaussNewton.scaleSearchDirection :        6

Times:                                        mean      sum
  InexactGaussNewton.findSearchDirection  : 1.55e-02, 9.29e-02,    6x
  InexactGaussNewton.minimize             : 1.10e-01, 1.10e-01,    1x
  InexactGaussNewton.modifySearchDirection: 2.89e-04, 1.73e-03,    6x
  InexactGaussNewton.projection           : 3.69e-06, 1.11e-04,   30x
  InexactGaussNewton.stoppingCriteria     : 1.16e-04, 1.51e-03,   13x
  Inversion.dataObj                       : 6.60e-05, 8.58e-04,   13x
  Inversion.dataObj2Deriv                 : 1.03e-04, 6.20e-03,   60x
  Inversion.dataObjDeriv                  : 5.06e-05, 3.54e-04,    7x
  Inversion.evalFunction                  : 7.75e-04, 1.01e-02,   13x
  Inversion.run                           : 1.10e-01, 1.10e-01,    1x
  Regularization.modelObj                 : 3.56e-04, 4.63e-03,   13x
  Regularization.modelObj2Deriv           : 1.29e-03, 7.76e-02,   60x
  Regularization.modelObjDeriv            : 5.01e-04, 3.51e-03,    7x
‘’’
This commit is contained in:
Rowan Cockett
2013-11-20 21:59:53 -08:00
parent 514b709270
commit 2782a6fcfb
5 changed files with 160 additions and 15 deletions
+8 -3
View File
@@ -1,7 +1,7 @@
import numpy as np
import scipy.sparse as sp
import SimPEG
from SimPEG.utils import sdiag, mkvc, setKwargs, checkStoppers, printStoppers
from SimPEG.utils import sdiag, mkvc, setKwargs, checkStoppers, printStoppers, count, timeIt
from Optimize import Remember
from BetaSchedule import Cooling
@@ -13,6 +13,8 @@ class BaseInversion(object):
debug = False
beta0 = 1e4
counter = None
def __init__(self, prob, reg, opt, **kwargs):
setKwargs(self, **kwargs)
self.prob = prob
@@ -56,6 +58,7 @@ class BaseInversion(object):
def phi_d_target(self, value):
self._phi_d_target = value
@timeIt
def run(self, m0):
self.startup(m0)
while True:
@@ -131,7 +134,7 @@ class BaseInversion(object):
"""
printStoppers(self, self.stoppers)
@timeIt
def evalFunction(self, m, return_g=True, return_H=True):
u = self.prob.field(m)
@@ -162,7 +165,7 @@ class BaseInversion(object):
out += (operator,)
return out if len(out) > 1 else out[0]
@timeIt
def dataObj(self, m, u=None):
"""
:param numpy.array m: geophysical model
@@ -184,6 +187,7 @@ class BaseInversion(object):
R = mkvc(R)
return 0.5*np.vdot(R, R)
@timeIt
def dataObjDeriv(self, m, u=None):
"""
:param numpy.array m: geophysical model
@@ -224,6 +228,7 @@ class BaseInversion(object):
return dmisfit
@timeIt
def dataObj2Deriv(self, m, v, u=None):
"""
:param numpy.array m: geophysical model