-
Notifications
You must be signed in to change notification settings - Fork 98
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
7 changed files
with
134 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.. _section-nlevel: | ||
|
||
N-level basis | ||
============= | ||
|
||
Systems consisting of discrete states like e.g. an atom represented by a few relevant levels can be treated using the :jl:type:`NLevelBasis`. The only thing it needs to know is the number of states:: | ||
|
||
N = 3 | ||
b = NLevelBasis(N) | ||
|
||
Essentially it is defined just as:: | ||
|
||
type NLevelBasis <: Basis | ||
shape::Vector{Int} | ||
N::Int | ||
end | ||
|
||
Defined operators: | ||
|
||
* :jl:func:`transition` | ||
|
||
|
||
States can be created with | ||
|
||
* :jl:func:`nlevelstate` |
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,68 @@ | ||
module nlevel | ||
|
||
import Base.== | ||
|
||
using ..bases, ..states, ..operators, ..operators_sparse | ||
|
||
export NLevelBasis, transition, nlevelstate | ||
|
||
""" | ||
Basis for a system consisting of N states. | ||
Arguments | ||
--------- | ||
N | ||
Number of states. | ||
""" | ||
type NLevelBasis <: Basis | ||
shape::Vector{Int} | ||
N::Int | ||
function NLevelBasis(N::Int) | ||
if N < 1 | ||
throw(DimensionMismatch()) | ||
end | ||
new([N], N) | ||
end | ||
end | ||
|
||
==(b1::NLevelBasis, b2::NLevelBasis) = b1.N == b2.N | ||
|
||
|
||
""" | ||
Transition operator :math:`|n><m|`. | ||
Arguments | ||
--------- | ||
b | ||
NLevelBasis | ||
to | ||
Index of ket state in :math:`|to><from|` | ||
from | ||
Index of bra state in :math:`|to><from|` | ||
""" | ||
function transition(b::NLevelBasis, to::Int, from::Int) | ||
if to < 1 || b.N < to | ||
throw(BoundsError("'to' index has to be between 1 and b.N")) | ||
end | ||
if from < 1 || b.N < from | ||
throw(BoundsError("'from' index has to be between 1 and b.N")) | ||
end | ||
op = SparseOperator(b) | ||
op.data[to, from] = 1. | ||
op | ||
end | ||
|
||
|
||
""" | ||
State where the system is completely in the n-th level. | ||
""" | ||
function nlevelstate(b::NLevelBasis, n::Int) | ||
if n < 1 || b.N < n | ||
throw(BoundsError("n has to be between 1 and b.N")) | ||
end | ||
basis_ket(b, n) | ||
end | ||
|
||
end # module |
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,24 @@ | ||
using Base.Test | ||
using QuantumOptics | ||
|
||
|
||
N = 3 | ||
b = NLevelBasis(N) | ||
|
||
# Test basis equality | ||
@test b == NLevelBasis(N) | ||
@test b != NLevelBasis(N+1) | ||
|
||
# Test transition operator | ||
@test_throws BoundsError transition(b, 0, 1) | ||
@test_throws BoundsError transition(b, N+1, 1) | ||
@test_throws BoundsError transition(b, 1, 0) | ||
@test_throws BoundsError transition(b, 1, N+1) | ||
@test full(transition(b, 2, 1)) == basis_ket(b, 2) ⊗ basis_bra(b, 1) | ||
|
||
# Test nlevel states | ||
@test_throws BoundsError nlevelstate(b, 0) | ||
@test_throws BoundsError nlevelstate(b, N+1) | ||
@test norm(nlevelstate(b, 1)) == 1. | ||
@test norm(dagger(nlevelstate(b, 1))*nlevelstate(b, 2)) == 0. | ||
@test norm(dagger(nlevelstate(b, 1))*transition(b, 1, 2)*nlevelstate(b, 2)) == 1. |