Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Solvers

Marc Davis edited this page Apr 10, 2020 · 2 revisions

The search_compiler.solver.Solver class is used in both Projects and manually created SearchCompilers. It defines which numerical optimizer is used when solving for parameters.

Provided Solvers

Jacobian Solvers

These are the fastest solvers, but they require the optional mat_jac function to be implemented by all gates in the gateset. Fortunately, any gateset built from constant gates and the provide single qubit gates will automatically be supported.

  • BFGS_Jac_Solver - This solver is robust and fast. It is generally the go-to option when mat_jac is available.
  • LeastSquares_Jac_Solver - This solver frames the optimization problem as a least squares problem and solves using the Levenberg-Marquardt implementation in scipy. This optimizer is generally the fastest, but it ignores custom values of error_func, and it may run into issues in certain situations. However, it works well with the provided gatesets when using the default matrix_distance_squared as the error_func, so it is the default solver for those cases. For customized situations, we strongly recommend BFGS_Jac_Solver as the safer choice.

General Purpose Solvers

These solvers are robust and work well even without the Jacobian, but require many more function evaluations and therefore are much slower.

  • COBYLA_Solver - This is the fastest non-Jacobian solver from our testing. We recommend this solver if your gateset includes a gate that does not implement mat_jac.
  • CMA_Solver - This is the most robust non-Jacobian solver from our testing. However, it is much slower than COBYLA, so we generally recommend COBYLA.

Custom Solvers

The easiest way to produce a custom solver is to use DIY_Solver. You can use this class to create a solver object from a function.

import search_compiler as sc
# f must be a function that takes an error function and an initial guess, and returns the array of parameter values that minimize the error function
mysovler = sc.solver.DIY_Solver(f)

You can also create your own custom search_compiler.solver.Solver class for more control. To do this, you must implement the solve_for_unitary function.

solve_for_unitary(circuit, U, error_func)
  • circuit is a search_compiler.circuits.QuantumStep object that represents the current ansatz circuit structure.
  • U is the target unitary as a numpy ndarray.
  • error_func is a function used to compare two matrices that should be minimized. The default is search_compiler.utils.matrix_distance_squared. The custom Solver must find the parameters for circuit that produce a matrix that produces a minimal value of error_func when it is used to compare the matrix from circuit to U.
Clone this wiki locally