-
Notifications
You must be signed in to change notification settings - Fork 8
/
SpinChain.m
189 lines (186 loc) · 9.25 KB
/
SpinChain.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
(* ::Package:: *)
(* {{{ *) BeginPackage["SpinChain`",{"Carlos`", "Quantum`"}]
(* {{{ Primitives *)
ApplyMagnetickKick::usage = "ApplyMagnetickKick[state_, b_, Target_] or ApplyMagnetickKick[state_, b_]"
ApplyIsing::usage = "ApplyIsing[state_, J_, Position1_, Position2_]"
(* }}} *)
(* {{{ Full topologies*)
ApplyIsingTorus::usage="Se hace la topologia de un toro. Solo la parte de Ising"
ApplyIsingChain::usage="Se hace la topologia de una cadena. Solo la parte de Ising"
ApplyChain::usage="Se hace la topologia de una cadena."
ApplyInverseChain::usage="Se hace la topologia de una cadena pero hacia atras en el tiempo."
ApplyCommonEnvironment::usage="Se refiere a la topologia (a) del PRL de n-body Bell en PRA."
ApplyDephasingChain::usage="ApplyDephasingChain[psi0_, Delta_, Jenv_, benv_, Jinteraction_] Se hace la topologia de una cadena que solo hace dephasing"
ApplyChainStar::usage="ApplyChainStar[state_, Jenv_,Jint_, b_] Se hace la topologia de la estrella con el magnetic kick"
ApplyIsingStar::usage="Se hace la topologia de una estrella, solo la parte de Ising"
ApplyIsingStarEnvironment::usage="Se hace la topologia de una estrella, solo la parte de Ising, en el environment"
ApplyMagnetickKickStarEnvironment::usage="Se hace el kick pero solo en los qubits que son del environment"
ApplyIsingStarInteractionQubitEnvironment::usage="Se hace el kick pero solo la interaccion con el environment"
ApplyInomogeneousChain::usage="ApplyInomogeneousChain[state_?VectorQ, J_, J10_, b_] Se hace la cadena inhomogenea donde J10 indica la interaccion ising entre el primero y segundo qubit"
(* }}} *)
(* {{{ Explicit Matrices *)
IsingMatrix::usage="Get the matrix for the Ising Interaction Sigma_i Sigma_j, or for sum Sigma_i Sigma_j. In the first case, call as IsingMatrix[{IsingPosition1_Integer, IsingPosition2_Integer}, Qubits_Integer], and in the second, IsingMatrix[IsingPositions_List, Qubits_Integer]"
SpinChainIsingMatrix::usage="The Ising matrix that has to come in the IsingMatrix routine, for a perdic spin chain. Call as SpinChainIsingMatrix[Qubits_] "
SpinGridIsingMatrix::usage="The Ising matrix that has to come in the IsingMatrix routine, for a toric spin grid. Call as SpinGridIsingMatrix[{nx_, ny_}]"
MatrixPauliMagneticField::usage="Matrix corresponding to the hamiltonian b.sum sigma_j"
HamiltonianMagenitcChain::usage="Matrix Corresponding to the continuous Periodic ising spin chain with magnetic field"
HamiltonianMagenitcGrid::usage="Matrix Corresponding to the continuous toric ising grid chain with magnetic field"
ApplyMagnetickKickInhom::usage="ApplyMagnetickKickInhom[state_, b_, binhom_], Se aplica el magnetick kick donde binhom es el campo del spin 0"
ApplyIsingAllVsAll::usage"ApplyIsingAllVsAll[state_,J_]"
(* }}} *)
(* }}} *)
Begin["Private`"]
(* {{{ Primitives*)
(* {{{ *) ApplyMagnetickKick[state_?VectorQ, b_, Target_] :=
Module[{RotationMatrix, statenew, i, pos},
RotationMatrix = MatrixExp[-I MatrixPauliMagneticField[b,1]];
statenew = state;
For[i = 0, i < Length[state]/2, i++,
pos = {MergeTwoIntegers[0, i, Power[2, Target]],
MergeTwoIntegers[1, i, Power[2, Target]]} + 1;
statenew[[pos]] = RotationMatrix.statenew[[pos]];];
statenew]
(* }}} *)
(* {{{ *) ApplyMagnetickKick[state_?VectorQ, b_] :=
Module[{Qubits, statenew, QubitToAdress},
Qubits = Log[2, Length[state]];
statenew = state;
For[QubitToAdress = 0, QubitToAdress < Qubits, QubitToAdress++,
(*Print["en el loop QubitToAdress="<>ToString[QubitToAdress]];*)
statenew = ApplyMagnetickKick[statenew, b, QubitToAdress]];
statenew]
(* }}} *)
(* {{{ *) ApplyMagnetickKickStarEnvironment[state_?VectorQ, b_] :=
Module[{Qubits, statenew, QubitToAdress},
Qubits = Log[2, Length[state]];
statenew = state;
For[QubitToAdress = 1, QubitToAdress < Qubits, QubitToAdress++,
(*Print["en el loop QubitToAdress="<>ToString[QubitToAdress]];*)
statenew = ApplyMagnetickKick[statenew, b, QubitToAdress]];
statenew]
(* }}} *)
(* {{{ *) ApplyIsing[state_?VectorQ, J_, Position1_, Position2_] :=
Module[{scalar, i, statenew},
scalar = Exp[-I J];
statenew = state;
For[i = 0, i < Length[state], i++,
If[BitGet[i, Position1] == BitGet[i, Position2],
statenew[[i + 1]] = scalar statenew[[i + 1]],
statenew[[i + 1]] = Conjugate[scalar] statenew[[i + 1]]]];
statenew]
(* }}} *)
(* }}} *)
(* {{{ Full topologies *)
(* {{{ *) ApplyIsingChain[state_?VectorQ, J_] := Module[{Qubits, statenew, QubitToAdress,q},
Qubits = Log[2, Length[state]];
statenew=state;
For[q=0, q<Qubits-1, q++,
statenew = ApplyIsing[statenew, J, q, q+1];
];
statenew = ApplyIsing[statenew, J, 0 , Qubits-1];
statenew]
(* }}} *)
(* {{{ *) ApplyInverseChain[state_?VectorQ, J_, b_] := Module[{statenew},
statenew = state;
statenew = ApplyMagnetickKick[statenew, -b];
statenew = ApplyIsingChain[statenew, -J];
statenew ]
(* }}} *)
(* {{{ *) ApplyChain[state_?VectorQ, J_, b_] := Module[{statenew},
statenew = state;
statenew = ApplyIsingChain[statenew, J];
statenew = ApplyMagnetickKick[statenew, b];
statenew ]
(* }}} *)
(* {{{ *) ApplyCommonEnvironment[state_?VectorQ, b_, Jenv_, Jcoupling_] :=
Module[{statenew, J, qubits}, qubits = Log[2, Length[state]];
J = Table[Jenv, {qubits}];
J[[1]] = 0;
J[[2]] = Jcoupling;
J[[-1]] = Jcoupling;
ApplyIsing[ApplyMagnetickKick[state, b], J]]
(* }}} *)
(* {{{ *) ApplyDephasingChain[psi0_, Delta_, Jenv_, benv_, Jinteraction_] := Module[{statenew},
statenew = psi0;
(*U2 interno del env, las ising y la interaccion con el medio*)
statenew = ApplyIsingStar[statenew, Jenv, Jinteraction];
(* En el qubit solo se hace en direccion z, en el resto de la cadena
donde sea, para que sea integrable/caotica.
*)
statenew = ApplyMagnetickKickStarEnvironment[statenew, benv];
statenew = ApplyMagnetickKick[statenew, {0, 0, Delta/2}, 0];
statenew]
(* }}} *)
(* {{{ *) ApplyChainStar[state_?VectorQ, Jenv_,Jint_, b_] := Module[{statenew},
statenew = state;
statenew = ApplyIsingStar[statenew, Jenv, Jint];
statenew = ApplyMagnetickKick[statenew, b];
statenew ]
(* }}} *)
(* {{{ *) ApplyIsingStar[state_?VectorQ, Jenv_, Jint_] := Module[{Qubits, statenew, QubitToAdress, q},
Qubits = Log[2, Length[state]];
If[IntegerQ[Qubits]==False,Print["Error: The state does not correspond to a integer number of qubits"];Abort[]];
statenew=state;
statenew = ApplyIsingStarEnvironment[statenew, Jenv];
statenew = ApplyIsingStarInteractionQubitEnvironment[statenew, Jint];
statenew
];
(* }}} *)
(* {{{ *) ApplyIsingStarEnvironment[state_?VectorQ, Jenv_] := Module[{Qubits, statenew, QubitToAdress, q},
Qubits = Log[2, Length[state]];
If[IntegerQ[Qubits]==False,Print["Error: The state does not correspond to a integer number of qubits"];Abort[]];
statenew=state;
For[q=1, q<Qubits-1, q++, statenew = ApplyIsing[statenew, Jenv, q , q+1]; ];
statenew = ApplyIsing[statenew, Jenv, Qubits-1 , 1];
statenew
];
(* }}} *)
(* {{{ *) ApplyIsingStarInteractionQubitEnvironment[state_?VectorQ, Jint_] := Module[{Qubits, statenew, QubitToAdress, q},
Qubits = Log[2, Length[state]];
If[IntegerQ[Qubits]==False,Print["Error: The state does not correspond to a integer number of qubits"];Abort[]];
statenew=state;
For[q=1, q<Qubits, q++, statenew = ApplyIsing[statenew, Jint, 0 , q]; ];
statenew
];
(* }}} *)
(* {{{ *) ApplyInomogeneousChain[state_?VectorQ, J_, J10_, b_] := Module[{Qubits, statenew, QubitToAdress, q},
Qubits = Log[2, Length[state]];
If[IntegerQ[Qubits]==False,Print["Error: The state does not correspond to a integer number of qubits"];Abort[]];
statenew=state;
statenew=ApplyIsing[statenew, J10, 0, 1];
For[q=1, q<Qubits-1, q++,
statenew = ApplyIsing[statenew, J, q , q + 1];
];
statenew = ApplyIsing[statenew, J, 0 , Qubits-1];
statenew = ApplyMagnetickKick[statenew, b];
statenew
];
(* }}} *)
(* {{{ *) ApplyMagnetickKickInhom[state_, b_, binhom_] := Module[{finalstate, Qubits, i},
Qubits = Log[2, Length[state]];
finalstate = ApplyMagnetickKick[state, binhom, 0];
For[i = 1, i < Qubits, i++,
finalstate = ApplyMagnetickKick[finalstate, b, i]];
finalstate]
(* }}} *)
(* {{{ *)ApplyIsingAllVsAll[state_,J_]:=Module[{statenew, Qubits, i, j},
Qubits = Log[2, Length[state]];
statenew = state;
For[i=0,i<Qubits,i++,
For[j=1+i, j<Qubits,j++,
statenew=ApplyIsing[statenew,J,i,j];
]];
statenew]
(* }}} *)
(* }}} *)
(* {{{ Explicit Matrices *)
IsingMatrix[{IsingPosition1_Integer, IsingPosition2_Integer}, Qubits_Integer] := Pauli[Table[ If[l == Qubits - IsingPosition1 || l == Qubits - IsingPosition2, 3, 0], {l, Qubits}]];
IsingMatrix[IsingPositions_List, Qubits_Integer] := Module[{IsingPosition}, Sum[IsingMatrix[IsingPosition, Qubits], {IsingPosition, IsingPositions}]]
SpinChainIsingMatrix[Qubits_] := Table[{Mod[i, Qubits], Mod[i + 1, Qubits]}, {i, 0, Qubits - 1}]
SpinGridIsingMatrix[{nx_, ny_}] := Join[Table[{i, i + 1 + If[Mod[i, nx] == nx - 1, -nx, 0]}, {i, 0, nx ny - 1}], Table[{i, Mod[i + nx, nx ny]}, {i, 0, nx ny - 1}]]
MatrixPauliMagneticField[MagneticField_, Qubits_] := MagneticField.{SumSigmaX[Qubits], SumSigmaY[Qubits], SumSigmaZ[Qubits]}
HamiltonianMagenitcChain[MagneticField_, J_, Qubits_] := MatrixPauliMagneticField[MagneticField, Qubits] + J IsingMatrix[SpinChainIsingMatrix[Qubits], Qubits]
HamiltonianMagenitcGrid[MagneticField_, J_, {nx_, ny_}] := MatrixPauliMagneticField[MagneticField, nx ny] + J IsingMatrix[SpinGridIsingMatrix[{nx, ny}]]
(* }}} *)
End[]
EndPackage[]