Example:
Here we explain how the example project "binaryMERA.ttp" provided with TensorTrace can be utilized in a tensor network algorithm which finds the ground state of a quantum spin chain.
Fig.1: (above) Depicted are the two networks contained in the "binaryMERA.ttp" example project. Upon exporting the code a function of the following form is generated:
tensor_out = binaryMERA(tensors_in, which_network, which_env)
Here the input argument "tensors_in" is a list of the unique tensors contained in the networks, counting from the 1st tensor of the 1st network, which in the present case is "tensors_in = [uDis, wIso, hamThree, rhoThee]". Note that this information regarding "tensors_in" can also be found in the header of the function file. The other arguments "which_network" and "which_env" dictate the network and tensor environment that should be returned (i.e. so setting "which_network = 2" and "which_env = 3" will return the environment of the tensor labelled N2.3 in the figure, which is the 3rd tensor of the 2nd network). Setting "which_env = 0" or omitting this argument entirely will return the scalar corresponding to the closed network. The autogenerated code is provided below (Python version):
The networks in Fig.1 are those necessary to optimize a MERA tensor network via variational energy minimization, such that it can provide an approximate representation of the ground state of a quantum system on a 1D lattice. While the details of this optimization algorithm are nontrivial, in essence the algorithm varies the parameters in the "uDis" and "wIso" tensors such as to minimize the scalar products associated to the networks of Fig.1 (which equate to the energy of our quantum state). This variational minimization involves iteratively computing the environments (or derivatives) of the tensors "uDis" and "wIso", which are easily obtained from the "binaryMERA" function given above.
A script file (Python version) containing the full variational MERA algorithm is presented below, and is composed of the following parts:

Defining the lattice Hamiltonian (here the critical transverse Ising model)

Initializing the tensors in the network

Performing variational sweeps, where each unique tensor in the network is updated in such a way as to reduce the energy of the quantum state represented by the MERA
After each sweep of the algorithm is complete, the current energy is printed to the console, which should be seen to converge slowly to the exactly known ground energy.