Skip to content

Commit

Permalink
push NP into SetNestedSolver (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmckerns authored Jan 14, 2025
1 parent d8159cf commit 0d79f75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 9 additions & 1 deletion mystic/abstract_ensemble_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def __total_iters(self):
"""total number of iterations"""
return sum(self._all_iters)

def SetNestedSolver(self, solver):
def SetNestedSolver(self, solver, **kwds):
"""set the nested solver
Args:
Expand All @@ -179,6 +179,14 @@ def SetNestedSolver(self, solver):
None
"""
self._solver = solver
#HACK: add NP attribute if NP provided
if 'NP' in kwds:
from mystic.abstract_solver import AbstractSolver
if AbstractSolver in getattr(solver, 'mro', lambda:())():
solver.NP = kwds['NP']
else:
msg = "solver got an unexpected keyword argument 'NP'"
raise TypeError(msg)
return

def __get_solver_instance(self, reset=False):
Expand Down
9 changes: 2 additions & 7 deletions mystic/abstract_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,8 @@ def __init__(self, bounds, model, npts=None, **kwds):
# apply additional kwds
solver = self._kwds['solver']
if solver is not None:
if not hasattr(solver, 'nPop'):
#HACK: add NP attribute if NP provided
NP = self._kwds['NP']
solver.NP = NP
elif 'NP' in kwds:
msg = "cannot modify 'nPop' for configured solver"
raise NotImplementedError(msg)
if 'NP' in self._kwds: #XXX: instead use npts?
s.SetNestedSolver(solver, NP=self._kwds['NP'])
s.SetNestedSolver(solver)
s.id = self._kwds['id']
s.SetDistribution(self._kwds['dist'])
Expand Down

0 comments on commit 0d79f75

Please sign in to comment.