Skip to content

Commit

Permalink
Public release
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum-mob committed Sep 25, 2024
1 parent 9e8a4c5 commit 57183ef
Show file tree
Hide file tree
Showing 63 changed files with 15,869 additions and 7,120 deletions.
410 changes: 312 additions & 98 deletions Q3/Documentation/English/Guides/CliffordQuantumCircuits.nb

Large diffs are not rendered by default.

394 changes: 256 additions & 138 deletions Q3/Documentation/English/Guides/FermionicQuantumComputation.nb

Large diffs are not rendered by default.

268 changes: 134 additions & 134 deletions Q3/Documentation/English/Guides/QuantumInformationSystems.nb

Large diffs are not rendered by default.

Binary file modified Q3/Documentation/English/Index/_0.cfs
Binary file not shown.
Binary file modified Q3/Documentation/English/Index/segments_3
Binary file not shown.
1,207 changes: 1,061 additions & 146 deletions Q3/Documentation/English/ReferencePages/Symbols/CliffordCircuit.nb

Large diffs are not rendered by default.

179 changes: 89 additions & 90 deletions Q3/Documentation/English/ReferencePages/Symbols/CliffordFactor.nb

Large diffs are not rendered by default.

283 changes: 147 additions & 136 deletions Q3/Documentation/English/ReferencePages/Symbols/CliffordGroup.nb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

238 changes: 130 additions & 108 deletions Q3/Documentation/English/ReferencePages/Symbols/CliffordMatrixQ.nb

Large diffs are not rendered by default.

354 changes: 228 additions & 126 deletions Q3/Documentation/English/ReferencePages/Symbols/CliffordState.nb

Large diffs are not rendered by default.

215 changes: 108 additions & 107 deletions Q3/Documentation/English/ReferencePages/Symbols/CliffordUnitary.nb

Large diffs are not rendered by default.

246 changes: 123 additions & 123 deletions Q3/Documentation/English/ReferencePages/Symbols/FromGottesmanMatrix.nb

Large diffs are not rendered by default.

223 changes: 117 additions & 106 deletions Q3/Documentation/English/ReferencePages/Symbols/FromGottesmanVector.nb

Large diffs are not rendered by default.

352 changes: 185 additions & 167 deletions Q3/Documentation/English/ReferencePages/Symbols/FullCliffordGroup.nb

Large diffs are not rendered by default.

236 changes: 106 additions & 130 deletions Q3/Documentation/English/ReferencePages/Symbols/FullGottesmanMatrix.nb

Large diffs are not rendered by default.

229 changes: 120 additions & 109 deletions Q3/Documentation/English/ReferencePages/Symbols/FullGottesmanVector.nb

Large diffs are not rendered by default.

1,112 changes: 636 additions & 476 deletions Q3/Documentation/English/ReferencePages/Symbols/FullPauliGroup.nb

Large diffs are not rendered by default.

258 changes: 134 additions & 124 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanBasis.nb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

188 changes: 94 additions & 94 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanFlip.nb

Large diffs are not rendered by default.

241 changes: 126 additions & 115 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanGroup.nb

Large diffs are not rendered by default.

389 changes: 198 additions & 191 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanInverse.nb

Large diffs are not rendered by default.

182 changes: 91 additions & 91 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanMap.nb

Large diffs are not rendered by default.

452 changes: 226 additions & 226 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanMatrix.nb

Large diffs are not rendered by default.

377 changes: 264 additions & 113 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanMatrixQ.nb

Large diffs are not rendered by default.

209 changes: 110 additions & 99 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanMerge.nb

Large diffs are not rendered by default.

310 changes: 159 additions & 151 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanSolve.nb

Large diffs are not rendered by default.

213 changes: 112 additions & 101 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanSplit.nb

Large diffs are not rendered by default.

627 changes: 354 additions & 273 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanStandard.nb

Large diffs are not rendered by default.

307 changes: 159 additions & 148 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanTimes.nb

Large diffs are not rendered by default.

205 changes: 108 additions & 97 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanVector.nb

Large diffs are not rendered by default.

162 changes: 81 additions & 81 deletions Q3/Documentation/English/ReferencePages/Symbols/GottesmanVectorQ.nb

Large diffs are not rendered by default.

1,523 changes: 1,523 additions & 0 deletions Q3/Documentation/English/ReferencePages/Symbols/PauliDecoherence.nb

Large diffs are not rendered by default.

