Example of Hamiltonian decomposition into Pauli matrices


I need to see an example of how Hamiltonian, i.e. any Hermitian matrix, can be decomposed into a linear combination of Pauli matrices. Please show me how this is written in Python.

What I have tried so far is this:

I would prefer an option to do this in larger than 2 dimensions, if that is possible.


Posted 2020-05-07T18:54:14.363

Reputation: 139

Question was closed 2020-05-11T22:59:10.573

Hi and welcome to Quantum computing SE. There is probably missing figure or equation because there is written What I have tried so far is this: but then there is nothing. – Martin Vesely – 2020-05-07T21:57:30.783

3Please clarify what exactly you are asking for. Right now, H = qutip.sigmax() seems like it would be a possible answer to your question: it's an Hermitian matrix decomposed into a linear combination of Pauli matrices, written in python. I'm guessing you are asking for something more specific? – glS – 2020-05-08T12:30:22.457

The user accepted my answer. What they want is clear. Please re-open or choose a close reason different from "needs details for clarity". – user1271772 – 2021-02-27T21:23:09.510



I call this the "Paulinomial decomposition" as you are writing the matrix $H$ as a polynomial of Pauli matrices:

$H=a_{XX}X_1X_2 + a_{XY}X_1Y_2 +a_{XZ}X_1Z_2 + a_{XI}X_1 + a_{YY}Y_1Y_2 + \cdots $ (for the 2-qubit case).

To get the coefficients, you can use this formula:

$a_{ij}=\frac{1}{4}\textrm{tr}\left((\sigma_i\otimes \sigma_{j})H\right)$

For example, here is a 2-qubit gate (the square root of the SWAP gate) written as a polynomial of Pauli matrices:

You can even do this for a $2^n \times 2^n$ Hamiltonian, for example an 8x8 Hamiltonian can be done like this:

$a_{ijk}=\frac{1}{8}\textrm{tr}((\sigma_i\otimes \sigma_{j}\otimes \sigma_{k}))H)$

I have a code that can also do it for arbitrary matrices (not only $2^n \times 2^n$, but I haven't touched it for 2 years and might need to test it again). If it would be helpful, I can try to dig it up and polish it for you to use.


Posted 2020-05-07T18:54:14.363

Reputation: 8 162

To correct my notation -- every term appears to power 0 or 1, so it is really a linear decomposition. You can of course call this a polynomial, but it is really a linear decomposition. – Norbert Schuch – 2020-05-08T21:40:17.177

@NorbertSchuch Again, it is not linear either. The multi-variable function $xy+x+y-2$ is considered a quadratic, not a linear function, and it is not a monomial because it has multiple terms. For example this is a quadratic function: https://en.wikipedia.org/wiki/Quadratic_function#Bivariate_(two_variable)_quadratic_function even if $A$ and $B$ are 0 but $E\ne0$. When you have a product of two variables, you can't for example use linear programming (for optimization) because the problem is considered "non-linear".

– user1271772 – 2020-05-08T21:48:22.920

1Multilinear? ... – Norbert Schuch – 2020-05-08T22:25:14.517

That might be another way to describe it. In the definition of a "quadratic form" for example, it's okay for $a_{ij}=0$ whenever $i=j$. I suppose if we consider $X_1$ and $X_2$ to be different "variables" since they act on different qubits (one of them is the matrix $I \otimes X$ and the other one is $X \otimes I$), we could call this linear, but in the AQC community, and also in the Operations Research community, we definitely call XX terms quadratic and X terms linear. There is an entire field called "quadratization" which is about turning k-local Hamiltonians into "quadratics" exactly like – user1271772 – 2020-05-08T23:32:09.723

the first equation in my answer. I did not come up with this term, it might have been Endre Boros, Aritanan Gruber, Yves Crama, and Martin Anthony who came up with the term, but it might have been around even earlier. In any case, minimizing $b_1b_2 + b_1 - b_2$ where $b_1,b_2\in {0,1}$ is *most definitely* called QUBO (quadratic unconstrained boolean optimization). That literature is too big for us not to accept these functions as quadratic! P.S. when I talked about "quadratic forms" I meant to include this: https://en.wikipedia.org/wiki/Quadratic_form#Definitions.

– user1271772 – 2020-05-08T23:35:00.640

@user1271772 can you post the python code that you mentioned in your answer? – thespaceman – 2020-09-25T01:06:33.227

@thespaceman LOL where does it say Python? Thank you for the upvote though! – user1271772 – 2020-09-25T06:30:24.550