Commit 12712d95 authored by theos's avatar theos

Made use of keepers.logging compatible with inheritance.

parent 197af1ee
......@@ -26,7 +26,9 @@ mpl.use('Agg')
from .version import __version__
from logger import logger
# initialize the logger instance
from keepers import MPILogger
logger = MPILogger()
import dummys
......
......@@ -14,11 +14,10 @@ from nifty.spaces.power_space import PowerSpace
import nifty.nifty_utilities as utilities
from nifty.random import Random
import logging
logger = logging.getLogger('NIFTy.Field')
from keepers import Loggable
class Field(object):
class Field(object, Loggable):
# ---Initialization methods---
def __init__(self, domain=None, val=None, dtype=None, field_type=None,
......@@ -116,7 +115,7 @@ class Field(object):
elif isinstance(val, Field):
distribution_strategy = val.distribution_strategy
else:
logger.info("Datamodel set to default!")
self.logger.info("Datamodel set to default!")
distribution_strategy = gc['default_distribution_strategy']
elif distribution_strategy not in DISTRIBUTION_STRATEGIES['global']:
raise ValueError(
......@@ -387,7 +386,7 @@ class Field(object):
result_list[0].domain_axes[power_space_index])
if pindex.distribution_strategy is not local_distribution_strategy:
logger.warn(
self.logger.warn(
"The distribution_stragey of pindex does not fit the "
"slice_local distribution strategy of the synthesized field.")
......
# -*- coding: utf-8 -*-
from keepers import MPILogger
logger = MPILogger()
# -*- coding: utf-8 -*-
from line_searching import *
from conjugate_gradient import ConjugateGradient
from quasi_newton_minimizer import QuasiNewtonMinimizer
from steepest_descent import SteepestDescent
......@@ -4,9 +4,6 @@
from __future__ import division
import numpy as np
import logging
logger = logging.getLogger('NIFTy.CG')
class ConjugateGradient(object):
def __init__(self, convergence_tolerance=1E-4, convergence_level=3,
......@@ -82,16 +79,16 @@ class ConjugateGradient(object):
d = self.preconditioner(r)
previous_gamma = r.dot(d)
if previous_gamma == 0:
logger.info("The starting guess is already perfect solution for "
"the inverse problem.")
self.logger.info("The starting guess is already perfect solution "
"for the inverse problem.")
return x0, self.convergence_level+1
norm_b = np.sqrt(b.dot(b))
x = x0
convergence = 0
iteration_number = 1
logger.info("Starting conjugate gradient.")
self.logger.info("Starting conjugate gradient.")
while(True):
while True:
if self.callback is not None:
self.callback(x, iteration_number)
......@@ -99,19 +96,19 @@ class ConjugateGradient(object):
alpha = previous_gamma/d.dot(q)
if not np.isfinite(alpha):
logger.error("Alpha became infinite! Stopping.")
self.logger.error("Alpha became infinite! Stopping.")
return x0, 0
x += d * alpha
reset = False
if alpha.real < 0:
logger.warn("Positive definiteness of A violated!")
self.logger.warn("Positive definiteness of A violated!")
reset = True
if self.reset_count is not None:
reset += (iteration_number % self.reset_count == 0)
if reset:
logger.info("Resetting conjugate directions.")
self.logger.info("Resetting conjugate directions.")
r = b - A(x)
else:
r -= q * alpha
......@@ -120,35 +117,37 @@ class ConjugateGradient(object):
gamma = r.dot(s)
if gamma.real < 0:
logger.warn("Positive definitness of preconditioner violated!")
self.logger.warn("Positive definitness of preconditioner "
"violated!")
beta = max(0, gamma/previous_gamma)
delta = np.sqrt(gamma)/norm_b
logger.debug("Iteration : %08u alpha = %3.1E beta = %3.1E "
"delta = %3.1E" %
(iteration_number,
np.real(alpha),
np.real(beta),
np.real(delta)))
self.logger.debug("Iteration : %08u alpha = %3.1E "
"beta = %3.1E delta = %3.1E" %
(iteration_number,
np.real(alpha),
np.real(beta),
np.real(delta)))
if gamma == 0:
convergence = self.convergence_level+1
logger.info("Reached infinite convergence.")
self.logger.info("Reached infinite convergence.")
break
elif abs(delta) < self.convergence_tolerance:
convergence += 1
logger.info("Updated convergence level to: %u" % convergence)
self.logger.info("Updated convergence level to: %u" %
convergence)
if convergence == self.convergence_level:
logger.info("Reached target convergence level.")
self.logger.info("Reached target convergence level.")
break
else:
convergence = max(0, convergence-1)
if self.iteration_limit is not None:
if iteration_number == self.iteration_limit:
logger.warn("Reached iteration limit. Stopping.")
self.logger.warn("Reached iteration limit. Stopping.")
break
d = s + d * beta
......
......@@ -9,9 +9,6 @@ from nifty.config import nifty_configuration as gc
from nifty.field import Field
from nifty.operators.endomorphic_operator import EndomorphicOperator
import logging
logger = logging.getLogger('NIFTy.DiagonalOperator')
class DiagonalOperator(EndomorphicOperator):
......@@ -119,7 +116,7 @@ class DiagonalOperator(EndomorphicOperator):
elif isinstance(val, Field):
distribution_strategy = val.distribution_strategy
else:
logger.info("Datamodel set to default!")
self.logger.info("Datamodel set to default!")
distribution_strategy = gc['default_distribution_strategy']
elif distribution_strategy not in DISTRIBUTION_STRATEGIES['all']:
raise ValueError(
......
......@@ -5,9 +5,6 @@ from nifty import GLSpace, LMSpace
from slicing_transformation import SlicingTransformation
import lm_transformation_factory as ltf
import logging
logger = logging.getLogger('NIFTy.GLLMTransformation')
libsharp = gdi.get('libsharp_wrapper_gl')
......@@ -121,8 +118,8 @@ class GLLMTransformation(SlicingTransformation):
elif inp.dtype == np.dtype('float64'):
return libsharp.map2alm(inp, **kwargs)
else:
logger.debug("performing dtype conversion for libsharp "
"compatibility.")
self.logger.debug("performing dtype conversion for libsharp "
"compatibility.")
casted_inp = inp.astype(np.dtype('float64'), copy=False)
result = libsharp.map2alm(casted_inp, **kwargs)
return result
......@@ -5,9 +5,6 @@ from nifty import GLSpace, LMSpace
from slicing_transformation import SlicingTransformation
import lm_transformation_factory as ltf
import logging
logger = logging.getLogger('NIFTy.LMGLTransformation')
libsharp = gdi.get('libsharp_wrapper_gl')
......@@ -128,8 +125,8 @@ class LMGLTransformation(SlicingTransformation):
elif inp.dtype == np.dtype('complex128'):
return libsharp.alm2map(inp, **kwargs)
else:
logger.debug("performing dtype conversion for libsharp "
"compatibility.")
self.logger.debug("Performing dtype conversion for libsharp "
"compatibility.")
casted_inp = inp.astype(np.dtype('complex128'), copy=False)
result = libsharp.alm2map(casted_inp, **kwargs)
return result
......@@ -5,13 +5,12 @@ from d2o import distributed_data_object, STRATEGIES
from nifty.config import dependency_injector as gdi
import nifty.nifty_utilities as utilities
import logging
logger = logging.getLogger('NIFTy.RGTransforms')
from keepers import Loggable
pyfftw = gdi.get('pyfftw')
class Transform(object):
class Transform(object, Loggable):
"""
A generic fft object without any implementation.
"""
......@@ -297,7 +296,7 @@ class FFTW(Transform):
def _repack_to_fftw_and_transform(self, val, axes, **kwargs):
temp_val = val.copy_empty(distribution_strategy='fftw')
logger.info("Repacking d2o to fftw distribution strategy")
self.logger.info("Repacking d2o to fftw distribution strategy")
temp_val.set_full_data(val, copy=False)
# Recursive call to transform
......
......@@ -4,9 +4,6 @@ from rg_transforms import FFTW, GFFT
from nifty.config import dependency_injector as gdi
from nifty import RGSpace, nifty_configuration
import logging
logger = logging.getLogger('NIFTy.RGRGTransformation')
class RGRGTransformation(Transformation):
def __init__(self, domain, codomain=None, module=None):
......@@ -84,8 +81,8 @@ class RGRGTransformation(Transformation):
cls.check_codomain(domain, new_space)
return new_space
@staticmethod
def check_codomain(domain, codomain):
@classmethod
def check_codomain(cls, domain, codomain):
if not isinstance(domain, RGSpace):
raise TypeError('ERROR: domain is not a RGSpace')
......@@ -104,7 +101,7 @@ class RGRGTransformation(Transformation):
if codomain.harmonic and not issubclass(codomain.dtype.type,
np.complexfloating):
logger.warn("codomain is harmonic but dtype is real.")
cls.logger.warn("Codomain is harmonic but dtype is real.")
# Check if the distances match, i.e. dist' = 1 / (num * dist)
if not np.all(
......
import abc
from keepers import Loggable
class Transformation(object):
class Transformation(object, Loggable):
"""
A generic transformation which defines a static check_codomain
method for all transforms.
......
......@@ -2,13 +2,14 @@
import abc
from keepers import Loggable
from nifty.field import Field
from nifty.spaces import Space
from nifty.field_types import FieldType
import nifty.nifty_utilities as utilities
class LinearOperator(object):
class LinearOperator(object, Loggable):
__metaclass__ = abc.ABCMeta
def __init__(self):
......
......@@ -6,9 +6,6 @@ from nifty.field import Field
from nifty.operators import EndomorphicOperator,\
FFTOperator
import logging
logger = logging.getLogger('NIFTy.PropagatorOperator')
class PropagatorOperator(EndomorphicOperator):
......
......@@ -10,9 +10,6 @@ from nifty.config import nifty_configuration as gc,\
dependency_injector as gdi
import nifty.nifty_utilities as utilities
import logging
logger = logging.getLogger('NIFTy.GLSpace')
gl = gdi.get('libsharp_wrapper_gl')
GL_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
......@@ -207,6 +204,6 @@ class GLSpace(Space):
else:
nlon = int(nlon)
if nlon != 2 * self.nlat - 1:
logger.warn("nlon was set to an unrecommended value: "
"nlon <> 2*nlat-1.")
self.logger.warn("nlon was set to an unrecommended value: "
"nlon <> 2*nlat-1.")
return nlon
......@@ -11,9 +11,6 @@ from lm_helper import _distance_array_helper
from d2o import arange
import logging
logger = logging.getLogger('NIFTy.LMSpace')
gl = gdi.get('libsharp_wrapper_gl')
hp = gdi.get('healpy')
......@@ -178,9 +175,8 @@ class LMSpace(Space):
def _parse_lmax(self, lmax):
lmax = np.int(lmax)
if lmax < 1:
raise ValueError(
"negative lmax is not allowed.")
raise ValueError("Negative lmax is not allowed.")
# exception lmax == 2 (nside == 1)
if (lmax % 2 == 0) and (lmax > 2):
logger.warn("unrecommended parameter (lmax <> 2*n+1).")
self.logger.warn("Unrecommended parameter (lmax <> 2*n+1).")
return lmax
......@@ -146,8 +146,10 @@ import abc
import numpy as np
from keepers import Loggable
class Space(object):
class Space(object, Loggable):
"""
.. __ __
.. /__/ / /_
......
......@@ -44,9 +44,9 @@ setup(name="ift_nifty",
]),
include_dirs=[numpy.get_include()],
dependency_links=[
'git+https://gitlab.mpcdf.mpg.de/ift/keepers.git#egg=keepers-0.3.0',
'git+https://gitlab.mpcdf.mpg.de/ift/keepers.git#egg=keepers-0.3.2',
'git+https://gitlab.mpcdf.mpg.de/ift/d2o.git#egg=d2o-1.0.4'],
install_requires=['keepers>=0.3.0', 'd2o>=1.0.4'],
install_requires=['keepers>=0.3.2', 'd2o>=1.0.4'],
package_data={'nifty.demos': ['demo_faraday_map.npy'],
},
license="GPLv3",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment