Skip to content

Commit

Permalink
Prepare for v0.8.3: key word arguments support for transfomations.
Browse files Browse the repository at this point in the history
  • Loading branch information
waltergu committed Nov 14, 2021
1 parent 5b026b4 commit dfb49d1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumLattices"
uuid = "78ae1a1f-1d5d-5174-b61c-66e31b2346dc"
authors = ["waltergu <[email protected]>"]
version = "0.8.2"
version = "0.8.3"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
19 changes: 11 additions & 8 deletions src/Essentials/Frameworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

"""
Expand Down
24 changes: 12 additions & 12 deletions src/Essentials/QuantumOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`.
Expand All @@ -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
Expand Down Expand Up @@ -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

"""
Expand All @@ -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
Expand All @@ -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

0 comments on commit dfb49d1

Please sign in to comment.