Skip to content

Commit

Permalink
Public release
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum-mob committed Jun 19, 2024
1 parent f086ac7 commit ee5dbb0
Show file tree
Hide file tree
Showing 31 changed files with 76,677 additions and 24,197 deletions.
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,373 changes: 1,373 additions & 0 deletions Q3/Documentation/English/ReferencePages/Symbols/CrossEntropy.nb

Large diffs are not rendered by default.

223 changes: 121 additions & 102 deletions Q3/Documentation/English/ReferencePages/Symbols/MutualInformation.nb

Large diffs are not rendered by default.

279 changes: 140 additions & 139 deletions Q3/Documentation/English/ReferencePages/Symbols/RenyiEntropy.nb

Large diffs are not rendered by default.

361 changes: 247 additions & 114 deletions Q3/Documentation/English/ReferencePages/Symbols/ShannonEntropy.nb

Large diffs are not rendered by default.

440 changes: 268 additions & 172 deletions Q3/Documentation/English/ReferencePages/Symbols/VonNeumannEntropy.nb

Large diffs are not rendered by default.

337 changes: 227 additions & 110 deletions Q3/Documentation/English/ReferencePages/Symbols/WeightedLog.nb

Large diffs are not rendered by default.

684 changes: 684 additions & 0 deletions Q3/Documentation/English/ReferencePages/Symbols/WickCircuit.nb

Large diffs are not rendered by default.

517 changes: 254 additions & 263 deletions Q3/Documentation/English/ReferencePages/Symbols/WickExpectation.nb

Large diffs are not rendered by default.

413 changes: 203 additions & 210 deletions Q3/Documentation/English/ReferencePages/Symbols/WickGreensFunction.nb

Large diffs are not rendered by default.

62,029 changes: 54,525 additions & 7,504 deletions Q3/Documentation/English/ReferencePages/Symbols/WickHistory.nb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

28,080 changes: 14,001 additions & 14,079 deletions Q3/Documentation/English/ReferencePages/Symbols/WickRandomCircuit.nb

Large diffs are not rendered by default.

4,485 changes: 3,814 additions & 671 deletions Q3/Documentation/English/ReferencePages/Symbols/WickState.nb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

192 changes: 96 additions & 96 deletions Q3/Documentation/English/ReferencePages/Symbols/WickUnitary.nb

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.
4 changes: 2 additions & 2 deletions Q3/Documentation/English/SearchIndex/5/indexMetadata.wl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<|"IndexedPaths" -> None, "Driver" -> "Lucene",
"CreationDate" -> DateObject[{2024, 6, 18, 20, 3,
24.119154`8.134937053097945}, "Instant", "Gregorian", 9.],
"CreationDate" -> DateObject[{2024, 6, 19, 19, 43,
34.452477`8.289795431347985}, "Instant", "Gregorian", 9.],
"Version" -> 5, "Synonyms" -> None, "Method" -> "BM25",
"Language" -> "English", "ContentFieldOptions" ->
<|"Title" -> <|"Stored" -> True, "Weight" -> 2|>,
Expand Down
Binary file modified Q3/Documentation/English/SearchIndex/5/segments_2
Binary file not shown.
Binary file modified Q3/Documentation/English/SpellIndex/_2p.cfs
Binary file not shown.
Binary file modified Q3/Documentation/English/SpellIndex/segments_5h
Binary file not shown.
473 changes: 218 additions & 255 deletions Q3/Documentation/English/Tutorials/ShannonEntropy.nb

Large diffs are not rendered by default.

14 changes: 5 additions & 9 deletions Q3/Kernel/Pauli.wl
Original file line number Diff line number Diff line change
Expand Up @@ -4746,11 +4746,11 @@ TraceDistance[a_, b_, ss:{___?SpeciesQ}] :=
Fidelity::usage = "Fidelity[\[Rho],\[Sigma]] returns the fidelity of the states \[Rho] and \[Sigma]. \[Rho] and \[Sigma] can take a vector (pure state), matrix (mixed state), ket expression (pure state), or opertor expression (mixed state).\nSee also ClassicalFidelity."

