-
Notifications
You must be signed in to change notification settings - Fork 8
Solvers
The sc.solver.Solver class is used in both Projects and manually created SearchCompilers. 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_jacis 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_squaredas theerror_func, so it is the default solver for those cases. For customized situations, we strongly recommendBFGS_Jac_Solveras 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)
-
circuitis asearch_compiler.circuits.QuantumStepobject that represents the current ansatz circuit structure. -
Uis the target unitary as anumpyndarray. -
error_funcis a function used to compare two matrices that should be minimized. The default issearch_compiler.utils.matrix_distance_squared. The customSolvermust find the parameters forcircuitthat produce a matrix that produces a minimal value oferror_funcwhen it is used to compare the matrix fromcircuittoU.