qsearch.utils

This module contains miscellaneous helper functions and tools.

The functions you may want to be aware of:

qsearch.utils.endian_reverse

Reverses the endianness of the specified unitary. Necessary for working with unitaries from Qiskit.

qsearch.utils.matrix_distance_squared

The default error_func. Returns the Hilbert-Schmidt norm between two matrices.

qsearch.utils.matrix_distance_squared_jac

Returns the value that matrix_distance_squared would return, as well as the jacobian.

qsearch.utils.matrix_residuals

The default error_residuals. Returns residuals based on difference between the poduct of the implemented matrix and the hermitian conjugate of the target and the identitiy.

qsearch.utils.matrix_residuals_jac

Returns the jacobian of matrix_residuals. Does not return the value of matrix_residuals as well.

qsearch.utils.remap

Remaps a unitary for acting on qudits in a different order.

qsearch.utils.upgrade_qudits

Upgrades a unitary from a lower qudit size to a larger qudit size.

Module Contents

Functions

matrix_product(*LU)

Performs matrix multiplication of a list of matrices.

matrix_kron(*LU)

Performs the kronecker product on a list of matrices.

op_norm(A)

An implementation of the l1-l1 operator norm.

nearest_unitary(A)

Calculate the closest unitary to a given matrix.

index_test(i, di, df)

downgrade_qudits_residuals(di, df, A, B, I)

downgrade_qudits_residuals_jac(di, df, A, B, J)

generate_stateprep_target_matrix(state)

re_rot_z(theta, old_z)

re_rot_z_jac(theta, old_z[, multiplier])

q1_unitary(x)

qt_arb_rot(Theta_1, Theta_2, Theta_3, Phi_1, Phi_2, ...)

Using the parameterization found in https://journals.aps.org/prd/pdf/10.1103/PhysRevD.38.1994,

random_near_identity(n, alpha)

remap(U, order[, d])

upgrade_qudits(U[, di, df])

endian_reverse(U[, d])

mpi_rank()

mpi_do_work(comm)

Do the work of a single compilation.

mpi_worker()

Create a worker that will keep running compilation requests until told to stop

Attributes

MPI

qsearch.utils.MPI
qsearch.utils.matrix_product(*LU)

Performs matrix multiplication of a list of matrices.

qsearch.utils.matrix_kron(*LU)

Performs the kronecker product on a list of matrices.

qsearch.utils.op_norm(A)

An implementation of the l1-l1 operator norm.

qsearch.utils.nearest_unitary(A)

Calculate the closest unitary to a given matrix.

Calculate the unitary matrix U that is closest with respect to the operator norm distance to the general matrix A.

D.M.Reich. “Characterisation and Identification of Unitary Dynamics Maps in Terms of Their Action on Density Matrices”

Parameters:

A (np.ndarray) – The matrix input.

Returns:

The unitary matrix closest to A. Return U as a numpy matrix.

Return type:

(np.ndarray)

Thank you to Ed Younis, this is based on code from qfast

qsearch.utils.index_test(i, di, df)
qsearch.utils.downgrade_qudits_residuals(di, df, A, B, I)
qsearch.utils.downgrade_qudits_residuals_jac(di, df, A, B, J)
qsearch.utils.generate_stateprep_target_matrix(state)
qsearch.utils.re_rot_z(theta, old_z)
qsearch.utils.re_rot_z_jac(theta, old_z, multiplier=1)
qsearch.utils.q1_unitary(x)
qsearch.utils.qt_arb_rot(Theta_1, Theta_2, Theta_3, Phi_1, Phi_2, Phi_3, Phi_4, Phi_5)

Using the parameterization found in https://journals.aps.org/prd/pdf/10.1103/PhysRevD.38.1994, this method constructs an arbitrary single_qutrit unitary operation.

Parameters:

qutrit_params

a list of eight parameters, in the following order Theta_1, Theta_2, Theta_3, Phi_1, Phi_2, Phi_3, Phi_4, Phi_5 The formula for the matrix is:

u11 = cos[Theta_1]*cos[Theta_2]*exp[i*Phi_1] u12 = sin[Theta_1]*exp[i*Phi_3] u13 = cos[Theta_1]*sin[Theta_2]*exp[i*Phi_4] u21 = sin[Theta_2]*sin[Theta_3]*exp[-i*Phi_4 - i*Phi_5] -

sin[Theta_1]*cos[Theta_2]*cos[Theta_3]*exp[i*Phi_1+i*Phi_2-i*Phi_3]

u22 = cos[Theta_1]*cos[Theta_3]*exp[i*Phi_2] u23 = -cos[Theta_2]*sin[Theta_3]*exp[-i*Phi_1 - i*Phi_5] -

sin[Theta_1]*sin[Theta_2]*cos[Theta_3]*exp[i*Phi_2 - i*Phi_3 + i*Phi_4]

u31 = -sin[Theta_1]*cos[Theta_2]*sin[Theta_3]*exp[i*Phi_1 - i*Phi_3 + i*Phi_5]
  • sin[Theta_2]*cos[Theta_3]*exp[-i*Phi_2-i*Phi_4]

u32 = cos[Theta_1]*sin[Theta_3]*exp[i*Phi_5] u33 = cos[Theta_2]*cos[Theta_3]*exp[-i*Phi_1 - i*Phi_2] -

sin[Theta_1]*sin[Theta_2]*sin[Theta_3]*exp[-i*Phi_3 + i*Phi_4 + i*Phi_5]

qsearch.utils.random_near_identity(n, alpha)
qsearch.utils.remap(U, order, d=2)
qsearch.utils.upgrade_qudits(U, di=2, df=3)
qsearch.utils.endian_reverse(U, d=2)
qsearch.utils.mpi_rank()
qsearch.utils.mpi_do_work(comm)

Do the work of a single compilation.

Parameters:

comm – An MPI communication object

qsearch.utils.mpi_worker()

Create a worker that will keep running compilation requests until told to stop