HaldaneDMRGSkeleton.ipynb 8.43 KB
Newer Older
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tenpy.models.lattice import Lattice\n",
    "from tenpy.models.model import CouplingMPOModel\n",
    "from tenpy.networks.site import SpinSite\n",
    "from tenpy.tools.params import get_parameter\n",
    "from tenpy.algorithms import dmrg\n",
    "from tenpy.networks.mps import MPS\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import time\n",
    "import random"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Model Definition"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Create a ComplingMPOModel to describe the system.\n",
    "#The parameters are passed via model_params\n",
    "class Heisenberg(CouplingMPOModel):\n",
    "\n",
    "    def __init__(self,model_params):\n",
    "        CouplingMPOModel.__init__(self,model_params)\n",
    "    \n",
    "    def init_lattice(self, model_params):\n",
    "        #Here initialize the type of lattice considered\n",
    "        lattice = get_parameter(model_params, 'lattice', self.name, False)\n",
    "        return lattice\n",
    "        \n",
    "    def init_terms(self, model_params):\n",
    "        D= get_parameter(model_params, 'D', 0., self.name, True)\n",
    "        #Try to get also the J and lambda paramter in the same way\n",
    "        #J= ...\n",
    "        #lam= ...\n",
    "        \n",
    "        #Here implement the couplings of the chain\n",
    "        \n",
    "        #D term\n",
    "        self.add_onsite(D, 0, 'Sz Sz')     \n",
    "        \n",
    "        #Heisenberg interaction\n",
    "        self.add_coupling(J, 0, 'Sx', 0, 'Sx', 1,) \n",
    "        #Implement the remaining couplings for the Heisenberg exchange\n",
    "        #Have a look at the documentation of the function add_coupling()\n",
    "        #\n",
    "        #\n",
    "        \n",
    "        #Quadratic Heisenberg term, the one with lambda\n",
    "        #Implement this term yourself\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Phase diagram for $\\lambda=0$ and varying $D$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Define the model "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "L=2 #Chain length (2 for the iMPS)\n",
    "J=1 #Anitferromagnetic interaction\n",
    "lam=0 #Quadratic term\n",
    "Dmin=-1\n",
    "Dmax=2\n",
    "points=30\n",
    "d=np.linspace(Dmin,Dmax,points,endpoint=True) #Values considered for D\n",
    "\n",
    "#Definition of the lattice model\n",
    "#Define the local Hilbert space, have a look at the documentation of SpinSite\n",
    "#site=SpinSite(...)\n",
    "#Define the lattice by looking at the documentation of Lattice\n",
    "#Inifinite MPS requires periodic boundaries for the lattice\n",
    "#lat=Lattice(...) #We choose an infinite MPS  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Perform iDMRG"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "entEnt=[]\n",
    "entSp=[]\n",
    "stagMag=[]\n",
    "for D in d:\n",
    "    \n",
    "    #Define the paramters of the model\n",
    "    model_params={\n",
    "        'verbose':0,\n",
    "        'J':J,\n",
    "        'D':D,\n",
    "        'lambda':lam, \n",
    "        'lattice':lat \n",
    "    }\n",
    "\n",
    "    #Create the model\n",
    "    chain=Heisenberg(model_params)\n",
    "\n",
    "    #Define the paramters for the DMRG\n",
    "    dmrg_paramsGs = {\n",
    "        'trunc_params': {\n",
    "            'chi_max': 20 #Maximum bond dimension\n",
    "        },\n",
    "        'verbose': 1\n",
    "    }\n",
    "    \n",
    "    #Initialize the MPS with an arbitrary product state\n",
    "    product_state=['up',0] \n",
    "    #Have a look at the documentation MPS.from_product_state()\n",
    "    #psiGs=MPS.from_product_state(...)\n",
    "    \n",
    "    #Perform iDMRG\n",
    "    #Check documentation of dmrg.run\n",
    "    #info=dmrg.run(...)\n",
    "   \n",
    "    #Check documentation for expectation_value(). Which operator do you want to measure for magnetization?\n",
    "    #mag=psiGs.expectation_value(...) #Measure magnetization\n",
    "    #Implement function to compute staggered magnetization from mag\n",
    "    #staggered=...\n",
    "    stagMag.append(staggered) #Compute staggered magnetization\n",
    "    \n",
    "    #Check documentation of entanglement_spectrum() and compute it\n",
    "    #spectrum=...\n",
    "    entSp.append(spectrum[0])\n",
    "    \n",
    "    #Check documentation of entanglement_entropy() and compute it\n",
    "    #entropy=...\n",
    "    entEnt.append(entropy[0])\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Study staggered magnetization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.figure(figsize=(14,5))\n",
    "plt.plot(d,stagMag,'o',ls='-',c='k')\n",
    "plt.xlabel('D');\n",
    "plt.ylabel('Staggered magnetization');\n",
    "plt.axvspan(-1, -0.33, alpha=0.2, color='red')\n",
    "plt.axvspan(-0.33, 1, alpha=0.2, color='b')\n",
    "plt.axvspan(1, 2, alpha=0.2, color='g')\n",
    "plt.xlim(-1,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Study of the entanglement entropy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.figure(figsize=(14,5))\n",
    "plt.tight_layout()\n",
    "plt.plot(d,entEnt,'o',ls='-',c='k')\n",
    "plt.xlabel('D');\n",
    "plt.ylabel('Entanglement Entropy');\n",
    "plt.axvspan(-1, -0.33, alpha=0.2, color='red')\n",
    "plt.axvspan(-0.33, 1, alpha=0.2, color='b')\n",
    "plt.axvspan(1, 2, alpha=0.2, color='g')\n",
    "plt.xlim(-1,2);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Study of the entanglement spectrum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.figure(figsize=(14,5))\n",
    "plt.tight_layout()\n",
    "\n",
    "for i in range(len(d)): \n",
    "    for j in range(int(len(entSp[i])/2)):\n",
    "        if abs(entSp[i][2*j]-entSp[i][2*j+1])<1e-4:\n",
    "            plt.scatter(d[i]-0.01,entSp[i][2*j],c='k',s=50,marker='.')\n",
    "            plt.scatter(d[i]+0.01,entSp[i][2*j+1],c='k',s=50,marker='.')\n",
    "            plt.plot([d[i]-0.03,d[i]+0.03],[entSp[i][2*j],entSp[i][2*j]],c='k')\n",
    "        else:\n",
    "            plt.scatter(d[i],entSp[i][2*j],c='k',s=50,marker='.')\n",
    "            plt.scatter(d[i],entSp[i][2*j+1],c='k',s=50,marker='.')\n",
    "            plt.plot([d[i]-0.03,d[i]+0.03],[entSp[i][2*j],entSp[i][2*j]],c='k')\n",
    "            plt.plot([d[i]-0.03,d[i]+0.03],[entSp[i][2*j+1],entSp[i][2*j+1]],c='k')\n",
    "        \n",
    "plt.xlabel('D');\n",
    "plt.ylabel('Entanglement Spectrum');\n",
    "plt.axvspan(-1.1, -0.33, alpha=0.2, color='red')\n",
    "plt.axvspan(-0.33, 1, alpha=0.2, color='b')\n",
    "plt.axvspan(1, 2.1, alpha=0.2, color='g')\n",
    "plt.xlim(-1.1,2.1);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Phase diagram for $D=0$ and varying $\\lambda$ "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Do the same studies for this new situation."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}