From dfb49d19c0596684fe30ca56b7efc0d62f1547ea Mon Sep 17 00:00:00 2001 From: waltergu Date: Sun, 14 Nov 2021 10:48:27 +0800 Subject: [PATCH] Prepare for v0.8.3: key word arguments support for transfomations. --- Project.toml | 2 +- src/Essentials/Frameworks.jl | 19 +++++++++++-------- src/Essentials/QuantumOperators.jl | 24 ++++++++++++------------ 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Project.toml b/Project.toml index e5b3feef..2d448601 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "QuantumLattices" uuid = "78ae1a1f-1d5d-5174-b61c-66e31b2346dc" authors = ["waltergu "] -version = "0.8.2" +version = "0.8.3" [deps] DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" diff --git a/src/Essentials/Frameworks.jl b/src/Essentials/Frameworks.jl index ea119b0a..80f80915 100644 --- a/src/Essentials/Frameworks.jl +++ b/src/Essentials/Frameworks.jl @@ -120,14 +120,15 @@ Get a new entry of quantum operators by merging two entries. @inline Base.merge(entry::Entry, another::Entry) = merge!(empty(entry), another) """ - (transformation::Transformation)(entry::Entry) -> Entry + (transformation::Transformation)(entry::Entry; kwargs...) -> Entry Get the transformed entry of quantum operators. """ -function (transformation::Transformation)(entry::Entry) - constops = transformation(entry.constops) - alterops = NamedContainer{keys(entry.alterops)}(map(transformation, values(entry.alterops))) - boundops = NamedContainer{keys(entry.boundops)}(map(transformation, values(entry.boundops))) +function (transformation::Transformation)(entry::Entry; kwargs...) + wrapper(m) = transformation(m; kwargs...) + constops = wrapper(entry.constops) + alterops = NamedContainer{keys(entry.alterops)}(map(wrapper, values(entry.alterops))) + boundops = NamedContainer{keys(entry.boundops)}(map(wrapper, values(entry.boundops))) return Entry(constops, alterops, boundops) end @@ -526,16 +527,18 @@ end """ (transformation::Transformation)(gen::AbstractGenerator; table::Union{Table, Nothing}=getcontent(gen, :table), - boundary::Boundary=getcontent(gen, :boundary) + boundary::Boundary=getcontent(gen, :boundary), + kwargs... ) -> SimplifiedGenerator Get the result of a transformation on the generator for the entry of quantum operators. """ function (transformation::Transformation)(gen::AbstractGenerator; table::Union{Table, Nothing}=getcontent(gen, :table), - boundary::Boundary=getcontent(gen, :boundary) + boundary::Boundary=getcontent(gen, :boundary), + kwargs... ) - return SimplifiedGenerator(Parameters(gen), transformation(getcontent(gen, :operators)), table=table, boundary=boundary) + return SimplifiedGenerator(Parameters(gen), transformation(getcontent(gen, :operators); kwargs...), table=table, boundary=boundary) end """ diff --git a/src/Essentials/QuantumOperators.jl b/src/Essentials/QuantumOperators.jl index 12f5e8d9..cc5836c6 100644 --- a/src/Essentials/QuantumOperators.jl +++ b/src/Essentials/QuantumOperators.jl @@ -810,14 +810,14 @@ abstract type Transformation <: Function end @inline Base.valtype(transformation::Transformation, m::QuantumOperator) = valtype(typeof(transformation), typeof(m)) """ - (transformation::Transformation)(ms::OperatorSum) -> OperatorSum + (transformation::Transformation)(ms::OperatorSum; kwargs...) -> OperatorSum Get the transformed quantum operators. """ -function (transformation::Transformation)(ms::OperatorSum) +function (transformation::Transformation)(ms::OperatorSum; kwargs...) result = zero(valtype(transformation, ms)) for m in ms - add!(result, transformation(m)) + add!(result, transformation(m; kwargs...)) end return result end @@ -829,7 +829,7 @@ The identity transformation. """ struct Identity <: Transformation end @inline Base.valtype(::Type{Identity}, M::Type{<:QuantumOperator}) = M -@inline (i::Identity)(m::Union{OperatorUnit, OperatorProd}) = m +@inline (i::Identity)(m::Union{OperatorUnit, OperatorProd}; kwargs...) = m """ Numericalization{T<:Number} <: Transformation @@ -844,7 +844,7 @@ struct Numericalization{T<:Number} <: Transformation end V = valtype(T, eltype(M)) return OperatorSum{V, idtype(V)} end -@inline (n::Numericalization)(m::OperatorProd) = convert(valtype(n, m), m) +@inline (n::Numericalization)(m::OperatorProd; kwargs...) = convert(valtype(n, m), m) """ MatrixRepresentation <: Transformation @@ -882,7 +882,7 @@ end @inline Base.valtype(P::Type{<:Permutation}, M::Type{<:OperatorSum}) = valtype(P, eltype(M)) """ - (permutation::Permutation)(m::OperatorProd) -> OperatorSum + (permutation::Permutation)(m::OperatorProd; kwargs...) -> OperatorSum Permute the operator units of an `OperatorProd` to the descending order according to the table contained in `permutation`. @@ -893,7 +893,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) +@inline function (permutation::Permutation)(m::OperatorProd; kwargs...) result = zero(valtype(permutation, m)) cache = eltype(result)[m] while length(cache) > 0 @@ -942,12 +942,12 @@ end @inline Base.valtype(P::Type{<:AbstractUnitSubstitution}, M::Type{<:OperatorSum}) = valtype(P, eltype(M)) """ - (unitsubstitution::AbstractUnitSubstitution)(m::OperatorProd) -> OperatorSum + (unitsubstitution::AbstractUnitSubstitution)(m::OperatorProd; kwargs...) -> OperatorSum Substitute every `OperatorUnit` in an `OperatorProd` with a new `OperatorSum`. """ -function (unitsubstitution::AbstractUnitSubstitution)(m::OperatorProd) - return prod(ntuple(i->unitsubstitution(m[i]), Val(rank(m))), init=value(m)) +function (unitsubstitution::AbstractUnitSubstitution)(m::OperatorProd; kwargs...) + return prod(ntuple(i->unitsubstitution(m[i]; kwargs...), Val(rank(m))), init=value(m)) end """ @@ -961,7 +961,7 @@ struct UnitSubstitution{U<:OperatorUnit, S<:OperatorSum, T<:AbstractDict{U, S}} new{keytype(table), valtype(table), typeof(table)}(table) end end -(unitsubstitution::UnitSubstitution)(m::OperatorUnit) = unitsubstitution.table[m] +(unitsubstitution::UnitSubstitution)(m::OperatorUnit; kwargs...) = unitsubstitution.table[m] """ RankFilter{R} <: Transformation @@ -981,6 +981,6 @@ end end @inline rank(rf::RankFilter) = rank(typeof(rf)) @inline rank(::Type{RankFilter{R}}) where R = R -@inline @generated (rf::RankFilter)(m::OperatorProd) = rank(m)==rank(rf) ? :(m) : 0 +@inline @generated (rf::RankFilter)(m::OperatorProd; kwargs...) = rank(m)==rank(rf) ? :(m) : 0 end #module