Skip to content

Commit

Permalink
update...
Browse files Browse the repository at this point in the history
  • Loading branch information
bastikr committed Jan 18, 2017
1 parent ab64d64 commit a727b7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
13 changes: 3 additions & 10 deletions src/correlationexpansion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type ApproximateOperator{N} <: Operator
end
end

function ApproximateOperator{N}(basis_l::CompositeBasis, basis_r::CompositeBasis, S::Set{CorrelationMask{N}})
function approximate{N}(basis_l::CompositeBasis, basis_r::CompositeBasis, S::Set{CorrelationMask{N}})
operators = ([DenseOperator(basis_l.bases[i], basis_r.bases[i]) for i=1:N]...)
correlations = Dict{CorrelationMask{N}, DenseOperator}()
for mask in S
Expand All @@ -69,12 +69,12 @@ end



ApproximateOperator{N}(basis::CompositeBasis, S::Set{CorrelationMask{N}}) = ApproximateOperator(basis, basis, S)
approximate{N}(basis::CompositeBasis, S::Set{CorrelationMask{N}}) = ApproximateOperator(basis, basis, S)

maskdiff{N}(x::CorrelationMask{N}, y::CorrelationMask{N}) = ([x[i] && !y[i] for i =1:N]...)


function ApproximateOperator{N}(rho::DenseOperator, S::Set{CorrelationMask{N}})
function approximate{N}(rho::DenseOperator, S::Set{CorrelationMask{N}})
operators = ([ptrace(rho, complement(N, [i])) for i=1:N]...)
correlations = Dict{CorrelationMask{N}, DenseOperator}()
for k=2:N
Expand All @@ -83,15 +83,11 @@ function ApproximateOperator{N}(rho::DenseOperator, S::Set{CorrelationMask{N}})
σ_sk -= tensor(operators[[s_k...]]...)
for s_n in keys(correlations)
if mask2indices(s_n) mask2indices(s_k)
println("s_n: ", mask2indices(s_n))
println("s_k: ", mask2indices(s_k))
s_x = maskdiff(complement(s_n), complement(s_k))
println("s_x: ", mask2indices(s_x))
ρ_sx = tensor(operators[[s_x...]]...)
σ_sn = correlations[s_n]
op = σ_sn ρ_sx # subsystems in wrong order
perm = sortperm([mask2indices(s_n); mask2indices(s_x)])
println("perm: ", perm)
σ_sk -= permutesystems(op, perm)
end
end
Expand All @@ -101,9 +97,6 @@ function ApproximateOperator{N}(rho::DenseOperator, S::Set{CorrelationMask{N}})
ApproximateOperator{N}(rho.basis_l, rho.basis_r, operators, correlations)
end

# function productoperator{N}(op::ApproximateOperator{N})
# tensor([op.operators[1][indices2mask(N, [i])] for i=1:N]...)
# end

# function correlationoperator{N}(op::ApproximateOperator{N}, s::CorrelationMask{N})
# indices = mask2indices(s)
Expand Down
6 changes: 3 additions & 3 deletions test/test_correlationexpansion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ b2 = SpinBasis(1//2)
b3 = NLevelBasis(4)
b = tensor(b1, b2, b3)

rho = correlationexpansion.ApproximateOperator(b, b, S2 S3)
rho = correlationexpansion.approximate(b, b, S2 S3)

psi1a = normalize(coherentstate(b1, 0.1))
psi1b = fockstate(b1, 1)
Expand All @@ -31,8 +31,8 @@ rho2 = 0.3*psi2a ⊗ dagger(psi2a) + 0.7*psi2b ⊗ dagger(psi2b)
rho3 = psi3 dagger(psi3)
rho = rho1 rho2 rho3
# rho = psi ⊗ dagger(psi)
println(methods(correlationexpansion.ApproximateOperator))
x = correlationexpansion.ApproximateOperator(rho, S2 S3)

x = correlationexpansion.approximate(rho, S2 S3)
for (c, sigma) in x.correlations
println(correlationexpansion.mask2indices(c), ": ", sum(real(sigma.data)))
# println(sum(abs(x.correlations[(true, true, true)].data)))
Expand Down

0 comments on commit a727b7d

Please sign in to comment.