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

Extra Utilities

Marc Davis edited this page Apr 30, 2020 · 3 revisions

There are some extra utilities that can be found in search_compiler.utils. Most of these are mainly used as subroutines by our code, but some of them you may find useful.

Matrix Utilities

  • endian_reverse - This function takes a unitary matrix, and reverses its endianness. This is needed to compare matrices from sources that use little endian, such as Qiskit, to matrices from sources that use big endian, such as search_compiler. This function relies on remap, described below.

  • remap - This function takes a unitary matrix and a list representing a rearrangement of qubits, and reorganizes the unitary according to the new arrangement. For example, remap(U, [1,0,2]) will produce the matrix that would represent the circuit produced by taking a circuit for U and swapping the names of qubits 1 and 0.

Functions you may want to write custom versions of

  • matrix_distance_squared - This is the default value of error_func and eval_func, and is an example of how to write your own versions of these functions. It is also a highly efficient distance function that can be used to compare two unitary matrices. It produces a value between 0 and 1, where a value of 0 indicates identical matrices and higher values indicate more different matrices. It ignores an overall phase difference between the two matrices. It only produces well-defined output for unitary matrices.

  • matrix_distance_squared_jac - This is a function used to calculate the Jacobian for matrix_distance_squared, and is a good example of how to write a Jacobian of custom distance functions, which is necessary in order to take advantage of Jacobian solvers. Functions of this type are provided as error_jac.

  • matrix_residuals - This is the residuals function that search_compiler.solver.LeastSquares_Jac_Solver minimizes. It also has a matrix_residuals_jac implementation. Note that the LeastSquares solver uses a different format, so eval_func must be specified in addition to error_func if you are customizing it. The default settings will automatically change eval_func for you when using LeastSquares.

Clone this wiki locally