0 votes
asked by (310 points)

Hi all,

Is it possible to overload the ITensors.op! as

function ITensors.op!(Op::ITensor, ::OpName"X", ::SiteType"MyType", s::Index; M::Matrix)
  for n in 1:dim(s)
    for m in 1:dim(s)
      Op[n, m] = M[n,m]

and use it in the autompo?

I cannot find a way to pass M with the autompo procedure.

Thanks for the help.

commented by (70.1k points)
Hi, no there is currently not a way to pass keyword arguments through the AutoMPO (now renamed OpSum) interface to these individual op functions. It’s an interesting idea but we had not put it into the interface, and I’m not quite sure what the best interface for doing that would be.

It would be helpful to know more about what you’re trying to accomplish. Could you either:
1. suggest the interface (on the AutoMPO level) that you are wishing we had? I’m always interested in ideas to improve it


2. Say more about the exact operator or operators you are trying to make? Maybe there’s another way to do it that could work well.

commented by (310 points)
edited by
for my special case I solved the problem by introducing a global array (in the same module that defines the new site type), and let the overloaded op() return the global array. However, it would be nice to have an interface for autompo like

ampo += M,"Id",p


ampo += M,p

(omitting the "Id"), where M is a matrix, p the site number and "Id" the identity operator. Of course the size of M should match those of the Id operator at the site p.

I am not interested into a specific operator but rather on the possibility to define any kind of operator in this way, without the need to write several op() for each single operator.
One could use a single op() and then create an MPO passing the matrix representation M of the single site operators.   

Something like:

ampo = OpSum()
ampo += M1,p1
ampo += M2,p2

where M1 and M2 are matrices (with proper size).

commented by (310 points)
edited by
I can add a second, maybe easier to implement, interface:

ampo += c1,"X[1,2]",p
ampo += c2,"X[2,2]",p

where c1, c2 are complex coefficients and p is an integer.
The parenthesis could be stripped from the operator name (X)
and parsed separately. The complex coefficient would be  put in position [1,2], [2,2]  of the X operator, and so on. This could be generalized to operators X with more that two indices.

I have something like this implemented in the C++ version of itensor.

What do you think?


1 Answer

0 votes
answered by (70.1k points)
selected by
Best answer

Thanks for this feedback. These are great suggestions and I think we should implement this feature. I just created an enhancement issue to remind us to do it:


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.