+1 vote
asked by (680 points)

I am writing a generic code that may allow for different SiteSet types, such as different values of spin. My code works fine, unless I save the SiteSet to memory, and then try to load it. As an example, I may have something like

SiteSet sites;
sites = SpinHalf(N);

Since sites is actually of type SpinHalf at run time, there is no issue. However, If I then try to save and then load this variable via

write(f, sites);
read(f, sites);

sites is now a basic site set, and thus loses operations such as 'op'. Is there a simple way to get around this, so I can keep my code general? Or do I have to, for example, write different code for each type of SiteSet?


1 Answer

+1 vote
answered by (680 points)

Actually I found a work around, so this is closed to me.

For those that are curious, here is my code

    auto sType = args->getString("SiteSet");
    if     (sType == "SpinHalf"){ auto rSites = SpinHalf(args->getInt("N")); rSites.read(f); sites = rSites; }
    else if(sType == "SpinOne") { auto rSites = SpinOne(args->getInt("N")); rSites.read(f); sites = rSites;  }
    else if(sType == "SpinTwo") { auto rSites = SpinTwo(args->getInt("N")); rSites.read(f); sites = rSites;  }  }

so rSites is cast into the specific type needed, and then I read the SiteSet of interest into rSites, and then I just set sites = rSites.

Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.