Optimizers

class slowquant.qiskit_interface.optimizers.Result

Result class for optimizers.

Initialize result class.

class slowquant.qiskit_interface.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 unique absolute eigenvalues, i.e. -1 and 1 is the “same” eigenvalue in this context, and \(x_\mu=\frac{2\mu}{2R+1}\pi\). In this implementation it is assumed that \(R=2\).

After the function \(E(x)\) have been reconstruced the global minima of the function can be found classically.

  1. 10.22331/q-2021-01-28-391, Algorithm 1

  2. 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.

minimize(f: Callable[[list[float]], float], x: list[float], jac=None) Result

Run minimization.

Parameters:
  • f – Function to be minimzed, can only take one argument.

  • x – Changable parameters of f.

  • jac – Placeholder for gradient function, is not used.

Returns:

Minimization results.

slowquant.qiskit_interface.optimizers.get_energy_evals(f: Callable[[list[float]], float], x: list[float], idx: int, R: int) list[float]

Evaluate the function in all points needed for the reconstrucing 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.qiskit_interface.optimizers.reconstructed_f(x: float, energy_vals: list[float], R: int) float

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)}\]
  1. 10.22331/q-2022-03-30-677, Eq. (57)

  2. https://pennylane.ai/qml/demos/tutorial_general_parshift/, 2024-03-14

Parameters:
  • x – Function variable.

  • energy_vals – Pre-calculated points of original function.

  • R – Parameter to control how many points are needed.

Returns:

Function value in x.