# Using kwargs with ITensors.op and AutoMPO in Julia

0 votes
asked

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]
end
end
end


and use it in the autompo?

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

Thanks for the help.
lello

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

or

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.

Thanks,
Miles
commented by (310 points)
edited by
Hi,
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

or

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).

Lello
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?

Lello

## 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:

https://github.com/ITensor/ITensors.jl/issues/722