Hi,
I try to use itensor to simulate the measurement phase transition. Basically I want both Haar random unitary matrices and random measurements during the time evolution.
So I wrote a short code
using LinearAlgebra
using ITensors
using StatsBase
using Statistics
using StaticArrays
using Random
function rand_haar2(::Val{n}) where n
M = randn(SMatrix{n,n,ComplexF64})
q = qr(M).Q
L = cispi.(2 .* @SVector(rand(n)))
return q*diagm(L)
end
function op(::OpName"haar2",::SiteType"S=1/2",s1::Index,s2::Index)
h = rand_haar2(Val{4}())
return itensor(h,s2',s1',s2,s1)
end
"""
psi: wavefunction, n: position where the projector is applyied, p:either up +1 or down -1
"""
function measure_proj(psi::MPS,n,p)
site_p = (0.5*(op("Id",siteind(psi,n))+2*p*op("Sz",siteind(psi,n))))*psi[n]
psi[n] = noprime!(site_p)
psi[n] = psi[n]/(norm(psi[n]))
return psi
end
function measure_prob(psi::MPS, n)
orthogonalize!(psi,n)
sn = siteind(psi,n)
p = scalar(dag(prime(psi[n],"Site"))*(0.5*(op("Id",sn)+2*op("Sz",sn)))*psi[n])
return real(p)
end
n = 10
s = siteinds("S=1/2",n)
psi = randomMPS(s)
Gates=[("haar2",3,4)]
apply(ops(Gates,s),psi;cutoff = 1e^-10)
But I got error
ERROR: Older op interface does not support multiple indices with mixed site types. You may want to overload `op(::OpName, ::SiteType..., ::Index...)` or `op!(::ITensor, ::OpName, ::SiteType..., ::Index...) for the operator "haar2" and Index tags ("S=1/2,Site,n=3", "S=1/2,Site,n=4").
I think I should use index rather than integer 3
and 4
, but how to fix it?
Also, I use some static arrays since I want to generate random 4x4 matrices frequently. Is this allowed?
Thanks