539 changes: 299 additions & 240 deletions Q3/Documentation/English/ReferencePages/Symbols/PauliGroup.nb

Large diffs are not rendered by default.

273 changes: 147 additions & 126 deletions Q3/Documentation/English/ReferencePages/Symbols/PauliMatrixQ.nb

Large diffs are not rendered by default.

236 changes: 118 additions & 118 deletions Q3/Documentation/English/ReferencePages/Symbols/PauliMeasurement.nb

Large diffs are not rendered by default.

1,342 changes: 1,160 additions & 182 deletions Q3/Documentation/English/ReferencePages/Symbols/RandomCliffordCircuit.nb

Large diffs are not rendered by default.

4,308 changes: 3,948 additions & 360 deletions Q3/Documentation/English/ReferencePages/Symbols/RandomCliffordCircuitSimulate.nb

Large diffs are not rendered by default.

158 changes: 79 additions & 79 deletions Q3/Documentation/English/ReferencePages/Symbols/RandomCliffordState.nb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file modified Q3/Documentation/English/SearchIndex/5/_0.cfe
Binary file not shown.
Binary file modified Q3/Documentation/English/SearchIndex/5/_0.cfs
Binary file not shown.
Binary file modified Q3/Documentation/English/SearchIndex/5/_0.si
Binary file not shown.
9 changes: 5 additions & 4 deletions Q3/Documentation/English/SearchIndex/5/indexMetadata.wl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<|"IndexedPaths" -> None, "Driver" -> "Lucene",
"CreationDate" -> DateObject[{2024, 9, 23, 14, 19,
49.580922`8.44788957438235}, "Instant", "Gregorian", 9.], "Version" -> 5,
"Synonyms" -> None, "Method" -> "BM25", "Language" -> "English",
"ContentFieldOptions" -> <|"Title" -> <|"Stored" -> True, "Weight" -> 2|>,
"CreationDate" -> DateObject[{2024, 9, 25, 9, 40,
9.531881`7.7317535984989885}, "Instant", "Gregorian", 9.],
"Version" -> 5, "Synonyms" -> None, "Method" -> "BM25",
"Language" -> "English", "ContentFieldOptions" ->
<|"Title" -> <|"Stored" -> True, "Weight" -> 2|>,
"ExactTitle" -> <|"Stored" -> True, "Tokenized" -> False,
"LengthWeighted" -> False|>, "NormalizedTitle" ->
<|"Tokenized" -> False, "LengthWeighted" -> False|>,
Expand Down
Binary file modified Q3/Documentation/English/SearchIndex/5/segments_2
Binary file not shown.
Binary file modified Q3/Documentation/English/SpellIndex/_2x.cfs
Binary file not shown.
Binary file modified Q3/Documentation/English/SpellIndex/segments_5x
Binary file not shown.
492 changes: 246 additions & 246 deletions Q3/Documentation/English/Tutorials/PauliAndCliffordGroups.nb

Large diffs are not rendered by default.

390 changes: 242 additions & 148 deletions Q3/Documentation/English/Tutorials/QuantumInformationSystems.nb

Large diffs are not rendered by default.

1,110 changes: 560 additions & 550 deletions Q3/Documentation/English/Tutorials/StabilizerFormalism.nb

Large diffs are not rendered by default.

128 changes: 108 additions & 20 deletions Q3/Kernel/Clifford.wl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BeginPackage["Q3`"]

{ CliffordUnitary, RandomCliffordUnitary };

{ PauliMeasurement };
{ PauliMeasurement, PauliDecoherence };

{ CliffordCircuit, RandomCliffordCircuit, RandomCliffordCircuitSimulate };

