Postprocessing Single DMRG Runs

[back] | DMRG.x Related Pages Postprocessing

In [1]:
# Notebook configuration settings
%matplotlib inline
%config InlineBackend.figure_format = 'svg'

Load the post-processing module by adding the postproc directory to the python system path

In [2]:
import sys
sys.path.append("/Users/jnvance/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

In [3]:
jobs_dir = "/Users/jnvance/Dropbox/MHPC-Thesis/DMRG_Postprocessing/JobsMarconi/"
data = dmrg.Data("TopoXY-0030-sweep_modes.sh-999118",jobs_dir,label="Data1")

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

In [4]:
data.PlotErrorEnergyPerSite(which='rel',marker='.')
plt.title("Convergence of the Energy")
plt.legend(loc=0)
plt.grid()
plt.show()

Or the total time for each iteration:

In [5]:
data.PlotTotalTime(units='min')
plt.title("Runtime")
plt.legend(loc=0)
plt.grid()
plt.show()

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

In [6]:
data.PlotEntanglementEntropy()
plt.grid(axis='y')
plt.show()

The data can also be printed directly onscreen:

In [7]:
print(data.EntanglementEntropy())
[1.6215595948556372, 1.6942884841233259, 1.705906435294797, 1.7077409199435452, 1.7081434323388536, 1.7082797775768204, 1.7375233975479756, 1.7398053098861488, 1.7400501472627519, 1.7401186230449921, 1.7401416950532567, 1.7480278034066112, 1.748508662152823, 1.7485638089188302, 1.7485752384365418]

Or you can also write your own functions to post-process the output data such as for plotting the energy convergence...

In [8]:
def EnergyConvergence(data):
    '''Energy difference between succesive sweeps'''
    E = np.array(data.EnergyPerSite())[data.SweepIdx()]
    diff = np.abs(E[1:] - E[:-1])
    return diff
In [9]:
d = EnergyConvergence(data)
plt.semilogy(d,'-o')
plt.xlabel(r'Sweeps ($n$)')
plt.ylabel(r'$E_{n+1}-E_n$')
plt.grid()
plt.show()

... and the entanglement spectra

In [10]:
def EntanglementSpectra(data,sweep,sector=None):
    '''Negative log of the density matrix eigenvalues at a particular DMRG step'''
    import itertools
    if sector is None:
        vals = [d['vals'] for d in data.RDMEigenvalues(sweep)]
    else:
        vals = [d['vals'] for d in data.RDMEigenvalues(sweep) if d['sector']==sector]
    vals = list(itertools.chain.from_iterable(vals))
    # filter out non-positive values
    vals = [v for v in vals if v>0]
    vals = -np.log(np.array(vals))
    vals[::-1].sort()
    return vals

def PlotEntanglementSpectra(data,sweep,pos_sectors_only=True,**kwargs):
    '''Plots the entanglement spectra at different magnetization sectors'''
    sectors = [d['sector'] for d in data.RDMEigenvalues(sweep) if (d['sector']>=0)]\
    if pos_sectors_only else [d['sector'] for d in data.RDMEigenvalues(sweep)]
    for sector in sectors:
        v = EntanglementSpectra(data,sweep,sector)
        d = np.zeros_like(v) + sector
        plt.plot(d,v,marker='_',markersize=8,linewidth=0,**kwargs)
    plt.xlabel(r'$\sum S^z$ sector')
    plt.ylabel(r'$\xi=-\log \lambda$')
In [11]:
PlotEntanglementSpectra(data,-1,pos_sectors_only=True,color='#1f77b4')
plt.show()