-
Notifications
You must be signed in to change notification settings - Fork 9
Solvers
The search_compiler.solver.Solver
class is used in both Project
s and manually created SearchCompiler
s. It defines which numerical optimizer is used when solving for parameters.
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 whenmat_jac
is available. -
LeastSquares_Jac_Solver
- This solver frames the optimization problem as a least squares problem and solves using the Levenberg-Marquardt implementation inscipy
. This optimizer is generally the fastest, but it ignores custom values oferror_func
, and it may run into issues in certain situations. However, it works well with the provided gatesets when using the defaultmatrix_distance_squared
as theerror_func
, so it is the default solver for those cases. For customized situations, we strongly recommendBFGS_Jac_Solver
as the safer choice.
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 implementmat_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.
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 asearch_compiler.circuits.QuantumStep
object that represents the current ansatz circuit structure. -
U
is the target unitary as anumpy
ndarray. -
error_func
is a function used to compare two matrices that should be minimized. The default issearch_compiler.utils.matrix_distance_squared
. The customSolver
must find the parameters forcircuit
that produce a matrix that produces a minimal value oferror_func
when it is used to compare the matrix fromcircuit
toU
.