Expand Down Expand Up @@ -43,13 +43,18 @@ MakeBoxes[cs:CliffordState[gnr_?MatrixQ, ___], fmt_] := Module[
CliffordState[data_, ss:{___?QubitQ}, rest___] :=
CliffordState[data, FlavorCap @ ss, rest] /; Not[FlavorCapQ @ ss]

(* quick initialization *)
CliffordState[Ket[v_?VectorQ], rest___] := Module[
{ n = Length[v],
vv, pp },
vv = SparseArray @ NestList[RotateRight[#, 2]&, PadRight[{0, 1}, 2n], n-1];
CliffordState[Transpose @ Append[Transpose @ vv, IntegerParity @ v], rest]
]

(* quick initialization *)
CliffordState[Ket[a_Association], rest___] :=
CliffordState[ Ket @ Values @ KeySelect[a, QubitQ] ]


CliffordState /:
StabilizerGenerators[CliffordState[gnr_, ___?OptionQ]] :=
Expand Down Expand Up @@ -130,7 +135,7 @@ PauliMeasurement[msr_?GottesmanVectorQ, kk:{___Integer}][cs_CliffordState] := Mo
{ ii = Riffle[2kk-1, 2kk],
vv = First[cs], ch, new, gnr },
vv = vv[[;;, ii]];
ch = Map[GottesmanInner[msr, #]&, vv];
ch = Map[GottesmanDot[msr, #]&, vv];
If[ ArrayZeroQ[ch],
$MeasurementOut[msr] = Indeterminate;
Return[cs]
Expand All @@ -157,7 +162,7 @@ PauliMeasurement[msr_?GottesmanVectorQ, kk:{___Integer}][cs_CliffordState] := Mo
PauliMeasurement[msr_?GottesmanVectorQ][cs_CliffordState] := Module[
{ gnr = First[cs],
chk, new },
chk = Map[GottesmanInner[msr, #]&, Most /@ gnr];
chk = Map[GottesmanDot[msr, #]&, Most /@ gnr];
If[ ArrayZeroQ[chk],
$MeasurementOut[msr] = Indeterminate;
Return[cs]
Expand All @@ -177,7 +182,41 @@ PauliMeasurement /:
Multiply[pre___, msr_PauliMeasurement, cs_CliffordState] :=
Multiply[pre, msr @ cs]

(**** </Measurement> ****)
(**** </PauliMeasurement> ****)


(**** <PauliDecoherence> ****)

PauliDecoherence::usage = "PauliDecoherence[vec] represents the Pauli measurement corresponding to Gottesman vector vec.\nPauliDecoherence[vec, {{k1, k2, \[Ellipsis]}, n}] represents the Pauli measurement on particular qubits numbered k1, k2, \[Ellipsis] among n qubits."

PauliDecoherence[msr_?GottesmanVectorQ, k_Integer] :=
PauliDecoherence[msr, {k}]

PauliDecoherence[msr_?GottesmanVectorQ, kk:{___Integer}][cs_CliffordState] := Module[
{ ii = Riffle[2kk-1, 2kk],
vv = First[cs], ch, new, gnr },
vv = vv[[;;, ii]];
ch = Map[GottesmanDot[msr, #]&, vv];
If[ArrayZeroQ[ch], Return[cs]];
(* Simulate the deocherence process. *)
ch = Position[ch, 1];
Module[
{ gnr = First[cs],
alt },
alt = gnr[[First @ First @ ch]];
gnr = ReplaceAt[gnr, v_?VectorQ :> GottesmanTimes[alt, v], Rest @ ch];
gnr = Delete[gnr, First @ ch];
If[gnr == {}, gnr = Zero @ {1, Length @ alt}]; (* the maximally-mixed state *)
ReplacePart[cs, 1 -> SparseArray[gnr]]
]
]


PauliDecoherence /:
Multiply[pre___, msr_PauliDecoherence, cs_CliffordState] :=
Multiply[pre, msr @ cs]

(**** </PauliDecoherence> ****)


(**** <CliffordUnitary> ****)
Expand Down Expand Up @@ -244,7 +283,7 @@ RandomCliffordUnitary[n_Integer, spec___] :=

(**** <CliffordLogarithmicNegativity> ****)

CliffordLogarithmicNegativity::usage = "CliffordLogarithmicNegativity[cs, {k1, k2, \[Ellipsis]}] returns the logarithmic negativity cs between qubits {k1, k2, \[Ellipsis]} and the rest of Clifford state.\nCliffordLogarithmicNegativity[{k1, k2, \[Ellipsis]}] is an operator form of CliffordLogarithmicNegativity that can be applied to Clifford states."
CliffordLogarithmicNegativity::usage = "CliffordLogarithmicNegativity[cs, {k1, k2, \[Ellipsis]}] returns the logarithmic negativity between qubits {k1, k2, \[Ellipsis]} and the rest in Clifford state cs.\nCliffordLogarithmicNegativity[{k1, k2, \[Ellipsis]}] is an operator form of CliffordLogarithmicNegativity that can be applied to Clifford states."
(* SEE ALSO: Sang et at. (2021) and Weinstein et al. (2022) *)

CliffordLogarithmicNegativity[kk:{___Integer}][cs_CliffordState] :=
Expand All @@ -253,12 +292,10 @@ CliffordLogarithmicNegativity[kk:{___Integer}][cs_CliffordState] :=
CliffordLogarithmicNegativity[cs_CliffordState, kk:{___Integer}] := Module[
{ gnr = First[cs],
chk },
gnr = Map[Partition[#, 2]&, gnr];
gnr = Flatten /@ gnr[[;;, kk]];
(* chk = IntegerParity @ Outer[GottesmanInner, gnr, gnr, 1]; *)
(* MatrixRank[chk] / 2 *)
(* NOTE: The above two lines do not seem to work; hence, the following two lines instead. *)
chk = Outer[GottesmanInner, gnr, gnr, 1];
gnr = gnr[[ ;; , Riffle[2kk-1, 2kk] ]];
chk = GottesmanDot[gnr, gnr];
(* MatrixRank[IntegerParity @ chk] / 2 *)
(* NOTE: The above line does not seem to work; hence, the following line instead. *)
MatrixRank[chk, Modulus -> 2] / 2
]

Expand Down Expand Up @@ -301,31 +338,62 @@ CliffordCircuit[gg:{_CliffordState, ___}][cs_CliffordState] :=
CliffordCircuit[Rest @ gg][cs]

CliffordCircuit[gg_List][cs_CliffordState] :=
Fold[Construct[#2, #1]&, cs, gg]
Fold[Construct[#2, #1]&, cs, Flatten @ gg]

CliffordCircuit /:
Elaborate @ CliffordCircuit[gg:{_CliffordState, ___}] :=
Fold[Construct[#2, #1]&, Flatten @ gg]

numberOfQubits[CliffordState[mat_?MatrixQ, ___]] := (Last[Dimensions @ mat] - 1)/2

numberOfQubits[CliffordUnitary[_?MatrixQ, {_, n_Integer}, ___]] = n
CliffordCircuit /:
Show[cc_CliffordCircuit, S_Symbol?QubitQ, more___?OptionQ] :=
Graphics[cc, S, more]

CliffordCircuit /:
Graphics[CliffordCircuit[gg_List], S_Symbol?QubitQ, more___?OptionQ] := Module[
{ n, cs, ss, qc },
n = FirstCase[gg, g:_Symbol[__] :> numberOfQubits[g], Indeterminate, Infinity];
If[n === Indeterminate, n = 1];
ss = S[Range @ n, $];
qc = gg /. {
CliffordCircuit[{}] -> "Spacer",
CliffordCircuit -> Identity,
CliffordState[__] :> Ket[ss],
CliffordUnitary[m_, kk_, opts___?OptionQ] :> Gate[S[kk, $], opts],
CliffordUnitary[m_, opts___?OptionQ] :> Gate[ss, opts, "Label" -> "U"],
PauliMeasurement[v_, kk_, opts___?OptionQ] :> Gate[S[kk, $], opts, "Shape" -> "Measurement"],
PauliDecoherence[v_, kk_, opts___?OptionQ] :> Gate[S[kk, $], opts, "Label" -> "\[ScriptCapitalD]"],
CNOT[i_, j_] :> Gate[{S[i,$]->1}, {S[j,$]}, "Shape" -> "CirclePlus"],
SWAP[i_, j_] :> Gate[{S[i,$]->1}, {S[j,$]}, "Shape" -> "Cross", "ControlShape" -> "Cross"],
Hadamard[kk_] :> Map[Gate[{#}, "Label" -> "H"]&, S[kk,$]],
Quadrant[kk_] :> Map[Gate[{#}, "Label" -> "S"]&, S[kk,$]]
};
QuantumCircuit[Sequence @@ qc, "PostMeasurementDashes" -> False]
]

numberOfQubits[CliffordUnitary[mat_?MatrixQ, ___?OptionQ]] := Length[mat] / 2

numberOfQubits[PauliMeasurement[_?VectorQ, {_, n_Integer}, ___]] = n
numberOfQubits[CliffordState[mat_?MatrixQ, ___]] := (Last[Dimensions @ mat] - 1)/2

numberOfQubits[CliffordUnitary[mat_?MatrixQ, ___?OptionQ]] := Length[mat] / 2

numberOfQubits[PauliMeasurement[vec_?VectorQ, ___?OptionQ]] := Length[vec] / 2

numberOfQubits[PauliDecoherence[vec_?VectorQ, ___?OptionQ]] := Length[vec] / 2

numberOfQubits[_] = Indeterminate

(**** </CliffordCircuit> ****)


(**** <RandomCliffordCircuit> ****)

RandomCliffordCircuit::usage = "RandomCliffordCircuit[{n, t}, p] generates a Clifford circuit of depth 3t on n qubits with alternating layers of randomly selected two-qubit Clifford unitary gates and single-qubit Pauli measurements, where each qubit is measured with probability p in the computational basis."

RandomCliffordCircuit[vol:{n_Integer, t_Integer}, p_?NumericQ] :=
RandomCliffordCircuit[vol:{n_Integer, t_Integer}, pp:(_?NumericQ|{_?NumericQ, _?NumericQ})] :=
CliffordCircuit @ Nest[
Append[
Join[#, randomCliffordUnitaryLayer @ n],
randomPauliMeasurementLayer[n, p]
randomPauliMeasurementLayer[n, pp]
]&,
{ CliffordState @ Ket @ Table[0, n] },
t
Expand All @@ -339,6 +407,22 @@ randomPauliMeasurementLayer[n_Integer, p_?NumericQ] := Module[
CliffordCircuit @ Map[PauliMeasurement[{0, 1}, #]&, kk]
]

randomPauliMeasurementLayer[n_Integer, {0|0., p_?NumericQ}] := Module[
{ kk = RandomPick[Range @ n, p],
mm = {{1, 0}, {0, 1}, {1, 1}} },
CliffordCircuit @ Map[PauliDecoherence[RandomChoice @ mm, #]&, kk]
]

randomPauliMeasurementLayer[n_Integer, pp:{_?NumericQ, _?NumericQ}] := Module[
{ kk = RandomPick[Range @ n, Total @ pp],
mm = PauliMeasurement[{0, 1}],
dc = PauliDecoherence /@ {{1, 0}, {0, 1}, {1, 1}},
pm = First[pp] / Total[pp] },
CliffordCircuit @ Table[
Append[If[RandomReal[] < pm, mm, RandomChoice @ dc], k],
{k, kk}
]
]

randomCliffordUnitaryLayer::usage = "randomPauliMeasurementLayer[n] generates a layer of random two-qubit Clifford unitaries on every pair of nearest-neighbor qubits among n qubits."

Expand Down Expand Up @@ -371,7 +455,11 @@ Options[RandomCliffordCircuitSimulate] = {
"Prefix" -> "RCC"
}

RandomCliffordCircuitSimulate[{n_Integer, t_Integer}, p_?NumericQ, OptionsPattern[]] := Module[
RandomCliffordCircuitSimulate[
{n_Integer, t_Integer},
pp:(_?NumericQ|{_?NumericQ, _?NumericQ}),
OptionsPattern[]
] := Module[
{ k = 0,
progress = 0,
save, data, qc, sn, sm },
Expand All @@ -380,7 +468,7 @@ RandomCliffordCircuitSimulate[{n_Integer, t_Integer}, p_?NumericQ, OptionsPatter
(* simulation *)
{sn, sm} = doAssureList[OptionValue["Samples"], 2];
data = Transpose @ Table[
qc = RandomCliffordCircuit[{n, t}, p];
qc = RandomCliffordCircuit[{n, t}, pp];
{ Table[
progress = ++k / (sn*sm);
FoldList[Construct[#2, #1]&, First @ qc],
Expand Down
6 changes: 6 additions & 0 deletions Q3/Kernel/Einstein.wl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ BeginPackage["Q3`"]

(**** <obsolete> ****)

{ GottesmanInner }; (* renamed *)
{ WickRandomCircuit }; (* renamed *)
{ WeightedLog }; (* renamed *)
{ PauliDecompose, PauliDecomposeRL, PauliCompose, PauliCompseRL }; (* renamed *)
Expand Down Expand Up @@ -177,6 +178,11 @@ Phase[qq:{__?QubitQ}, phi_, rest___] := (

(**** <obsolete> ****)

GottesmanInner[any___] := (
Message[Q3General::renamed, "GottesmanInner", "GottesmanDot"];
GottesmanDot[any]
)

WickRandomCircuit[any___] := (
Message[Q3General::renamed, "WickRandomCircuit", "RandomWickCircuitSimulate"];
RandomWickCircuitSimulate[any]
Expand Down
Loading

0 comments on commit 57183ef

Please sign in to comment.