Skip to content

Commit

Permalink
add fermionoperators
Browse files Browse the repository at this point in the history
fix fermionic creation and annihilation operators (c+, c, n) #7
  • Loading branch information
lkdvos committed Apr 25, 2023
1 parent ad26c39 commit 39ab706
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/MPSKitModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export sigma_xx, sigma_yy, sigma_zz, sigma_plusmin, sigma_minplus, sigma_exchang
export σˣ, σʸ, σᶻ, σ⁺, σ⁻, σˣˣ, σʸʸ, σᶻᶻ, σ⁺⁻, σ⁻⁺, σσ
include("operators/spinoperators.jl")

export cc, ccdag, cdagc, cdagcdag, number
include("operators/fermionoperators.jl")

export @mpoham
include("mpoham.jl")

Expand Down
34 changes: 34 additions & 0 deletions src/operators/fermionoperators.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function cc(elt::Type{<:Number}=ComplexF64)
pspace = Vect[FermionParity](0=>1, 1=>1)
cc = TensorMap(zeros, elt, pspace^2 pspace^2)
blocks(cc)[fℤ₂(0)][1, 2] = -one(elt)
return cc
end

function ccdag(elt::Type{<:Number}=ComplexF64)
pspace = Vect[FermionParity](0 => 1, 1 => 1)
ccdag = TensorMap(zeros, elt, pspace^2 pspace^2)
blocks(ccdag)[fℤ₂(1)][2, 1] = -one(elt)
return ccdag
end

function cdagc(elt::Type{<:Number}=ComplexF64)
pspace = Vect[FermionParity](0 => 1, 1 => 1)
cdagc = TensorMap(zeros, elt, pspace^2 pspace^2)
blocks(cdagc)[fℤ₂(1)][1, 2] = one(elt)
return cdagc
end

function cdagcdag(elt::Type{<:Number}=ComplexF64)
pspace = Vect[FermionParity](0 => 1, 1 => 1)
cdagcdag = TensorMap(zeros, elt, pspace^2 pspace^2)
blocks(cdagcdag)[fℤ₂(0)][2, 1] = one(elt)
return cdagcdag
end

function number(elt::Type{<:Number}=ComplexF64)
pspace = Vect[FermionParity](0 => 1, 1 => 1)
n = TensorMap(zeros, elt, pspace, pspace)
blocks(n)[fℤ₂(1)] .= one(elt)
return n
end
21 changes: 21 additions & 0 deletions test/fermionoperators.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using MPSKitModels
using TensorKit
using TensorOperations
using Test
using LinearAlgebra: tr

# anticommutation relations
# {cᵢ†, cⱼ†} = 0 = {cᵢ, cⱼ}

@test cc() -permute(cc(), (2, 1), (4, 3))
@test cdagcdag() -permute(cdagcdag(), (2, 1), (4, 3))
@test ccdag() -permute(cdagc(), (2, 1), (4, 3))

@tensor begin
term1[a; b] := ccdag()[a, i; i, b]
term2[a; b] := cdagc()[a, i; i, b]
end

@test term1 + term2 id(domain(term))

@test term2 number()
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ using Test
include("spinoperators.jl")
end

@testset "fermion operators" include("fermionoperators.jl")

@testset "transverse field ising model" begin
include("tfim.jl")
end
Expand Down

0 comments on commit 39ab706

Please sign in to comment.