Optimizers
- class slowquant.unitary_coupled_cluster.optimizers.Optimizers(fun: Callable[[list[float]], float | list[float]], method: str, grad: Callable[[list[float]], ndarray] | None = None, maxiter: int = 1000, tol: float = 1e-07, is_silent: bool = False)
Optimizers class.
Initialize optimizer class.
- Parameters:
fun – Function to minimize.
method – Optimization method.
grad – Gradient of function.
maxiter – Maximum iterations.
tol – Convergence tolerence.
is_silent – Supress progress output.
- _iteration: int
- _print_progress(x: Sequence[float], fun: Callable[[list[float]], float | list[float]], silent: bool = False) None
Print progress during optimization.
- Parameters:
x – Parameters.
fun – Function.
silent – Silence progress print.
- _start: float
- minimize(x0: Sequence[float], extra_options: dict[str, Any] | None = None) Result
Minimize function.
- extra_options:
R dict[str, int]: Order parameter needed for Rotosolve.
param_names Sequence[str]: Names of parameters needed for Rotosolve.
- Parameters:
x0 – Starting value of changable parameters.
extra_options – Extra options for optimizers.
- class slowquant.unitary_coupled_cluster.optimizers.Result
Result class for optimizers.
Initialize result class.
- class slowquant.unitary_coupled_cluster.optimizers.RotoSolve(R: dict[str, int], param_names: Sequence[str], maxiter: int = 30, tol: float = 1e-06, callback: Callable[[list[float]], None] | None = None)
Rotosolve optimizer.
Implemenation of Rotosolver assuming three eigenvalues for generators. This works for fermionic generators of the type:
\[\hat{G}_{pq} = \hat{a}^\dagger_p \hat{a}_q - \hat{a}_q^\dagger \hat{a}_p\]and,
\[\hat{G}_{pqrs} = \hat{a}^\dagger_p \hat{a}^\dagger_q \hat{a}_r \hat{a}_s - \hat{a}^\dagger_s \hat{a}^\dagger_r \hat{a}_p \hat{a}_q\]Rotosolve works by exactly reconstrucing the energy function in a single parameter:
\[E(x) = \frac{\sin\left(\frac{2R+1}{2}x\right)}{2R+1}\sum_{\mu=-R}^{R}E(x_\mu)\frac{(-1)^\mu}{\sin\left(\frac{x - x_\mu}{2}\right)}\]With \(R\) being the number of different positive differences between eigenvalues, and \(x_\mu=\frac{2\mu}{2R+1}\pi\).
After the function \(E(x)\) have been reconstruced the global minima of the function can be found classically.
10.22331/q-2021-01-28-391, Algorithm 1
10.22331/q-2022-03-30-677, Eq. (57)
Initialize Rotosolver.
- Parameters:
R – R parameter used for the function reconstruction.
param_names – Names of parameters, used to index R.
maxiter – Maximum number of iterations (sweeps).
tol – Convergence tolerence.
callback – Callback function, takes only x (parameters) as an argument.
- slowquant.unitary_coupled_cluster.optimizers.get_energy_evals(f: Callable[[list[float]], float | list[float]], x: list[float], idx: int, R: int) list[float] | list[list[float]]
Evaluate the function in all points needed for the reconstruction in Rotosolve.
- Parameters:
f – Function to evaluate.
x – Parameters of f.
idx – Index of parameter to be changed.
R – Parameter to control how many points are needed.
- Returns:
All needed function evaluations.
- slowquant.unitary_coupled_cluster.optimizers.reconstructed_f(x_vals: ndarray, energy_vals: list[float] | list[list[float]], R: int) ndarray
Reconstructed the function in terms of sin-functions.
\[E(x) = \frac{\sin\left(\frac{2R+1}{2}x\right)}{2R+1}\sum_{\mu=-R}^{R}E(x_\mu)\frac{(-1)^\mu}{\sin\left(\frac{x - x_\mu}{2}\right)}\]For better numerical stability the implemented form is instead:
\[E(x) = \sum_{\mu=-R}^{R}E(x_\mu)\frac{\mathrm{sinc}\left(\frac{2R+1}{2}(x-x_\mu)\right)}{\mathrm{sinc}\left(\frac{1}{2}(x-x_\mu)\right)}\]10.22331/q-2022-03-30-677, Eq. (57)
https://pennylane.ai/qml/demos/tutorial_general_parshift/, 2024-03-14
- Parameters:
x_vals – List of points to evaluate the function in.
energy_vals – Pre-calculated points of original function.
R – Parameter to control how many points are needed.
- Returns:
Function value in list of points.