Fidelity[a_?MatrixQ, b_?MatrixQ] := With[
{c = MatrixPower[a, 1/2]},
{ c = MatrixPower[a, 1/2] },
Tr @ MatrixPower[c . b . c, 1/2]
]
]

Fidelity[v_?VectorQ, m_?MatrixQ] := Chop @ Sqrt[Conjugate[v] . m . v]
Fidelity[v_?VectorQ, m_?MatrixQ] := Sqrt[Conjugate[v] . m . v]

Fidelity[m_?MatrixQ, v_?VectorQ] := Fidelity[v, m]

Expand Down Expand Up @@ -4796,9 +4796,7 @@ probabilityQ[_] = False
(**** </Fidelity> *****)


(* ***************************************************************** *)
(* <GraphForm> *)
(* ***************************************************************** *)
(**** <GraphForm> ****)

Vertex::usage = "Vertex[a, b, ...] represents an interaction vertex.\nNot to be confused with Vertices in Graph or related functions."

Expand Down Expand Up @@ -5089,9 +5087,7 @@ chiralVertexRulesShort[ii_List, jj_List, spec:{__Rule}] := spec
chiralVertexRulesShort[ii_List, jj_List, spec:{row_, col_}] :=
Join[ vertexRulesShort[ii, row], vertexRulesShort[jj, col] ]

(* ***************************************************************** *)
(* </GraphForm> *)
(* ***************************************************************** *)
(**** </GraphForm> ****)


(***** <TridiagonalToeplitzMatrix> ****)
Expand Down
108 changes: 71 additions & 37 deletions Q3/Kernel/VonNeumann.wl
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,42 @@ BeginPackage["Q3`"]
{ VonNeumannEntropy, QuantumLog };
{ RenyiEntropy };

{ EntanglementEntropy };
{ EntanglementEntropy, CrossEntropy };

{ MutualInformation };


Begin["`Private`"]

(**** <WeightedLog> ****)

WeightedLog::usage = "WeightedLog[z] returns -z*Log[2, z], the weighted logarithm to base 2.\nWeightedLog[0] = 0.\nWeightedLog[p, q] returns -p*Log[2, q].\nWeightedLog[0, q] = 0.\nWeightedLog[p>0, 0] = \[Infinity]."

SetAttributes[WeightedLog, Listable]

WeightedLog[0] = 0

WeightedLog[z_] := 0 /; Chop[z] == 0

WeightedLog[z_?Positive] := -z * Log2[z]


WeightedLog[0, _] = 0

WeightedLog[_?Positive, 0] = Infinity

WeightedLog[p_?Positive, q_?Positive] := -p * Log2[q]

WeightedLog[_?ZeroQ] = 0

WeightedLog[z_] := -z * Log2[z]


ShannonEntropy::usage = "ShannonEntropy[{p1, p2, \[Ellipsis]}] returns the base 2 Shannon entropy of the probability distribution {p1, p2, \[Ellipsis]}.\nShannonEntropy[{p1, p2, \[Ellipsis]}, {q1, q2, \[Ellipsis]}] returns the relative entropy between the two probability distributions {p1, p2, \[Ellipsis]} and {q1, q2, \[Ellipsis]}."
WeightedLog[0, _] = 0

ShannonEntropy::noprb = "`` does not seem to be a probability distribution."
WeightedLog[_?ZeroQ, _] = 0

ShannonEntropy[pp_?VectorQ] :=
(Message[ShannonEntropy::noprb, pp]; 0) /;
Not @ AllTrue[Chop @ pp, NonNegative]
WeightedLog[_?Positive, _?ZeroQ] = Infinity

ShannonEntropy[pp_?VectorQ, qq_?VectorQ] :=
(Message[ShannonEntropy::noprb, pp]; 0) /;
Not @ AllTrue[Chop @ pp, NonNegative]
WeightedLog[_, _?ZeroQ] = ComplexInfinity

ShannonEntropy[pp_?VectorQ, qq_?VectorQ] :=
(Message[ShannonEntropy::noprb, qq]; 0) /;
Not @ AllTrue[Chop @ qq, NonNegative]
WeightedLog[p_, q_] := -p * Log2[q]

ShannonEntropy[pp_?VectorQ] := Total[WeightedLog @ pp]
(**** </WeightedLog> ****)

