ITensors.jl icon indicating copy to clipboard operation
ITensors.jl copied to clipboard

Generalizations of `OpSum` interface

Open emstoudenmire opened this issue 4 years ago • 1 comments

Forum user lello suggested the following, which could be very useful: in input to OpSum, instead of only specifying operators by strings, one should be able to put a Julia matrix instead.

For example:

M1::Matrix
M2::Matrix
os = OpSum()
os += M1,i,M2,j

For more discussion and examples: http://itensor.org/support/3322/using-kwargs-with-itensors-op-and-autompo-in-julia

emstoudenmire avatar Aug 19 '21 02:08 emstoudenmire

Another generalization is allowing a function as the first input of the term, representing a function that will act on the operator after it is formed:

os = OpSum()
os += exp, "Z", 1

Additionally, I had an idea for something a bit more out there. Consider the following:

X = OpName("X")
Y = OpName("Y")
Z = OpName("Z")

os = Z(1) * Z(2) + X(1) + X(2)

The idea would be that Z(1) could create the the term ("Z", 1), then Z(1) * Z(2) could make the term ("Z", 1, "Z", 2).

In this case, we can also allow more general lazy operations, so we could have something like:

os = 1/2 * Z(1) * Z(2) + exp(-im * t * X(1)) + X(2)

mtfishman avatar Sep 24 '21 11:09 mtfishman

This is now defined in recent versions of ITensors, and works with MPO construction:

julia> using ITensors

julia> s = siteinds("Qubit", 2);

julia> O1 = randn(2, 2);

julia> O2 = randn(2, 2);

julia> os = OpSum() + (O1, 1, O2, 2);

julia> O = MPO(os, s);

julia> op(O1, s, 1) * op(O2, s, 2) ≈ contract(O)
true

mtfishman avatar Feb 24 '23 13:02 mtfishman