17.1.1.11. pysisyphus.line_searches package

17.1.1.11.1. Submodules

17.1.1.11.2. pysisyphus.line_searches.Backtracking module

class pysisyphus.line_searches.Backtracking.Backtracking(*args, rho_lo=0.05, rho_hi=0.9, use_grad=False, **kwargs)[source]

Bases: LineSearch

__init__(*args, rho_lo=0.05, rho_hi=0.9, use_grad=False, **kwargs)[source]

Backtracking line search enforcing Armijo conditions.

Uses only energy evaluations.

See [1], Chapter 3, Line Search methods, Section 3.1 p. 31 and Section 3.5 p. 56.

alpha_new_from_phi(cycle, phi0, dphi0, alpha, alpha_prev)[source]
alpha_new_from_phi_dphi(cycle, phi0, dphi0, alpha)[source]

17.1.1.11.3. pysisyphus.line_searches.HagerZhang module

class pysisyphus.line_searches.HagerZhang.HagerZhang(*args, alpha_prev=None, f_prev=None, dphi0_prev=None, quad_step=False, eps=1e-06, theta=0.5, gamma=0.5, rho=5, psi_0=0.01, psi_1=0.1, psi_2=2.0, psi_low=0.1, psi_hi=10, Delta=0.7, omega=0.001, max_bisects=10, **kwargs)[source]

Bases: LineSearch

bisect(a, b)[source]

Bisect interval [a, b].

bracket(c)[source]

Generate initial interval [a, b] that satisfies the opposite slope condition (dphi(a) < 0, dphi(b) > 0).

double_secant(a, b)[source]

Take secant² step.

initial()[source]

Get an initial guess for alpha.

interval_update(a, b, c)[source]

Narrows down the bracketing interval.

norm_inf(arr)[source]

Returns infinity norm of given array.

secant(a, b)[source]

Take secant step.

take_quad_step(alpha, g0_)[source]

Try to get alpha for minimum step from quadratic interpolation.

17.1.1.11.4. pysisyphus.line_searches.LineSearch module

class pysisyphus.line_searches.LineSearch.LineSearch(p, x0, f, df, alpha_init=None, f0=None, g0=None, cond='armijo', c1=0.1, c2=0.9, max_cycles=10, alpha_min=1e-06, logger=None)[source]

Bases: object

__init__(p, x0, f, df, alpha_init=None, f0=None, g0=None, cond='armijo', c1=0.1, c2=0.9, max_cycles=10, alpha_min=1e-06, logger=None)[source]

Abstract line search base class.

Derived line search classes can either be instantiated from a search direction p and the other required arrays and callables, OR from a geometry object, a search direction p and other kwargs. In the latter case the appropriate arguments are derived automatically from the geometry object. Please see the from_geom() method definition. This is realized via functools.singledispatchmethod.

HagerZhang(p, x0, f, ...) or HagerZhang(geometry, p, ...)

Choice of variable names (p, c1, c2, ...) is adapted from "Nocedal & Wright - Numerical Optimization".

Parameters:
  • p (ndarray) -- 1d numpy array containing the step direction, along which the line search is carried out.

  • x0 (ndarray) -- 1d array of initial coordinates, from where the line search is started.

  • f (Callable) -- Callable taking a 1d coordinate array as argument, returning the corresponding energy.

  • df (Callable) -- Callable taking a 1d coordinate array as argument, returning the corresponding 1d gradient array.

  • alpha_init (Optional[float], default: None) -- Optional, positive float. Initial step scaling value alpha.

  • f0 (Optional[ndarray], default: None) -- Optional, scalar energy value at x0.

  • g0 (Optional[ndarray], default: None) -- Optional, 1d gradient array at x0.

  • cond (Literal['armijo', 'wolfe', 'strong_wolfe'], default: 'armijo') -- Condition to be fulfilled by the line search. Must be one of 'armijo', 'wolfe', 'strong_wolfe'.

  • c1 (float, default: 0.1) -- Optional, positive float controlling the strictness of the selected condition. Must fullfil 0.0 < c1 < c2 < 1.0

  • c2 (float, default: 0.9) -- Optional, positive float controlling the strictness of the selected condition. Must fullfil 0.0 < c1 < c2 < 1.0. Depending on the condition c2 may be unused.

  • max_cycles (int, default: 10) -- Optional, positive integer controlling the maximum number of cycles in one line search.

  • alpha_min (float, default: 1e-06) -- Optional, positive float value giving the smallest allowed alpha value, before the line search is aborted.