ShannonEntropy[pp_?VectorQ, qq_?VectorQ] :=
Total[WeightedLog[pp, qq]] - Total[WeightedLog[pp]]

(**** <QuantumLog> ****)

QuantumLog::usage = "QuantumLog[p, q] returns -Tr[p ** Log[2, q]] for the observables p and q.\nQuantumLog[p, q, {s1, s2, \[Ellipsis]}] assumes that states p and q, either density operators or ket vectors, are defined for the systems {s1, s2, \[Ellipsis]}.\nQuantumLog is a low-level mathematical function intended for the use in VonNeumannEntropy or related functions."
QuantumLog::usage = "QuantumLog[p, q] returns -Tr[p ** Log[2, q]] for the density operators p and q.\nQuantumLog[p, q, {s1, s2, \[Ellipsis]}] assumes that states p and q, either density operators or ket vectors, are defined for the systems {s1, s2, \[Ellipsis]}.\nQuantumLog is a low-level mathematical function intended for the use in VonNeumannEntropy or related functions."

QuantumLog[a_?VectorQ, b_?VectorQ] :=
If[Fidelity[a, b] == 1, 0, Infinity]
Expand All @@ -70,7 +55,7 @@ QuantumLog[a_?MatrixQ, b_?VectorQ] := Module[
vec = Flatten[vec];
If[ AllTrue[vec, NumericQ], vec = Normalize[vec] ];
If[ Fidelity[vec, b] == 1, 0, Infinity ]
]
]

QuantumLog[a_?VectorQ, b_?MatrixQ] := Module[
{val, vec},
Expand All @@ -79,28 +64,58 @@ QuantumLog[a_?VectorQ, b_?MatrixQ] := Module[
vec = Orthogonalize[vec]
];
Total @ WeightedLog[Abs[Conjugate[a] . Transpose[vec]]^2, val]
]
]

QuantumLog[a_?MatrixQ, b_?MatrixQ] := Module[
{ aval, avec,
bval, bvec },
{aval, avec} = Eigensystem[a];
If[ AllTrue[Flatten @ avec, NumericQ] && Not[UnitaryMatrixQ @ avec],
avec = Orthogonalize[avec]
];
];
{bval, bvec} = Eigensystem[b];
If[ AllTrue[Flatten @ bvec, NumericQ] && Not[UnitaryMatrixQ @ bvec],
bvec = Orthogonalize[bvec]
];
];
Total @ WeightedLog[aval . Abs[Conjugate[avec] . Transpose[bvec]]^2, bval]
]
]


QuantumLog[a_, b_, ss:{___?SpeciesQ}] :=
QuantumLog[Matrix[a, ss], Matrix[b, ss]]

QuantumLog[a_, b_] := QuantumLog[a, b, Agents @ {a, b}]

(**** </QuantumLog> ****)


(**** <ShannonEntropy> ****)

ShannonEntropy::usage = "ShannonEntropy[{p1, p2, \[Ellipsis]}] returns the base 2 Shannon entropy of the probability distribution {p1, p2, \[Ellipsis]}.\nShannonEntropy[{p1, p2, \[Ellipsis]}, {q1, q2, \[Ellipsis]}] returns the relative entropy between the two probability distributions {p1, p2, \[Ellipsis]} and {q1, q2, \[Ellipsis]}."

ShannonEntropy::noprb = "`` does not seem to be a probability distribution."

ShannonEntropy[pp_?VectorQ] :=
(Message[ShannonEntropy::noprb, pp]; 0) /;
Not @ AllTrue[Chop @ pp, NonNegative]

ShannonEntropy[pp_?VectorQ, qq_?VectorQ] :=
(Message[ShannonEntropy::noprb, pp]; 0) /;
Not @ AllTrue[Chop @ pp, NonNegative]

ShannonEntropy[pp_?VectorQ, qq_?VectorQ] :=
(Message[ShannonEntropy::noprb, qq]; 0) /;
Not @ AllTrue[Chop @ qq, NonNegative]

ShannonEntropy[pp_?VectorQ] := Total[WeightedLog @ pp]

