Skip to content

Commit

Permalink
patched numeric Pauli string functions
Browse files Browse the repository at this point in the history
which previously did not accept symbolically-expressed but ultimately numerical Pauli-string coefficients, like "Rational[1,10]", "Sqrt[2]" or "Pi". Instead, they catastrophically crashed the QuEST process! This is despite passing validation because they were recognised as numeric, although they were not instantiated as floating-point types necessary for passing to the C process.

Now, they are correctly explicitly cast to floats before being dispatched to the backend.

The affected functions are all which numerically dispatch Pauli strings to the backend:
- CalcExpecPauliStringDerivs
- SetQuregToPauliString
- CalcExpecPauliString
- ApplyPauliString
- CalcPauliStringMatrix
- SampleExpecPauliString

What a doozie!
  • Loading branch information
TysonRayJones committed Mar 14, 2024
1 parent 02e78c6 commit 489af1b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Link/QuESTlink.m
Original file line number Diff line number Diff line change
Expand Up @@ -781,13 +781,13 @@ The probability of the forced measurement outcome (as if it were hypothetically
{{1}, {getOpCode@op}, {q}, {1}}
(* .1 X1 *)
getEncodedNumericPauliString[ Verbatim[Times][c:_?NumericQ, p:pauliOpPatt.. ] ] :=
{{c}, getOpCode /@ {p}[[All,1]], {p}[[All,2]], {Length@{p}[[All,2]]}}
{{N@c}, getOpCode /@ {p}[[All,1]], {p}[[All,2]], {Length@{p}[[All,2]]}}
(* X1 X2 *)
getEncodedNumericPauliString[ Verbatim[Times][p:pauliOpPatt.. ] ] :=
{{1}, getOpCode /@ {p}[[All,1]], {p}[[All,2]], {Length@{p}[[All,2]]}}
(* .1 X1 X2 *)
getEncodedNumericPauliString[ p:numericCoeffPauliProdPatt ] :=
{p[[1]], getOpCode /@ Rest[List@@p][[All,1]], Rest[List@@p][[All,2]], Length[p]-1}
{N@p[[1]], getOpCode /@ Rest[List@@p][[All,1]], Rest[List@@p][[All,2]], Length[p]-1}
(* .5 X1 X2 + X1 X2 + X1 + .5 X1 *)
getEncodedNumericPauliString[ s_Plus ] /; AllTrue[List@@s, MatchQ[numericCoeffPauliProdPatt]] :=
Join @@@ Transpose[getEncodedNumericPauliString /@ (List @@ s)]
Expand Down

0 comments on commit 489af1b

Please sign in to comment.