Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flexibilize types for partial_trace #109

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/math_util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@
0.2 0.6
```
"""
function partial_trace(ρ::Matrix, sys_dim::AbstractVector{Int}, dim_2_keep::AbstractVector{Int})
partial_trace(ρ::AbstractMatrix, sys_dim::AbstractVector{<:Integer}, dim_2_keep::Integer) = partial_trace(ρ,sys_dim,[dim_2_keep])

Check warning on line 215 in src/math_util.jl

View check run for this annotation

Codecov / codecov/patch

src/math_util.jl#L215

Added line #L215 was not covered by tests

function partial_trace(ρ::AbstractMatrix, sys_dim::AbstractVector{<:Integer}, dim_2_keep::AbstractVector{<:Integer})
size(ρ, 1) != size(ρ, 2) && throw(ArgumentError("ρ is not a square matrix."))
prod(sys_dim) != size(ρ, 1) && throw(ArgumentError("System dimensions do not multiply to density matrix dimension."))

Expand All @@ -226,7 +228,7 @@
re_dim[dim_2_trace] .= 1
tr_dim = copy(sys_dim)
tr_dim[dim_2_keep] .= 1
res = zeros(ComplexF64, re_dim..., re_dim...)
res = zeros(eltype(ρ), re_dim..., re_dim...)
for I in CartesianIndices(size(res))
for k in CartesianIndices((tr_dim...,))
delta = CartesianIndex(k, k)
Expand Down Expand Up @@ -358,4 +360,4 @@
L = diag(r)
L=L./abs.(L)
q*diagm(0=>L)
end
end
Loading