QuESTlink icon indicating copy to clipboard operation
QuESTlink copied to clipboard

Enhancement: read a Pauli-sum-product file

Open TysonRayJones opened this issue 6 years ago • 2 comments

and convert to a structure which can be read by CalcExpectedValue

TysonRayJones avatar Jun 24 '19 16:06 TysonRayJones

This code...

filename = "hamil.txt";
Plus @@ (#[[1]] Times @@ 
        MapThread[(Subscript[
            Switch[#2, 0, Null, 1, X, 2, Y, 3, Z], #1 - 1] /. 
            Subscript[Null, _] -> Sequence[] &), {Range@
           Length@#[[2 ;;]], #[[2 ;;]]}] &) /@ 
    ReadList[filename, Number, RecordLists -> True];

converts format (coeff, pauli-on-each-qubit) e.g.

0.4435314 0 0 1 0 1 2 2 
0.1991123 0 0 0 0 1 2 3 
...

into the form

0.4435314 X_2 X_4 Y_5 Y_6 + 0.1991123 X_4 Y_5 Z_6

which is accepted by the new CalcExpecPauliSum added in 9bcb519448f3e31a90572cbcb2f7c3e7357e0331

but the inner QuEST-core function calcExpecPauliSum needlessly converts this back into a format akin to the original final format. A more direct parse is the simple

{coeffs, paulicodes} = With[
 	{rows = ReadList["chemHamil6qb.txt", Number, RecordLists -> True]},
 	{rows[[All, 1]], Flatten @ rows[[All, 2 ;;]]}
 ]

I'm not sure which if any of these should be added to the library

TysonRayJones avatar Jul 03 '19 13:07 TysonRayJones

GetPauliSumFromCoeffs[] added in 35903fe8288fd31486d2fcdeaa57a46f194bf93c, although the aforementioned overhead of casting back to a non-symbolic form in the backend still exists

TysonRayJones avatar Jan 31 '21 09:01 TysonRayJones