mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-04 03:02:34 +08:00
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:
@@ -1,5 +1,5 @@
|
||||
import numpy as np
|
||||
from SimPEG.utils import mkvc, sdiag
|
||||
from SimPEG.utils import mkvc, sdiag, count, timeIt
|
||||
import scipy.sparse as sp
|
||||
norm = np.linalg.norm
|
||||
|
||||
@@ -37,6 +37,8 @@ class Problem(object):
|
||||
to (locally) find how model parameters change the data, and optimize!
|
||||
"""
|
||||
|
||||
counter = None
|
||||
|
||||
def __init__(self, mesh):
|
||||
self.mesh = mesh
|
||||
|
||||
@@ -83,6 +85,7 @@ class Problem(object):
|
||||
def dobs(self, value):
|
||||
self._dobs = value
|
||||
|
||||
@count
|
||||
def dpred(self, m, u=None):
|
||||
"""
|
||||
Predicted data.
|
||||
@@ -94,6 +97,7 @@ class Problem(object):
|
||||
u = self.field(m)
|
||||
return self.P*u
|
||||
|
||||
@count
|
||||
def dataResidual(self, m, u=None):
|
||||
"""
|
||||
:param numpy.array m: geophysical model
|
||||
@@ -113,6 +117,7 @@ class Problem(object):
|
||||
|
||||
return self.dpred(m, u=u) - self.dobs
|
||||
|
||||
@timeIt
|
||||
def J(self, m, v, u=None):
|
||||
"""
|
||||
:param numpy.array m: model
|
||||
@@ -142,6 +147,7 @@ class Problem(object):
|
||||
"""
|
||||
raise NotImplementedError('J is not yet implemented.')
|
||||
|
||||
@timeIt
|
||||
def Jt(self, m, v, u=None):
|
||||
"""
|
||||
:param numpy.array m: model
|
||||
@@ -155,6 +161,7 @@ class Problem(object):
|
||||
raise NotImplementedError('Jt is not yet implemented.')
|
||||
|
||||
|
||||
@timeIt
|
||||
def J_approx(self, m, v, u=None):
|
||||
"""
|
||||
|
||||
@@ -169,6 +176,7 @@ class Problem(object):
|
||||
"""
|
||||
return self.J(m, v, u)
|
||||
|
||||
@timeIt
|
||||
def Jt_approx(self, m, v, u=None):
|
||||
"""
|
||||
:param numpy.array m: model
|
||||
|
||||
Reference in New Issue
Block a user