Tensor Network Theory Library  Beta release 1.2.1 A library of routines for performing TNT-based operations
create_exop.c

A simple example of creating an expectation value structure and using it find expectation values of a random start state.

Note that the labels in the expectation value structure will be the variable names in the output file, therefore they should be valid variable names for the output format. E.g. for matlab output the rules given in the documentation here should be followed.

/*
Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
Date: $LastChangedDate$
(c) University of Oxford 2016
*/
/* Include the header for the TNT library, including MPS functions */
#include "tntMps.h"
int main(int argc, char **argv)
{
tntExOp expec; /* Expectation value structure */
tntNode b, bdag, n, os_int; /* Bosonic operator nodes */
tntNetwork wf_rand; /* Network representing wave function */
unsigned L = 15, chi = 4; /* Wave function length and internal dimension */
/* Create operators (first argument bosonic truncation) */
tntMpsCreateBosonOp(2, &b, &bdag, &n, &os_int, NULL);
/* Create arrays for onsite operators and one for labels: one label per operator */
expec.ExOpOs = tntNodeArrayCreate(n);
expec.LbOpOs = tntStringArrayCreate("density");
/* Create arrays for two-site operators and labels: one label per pair of operators */
expec.ExOp2nn = tntNodeArrayCreate(b, bdag, n, n);
expec.LbOp2nn = tntStringArrayCreate("sing_part_dens_mat", "denden");
expec.ExOp2cs.sz = 0; /* If there are no operators of a given type, set the size to zero */
expec.LbOp2cs.sz = 0;
expec.ExOp2ap = tntNodeArrayCreate(b, bdag);
expec.LbOp2ap = tntStringArrayCreate("sing_part_dens_mat_ap");
/* Now create a random wave function */
/* First set a random number seed based on time so that it is different each run */
/* Set the basis operator as the number operator so that the properties of the physical leg are known */
wf_rand = tntMpsCreateRandom(L, chi);
/* Output the expectation values to the screen */
tntMpsExpecOutput(wf_rand, &expec, 0, 1, 0, NULL, 0);
/* Free all memory */
tntMpsExOpFree(&expec);
tntNetworkFree(&wf_rand);
tntNodeFree(&bdag);
tntNodeFree(&os_int);
return 0;
}