├── .gitignore ├── Makefile ├── README.md ├── docs ├── Makefile ├── conf.py ├── finite_heisenberg.rst ├── heisenberg_model_for_four_spins.rst ├── heisenberg_model_for_two_spins.rst ├── how_to_use_the_tutorial.rst ├── hubbard.rst ├── index.rst ├── infinite_heisenberg.rst ├── playing_with_two_qbits.rst └── tfim.rst ├── solutions ├── heisenberg.py ├── heisenberg_for_four_spins.py ├── heisenberg_for_two_spins.py ├── hubbard.py ├── infinite_heisenberg.py ├── plot_entropies_obc.py ├── plot_from_file.py ├── tfim.py ├── two_qbit_entropies.dat └── two_qbit_system.py └── static ├── heisenberg_model.py ├── hubbard_helpers.py └── tfim_helpers.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[co] 2 | 3 | # Packages 4 | *.egg 5 | *.egg-info 6 | dist 7 | build 8 | eggs 9 | parts 10 | bin 11 | var 12 | sdist 13 | develop-eggs 14 | .installed.cfg 15 | 16 | # Installer logs 17 | pip-log.txt 18 | 19 | # Unit test / coverage reports 20 | .coverage 21 | .tox 22 | 23 | #Translations 24 | *.mo 25 | 26 | #Mr Developer 27 | .mr.developer.cfg 28 | 29 | #.DS_Store 30 | .DS_Store 31 | 32 | #MANIFEST 33 | MANIFEST 34 | 35 | # The build from sphinx for both the docs and the tutorial dirs 36 | docs/_build 37 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Users can install all the code, including the docs and all dependencies 3 | # needed, by doing: 4 | # 5 | # $ make install 6 | # 7 | .PHONY: install 8 | install: 9 | pip install -r requirements.txt 10 | # 11 | # The following are intended for developers only, you don't need to use 12 | # them if just want to work with the codes. Target 'all' builds a python 13 | # distribution in one shot, performing the tests, creating all the 14 | # documentation, making a requirement file for pip, and finally packing 15 | # all together in a python distribution that you can tag and upload to 16 | # github. 17 | # 18 | .PHONY: test requires doc dist 19 | test: 20 | nosetests tests 21 | nosetests --with-doctest --doctest-options='+ELLIPSIS' 22 | 23 | requires: 24 | pip freeze > requirements.txt 25 | 26 | doc: 27 | cd docs && make html && cd .. 28 | 29 | dist: 30 | python setup.py sdist --formats=gztar,zip 31 | 32 | .PHONY : all 33 | all: test doc requires dist 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | dmrg101 tutorial 2 | ================ 3 | 4 | Tutorial for the Taipei Density Matrix Renormalization Group School. 5 | 6 | This is the repository for the tutorial of the Taipei Density Matrix Renormalization Group School, and contains a few examples of problems on DMRG. To use the code here you need to install the dmrg101 Python package. 7 | 8 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | 44 | html: 45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 48 | 49 | dirhtml: 50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 51 | @echo 52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 53 | 54 | singlehtml: 55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 56 | @echo 57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 58 | 59 | pickle: 60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 61 | @echo 62 | @echo "Build finished; now you can process the pickle files." 63 | 64 | json: 65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 66 | @echo 67 | @echo "Build finished; now you can process the JSON files." 68 | 69 | htmlhelp: 70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 71 | @echo 72 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 73 | ".hhp project file in $(BUILDDIR)/htmlhelp." 74 | 75 | qthelp: 76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 77 | @echo 78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/DMRG101tutorial.qhcp" 81 | @echo "To view the help file:" 82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/DMRG101tutorial.qhc" 83 | 84 | devhelp: 85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 86 | @echo 87 | @echo "Build finished." 88 | @echo "To view the help file:" 89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/DMRG101tutorial" 90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/DMRG101tutorial" 91 | @echo "# devhelp" 92 | 93 | epub: 94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 95 | @echo 96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 97 | 98 | latex: 99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 100 | @echo 101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 103 | "(use \`make latexpdf' here to do that automatically)." 104 | 105 | latexpdf: 106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 107 | @echo "Running LaTeX files through pdflatex..." 108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 110 | 111 | text: 112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 113 | @echo 114 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 115 | 116 | man: 117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 118 | @echo 119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 120 | 121 | texinfo: 122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 123 | @echo 124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 125 | @echo "Run \`make' in that directory to run these through makeinfo" \ 126 | "(use \`make info' here to do that automatically)." 127 | 128 | info: 129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 130 | @echo "Running Texinfo files through makeinfo..." 131 | make -C $(BUILDDIR)/texinfo info 132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 133 | 134 | gettext: 135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 136 | @echo 137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 138 | 139 | changes: 140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 141 | @echo 142 | @echo "The overview file is in $(BUILDDIR)/changes." 143 | 144 | linkcheck: 145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 146 | @echo 147 | @echo "Link check complete; look for any errors in the above output " \ 148 | "or in $(BUILDDIR)/linkcheck/output.txt." 149 | 150 | doctest: 151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 152 | @echo "Testing of doctests in the sources finished, look at the " \ 153 | "results in $(BUILDDIR)/doctest/output.txt." 154 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # DMRG101 tutorial documentation build configuration file, created by 4 | # sphinx-quickstart on Sat Oct 27 17:36:30 2012. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | # -- General configuration ----------------------------------------------------- 22 | 23 | # If your documentation needs a minimal Sphinx version, state it here. 24 | #needs_sphinx = '1.0' 25 | 26 | # Add any Sphinx extension module names here, as strings. They can be extensions 27 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 28 | extensions = ['sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.pngmath', 'sphinx.ext.viewcode'] 29 | 30 | # Add any paths that contain templates here, relative to this directory. 31 | templates_path = ['_templates'] 32 | 33 | # The suffix of source filenames. 34 | source_suffix = '.rst' 35 | 36 | # The encoding of source files. 37 | #source_encoding = 'utf-8-sig' 38 | 39 | # The master toctree document. 40 | master_doc = 'index' 41 | 42 | # General information about the project. 43 | project = u'DMRG101 tutorial' 44 | copyright = u'2012, Ivan Gonzalez' 45 | 46 | # The version info for the project you're documenting, acts as replacement for 47 | # |version| and |release|, also used in various other places throughout the 48 | # built documents. 49 | # 50 | # The short X.Y version. 51 | version = '0.1' 52 | # The full version, including alpha/beta/rc tags. 53 | release = '0.1' 54 | 55 | # The language for content autogenerated by Sphinx. Refer to documentation 56 | # for a list of supported languages. 57 | #language = None 58 | 59 | # There are two options for replacing |today|: either, you set today to some 60 | # non-false value, then it is used: 61 | #today = '' 62 | # Else, today_fmt is used as the format for a strftime call. 63 | #today_fmt = '%B %d, %Y' 64 | 65 | # List of patterns, relative to source directory, that match files and 66 | # directories to ignore when looking for source files. 67 | exclude_patterns = ['_build'] 68 | 69 | # The reST default role (used for this markup: `text`) to use for all documents. 70 | #default_role = None 71 | 72 | # If true, '()' will be appended to :func: etc. cross-reference text. 73 | #add_function_parentheses = True 74 | 75 | # If true, the current module name will be prepended to all description 76 | # unit titles (such as .. function::). 77 | #add_module_names = True 78 | 79 | # If true, sectionauthor and moduleauthor directives will be shown in the 80 | # output. They are ignored by default. 81 | #show_authors = False 82 | 83 | # The name of the Pygments (syntax highlighting) style to use. 84 | pygments_style = 'sphinx' 85 | 86 | # A list of ignored prefixes for module index sorting. 87 | #modindex_common_prefix = [] 88 | 89 | 90 | # -- Options for HTML output --------------------------------------------------- 91 | 92 | # The theme to use for HTML and HTML Help pages. See the documentation for 93 | # a list of builtin themes. 94 | html_theme = 'default' 95 | 96 | # Theme options are theme-specific and customize the look and feel of a theme 97 | # further. For a list of options available for each theme, see the 98 | # documentation. 99 | #html_theme_options = {} 100 | 101 | # Add any paths that contain custom themes here, relative to this directory. 102 | #html_theme_path = [] 103 | 104 | # The name for this set of Sphinx documents. If None, it defaults to 105 | # " v documentation". 106 | #html_title = None 107 | 108 | # A shorter title for the navigation bar. Default is the same as html_title. 109 | #html_short_title = None 110 | 111 | # The name of an image file (relative to this directory) to place at the top 112 | # of the sidebar. 113 | #html_logo = None 114 | 115 | # The name of an image file (within the static path) to use as favicon of the 116 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 117 | # pixels large. 118 | #html_favicon = None 119 | 120 | # Add any paths that contain custom static files (such as style sheets) here, 121 | # relative to this directory. They are copied after the builtin static files, 122 | # so a file named "default.css" will overwrite the builtin "default.css". 123 | html_static_path = ['_static'] 124 | 125 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 126 | # using the given strftime format. 127 | #html_last_updated_fmt = '%b %d, %Y' 128 | 129 | # If true, SmartyPants will be used to convert quotes and dashes to 130 | # typographically correct entities. 131 | #html_use_smartypants = True 132 | 133 | # Custom sidebar templates, maps document names to template names. 134 | #html_sidebars = {} 135 | 136 | # Additional templates that should be rendered to pages, maps page names to 137 | # template names. 138 | #html_additional_pages = {} 139 | 140 | # If false, no module index is generated. 141 | #html_domain_indices = True 142 | 143 | # If false, no index is generated. 144 | #html_use_index = True 145 | 146 | # If true, the index is split into individual pages for each letter. 147 | #html_split_index = False 148 | 149 | # If true, links to the reST sources are added to the pages. 150 | #html_show_sourcelink = True 151 | 152 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 153 | #html_show_sphinx = True 154 | 155 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 156 | #html_show_copyright = True 157 | 158 | # If true, an OpenSearch description file will be output, and all pages will 159 | # contain a tag referring to it. The value of this option must be the 160 | # base URL from which the finished HTML is served. 161 | #html_use_opensearch = '' 162 | 163 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 164 | #html_file_suffix = None 165 | 166 | # Output file base name for HTML help builder. 167 | htmlhelp_basename = 'DMRG101tutorialdoc' 168 | 169 | 170 | # -- Options for LaTeX output -------------------------------------------------- 171 | 172 | latex_elements = { 173 | # The paper size ('letterpaper' or 'a4paper'). 174 | #'papersize': 'letterpaper', 175 | 176 | # The font size ('10pt', '11pt' or '12pt'). 177 | #'pointsize': '10pt', 178 | 179 | # Additional stuff for the LaTeX preamble. 180 | #'preamble': '', 181 | } 182 | 183 | # Grouping the document tree into LaTeX files. List of tuples 184 | # (source start file, target name, title, author, documentclass [howto/manual]). 185 | latex_documents = [ 186 | ('index', 'DMRG101tutorial.tex', u'DMRG101 tutorial Documentation', 187 | u'Ivan Gonzalez', 'manual'), 188 | ] 189 | 190 | # The name of an image file (relative to this directory) to place at the top of 191 | # the title page. 192 | #latex_logo = None 193 | 194 | # For "manual" documents, if this is true, then toplevel headings are parts, 195 | # not chapters. 196 | #latex_use_parts = False 197 | 198 | # If true, show page references after internal links. 199 | #latex_show_pagerefs = False 200 | 201 | # If true, show URL addresses after external links. 202 | #latex_show_urls = False 203 | 204 | # Documents to append as an appendix to all manuals. 205 | #latex_appendices = [] 206 | 207 | # If false, no module index is generated. 208 | #latex_domain_indices = True 209 | 210 | 211 | # -- Options for manual page output -------------------------------------------- 212 | 213 | # One entry per manual page. List of tuples 214 | # (source start file, name, description, authors, manual section). 215 | man_pages = [ 216 | ('index', 'dmrg101tutorial', u'DMRG101 tutorial Documentation', 217 | [u'Ivan Gonzalez'], 1) 218 | ] 219 | 220 | # If true, show URL addresses after external links. 221 | #man_show_urls = False 222 | 223 | 224 | # -- Options for Texinfo output ------------------------------------------------ 225 | 226 | # Grouping the document tree into Texinfo files. List of tuples 227 | # (source start file, target name, title, author, 228 | # dir menu entry, description, category) 229 | texinfo_documents = [ 230 | ('index', 'DMRG101tutorial', u'DMRG101 tutorial Documentation', 231 | u'Ivan Gonzalez', 'DMRG101tutorial', 'One line description of project.', 232 | 'Miscellaneous'), 233 | ] 234 | 235 | # Documents to append as an appendix to all manuals. 236 | #texinfo_appendices = [] 237 | 238 | # If false, no module index is generated. 239 | #texinfo_domain_indices = True 240 | 241 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 242 | #texinfo_show_urls = 'footnote' 243 | 244 | 245 | # -- Options for Epub output --------------------------------------------------- 246 | 247 | # Bibliographic Dublin Core info. 248 | epub_title = u'DMRG101 tutorial' 249 | epub_author = u'Ivan Gonzalez' 250 | epub_publisher = u'Ivan Gonzalez' 251 | epub_copyright = u'2012, Ivan Gonzalez' 252 | 253 | # The language of the text. It defaults to the language option 254 | # or en if the language is not set. 255 | #epub_language = '' 256 | 257 | # The scheme of the identifier. Typical schemes are ISBN or URL. 258 | #epub_scheme = '' 259 | 260 | # The unique identifier of the text. This can be a ISBN number 261 | # or the project homepage. 262 | #epub_identifier = '' 263 | 264 | # A unique identification for the text. 265 | #epub_uid = '' 266 | 267 | # A tuple containing the cover image and cover page html template filenames. 268 | #epub_cover = () 269 | 270 | # HTML files that should be inserted before the pages created by sphinx. 271 | # The format is a list of tuples containing the path and title. 272 | #epub_pre_files = [] 273 | 274 | # HTML files shat should be inserted after the pages created by sphinx. 275 | # The format is a list of tuples containing the path and title. 276 | #epub_post_files = [] 277 | 278 | # A list of files that should not be packed into the epub file. 279 | #epub_exclude_files = [] 280 | 281 | # The depth of the table of contents in toc.ncx. 282 | #epub_tocdepth = 3 283 | 284 | # Allow duplicate toc entries. 285 | #epub_tocdup = True 286 | 287 | 288 | # Example configuration for intersphinx: refer to the Python standard library. 289 | intersphinx_mapping = {'http://docs.python.org/': None} 290 | -------------------------------------------------------------------------------- /docs/finite_heisenberg.rst: -------------------------------------------------------------------------------- 1 | Finite DMRG algorithm for the Heisenberg chain 2 | ============================================== 3 | 4 | The goal of this exercise is to implement the finite version of the DMRG 5 | algorithm for the antiferromagnetic Heisenberg chain of spins one-half. 6 | 7 | The Hamiltonian that we will build is the antiferromagnetic Heisenberg 8 | model: 9 | 10 | .. math:: 11 | H=\sum_{i}\vec{S}_{i}\cdot\vec{S}_{i+1}= 12 | \sum_{i}\left[S^{z}_{i}S^{z}_{i+1}+ 13 | \frac{1}{2}\left(S^{\dagger}_{i}S^{-}_{i+1}+ 14 | S^{-}_{i}S^{\dagger}_{i+1}\right)\right] 15 | 16 | 17 | where :math:`\vec{S}_{i}=\vec{\sigma}_{i}/2` are the spin operators, 18 | :math:`\sigma_{i}` are the Pauli matrices, and 19 | :math:`S^{\pm}_{i}=S^{x}_{i}\pm i S^{y}_{i}`. 20 | 21 | Exercise 22 | -------- 23 | 24 | Calculate the ground state energy of the antiferromagnetic Heisenberg 25 | model for a chain of spins :math:`S=1/2` using the finite version of the 26 | DMRG algorithm. You should be able to pass the number of sites of the 27 | chain, the number of states kept during the DMRG truncation, and the 28 | number of sweeps during the finite algorithm as parameters. The output 29 | should be the energy per site, entanglement entropy and, truncation error 30 | at each step of the algorithm. You could: 31 | 32 | - make a plot of the energy per site versus system size to see how 33 | converges. The relative error in energy is given by the truncation 34 | error. In a given sweep, where is the energy best approximate to the 35 | actual value? 36 | - for the same size you chose in the last exercise, repeat the same 37 | extrapolation for the energy to zero truncation error. Compare this with 38 | the exact value for a finite size given by the Bethe Anstatz, and with 39 | the results you 40 | - find the scaling of the entanglement entropy for the Heisenberg model. 41 | The entanglement entropy for open boundary conditions scales as 42 | :math:`S(x)=\frac{c}{6}\log\left[\frac{2L}{\pi}sin\left(\frac{\pi 43 | x}{L}\right)\right]`, where :math:`c, x, L` are the central charge of 44 | the model; the size of the part of the chain you keep in the reduced 45 | density matrix, and the size of the whole chain, respectively. 46 | 47 | Solution 48 | -------- 49 | 50 | This is the first implementation of a full DMRG algorithm in the tutorial. 51 | The full DMRG algorithm involves doing first the infinite version of the 52 | DMRG algorithm, which we cover in the last exercise, and then a number of 53 | sweeps keeping the size of the system fixed. The latter are called finite 54 | algorithm sweeps. During the finite sweeps, one block is growing exactly 55 | as during the infinite version of the algorithm, while the other has to 56 | shrink to keep the system size constant. As the truncation in DMRG can 57 | take you only for larger block sizes, you have to use an old version of 58 | the block that is shrinking. This is done saving each of the block when 59 | they grow, so you simply pull the right one from a list of old blocks. 60 | 61 | To being able to reuse this code latter we are going to put all the stuff 62 | related to the AF Heisenberg model in a new object. In this way it's 63 | easier to switch between different models. This bring nothing new to the 64 | algorithm itself. The file with the model is something like this: 65 | 66 | .. literalinclude:: ../static/heisenberg_model.py 67 | 68 | The real changes are in the functions to grow the blocks, and perform the 69 | infinite and finite DMRG steps. As was said above these functions are 70 | included not in the main file, as in the previous exercise, but in the 71 | `System` class. Apart from the minor changes introduced by this change in 72 | the interface, you show pay attention to the changes in the functions 73 | themselves. 74 | 75 | The first change we will make is to grow the system asymmetrically. This 76 | means that during the infinite version of the algorithm we keep on block 77 | (the right one) one-site long. You do this simply but not growing the 78 | right block: 79 | 80 | .. literalinclude:: ../static/system.py 81 | :pyobject: System.infinite_dmrg_step 82 | 83 | Next thing is to write the function to implement the DMRG step during the 84 | finite algorithm. The only difference with the infinite version is that 85 | now in addition to grow one of the blocks, you set the other one to be the 86 | one with the proper size in a previous sweep. 87 | 88 | .. literalinclude:: ../static/system.py 89 | :pyobject: System.finite_dmrg_step 90 | 91 | During the finite sweeps you want to increase the number of states that 92 | you keep. A good way to do that is increasing them linearly at each 93 | half-sweep from the number of states at the end of the infinite algorithm 94 | to the number you want to keep at the end. 95 | 96 | The rest is just doing a loop for the sweeps, each finite sweep comprising 97 | a "half-sweep" to the left and a "half-sweep" to the right, and being sure 98 | that during the finite algorithm the size of the system is constant. The 99 | implementation (with some extras for saving the results and the rest) 100 | looks like this: 101 | 102 | .. literalinclude:: ../solutions/heisenberg.py 103 | :pyobject: main 104 | 105 | See :download:`a full implementation of the above code 106 | <../solutions/heisenberg.py>`. To learn how to run this code you 107 | can use: 108 | :: 109 | 110 | $ ./tutorial/solutions/heisenberg.py --help 111 | Implements the full DMRG algorithm for the S=1/2 AF Heisenberg. 112 | 113 | Calculates the ground state energy and wavefunction for the 114 | antiferromagnetic Heisenberg model for a chain of spin one-half. The 115 | calculation of the ground state is done using the full DMRG algorithm, 116 | i.e. first the infinite algorithm, and then doing sweeps for convergence 117 | with the finite algorithm. 118 | 119 | Usage: 120 | heisenberg.py (-m= -n= -s=) [--dir=DIR -o=FILE] 121 | heisenberg.py -h | --help 122 | 123 | Options: 124 | -h --help Shows this screen. 125 | -n Number of sites of the chain. 126 | -m Number of states kept. 127 | -s Number of sweeps in the finite algorithm. 128 | -o --output=FILE Ouput file [default: heisenberg.dat] 129 | --dir=DIR Ouput directory [default: ./] 130 | 131 | You can use :download:`this script <../solutions/plot_entropies_obc.py>` 132 | to plot the entropies and fit them to the result from conformal field 133 | theory. 134 | -------------------------------------------------------------------------------- /docs/heisenberg_model_for_four_spins.rst: -------------------------------------------------------------------------------- 1 | Heisenberg model for four spins 2 | =============================== 3 | 4 | The goal of this exercise is to build a Hamiltonian for the four spin 5 | system, and calculate its ground state. The difference with the previous 6 | exercise is that we will use the same setup as for the DMRG algorithm. 7 | This means that we will build a chain as a block-site-site-block system, 8 | where the left-most spin will be the left block, the two central spins 9 | will be the single sites, and the right-most spin will be the right block. 10 | 11 | Again, the Hamiltonian that we will build is the antiferromagnetic Heisenberg 12 | model: 13 | 14 | .. math:: 15 | H=\sum_{i}\vec{S}_{i}\cdot\vec{S}_{i+1}= 16 | \sum_{i}\left[S^{z}_{i}S^{z}_{i+1}+ 17 | \frac{1}{2}\left(S^{\dagger}_{i}S^{-}_{i+1}+ 18 | S^{-}_{i}S^{\dagger}_{i+1}\right)\right] 19 | 20 | where :math:`\vec{S}_{i}=\vec{\sigma}_{i}/2` are the spin operators, 21 | :math:`\sigma_{i}` are the Pauli matrices, and 22 | :math:`S^{\pm}_{i}=S^{x}_{i}\pm i S^{y}_{i}`. 23 | 24 | Exercise 25 | -------- 26 | 27 | Calculate the ground state (energy and wavefunction) of the 28 | antiferromagnetic Heisenberg model for a system of four spins one-half. 29 | 30 | Solution 31 | -------- 32 | 33 | You can use the `System` class to create the four spin chain, and set the 34 | system Hamiltonian to the antiferromagnetic Heisenberg model. To do that 35 | you add the terms to the system Hamiltonian, and to add a term you just 36 | have to specify which operator acts in each of the parts: left block, left 37 | site, right site, and right block, using the name of the operator. You can 38 | specify a parameter if you need to with a fifth optional argument. This 39 | function does that: 40 | 41 | .. literalinclude:: ../solutions/heisenberg_for_four_spins.py 42 | :pyobject: set_hamiltonian_to_AF_Heisenberg 43 | 44 | The remaining is calling again to the Lanczos solver to get the ground 45 | state energy and wavefunction. You can use a convenience function in the 46 | `System` class. Putting everything together you end up with something like 47 | this: 48 | 49 | .. literalinclude:: ../solutions/heisenberg_for_four_spins.py 50 | :pyobject: main 51 | 52 | See :download:`a full implementation of the above code 53 | <../solutions/heisenberg_for_four_spins.py>`. If you run that code you should 54 | get: 55 | :: 56 | 57 | $ ./solutions/heisenberg_for_four_spins.py 58 | The ground state energy is -1.616025. 59 | The ground state wavefunction is: 60 | [[ ... 61 | 62 | ------------------------------------------------------------------------------ 63 | -------------------------------------------------------------------------------- /docs/heisenberg_model_for_two_spins.rst: -------------------------------------------------------------------------------- 1 | Heisenberg model for two spins 2 | ============================== 3 | 4 | The goal of this exercise is to build a Hamiltonian for the two spin 5 | system in the previous exercise, and calculate its ground state. Again the 6 | purpose is just to get you familiar with the code. 7 | 8 | The Hamiltonian that we will build is the antiferromagnetic Heisenberg 9 | model, which reads like: 10 | 11 | .. math:: 12 | H=\vec{S}_{1}\cdot\vec{S}_{2}=S^{z}_{1}S^{z}_{2}+ 13 | \frac{1}{2}\left(S^{\dagger}_{1}S^{-}_{2}+ 14 | S^{-}_{1}S^{\dagger}_{2}\right) 15 | 16 | 17 | where :math:`\vec{S}_{i}=\vec{\sigma}_{i}/2` are the spin operators, 18 | :math:`\sigma_{i}` are the Pauli matrices, and 19 | :math:`S^{\pm}_{i}=S^{x}_{i}\pm i S^{y}_{i}`. 20 | 21 | Exercise 22 | -------- 23 | 24 | Calculate the ground state (energy and wavefunction) of the 25 | antiferromagentic Heisenberg model for a system of two spins one-half. 26 | 27 | Hint 28 | ---- 29 | 30 | Two things. First, remember that the wavefunction in the code is written 31 | as a matrix, where the left (row) indexes correspond to the left system, 32 | i.e. the left spin, and where the right (colum) indexes correspond to the 33 | right system, i.e. the right spin. 34 | 35 | Second, once we have build up the Hamiltonian we will use the `Lanczos 36 | algorithm `_ to get its 37 | ground state. This is a whole beast on his own, and we are not going to 38 | enter much into it. Just believe that it works as described. [#]_ 39 | 40 | Solution 41 | -------- 42 | 43 | The first thing we need is the spin operators. For this you can create a 44 | `SpinOneHalfSite` which is an object in dmrg101 with the operators you 45 | need build in: :: 46 | 47 | >>> from dmrg101.core.Sites import SpinOneHalfSite 48 | >>> left_spin = SpinOneHalfSite() 49 | >>> right_spin = SpinOneHalfSite() 50 | >>> # check all it's what you expected 51 | >>> print left_spin.operators['s_z'] 52 | [[-0.5. 0. ] 53 | [ 0. 0.5]] 54 | >>> print left_spin.operators['s_p'] 55 | [[ 0. 0.] 56 | [ 1. 0.]] 57 | >>> print left_spin.operators['s_m'] 58 | [[ 0. 1.] 59 | [ 0. 0.]] 60 | 61 | Now we have to build the Hamiltonian operator, keeping in mind the 62 | wavefunction is a matrix. There is an `operator` object in the code which 63 | takes care of this issue. Basically you create a new operator by creating 64 | first a blank operator and adding to it terms. To add a term you have to 65 | specify which is the operator acting on the left system, and which on the 66 | right system. The following function does that: 67 | 68 | .. literalinclude:: ../solutions/heisenberg_for_two_spins.py 69 | :pyobject: build_HAF_hamiltonian_for_two_spins 70 | 71 | Then it's just a matter to call the Lanczos subroutine to solve for the 72 | ground state and put everything together: 73 | 74 | .. literalinclude:: ../solutions/heisenberg_for_two_spins.py 75 | :pyobject: main 76 | 77 | See :download:`a full implementation of the above code 78 | <../solutions/heisenberg_for_two_spins.py>`. If you run that code you should 79 | get something like this: 80 | :: 81 | 82 | $ ./solutions/heisenberg_for_two_spins.py 83 | The ground state energy is -0.75 84 | The ground state wavefunction is: 85 | [[ 0. 0.70710678] 86 | [ 0.70710678 0. ]] 87 | 88 | ------------------------------------------------------------------------------ 89 | 90 | .. [#] The two spin system is small enough to be solve by exact 91 | diagonalization, i.e. just diagonalizing fully the Hamiltonian matrix. 92 | We use Lanczos here, because the larger systems that we will find 93 | later cannot be fully diagonalized, and you're force to stick with 94 | Lanczos or a similar method. 95 | -------------------------------------------------------------------------------- /docs/how_to_use_the_tutorial.rst: -------------------------------------------------------------------------------- 1 | How to use the tutorial 2 | ======================= 3 | 4 | Each of the exercises is more or less self-content, but ideally you will 5 | do them in order as the last exercises require more familiarity with the 6 | code. 7 | 8 | You are supposed to write some code on your own and then run it to 9 | finish the exercises. Obviously you don't have to write the whole code on 10 | your own, you are supposed to use the functions that we already coded 11 | within the dmrg101 package. As each of you have a different set of 12 | programming skills, the amount of guidance you need to complete the 13 | exercises will be different in each case. 14 | 15 | We provide a complete implementation of the code needed for each exercise, 16 | so nobody gets stuck in the programming part. Just find your pace and use 17 | the solution and hints as much as you need it. Remember that this is not a 18 | course on programming, but on physics, so focus in understanding the 19 | algorithm and the physical ideas behind it. 20 | 21 | If you installed dmrg101, you have a copy of all the solution for the 22 | exercises. Just check now that everything is there: :: 23 | 24 | $ cd tutorial 25 | $ ls 26 | 27 | We recommmend that you don't overwrite these files, so you have always a 28 | code for the exercise that works. If you want to use the solution as an 29 | starting point for you own coding, just make a new folder and copy the 30 | solution in there. 31 | 32 | *Let's start!* 33 | -------------------------------------------------------------------------------- /docs/hubbard.rst: -------------------------------------------------------------------------------- 1 | DMRG algorithm for the Hubbard model 2 | ==================================== 3 | 4 | The goal of this exercise is to implement the finite version of the DMRG 5 | algorithm for the one-dimensional Hubbard model. The Hamiltonian is: 6 | 7 | .. math:: 8 | H=-t\sum_{i, \sigma}\left(c^{\dagger}_{i, \sigma}c_{i, \sigma} + h.c.\right)+ 9 | U\sum_{i}n_{i, \uparrow}n_{i, \downarrow} 10 | 11 | where :math:`c_{i, \sigma}` is the destruction operator for an electron at 12 | site :math:`i` and spin :math:`\sigma`, and 13 | :math:`n_{i, \sigma}=c^{\dagger}_{i, \sigma}c_{i, \sigma}`. 14 | 15 | Exercise 16 | -------- 17 | 18 | Decide by yourself what you want to calculate with this code. 19 | 20 | Solution 21 | -------- 22 | 23 | The implementation is straighforward now. You have to write a model class 24 | which with the functions to set the Hamiltonian, block Hamiltonians, and 25 | operators to update. A possible implementation is: 26 | 27 | .. literalinclude:: ../static/hubbard_helpers.py 28 | :pyobject: HubbardModel 29 | 30 | You also have to write a single site class for the 31 | electronic site, providing operators defined in the Hilbert space of the 32 | site: 33 | 34 | .. literalinclude:: ../static/hubbard_helpers.py 35 | :pyobject: ElectronicSite 36 | 37 | The implementation of the DMRG algorithm itself has only minor changes 38 | with respect what you have done before: 39 | 40 | .. literalinclude:: ../solutions/hubbard.py 41 | :pyobject: main 42 | 43 | See :download:`a full implementation of the above code 44 | <../solutions/tfim.py>`. To learn how to run this code you 45 | can use: 46 | :: 47 | 48 | $ ./solutions/tfim.py --help 49 | Implements the full DMRG algorithm for the S=1/2 TFIM. 50 | 51 | Calculates the ground state energy and wavefunction for the 52 | Ising model in a transverse field for a chain of spin one-half. The 53 | calculation of the ground state is done using the full DMRG algorithm, 54 | i.e. first the infinite algorithm, and then doing sweeps for 55 | convergence with the finite algorithm. 56 | 57 | Usage: 58 | tfim.py (-m= -n= -s= -H=) [--dir=DIR -o=FILE] 59 | tfim.py -h | --help 60 | 61 | Options: 62 | -h --help Shows this screen. 63 | -n Number of sites of the chain. 64 | -m Number of states kept. 65 | -s Number of sweeps in the finite algorithm. 66 | -H Magnetic field in units of coupling between spins. 67 | -o --output=FILE Ouput file [default: tfim.dat] 68 | --dir=DIR Ouput directory [default: ./] 69 | 70 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. DMRG101 tutorial documentation master file, created by 2 | sphinx-quickstart on Sat Oct 27 17:36:30 2012. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to DMRG101 tutorial's pages! 7 | ==================================== 8 | 9 | These pages contain a few exercises to be used with the dmrg101 code. The 10 | exercises are the ones used for the hands-on tutorial of the `Taipei 11 | Density Matrix Renormalization Group Winter School 12 | `_. We hope that even those 13 | that could not attend to the School can find this useful to learn some 14 | basics about the `Density Matrix 15 | Renormalization Group algorithm 16 | `_ 17 | (DMRG). 18 | 19 | Some of the exercises here are adapted from a similar tutorial by Adrian 20 | Feiguin, published in `Lectures on the Physics of Strongly Correlated 21 | Systems XV `_. 22 | 23 | This page is only about the tutorial itself. If you need information about 24 | the drmg101 code, check out the `dmrg101 documentation 25 | `_. 26 | 27 | There is also a `PDF version of this webpage 28 | `_. 29 | 30 | This tutorial is released under a CC BY-NC-SA 3.0 license. The dmrg101 31 | code is released under a MIT license. 32 | 33 | Warmup 34 | ------ 35 | 36 | .. toctree:: 37 | :maxdepth: 1 38 | 39 | how_to_use_the_tutorial 40 | playing_with_two_qbits 41 | heisenberg_model_for_two_spins 42 | heisenberg_model_for_four_spins 43 | 44 | Spin systems 45 | ------------ 46 | 47 | .. toctree:: 48 | :maxdepth: 1 49 | 50 | infinite_heisenberg 51 | finite_heisenberg 52 | tfim 53 | 54 | Electronic systems 55 | ------------------ 56 | 57 | .. toctree:: 58 | :maxdepth: 1 59 | 60 | hubbard 61 | 62 | .. Time dependence 63 | --------------- 64 | .. toctree:: 65 | :maxdepth: 1 66 | 67 | .. spin_charge_separation 68 | -------------------------------------------------------------------------------- /docs/infinite_heisenberg.rst: -------------------------------------------------------------------------------- 1 | Infinite DMRG algorithm for the Heisenberg chain 2 | ================================================ 3 | 4 | The goal of this exercise is to implement the infinite version of the DMRG 5 | algorithm for the antiferromagnetic Heisenberg chain of spins one-half. 6 | 7 | The Hamiltonian that we will build is the antiferromagnetic Heisenberg 8 | model: 9 | 10 | .. math:: 11 | H=\sum_{i}\vec{S}_{i}\cdot\vec{S}_{i+1}= 12 | \sum_{i}\left[S^{z}_{i}S^{z}_{i+1}+ 13 | \frac{1}{2}\left(S^{\dagger}_{i}S^{-}_{i+1}+ 14 | S^{-}_{i}S^{\dagger}_{i+1}\right)\right] 15 | 16 | 17 | where :math:`\vec{S}_{i}=\vec{\sigma}_{i}/2` are the spin operators, 18 | :math:`\sigma_{i}` are the Pauli matrices, and 19 | :math:`S^{\pm}_{i}=S^{x}_{i}\pm i S^{y}_{i}`. 20 | 21 | Exercise 22 | -------- 23 | 24 | Calculate the ground state energy of the antiferromagnetic Heisenberg 25 | model for a chain of spins :math:`S=1/2` using the infinite version of 26 | the DMRG algorithm. You should be able to pass the number of sites of the 27 | chain and the number of states kept during the DMRG truncation as 28 | parameters. The output should be the energy per site, entanglement entropy 29 | and, truncation error at each step of the algorithm. You could: 30 | 31 | - make a plot of the energy per site versus system size to see how 32 | converges. The relative error in energy is given by the truncation 33 | error. 34 | - for a given system size (say :math:`n=32,\dots, 64`) calculate the 35 | energy per site for different number of states kept, make a plot, and 36 | extrapolate the values of the energy to zero truncation error with a 37 | linear fit. Compare this with the exact value for a finite size given by 38 | the Bethe Anstatz. 39 | 40 | +----+-------------------+ 41 | | L | E/J | 42 | +====+===================+ 43 | | 16 | -6.9117371455749 | 44 | +----+-------------------+ 45 | | 24 | -10.4537857604096 | 46 | +----+-------------------+ 47 | | 32 | -13.9973156182243 | 48 | +----+-------------------+ 49 | | 48 | -21.0859563143863 | 50 | +----+-------------------+ 51 | | 64 | -28.1754248597421 | 52 | +----+-------------------+ 53 | 54 | Solution 55 | -------- 56 | 57 | You can use the `System` class to create the four spin chain, and set the 58 | system Hamiltonian to the antiferromagnetic Heisenberg model, as we did in 59 | the previous exercise. Then you calculate ground state as before. From 60 | there you need to implement the DMRG transformation. We did most of the 61 | required steps (calculating, diagonalizing, and truncating the reduced 62 | density matrix) in a previous exercise. 63 | 64 | The new thing is updating the operators using the transformation matrix. 65 | You need to specify two things before doing that. First which are going to 66 | be the operators to be transformed. These are the ones that you need in 67 | the next step of the DMRG algorithm. To build the Heisenberg Hamiltonian 68 | using the block-site-site-block construction, you need your block to have 69 | a truncated version of the current single site spin operators 70 | :math:`S^{z}, S^{\dagger}, S^{-}`. Additionally you need to update the 71 | block hamiltonian, which belongs to the current block and contains the 72 | part of the Hamiltonian involving only degrees of freedom *within* the 73 | block. This function sets the operators to be updated: 74 | 75 | .. literalinclude:: ../solutions/infinite_heisenberg.py 76 | :pyobject: set_operators_to_update_to_AF_Heisenberg 77 | 78 | The block hamiltonian is built by including the previous block hamiltonian, 79 | if any, and the terms coming from the interactions between the block and 80 | the single site that is being included in the new block: 81 | 82 | .. literalinclude:: ../solutions/infinite_heisenberg.py 83 | :pyobject: set_block_hamiltonian_to_AF_Heisenberg 84 | 85 | Now we can put together the function to grow a block by one site: 86 | 87 | .. literalinclude:: ../solutions/infinite_heisenberg.py 88 | :pyobject: grow_block_by_one_site 89 | 90 | A step of the infinite DMRG algorithm consists in growing at the same time 91 | both the left and the right blocks by one site. 92 | 93 | .. literalinclude:: ../solutions/infinite_heisenberg.py 94 | :pyobject: infinite_dmrg_step 95 | 96 | The other thing remaining is to make a small change in the function to set 97 | up the AF Heisenberg Hamiltonian that we used in the previous exercise to 98 | include the block hamiltonians: 99 | 100 | .. literalinclude:: ../solutions/infinite_heisenberg.py 101 | :pyobject: set_hamiltonian_to_AF_Heisenberg 102 | 103 | Now you just make a loop that repeats the DMRG step until you reach the 104 | desired system size. Adding some code to pass the arguments from the 105 | command line and to save the results to a file, you get something like 106 | this: 107 | 108 | .. literalinclude:: ../solutions/infinite_heisenberg.py 109 | :pyobject: main 110 | 111 | See :download:`a full implementation of the above code 112 | <../solutions/infinite_heisenberg.py>`. To learn how to run this code you 113 | can use: 114 | :: 115 | 116 | $ ./tutorial/solutions/infinite_heisenberg.py --help 117 | Implements the infinite version of the DMRG algorithm for the S=1/2 AF 118 | Heisenberg. 119 | 120 | Calculates the ground state energy and wavefunction for the 121 | antiferromagnetic Heisenberg model for a chain of spin one-half. The 122 | calculation of the ground state is done using the infinite version of the 123 | DMRG algorithm. 124 | 125 | Usage: 126 | infinite_heisenberg.py (-m= -n=) [--dir=DIR -o=FILE] 127 | infinite_heisenberg.py -h | --help 128 | 129 | Options: 130 | -h --help Shows this screen. 131 | -n Number of sites of the chain. 132 | -m Number of states kept. 133 | -o --output=FILE Ouput file [default: infinite_heisenberg.dat] 134 | --dir=DIR Ouput directory [default: ./] 135 | -------------------------------------------------------------------------------- /docs/playing_with_two_qbits.rst: -------------------------------------------------------------------------------- 1 | Playing with a two-qbit system 2 | ============================== 3 | 4 | The goal of this exercise is to build the wavefunction of a pair of spins 5 | one-half (a.k.a. a pair of qbits), and calculate its entanglement 6 | entropy. This is a pretty trivial exercise that you could do without much 7 | hassle in a piece of paper (see below.) The purpose is just get you 8 | familiar with how things are done in the code before moving to bigger 9 | adventures. 10 | 11 | Exercise 12 | -------- 13 | 14 | Calculate the entanglement entropy when you trace out one of the spins in 15 | a general state in the subspace of a two spin one-half system where the 16 | two particles have opposite spin. For which of the states in this 17 | subspace is are the two spins maximally entangled (i.e. the Von Neumann 18 | entanglement entropy is maximal)? 19 | 20 | Hint 21 | ---- 22 | 23 | The first thing we need to do is to write the wavefunction of the two spin 24 | system. In dmrg101 the wavefunctions are represented as matrices instead 25 | of vectors, which may be more familiar to you. 26 | 27 | The reason for that is that as in DMRG we always have to split the 28 | physical systems (say a chain of spins, or the two spins of the problem) 29 | in left and right subsystems, the notation with matrices is more suited. 30 | In the dmrg101 code the rows of the matrix representing a wavefunction 31 | correspond to states of the left subsystem, and the columns correspond to 32 | states of the right subsystem. 33 | 34 | For example to represent the two spin one-half system, with one spin as 35 | left subsystem and the other as right subsystem, we need a 2x2 matrix. 36 | Matrix elements in the first row (column) will correspond to states with 37 | the left (right) spin down. Matrix elements in the second row (column) 38 | will correspond to states with the left (right) spin up. The choice of 39 | whether the first or second row corresponds to spin down or up is 40 | arbitrary, but once you made the choice you have to be consistent. 41 | 42 | If we restrict ourselves to the subspace where the particles have 43 | opposite spin, the most general wavefunction for the two qbit systems 44 | is simply [#]_: 45 | 46 | .. math:: 47 | |\psi\rangle = \cos \phi |\downarrow\uparrow\rangle 48 | + \sin \phi |\uparrow\downarrow\rangle = 49 | \begin{pmatrix} 0 & \cos \phi \\ \sin\phi & 0 \end{pmatrix} 50 | 51 | Solution 52 | -------- 53 | 54 | The plan is the following. First we are going to write a function to 55 | calculate the wavefunction for the two-qbit system as a function of 56 | an angle `psi`: 57 | 58 | .. literalinclude:: ../solutions/two_qbit_system.py 59 | :pyobject: create_two_qbit_system_in_singlet 60 | 61 | Now we are going to get the reduced density matrix tracing out the 62 | left qbit and calculate the corresponding entanglement entropy: 63 | 64 | .. literalinclude:: ../solutions/two_qbit_system.py 65 | :pyobject: trace_out_left_qbit_and_calculate_entropy 66 | 67 | Now it just a matter to generate a bunch of different values for `psi`, 68 | calculate the corresponding wavefunction with the first function above, 69 | and pass the wavefunction to the second funciton above to get the value 70 | for the entropy. The following code makes this: 71 | 72 | .. literalinclude:: ../solutions/two_qbit_system.py 73 | :pyobject: main 74 | 75 | See :download:`a full implementation of the above code 76 | <../solutions/two_qbit_system.py>`. If you run that code you should 77 | get something like this: 78 | :: 79 | 80 | $ ./solutions/two_qbit_system.py 81 | The maximum value for entropy is 0.693147. 82 | The wavefunction with max entropy is: 83 | [[ 0. 0.70710678] 84 | [ 0.70710678 0. ]] 85 | The whole list of psi vs entropies is saved in two_qbit_entropies.dat. 86 | 87 | which are in fact the entropy (:math:`log(2)`) and the wavefunction of 88 | the triplet state where the particles have opposite spins. In your own 89 | code, you might alternatively have observed a state with the same entropy 90 | but where one of the two components is negative; this is the singlet 91 | state. See also the :download:`data for the entropies vs psi 92 | <../solutions/two_qbit_entropies.dat>`. To see the options avaliable: 93 | :: 94 | 95 | $ ./solutions/two_qbit_system.py --help 96 | Calculates the entanglement entropy of a two qbit system 97 | 98 | Calculates the von Neumann entanglement entropu of a system of two 99 | spin one-half spins restricted to the subspace of total spin equal to 100 | zero. 101 | 102 | Usage: 103 | two_qbit_system.py [--dir=DIR -o=FILE] 104 | two_qbit_system.py -h | --help 105 | 106 | Options: 107 | -h --help Shows this screen. 108 | -o --output=FILE Ouput file [default: two_qbit_entropies.dat] 109 | --dir=DIR Ouput directory [default: ./] 110 | 111 | Conclusion 112 | ---------- 113 | 114 | It is important that you note that this is the general solution for a 115 | system of two qbits, and that two-qbits cannot be more entangled than 116 | when they are in an equal amplitude (but possibly opposite phase) 117 | superposition state over configurations where the particles have opposite 118 | spin. In system of many particles is splitted in two parts (think in a 119 | larger chain of spins cut at some point in two), one can always represent 120 | the relevant degrees of freedom at the cut as a set of qbits. Then it 121 | follows from the result you just proved that the most *economical* way of 122 | representing the entanglement across the cut is to map the degrees of 123 | freedom of each side to a qbits and *maximally entangle* them across 124 | the cut. Any other state to be formed with the qbits in one side and the 125 | other, will either have less entanglement across the cut than the one 126 | in the original degrees of freedom, or use more qbits at each side of 127 | the cut. This is the basis of the mappings used in quantum information 128 | methods like MPS or TNS, and you will see *maximally entangled 129 | spins/qbits* a lot in the rest of the school. 130 | 131 | -------------------------------------- 132 | 133 | .. [#] There could be an extra phase between the two components, but it 134 | cancels out later, so we don't bother to include it. 135 | 136 | -------------------------------------------------------------------------------- /docs/tfim.rst: -------------------------------------------------------------------------------- 1 | DMRG algorithm for the Ising model in a transverse field 2 | ======================================================== 3 | 4 | The goal of this exercise is to implement the finite version of the DMRG 5 | algorithm for the Ising model in a transverse field (TFIM) for a chain of 6 | spins one-half and study the model close to the quantum phase transition. 7 | 8 | The Hamiltonian is: 9 | 10 | .. math:: 11 | H=\sum_{i}\left(-JS^{z}_{i}S^{z}_{i+1}-hS^{x}_{i}\right) 12 | 13 | 14 | where :math:`\vec{S}_{i}=\vec{\sigma}_{i}/2` are the spin operators, and 15 | :math:`\sigma_{i}` are the Pauli matrices. 16 | 17 | This model has a quantum phase transition at :math:`h/J=1.0`. At the 18 | critical point the exact value for the ground state energy for a finite 19 | system with open boundary conditions is given by: 20 | 21 | .. math:: 22 | E/J=1-cosec\left(\frac{\pi}{2\left(2L+1\right)}\right) 23 | 24 | The high field phase :math:`h/J>1.0` is a paramagnet with an order 25 | parameter :math:`\langle S^{x}\rangle\neq 0`. The low field phase 26 | :math:`h/J<1.0` is a ferromagnet with an order parameter :math:`\langle 27 | S^{z}\rangle\neq 0`. At the critical point, both order parameters go to 28 | zero. 29 | 30 | The exact values of the energies at the critical point are: 31 | 32 | +----+---------------+ 33 | | L | E/L (J) | 34 | +====+===============+ 35 | | 16 | -1.2510242438 | 36 | +----+---------------+ 37 | | 20 | -1.255389856 | 38 | +----+---------------+ 39 | | 32 | -1.2620097863 | 40 | +----+---------------+ 41 | | 40 | -1.264235845 | 42 | +----+---------------+ 43 | | 64 | -1.267593439 | 44 | +----+---------------+ 45 | 46 | Exercise 47 | -------- 48 | 49 | Study the quantum phase transition in the TFIM by measuring the order 50 | parameters at each side of the transition and comparing the energy at the 51 | critical point with the exact result. The critical point is 52 | 53 | - calculate the energy per site for a given system size and different 54 | number of states kept, make a plot, and extrapolate the values of the 55 | energy to zero truncation error with a linear fit. Compare this with the 56 | exact value for a finite size given by the exact solution. 57 | - measure the value of the order parameters for a given system size and 58 | a few values of :math:`h/J` around the critical point. Use a reasonable 59 | system size and a number of states, so you actually are able to get to 60 | sample the phase diagram around the critical point. Get the order 61 | parameter by summing up the values of :math:`S^{x}` or :math:`S^{z}` 62 | for all sites of the chain. Plot both order parameters versus :math:`h/J`. 63 | 64 | Solution 65 | -------- 66 | 67 | The implementation goes is pretty similar to the one for the Heisenberg 68 | model of the last exercise. The main change is of course the change of the 69 | Hamiltonian, block Hamiltonian, and the operators you need to update after 70 | each DMRG step. 71 | 72 | To simplify things and switching between different models, the `System` 73 | class has a few convience functions to do grow the blocks, perform the 74 | infinite and finite DMRG steps, and set the Hamiltonian. These are the 75 | same functions we have seen before, but now written as methods of the 76 | `System` class. 77 | 78 | When using these methods you have to write a `Model` class that contains 79 | the details of the TFIM model: 80 | 81 | .. literalinclude:: ../static/tfim_helpers.py 82 | :pyobject: TranverseFieldIsingModel 83 | 84 | The best thing is to look at the final implementation and compare to the 85 | previous one for the Heisenberg model: 86 | 87 | .. literalinclude:: ../solutions/tfim.py 88 | :pyobject: main 89 | 90 | See :download:`a full implementation of the above code 91 | <../solutions/tfim.py>`. To learn how to run this code you 92 | can use: 93 | :: 94 | 95 | $ ./solutions/tfim.py --help 96 | Implements the full DMRG algorithm for the S=1/2 TFIM. 97 | 98 | Calculates the ground state energy and wavefunction for the 99 | Ising model in a transverse field for a chain of spin one-half. The 100 | calculation of the ground state is done using the full DMRG algorithm, 101 | i.e. first the infinite algorithm, and then doing sweeps for 102 | convergence with the finite algorithm. 103 | 104 | Usage: 105 | tfim.py (-m= -n= -s= -H=) [--dir=DIR -o=FILE] 106 | tfim.py -h | --help 107 | 108 | Options: 109 | -h --help Shows this screen. 110 | -n Number of sites of the chain. 111 | -m Number of states kept. 112 | -s Number of sweeps in the finite algorithm. 113 | -H Magnetic field in units of coupling between spins. 114 | -o --output=FILE Ouput file [default: tfim.dat] 115 | --dir=DIR Ouput directory [default: ./] 116 | 117 | -------------------------------------------------------------------------------- /solutions/heisenberg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Implements the full DMRG algorithm for the S=1/2 AF Heisenberg. 3 | 4 | Calculates the ground state energy and wavefunction for the 5 | antiferromagnetic Heisenberg for a chain of spin one-half. The 6 | calculation of the ground state is done using the full DMRG algorithm, 7 | i.e. first the infinite algorithm, and then doing sweeps for convergence 8 | with the finite algorithm. 9 | 10 | Usage: 11 | heisenberg.py (-m= -n= -s=) [--dir=DIR -o=FILE] 12 | heisenberg.py -h | --help 13 | 14 | Options: 15 | -h --help Shows this screen. 16 | -n Number of sites of the chain. 17 | -m Number of states kept. 18 | -s Number of sweeps in the finite algorithm. 19 | -o --output=FILE Ouput file [default: heisenberg.dat] 20 | --dir=DIR Ouput directory [default: ./] 21 | 22 | """ 23 | from dmrg101.core.calculate_states_to_keep import calculate_states_to_keep 24 | from dmrg101.core.sites import SpinOneHalfSite 25 | from dmrg101.core.system import System 26 | from dmrg101.utils.models.heisenberg_model import HeisenbergModel 27 | from docopt import docopt 28 | import os 29 | 30 | def main(args): 31 | # 32 | # create a system object with spin one-half sites and blocks, and set 33 | # its model to be the TFIM. 34 | # 35 | spin_one_half_site = SpinOneHalfSite() 36 | system = System(spin_one_half_site) 37 | system.model = HeisenbergModel() 38 | # 39 | # read command-line arguments and initialize some stuff 40 | # 41 | number_of_sites = int(args['-n']) 42 | number_of_states_kept = int(args['-m']) 43 | number_of_sweeps = int(args['-s']) 44 | number_of_states_infinite_algorithm = 10 45 | if number_of_states_kept < number_of_states_infinite_algorithm: 46 | number_of_states_kept = number_of_states_infinite_algorithm 47 | sizes = [] 48 | energies = [] 49 | entropies = [] 50 | truncation_errors = [] 51 | system.number_of_sites = number_of_sites 52 | # 53 | # infinite DMRG algorithm 54 | # 55 | max_left_block_size = number_of_sites - 3 56 | for left_block_size in range(1, max_left_block_size+1): 57 | energy, entropy, truncation_error = ( 58 | system.infinite_dmrg_step(left_block_size, 59 | number_of_states_infinite_algorithm) ) 60 | current_size = left_block_size + 3 61 | sizes.append(left_block_size) 62 | energies.append(energy) 63 | entropies.append(entropy) 64 | truncation_errors.append(truncation_error) 65 | # 66 | # finite DMRG algorithm 67 | # 68 | states_to_keep = calculate_states_to_keep(number_of_states_infinite_algorithm, 69 | number_of_states_kept, 70 | number_of_sweeps) 71 | half_sweep = 0 72 | while half_sweep < len(states_to_keep): 73 | # sweep to the left 74 | for left_block_size in range(max_left_block_size, 0, -1): 75 | states = states_to_keep[half_sweep] 76 | energy, entropy, truncation_error = ( 77 | system.finite_dmrg_step('right', left_block_size, states) ) 78 | sizes.append(left_block_size) 79 | energies.append(energy) 80 | entropies.append(entropy) 81 | truncation_errors.append(truncation_error) 82 | half_sweep += 1 83 | # sweep to the right 84 | # if this is the last sweep, stop at the middle 85 | if half_sweep == 2 * number_of_sweeps - 1: 86 | max_left_block_size = number_of_sites / 2 - 1 87 | for left_block_size in range(1, max_left_block_size + 1): 88 | energy, entropy, truncation_error = ( 89 | system.finite_dmrg_step('left', left_block_size, states) ) 90 | sizes.append(left_block_size) 91 | energies.append(energy) 92 | entropies.append(entropy) 93 | truncation_errors.append(truncation_error) 94 | half_sweep += 1 95 | # 96 | # save results 97 | # 98 | output_file = os.path.join(os.path.abspath(args['--dir']), args['--output']) 99 | f = open(output_file, 'w') 100 | zipped = zip (sizes, energies, entropies, truncation_errors) 101 | f.write('\n'.join('%s %s %s %s' % x for x in zipped)) 102 | f.close() 103 | print 'Results stored in ' + output_file 104 | 105 | if __name__ == '__main__': 106 | args = docopt(__doc__, version = 0.1) 107 | main(args) 108 | -------------------------------------------------------------------------------- /solutions/heisenberg_for_four_spins.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ Calculates the ground state for the AF Heisenberg for two spins 1/2. 3 | 4 | Calculates the ground state energy and wavefunction for the 5 | antiferromagnetic Heisenberg model for a chain of four spin one-half. The 6 | calculation of the ground state is done using the Lanczos algorithm. 7 | 8 | Usage: 9 | 10 | heisenberg_for_four_spins.py -h | --help 11 | 12 | Options: 13 | -h --help Shows this screen. 14 | 15 | """ 16 | from docopt import docopt 17 | from dmrg101.core.sites import SpinOneHalfSite 18 | from dmrg101.core.system import System 19 | 20 | def set_hamiltonian_to_AF_Heisenberg(system): 21 | """Sets a system Hamiltonian to the AF Heisenberg Hamiltonian. 22 | 23 | Does exactly this. If the system hamiltonian has some other terms on 24 | it, there are not touched. So be sure to use this function only in 25 | newly created `System` objects. 26 | 27 | Parameters 28 | ---------- 29 | system : a System. 30 | The System you want to set the Hamiltonain for. 31 | """ 32 | system.add_to_hamiltonian('id', 'id', 's_z', 's_z') 33 | system.add_to_hamiltonian('id', 'id', 's_p', 's_m', .5) 34 | system.add_to_hamiltonian('id', 'id', 's_m', 's_p', .5) 35 | system.add_to_hamiltonian('id', 's_z', 's_z', 'id') 36 | system.add_to_hamiltonian('id', 's_p', 's_m', 'id', .5) 37 | system.add_to_hamiltonian('id', 's_m', 's_p', 'id', .5) 38 | system.add_to_hamiltonian('s_z', 's_z', 'id', 'id') 39 | system.add_to_hamiltonian('s_p', 's_m', 'id', 'id', .5) 40 | system.add_to_hamiltonian('s_m', 's_p', 'id', 'id', .5) 41 | 42 | def main(): 43 | # 44 | # create a system object with spin one-half sites and blocks. 45 | # 46 | spin_one_half_site = SpinOneHalfSite() 47 | system = System(spin_one_half_site) 48 | # 49 | # build the Hamiltonian, and solve it using Lanczos. 50 | # 51 | set_hamiltonian_to_AF_Heisenberg(system) 52 | ground_state_energy, ground_state_wf = system.calculate_ground_state() 53 | # 54 | # print results 55 | # 56 | print "The ground state energy is %8.6f." %ground_state_energy 57 | print "The ground state wavefunction is :" 58 | print ground_state_wf.as_matrix 59 | 60 | if __name__ == '__main__': 61 | args = docopt(__doc__, version = 0.1) 62 | main() 63 | -------------------------------------------------------------------------------- /solutions/heisenberg_for_two_spins.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ Calculates the ground state for the AF Heisenberg for two spins 1/2. 3 | 4 | Calculates the ground state energy and wavefunction for the 5 | antiferromagnetic Heisenberg model for a system of two spins one-half. The 6 | calculation of the ground state is done using the Lanczos algorithm. 7 | 8 | Usage: 9 | 10 | heisenberg_for_two_spins.py -h | --help 11 | 12 | Options: 13 | -h --help Shows this screen. 14 | 15 | """ 16 | from docopt import docopt 17 | from dmrg101.core.lanczos import calculate_ground_state 18 | from dmrg101.core.operators import CompositeOperator 19 | from dmrg101.core.sites import SpinOneHalfSite 20 | 21 | def build_HAF_hamiltonian_for_two_spins(left_spin, right_spin): 22 | """ Builds the AF Heisenberg Hamiltonian for two spins. 23 | 24 | Parameters 25 | ---------- 26 | left_spin : a Site 27 | The Site must have the s_z, s_p, and s_m operators defined. 28 | right_spin : a Site 29 | The Site must have the s_z, s_p, and s_m operators defined. 30 | 31 | Returns 32 | ------- 33 | result : an Operator 34 | The Hamiltonian of the AF Heisenberg. 35 | 36 | Notes 37 | ----- 38 | This function should raise an exception if the keys for the 39 | operators are not found in the site, but I'll leave without it 40 | because it just makes the code more complicated to read. 41 | """ 42 | result = CompositeOperator(left_spin.dim, right_spin.dim) 43 | result.add(left_spin.operators['s_z'], right_spin.operators['s_z']) 44 | result.add(left_spin.operators['s_p'], right_spin.operators['s_m'], .5) 45 | result.add(left_spin.operators['s_m'], right_spin.operators['s_p'], .5) 46 | return result 47 | 48 | def main(): 49 | # 50 | # create the two spin one-half sites 51 | # 52 | left_spin = SpinOneHalfSite() 53 | right_spin = SpinOneHalfSite() 54 | # 55 | # build the Hamiltonian, and solve it using Lanczos. 56 | # 57 | hamiltonian = build_HAF_hamiltonian_for_two_spins(left_spin, 58 | right_spin) 59 | ground_state_energy, ground_state_wf = calculate_ground_state(hamiltonian) 60 | # 61 | # print results 62 | # 63 | print "The ground state energy is %8.6f." %ground_state_energy 64 | print "The ground state wavefunction is :" 65 | print ground_state_wf.as_matrix 66 | 67 | if __name__ == '__main__': 68 | args = docopt(__doc__, version = 0.1) 69 | main() 70 | -------------------------------------------------------------------------------- /solutions/hubbard.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Implements the full DMRG algorithm for the Hubbard model. 3 | 4 | Calculates the ground state energy and wavefunction for the 5 | one-dimensional Hubbard model. The calculation of the ground state is done 6 | using the full DMRG algorithm, i.e. first the infinite algorithm, and then 7 | doing sweeps for convergence with the finite algorithm. 8 | 9 | Usage: 10 | hubbard.py (-m= -n= -s= -U=) [--dir=DIR -o=FILE] 11 | hubbard.py -h | --help 12 | 13 | Options: 14 | -h --help Shows this screen. 15 | -n Number of sites of the chain. 16 | -m Number of states kept. 17 | -s Number of sweeps in the finite algorithm. 18 | -U Electronic interaction in units of hopping. 19 | -o --output=FILE Ouput file [default: hubbard.dat] 20 | --dir=DIR Ouput directory [default: ./] 21 | 22 | """ 23 | from dmrg101.core.calculate_states_to_keep import calculate_states_to_keep 24 | from dmrg101.core.sites import ElectronicSite 25 | from dmrg101.core.system import System 26 | from dmrg101.utils.models.hubbard_model import HubbardModel 27 | from docopt import docopt 28 | import os 29 | 30 | def main(args): 31 | # 32 | # create a system object with electron sites and blocks, and set 33 | # its model to be the Hubbard model. 34 | # 35 | electronic_site = ElectronicSite() 36 | system = System(electronic_site) 37 | system.model = HubbardModel() 38 | # 39 | # read command-line arguments and initialize some stuff 40 | # 41 | number_of_sites = int(args['-n']) 42 | number_of_states_kept = int(args['-m']) 43 | number_of_sweeps = int(args['-s']) 44 | system.model.U = float(args['-U']) 45 | number_of_states_infinite_algorithm = 10 46 | if number_of_states_kept < number_of_states_infinite_algorithm: 47 | number_of_states_kept = number_of_states_infinite_algorithm 48 | sizes = [] 49 | energies = [] 50 | entropies = [] 51 | truncation_errors = [] 52 | system.number_of_sites = number_of_sites 53 | # 54 | # infinite DMRG algorithm 55 | # 56 | max_left_block_size = number_of_sites - 3 57 | for left_block_size in range(1, max_left_block_size + 1): 58 | energy, entropy, truncation_error = ( 59 | system.infinite_dmrg_step(left_block_size, 60 | number_of_states_infinite_algorithm) ) 61 | current_size = left_block_size + 3 62 | sizes.append(left_block_size) 63 | energies.append(energy) 64 | entropies.append(entropy) 65 | truncation_errors.append(truncation_error) 66 | # 67 | # finite DMRG algorithm 68 | # 69 | states_to_keep = calculate_states_to_keep(number_of_states_infinite_algorithm, 70 | number_of_states_kept, 71 | number_of_sweeps) 72 | half_sweep = 0 73 | while half_sweep < len(states_to_keep): 74 | # sweep to the left 75 | for left_block_size in range(max_left_block_size, 0, -1): 76 | states = states_to_keep[half_sweep] 77 | energy, entropy, truncation_error = ( 78 | system.finite_dmrg_step('right', left_block_size, states) ) 79 | sizes.append(left_block_size) 80 | energies.append(energy) 81 | entropies.append(entropy) 82 | truncation_errors.append(truncation_error) 83 | half_sweep += 1 84 | # sweep to the right 85 | # if this is the last sweep, stop at the middle 86 | if half_sweep == 2 * number_of_sweeps - 1: 87 | max_left_block_size = number_of_sites / 2 - 1 88 | for left_block_size in range(1, max_left_block_size + 1): 89 | energy, entropy, truncation_error = ( 90 | system.finite_dmrg_step('left', left_block_size, states) ) 91 | sizes.append(left_block_size) 92 | energies.append(energy) 93 | entropies.append(entropy) 94 | truncation_errors.append(truncation_error) 95 | half_sweep += 1 96 | # 97 | # save results 98 | # 99 | output_file = os.path.join(os.path.abspath(args['--dir']), args['--output']) 100 | f = open(output_file, 'w') 101 | zipped = zip (sizes, energies, entropies, truncation_errors) 102 | f.write('\n'.join('%s %s %s %s' % x for x in zipped)) 103 | f.close() 104 | print 'Results stored in ' + output_file 105 | 106 | if __name__ == '__main__': 107 | args = docopt(__doc__, version = 0.1) 108 | main(args) 109 | -------------------------------------------------------------------------------- /solutions/infinite_heisenberg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Implements the infinite version of the DMRG algorithm for the S=1/2 AF Heisenberg. 3 | 4 | Calculates the ground state energy and wavefunction for the 5 | antiferromagnetic Heisenberg model for a chain of spin one-half. The 6 | calculation of the ground state is done using the infinite version of the 7 | DMRG algorithm. 8 | 9 | Usage: 10 | infinite_heisenberg.py (-m= -n=) [--dir=DIR -o=FILE] 11 | infinite_heisenberg.py -h | --help 12 | 13 | Options: 14 | -h --help Shows this screen. 15 | -n Number of sites of the chain. 16 | -m Number of states kept. 17 | -o --output=FILE Ouput file [default: infinite_heisenberg.dat] 18 | --dir=DIR Ouput directory [default: ./] 19 | 20 | """ 21 | from dmrg101.core.entropies import calculate_entropy, calculate_renyi 22 | from dmrg101.core.reduced_DM import diagonalize, truncate 23 | from dmrg101.core.sites import SpinOneHalfSite 24 | from dmrg101.core.system import System 25 | from dmrg101.core.truncation_error import calculate_truncation_error 26 | from docopt import docopt 27 | import numpy as np 28 | import os 29 | 30 | def set_hamiltonian_to_AF_Heisenberg(system): 31 | """Sets a system Hamiltonian to the AF Heisenberg Hamiltonian. 32 | 33 | Does exactly this. If the system hamiltonian has some other terms on 34 | it, there are not touched. So be sure to use this function only in 35 | newly created `System` objects. 36 | 37 | Parameters 38 | ---------- 39 | system : a System. 40 | The System you want to set the Hamiltonain for. 41 | """ 42 | system.clear_hamiltonian() 43 | if 'bh' in system.left_block.operators.keys(): 44 | system.add_to_hamiltonian(left_block_op='bh') 45 | if 'bh' in system.right_block.operators.keys(): 46 | system.add_to_hamiltonian(right_block_op='bh') 47 | system.add_to_hamiltonian('id', 'id', 's_z', 's_z') 48 | system.add_to_hamiltonian('id', 'id', 's_p', 's_m', .5) 49 | system.add_to_hamiltonian('id', 'id', 's_m', 's_p', .5) 50 | system.add_to_hamiltonian('id', 's_z', 's_z', 'id') 51 | system.add_to_hamiltonian('id', 's_p', 's_m', 'id', .5) 52 | system.add_to_hamiltonian('id', 's_m', 's_p', 'id', .5) 53 | system.add_to_hamiltonian('s_z', 's_z', 'id', 'id') 54 | system.add_to_hamiltonian('s_p', 's_m', 'id', 'id', .5) 55 | system.add_to_hamiltonian('s_m', 's_p', 'id', 'id', .5) 56 | 57 | def set_block_hamiltonian_to_AF_Heisenberg(system): 58 | """Sets the block Hamiltonian to be what you need for AF Heisenberg. 59 | 60 | Builds a matrix with the proper dimensions full of zeros. Then adds 61 | the terms in the Hamiltonian that contain degrees of freedom belonging 62 | only to one block. Finally adds the matrix to the block as the 63 | operator labelled 'bh'. 64 | 65 | Parameters 66 | ---------- 67 | system : a System. 68 | The System you want to set the Hamiltonian for. 69 | """ 70 | tmp_matrix_size = None 71 | if system.growing_side == 'left': 72 | tmp_matrix_size = system.get_left_dim() 73 | else: 74 | tmp_matrix_size = system.get_right_dim() 75 | tmp_matrix_for_bh = np.zeros((tmp_matrix_size, tmp_matrix_size)) 76 | if 'bh' in system.growing_block.operators.keys(): 77 | system.add_to_block_hamiltonian(tmp_matrix_for_bh, 'bh', 'id') 78 | system.add_to_block_hamiltonian(tmp_matrix_for_bh, 's_z', 's_z') 79 | system.add_to_block_hamiltonian(tmp_matrix_for_bh, 's_p', 's_m', .5) 80 | system.add_to_block_hamiltonian(tmp_matrix_for_bh, 's_m', 's_p', .5) 81 | system.operators_to_add_to_block['bh'] = tmp_matrix_for_bh 82 | 83 | def set_operators_to_update_to_AF_Heisenberg(system): 84 | """Sets the operators to update to be what you need to AF Heisenberg. 85 | 86 | Parameters 87 | ---------- 88 | system : a System. 89 | The System you want to set the Hamiltonian for. 90 | 91 | Notes 92 | ----- 93 | The block Hamiltonian, althought needs to be updated, is treated 94 | separately by the very functions in the `System` class. 95 | """ 96 | system.add_to_operators_to_update('s_z', site_op='s_z') 97 | system.add_to_operators_to_update('s_p', site_op='s_p') 98 | system.add_to_operators_to_update('s_m', site_op='s_m') 99 | 100 | def grow_block_by_one_site(growing_block, ground_state_wf, system, 101 | number_of_states_kept): 102 | """Grows one side of the system by one site. 103 | 104 | Calculates the truncation matrix by calculating the reduced density 105 | matrix for `ground_state_wf` by tracing out the degrees of freedom of 106 | the shrinking side. Then updates the operators you need in the next 107 | steps, effectively growing the size of the block by one site. 108 | 109 | Parameters 110 | ---------- 111 | growing_block : a string. 112 | The block which is growing. It must be 'left' or 'right'. 113 | ground_state_wf : a Wavefunction. 114 | The ground state wavefunction of your system. 115 | system : a System object. 116 | The system you want to do the calculation on. This function 117 | assumes that you have set the Hamiltonian to something. 118 | number_of_states_kept : an int. 119 | The number of states you want to keep in each block after the 120 | truncation. If the `number_of_states_kept` is smaller than the 121 | dimension of the current Hilbert space block, all states are kept. 122 | 123 | Returns 124 | ------- 125 | entropy : a double. 126 | The Von Neumann entropy for the cut that splits the chain into two 127 | equal halves. 128 | truncation_error : a double. 129 | The truncation error, i.e. the sum of the discarded eigenvalues of 130 | the reduced density matrix. 131 | 132 | Raises 133 | ------ 134 | DMRGException 135 | if `growing_side` is not 'left' or 'right'. 136 | """ 137 | if growing_block not in ('left', 'right'): 138 | raise DMRGException('Growing side must be left or right.') 139 | system.set_growing_side(growing_block) 140 | rho = ground_state_wf.build_reduced_density_matrix(growing_block) 141 | evals, evecs = diagonalize(rho) 142 | truncated_evals, truncation_matrix = truncate(evals, evecs, 143 | number_of_states_kept) 144 | entropy = calculate_entropy(truncated_evals) 145 | truncation_error = calculate_truncation_error(truncated_evals) 146 | set_block_hamiltonian_to_AF_Heisenberg(system) 147 | set_operators_to_update_to_AF_Heisenberg(system) 148 | system.update_all_operators(truncation_matrix) 149 | return entropy, truncation_error 150 | 151 | def infinite_dmrg_step(system, current_size, number_of_states_kept): 152 | """Performs one step of the infinite DMRG algorithm. 153 | 154 | Calculates the ground state of a system with a given size, then 155 | performs the DMRG transformation on the operators of *both* blocks, 156 | therefore increasing by one site the number of sites encoded in the 157 | Hilbert space of each blocks, and reset the blocks in the system to be 158 | the new, enlarged, truncated ones. 159 | 160 | In reality the second block is not updated but just copied over from 161 | the first. 162 | 163 | Parameters 164 | ---------- 165 | system : a System object. 166 | The system you want to do the calculation on. This function 167 | assumes that you have set the Hamiltonian to something. 168 | current_size : an int. 169 | The number of sites of the chain. 170 | number_of_states_kept : an int. 171 | The number of states you want to keep in each block after the 172 | truncation. If the `number_of_states_kept` is smaller than the 173 | dimension of the current Hilbert space block, all states are kept. 174 | 175 | Returns 176 | ------- 177 | energy_per_site : a double. 178 | The energy per site for the `current_size`. 179 | entropy : a double. 180 | The Von Neumann entropy for the cut that splits the chain into two 181 | equal halves. 182 | truncation_error : a double. 183 | The truncation error, i.e. the sum of the discarded eigenvalues of 184 | the reduced density matrix. 185 | 186 | Notes 187 | ----- 188 | Normally you don't update both blocks. If the chain is symmetric, you 189 | just can use the operators for the one of the sides to mirror the 190 | operators in the other side, saving the half of the CPU time. In 191 | practical DMRG calculations one uses the finite algorithm to 192 | improve the result of the infinite algorithm, and one of the blocks 193 | is kept one site long, and therefore not updated. 194 | """ 195 | set_hamiltonian_to_AF_Heisenberg(system) 196 | ground_state_energy, ground_state_wf = system.calculate_ground_state() 197 | entropy, truncation_error = grow_block_by_one_site('left', ground_state_wf, 198 | system, 199 | number_of_states_kept) 200 | system.right_block = system.left_block 201 | return ground_state_energy / current_size, entropy, truncation_error 202 | 203 | def main(args): 204 | # 205 | # create a system object with spin one-half sites and blocks. 206 | # 207 | spin_one_half_site = SpinOneHalfSite() 208 | system = System(spin_one_half_site) 209 | # 210 | # read command-line arguments and initialize some stuff 211 | # 212 | number_of_sites = int(args['-n']) 213 | number_of_states_kept= int(args['-m']) 214 | sizes = [] 215 | energies = [] 216 | entropies = [] 217 | truncation_errors = [] 218 | # 219 | # infinite DMRG algorithm 220 | # 221 | number_of_sites = 2 * (number_of_sites / 2) # make it even 222 | for current_size in range(4, number_of_sites + 1, 2): 223 | #block_size = current_size / 2 - 1 224 | energy, entropy, truncation_error = ( 225 | infinite_dmrg_step(system, current_size, number_of_states_kept) ) 226 | sizes.append(current_size) 227 | energies.append(energy) 228 | entropies.append(entropy) 229 | truncation_errors.append(truncation_error) 230 | # 231 | # save results 232 | # 233 | output_file = os.path.join(os.path.abspath(args['--dir']), args['--output']) 234 | f = open(output_file, 'w') 235 | zipped = zip (sizes, energies, entropies, truncation_errors) 236 | f.write('\n'.join('%s %s %s %s' % x for x in zipped)) 237 | f.close() 238 | print 'Results stored in ' + output_file 239 | 240 | if __name__ == '__main__': 241 | args = docopt(__doc__, version = 0.1) 242 | main(args) 243 | -------------------------------------------------------------------------------- /solutions/plot_entropies_obc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ Plots entanglement entropy data from a text file using matplotlib. 3 | 4 | The file must contain two columns of the same lenght. The first column are 5 | the sizes of the growing block, not including the single site. The second 6 | column is not used. The second column are the entanglement entropies 7 | calculated for this cut. The number of sites must be even and the lower 8 | branch, i.e. when number of sites in the growing side -not including the 9 | single site- is odd, is used. This is the ouput format for the scripts 10 | that implement the DMRG algorithm in this tutorial. 11 | 12 | The quantity plotted in the x-axis is :math:`ln(2x')`, where 13 | :math:`x'=(L/\pi)\sin{\pi x /L}`. The slope of this plot is proportional 14 | to the central charge of the CFT: 15 | 16 | .. :math: S_{vN} \approx \frac{c}{6}ln(x') 17 | 18 | The plot show the data as blue points and a green line with the CFT result 19 | above, as a guide to the eye (not a real fit to data.) 20 | 21 | See e.g. A. B. Kallin et al, Phys. Rev. Lett. 103, 117203 (2009). 22 | 23 | Usage: 24 | plot_entropies.py (-n=) 25 | plot_entropies.py -h | --help 26 | 27 | Options: 28 | -h --help Shows this screen. 29 | -n Number of sites of the chain. 30 | 31 | """ 32 | from docopt import docopt 33 | import numpy as np 34 | import math 35 | import matplotlib.pyplot as plt 36 | import os 37 | 38 | args = docopt(__doc__, version = 0.1) 39 | data_file = os.path.abspath(args['']) 40 | number_of_sites = int(args['-n']) 41 | fin = open(data_file, 'r') 42 | x = [] 43 | y = [] 44 | for lines in fin: 45 | line = lines.split() 46 | # the system (opposed to enviroment) has even sites: 47 | if int(line[0]) % 2 == 1: 48 | x_prime = math.sin(math.pi * (float(line[0]) + 1) / number_of_sites) 49 | x_prime *= 2 * number_of_sites / math.pi 50 | x.append(math.log(x_prime)) 51 | y.append(float(line[2])) 52 | 53 | # cft_result is the part of the CFT result proportional to the central 54 | # charge (there are other smaller terms for finite number_of_sites), 55 | # forced to pass by the last point of your data. So it's not a real fit, 56 | # just a guide to the eye. 57 | cft_result = np.array(x) / 6 58 | cft_result += y[-1] - x[-1] / 6 59 | plt.plot(x, y, 'bo') 60 | plt.plot(x, cft_result, 'g-') 61 | plt.show() 62 | -------------------------------------------------------------------------------- /solutions/plot_from_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ Plots data from a text file using matplotlib. 3 | 4 | The file must contain two columns of the same lenght. The first column 5 | will be the data in the x-axis, the second column the data in the y-axis. 6 | 7 | Usage: 8 | plot_from_file.py [-x= -y=] 9 | plot_from_file.py -h | --help 10 | 11 | Options: 12 | -h --help Shows this screen. 13 | -x Which column has the data for x-axis [default: 0] 14 | -y Which column has the data for y-axis [default: 1] 15 | 16 | """ 17 | from docopt import docopt 18 | import matplotlib.pyplot as plt 19 | import os 20 | 21 | args = docopt(__doc__, version = 0.1) 22 | data_file = os.path.abspath(args['']) 23 | x_col = int(args['-x']) 24 | y_col = int(args['-y']) 25 | fin = open(data_file, 'r') 26 | x = [] 27 | y = [] 28 | for lines in fin: 29 | line = lines.split() 30 | x.append(float(line[x_col])) 31 | y.append(float(line[y_col])) 32 | plt.plot(x, y) 33 | plt.show() 34 | -------------------------------------------------------------------------------- /solutions/tfim.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Implements the full DMRG algorithm for the S=1/2 TFIM. 3 | 4 | Calculates the ground state energy and wavefunction for the 5 | Ising model in a transverse field for a chain of spin one-half. The 6 | calculation of the ground state is done using the full DMRG algorithm, 7 | i.e. first the infinite algorithm, and then doing sweeps for convergence 8 | with the finite algorithm. 9 | 10 | Usage: 11 | tfim.py (-m= -n= -s= -H=) [--dir=DIR -o=FILE] 12 | tfim.py -h | --help 13 | 14 | Options: 15 | -h --help Shows this screen. 16 | -n Number of sites of the chain. 17 | -m Number of states kept. 18 | -s Number of sweeps in the finite algorithm. 19 | -H Magnetic field in units of coupling between spins. 20 | -o --output=FILE Ouput file [default: tfim.dat] 21 | --dir=DIR Ouput directory [default: ./] 22 | 23 | """ 24 | from dmrg101.core.calculate_states_to_keep import calculate_states_to_keep 25 | from dmrg101.core.sites import SpinOneHalfSite 26 | from dmrg101.core.system import System 27 | from dmrg101.utils.models.tfi_model import TranverseFieldIsingModel 28 | from docopt import docopt 29 | import os 30 | 31 | def main(args): 32 | # 33 | # create a system object with spin one-half sites and blocks, and set 34 | # its model to be the TFIM. 35 | # 36 | spin_one_half_site = SpinOneHalfSite() 37 | system = System(spin_one_half_site) 38 | system.model = TranverseFieldIsingModel() 39 | # 40 | # read command-line arguments and initialize some stuff 41 | # 42 | number_of_sites = int(args['-n']) 43 | number_of_states_kept = int(args['-m']) 44 | number_of_sweeps = int(args['-s']) 45 | system.model.H = float(args['-H']) 46 | number_of_states_infinite_algorithm = 10 47 | if number_of_states_kept < number_of_states_infinite_algorithm: 48 | number_of_states_kept = number_of_states_infinite_algorithm 49 | sizes = [] 50 | energies = [] 51 | entropies = [] 52 | truncation_errors = [] 53 | system.number_of_sites = number_of_sites 54 | # 55 | # infinite DMRG algorithm 56 | # 57 | max_left_block_size = number_of_sites - 3 58 | for left_block_size in range(1, max_left_block_size+1): 59 | energy, entropy, truncation_error = ( 60 | system.infinite_dmrg_step(left_block_size, 61 | number_of_states_infinite_algorithm) ) 62 | current_size = left_block_size + 3 63 | sizes.append(left_block_size) 64 | energies.append(energy) 65 | entropies.append(entropy) 66 | truncation_errors.append(truncation_error) 67 | # 68 | # finite DMRG algorithm 69 | # 70 | states_to_keep = calculate_states_to_keep(number_of_states_infinite_algorithm, 71 | number_of_states_kept, 72 | number_of_sweeps) 73 | half_sweep = 0 74 | while half_sweep < len(states_to_keep): 75 | # sweep to the left 76 | for left_block_size in range(max_left_block_size, 0, -1): 77 | states = states_to_keep[half_sweep] 78 | energy, entropy, truncation_error = ( 79 | system.finite_dmrg_step('right', left_block_size, states) ) 80 | sizes.append(left_block_size) 81 | energies.append(energy) 82 | entropies.append(entropy) 83 | truncation_errors.append(truncation_error) 84 | half_sweep += 1 85 | # sweep to the right 86 | # if this is the last sweep, stop at the middle 87 | if half_sweep == 2 * number_of_sweeps - 1: 88 | max_left_block_size = number_of_sites / 2 - 1 89 | for left_block_size in range(1, max_left_block_size + 1): 90 | energy, entropy, truncation_error = ( 91 | system.finite_dmrg_step('left', left_block_size, states) ) 92 | sizes.append(left_block_size) 93 | energies.append(energy) 94 | entropies.append(entropy) 95 | truncation_errors.append(truncation_error) 96 | half_sweep += 1 97 | # 98 | # save results 99 | # 100 | output_file = os.path.join(os.path.abspath(args['--dir']), args['--output']) 101 | f = open(output_file, 'w') 102 | zipped = zip (sizes, energies, entropies, truncation_errors) 103 | f.write('\n'.join('%s %s %s %s' % x for x in zipped)) 104 | f.close() 105 | print 'Results stored in ' + output_file 106 | 107 | if __name__ == '__main__': 108 | args = docopt(__doc__, version = 0.1) 109 | main(args) 110 | -------------------------------------------------------------------------------- /solutions/two_qbit_entropies.dat: -------------------------------------------------------------------------------- 1 | 0.0 -0 2 | 0.00628318530718 0.000439773909168 3 | 0.0125663706144 0.00154011976651 4 | 0.0188495559215 0.00317693573276 5 | 0.0251327412287 0.00528398146561 6 | 0.0314159265359 0.00781486197139 7 | 0.0376991118431 0.0107336757226 8 | 0.0439822971503 0.0140110537908 9 | 0.0502654824574 0.0176220925873 10 | 0.0565486677646 0.0215451347091 11 | 0.0628318530718 0.025760988666 12 | 0.069115038379 0.0302523991136 13 | 0.0753982236862 0.0350036706809 14 | 0.0816814089933 0.0400003912818 15 | 0.0879645943005 0.0452292227253 16 | 0.0942477796077 0.0506777384909 17 | 0.100530964915 0.0563342955447 18 | 0.106814150222 0.0621879313424 19 | 0.113097335529 0.0682282798639 20 | 0.119380520836 0.0744455023015 21 | 0.125663706144 0.0808302292077 22 | 0.131946891451 0.0873735117368 23 | 0.138230076758 0.0940667801934 24 | 0.144513262065 0.100901808518 25 | 0.150796447372 0.107870683645 26 | 0.157079632679 0.114965778904 27 | 0.163362817987 0.122179730785 28 | 0.169646003294 0.129505418554 29 | 0.175929188601 0.136935946267 30 | 0.182212373908 0.144464626844 31 | 0.188495559215 0.152084967905 32 | 0.194778744523 0.15979065912 33 | 0.20106192983 0.167575560889 34 | 0.207345115137 0.175433694169 35 | 0.213628300444 0.183359231298 36 | 0.219911485751 0.191346487717 37 | 0.226194671058 0.199389914467 38 | 0.232477856366 0.207484091375 39 | 0.238761041673 0.215623720856 40 | 0.24504422698 0.223803622266 41 | 0.251327412287 0.23201872674 42 | 0.257610597594 0.240264072468 43 | 0.263893782902 0.248534800375 44 | 0.270176968209 0.256826150143 45 | 0.276460153516 0.265133456563 46 | 0.282743338823 0.27345214618 47 | 0.28902652413 0.281777734194 48 | 0.295309709437 0.290105821609 49 | 0.301592894745 0.298432092594 50 | 0.307876080052 0.306752312049 51 | 0.314159265359 0.315062323352 52 | 0.320442450666 0.323358046272 53 | 0.326725635973 0.331635475035 54 | 0.333008821281 0.339890676535 55 | 0.339292006588 0.34811978867 56 | 0.345575191895 0.356319018798 57 | 0.351858377202 0.364484642306 58 | 0.358141562509 0.372613001278 59 | 0.364424747816 0.380700503258 60 | 0.370707933124 0.388743620101 61 | 0.376991118431 0.396738886902 62 | 0.383274303738 0.404682900999 63 | 0.389557489045 0.412572321054 64 | 0.395840674352 0.420403866183 65 | 0.402123859659 0.428174315164 66 | 0.408407044967 0.435880505684 67 | 0.414690230274 0.443519333649 68 | 0.420973415581 0.451087752537 69 | 0.427256600888 0.4585827728 70 | 0.433539786195 0.4660014613 71 | 0.439822971503 0.473340940797 72 | 0.44610615681 0.480598389461 73 | 0.452389342117 0.487771040424 74 | 0.458672527424 0.494856181365 75 | 0.464955712731 0.501851154121 76 | 0.471238898038 0.508753354329 77 | 0.477522083346 0.515560231091 78 | 0.483805268653 0.522269286669 79 | 0.49008845396 0.528878076194 80 | 0.496371639267 0.535384207402 81 | 0.502654824574 0.541785340393 82 | 0.508938009882 0.548079187399 83 | 0.515221195189 0.554263512577 84 | 0.521504380496 0.560336131819 85 | 0.527787565803 0.566294912566 86 | 0.53407075111 0.572137773655 87 | 0.540353936417 0.577862685159 88 | 0.546637121725 0.583467668256 89 | 0.552920307032 0.588950795095 90 | 0.559203492339 0.594310188689 91 | 0.565486677646 0.5995440228 92 | 0.571769862953 0.604650521849 93 | 0.578053048261 0.609627960824 94 | 0.584336233568 0.614474665203 95 | 0.590619418875 0.619189010878 96 | 0.596902604182 0.623769424093 97 | 0.603185789489 0.628214381382 98 | 0.609468974796 0.632522409516 99 | 0.615752160104 0.636692085458 100 | 0.622035345411 0.640722036316 101 | 0.628318530718 0.644610939309 102 | 0.634601716025 0.648357521727 103 | 0.640884901332 0.65196056091 104 | 0.647168086639 0.655418884213 105 | 0.653451271947 0.658731368989 106 | 0.659734457254 0.661896942563 107 | 0.666017642561 0.66491458222 108 | 0.672300827868 0.667783315187 109 | 0.678584013175 0.67050221862 110 | 0.684867198483 0.673070419594 111 | 0.69115038379 0.675487095093 112 | 0.697433569097 0.677751472002 113 | 0.703716754404 0.679862827101 114 | 0.709999939711 0.681820487061 115 | 0.716283125018 0.683623828438 116 | 0.722566310326 0.68527227767 117 | 0.728849495633 0.686765311074 118 | 0.73513268094 0.688102454847 119 | 0.741415866247 0.68928328506 120 | 0.747699051554 0.690307427659 121 | 0.753982236862 0.691174558468 122 | 0.760265422169 0.69188440318 123 | 0.766548607476 0.692436737366 124 | 0.772831792783 0.692831386468 125 | 0.77911497809 0.693068225803 126 | 0.785398163397 0.69314718056 127 | 0.791681348705 0.693068225803 128 | 0.797964534012 0.692831386468 129 | 0.804247719319 0.692436737366 130 | 0.810530904626 0.69188440318 131 | 0.816814089933 0.691174558468 132 | 0.823097275241 0.690307427659 133 | 0.829380460548 0.68928328506 134 | 0.835663645855 0.688102454847 135 | 0.841946831162 0.686765311074 136 | 0.848230016469 0.68527227767 137 | 0.854513201776 0.683623828438 138 | 0.860796387084 0.681820487061 139 | 0.867079572391 0.679862827101 140 | 0.873362757698 0.677751472002 141 | 0.879645943005 0.675487095093 142 | 0.885929128312 0.673070419594 143 | 0.89221231362 0.67050221862 144 | 0.898495498927 0.667783315187 145 | 0.904778684234 0.66491458222 146 | 0.911061869541 0.661896942563 147 | 0.917345054848 0.658731368989 148 | 0.923628240155 0.655418884213 149 | 0.929911425463 0.65196056091 150 | 0.93619461077 0.648357521727 151 | 0.942477796077 0.644610939309 152 | 0.948760981384 0.640722036316 153 | 0.955044166691 0.636692085458 154 | 0.961327351998 0.632522409516 155 | 0.967610537306 0.628214381382 156 | 0.973893722613 0.623769424093 157 | 0.98017690792 0.619189010878 158 | 0.986460093227 0.614474665203 159 | 0.992743278534 0.609627960824 160 | 0.999026463842 0.604650521849 161 | 1.00530964915 0.5995440228 162 | 1.01159283446 0.594310188689 163 | 1.01787601976 0.588950795095 164 | 1.02415920507 0.583467668256 165 | 1.03044239038 0.577862685159 166 | 1.03672557568 0.572137773655 167 | 1.04300876099 0.566294912566 168 | 1.0492919463 0.560336131819 169 | 1.05557513161 0.554263512577 170 | 1.06185831691 0.548079187399 171 | 1.06814150222 0.541785340393 172 | 1.07442468753 0.535384207402 173 | 1.08070787283 0.528878076194 174 | 1.08699105814 0.522269286669 175 | 1.09327424345 0.515560231091 176 | 1.09955742876 0.508753354329 177 | 1.10584061406 0.501851154121 178 | 1.11212379937 0.494856181365 179 | 1.11840698468 0.487771040424 180 | 1.12469016999 0.480598389461 181 | 1.13097335529 0.473340940797 182 | 1.1372565406 0.4660014613 183 | 1.14353972591 0.4585827728 184 | 1.14982291121 0.451087752537 185 | 1.15610609652 0.443519333649 186 | 1.16238928183 0.435880505684 187 | 1.16867246714 0.428174315164 188 | 1.17495565244 0.420403866183 189 | 1.18123883775 0.412572321054 190 | 1.18752202306 0.404682900999 191 | 1.19380520836 0.396738886902 192 | 1.20008839367 0.388743620101 193 | 1.20637157898 0.380700503258 194 | 1.21265476429 0.372613001278 195 | 1.21893794959 0.364484642306 196 | 1.2252211349 0.356319018798 197 | 1.23150432021 0.34811978867 198 | 1.23778750551 0.339890676535 199 | 1.24407069082 0.331635475035 200 | 1.25035387613 0.323358046272 201 | 1.25663706144 0.315062323352 202 | 1.26292024674 0.306752312049 203 | 1.26920343205 0.298432092594 204 | 1.27548661736 0.290105821609 205 | 1.28176980266 0.281777734194 206 | 1.28805298797 0.27345214618 207 | 1.29433617328 0.265133456563 208 | 1.30061935859 0.256826150143 209 | 1.30690254389 0.248534800375 210 | 1.3131857292 0.240264072468 211 | 1.31946891451 0.23201872674 212 | 1.32575209981 0.223803622266 213 | 1.33203528512 0.215623720856 214 | 1.33831847043 0.207484091375 215 | 1.34460165574 0.199389914467 216 | 1.35088484104 0.191346487717 217 | 1.35716802635 0.183359231298 218 | 1.36345121166 0.175433694169 219 | 1.36973439697 0.167575560889 220 | 1.37601758227 0.15979065912 221 | 1.38230076758 0.152084967905 222 | 1.38858395289 0.144464626844 223 | 1.39486713819 0.136935946267 224 | 1.4011503235 0.129505418554 225 | 1.40743350881 0.122179730785 226 | 1.41371669412 0.114965778904 227 | 1.41999987942 0.107870683645 228 | 1.42628306473 0.100901808518 229 | 1.43256625004 0.0940667801934 230 | 1.43884943534 0.0873735117368 231 | 1.44513262065 0.0808302292077 232 | 1.45141580596 0.0744455023015 233 | 1.45769899127 0.0682282798639 234 | 1.46398217657 0.0621879313424 235 | 1.47026536188 0.0563342955447 236 | 1.47654854719 0.0506777384909 237 | 1.48283173249 0.0452292227253 238 | 1.4891149178 0.0400003912818 239 | 1.49539810311 0.0350036706809 240 | 1.50168128842 0.0302523991136 241 | 1.50796447372 0.025760988666 242 | 1.51424765903 0.0215451347091 243 | 1.52053084434 0.0176220925873 244 | 1.52681402964 0.0140110537908 245 | 1.53309721495 0.0107336757226 246 | 1.53938040026 0.00781486197139 247 | 1.54566358557 0.00528398146561 248 | 1.55194677087 0.00317693573276 249 | 1.55822995618 0.00154011976651 250 | 1.56451314149 0.000439773909168 251 | 1.57079632679 -0 252 | 1.5770795121 0.000439773909168 253 | 1.58336269741 0.00154011976651 254 | 1.58964588272 0.00317693573276 255 | 1.59592906802 0.00528398146561 256 | 1.60221225333 0.00781486197139 257 | 1.60849543864 0.0107336757226 258 | 1.61477862395 0.0140110537908 259 | 1.62106180925 0.0176220925873 260 | 1.62734499456 0.0215451347091 261 | 1.63362817987 0.025760988666 262 | 1.63991136517 0.0302523991136 263 | 1.64619455048 0.0350036706809 264 | 1.65247773579 0.0400003912818 265 | 1.6587609211 0.0452292227253 266 | 1.6650441064 0.0506777384909 267 | 1.67132729171 0.0563342955447 268 | 1.67761047702 0.0621879313424 269 | 1.68389366232 0.0682282798639 270 | 1.69017684763 0.0744455023015 271 | 1.69646003294 0.0808302292077 272 | 1.70274321825 0.0873735117368 273 | 1.70902640355 0.0940667801934 274 | 1.71530958886 0.100901808518 275 | 1.72159277417 0.107870683645 276 | 1.72787595947 0.114965778904 277 | 1.73415914478 0.122179730785 278 | 1.74044233009 0.129505418554 279 | 1.7467255154 0.136935946267 280 | 1.7530087007 0.144464626844 281 | 1.75929188601 0.152084967905 282 | 1.76557507132 0.15979065912 283 | 1.77185825662 0.167575560889 284 | 1.77814144193 0.175433694169 285 | 1.78442462724 0.183359231298 286 | 1.79070781255 0.191346487717 287 | 1.79699099785 0.199389914467 288 | 1.80327418316 0.207484091375 289 | 1.80955736847 0.215623720856 290 | 1.81584055377 0.223803622266 291 | 1.82212373908 0.23201872674 292 | 1.82840692439 0.240264072468 293 | 1.8346901097 0.248534800375 294 | 1.840973295 0.256826150143 295 | 1.84725648031 0.265133456563 296 | 1.85353966562 0.27345214618 297 | 1.85982285093 0.281777734194 298 | 1.86610603623 0.290105821609 299 | 1.87238922154 0.298432092594 300 | 1.87867240685 0.306752312049 301 | 1.88495559215 0.315062323352 302 | 1.89123877746 0.323358046272 303 | 1.89752196277 0.331635475035 304 | 1.90380514808 0.339890676535 305 | 1.91008833338 0.34811978867 306 | 1.91637151869 0.356319018798 307 | 1.922654704 0.364484642306 308 | 1.9289378893 0.372613001278 309 | 1.93522107461 0.380700503258 310 | 1.94150425992 0.388743620101 311 | 1.94778744523 0.396738886902 312 | 1.95407063053 0.404682900999 313 | 1.96035381584 0.412572321054 314 | 1.96663700115 0.420403866183 315 | 1.97292018645 0.428174315164 316 | 1.97920337176 0.435880505684 317 | 1.98548655707 0.443519333649 318 | 1.99176974238 0.451087752537 319 | 1.99805292768 0.4585827728 320 | 2.00433611299 0.4660014613 321 | 2.0106192983 0.473340940797 322 | 2.0169024836 0.480598389461 323 | 2.02318566891 0.487771040424 324 | 2.02946885422 0.494856181365 325 | 2.03575203953 0.501851154121 326 | 2.04203522483 0.508753354329 327 | 2.04831841014 0.515560231091 328 | 2.05460159545 0.522269286669 329 | 2.06088478075 0.528878076194 330 | 2.06716796606 0.535384207402 331 | 2.07345115137 0.541785340393 332 | 2.07973433668 0.548079187399 333 | 2.08601752198 0.554263512577 334 | 2.09230070729 0.560336131819 335 | 2.0985838926 0.566294912566 336 | 2.10486707791 0.572137773655 337 | 2.11115026321 0.577862685159 338 | 2.11743344852 0.583467668256 339 | 2.12371663383 0.588950795095 340 | 2.12999981913 0.594310188689 341 | 2.13628300444 0.5995440228 342 | 2.14256618975 0.604650521849 343 | 2.14884937506 0.609627960824 344 | 2.15513256036 0.614474665203 345 | 2.16141574567 0.619189010878 346 | 2.16769893098 0.623769424093 347 | 2.17398211628 0.628214381382 348 | 2.18026530159 0.632522409516 349 | 2.1865484869 0.636692085458 350 | 2.19283167221 0.640722036316 351 | 2.19911485751 0.644610939309 352 | 2.20539804282 0.648357521727 353 | 2.21168122813 0.65196056091 354 | 2.21796441343 0.655418884213 355 | 2.22424759874 0.658731368989 356 | 2.23053078405 0.661896942563 357 | 2.23681396936 0.66491458222 358 | 2.24309715466 0.667783315187 359 | 2.24938033997 0.67050221862 360 | 2.25566352528 0.673070419594 361 | 2.26194671058 0.675487095093 362 | 2.26822989589 0.677751472002 363 | 2.2745130812 0.679862827101 364 | 2.28079626651 0.681820487061 365 | 2.28707945181 0.683623828438 366 | 2.29336263712 0.68527227767 367 | 2.29964582243 0.686765311074 368 | 2.30592900773 0.688102454847 369 | 2.31221219304 0.68928328506 370 | 2.31849537835 0.690307427659 371 | 2.32477856366 0.691174558468 372 | 2.33106174896 0.69188440318 373 | 2.33734493427 0.692436737366 374 | 2.34362811958 0.692831386468 375 | 2.34991130489 0.693068225803 376 | 2.35619449019 0.69314718056 377 | 2.3624776755 0.693068225803 378 | 2.36876086081 0.692831386468 379 | 2.37504404611 0.692436737366 380 | 2.38132723142 0.69188440318 381 | 2.38761041673 0.691174558468 382 | 2.39389360204 0.690307427659 383 | 2.40017678734 0.68928328506 384 | 2.40645997265 0.688102454847 385 | 2.41274315796 0.686765311074 386 | 2.41902634326 0.68527227767 387 | 2.42530952857 0.683623828438 388 | 2.43159271388 0.681820487061 389 | 2.43787589919 0.679862827101 390 | 2.44415908449 0.677751472002 391 | 2.4504422698 0.675487095093 392 | 2.45672545511 0.673070419594 393 | 2.46300864041 0.67050221862 394 | 2.46929182572 0.667783315187 395 | 2.47557501103 0.66491458222 396 | 2.48185819634 0.661896942563 397 | 2.48814138164 0.658731368989 398 | 2.49442456695 0.655418884213 399 | 2.50070775226 0.65196056091 400 | 2.50699093756 0.648357521727 401 | 2.51327412287 0.644610939309 402 | 2.51955730818 0.640722036316 403 | 2.52584049349 0.636692085458 404 | 2.53212367879 0.632522409516 405 | 2.5384068641 0.628214381382 406 | 2.54469004941 0.623769424093 407 | 2.55097323471 0.619189010878 408 | 2.55725642002 0.614474665203 409 | 2.56353960533 0.609627960824 410 | 2.56982279064 0.604650521849 411 | 2.57610597594 0.5995440228 412 | 2.58238916125 0.594310188689 413 | 2.58867234656 0.588950795095 414 | 2.59495553187 0.583467668256 415 | 2.60123871717 0.577862685159 416 | 2.60752190248 0.572137773655 417 | 2.61380508779 0.566294912566 418 | 2.62008827309 0.560336131819 419 | 2.6263714584 0.554263512577 420 | 2.63265464371 0.548079187399 421 | 2.63893782902 0.541785340393 422 | 2.64522101432 0.535384207402 423 | 2.65150419963 0.528878076194 424 | 2.65778738494 0.522269286669 425 | 2.66407057024 0.515560231091 426 | 2.67035375555 0.508753354329 427 | 2.67663694086 0.501851154121 428 | 2.68292012617 0.494856181365 429 | 2.68920331147 0.487771040424 430 | 2.69548649678 0.480598389461 431 | 2.70176968209 0.473340940797 432 | 2.70805286739 0.4660014613 433 | 2.7143360527 0.4585827728 434 | 2.72061923801 0.451087752537 435 | 2.72690242332 0.443519333649 436 | 2.73318560862 0.435880505684 437 | 2.73946879393 0.428174315164 438 | 2.74575197924 0.420403866183 439 | 2.75203516454 0.412572321054 440 | 2.75831834985 0.404682900999 441 | 2.76460153516 0.396738886902 442 | 2.77088472047 0.388743620101 443 | 2.77716790577 0.380700503258 444 | 2.78345109108 0.372613001278 445 | 2.78973427639 0.364484642306 446 | 2.79601746169 0.356319018798 447 | 2.802300647 0.34811978867 448 | 2.80858383231 0.339890676535 449 | 2.81486701762 0.331635475035 450 | 2.82115020292 0.323358046272 451 | 2.82743338823 0.315062323352 452 | 2.83371657354 0.306752312049 453 | 2.83999975885 0.298432092594 454 | 2.84628294415 0.290105821609 455 | 2.85256612946 0.281777734194 456 | 2.85884931477 0.27345214618 457 | 2.86513250007 0.265133456563 458 | 2.87141568538 0.256826150143 459 | 2.87769887069 0.248534800375 460 | 2.883982056 0.240264072468 461 | 2.8902652413 0.23201872674 462 | 2.89654842661 0.223803622266 463 | 2.90283161192 0.215623720856 464 | 2.90911479722 0.207484091375 465 | 2.91539798253 0.199389914467 466 | 2.92168116784 0.191346487717 467 | 2.92796435315 0.183359231298 468 | 2.93424753845 0.175433694169 469 | 2.94053072376 0.167575560889 470 | 2.94681390907 0.15979065912 471 | 2.95309709437 0.152084967905 472 | 2.95938027968 0.144464626844 473 | 2.96566346499 0.136935946267 474 | 2.9719466503 0.129505418554 475 | 2.9782298356 0.122179730785 476 | 2.98451302091 0.114965778904 477 | 2.99079620622 0.107870683645 478 | 2.99707939152 0.100901808518 479 | 3.00336257683 0.0940667801934 480 | 3.00964576214 0.0873735117368 481 | 3.01592894745 0.0808302292077 482 | 3.02221213275 0.0744455023015 483 | 3.02849531806 0.0682282798639 484 | 3.03477850337 0.0621879313424 485 | 3.04106168867 0.0563342955447 486 | 3.04734487398 0.0506777384909 487 | 3.05362805929 0.0452292227253 488 | 3.0599112446 0.0400003912818 489 | 3.0661944299 0.0350036706809 490 | 3.07247761521 0.0302523991136 491 | 3.07876080052 0.025760988666 492 | 3.08504398583 0.0215451347091 493 | 3.09132717113 0.0176220925873 494 | 3.09761035644 0.0140110537908 495 | 3.10389354175 0.0107336757226 496 | 3.11017672705 0.00781486197139 497 | 3.11645991236 0.00528398146561 498 | 3.12274309767 0.00317693573276 499 | 3.12902628298 0.00154011976651 500 | 3.13530946828 0.000439773909167 501 | 3.14159265359 -0 502 | 3.1478758389 0.000439773909168 503 | 3.1541590242 0.00154011976651 504 | 3.16044220951 0.00317693573276 505 | 3.16672539482 0.00528398146561 506 | 3.17300858013 0.00781486197139 507 | 3.17929176543 0.0107336757226 508 | 3.18557495074 0.0140110537908 509 | 3.19185813605 0.0176220925873 510 | 3.19814132135 0.0215451347091 511 | 3.20442450666 0.025760988666 512 | 3.21070769197 0.0302523991136 513 | 3.21699087728 0.0350036706809 514 | 3.22327406258 0.0400003912818 515 | 3.22955724789 0.0452292227253 516 | 3.2358404332 0.0506777384909 517 | 3.2421236185 0.0563342955447 518 | 3.24840680381 0.0621879313424 519 | 3.25468998912 0.0682282798639 520 | 3.26097317443 0.0744455023015 521 | 3.26725635973 0.0808302292077 522 | 3.27353954504 0.0873735117368 523 | 3.27982273035 0.0940667801934 524 | 3.28610591565 0.100901808518 525 | 3.29238910096 0.107870683645 526 | 3.29867228627 0.114965778904 527 | 3.30495547158 0.122179730785 528 | 3.31123865688 0.129505418554 529 | 3.31752184219 0.136935946267 530 | 3.3238050275 0.144464626844 531 | 3.33008821281 0.152084967905 532 | 3.33637139811 0.15979065912 533 | 3.34265458342 0.167575560889 534 | 3.34893776873 0.175433694169 535 | 3.35522095403 0.183359231298 536 | 3.36150413934 0.191346487717 537 | 3.36778732465 0.199389914467 538 | 3.37407050996 0.207484091375 539 | 3.38035369526 0.215623720856 540 | 3.38663688057 0.223803622266 541 | 3.39292006588 0.23201872674 542 | 3.39920325118 0.240264072468 543 | 3.40548643649 0.248534800375 544 | 3.4117696218 0.256826150143 545 | 3.41805280711 0.265133456563 546 | 3.42433599241 0.27345214618 547 | 3.43061917772 0.281777734194 548 | 3.43690236303 0.290105821609 549 | 3.44318554833 0.298432092594 550 | 3.44946873364 0.306752312049 551 | 3.45575191895 0.315062323352 552 | 3.46203510426 0.323358046272 553 | 3.46831828956 0.331635475035 554 | 3.47460147487 0.339890676535 555 | 3.48088466018 0.34811978867 556 | 3.48716784548 0.356319018798 557 | 3.49345103079 0.364484642306 558 | 3.4997342161 0.372613001278 559 | 3.50601740141 0.380700503258 560 | 3.51230058671 0.388743620101 561 | 3.51858377202 0.396738886902 562 | 3.52486695733 0.404682900999 563 | 3.53115014263 0.412572321054 564 | 3.53743332794 0.420403866183 565 | 3.54371651325 0.428174315164 566 | 3.54999969856 0.435880505684 567 | 3.55628288386 0.443519333649 568 | 3.56256606917 0.451087752537 569 | 3.56884925448 0.4585827728 570 | 3.57513243979 0.4660014613 571 | 3.58141562509 0.473340940797 572 | 3.5876988104 0.480598389461 573 | 3.59398199571 0.487771040424 574 | 3.60026518101 0.494856181365 575 | 3.60654836632 0.501851154121 576 | 3.61283155163 0.508753354329 577 | 3.61911473694 0.515560231091 578 | 3.62539792224 0.522269286669 579 | 3.63168110755 0.528878076194 580 | 3.63796429286 0.535384207402 581 | 3.64424747816 0.541785340393 582 | 3.65053066347 0.548079187399 583 | 3.65681384878 0.554263512577 584 | 3.66309703409 0.560336131819 585 | 3.66938021939 0.566294912566 586 | 3.6756634047 0.572137773655 587 | 3.68194659001 0.577862685159 588 | 3.68822977531 0.583467668256 589 | 3.69451296062 0.588950795095 590 | 3.70079614593 0.594310188689 591 | 3.70707933124 0.5995440228 592 | 3.71336251654 0.604650521849 593 | 3.71964570185 0.609627960824 594 | 3.72592888716 0.614474665203 595 | 3.73221207246 0.619189010878 596 | 3.73849525777 0.623769424093 597 | 3.74477844308 0.628214381382 598 | 3.75106162839 0.632522409516 599 | 3.75734481369 0.636692085458 600 | 3.763627999 0.640722036316 601 | 3.76991118431 0.644610939309 602 | 3.77619436961 0.648357521727 603 | 3.78247755492 0.65196056091 604 | 3.78876074023 0.655418884213 605 | 3.79504392554 0.658731368989 606 | 3.80132711084 0.661896942563 607 | 3.80761029615 0.66491458222 608 | 3.81389348146 0.667783315187 609 | 3.82017666677 0.67050221862 610 | 3.82645985207 0.673070419594 611 | 3.83274303738 0.675487095093 612 | 3.83902622269 0.677751472002 613 | 3.84530940799 0.679862827101 614 | 3.8515925933 0.681820487061 615 | 3.85787577861 0.683623828438 616 | 3.86415896392 0.68527227767 617 | 3.87044214922 0.686765311074 618 | 3.87672533453 0.688102454847 619 | 3.88300851984 0.68928328506 620 | 3.88929170514 0.690307427659 621 | 3.89557489045 0.691174558468 622 | 3.90185807576 0.69188440318 623 | 3.90814126107 0.692436737366 624 | 3.91442444637 0.692831386468 625 | 3.92070763168 0.693068225803 626 | 3.92699081699 0.69314718056 627 | 3.93327400229 0.693068225803 628 | 3.9395571876 0.692831386468 629 | 3.94584037291 0.692436737366 630 | 3.95212355822 0.69188440318 631 | 3.95840674352 0.691174558468 632 | 3.96468992883 0.690307427659 633 | 3.97097311414 0.68928328506 634 | 3.97725629944 0.688102454847 635 | 3.98353948475 0.686765311074 636 | 3.98982267006 0.68527227767 637 | 3.99610585537 0.683623828438 638 | 4.00238904067 0.681820487061 639 | 4.00867222598 0.679862827101 640 | 4.01495541129 0.677751472002 641 | 4.02123859659 0.675487095093 642 | 4.0275217819 0.673070419594 643 | 4.03380496721 0.67050221862 644 | 4.04008815252 0.667783315187 645 | 4.04637133782 0.66491458222 646 | 4.05265452313 0.661896942563 647 | 4.05893770844 0.658731368989 648 | 4.06522089375 0.655418884213 649 | 4.07150407905 0.65196056091 650 | 4.07778726436 0.648357521727 651 | 4.08407044967 0.644610939309 652 | 4.09035363497 0.640722036316 653 | 4.09663682028 0.636692085458 654 | 4.10292000559 0.632522409516 655 | 4.1092031909 0.628214381382 656 | 4.1154863762 0.623769424093 657 | 4.12176956151 0.619189010878 658 | 4.12805274682 0.614474665203 659 | 4.13433593212 0.609627960824 660 | 4.14061911743 0.604650521849 661 | 4.14690230274 0.5995440228 662 | 4.15318548805 0.594310188689 663 | 4.15946867335 0.588950795095 664 | 4.16575185866 0.583467668256 665 | 4.17203504397 0.577862685159 666 | 4.17831822927 0.572137773655 667 | 4.18460141458 0.566294912566 668 | 4.19088459989 0.560336131819 669 | 4.1971677852 0.554263512577 670 | 4.2034509705 0.548079187399 671 | 4.20973415581 0.541785340393 672 | 4.21601734112 0.535384207402 673 | 4.22230052642 0.528878076194 674 | 4.22858371173 0.522269286669 675 | 4.23486689704 0.515560231091 676 | 4.24115008235 0.508753354329 677 | 4.24743326765 0.501851154121 678 | 4.25371645296 0.494856181365 679 | 4.25999963827 0.487771040424 680 | 4.26628282357 0.480598389461 681 | 4.27256600888 0.473340940797 682 | 4.27884919419 0.4660014613 683 | 4.2851323795 0.4585827728 684 | 4.2914155648 0.451087752537 685 | 4.29769875011 0.443519333649 686 | 4.30398193542 0.435880505684 687 | 4.31026512073 0.428174315164 688 | 4.31654830603 0.420403866183 689 | 4.32283149134 0.412572321054 690 | 4.32911467665 0.404682900999 691 | 4.33539786195 0.396738886902 692 | 4.34168104726 0.388743620101 693 | 4.34796423257 0.380700503258 694 | 4.35424741788 0.372613001278 695 | 4.36053060318 0.364484642306 696 | 4.36681378849 0.356319018798 697 | 4.3730969738 0.34811978867 698 | 4.3793801591 0.339890676535 699 | 4.38566334441 0.331635475035 700 | 4.39194652972 0.323358046272 701 | 4.39822971503 0.315062323352 702 | 4.40451290033 0.306752312049 703 | 4.41079608564 0.298432092594 704 | 4.41707927095 0.290105821609 705 | 4.42336245625 0.281777734194 706 | 4.42964564156 0.27345214618 707 | 4.43592882687 0.265133456563 708 | 4.44221201218 0.256826150143 709 | 4.44849519748 0.248534800375 710 | 4.45477838279 0.240264072468 711 | 4.4610615681 0.23201872674 712 | 4.4673447534 0.223803622266 713 | 4.47362793871 0.215623720856 714 | 4.47991112402 0.207484091375 715 | 4.48619430933 0.199389914467 716 | 4.49247749463 0.191346487717 717 | 4.49876067994 0.183359231298 718 | 4.50504386525 0.175433694169 719 | 4.51132705055 0.167575560889 720 | 4.51761023586 0.15979065912 721 | 4.52389342117 0.152084967905 722 | 4.53017660648 0.144464626844 723 | 4.53645979178 0.136935946267 724 | 4.54274297709 0.129505418554 725 | 4.5490261624 0.122179730785 726 | 4.55530934771 0.114965778904 727 | 4.56159253301 0.107870683645 728 | 4.56787571832 0.100901808518 729 | 4.57415890363 0.0940667801934 730 | 4.58044208893 0.0873735117368 731 | 4.58672527424 0.0808302292077 732 | 4.59300845955 0.0744455023015 733 | 4.59929164486 0.0682282798639 734 | 4.60557483016 0.0621879313424 735 | 4.61185801547 0.0563342955447 736 | 4.61814120078 0.0506777384909 737 | 4.62442438608 0.0452292227253 738 | 4.63070757139 0.0400003912818 739 | 4.6369907567 0.0350036706809 740 | 4.64327394201 0.0302523991136 741 | 4.64955712731 0.025760988666 742 | 4.65584031262 0.0215451347091 743 | 4.66212349793 0.0176220925873 744 | 4.66840668323 0.0140110537908 745 | 4.67468986854 0.0107336757226 746 | 4.68097305385 0.00781486197139 747 | 4.68725623916 0.00528398146561 748 | 4.69353942446 0.00317693573276 749 | 4.69982260977 0.00154011976651 750 | 4.70610579508 0.000439773909167 751 | 4.71238898038 -0 752 | 4.71867216569 0.000439773909168 753 | 4.724955351 0.00154011976651 754 | 4.73123853631 0.00317693573276 755 | 4.73752172161 0.00528398146561 756 | 4.74380490692 0.00781486197139 757 | 4.75008809223 0.0107336757226 758 | 4.75637127753 0.0140110537908 759 | 4.76265446284 0.0176220925873 760 | 4.76893764815 0.0215451347091 761 | 4.77522083346 0.025760988666 762 | 4.78150401876 0.0302523991136 763 | 4.78778720407 0.0350036706809 764 | 4.79407038938 0.0400003912818 765 | 4.80035357469 0.0452292227253 766 | 4.80663675999 0.0506777384909 767 | 4.8129199453 0.0563342955447 768 | 4.81920313061 0.0621879313424 769 | 4.82548631591 0.0682282798639 770 | 4.83176950122 0.0744455023015 771 | 4.83805268653 0.0808302292077 772 | 4.84433587184 0.0873735117368 773 | 4.85061905714 0.0940667801934 774 | 4.85690224245 0.100901808518 775 | 4.86318542776 0.107870683645 776 | 4.86946861306 0.114965778904 777 | 4.87575179837 0.122179730785 778 | 4.88203498368 0.129505418554 779 | 4.88831816899 0.136935946267 780 | 4.89460135429 0.144464626844 781 | 4.9008845396 0.152084967905 782 | 4.90716772491 0.15979065912 783 | 4.91345091021 0.167575560889 784 | 4.91973409552 0.175433694169 785 | 4.92601728083 0.183359231298 786 | 4.93230046614 0.191346487717 787 | 4.93858365144 0.199389914467 788 | 4.94486683675 0.207484091375 789 | 4.95115002206 0.215623720856 790 | 4.95743320736 0.223803622266 791 | 4.96371639267 0.23201872674 792 | 4.96999957798 0.240264072468 793 | 4.97628276329 0.248534800375 794 | 4.98256594859 0.256826150143 795 | 4.9888491339 0.265133456563 796 | 4.99513231921 0.27345214618 797 | 5.00141550451 0.281777734194 798 | 5.00769868982 0.290105821609 799 | 5.01398187513 0.298432092594 800 | 5.02026506044 0.306752312049 801 | 5.02654824574 0.315062323352 802 | 5.03283143105 0.323358046272 803 | 5.03911461636 0.331635475035 804 | 5.04539780167 0.339890676535 805 | 5.05168098697 0.34811978867 806 | 5.05796417228 0.356319018798 807 | 5.06424735759 0.364484642306 808 | 5.07053054289 0.372613001278 809 | 5.0768137282 0.380700503258 810 | 5.08309691351 0.388743620101 811 | 5.08938009882 0.396738886902 812 | 5.09566328412 0.404682900999 813 | 5.10194646943 0.412572321054 814 | 5.10822965474 0.420403866183 815 | 5.11451284004 0.428174315164 816 | 5.12079602535 0.435880505684 817 | 5.12707921066 0.443519333649 818 | 5.13336239597 0.451087752537 819 | 5.13964558127 0.4585827728 820 | 5.14592876658 0.4660014613 821 | 5.15221195189 0.473340940797 822 | 5.15849513719 0.480598389461 823 | 5.1647783225 0.487771040424 824 | 5.17106150781 0.494856181365 825 | 5.17734469312 0.501851154121 826 | 5.18362787842 0.508753354329 827 | 5.18991106373 0.515560231091 828 | 5.19619424904 0.522269286669 829 | 5.20247743434 0.528878076194 830 | 5.20876061965 0.535384207402 831 | 5.21504380496 0.541785340393 832 | 5.22132699027 0.548079187399 833 | 5.22761017557 0.554263512577 834 | 5.23389336088 0.560336131819 835 | 5.24017654619 0.566294912566 836 | 5.24645973149 0.572137773655 837 | 5.2527429168 0.577862685159 838 | 5.25902610211 0.583467668256 839 | 5.26530928742 0.588950795095 840 | 5.27159247272 0.594310188689 841 | 5.27787565803 0.5995440228 842 | 5.28415884334 0.604650521849 843 | 5.29044202865 0.609627960824 844 | 5.29672521395 0.614474665203 845 | 5.30300839926 0.619189010878 846 | 5.30929158457 0.623769424093 847 | 5.31557476987 0.628214381382 848 | 5.32185795518 0.632522409516 849 | 5.32814114049 0.636692085458 850 | 5.3344243258 0.640722036316 851 | 5.3407075111 0.644610939309 852 | 5.34699069641 0.648357521727 853 | 5.35327388172 0.65196056091 854 | 5.35955706702 0.655418884213 855 | 5.36584025233 0.658731368989 856 | 5.37212343764 0.661896942563 857 | 5.37840662295 0.66491458222 858 | 5.38468980825 0.667783315187 859 | 5.39097299356 0.67050221862 860 | 5.39725617887 0.673070419594 861 | 5.40353936417 0.675487095093 862 | 5.40982254948 0.677751472002 863 | 5.41610573479 0.679862827101 864 | 5.4223889201 0.681820487061 865 | 5.4286721054 0.683623828438 866 | 5.43495529071 0.68527227767 867 | 5.44123847602 0.686765311074 868 | 5.44752166132 0.688102454847 869 | 5.45380484663 0.68928328506 870 | 5.46008803194 0.690307427659 871 | 5.46637121725 0.691174558468 872 | 5.47265440255 0.69188440318 873 | 5.47893758786 0.692436737366 874 | 5.48522077317 0.692831386468 875 | 5.49150395847 0.693068225803 876 | 5.49778714378 0.69314718056 877 | 5.50407032909 0.693068225803 878 | 5.5103535144 0.692831386468 879 | 5.5166366997 0.692436737366 880 | 5.52291988501 0.69188440318 881 | 5.52920307032 0.691174558468 882 | 5.53548625563 0.690307427659 883 | 5.54176944093 0.68928328506 884 | 5.54805262624 0.688102454847 885 | 5.55433581155 0.686765311074 886 | 5.56061899685 0.68527227767 887 | 5.56690218216 0.683623828438 888 | 5.57318536747 0.681820487061 889 | 5.57946855278 0.679862827101 890 | 5.58575173808 0.677751472002 891 | 5.59203492339 0.675487095093 892 | 5.5983181087 0.673070419594 893 | 5.604601294 0.67050221862 894 | 5.61088447931 0.667783315187 895 | 5.61716766462 0.66491458222 896 | 5.62345084993 0.661896942563 897 | 5.62973403523 0.658731368989 898 | 5.63601722054 0.655418884213 899 | 5.64230040585 0.65196056091 900 | 5.64858359115 0.648357521727 901 | 5.65486677646 0.644610939309 902 | 5.66114996177 0.640722036316 903 | 5.66743314708 0.636692085458 904 | 5.67371633238 0.632522409516 905 | 5.67999951769 0.628214381382 906 | 5.686282703 0.623769424093 907 | 5.6925658883 0.619189010878 908 | 5.69884907361 0.614474665203 909 | 5.70513225892 0.609627960824 910 | 5.71141544423 0.604650521849 911 | 5.71769862953 0.5995440228 912 | 5.72398181484 0.594310188689 913 | 5.73026500015 0.588950795095 914 | 5.73654818545 0.583467668256 915 | 5.74283137076 0.577862685159 916 | 5.74911455607 0.572137773655 917 | 5.75539774138 0.566294912566 918 | 5.76168092668 0.560336131819 919 | 5.76796411199 0.554263512577 920 | 5.7742472973 0.548079187399 921 | 5.78053048261 0.541785340393 922 | 5.78681366791 0.535384207402 923 | 5.79309685322 0.528878076194 924 | 5.79938003853 0.522269286669 925 | 5.80566322383 0.515560231091 926 | 5.81194640914 0.508753354329 927 | 5.81822959445 0.501851154121 928 | 5.82451277976 0.494856181365 929 | 5.83079596506 0.487771040424 930 | 5.83707915037 0.480598389461 931 | 5.84336233568 0.473340940797 932 | 5.84964552098 0.4660014613 933 | 5.85592870629 0.4585827728 934 | 5.8622118916 0.451087752537 935 | 5.86849507691 0.443519333649 936 | 5.87477826221 0.435880505684 937 | 5.88106144752 0.428174315164 938 | 5.88734463283 0.420403866183 939 | 5.89362781813 0.412572321054 940 | 5.89991100344 0.404682900999 941 | 5.90619418875 0.396738886902 942 | 5.91247737406 0.388743620101 943 | 5.91876055936 0.380700503258 944 | 5.92504374467 0.372613001278 945 | 5.93132692998 0.364484642306 946 | 5.93761011528 0.356319018798 947 | 5.94389330059 0.34811978867 948 | 5.9501764859 0.339890676535 949 | 5.95645967121 0.331635475035 950 | 5.96274285651 0.323358046272 951 | 5.96902604182 0.315062323352 952 | 5.97530922713 0.306752312049 953 | 5.98159241243 0.298432092594 954 | 5.98787559774 0.290105821609 955 | 5.99415878305 0.281777734194 956 | 6.00044196836 0.27345214618 957 | 6.00672515366 0.265133456563 958 | 6.01300833897 0.256826150143 959 | 6.01929152428 0.248534800375 960 | 6.02557470959 0.240264072468 961 | 6.03185789489 0.23201872674 962 | 6.0381410802 0.223803622266 963 | 6.04442426551 0.215623720856 964 | 6.05070745081 0.207484091375 965 | 6.05699063612 0.199389914467 966 | 6.06327382143 0.191346487717 967 | 6.06955700674 0.183359231298 968 | 6.07584019204 0.175433694169 969 | 6.08212337735 0.167575560889 970 | 6.08840656266 0.15979065912 971 | 6.09468974796 0.152084967905 972 | 6.10097293327 0.144464626844 973 | 6.10725611858 0.136935946267 974 | 6.11353930389 0.129505418554 975 | 6.11982248919 0.122179730785 976 | 6.1261056745 0.114965778904 977 | 6.13238885981 0.107870683645 978 | 6.13867204511 0.100901808518 979 | 6.14495523042 0.0940667801934 980 | 6.15123841573 0.0873735117368 981 | 6.15752160104 0.0808302292077 982 | 6.16380478634 0.0744455023015 983 | 6.17008797165 0.0682282798639 984 | 6.17637115696 0.0621879313424 985 | 6.18265434226 0.0563342955447 986 | 6.18893752757 0.0506777384909 987 | 6.19522071288 0.0452292227253 988 | 6.20150389819 0.0400003912818 989 | 6.20778708349 0.0350036706809 990 | 6.2140702688 0.0302523991136 991 | 6.22035345411 0.025760988666 992 | 6.22663663941 0.0215451347091 993 | 6.23291982472 0.0176220925873 994 | 6.23920301003 0.0140110537908 995 | 6.24548619534 0.0107336757226 996 | 6.25176938064 0.00781486197139 997 | 6.25805256595 0.00528398146561 998 | 6.26433575126 0.00317693573276 999 | 6.27061893657 0.00154011976651 1000 | 6.27690212187 0.000439773909167 -------------------------------------------------------------------------------- /solutions/two_qbit_system.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ Calculates the entanglement entropy of a two qbit system 3 | 4 | Calculates the von Neumann entanglement entropu of a system of two 5 | spin one-half spins restricted to the subspace of total spin equal to 6 | zero. 7 | 8 | Usage: 9 | two_qbit_system.py [--dir=DIR -o=FILE] 10 | two_qbit_system.py -h | --help 11 | 12 | Options: 13 | -h --help Shows this screen. 14 | -o --output=FILE Ouput file [default: two_qbit_entropies.dat] 15 | --dir=DIR Ouput directory [default: ./] 16 | 17 | """ 18 | from docopt import docopt 19 | import os 20 | from math import cos, sin, pi 21 | from dmrg101.core.entropies import calculate_entropy 22 | from dmrg101.core.reduced_DM import diagonalize 23 | from dmrg101.core.wavefunction import Wavefunction 24 | 25 | def create_two_qbit_system_in_singlet(psi): 26 | """ Returns the wf of the system as a function of `psi`. 27 | 28 | The (normalized) wavefunction of the two-qbit system can be 29 | parametrized as a function an angle `psi`. 30 | 31 | Parameters 32 | ---------- 33 | psi : a double 34 | Parametrizes the wavefunction. 35 | 36 | Returns 37 | ------- 38 | result : a Wavefunction 39 | The wavefunction of the two-qbit system for the given `psi`. 40 | """ 41 | result = Wavefunction(2, 2) 42 | 43 | # set the different components. 44 | result.as_matrix[0, 0] = 0. 45 | result.as_matrix[0, 1] = cos(psi) 46 | result.as_matrix[1, 0] = sin(psi) 47 | result.as_matrix[1, 1] = 0. 48 | return result 49 | 50 | def trace_out_left_qbit_and_calculate_entropy(wf): 51 | """Calculates the entropy after tracing out the left qbit. 52 | 53 | To calculate the entanglement entropy you need to first build the 54 | reduced density matrix tracing out the degrees of freedom of one of 55 | the two qbits (it does not matter which, we pick up left here.) 56 | 57 | Parameters 58 | ---------- 59 | wf : a Wavefunction 60 | The wavefunction you build up the reduced density matrix with. 61 | 62 | Returns 63 | ------- 64 | result : a double 65 | The value of the von Neumann entanglement entropy after tracing 66 | out the left qbit. 67 | """ 68 | reduced_DM_for_right_qbit = wf.build_reduced_density_matrix('left') 69 | evals, evecs = diagonalize(reduced_DM_for_right_qbit) 70 | result = calculate_entropy(evals) 71 | return result 72 | 73 | def main(args): 74 | """Calculates the entanglement entropy for a system of two qbits in a 75 | singlet state. 76 | """ 77 | # 78 | # get a bunch of values (number_of_psi) for psi 79 | # 80 | number_of_psi = 1000 81 | step = 2*pi/number_of_psi 82 | psi_values = [x*step for x in range(number_of_psi)] 83 | # 84 | # python function map applies a function to a sequence 85 | # 86 | wfs = map(create_two_qbit_system_in_singlet, psi_values) 87 | entropies = map(trace_out_left_qbit_and_calculate_entropy, wfs) 88 | # 89 | # find to which value of psi corresponds the max entropy 90 | # 91 | zipped = zip(psi_values, entropies) 92 | max_value = max(zipped, key=lambda item: (item[1])) 93 | # 94 | # print the results 95 | # 96 | print "The maximum value for entropy is %8.6f." %max_value[1] 97 | print "The wavefunction with max entropy is: " 98 | print create_two_qbit_system_in_singlet(max_value[0]).as_matrix 99 | # 100 | # save for plotting 101 | # 102 | filename = args['--output'] 103 | f = open(filename, 'w') 104 | f.write('\n'.join('%s %s' % x for x in zipped)) 105 | f.close() 106 | 107 | if __name__ == '__main__': 108 | args = docopt(__doc__, version = 0.1) 109 | main(args) 110 | output_file = os.path.join(os.path.abspath(args['--dir']), args['--output']) 111 | print "The whole list of psi vs entropies is saved in", 112 | print output_file+'.' 113 | -------------------------------------------------------------------------------- /static/heisenberg_model.py: -------------------------------------------------------------------------------- 1 | """A few convenience functions to setup the Heisenberg model. 2 | 3 | .. math:: 4 | H=\sum_{i}\vec{S}_{i}\cdot\vec{S}_{i+1}= 5 | \sum_{i}\left[S^{z}_{i}S^{z}_{i+1}+ 6 | \frac{1}{2}\left(S^{\dagger}_{i}S^{-}_{i+1}+ 7 | S^{-}_{i}S^{\dagger}_{i+1}\right)\right] 8 | 9 | """ 10 | class HeisenbergModel(object): 11 | """Implements a few convenience functions for AF Heisenberg. 12 | 13 | Does exactly that. 14 | """ 15 | def __init__(self): 16 | super(HeisenbergModel, self).__init__() 17 | 18 | def set_hamiltonian(self, system): 19 | """Sets a system Hamiltonian to the AF Heisenberg Hamiltonian. 20 | 21 | Does exactly this. If the system hamiltonian has some other terms on 22 | it, there are not touched. So be sure to use this function only in 23 | newly created `System` objects. 24 | 25 | Parameters 26 | ---------- 27 | system : a System. 28 | The System you want to set the Hamiltonain for. 29 | """ 30 | system.clear_hamiltonian() 31 | if 'bh' in system.left_block.operators.keys(): 32 | system.add_to_hamiltonian(left_block_op='bh') 33 | if 'bh' in system.right_block.operators.keys(): 34 | system.add_to_hamiltonian(right_block_op='bh') 35 | system.add_to_hamiltonian('id', 'id', 's_z', 's_z') 36 | system.add_to_hamiltonian('id', 'id', 's_p', 's_m', .5) 37 | system.add_to_hamiltonian('id', 'id', 's_m', 's_p', .5) 38 | system.add_to_hamiltonian('id', 's_z', 's_z', 'id') 39 | system.add_to_hamiltonian('id', 's_p', 's_m', 'id', .5) 40 | system.add_to_hamiltonian('id', 's_m', 's_p', 'id', .5) 41 | system.add_to_hamiltonian('s_z', 's_z', 'id', 'id') 42 | system.add_to_hamiltonian('s_p', 's_m', 'id', 'id', .5) 43 | system.add_to_hamiltonian('s_m', 's_p', 'id', 'id', .5) 44 | 45 | def set_block_hamiltonian(self, tmp_matrix_for_bh, system): 46 | """Sets the block Hamiltonian to be what you need for AF Heisenberg. 47 | 48 | Parameters 49 | ---------- 50 | tmp_matrix_for_bh : a numpy array of ndim = 2. 51 | An auxiliary matrix to keep track of the result. 52 | system : a System. 53 | The System you want to set the Hamiltonian for. 54 | """ 55 | # If you have a block hamiltonian in your block, add it 56 | if 'bh' in system.growing_block.operators.keys(): 57 | system.add_to_block_hamiltonian(tmp_matrix_for_bh, 'bh', 'id') 58 | system.add_to_block_hamiltonian(tmp_matrix_for_bh, 's_z', 's_z') 59 | system.add_to_block_hamiltonian(tmp_matrix_for_bh, 's_p', 's_m', .5) 60 | system.add_to_block_hamiltonian(tmp_matrix_for_bh, 's_m', 's_p', .5) 61 | 62 | def set_operators_to_update(self, system): 63 | """Sets the operators to update to be what you need to AF Heisenberg. 64 | 65 | Parameters 66 | ---------- 67 | system : a System. 68 | The System you want to set the Hamiltonian for. 69 | 70 | Notes 71 | ----- 72 | The block Hamiltonian, althought needs to be updated, is treated 73 | separately by the very functions in the `System` class. 74 | """ 75 | system.add_to_operators_to_update('s_z', site_op='s_z') 76 | system.add_to_operators_to_update('s_p', site_op='s_p') 77 | system.add_to_operators_to_update('s_m', site_op='s_m') 78 | -------------------------------------------------------------------------------- /static/hubbard_helpers.py: -------------------------------------------------------------------------------- 1 | """ A file with some stuff to use in the docs. 2 | 3 | This file is **not** meant to be used in the actual code. It just copies a 4 | couple of functions from the dmrg101.core package to display them in the 5 | tutorial docs. 6 | """ 7 | 8 | class ElectronicSite(Site): 9 | """A site for electronic models 10 | 11 | You use this site for models where the single sites are electron 12 | sites. The Hilbert space is ordered such as: 13 | 14 | - the first state, labelled 0, is the empty site, 15 | - the second, labelled 1, is spin down, 16 | - the third, labelled 2, is spin up, and 17 | - the fourth, labelled 3, is double occupancy. 18 | 19 | Notes 20 | ----- 21 | Postcond: The site has already built-in the spin operators for: 22 | 23 | - c_up : destroys an spin up electron, 24 | - c_up_dag, creates an spin up electron, 25 | - c_down, destroys an spin down electron, 26 | - c_down_dag, creates an spin down electron, 27 | - s_z, component z of spin, 28 | - s_p, raises the component z of spin, 29 | - s_m, lowers the component z of spin, 30 | - n_up, number of electrons with spin up, 31 | - n_down, number of electrons with spin down, 32 | - n, number of electrons, i.e. n_up+n_down, and 33 | - u, number of double occupancies, i.e. n_up*n_down. 34 | 35 | """ 36 | def __init__(self): 37 | super(ElectronicSite, self).__init__(4) 38 | # add the operators 39 | self.add_operator("c_up") 40 | self.add_operator("c_up_dag") 41 | self.add_operator("c_down") 42 | self.add_operator("c_down_dag") 43 | self.add_operator("s_z") 44 | self.add_operator("s_p") 45 | self.add_operator("s_m") 46 | self.add_operator("n_up") 47 | self.add_operator("n_down") 48 | self.add_operator("n") 49 | self.add_operator("u") 50 | # for clarity 51 | c_up = self.operators["c_up"] 52 | c_up_dag = self.operators["c_up_dag"] 53 | c_down = self.operators["c_down"] 54 | c_down_dag = self.operators["c_down_dag"] 55 | s_z = self.operators["s_z"] 56 | s_p = self.operators["s_p"] 57 | s_m = self.operators["s_m"] 58 | n_up = self.operators["n_up"] 59 | n_down = self.operators["n_down"] 60 | n = self.operators["n"] 61 | u = self.operators["u"] 62 | # set the matrix elements different from zero to the right values 63 | # TODO: missing s_p, s_m 64 | c_up[0,2] = 1.0 65 | c_up[1,3] = 1.0 66 | c_up_dag[2,0] = 1.0 67 | c_up_dag[3,1] = 1.0 68 | c_down[0,1] = 1.0 69 | c_down[2,3] = 1.0 70 | c_down_dag[1,0] = 1.0 71 | c_down_dag[3,2] = 1.0 72 | s_z[1,1] = -1.0 73 | s_z[2,2] = 1.0 74 | n_up[2,2] = 1.0 75 | n_up[3,3] = 1.0 76 | n_down[1,1] = 1.0 77 | n_down[3,3] = 1.0 78 | n[1,1] = 1.0 79 | n[2,2] = 1.0 80 | n[3,3] = 2.0 81 | u[3,3] = 1.0 82 | 83 | class HubbardModel(object): 84 | """Implements a few convenience functions for Hubbard model. 85 | 86 | Does exactly that. 87 | """ 88 | def __init__(self): 89 | super(HubbardModel, self).__init__() 90 | 91 | def set_hamiltonian(self, system): 92 | """Sets a system Hamiltonian to the Hubbard Hamiltonian. 93 | 94 | Does exactly this. If the system hamiltonian has some other terms on 95 | it, there are not touched. So be sure to use this function only in 96 | newly created `System` objects. 97 | 98 | Parameters 99 | ---------- 100 | system : a System. 101 | The System you want to set the Hamiltonian for. 102 | """ 103 | system.clear_hamiltonian() 104 | if 'bh' in system.left_block.operators.keys(): 105 | system.add_to_hamiltonian(left_block_op='bh') 106 | if 'bh' in system.right_block.operators.keys(): 107 | system.add_to_hamiltonian(right_block_op='bh') 108 | system.add_to_hamiltonian('c_up', 'c_up_dag', 'id', 'id', -1.) 109 | system.add_to_hamiltonian('c_up_dag', 'c_up', 'id', 'id', -1.) 110 | system.add_to_hamiltonian('c_down', 'c_down_dag', 'id', 'id', -1.) 111 | system.add_to_hamiltonian('c_down_dag', 'c_down', 'id', 'id', -1.) 112 | system.add_to_hamiltonian('id', 'c_up', 'c_up_dag', 'id', -1.) 113 | system.add_to_hamiltonian('id', 'c_up_dag', 'c_up', 'id', -1.) 114 | system.add_to_hamiltonian('id', 'c_down', 'c_down_dag', 'id', -1.) 115 | system.add_to_hamiltonian('id', 'c_down_dag', 'c_down', 'id', -1.) 116 | system.add_to_hamiltonian('id', 'id', 'c_up', 'c_up_dag', -1.) 117 | system.add_to_hamiltonian('id', 'id', 'c_up_dag', 'c_up', -1.) 118 | system.add_to_hamiltonian('id', 'id', 'c_down', 'c_down_dag', -1.) 119 | system.add_to_hamiltonian('id', 'id', 'c_down_dag', 'c_down', -1.) 120 | system.add_to_hamiltonian('u', 'id', 'id', 'id', self.U) 121 | system.add_to_hamiltonian('id', 'u', 'id', 'id', self.U) 122 | system.add_to_hamiltonian('id', 'id', 'u', 'id', self.U) 123 | system.add_to_hamiltonian('id', 'id', 'id', 'u', self.U) 124 | 125 | def set_block_hamiltonian(self, system): 126 | """Sets the block Hamiltonian to the Hubbard model block Hamiltonian. 127 | 128 | Parameters 129 | ---------- 130 | system : a System. 131 | The System you want to set the Hamiltonian for. 132 | """ 133 | # If you have a block hamiltonian in your block, add it 134 | if 'bh' in system.growing_block.operators.keys(): 135 | system.add_to_block_hamiltonian('bh', 'id') 136 | system.add_to_block_hamiltonian('c_up', 'c_up_dag', -1.) 137 | system.add_to_block_hamiltonian('c_up_dag', 'c_up', -1.) 138 | system.add_to_block_hamiltonian('c_down', 'c_down_dag', -1.) 139 | system.add_to_block_hamiltonian('c_down_dag', 'c_down', -1.) 140 | system.add_to_block_hamiltonian('id', 'u', self.U) 141 | system.add_to_block_hamiltonian('u', 'id', self.U) 142 | 143 | def set_operators_to_update(self, system): 144 | """Sets the operators to update to the ones for the Hubbard model. 145 | 146 | Parameters 147 | ---------- 148 | system : a System. 149 | The System you want to set the Hamiltonian for. 150 | """ 151 | # If you have a block hamiltonian in your block, update it 152 | if 'bh' in system.growing_block.operators.keys(): 153 | system.add_to_operators_to_update('bh', block_op='bh') 154 | system.add_to_operators_to_update('c_up', site_op='c_up') 155 | system.add_to_operators_to_update('c_up_dag', site_op='c_up_dag') 156 | system.add_to_operators_to_downdate('c_down', site_op='c_down') 157 | system.add_to_operators_to_downdate('c_down_dag', site_op='c_down_dag') 158 | system.add_to_operators_to_update('u', site_op='u') 159 | -------------------------------------------------------------------------------- /static/tfim_helpers.py: -------------------------------------------------------------------------------- 1 | """A few convenience functions to setup the Ising model in a TF. 2 | 3 | TFIM stands for Ising model in a transverse field, i.e.: 4 | 5 | .. math:: 6 | H=\sum_{i}\left[S^{z}_{i}S^{z}_{i+1} + h S^{x}_{i}\right)\right] 7 | 8 | This file is **not** meant to be used in the actual code. It just copies a 9 | couple of functions from the dmrg101.core package to display them in the 10 | tutorial docs. 11 | """ 12 | class TranverseFieldIsingModel(object): 13 | """Implements a few convenience functions for the TFIM. 14 | 15 | Does exactly that. 16 | """ 17 | def __init__(self, h = 0): 18 | super(TranverseFieldIsingModel, self).__init__() 19 | self.h = h 20 | 21 | def set_hamiltonian(self, system): 22 | """Sets a system Hamiltonian to the TFIM Hamiltonian. 23 | 24 | Does exactly this. If the system hamiltonian has some other terms on 25 | it, there are not touched. So be sure to use this function only in 26 | newly created `System` objects. 27 | 28 | Parameters 29 | ---------- 30 | system : a System. 31 | The System you want to set the Hamiltonain for. 32 | """ 33 | system.clear_hamiltonian() 34 | if 'bh' in system.left_block.operators.keys(): 35 | system.add_to_hamiltonian(left_block_op='bh') 36 | if 'bh' in system.right_block.operators.keys(): 37 | system.add_to_hamiltonian(right_block_op='bh') 38 | system.add_to_hamiltonian('id', 'id', 's_z', 's_z') 39 | system.add_to_hamiltonian('id', 's_z', 's_z', 'id') 40 | system.add_to_hamiltonian('s_z', 's_z', 'id', 'id') 41 | system.add_to_hamiltonian('id', 'id', 'id', 's_x', self.h) 42 | system.add_to_hamiltonian('id', 'id', 's_x', 'id', self.h) 43 | system.add_to_hamiltonian('id', 's_x', 'id', 'id', self.h) 44 | system.add_to_hamiltonian('s_x', 'id', 'id', 'id', self.h) 45 | 46 | def set_block_hamiltonian(self, system): 47 | """Sets the block Hamiltonian to be what you need for TFIM. 48 | 49 | Parameters 50 | ---------- 51 | system : a System. 52 | The System you want to set the Hamiltonian for. 53 | """ 54 | # If you have a block hamiltonian in your block, add it 55 | if 'bh' in system.growing_block.operators.keys(): 56 | system.add_to_block_hamiltonian('bh', 'id') 57 | system.add_to_block_hamiltonian('s_z', 's_z') 58 | system.add_to_hamiltonian('id', 's_x', self.h) 59 | system.add_to_hamiltonian('s_x', 'id', self.h) 60 | 61 | def set_operators_to_update(self, system): 62 | """Sets the operators to update to be what you need to TFIM. 63 | 64 | Parameters 65 | ---------- 66 | system : a System. 67 | The System you want to set the Hamiltonian for. 68 | """ 69 | # If you have a block hamiltonian in your block, update it 70 | if 'bh' in system.growing_block.operators.keys(): 71 | system.add_to_operators_to_update('bh', block_op='bh') 72 | system.add_to_operators_to_update('s_z', site_op='s_z') 73 | system.add_to_operators_to_update('s_x', site_op='s_x') 74 | --------------------------------------------------------------------------------