Hi, I know there is a way to extract the probability amplitudes of a state vector from its MPS representation (MPS and MPO Examples · ITensors.jl), but this requires inputting a sequence of integers corresponding to the component of the underlying tensor you want to find. I don’t know exactly which components I want to find, but I do want to find (for the purpose of summing) all the non-zero components i.e. I want to sum the amplitudes as opposed to the squared amplitudes. Most ways I can think of doing this seem to be exponentially costly. Is there a simple way of doing this?

Thank you very much, and thank you for the great work done for ITensor!

EDIT: On top of summing the amplitudes, I also need to define a state as follows. I am working with a spin 1/2 chain with N sites. Suppose it is in the superposition

You’re in luck – this is a task which is ideal to perform for an MPS in a fast, polynomial-scaling way. The basic idea is that the state you identified \ket{\mathbb{I}} is actually a product (unentangled) state i.e. an MPS of bond dimension 1. It is defined by making each MPS tensor to be just a vector with entries [1,1] (for the case of a d=2 dimensional site index).

Then after defining this “summing state” \ket{\mathbb{I}} you compute its inner product with the MPS whose components or amplitudes you want to sum. Here is some code to do it manually in ITensor, making each MPS tensor of the \ket{\mathbb{I}} state on the fly:

using ITensors
let
N = 100
s = siteinds("S=1/2",N)
psi = randomMPS(s;linkdims=10)
I = ITensor(1.0)
for j=1:N
I = I*(psi[j]*ITensor([1.0,1.0],s[j]))
end
@show scalar(I)
return
end

Another way to do the above would be to actually make the MPS for the state \ket{\mathbb{I}} then use the function inner to compute its inner product with the other MPS.

This code doesn’t seem to work with QN conserving MPS. Is there a way to ‘convert’ the block-sparse tensors to the dense tensors, or maybe is there a better way to do it with QN conserving MPS?

I would recommend just converting the MPS to a dense MPS. I.e. just before the main part of the code runs you can do:

dpsi = dense(psi)

and then use dpsi in the rest of that part of the code. It should still be very efficient, and this kind of algorithm is not going to make much use of the block sparse structure of the MPS anyway. So the speed should be very similar.