From c28aa539f93a2f3083332636fcdff9e37c0e38d6 Mon Sep 17 00:00:00 2001 From: waltergu Date: Thu, 3 Mar 2022 22:24:55 +0800 Subject: [PATCH] 1) Modify DMPhonon 2) More support of transformation on quantum operators. --- src/Essentials/QuantumOperators.jl | 18 ++++++++++++++---- src/Essentials/QuantumSystems.jl | 15 +++++++++------ test/Essentials/QuantumSystems.jl | 18 +----------------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/Essentials/QuantumOperators.jl b/src/Essentials/QuantumOperators.jl index ec9da7c6..ab968dbd 100644 --- a/src/Essentials/QuantumOperators.jl +++ b/src/Essentials/QuantumOperators.jl @@ -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) @@ -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 @@ -827,6 +836,7 @@ 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 @@ -834,9 +844,9 @@ abstract type Transformation <: Function end 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 @@ -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) diff --git a/src/Essentials/QuantumSystems.jl b/src/Essentials/QuantumSystems.jl index 8a2714df..60c03b82 100644 --- a/src/Essentials/QuantumSystems.jl +++ b/src/Essentials/QuantumSystems.jl @@ -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 @@ -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 diff --git a/test/Essentials/QuantumSystems.jl b/test/Essentials/QuantumSystems.jl index a6e71994..488f860c 100644 --- a/test/Essentials/QuantumSystems.jl +++ b/test/Essentials/QuantumSystems.jl @@ -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])) )