Commit a79fd6a2 authored by Philipp Arras's avatar Philipp Arras
Browse files

Add docstrings

parent 387298b6
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik. # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import functools import functools
from time import time
import numpy as np import numpy as np
...@@ -39,6 +40,10 @@ class IterationController(metaclass=NiftyMeta): ...@@ -39,6 +40,10 @@ class IterationController(metaclass=NiftyMeta):
class; the implementer has full flexibility to use whichever criteria are class; the implementer has full flexibility to use whichever criteria are
appropriate for a particular problem - as long as they can be computed from appropriate for a particular problem - as long as they can be computed from
the information passed to the controller during the iteration process. the information passed to the controller during the iteration process.
For analyzing minimization procedures IterationControllers can log energy
values together with the respective time stamps. In order to activate this
feature `activate_and_reset_logging()` needs to be called.
""" """
CONVERGED, CONTINUE, ERROR = list(range(3)) CONVERGED, CONTINUE, ERROR = list(range(3))
...@@ -75,7 +80,13 @@ class IterationController(metaclass=NiftyMeta): ...@@ -75,7 +80,13 @@ class IterationController(metaclass=NiftyMeta):
raise NotImplementedError raise NotImplementedError
def pop_history(self): def pop_history(self):
"""FIXME""" """Returns the collected history of energy values and resets the
history afterwards.
Returns
-------
list : List of (unix timestamp, energy values) tuples
"""
if self._history is None: if self._history is None:
raise RuntimeError('No history was taken') raise RuntimeError('No history was taken')
res = self._history res = self._history
...@@ -83,16 +94,17 @@ class IterationController(metaclass=NiftyMeta): ...@@ -83,16 +94,17 @@ class IterationController(metaclass=NiftyMeta):
return res return res
def activate_and_reset_logging(self): def activate_and_reset_logging(self):
"""FIXME""" """Activates the logging functionality. If the log has been populated
before, it is reset."""
self._history = [] self._history = []
def append_history(func): def append_history(func):
"""FIXME"""
@functools.wraps(func) @functools.wraps(func)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
if args[0]._history is not None: if args[0]._history is not None:
args[0]._history.append(args[1].value) energy_val = args[1].value
args[0]._history.append((time(), energy_val))
return func(*args, **kwargs) return func(*args, **kwargs)
return wrapper return wrapper
......
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