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

Add docstrings

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