Skip to content

Commit b9ff75a

Browse files
committed
Add example for TL-CTMRG
1 parent e5b1bfd commit b9ff75a

File tree

2 files changed

+117
-3
lines changed

2 files changed

+117
-3
lines changed

examples/heisenberg_afm_square.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
## Select the method used to calculate the descent direction during optimization
1919
varipeps.config.optimizer_method = varipeps.config.Optimizing_Methods.CG
2020
## Select the method used to calculate the (full) projectors in the CTMRG routine
21-
varipeps.config.ctmrg_full_projector_method = (
22-
varipeps.config.Projector_Method.FISHMAN
23-
)
21+
varipeps.config.ctmrg_full_projector_method = varipeps.config.Projector_Method.FISHMAN
2422
## Set maximal steps for the optimization routine
2523
varipeps.config.optimizer_max_steps = 2000
2624
## Increase enviroment bond dimension if truncation error is below this value
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import varipeps
2+
import jax
3+
import jax.numpy as jnp
4+
5+
# Config Setting
6+
## Set maximal steps for the CTMRG routine
7+
varipeps.config.ad_custom_max_steps = 100
8+
## Set maximal steps for the fix point routine in the gradient calculation
9+
varipeps.config.ctmrg_max_steps = 100
10+
## Set convergence threshold for the CTMRG routine
11+
varipeps.config.ctmrg_convergence_eps = 1e-7
12+
## Set convergence threshold for the fix point routine in the gradient calculation
13+
varipeps.config.ad_custom_convergence_eps = 5e-8
14+
## Enable/Disable printing of the convergence of the single CTMRG/gradient fix point steps.
15+
## Useful to enable this during debugging, should be disabled for batch runs
16+
varipeps.config.ctmrg_print_steps = True
17+
varipeps.config.ad_custom_print_steps = False
18+
## Select the method used to calculate the descent direction during optimization
19+
varipeps.config.optimizer_method = varipeps.config.Optimizing_Methods.L_BFGS
20+
## Select the method used to calculate the (full) projectors in the CTMRG routine
21+
varipeps.config.ctmrg_full_projector_method = varipeps.config.Projector_Method.FISHMAN
22+
## Set maximal steps for the optimization routine
23+
varipeps.config.optimizer_max_steps = 2000
24+
## Increase enviroment bond dimension if truncation error is below this value
25+
varipeps.config.ctmrg_heuristic_increase_chi_threshold = 1e-4
26+
27+
# Set constants for the simulation
28+
modelName = "HeisenbergModel"
29+
# Interaction strength
30+
J = 1
31+
# iPEPS bond dimension
32+
chiB = 2
33+
# Physical dimension
34+
p = 2
35+
# Maximal enviroment bond dimension
36+
maxChi = 64
37+
# Start value for enviroment bond dimension
38+
startChi = maxChi
39+
40+
# define spin-1/2 matrices
41+
Id = jnp.eye(2)
42+
Sx = jnp.array([[0, 1], [1, 0]]) / 2
43+
Sy = jnp.array([[0, -1j], [1j, 0]]) / 2
44+
Sz = jnp.array([[1, 0], [0, -1]]) / 2
45+
46+
# construct Hamiltonian terms
47+
hamiltonianGates = J * (jnp.kron(Sx, Sx) + jnp.kron(Sy, Sy) + jnp.kron(Sz, Sz))
48+
49+
# create function to compute expectation values for the square Heisenberg AFM
50+
exp_func = (
51+
varipeps.expectation.triangular_two_sites.Triangular_Two_Sites_Expectation_Value(
52+
horizontal_gates=(hamiltonianGates,),
53+
vertical_gates=(hamiltonianGates,),
54+
diagonal_gates=(hamiltonianGates,),
55+
real_d=2,
56+
is_spiral_peps=True,
57+
spiral_unitary_operator=Sy,
58+
)
59+
)
60+
61+
# Unit cell structure
62+
structure = [[0]]
63+
64+
# Create random initialization for the iPEPS unit cell
65+
unitcell = varipeps.peps.PEPS_Unit_Cell.random(
66+
structure, # Unit cell structure
67+
p, # Physical dimension
68+
chiB, # iPEPS bond dimension
69+
startChi, # Start value for enviroment bond dimension
70+
float, # Data type for the tensors: float (real) or complex tensors
71+
max_chi=maxChi, # Maximal enviroment bond dimension
72+
peps_type=varipeps.peps.PEPS_Type.TRIANGULAR, # Select triangular PEPS
73+
)
74+
75+
# Run optimization
76+
result = varipeps.optimization.optimize_unitcell_fixed_spiral_vector(
77+
unitcell,
78+
jnp.array((2 / 3, 2 / 3), dtype=jnp.float64), # Spiral vector
79+
exp_func,
80+
autosave_filename=f"data/autosave_triangular_chiB_{chiB:d}.hdf5",
81+
)
82+
83+
# Calculate magnetic expectation values
84+
Mag_Gates = [Sx, Sy, Sz]
85+
86+
87+
def calc_magnetic(unitcell):
88+
mag_result = []
89+
for ti, t in enumerate(unitcell.get_unique_tensors()):
90+
r = varipeps.expectation.triangular_one_site.calc_triangular_one_site(
91+
t.tensor, t, Mag_Gates
92+
)
93+
mag_result += r
94+
return mag_result
95+
96+
97+
magnetic_exp_values = calc_magnetic(result.unitcell)
98+
99+
# Define some auxiliary data which should be stored along the final iPEPS unit cell
100+
auxiliary_data = {
101+
"best_energy": result.fun,
102+
"best_run": result.best_run,
103+
"magnetic_exp_values": magnetic_exp_values,
104+
}
105+
for k in sorted(result.max_trunc_error_list.keys()):
106+
auxiliary_data[f"max_trunc_error_list_{k:d}"] = result.max_trunc_error_list[k]
107+
auxiliary_data[f"step_energies_{k:d}"] = result.step_energies[k]
108+
auxiliary_data[f"step_chi_{k:d}"] = result.step_chi[k]
109+
auxiliary_data[f"step_conv_{k:d}"] = result.step_conv[k]
110+
auxiliary_data[f"step_runtime_{k:d}"] = result.step_runtime[k]
111+
112+
# save full iPEPS state
113+
result.unitcell.save_to_file(
114+
f"data/heisenberg_triangular_J_{J:d}_chiB_{chiB:d}_chiMax_{chiM:d}.hdf5",
115+
auxiliary_data=auxiliary_data,
116+
)

0 commit comments

Comments
 (0)