Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle np.float in logfile, getitem preserves settings #271

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
handle np.float in logfile, getitem preserves settings
  • Loading branch information
mmckerns committed Jan 24, 2025
commit 395b575e8e258321985d2b83e84de41b2678a2fe
30 changes: 30 additions & 0 deletions mystic/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@
m._x = self._x[y]
m._y = self._y[y]
m._id = self._id[y]
# copy other internals
m.k = self.k
m.label = self.label
m._npts = self._npts
return m

def __setitem__(self, i, y):
Expand Down Expand Up @@ -415,6 +419,13 @@
if id is not None: msg = "[id: %s] " % (id) + msg
print(msg)
return
def __getitem__(self, y):
"""x.__getitem__(y) <==> x[y]"""
m = super(VerboseMonitor,self).__getitem__(y)
if hasattr(m, '_yinterval'): m._yinterval = self._yinterval
if hasattr(m, '_xinterval'): m._xinterval = self._xinterval
if hasattr(m, '_all'): m._all = self._all
return m

Check warning on line 428 in mystic/monitors.py

View check run for this annotation

Codecov / codecov/patch

mystic/monitors.py#L424-L428

Added lines #L424 - L428 were not covered by tests
pass

class LoggingMonitor(Monitor):
Expand Down Expand Up @@ -491,6 +502,15 @@
def __setstate__(self, state):
self.__dict__.update(state)
return
def __getitem__(self, y):
"""x.__getitem__(y) <==> x[y]"""
m = super(LoggingMonitor,self).__getitem__(y)
if hasattr(m, '_yinterval'): m._yinterval = self._yinterval
if hasattr(m, '_xinterval'): m._xinterval = self._xinterval
if hasattr(m, '_all'): m._all = self._all
if hasattr(m, '_filename'): m._filename = self._filename
if hasattr(m, '_file'): m._file = self._file
return m

Check warning on line 513 in mystic/monitors.py

View check run for this annotation

Codecov / codecov/patch

mystic/monitors.py#L507-L513

Added lines #L507 - L513 were not covered by tests
pass

class VerboseLoggingMonitor(LoggingMonitor):
Expand Down Expand Up @@ -556,6 +576,16 @@
def __setstate__(self, state):
self.__dict__.update(state)
return
def __getitem__(self, y):
"""x.__getitem__(y) <==> x[y]"""
m = super(VerboseLoggingMonitor,self).__getitem__(y)
if hasattr(m, '_yinterval'): m._yinterval = self._yinterval
if hasattr(m, '_xinterval'): m._xinterval = self._xinterval
if hasattr(m, '_all'): m._all = self._all
if hasattr(m, '_filename'): m._filename = self._filename
if hasattr(m, '_file'): m._file = self._file
if hasattr(m, '_vyinterval'): m._vyinterval = self._vyinterval
if hasattr(m, '_vxinterval'): m._vxinterval = self._vxinterval

Check warning on line 588 in mystic/monitors.py

View check run for this annotation

Codecov / codecov/patch

mystic/monitors.py#L581-L588

Added lines #L581 - L588 were not covered by tests
pass

def CustomMonitor(*args,**kwds):
Expand Down
3 changes: 2 additions & 1 deletion mystic/munge.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def logfile_reader(filename, iter=False):
If iter=True, returns tuple of (iter, params, energy), as defined above.
If iter=False, returns tuple of (params, energy).
"""
from numpy import inf, nan
import numpy as np
inf, nan = np.inf, np.nan
f = open(filename,"r")
file = f.read()
f.close()
Expand Down