toqito: Bug: Generalized Gell-Mann Matrices

Before reporting this bug:

  • Verify there is not an existing issue for it already
  • You are using the latest version of toqito with a python version >=3.10

Describe the bug

Yesterday I was skimming through the gen_gell_mann function, I’ve found a logic issue in the calculation of the diagonal matrices when ind_1 == ind_2 and ind_1 > 0. The function is intended to solve

  • Diagonal (traceless) Hermitian matrices for ind_1 == ind_2.

  • Off-diagonal symmetric matrices for ind_1 < ind_2.

  • Off-diagonal anti-symmetric matrices for ind_1 > ind_2. In the case ind_1 == ind_2, the diagonal Gell-Mann matrix should be Traceless, Hermitian, and normalized. The identity matrix is not part of the Gell-Mann basis. This should be skipped entirely or explicitly excluded since Gell-Mann matrices are traceless Hermitian generators of SU(N).

scalar = np.sqrt(2 / (ind_1 * (ind_1 + 1)))
diag = np.ones((ind_1,))
diag = np.append(diag, -ind_1)
diag = scalar * np.append(diag, np.zeros((dim - ind_1 - 1)))

The problem is in how the diagonal values are being constructed. For the standard generalized Gell-Mann matrices, the diagonal matrices when ind_1 == ind_2 > 0 should have:

The first ind_1 positions filled with ones The position at index ind_1 should have value -ind_1 The remaining positions should be zeros

However, when we look at what the code is doing:

It correctly creates an array of ind_1 ones It appends -ind_1 as a single value It then multiplies everything by scalar

This will result in a diagonal matrix with all values having the same magnitude (except for the single -ind_1 value), which doesn’t follow the proper definition of generalized Gell-Mann matrices. For a proper implementation, the code should create a diagonal with ones in the first ind_1 positions and -ind_1 in the ind_1-th position, without applying the same scalar to all elements.

To Reproduce

The issue is that when ind_1 > ind_2, we’re creating an anti-symmetric matrix with imaginary components. But the standard definition usually has the symmetric matrices for ind_1 < ind_2 and antisymmetric for ind_1 > ind_2. The current implementation would produce a matrix that is neither Hermitian nor follows the standard convention.

if ind_1 < ind_2:
    gm_op = e_mat + e_mat.conj().T
else:  # ind_1 > ind_2
    gm_op = 1j * e_mat - 1j * e_mat.conj().T

Expected behavior

there are three distinct cases:

  • When ind_1 == ind_2 == 0: Identity matrix
  • When ind_1 == ind_2 > 0: Diagonal matrices with specific structure
  • When ind_1 != ind_2: Off-diagonal matrices (symmetric or anti-symmetric) Looking at case 2 (diagonal matrices where ind_1 == ind_2 > 0), the code computes:
scalar = np.sqrt(2 / (ind_1 * (ind_1 + 1)))
diag = np.ones((ind_1,))
diag = np.append(diag, -ind_1)
diag = scalar * np.append(diag, np.zeros((dim - ind_1 - 1)))
  • Creates a scalar = sqrt(2/(ind_1*(ind_1+1)))
  • Creates an array of ind_1 ones: [1, 1, …, 1]
  • Appends -ind_1 to this array: [1, 1, …, 1, -ind_1]
  • Appends zeros to fill the remaining positions to dimension dim
  • Multiplies everything by the scalar

The issue is with the sign in the anti-symmetric case. The current implementation is not producing a Hermitian matrix when ind_1 > ind_2. Asymmetric Gell-Mann matrices’ index condition is reversed

if ind_1 < ind_2:
    gm_op = e_mat + e_mat.conj().T  # symmetric
else:
    gm_op = 1j * e_mat - 1j * e_mat.conj().T  # anti-symmetric

some more potential errors validation for the input indices ind_1 and ind_2. It didn’t check if they were within the valid range of 0 to dim-1. This could lead to IndexError if the inputs were out of bounds.

References

Gell-Man

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 28 (28 by maintainers)

Most upvoted comments

@AbdullahKazi500 yes, there is an associated GitHub project https://github.com/nathanieljohnston/QETLAB

Have added the issues there waiting for response BTW I feel like I have not made any active contributions to toqito like people are making PRs lol

Much appreciated, @AbdullahKazi500 . If you would like to claim #1148, we are welcome to! You have already made improvements to the toqito package, and we sincerely appreciate your attention to detail!

I think we should wait for Nathaniel reply on this I believe that we need to adapt the changes they will make in qetlab in our package