callbacks

Callback classes for the minimization.

class BasicCallback(mol: ~pyscf.gto.mole.Mole | None = None, energy: ~typing.List[~mldft.ofdft.energies.Energies] = <factory>, gradient_norm: ~typing.List[float] = <factory>, l2_norm: ~typing.List[float] = <factory>, learning_rate: ~typing.List[float] = <factory>, coeffs: ~typing.List[~torch.Tensor] = <factory>, stopping_index: int | None = None)[source]

Callback class for basic information during the minimization.

The basic callback is used to store the energy, gradient norm, learning rate and the coefficients during the minimization. It can be used to plot the minimization progress.

mol

PySCF Mole object

Type:

Optional[gto.Mole]

energy

List of electronic energies

Type:

List[Energies]

gradient_norm

List of gradient norm

Type:

List[float]

learning_rate

List of learning rates

Type:

List[float]

coeffs

List of coefficients

Type:

List[np.ndarray]

__call__(minimization_locals: dict) None[source]

Callback function for the minimization.

Parameters:

minimization_locals (dict) – Dictionary containing the local variables of the minimization function.

__eq__(other)

Return self==value.

__init__(mol: ~pyscf.gto.mole.Mole | None = None, energy: ~typing.List[~mldft.ofdft.energies.Energies] = <factory>, gradient_norm: ~typing.List[float] = <factory>, l2_norm: ~typing.List[float] = <factory>, learning_rate: ~typing.List[float] = <factory>, coeffs: ~typing.List[~torch.Tensor] = <factory>, stopping_index: int | None = None) None
__repr__()

Return repr(self).

convert_to_numpy() dict[source]

Convert the data to a numpy array.

Returns:

Dictionary containing the data as numpy arrays.

Return type:

dict

classmethod from_npz(filename: str | Path, mol: Mole | None = None) BasicCallback[source]

Load the data from a npz file.

Parameters:
  • filename (str | Path) – Filename.

  • mol (Optional[gto.Mole]) – PySCF Mole object.

Returns:

Callback object. If mol is not None, the mol attribute is

set to mol.

Return type:

BasicCallback

save_to_file(filename: str | Path) None[source]

Save the data to a npz file.

Parameters:

filename (str | Path) – Filename.

class ConvergenceCallback(mol: ~pyscf.gto.mole.Mole | None = None, energy: ~typing.List[~mldft.ofdft.energies.Energies] = <factory>, gradient_norm: ~typing.List[float] = <factory>, l2_norm: ~typing.List[float] = <factory>, learning_rate: ~typing.List[float] = <factory>, coeffs: ~typing.List[~torch.Tensor] = <factory>, stopping_index: int | None = None)[source]

Callback that extends BasisCallback by the stopping criterion.

get_convergence_result(convergence_criterion: str | ConvergenceCriterion = 'last_iter') OFState[source]

Return the final “converged” result.

If the criterion is last iteration, the last step is used. If the criterion is mof_small_scale, the final result is the one with the smallest energy difference. If the criterion is mof_large_scale, the final result is chosen hierarchically:

  1. The step where the projected gradient first stops decreasing, if existent. Unless there are constant values, this is the first local minimum of the projected gradient.

  2. The first step where the single-step energy update first stops decreasing, if existent. Unless there are constant values, this is the first local minimum of the single-step energy update.

  3. The minimal energy update (always exists).

The energy update is to be understood as the absolute value of the difference.

Parameters:

convergence_criterion – The criterion to choose the final result.

Returns:

OFState of the chosen final result. It has the new attribute stopping_index and stopping_criterion, which contain the index of the chosen result and the StoppingCriterion that was used.

Raises:

ValueError – If the lengths of energy, gradient_norm and coeffs do not match.

class ConvergenceCriterion(*values)[source]
__format__(format_spec, /)

Return a formatted version of the string as described by format_spec.

__new__(value)
__str__()

Return str(self).

static _generate_next_value_(name, start, count, last_values)

Return the lower-cased version of the member name.