Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion xdeps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .tasks import Manager
from . import madxutils
from .table import Table
from .optimize import (Optimize, Vary, Target, TargetList, VaryList, Action)
from .optimize import (Optimize, Vary, Target, TargetList, VaryList, Action, MeritFunctionForMatch)
from .functions import FunctionPieceWiseLinear

from ._version import __version__
Expand All @@ -22,6 +22,7 @@
"TargetList",
"VaryList",
"Action",
"MeritFunctionForMatch",
"FunctionPieceWiseLinear",
"__version__",
]
4 changes: 2 additions & 2 deletions xdeps/optimize/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .optimize import (Optimize, Vary, Target, TargetList, VaryList, Action)
from .optimize import (Optimize, Vary, Target, TargetList, VaryList, Action, MeritFunctionForMatch)


__all__ = ['Optimize', 'Vary', 'Target', 'TargetList', 'VaryList', 'Action']
__all__ = ['Optimize', 'Vary', 'Target', 'TargetList', 'VaryList', 'Action', 'MeritFunctionForMatch']
2 changes: 1 addition & 1 deletion xdeps/optimize/jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def step(self, n_steps=1, rcond = None, sing_val_cutoff = None, broyden = False)
_print("Function tolerance met")
break
# Equation search
if broyden and hasattr(self, "_last_jac"):
if broyden and hasattr(self, "_last_jac") and self._last_jac is not None:
dx = self.x - self._last_jac_x
dy = y - self._last_y
# Broyden update
Expand Down
11 changes: 8 additions & 3 deletions xdeps/optimize/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ def get_jacobian(self, x, f0=None):
x[ii] -= steps[ii]

self._last_jac = jac
self._set_x(x)
return jac

def _clip_to_max_steps(self, x_step):
Expand Down Expand Up @@ -1018,12 +1019,12 @@ def step(

this_broyden = False
if broyden:
if broyden == True:
if isinstance(broyden, bool):
this_broyden = True
else:
assert isinstance(broyden, int)
this_broyden = True
if i_step % broyden == 0:
if i_step % (broyden + 1) == 0:
this_broyden = False

self.solver.step(
Expand Down Expand Up @@ -1291,7 +1292,7 @@ def target_mismatch(self, ret=False, max_col_width=40):
print("Target mismatch: ")
out.show(max_col_width=max_col_width, maxwidth=1000)


# TODO get current value if no iteration
def get_knob_values(self, iteration=None):
"""
Get the knob values at a given iteration.
Expand Down Expand Up @@ -1692,6 +1693,10 @@ def check_limits(self, value):
def _err(self):
return self.solver.func

@_err.setter
def _err(self, value):
self.solver.func = value

@property
def actions(self):
return self._err.actions
Expand Down