How can I create a new MPS which is the “concantenation” (kronecker product) of two MPSs?
Namely, say MPS1 is a random MPS, and MPS2 is simply |0>. Then I want to create a new MPS being |0>|MPS1>.
The minimal example is:
s1=siteinds("Qubit", 4)
mps1= randomMPS(s;linkdims=3)
s2=siteinds("Qubit", 1)
mps2 = MPS(s2, ["0"])
# mps = kron(mps2, mps1) ?
I understand that, mathematically, it is just that I need to create a singleton axis for the mps2 on the right and for mps1 on the left. But how do I achieve that in ITensors
?
I notice a similar question is mentioned in
However, what I cannot figure out is to make the “index” match. I guess that has to be done in Step 4
- finally, write a for loop that just assigns the tensors of the MPS ∣r⟩\ket{r}∣r⟩ to the appropriate tensors of
psi
But the naive method doesn’t work
for i in 2:N
mps[i] = mps1[i-1]
end
because it will miss the link between mps[1] and mps[2].
And I also try to “manually” copy only the data of tensor but not the index through
mps=MPS(vcat(s1,s2),"0")
for idx in 2:n
if idx == 2
arr=array(mps1[idx-1])
mps[idx] = ITensor(reshape(arr,(1,size(arr)...)),inds(mps[idx]))
else
mps[idx]=ITensor( array(psi1[idx-1]) , inds(mps[idx]))
end
end
which also fails:
DimensionMismatch: In ITensor(::AbstractArray, inds), length of AbstractArray (6) must match total dimension of IndexSet (2)
Stacktrace:
[1] ITensor(as::NDTensors.NeverAlias, eltype::Type{Float64}, A::Array{Float64, 3}, inds::Tuple{Index{Int64}, Index{Int64}, Index{Int64}}; kwargs::@Kwargs{})
@ ITensors ~/.julia/packages/ITensors/UHeB1/src/itensor.jl:352
[2] ITensor
@ ITensors ~/.julia/packages/ITensors/UHeB1/src/itensor.jl:345 [inlined]
[3] #ITensor#136
@ ITensors ~/.julia/packages/ITensors/UHeB1/src/itensor.jl:411 [inlined]
[4] ITensor
@ ITensors ~/.julia/packages/ITensors/UHeB1/src/itensor.jl:408 [inlined]
[5] #ITensor#138
@ ITensors ~/.julia/packages/ITensors/UHeB1/src/itensor.jl:421 [inlined]
[6] ITensor(A::Array{Float64, 3}, is::Tuple{Index{Int64}, Index{Int64}, Index{Int64}})
@ ITensors ~/.julia/packages/ITensors/UHeB1/src/itensor.jl:420
[7] top-level scope
@ ./In[163]:8