Here's the problem. I'm trying to simulate a noisy Quantum Walk to obtain results similar to these, experimentally obtained.
I wrote my code, and I get results which are in accordance to what I expected.
The problem is, my evaluation time is too high. In the article they achieve a simulation of a 100-step QW, but I have to wait up to 5 hours just to get a 16-step result.
These are the time-consuming lines of code:
finalstate =
ParallelTable[
Expand[
Nest[TotalF,
state[1, 1, -1, j] state[2, 0, 1, j] -
state[1, 0, -1, j] state[2, 1, 1, j],
length]],
{j, 1, jmax}];
probabilities =
ParallelTable[
Table[{i, k,
Total[
Cases[Expand @ finalstate[[j]],
a___ state[1, _, i, _] state[2, _, k, _] :>
Abs[If[a === Null, 1, a]]^2]]},
{i, -length - 10, length + 10},
{k, -length - 10, length + 10}],
{j, 1, jmax}];
Where TotalF
is defined as such:
phase =
Table[
Table[{Exp[I*RandomReal[{0, ϕmax}]], Exp[I*RandomReal[{0, ϕmax}]]},
{i, -length - 10, length + 10}],
{j, 1, jmax}];
TotalF[state[index_, coin : (0 | 1), position_, conf_]] :=
Module[{row = position + length + 3, col = If[coin == 0, 1, 2]},
1/Sqrt[2] * phase[[conf, row, col]] *
(state[index, 0, position + 1, conf] +
If[coin == 0, 1, -1] state[index, 1, position - 1, conf])];
TotalF[u_ + v_] := TotalF[u] + TotalF[v];
TotalF[u_?(FreeQ[#, state] &) v_] := u TotalF[v];
TotalF[u_ v_] := TotalF[u] TotalF[v];
ϕmax
, length
and jmax
are constants.
Now, evaluating finalstate
takes 2.5 seconds for 8 steps and 680 seconds for 16 steps. Evaluating probabilities
takes 37 seconds for 8 steps and a lot more (about 5 hours, didn't try it with AbsoluteTiming) for 16 steps, so if I could at least speed up this last part (although if I want to achieve the 100-steps result I'd have to optimize the first one as well) it would be great.
I hope I made myself clear enough, I'm willing to provide extra information if needed.
phase
which is vital to the definition ofTotalF
. $\endgroup$