+1 vote
asked by (340 points)

Hello,

Is there a way to loop over the Args elements?

for(Val const & a: args){
 //Do something with a
}

I'm using Args to simplify the construction of operators. Since this construction is quite general, I don't know what Args have been added so I would like to loop over all elements. Thank you very much.

Best,
João

commented by (70.1k points)
Good question. Right now I don't think you can do this. But it's something that should be added for sure, and I think will be quite easy to add. Let me work on it and get back to you.

Let me also note that, as you probably know, you can put a default value when retrieiving an arg. You can also call the .defined(name) method to see if an arg is defined in a certain args object. Just mentioning those two features in case it already solves your problem.
commented by (340 points)
edited by
Adding

storage_type
    getValues(){ return vals_;}

to the public function of args.h works just fine. Yes I know, but I'm constructing some more Elaborate Args arguments like "Sy.Id.Sz|{1,2}". Thanks
commented by (70.1k points)
Hi, so I realized just now in looking more at the args code that there are some non-trivial design questions here for the case of modifying the args. Looping over them and inspecting them, printing them, etc is easy to add & I can do that. But modifying them raises a number of complexities such as cases like setting two args to have the same name by accident. The current interface takes care of that for you and it's harder to control that in a loop that allows modification.

So toward reaching the best design, could you let me know more specifically what you're trying to do? What do you mean by "Sy.Id.Sz|{1,2}" also? Is that the name of the arg or both it's name and value? If it's just the name, what is the value you want to set there? What about the current interface is making this hard to do? Thanks -

Miles
commented by (340 points)
Hi Miles,

Currently outputting a const value is enough as I'm not changing the args, only reading them.
I can explain myself a bit better. At the moment, I want to create a class named Generator which, given some instructions (aka args), generates and stores the gates necessary for TEBD.  It receives a siteset Z4 and some Args

Generator(Z4 const& st, Args const& args = Args::global())

The args contain all the info about the Hamiltonian in an easy to read fashion. Say you want the XXZ chain, then you would add

 {"Sx.Sx|all",t,"Sy.Sy|all",t,"Sz.Sz|all",delta}

where t would be the strength of the hopping. In case you also want to add a next-to-nearest interaction at the second site of the chain with strength 4, you just need to do

{"Sx.Sx|all",t,"Sy.Sy|all",t,"Sz.Sz|all",delta,"Sz.Id.Sz|{2}",4}  

Constructing the Generator from an Args system is quite practical but I need to loop over the Args. At the moment, I loop over them, extract the operator and where it applies by reading arg.name() and then retrieve the strength by reading arg.realVal().

Maybe I'm doing this is in the worst possible way, feel free to suggest alternatives. I also thought about using the input file but I don't know how to make it so clean.

Please log in or register to answer this question.

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.

Categories

...