I am attempting to evaluate a notebook with the following code via the command line
Z = PauliMatrix[3];
X = PauliMatrix[1];
Y = PauliMatrix[2];
id = PauliMatrix[0];
spinRaise = (X + I Y)/2;
spinLower = (X - I Y)/2;
pauli0 = 1/2 (id - (Z/(2 + 1)));
zero = {1, 0};
one = {0, 1};
\[Sigma]p = (1/2) (X + I Y);
\[Sigma]m = (1/2) (X - I Y);
\[Sigma]0 = (1/2) (id - Z/(2 n + 1));
\[Sigma]z = {{1, 0}, {0, -1}};
fragState = {{1/2, 1/2}, {1/2, 1/2}};
\[Rho]initialE = KroneckerProduct[fragState, fragState, fragState];
(*systemInitial={{1/4,1/4,0,0},{1/4,1/4,0,0},{0,0,0,0},{0,0,0,1/2}}*)
systemInitial = {{1/2, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1/4, 1/4}, {0,
0, 1/4, 1/4}};
(*systemInitial={{1/2,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,1/2}};*)
\
(*systemInitial={{1/3,0,0,0},{0,0,0,0},{0,0,1/3,1/3},{0,0,1/3,1/3}};*)
totalSysInitial =
KroneckerProduct[N[systemInitial], N[\[Rho]initialE]];
subsystem2Measure1 =
KroneckerProduct[{Cos[\[Theta]], Exp[I \[Phi]]*Sin[\[Theta]]},
Conjugate[{Cos[\[Theta]], Exp[I \[Phi]]*Sin[\[Theta]]}]];
subsystem2Measure2 =
KroneckerProduct[{Exp[-I \[Phi]]*Sin[\[Theta]], -Cos[\[Theta]]},
Conjugate[{Exp[-I \[Phi]]*Sin[\[Theta]], -Cos[\[Theta]]}]];
postMeasuredState1 =
dTraceSystem[
Flatten[Map[
KroneckerProduct @@ # &, {{subsystem2Measure1,
IdentityMatrix[2]}}], 1].systemInitial.Flatten[
Map[KroneckerProduct @@ # &, {{subsystem2Measure1,
IdentityMatrix[2]}}], 1], {1}, 2];
postMeasuredState2 =
dTraceSystem[
Flatten[Map[
KroneckerProduct @@ # &, {{subsystem2Measure2,
IdentityMatrix[2]}}], 1].systemInitial.Flatten[
Map[KroneckerProduct @@ # &, {{subsystem2Measure2,
IdentityMatrix[2]}}], 1], {1}, 2];
probMeasure1 =
Simplify[ComplexExpand[
Tr[Flatten[
Map[KroneckerProduct @@ # &, {{postMeasuredState1,
IdentityMatrix[2]}}], 1].systemInitial.Flatten[
Map[KroneckerProduct @@ # &, {{postMeasuredState1,
IdentityMatrix[2]}}], 1]]]];
probMeasure2 =
Simplify[ComplexExpand[
Tr[Flatten[
Map[KroneckerProduct @@ # &, {{postMeasuredState2,
IdentityMatrix[2]}}], 1].systemInitial.Flatten[
Map[KroneckerProduct @@ # &, {{postMeasuredState2,
IdentityMatrix[2]}}], 1]]]];
normPost1 = postMeasuredState1/probMeasure1;
normPost2 = postMeasuredState2/probMeasure2;
eigPost1 =
Eigenvalues[normPost1 + 10^-15 IdentityMatrix[Length[normPost1]]];
entropyPost1 =
Simplify[ComplexExpand[-Sum[
eigPost1[[j]] Log[2, eigPost1[[j]]], {j, 1, Length[eigPost1]}]]];
eigPost2 =
Eigenvalues[normPost2 + 10^-15 IdentityMatrix[Length[normPost2]]];
entropyPost2 =
Simplify[ComplexExpand[-Sum[
eigPost2[[j]] Log[2, eigPost2[[j]]], {j, 1, Length[eigPost2]}]]];
eigSub2 =
Eigenvalues[
dTraceSystem[sysInitial, {1}, 2] +
10^-15 IdentityMatrix[Length[dTraceSystem[sysInitial, {1}, 2]]]]
entropyPost2 =
Simplify[ComplexExpand[-Sum[
eigSub2[[j]] Log[2, eigSub2[[j]]], {j, 1, Length[eigSub2]}]]];
entropyPost2 -
NMinimize[{probMeasure1*entropyPost1 +
probMeasure2*entropyPost2, {\[Theta] \[Element] Reals, \[Theta] <=
2*\[Pi], \[Phi] \[Element] Reals,
0 <= \[Phi] <= 2*\[Pi]}}, {\[Theta], \[Phi]}]
I have tried math -script <notebook.nb, math -run < notebook.nb, the same again using a .wls file instead (yes, I changed the cells to initialisation cells), and also a .m file with math -run "<<notebook.m". Even changed the cells from Input to Code, per this post. There is no change to the files in any of these cases, and the runtime doesn't seem to be what it should be either. Sometime it's instant, others a few seconds. The only one that actually appears to output something to the command line, not even the file, is math -run < notebook.nb
All I want to do is take the notebook file, evaluate it via the command line, and have those evaluations appear in the notebook. I have looked at a myriad of posts, including this one, but I can't get it to work.
dTraceSystem
is not defined in your code. $\endgroup$