Created
June 7, 2022 16:22
-
-
Save lucainnocenti/bccab7fae7777f7a75ece444af1b407b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generatePair[pauliIndices_List, tuple_List] := { | |
BitXor[ | |
ReplaceAll[ | |
pauliIndices, {3 -> 0, 2 -> 1} | |
], | |
tuple | |
], | |
(-1)^Total@tuple[[Flatten@Position[pauliIndices, 2 | 3]]] | |
}; | |
matrixElementsFromPauliTuple[matrix_, pauliIndices_] := Table[ | |
{ | |
#[[2]], | |
{FromDigits[tuple, 2] + 1, FromDigits[#[[1]], 2] + 1} | |
} &@generatePair[pauliIndices, tuple], | |
{tuple, Tuples[{0, 1}, Length@pauliIndices]} | |
] // Transpose // Total@Times[ | |
matrix[[Sequence @@ #]] & /@ #[[2]], | |
#[[1]] | |
] &; | |
coefficientsFromMatrix[matrix_] := Table[ | |
matrixElementsFromPauliTuple[matrix, | |
IntegerDigits[idx - 1, 4, Log[2, Length@matrix]] | |
], | |
{idx, 4^Log[2, Length@matrix]} | |
]/Length@matrix; | |
matrixElementsFromPauliTuple[ | |
IdentityMatrix@4, | |
{0, 0} | |
] | |
coefficientsFromMatrix[IdentityMatrix@4] | |
coefficientsFromMatrix[IdentityMatrix@8] // Length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
direct method with LinearSolve:
This manages to solve up to 8 qubits, in roughly 8 seconds. Hangs for more than a minute for 9 qubits.