pycif.plugins.minimizers.congrad — API reference#

Configuration reference: congrad plugin

pycif.plugins.minimizers.congrad.check.check_options(self, chi, **kwargs)[source]#

Validate CONGRAD parameters and fill missing ones with defaults.

Parameters:
  • self (Plugin) – CONGRAD minimizer plugin instance. Reads/sets: zreduc (default 1e-15), pevbnd (default 0.01), kvadim, kverbose (default 1), ldsolve (default True), maxiter (mandatory), knevecout.

  • chi (np.ndarray) – initial iterate; used only to read its dimension.

  • **kwargs – unused; accepted for interface consistency.

Returns:

self with all resolved parameters written back.

Return type:

Plugin

Raises:

AttributeError – if maxiter is not defined on the plugin.

Job evaluating the cost function and its gradient for an intermediate check of CONGRAD. Submitted by the CONGRAD minimizer as:

python -m pycif.plugins.minimizers.congrad.check_job <config.yml> <chi.npy> <run_id> [--linear]
pycif.plugins.minimizers.congrad.check_job.main()[source]#
pycif.plugins.minimizers.congrad.checks.init_check_files(self)[source]#

Set the paths of the files monitoring the convergence and back up the ones from a previous run.

pycif.plugins.minimizers.congrad.checks.write_predicted(self, niter, chi, cost, grad)[source]#

Write the cost function and gradient predicted by the quadratic model at the current estimate of the minimum.

Parameters:
  • niter (int) – number of Lanczos iterations performed so far.

  • chi (np.ndarray) – current estimate of the minimum.

  • cost (float) – predicted cost function.

  • grad (np.ndarray) – predicted gradient.

pycif.plugins.minimizers.congrad.checks.dump_state(self, chi, niter, **kwargs)[source]#

Dump the control vector at the current estimate of the minimum.

Parameters:
  • chi (np.ndarray) – current estimate of the minimum.

  • niter (int) – number of Lanczos iterations performed so far.

  • **kwargs – forwarded to sqrtbprod.

pycif.plugins.minimizers.congrad.checks.submit_check(self, chi, niter)[source]#

Submit a job evaluating the cost function and its gradient at the current estimate of the minimum.

Parameters:
  • chi (np.ndarray) – current estimate of the minimum.

  • niter (int) – number of Lanczos iterations performed so far.

pycif.plugins.minimizers.congrad.checks.collect_checks(self, wait=False)[source]#

Process the evaluated checks whose job is over.

Parameters:

wait (bool) – wait for all pending checks to be over.

pycif.plugins.minimizers.congrad.congrad.congrad(self, px, pgrad, planc1, pcost, **kwargs)[source]#

Execute the CONGRAD Lanczos inner loop.

Builds a Krylov subspace basis via the Lanczos iteration, solves the resulting tridiagonal problem, and estimates the leading eigenpairs of the Hessian \(\mathbf{A}\) of the cost function in \(\chi\)-space.

Parameters:
  • self (Plugin) – CONGRAD plugin instance with all parameters already resolved by check_options (zreduc, pevbnd, kvadim, maxiter, kverbose, ldsolve).

  • px (np.ndarray) – initial iterate \(\chi_0\), shape (n,).

  • pgrad (np.ndarray) – initial gradient \(\nabla J(\chi_0)\), shape (n,).

  • planc1 (np.ndarray) – first Lanczos vector (copy of pgrad on entry), shape (n,).

  • pcost (float) – initial cost function value \(J(\chi_0)\).

  • **kwargs – forwarded to the simulator.

Returns:

(xopt, gradopt, preduc, pevecs, iiter)

  • xopt (np.ndarray): optimal iterate.

  • gradopt (np.ndarray): gradient at xopt.

  • preduc (float): achieved relative gradient-norm reduction.

  • pevecs (np.ndarray): leading eigenvectors \(v_k\) of \(\mathbf{A}\), sorted by decreasing eigenvalue \(\lambda_k\) and scaled by \(\sqrt{1 - 1/\lambda_k}\), so that \(\mathbf{A}^{-1} \approx \mathbf{I} - \sum_k p_k p_k^\top\). Shape (maxiter, n); unused rows are zero.

  • iiter (int): number of Lanczos iterations performed.

Return type:

tuple

pycif.plugins.minimizers.congrad.minimize.minimize(self, finit, gradinit, chi0, **kwargs)[source]#

Run the CONGRAD Lanczos minimisation and return the optimal iterate.

Parameters:
  • self (Plugin) – CONGRAD minimizer plugin instance.

  • finit (float) – initial cost function value \(J(\chi_0)\).

  • gradinit (np.ndarray) – initial gradient \(\nabla J(\chi_0)\), shape (n,).

  • chi0 (np.ndarray) – initial iterate \(\chi_0\), shape (n,).

  • **kwargs – forwarded to the simulator.

Returns:

optimal iterate \(\chi_\mathrm{opt}\), shape (n,).

Return type:

np.ndarray

pycif.plugins.minimizers.congrad.wrevecs.wrevecs(kdprob, knits, kmaxit, kverbose, pevals, pbnds, pblim, pv, plancv, logfile)[source]#

Python version of the congrad minimization algorithm

Mike Fisher (ECMWF), April 2002 Frederic Chevallier (LSCE), April 2004, for the Python adaptation verbose from the Fortran subroutine:

WREVECS - Called from CONGRAD. Computes and saves eigenvectors.

Purpose. –

Interface. -

CALL WREVECS (kdprob,knits,kmaxit,pevals,pbnds,pblim,pv,plancv,&

&kngood,ptheta)

Explicit arguments:

Inputs: kdprob – dimension of the problem.

knits – Number of Lanczos vectors. kmaxit – First dimension of ‘pv’. kulout – unit number for information messages (e.g. standard output) kverbose – verbosity (0 => no messages, 1 => taciturn, 2 => verbose) pevals – Approximate eigenvalues (Ritz values). pbnds – Error bounds on eigenvectors. pblim – Error bound below which eigenvector is ‘good’. pv – Eigenvector matrix of tridiagonal problem. plancv – Lanczos vectors

Outputs: kngood – Number of eigenvectors writen.

ptheta – Eigenvalues . pvcglev – Eigenvectors prcglev – Eigenvalues again (originally, this was a file)

Externals. -

Reference. -

None yet!

Author. -

Mike Fisher ECMWF

modifications. –

Original 20/5/94 M. Fisher 01-01-96 : Optionally save vectors in memory M. Fisher 26-11-96 : USE YOM_DISTRIBUTED_VECTORS M. Fisher 31-03-99 : Removed the last vestiges of the MIO package F. Chevallier 04/05: Translate into python