|
| 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.config.ctmrg_print_steps = True |
| 17 | +varipeps.config.config.ad_custom_print_steps = False |
| 18 | +## Select the method used to calculate the descent direction during optimization |
| 19 | +varipeps.config.config.optimizer_method = varipeps.config.Optimizing_Methods.CG |
| 20 | +## Select the method used to calculate the (full) projectors in the CTMRG routine |
| 21 | +varipeps.config.config.ctmrg_full_projector_method = ( |
| 22 | + varipeps.config.Projector_Method.FISHMAN |
| 23 | +) |
| 24 | +## Set maximal steps for the optimization routine |
| 25 | +varipeps.config.config.optimizer_max_steps = 2000 |
| 26 | +## Increase enviroment bond dimension if truncation error is below this value |
| 27 | +varipeps.config.config.ctmrg_heuristic_increase_chi_threshold = 1e-4 |
| 28 | + |
| 29 | +# Set constants for the simulation |
| 30 | +modelName = "HeisenbergModel" |
| 31 | +# Interaction strength |
| 32 | +J = 1 |
| 33 | +# iPEPS bond dimension |
| 34 | +chiB = 2 |
| 35 | +# Physical dimension |
| 36 | +p = 2 |
| 37 | +# Maximal enviroment bond dimension |
| 38 | +maxChi = 36 |
| 39 | +# Start value for enviroment bond dimension |
| 40 | +startChi = chiB**2 if chiB**2 < maxChi else maxChi |
| 41 | + |
| 42 | +# Unit cell structure |
| 43 | +structure = [[0, 1], [1, 0]] |
| 44 | + |
| 45 | +# define spin-1/2 matrices |
| 46 | +Id = jnp.eye(2) |
| 47 | +Sx = jnp.array([[0, 1], [1, 0]]) / 2 |
| 48 | +Sy = jnp.array([[0, -1j], [1j, 0]]) / 2 |
| 49 | +Sz = jnp.array([[1, 0], [0, -1]]) / 2 |
| 50 | + |
| 51 | +# construct Hamiltonian terms |
| 52 | +hamiltonianGates = J * (jnp.kron(Sx, Sx) + jnp.kron(Sy, Sy) + jnp.kron(Sz, Sz)) |
| 53 | + |
| 54 | +# create function to compute expectation values for the square Heisenberg AFM |
| 55 | +exp_func = varipeps.expectation.Two_Sites_Expectation_Value( |
| 56 | + horizontal_gates=(hamiltonianGates,), |
| 57 | + vertical_gates=(hamiltonianGates,), |
| 58 | +) |
| 59 | + |
| 60 | +# Create random initialization for the iPEPS unit cell |
| 61 | +unitcell = varipeps.peps.PEPS_Unit_Cell.random( |
| 62 | + structure, # Unit cell structure |
| 63 | + p, # Physical dimension |
| 64 | + chiB, # iPEPS bond dimension |
| 65 | + startChi, # Start value for enviroment bond dimension |
| 66 | + float, # Data type for the tensors: float (real) or complex tensors |
| 67 | + max_chi=maxChi, # Maximal enviroment bond dimension |
| 68 | +) |
| 69 | + |
| 70 | +# Run optimization |
| 71 | +result = varipeps.optimization.optimize_peps_network( |
| 72 | + unitcell, |
| 73 | + exp_func, |
| 74 | + autosave_filename=f"data/autosave_square_chiB_{chiB:d}.hdf5", |
| 75 | +) |
| 76 | + |
| 77 | +# Calculate magnetic expectation values |
| 78 | +Mag_Gates = [Sx, Sy, Sz] |
| 79 | + |
| 80 | + |
| 81 | +def calc_magnetic(unitcell): |
| 82 | + mag_result = [] |
| 83 | + for ti, t in enumerate(unitcell.get_unique_tensors()): |
| 84 | + r = varipeps.expectation.one_site.calc_one_site_multi_gates( |
| 85 | + t.tensor, t, Mag_Gates |
| 86 | + ) |
| 87 | + mag_result += r |
| 88 | + return mag_result |
| 89 | + |
| 90 | + |
| 91 | +magnetic_exp_values = calc_magnetic(result.unitcell) |
| 92 | + |
| 93 | +# Define some auxiliary data which should be stored along the final iPEPS unit cell |
| 94 | +auxiliary_data = { |
| 95 | + "best_energy": result.fun, |
| 96 | + "best_run": result.best_run, |
| 97 | + "magnetic_exp_values": magnetic_exp_values, |
| 98 | +} |
| 99 | +for k in sorted(result.max_trunc_error_list.keys()): |
| 100 | + auxiliary_data[f"max_trunc_error_list_{k:d}"] = result.max_trunc_error_list[k] |
| 101 | + auxiliary_data[f"step_energies_{k:d}"] = result.step_energies[k] |
| 102 | + auxiliary_data[f"step_chi_{k:d}"] = result.step_chi[k] |
| 103 | + auxiliary_data[f"step_conv_{k:d}"] = result.step_conv[k] |
| 104 | + auxiliary_data[f"step_runtime_{k:d}"] = result.step_runtime[k] |
| 105 | + |
| 106 | +# save full iPEPS state |
| 107 | +result.unitcell.save_to_file( |
| 108 | + f"data/heisenberg_square_J_{J:d}_chiB_{chiB:d}_chiMax_{chiM:d}.hdf5", |
| 109 | + auxiliary_data=auxiliary_data, |
| 110 | +) |
0 commit comments