ShannonEntropy[pp_?VectorQ, qq_?VectorQ] :=
Total[WeightedLog[pp, qq]] - Total[WeightedLog[pp]]

(**** </ShannonEntropy> ****)


(**** <VonNeumannEntropy> ****)

VonNeumannEntropy::usage = "VonNeumannEntropy[mat|vec] returns the base 2 VonNeumann entropy of the quantum state described by the density matrix 'mat' or vector 'vec'.\nVonNeumannEntropy[mat1, mat2] returns the quantum relative entropy of the mixed state mat1 with respect to mat2."

Expand All @@ -127,6 +142,8 @@ VonNeumannEntropy[rho_, sgm_, ss:{___?SpeciesQ}] :=
VonNeumannEntropy[rho_, sgm_] :=
VonNeumannEntropy[rho, sgm, Agents @ {rho, sgm}]

(**** </VonNeumannEntropy> ****)


(**** <MutualInformation> ****)

Expand Down Expand Up @@ -192,7 +209,8 @@ RenyiEntropy[a_?Positive, rho_?MatrixQ, sgm_?MatrixQ] :=
Dot[
MatrixPower[sgm, (1-a)/(2*a)], rho,
MatrixPower[sgm, (1-a)/(2*a)]
], a ] ] / (a - 1)
], a ]
] / (a - 1)


RenyiEntropy[a_, rho_] := RenyiEntropy[a, rho, Agents @ rho]
Expand Down Expand Up @@ -224,7 +242,7 @@ EntanglementEntropy::qubit = "`` does not seem to be a vector or matrix for qubi
EntanglementEntropy[rho:(_?VectorQ|_?MatrixQ), jj:{__Integer}] := (
Message[EntanglementEntropy::qubit, rho];
rho
) /; Not @ IntegerQ @ Log[2, Length @ rho]
) /; Not @ IntegerQ @ Log[2, Length @ rho]

EntanglementEntropy[rho:(_?VectorQ|_?MatrixQ), jj:{__Integer}] :=
EntanglementEntropy[rho, ConstantArray[2, Log[2, Length @ rho]], jj]
Expand All @@ -243,21 +261,37 @@ EntanglementEntropy[expr_, ss:{__?SpeciesQ}] := Module[
qq = Union[qq, rr];
jj = Flatten @ Map[FirstPosition[qq, #]&, Complement[qq, rr]];
VonNeumannEntropy @ PartialTrace[Matrix[expr, qq], Dimension[qq], jj]
]
]


EntanglementEntropy[expr_, jj:{__Integer}] := Module[
{ nn = Length @ FirstCase[expr, _Ket, Infinity] },
VonNeumannEntropy @ PartialTrace[Matrix[expr], Complement[Range @ nn, jj]]
] /; fPauliKetQ[expr]
] /; fPauliKetQ[expr]

EntanglementEntropy[expr_, jj:{__Integer}] := Module[
{ nn = Length @ FirstCase[expr, _Pauli, Infinity] },
VonNeumannEntropy @ PartialTrace[Matrix[expr], Complement[Range @ nn, jj]]
] /; Not @ FreeQ[expr, _Pauli]
] /; Not @ FreeQ[expr, _Pauli]

(**** </EntanglementEntropy> ****)


(**** <CrossEntropy> ****)

CrossEntropy::usage = "CrossEntropy[{p1, p2, \[Ellipsis]}, {q1, q2, \[Ellipsis]}] returns the classical cross-entropy between two probability distributions {p1, p2, \[Ellipsis]} and {q1, q2, \[Ellipsis]}.\nCrossEntropy[rho, sgm] returns the quantum cross-entropy between two density matrices rho and sgm."

CrossEntropy[pp_?VectorQ, qq_?VectorQ] := Total @ WeightedLog[pp, pp]

CrossEntropy[rho_?MatrixQ, sgm_?MatrixQ] := QuantumLog[rho, sgm]

CrossEntropy[rho_, sgm_] := With[
{ ss = Agents @ {rho, sgm} },
QuantumLog[Matrix[rho, ss], Matrix[sgm, ss]]
]

(**** </CrossEntropy> ****)

End[]

EndPackage[]
Loading

0 comments on commit ee5dbb0

Please sign in to comment.