# 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
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
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
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:
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:
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 such as for plotting the energy convergence...
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()
... and the entanglement spectra
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$')
PlotEntanglementSpectra(data,-1,pos_sectors_only=True,color='#1f77b4')
plt.show()