-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test_bases from QuantumOpticsBase and reorganize a bit
- Loading branch information
Showing
12 changed files
with
203 additions
and
135 deletions.
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
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import LinearAlgebra: tr, ishermitian, norm, normalize, normalize! | ||
|
||
""" | ||
ishermitian(op::AbstractOperator) | ||
|
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
samebases(a::AbstractOperator) = samebases(a.basis_l, a.basis_r)::Bool | ||
samebases(a::AbstractOperator, b::AbstractOperator) = samebases(a.basis_l, b.basis_l)::Bool && samebases(a.basis_r, b.basis_r)::Bool | ||
check_samebases(a::Union{AbstractOperator, AbstractSuperOperator}) = check_samebases(a.basis_l, a.basis_r) | ||
multiplicable(a::AbstractOperator, b::AbstractOperator) = multiplicable(a.basis_r, b.basis_l) | ||
samebases(a::AbstractOperator) = samebases(a.basis_l, a.basis_r)::Bool # FIXME issue #12 | ||
samebases(a::AbstractOperator, b::AbstractOperator) = samebases(a.basis_l, b.basis_l)::Bool && samebases(a.basis_r, b.basis_r)::Bool # FIXME issue #12 | ||
check_samebases(a::Union{AbstractOperator, AbstractSuperOperator}) = check_samebases(a.basis_l, a.basis_r) # FIXME issue #12 | ||
multiplicable(a::AbstractOperator, b::AbstractOperator) = multiplicable(a.basis_r, b.basis_l) # FIXME issue #12 | ||
dagger(a::AbstractOperator) = arithmetic_unary_error("Hermitian conjugate", a) | ||
transpose(a::AbstractOperator) = arithmetic_unary_error("Transpose", a) | ||
directsum(a::AbstractOperator...) = reduce(directsum, a) | ||
ptrace(a::AbstractOperator, index) = arithmetic_unary_error("Partial trace", a) | ||
_index_complement(b::CompositeBasis, indices) = complement(length(b.bases), indices) | ||
reduced(a, indices) = ptrace(a, _index_complement(basis(a), indices)) | ||
traceout!(s::StateVector, i) = ptrace(s,i) | ||
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,69 @@ | ||
import Base: show, summary | ||
|
||
function summary(stream::IO, x::AbstractOperator) | ||
print(stream, "$(typeof(x).name.name)(dim=$(length(x.basis_l))x$(length(x.basis_r)))\n") | ||
if samebases(x) | ||
print(stream, " basis: ") | ||
show(stream, basis(x)) | ||
else | ||
print(stream, " basis left: ") | ||
show(stream, x.basis_l) | ||
print(stream, "\n basis right: ") | ||
show(stream, x.basis_r) | ||
end | ||
end | ||
|
||
show(stream::IO, x::AbstractOperator) = summary(stream, x) | ||
|
||
function show(stream::IO, x::GenericBasis) | ||
if length(x.shape) == 1 | ||
write(stream, "Basis(dim=$(x.shape[1]))") | ||
else | ||
s = replace(string(x.shape), " " => "") | ||
write(stream, "Basis(shape=$s)") | ||
end | ||
end | ||
|
||
function show(stream::IO, x::CompositeBasis) | ||
write(stream, "[") | ||
for i in 1:length(x.bases) | ||
show(stream, x.bases[i]) | ||
if i != length(x.bases) | ||
write(stream, " ⊗ ") | ||
end | ||
end | ||
write(stream, "]") | ||
end | ||
|
||
function show(stream::IO, x::SpinBasis) | ||
d = denominator(x.spinnumber) | ||
n = numerator(x.spinnumber) | ||
if d == 1 | ||
write(stream, "Spin($n)") | ||
else | ||
write(stream, "Spin($n/$d)") | ||
end | ||
end | ||
|
||
function show(stream::IO, x::FockBasis) | ||
if iszero(x.offset) | ||
write(stream, "Fock(cutoff=$(x.N))") | ||
else | ||
write(stream, "Fock(cutoff=$(x.N), offset=$(x.offset))") | ||
end | ||
end | ||
|
||
function show(stream::IO, x::NLevelBasis) | ||
write(stream, "NLevel(N=$(x.N))") | ||
end | ||
|
||
function show(stream::IO, x::SumBasis) | ||
write(stream, "[") | ||
for i in 1:length(x.bases) | ||
show(stream, x.bases[i]) | ||
if i != length(x.bases) | ||
write(stream, " ⊕ ") | ||
end | ||
end | ||
write(stream, "]") | ||
end |
Oops, something went wrong.