Skip to content

Commit

Permalink
added null-state warning to DrawPauliTransferMap/Eval
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonRayJones committed Apr 1, 2024
1 parent 3715f94 commit 29913d6
Show file tree
Hide file tree
Showing 5 changed files with 1,554 additions and 2,337 deletions.
28 changes: 24 additions & 4 deletions Link/QuESTlink.m
Original file line number Diff line number Diff line change
Expand Up @@ -5298,8 +5298,13 @@ variable renaming in nested scoping structs (Module[ Function[]]) *)
(* fail immediately if given unrecognised option *)
Check[OptionValue["PauliStringForm"], Return @ $Failed];

(* warn about not plotting null entries *)
If[ MemberQ[{rules}, _->{}], Message[DrawPauliTransferMap::error,
"Warning: The Pauli transfer map produces no Pauli string from some initial strings. " <>
"These edges (and null strings) are not being plotted. Hide this warning with Quiet[]."]];

(* get {pauliInd -> pauliInd, ...} **)
edges = Flatten @ Table[ rule[[1]]->rhs[[1]] , {rule,{rules}}, {rhs,rule[[2]]}];
edges = Flatten @ Table[ rule[[1]]->rhs[[1]], {rule,{rules}}, {rhs,rule[[2]]}];

(* get { (pauliInd -> pauliInd) -> coeff, ...} *)
edgeLabels = If[
Expand Down Expand Up @@ -5646,7 +5651,7 @@ variable renaming in nested scoping structs (Module[ Function[]]) *)

Options[CalcPauliTransferEval] = {
"CombineStrings" -> True,
"OutputForm" -> "Simple" (* or "Simple" *)
"OutputForm" -> "Simple" (* or "Detailed" *)
};

(*CalcPauliTransferEval additionally accepts all options to ApplyPauliTransferMap (and its subroutines) which are internally called *)
Expand Down Expand Up @@ -5789,6 +5794,18 @@ variable renaming in nested scoping structs (Module[ Function[]]) *)
(* validate options *)
Check[validateDrawPauliTransferEvalOptions[opts], Return @ $Failed];

(* warn if eval history contains null states (e.g. by fully-mixing channels) *)
If[
(* which is detectable by non-leaf nodes having no children *)
AnyTrue[
Keys @ Select[eval @ "Outdegree", PossibleZeroQ],
(Not @ MemberQ[Last @ eval @ "Layers", #]&)
],
Message[DrawPauliTransferEval::error,
"Warning: the evaluation includes Pauli strings being mapped to null strings, " <>
"as can occur from fully-mixing channels. The null strings and edges to them are " <>
"not being rendered. Suppress this warning using Quiet[]."]];

(* { id->id ... } *)
edges = Thread /@ Normal @ eval["Children"] // Flatten;

Expand Down Expand Up @@ -5842,7 +5859,7 @@ variable renaming in nested scoping structs (Module[ Function[]]) *)
Sequence @@ FilterRules[{opts}, Options[Graph]]]
]

simplePTMapEvalPatt = { { { {__Integer}, _Integer, {{_Integer,_}...} } .. } .. };
simplePTMapEvalPatt = { { { {__Integer}, _Integer, {{_Integer,_}...} } ... } .. };

DrawPauliTransferEval[ layers:simplePTMapEvalPatt, opts:drawPTEvalOptPatt ] :=
Module[
Expand All @@ -5854,6 +5871,9 @@ variable renaming in nested scoping structs (Module[ Function[]]) *)
(* compute a simplified 'Detailed' Association containing only the necessary keys *)
keys = {"Ids", "NumQubits", "Children", "Outdegree"};

(* needed to discover null Pauli strings to issue warning *)
AppendTo[keys, "Layers"];

If[ OptionValue @ "ShowCoefficients" =!= False,
keys = Join[keys, {"ParentFactors"}]];

Expand All @@ -5869,7 +5889,7 @@ variable renaming in nested scoping structs (Module[ Function[]]) *)

DrawPauliTransferEval[ pauliStr_?isValidSymbolicPauliString, circ:(mixedGatesAndMapsPatt|_?isGateFormat), opts:drawPTEvalOptPatt ] := (
Check[validateDrawPauliTransferEvalOptions[opts], Return @ $Failed];
DrawPauliTransferEval[CalcPauliTransferEval[pauliStr, circ, extractCalcPTEvalOptions @ opts], opts])
DrawPauliTransferEval[CalcPauliTransferEval[pauliStr, circ, extractCalcPTEvalOptions @ opts], opts] )

DrawPauliTransferEval[___] := invalidArgError[DrawPauliTransferEval];

Expand Down

0 comments on commit 29913d6

Please sign in to comment.