-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
schmidt_decomposition(ψ::AbstractVector, dims::AbstractVector{<:Integer}) | ||
Produces the Schmidt decomposition of `ψ` with subsystem dimensions `dims`. Returns the (sorted) Schmidt coefficients λ and isometries U, V such that | ||
kron(U', V')*`ψ` is of Schmidt form. | ||
""" | ||
function schmidt_decomposition(ψ::AbstractVector, dims::AbstractVector{<:Integer}) | ||
length(dims) != 2 && throw(ArgumentError("Two subsystem sizes must be specified.")) | ||
m = transpose(reshape(ψ, dims[2], dims[1])) #necessary because the natural reshaping would be row-major, but Julia does it col-major | ||
U, λ, V = LA.svd(m) | ||
return λ, U, conj(V) | ||
end | ||
""" | ||
schmidt_decomposition(ψ::AbstractVector, dims::AbstractVector{<:Integer}) | ||
Produces the Schmidt decomposition of `ψ` assuming equally-sized subsystems. Returns the (sorted) Schmidt coefficients λ and isometries U, V such that | ||
kron(U', V')*`ψ` is of Schmidt form. | ||
""" | ||
function schmidt_decomposition(ψ::AbstractVector) | ||
n = length(ψ) | ||
d = isqrt(n) | ||
d^2 != n && throw(ArgumentError("Subsystems are not equally-sized, please specify sizes.")) | ||
return schmidt_decomposition(ψ, [d, d]) | ||
end | ||
export schmidt_decomposition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@testset "Entanglement " begin | ||
for R in [Float64, Double64, Float128, BigFloat] | ||
T = Complex{R} | ||
ψ = random_state_vector(T, 6) | ||
λ, U, V = schmidt_decomposition(ψ, [2, 3]) | ||
@test vec(Diagonal(λ)) ≈ kron(U', V') * ψ | ||
ψ = random_state_vector(T, 4) | ||
λ, U, V = schmidt_decomposition(ψ) | ||
@test vec(Diagonal(λ)) ≈ kron(U', V') * ψ | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters