Hamiltonian decomposition

Consider i have a 4x4 matrix

H = array([[-2.,  1.,  0.,  0.],
       [ 1., -2.,  1.,  0.],
       [ 0.,  1., -2.,  1.],
       [ 0.,  0.,  1., -2.]]

i can decomose this matrix to unitaries with PauliX, Identity, PauliY and PauliZ with qml.utils.decompose_hamiltonian. I want to decompose M with these matrices

 C = Matrix([[0, 1],[0, 0]])
 S = Matrix([[0, 0],[1, 0]])

where are non-unitary. These matrices are spin rising and spin lowering operators, too. How can i decompose M using Identity, C, and S with qml.utils.decompose_hamiltonian?

Hi @sassan_moradi, unfortunately qml.utils.decompose_hamiltonian doesn’t allow you to specify the operators for the decomposition. I don’t think we have any function that does what you need but if you feel that this is an important feature to have it would be great if you could add it as a feature request on GitHub. If you want to explain your use case here or there it can also be useful to understand your need better.

Hi @sassan_moradi, looking deeper into your question @josh noticed that it isn’t even possible to decompose your 4x4 matrix into only the two 2x2 matrices you have. You would need 16 basis matrices to decompose into.

It is possible to decompose the tridiagonal matrices with Identity and sigma_+ and sigma_-. The number of terms reduce by 2log(N)+1. While with Identity, PauliX, PauliY, and PauliZ, the number of terms are N, if you do the decomposition. Here is the paper: https://journals.aps.org/pra/abstract/10.1103/PhysRevA.104.022418

Hi @sassan_moradi, thank you for this link. How important/urgent is this feature for you?

It is very important. I think i need to change the source code for decompose_hamiltonian. I think this line paulis = [qml.Identity, qml.PauliX, qml.PauliY, qml.PauliZ] must be changed.

Hi @sassan_moradi,

Modifying the decompose_hamiltonian function as you mention would probably cause other errors in different places. It’s probably better to create a new function that tells you whether or not this decomposition is possible (because it’s not possible for any random matrix) and then perform the decomposition if possible. You could try the following:

  1. Determine whether you can decompose the matrix in terms of Identity, PauliX, PauliY.
  2. If it’s not possible then show an error message and exit the function.
  3. If it is possible then decompose it into Identity, PauliX, PauliY, and then further decompose these into C and S.

Is this a feature that you would like to work on and contribute to PennyLane?

Many thanks. I will follow what you mentioned above. First i decompose the matrix to PauliX and PauliY. Since S = (PauliX + 1jPauliY)/2 and C = (PauliX - 1jPauliY)/2, i can rewrite the decomposition based on Identity, S, and C.

Awesome! :smiley:

Let me know if you have any further questions.