From 489af1b943f357d918c0ca79ea760b3f9b179b3a Mon Sep 17 00:00:00 2001 From: TysonRayJones Date: Thu, 14 Mar 2024 19:25:59 +0100 Subject: [PATCH] patched numeric Pauli string functions 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! --- Link/QuESTlink.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Link/QuESTlink.m b/Link/QuESTlink.m index 708fce19..76da22f8 100644 --- a/Link/QuESTlink.m +++ b/Link/QuESTlink.m @@ -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)]