Skip to content

Commit

Permalink
1) Modify DMPhonon
Browse files Browse the repository at this point in the history
2) More support of transformation on quantum operators.
  • Loading branch information
waltergu committed Mar 3, 2022
1 parent 9876e75 commit c28aa53
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
18 changes: 14 additions & 4 deletions src/Essentials/QuantumOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,15 @@ Show a quantum operator.
"""
Base.show(io::IO, ::MIME"text/latex", m::QuantumOperator) = show(io, MIME"text/latex"(), latexstring(latexstring(m)))

"""
add!(destination, transformation::Function, op::QuantumOperator; kwargs...) -> typeof(destination)
Add the result of the transformation on a quantum operator to the destination.
"""
@inline function add!(destination, transformation::Function, op::QuantumOperator; kwargs...)
add!(destination, transformation(op; kwargs...))
end

"""
map!(transformation::Function, ms::OperatorSum; kwargs...) -> typeof(ms)
Expand All @@ -813,7 +822,7 @@ In place map of an `OperatorSum` by a function.
"""
function Base.map!(transformation::Function, destination, ms::OperatorSum; kwargs...)
for m in ms
add!(destination, transformation(m; kwargs...))
add!(destination, transformation, m; kwargs...)
end
return destination
end
Expand All @@ -827,16 +836,17 @@ abstract type Transformation <: Function end
@inline Base.:(==)(transformation₁::Transformation, transformation₂::Transformation) = ==(efficientoperations, transformation₁, transformation₂)
@inline Base.isequal(transformation₁::Transformation, transformation₂::Transformation) = isequal(efficientoperations, transformation₁, transformation₂)
@inline Base.valtype(transformation::Transformation, m::QuantumOperator) = valtype(typeof(transformation), typeof(m))
@inline Base.zero(transformation::Transformation, m::QuantumOperator) = zero(valtype(transformation, m))

"""
(transformation::Transformation)(ms::OperatorSum; kwargs...) -> OperatorSum
Get the transformed quantum operators.
"""
function (transformation::Transformation)(ms::OperatorSum; kwargs...)
result = zero(valtype(transformation, ms))
result = zero(transformation, ms)
for m in ms
add!(result, transformation(m; kwargs...))
add!(result, transformation, m; kwargs...)
end
return result
end
Expand Down Expand Up @@ -913,7 +923,7 @@ Permute the operator units of an `OperatorProd` to the descending order accordin
Here, `u₁` and `u₂` are two arbitrary operator units contained in `id(m)`.
"""
@inline function (permutation::Permutation)(m::OperatorProd; kwargs...)
result = zero(valtype(permutation, m))
result = zero(permutation, m)
cache = eltype(result)[m]
while length(cache) > 0
current = pop!(cache)
Expand Down
15 changes: 9 additions & 6 deletions src/Essentials/QuantumSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1237,11 +1237,11 @@ function expand(dmp::Coupling{<:Number, <:Tuple{NID{Symbol}, SID{wildcard, Int,
@assert dmp.cid[1].tag=='u' && dmp.cid[2].orbital==1 && spin.norbital==1 "expand error: not supported expansion of DM magnon-phonon coupling."
return DMPExpand{totalspin(spin)}(totalspin(spin)/a, R̂, (bond.epoint, bond.spoint))
end
struct DMPExpand{S, V<:Number, P<:AbstractPID} <: CartesianVectorSpace{Tuple{V, Tuple{OID{Index{P, NID{Char}}, SVector{2, V}}, OID{Index{P, SID{S, Int, Char}}, SVector{2, V}}}}}
struct DMPExpand{S, V<:Number, D, P<:AbstractPID} <: CartesianVectorSpace{Tuple{V, Tuple{OID{Index{P, NID{Char}}, SVector{D, V}}, OID{Index{P, SID{S, Int, Char}}, SVector{D, V}}}}}
value::V
direction::SVector{2, V}
points::NTuple{2, Point{2, P, V}}
DMPExpand{S}(value::Number, direction::SVector, points::NTuple{2, Point}) where S = new{S, typeof(value), pidtype(eltype(points))}(value, direction, points)
direction::SVector{D, V}
points::NTuple{2, Point{D, P, V}}
DMPExpand{S}(value::Number, direction::SVector{D}, points::NTuple{2, Point}) where {S, D} = new{S, typeof(value), D, pidtype(eltype(points))}(value, direction, points)
end
@inline shape(dmp::DMPExpand) = (1:2, 1:2, 1:2, 1:2)
function Tuple(index::CartesianIndex{4}, dmp::DMPExpand{S}) where S
Expand Down Expand Up @@ -1269,10 +1269,13 @@ const DMPhonon{id, V, C<:TermCouplings, A<:TermAmplitude, M<:TermModulate} = Ter
Term{:DMPhonon}(id, value, bondkind, couplings=dmphonon"", amplitude=amplitude, modulate=modulate)
end
@inline abbr(::Type{<:DMPhonon}) = :dmp
@inline ishermitian(::Type{<:DMPhonon}) = false
@inline ishermitian(::Type{<:DMPhonon}) = true
@inline couplingcenters(::Coupling, ::Bond, ::Val{:DMPhonon}) = (1, 2)
@inline function optype(T::Type{<:Term{:DMPhonon}}, H::Type{<:Hilbert}, B::Type{<:AbstractBond})
Operator{valtype(T), <:ID{OID{<:Index{pidtype(eltype(B)), <:SimpleIID}, SVector{dimension(eltype(B)), dtype(eltype(B))}}, rank(T)}}
V = SVector{dimension(eltype(B)), dtype(eltype(B))}
I₁ = OID{Index{pidtype(eltype(B)), NID{Char}}, V}
I₂ = OID{Index{pidtype(eltype(B)), SID{totalspin(filter(SID, valtype(H))), Int, Char}}, V}
Operator{valtype(T), Tuple{I₁, I₂}}
end

end # module
18 changes: 1 addition & 17 deletions test/Essentials/QuantumSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -909,41 +909,25 @@ end

term = DMPhonon(:dmp, 2.0, 1)
@test abbr(term) == abbr(typeof(term)) == :dmp
@test ishermitian(term) == ishermitian(typeof(term)) == false
@test ishermitian(term) == ishermitian(typeof(term)) == true

bond = Bond(1, Point(PID(2), [0.5, 0.5], [0.0, 0.0]), Point(PID(1), [0.0, 0.0], [0.0, 0.0]))
hilbert = Hilbert(pid=>Phonon(2)Spin{1//2}(1) for pid in [bond.epoint.pid, bond.spoint.pid])
operators = Operators(
Operator(2/2, OID(Index(PID(1), SID{1//2}(1, 'y')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(2), NID('u', 'x')), [0.5, 0.5], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(2), NID('u', 'x')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(2), SID{1//2}(1, 'y')), [0.5, 0.5], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(1), NID('u', 'x')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(2), SID{1//2}(1, 'x')), [0.5, 0.5], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(1), NID('u', 'x')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(1), SID{1//2}(1, 'x')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(1), SID{1//2}(1, 'x')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(2), NID('u', 'x')), [0.5, 0.5], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(1), SID{1//2}(1, 'y')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(1), NID('u', 'x')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(1), SID{1//2}(1, 'x')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(1), NID('u', 'y')), [0.0, 0.0], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(2), NID('u', 'x')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(1), SID{1//2}(1, 'y')), [0.0, 0.0], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(1), NID('u', 'y')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(1), SID{1//2}(1, 'y')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(1), NID('u', 'y')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(1), SID{1//2}(1, 'x')), [0.0, 0.0], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(2), SID{1//2}(1, 'y')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(1), NID('u', 'y')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(2), SID{1//2}(1, 'x')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(2), NID('u', 'x')), [0.5, 0.5], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(2), NID('u', 'y')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(2), SID{1//2}(1, 'x')), [0.5, 0.5], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(1), SID{1//2}(1, 'y')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(1), NID('u', 'y')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(1), NID('u', 'x')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(2), SID{1//2}(1, 'y')), [0.5, 0.5], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(2), SID{1//2}(1, 'y')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(1), NID('u', 'x')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(2), NID('u', 'y')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(1), SID{1//2}(1, 'y')), [0.0, 0.0], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(2), SID{1//2}(1, 'y')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(2), NID('u', 'x')), [0.5, 0.5], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(1), NID('u', 'y')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(2), SID{1//2}(1, 'y')), [0.5, 0.5], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(2), NID('u', 'y')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(1), SID{1//2}(1, 'x')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(2), SID{1//2}(1, 'x')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(1), NID('u', 'y')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(1), SID{1//2}(1, 'y')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(2), NID('u', 'y')), [0.5, 0.5], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(2), SID{1//2}(1, 'x')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(2), NID('u', 'y')), [0.5, 0.5], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(2), SID{1//2}(1, 'x')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(1), NID('u', 'x')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(1), NID('u', 'x')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(1), SID{1//2}(1, 'y')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(2), NID('u', 'x')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(2), SID{1//2}(1, 'x')), [0.5, 0.5], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(2), SID{1//2}(1, 'y')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(2), NID('u', 'y')), [0.5, 0.5], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(1), SID{1//2}(1, 'x')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(2), NID('u', 'y')), [0.5, 0.5], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(2), NID('u', 'y')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(2), SID{1//2}(1, 'y')), [0.5, 0.5], [0.0, 0.0])),
Operator(2/2, OID(Index(PID(1), SID{1//2}(1, 'x')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(1), NID('u', 'x')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(2), NID('u', 'x')), [0.5, 0.5], [0.0, 0.0]), OID(Index(PID(1), SID{1//2}(1, 'x')), [0.0, 0.0], [0.0, 0.0])),
Operator(-√2/2, OID(Index(PID(1), NID('u', 'y')), [0.0, 0.0], [0.0, 0.0]), OID(Index(PID(2), SID{1//2}(1, 'x')), [0.5, 0.5], [0.0, 0.0]))
)
Expand Down

0 comments on commit c28aa53

Please sign in to comment.