Hi, I want to create a state like |00\rangle |W_{n}\rangle |00\rangle where the W-state is defined on a subset of qubits in the middle of the chain, i.e. |W \rangle = (|100\cdots 0\rangle + |010\cdots0\rangle + \cdots |00 \cdots 1 \rangle )/\sqrt{\mathcal{N}}. When I do this, using the code below, I get an error about having unmatched site indices (unmatched on the links). I’m sure there is some easy fix, but I can’t seem to figure it out and would appreciate any help I can get!
using ITensors, ITensorMPS
using LinearAlgebra
let
# Want to create a state |00> |W_state> |00>
Ntot = 6
Nleft = 1:2
Nright = Ntot-1:Ntot
Nmid = 3:Ntot-2
function state_vec(n)
twos_vec = [1 << nn for nn = collect(0:n-1)]
cb_idx(bs) = dot(twos_vec, bs) + 1
bitstrings = Diagonal(ones(Bool,n))
@show bitstrings[1,:]
@show bvals = [cb_idx(bitstrings[i,:]) for i in 1:n]
state = zeros(2^n)
coef = ones(n)
state[bvals] .= coef
return state
end
maxdim = 10; cutoff = 1e-8
sites = siteinds("Qubit", Ntot)
psi_temp = MPS(sites,"0")
# Initialize Wstate from the state vector corresponding to a sum of each state
Wstate = MPS(state_vec(length(Nmid)),sites[Nmid];maxdim=maxdim, cutoff=cutoff)
normalize!(Wstate)
println("Psi temporary")
display(psi_temp)
println("W state")
display(Wstate)
for (i,j) in enumerate(Nmid)
psi_temp[j] = Wstate[i]
end
orthogonalize!(psi_temp,1)
psi = psi_temp
println("Final State")
display(psi)
@show inner(psi',psi)
end
which gives the error indicating the mis-matched link indices:
ERROR: LoadError: Calling `dot(ϕ::MPS/MPO, ψ::MPS/MPO)` with multiple site indices per
MPS/MPO tensor but the site indices don't match. Even with `make_inds_match = true`,
the case of multiple site indices per MPS/MPO is not handled automatically.
The sites with unmatched site indices are:
inds(ϕ[1]) = ((dim=2|id=855|"Qubit,Site,n=1")', (dim=2|id=382|"Link,l=1")')
inds(ψ[1]) = ((dim=2|id=855|"Qubit,Site,n=1"), (dim=2|id=938|"Link,l=1"))
Make sure the site indices of your MPO/MPS match. You may need to prime
one of the MPS, such as `dot(ϕ', ψ)`.