check_alpha(alpha)[source]
curvature_condition(alpha)[source]
from_geom(geom, p, **kwargs)[source]

Construct LineSearch from geometry object and search direction.

get_fg(what, alpha)[source]

Lookup raw function/gradient values for a given alpha.

get_phi_dphi(what, alpha, check=True)[source]

Wrapper that handles function/gradient evaluations.

got_alpha_phi_dphi(alpha)[source]
log(message, level=10)[source]
run()[source]
strong_curvature_condition(alpha)[source]
strong_wolfe_condition(alpha)[source]

Strong wolfe condition.

sufficiently_decreased(alpha)[source]

Sufficient decrease/Armijo condition.

wolfe_condition(alpha)[source]

Normal, not strong, Wolfe condition.

exception pysisyphus.line_searches.LineSearch.LineSearchConverged(alpha)[source]

Bases: Exception

exception pysisyphus.line_searches.LineSearch.LineSearchNotConverged[source]

Bases: Exception

class pysisyphus.line_searches.LineSearch.LineSearchResult(converged, alpha, f_new, g_new, f_evals, df_evals, dphi0)

Bases: tuple

alpha

Alias for field number 1

converged

Alias for field number 0

df_evals

Alias for field number 5

dphi0

Alias for field number 6

f_evals

Alias for field number 4

f_new

Alias for field number 2

g_new

Alias for field number 3

17.1.1.11.5. pysisyphus.line_searches.StrongWolfe module

class pysisyphus.line_searches.StrongWolfe.StrongWolfe(*args, alpha_max=10.0, fac=2, **kwargs)[source]

Bases: LineSearch

__init__(*args, alpha_max=10.0, fac=2, **kwargs)[source]

Wolfe line search.

Uses only energy & gradient evaluations.

See [1], Chapter 3, Line Search methods, Section 3.5 p. 60.

zoom(alpha_lo, alpha_hi, phi_lo, phi_alpha_=None, alpha_0_=None, max_cycles=10)[source]

17.1.1.11.6. pysisyphus.line_searches.interpol module

pysisyphus.line_searches.interpol.interpol_alpha_cubic(f_0, df_0, f_alpha_0, f_alpha_1, alpha_0, alpha_1)[source]
pysisyphus.line_searches.interpol.interpol_alpha_quad(f_0, df_0, f_alpha_0, alpha_0)[source]

17.1.1.11.7. Module contents

class pysisyphus.line_searches.Backtracking(*args, rho_lo=0.05, rho_hi=0.9, use_grad=False, **kwargs)[source]

Bases: LineSearch

__init__(*args, rho_lo=0.05, rho_hi=0.9, use_grad=False, **kwargs)[source]

Backtracking line search enforcing Armijo conditions.

Uses only energy evaluations.

See [1], Chapter 3, Line Search methods, Section 3.1 p. 31 and Section 3.5 p. 56.

alpha_new_from_phi(cycle, phi0, dphi0, alpha, alpha_prev)[source]
alpha_new_from_phi_dphi(cycle, phi0, dphi0, alpha)[source]
class pysisyphus.line_searches.HagerZhang(*args, alpha_prev=None, f_prev=None, dphi0_prev=None, quad_step=False, eps=1e-06, theta=0.5, gamma=0.5, rho=5, psi_0=0.01, psi_1=0.1, psi_2=2.0, psi_low=0.1, psi_hi=10, Delta=0.7, omega=0.001, max_bisects=10, **kwargs)[source]

Bases: LineSearch

bisect(a, b)[source]

Bisect interval [a, b].

bracket(c)[source]

Generate initial interval [a, b] that satisfies the opposite slope condition (dphi(a) < 0, dphi(b) > 0).

double_secant(a, b)[source]

Take secant² step.

initial()[source]

Get an initial guess for alpha.

interval_update(a, b, c)[source]

Narrows down the bracketing interval.

norm_inf(arr)[source]

Returns infinity norm of given array.

secant(a, b)[source]

Take secant step.

take_quad_step(alpha, g0_)[source]

Try to get alpha for minimum step from quadratic interpolation.

class pysisyphus.line_searches.StrongWolfe(*args, alpha_max=10.0, fac=2, **kwargs)[source]

Bases: LineSearch

__init__(*args, alpha_max=10.0, fac=2, **kwargs)[source]

Wolfe line search.

Uses only energy & gradient evaluations.

See [1], Chapter 3, Line Search methods, Section 3.5 p. 60.

zoom(alpha_lo, alpha_hi, phi_lo, phi_alpha_=None, alpha_0_=None, max_cycles=10)[source]