forked from qutip/QuantumToolbox.jl
-
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.
Merge pull request qutip#156 from ytdHuang/dev/operator
Introduce `commutator`, `fcreate`, and `fdestroy`
- Loading branch information
Showing
4 changed files
with
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,9 +95,12 @@ sigmay | |
sigmaz | ||
destroy | ||
create | ||
fdestroy | ||
fcreate | ||
eye | ||
qeye | ||
projection | ||
commutator | ||
spre | ||
spost | ||
sprepost | ||
|
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,27 @@ | ||
@testset "States and Operators" begin | ||
# test commutation relations for fermionic creation and annihilation operators | ||
sites = 4 | ||
SIZE = 2^sites | ||
dims = fill(2, sites) | ||
Q_iden = Qobj(sparse((1.0 + 0.0im) * LinearAlgebra.I, SIZE, SIZE); dims = dims) | ||
Q_zero = Qobj(spzeros(ComplexF64, SIZE, SIZE); dims = dims) | ||
for i in 0:(sites-1) | ||
d_i = fdestroy(sites, i) | ||
@test d_i' ≈ fcreate(sites, i) | ||
|
||
for j in 0:(sites-1) | ||
d_j = fdestroy(sites, j) | ||
|
||
if i == j | ||
@test commutator(d_i, d_j'; anti = true) ≈ Q_iden | ||
else | ||
@test commutator(d_i, d_j'; anti = true) ≈ Q_zero | ||
end | ||
@test commutator(d_i', d_j'; anti = true) ≈ Q_zero | ||
@test commutator(d_i, d_j; anti = true) ≈ Q_zero | ||
end | ||
end | ||
@test_throws ArgumentError fdestroy(0, 0) | ||
@test_throws ArgumentError fdestroy(sites, -1) | ||
@test_throws ArgumentError fdestroy(sites, sites) | ||
end |