Postprocessing

Guide to using the python postprocessing module.

The DMRG.x application comes with the python-based Postprocessing module in postproc/dmrg_postprocessing.py. In this tutorial, we look at some of the basic data processing and visualization that can be done with the output files provided by the application.

Output Files

The output files stored in the path provided to -data_dir are written in the JavaScript Object Notation (json) format for portability and human readability.

The data files typically consist of the following:

  • DMRGSteps.json - data on the number of sites and states of each block, truncation error, and ground state energy for each DMRG iteration
  • DMRGRun.json - parameters of the Hamiltonian and the number of kept states during the warmup and sweep stages
  • EntanglementSpectra.json - the eigenvalues of the reduced density matrices for the enlarged system and environement blocks for each iteration, grouped according to their magnetization sectors
  • Correlations.json - labels and values of the correlators calculated at the end of the warmup and after each sweep.
  • Timings.json - time spent at every major step of each DMRG iteration

The structure of the json files can be classified into a Dictionary, Table or Array. Tables are specific dictionary types where the main entries are "headers" and "table". These types of data files are read-in using their respective functions in JSON Utilities.

Postprocessing Single DMRG Runs

First, we load the module by adding the postproc directory to the python system path. We can also load other useful modules (numpy and pyplot)

import sys
sys.path.append("/path/to/DMRG.x/postproc")
import dmrg_postprocessing as dmrg
import numpy as np
import matplotlib.pyplot as plt

The dmrg_postprocessing.Data class can be used for postprocessing the output files for single DMRG runs.

jobs_dir = "/path/to/all/data_dirs"
data = dmrg.Data("data_dir",jobs_dir,label="Data1")

Using the visualization functions, one can for example plot the convergence of the energy as a function of DMRG steps:

data.PlotErrorEnergyPerSite(which='rel',marker='.')
plt.title("Convergence of the Energy")
plt.legend(loc=0)
plt.show()

Or the total time for each iteration:

data.PlotTotalTime()
plt.title("Runtime")
plt.legend(loc=0)
plt.grid()
plt.show()

And also the Von Neumann entropy calculated at the end of each sweep:

data.PlotEntanglementEntropy()
plt.grid(axis='y')
plt.show()

The data can also be printed directly onscreen:

print(data.EntanglementEntropy())

Or you can also write your own functions to post-process the output data:

def EnergyConvergence(data):
'''Energy difference between succesive sweeps'''
E = np.array(data.EnergyPerSite())[data.SweepIdx()]
diff = np.abs(E[1:] - E[:-1])
return diff
d = EnergyConvergence(data)
plt.semilogy(d,'-o')
plt.xlabel(r'Sweeps ($n$)')
plt.ylabel(r'$E_{n+1}-E_n$')
plt.grid()
plt.show()
Note
See the output of the above sample code and some additional examples in the following ipython notebook.
See also
Postprocessing, JSON Utilities, dmrg_postprocessing
This site was generated by Sphinx using Doxygen with a customized theme from doxygen-bootstrapped.