# If running from google colab change to TRUE
run_from_colab = False # True if using google colab
You can clone the latest tnsu
repo from github or run
!pip install tnsu
import sys
import os
if run_from_colab:
# clone the git reposetory
!git clone https://github.com/RoyElkabetz/Tensor-Networks-Simple-Update
# add path to .py files for import
sys.path.insert(1, "/content/Tensor-Networks-Simple-Update/src")
# mount google drive
from google.colab import drive
drive.mount('/content/gdrive')
# path for saving the networks
save_path = '/content/gdrive/MyDrive/tmp'
else:
# clone the git reposetory
!git clone https://github.com/RoyElkabetz/Tensor-Networks-Simple-Update
# add path to .py files for import
sys.path.insert(1, "Tensor-Networks-Simple-Update/src")
# path for saving the networks
save_path = '../tmp/networks'
if not os.path.exists(save_path):
os.makedirs(save_path)
fatal: destination path 'Tensor-Networks-Simple-Update' already exists and is not an empty directory.
import numpy as np
import matplotlib.pyplot as plt
from tnsu.tensor_network import TensorNetwork
import tnsu.simple_update as su
np.random.seed(216)
plt.rcParams.update({'font.size': 16,
"figure.facecolor": 'white',
"axes.facecolor": 'white',
"savefig.facecolor": 'white',
'savefig.edgecolor' : 'white',
'figure.edgecolor' : 'white'})
The ITF Hamiltonian is given by
H=−J∑<i,j>σzi⋅σzj−h∑iσxi# The Tensor Network structure matrix
ising_structure_matrix = np.array([[1, 2, 3, 4, 0, 0, 0, 0],
[1, 2, 0, 0, 3, 4, 0, 0],
[0, 0, 1, 2, 0, 0, 3, 4,],
[0, 0, 0, 0, 1, 2, 3, 4]])
# Simple-Update parameters
d_max_ising = [2]
error = 1e-6
max_iterations = 200
ising_energy = []
ising_z_magnetizaton = []
ising_x_magnetizaton = []
j_ij_ising = [-1.] * 8
dts = [0.1, 0.01, 0.001, 0.0001, 0.00001]
h_k = -np.linspace(0, 4, 60)
# Pauli matrices
pauli_x = np.array([[0, 1],
[1, 0]])
pauli_y = np.array([[0, -1j],
[1j, 0]])
pauli_z = np.array([[1, 0],
[0, -1]])
s_i = [pauli_z]
s_j = [pauli_z]
s_k = [pauli_x]
# Run
for d_max in d_max_ising:
for h in h_k:
ising = TensorNetwork(structure_matrix=ising_structure_matrix,
virtual_dim=d_max)
ising_su = su.SimpleUpdate(tensor_network=ising,
dts=dts,
j_ij=j_ij_ising,
h_k=h,
s_i=s_i,
s_j=s_j,
s_k=s_k,
d_max=d_max,
max_iterations=max_iterations,
convergence_error=error,
log_energy=False,
print_process=False)
ising_su.run()
energy = ising_su.energy_per_site()
z_magnetization = ising_su.expectation_per_site(pauli_z)
x_magnetization = ising_su.expectation_per_site(pauli_x)
print('| D max: {:3d} | h: {:3.10f} | Energy: {:3.10f} | Mz: {:3.10f} | Mx: {:3.10f} |'
.format(d_max, h, energy, z_magnetization, x_magnetization))
ising_energy.append(energy)
ising_z_magnetizaton.append(z_magnetization)
ising_x_magnetizaton.append(x_magnetization)
Exception ignored in: <function tqdm.__del__ at 0x7f7df822b5e0> Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tqdm/std.py", line 1145, in __del__ self.close() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tqdm/notebook.py", line 283, in close self.disp(bar_style='danger', check_delay=False) AttributeError: 'tqdm' object has no attribute 'disp'
==> Simple Update converged. final error is 0.0000000000 < 0.0000010000. | D max: 2 | h: -0.0000000000 | Energy: -1.9999999997 | Mz: 0.9999999999 | Mx: 0.0000120168 | ==> Simple Update converged. final error is 0.0000000011 < 0.0000010000. | D max: 2 | h: -0.0677966102 | Energy: -2.0005745609 | Mz: -0.9998562105 | Mx: 0.0169572669 | ==> Simple Update converged. final error is 0.0000000018 < 0.0000010000. | D max: 2 | h: -0.1355932203 | Energy: -2.0022984096 | Mz: -0.9994249695 | Mx: 0.0339055010 | ==> Simple Update converged. final error is 0.0000000029 < 0.0000010000. | D max: 2 | h: -0.2033898305 | Energy: -2.0051720406 | Mz: -0.9987049077 | Mx: 0.0508700458 | ==> Simple Update converged. final error is 0.0000000046 < 0.0000010000. | D max: 2 | h: -0.2711864407 | Energy: -2.0091962803 | Mz: -0.9976943962 | Mx: 0.0678493320 | ==> Simple Update converged. final error is 0.0000000067 < 0.0000010000. | D max: 2 | h: -0.3389830508 | Energy: -2.0143722883 | Mz: 0.9963909671 | Mx: 0.0848485028 | ==> Simple Update converged. final error is 0.0000000095 < 0.0000010000. | D max: 2 | h: -0.4067796610 | Energy: -2.0207015590 | Mz: 0.9947914672 | Mx: 0.1018721674 | ==> Simple Update converged. final error is 0.0000000109 < 0.0000010000. | D max: 2 | h: -0.4745762712 | Energy: -2.0281859371 | Mz: 0.9928919761 | Mx: 0.1189253465 | ==> Simple Update converged. final error is 0.0000000112 < 0.0000010000. | D max: 2 | h: -0.5423728814 | Energy: -2.0368276047 | Mz: -0.9906877745 | Mx: 0.1360132323 | ==> Simple Update converged. final error is 0.0000000117 < 0.0000010000. | D max: 2 | h: -0.6101694915 | Energy: -2.0466290810 | Mz: -0.9881733257 | Mx: 0.1531410128 | ==> Simple Update converged. final error is 0.0000000123 < 0.0000010000. | D max: 2 | h: -0.6779661017 | Energy: -2.0575932480 | Mz: -0.9853422367 | Mx: 0.1703139373 | ==> Simple Update converged. final error is 0.0000000127 < 0.0000010000. | D max: 2 | h: -0.7457627119 | Energy: -2.0697233480 | Mz: 0.9821872055 | Mx: 0.1875373340 | ==> Simple Update converged. final error is 0.0000000133 < 0.0000010000. | D max: 2 | h: -0.8135593220 | Energy: -2.0830229877 | Mz: 0.9786998844 | Mx: 0.2048169880 | ==> Simple Update converged. final error is 0.0000000138 < 0.0000010000. | D max: 2 | h: -0.8813559322 | Energy: -2.0974961544 | Mz: -0.9748710528 | Mx: 0.2221579837 | ==> Simple Update converged. final error is 0.0000000144 < 0.0000010000. | D max: 2 | h: -0.9491525424 | Energy: -2.1131472160 | Mz: 0.9706901963 | Mx: 0.2395663700 | ==> Simple Update converged. final error is 0.0000000153 < 0.0000010000. | D max: 2 | h: -1.0169491525 | Energy: -2.1299809381 | Mz: 0.9661456323 | Mx: 0.2570480867 | ==> Simple Update converged. final error is 0.0000000159 < 0.0000010000. | D max: 2 | h: -1.0847457627 | Energy: -2.1480024979 | Mz: -0.9612242914 | Mx: 0.2746094447 | ==> Simple Update converged. final error is 0.0000000167 < 0.0000010000. | D max: 2 | h: -1.1525423729 | Energy: -2.1672174856 | Mz: 0.9559118547 | Mx: 0.2922562475 | ==> Simple Update converged. final error is 0.0000000175 < 0.0000010000. | D max: 2 | h: -1.2203389831 | Energy: -2.1876319308 | Mz: -0.9501921915 | Mx: 0.3099952663 | ==> Simple Update converged. final error is 0.0000000185 < 0.0000010000. | D max: 2 | h: -1.2881355932 | Energy: -2.2092523090 | Mz: -0.9440474448 | Mx: 0.3278333305 | ==> Simple Update converged. final error is 0.0000000193 < 0.0000010000. | D max: 2 | h: -1.3559322034 | Energy: -2.2320855694 | Mz: -0.9374577057 | Mx: 0.3457777383 | ==> Simple Update converged. final error is 0.0000000204 < 0.0000010000. | D max: 2 | h: -1.4237288136 | Energy: -2.2561391383 | Mz: -0.9304012220 | Mx: 0.3638351679 | ==> Simple Update converged. final error is 0.0000000218 < 0.0000010000. | D max: 2 | h: -1.4915254237 | Energy: -2.2814209503 | Mz: 0.9228533553 | Mx: 0.3820137144 | ==> Simple Update converged. final error is 0.0000000239 < 0.0000010000. | D max: 2 | h: -1.5593220339 | Energy: -2.3079394664 | Mz: 0.9147867891 | Mx: 0.4003215070 | ==> Simple Update converged. final error is 0.0000000261 < 0.0000010000. | D max: 2 | h: -1.6271186441 | Energy: -2.3357037116 | Mz: 0.9061708967 | Mx: 0.4187673444 | ==> Simple Update converged. final error is 0.0000000285 < 0.0000010000. | D max: 2 | h: -1.6949152542 | Energy: -2.3647232868 | Mz: -0.8969722399 | Mx: 0.4373588920 | ==> Simple Update converged. final error is 0.0000000310 < 0.0000010000. | D max: 2 | h: -1.7627118644 | Energy: -2.3950084023 | Mz: -0.8871524235 | Mx: 0.4561059990 | ==> Simple Update converged. final error is 0.0000000338 < 0.0000010000. | D max: 2 | h: -1.8305084746 | Energy: -2.4265699127 | Mz: -0.8766685544 | Mx: 0.4750184800 | ==> Simple Update converged. final error is 0.0000000367 < 0.0000010000. | D max: 2 | h: -1.8983050847 | Energy: -2.4594193523 | Mz: -0.8654722035 | Mx: 0.4941067294 | ==> Simple Update converged. final error is 0.0000000400 < 0.0000010000. | D max: 2 | h: -1.9661016949 | Energy: -2.4935689751 | Mz: -0.8535084653 | Mx: 0.5133817833 | ==> Simple Update converged. final error is 0.0000000436 < 0.0000010000. | D max: 2 | h: -2.0338983051 | Energy: -2.5290317987 | Mz: 0.8407148004 | Mx: 0.5328553858 | ==> Simple Update converged. final error is 0.0000000519 < 0.0000010000. | D max: 2 | h: -2.1016949153 | Energy: -2.5658216536 | Mz: -0.8270206581 | Mx: 0.5525386869 | ==> Simple Update converged. final error is 0.0000000688 < 0.0000010000. | D max: 2 | h: -2.1694915254 | Energy: -2.6039532348 | Mz: -0.8123415800 | Mx: 0.5724477334 | ==> Simple Update converged. final error is 0.0000000888 < 0.0000010000. | D max: 2 | h: -2.2372881356 | Energy: -2.6434421652 | Mz: -0.7965842192 | Mx: 0.5925940102 | ==> Simple Update converged. final error is 0.0000001091 < 0.0000010000. | D max: 2 | h: -2.3050847458 | Energy: -2.6843050622 | Mz: 0.7796357163 | Mx: 0.6129943846 | ==> Simple Update converged. final error is 0.0000001345 < 0.0000010000. | D max: 2 | h: -2.3728813559 | Energy: -2.7265595991 | Mz: -0.7613641023 | Mx: 0.6336656878 | ==> Simple Update converged. final error is 0.0000001632 < 0.0000010000. | D max: 2 | h: -2.4406779661 | Energy: -2.7702246088 | Mz: 0.7416120989 | Mx: 0.6546261614 | ==> Simple Update converged. final error is 0.0000001949 < 0.0000010000. | D max: 2 | h: -2.5084745763 | Energy: -2.8153201641 | Mz: -0.7201953193 | Mx: 0.6758909696 | ==> Simple Update converged. final error is 0.0000002294 < 0.0000010000. | D max: 2 | h: -2.5762711864 | Energy: -2.8618676803 | Mz: 0.6968747640 | Mx: 0.6974884602 | ==> Simple Update converged. final error is 0.0000002662 < 0.0000010000. | D max: 2 | h: -2.6440677966 | Energy: -2.9098900415 | Mz: -0.6713706611 | Mx: 0.7194353770 | ==> Simple Update converged. final error is 0.0000003043 < 0.0000010000. | D max: 2 | h: -2.7118644068 | Energy: -2.9594117242 | Mz: 0.6433109922 | Mx: 0.7417631700 | ==> Simple Update converged. final error is 0.0000003424 < 0.0000010000. | D max: 2 | h: -2.7796610169 | Energy: -3.0104589575 | Mz: -0.6122263293 | Mx: 0.7644965170 | ==> Simple Update converged. final error is 0.0000003784 < 0.0000010000. | D max: 2 | h: -2.8474576271 | Energy: -3.0630598874 | Mz: -0.5774714847 | Mx: 0.7876723886 | ==> Simple Update converged. final error is 0.0000004091 < 0.0000010000. | D max: 2 | h: -2.9152542373 | Energy: -3.1172447813 | Mz: -0.5381562763 | Mx: 0.8113254466 | ==> Simple Update converged. final error is 0.0000004311 < 0.0000010000. | D max: 2 | h: -2.9830508475 | Energy: -3.1730462005 | Mz: -0.4928628913 | Mx: 0.8355424375 | ==> Simple Update converged. final error is 0.0000004017 < 0.0000010000. | D max: 2 | h: -3.0508474576 | Energy: -3.2304991004 | Mz: -0.4391370362 | Mx: 0.8604882092 | ==> Simple Update converged. final error is 0.0000003704 < 0.0000010000. | D max: 2 | h: -3.1186440678 | Energy: -3.2896391827 | Mz: -0.3714490838 | Mx: 0.8866746207 | ==> Simple Update converged. final error is 0.0000002809 < 0.0000010000. | D max: 2 | h: -3.1864406780 | Energy: -3.3504475719 | Mz: 0.2617293979 | Mx: 0.9179402864 | ==> Simple Update converged. final error is 0.0000001011 < 0.0000010000. | D max: 2 | h: -3.2542372881 | Energy: -3.4130312047 | Mz: -0.0157501399 | Mx: 0.9474613624 | ==> Simple Update converged. final error is 0.0000000995 < 0.0000010000. | D max: 2 | h: -3.3220338983 | Energy: -3.4773510383 | Mz: -0.0061220514 | Mx: 0.9499163307 | ==> Simple Update converged. final error is 0.0000000996 < 0.0000010000. | D max: 2 | h: -3.3898305085 | Energy: -3.5418294421 | Mz: 0.0031098580 | Mx: 0.9521348522 | ==> Simple Update converged. final error is 0.0000000998 < 0.0000010000. | D max: 2 | h: -3.4576271186 | Energy: -3.6064523146 | Mz: 0.0018442022 | Mx: 0.9541952569 | ==> Simple Update converged. final error is 0.0000001000 < 0.0000010000. | D max: 2 | h: -3.5254237288 | Energy: -3.6712099285 | Mz: 0.0011625538 | Mx: 0.9561182326 | ==> Simple Update converged. final error is 0.0000001002 < 0.0000010000. | D max: 2 | h: -3.5932203390 | Energy: -3.7360934829 | Mz: -0.0009802413 | Mx: 0.9579170474 | ==> Simple Update converged. final error is 0.0000001004 < 0.0000010000. | D max: 2 | h: -3.6610169492 | Energy: -3.8010951146 | Mz: 0.0006927509 | Mx: 0.9596032237 | ==> Simple Update converged. final error is 0.0000001007 < 0.0000010000. | D max: 2 | h: -3.7288135593 | Energy: -3.8662074842 | Mz: 0.0003816074 | Mx: 0.9611863173 | ==> Simple Update converged. final error is 0.0000001010 < 0.0000010000. | D max: 2 | h: -3.7966101695 | Energy: -3.9314238638 | Mz: 0.0003206137 | Mx: 0.9626748199 | ==> Simple Update converged. final error is 0.0000001013 < 0.0000010000. | D max: 2 | h: -3.8644067797 | Energy: -3.9967381540 | Mz: -0.0002894299 | Mx: 0.9640764964 | ==> Simple Update converged. final error is 0.0000001016 < 0.0000010000. | D max: 2 | h: -3.9322033898 | Energy: -4.0621447229 | Mz: 0.0001679938 | Mx: 0.9653982247 | ==> Simple Update converged. final error is 0.0000001019 < 0.0000010000. | D max: 2 | h: -4.0000000000 | Energy: -4.1276383352 | Mz: 0.0002015268 | Mx: 0.9666461585 |
fig, ax = plt.subplots(1, 2, figsize=(17, 6))
ax[0].plot(-h_k, ising_energy, '--o', label=r'$\epsilon_0$', color='tab:red',
markerfacecolor='none', linewidth=1, markersize=10)
ax[0].set_xlabel(r'h')
ax[0].set_ylabel(r'$\epsilon_0$')
ax[0].set_title('$2D$ Ising model ground-state energy per-site')
ax[0].tick_params(direction='in', axis='both')
ax[0].grid()
ax[0].legend()
ax[1].plot(-h_k, np.abs(np.array(ising_z_magnetizaton)), '--o', label=r'$M_z$',
color='tab:blue', markerfacecolor='none', linewidth=1, markersize=10)
ax[1].plot(-h_k, ising_x_magnetizaton, '--o', label=r'$M_x$', color='tab:green',
markerfacecolor='none', linewidth=1, markersize=10)
ax[1].set_xlabel(r'h')
ax[1].set_ylabel(r'$M$')
ax[1].set_title(r'$2D$ Ising model $\hat{z}, \hat{x}$ magnetizations per-site')
ax[1].tick_params(direction='in', axis='both')
ax[1].grid()
ax[1].legend()
<matplotlib.legend.Legend at 0x7f7df826bbb0>