Skip to content

Commit

Permalink
Modify the nameof function in Frameworks.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
waltergu committed Oct 7, 2022
1 parent 6e76628 commit a945407
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/Frameworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,11 @@ Get the repr representation of an algorithm.
Optionally, some parameters of the algorithm can be filtered by specifying the `f` function. Besides, the maximum number of decimals of the parameters can also be specified by the keyword argument `ndecimal`.
"""
function Base.repr(alg::Algorithm, f::Function=param->true; ndecimal::Int=10)
result = [@sprintf "%s(%s)" alg.name alg.frontend]
result = String[]
for (name, value) in pairs(alg.parameters)
f(name) && push!(result, decimaltostr(value, ndecimal))
f(name) && push!(result, @sprintf "%s(%s)" name decimaltostr(value, ndecimal))
end
return join(result, "_")
return @sprintf "%s(%s)-%s" alg.name alg.frontend join(result, "")
end

"""
Expand All @@ -674,7 +674,7 @@ end
Get the name of the combination of an algorithm and an assignment.
"""
@inline Base.nameof(alg::Algorithm, assign::Assignment) = @sprintf "%s_%s" repr(alg) assign.id
@inline Base.nameof(alg::Algorithm, assign::Assignment) = @sprintf "%s-%s" repr(alg) assign.id

"""
add!(alg::Algorithm, id::Symbol, action::Action; parameters::Parameters=Parameters{()}(), map::Function=identity, dependences::Tuple=(), kwargs...) -> Tuple{Algorithm, Assignment}
Expand Down
16 changes: 8 additions & 8 deletions test/Frameworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ end
@inline run!(alg::Algorithm{VCA}, assign::Assignment{GF}) = (assign.action.count += 1; assign.data[:, :] .= alg.frontend.t+alg.frontend.U)

mutable struct DOS <: Action
mu::Float
μ::Float
end
@inline update!(eb::DOS; kwargs...) = (eb.mu = get(kwargs, :mu, eb.mu); eb)
@inline update!(eb::DOS; kwargs...) = (eb.μ = get(kwargs, :μ, eb.μ); eb)
@inline initialize(dos::DOS, vca::VCA) = 0.0
@inline function run!(alg::Algorithm{VCA}, assign::Assignment{DOS})
prepare!(alg, assign)
gf = alg.assignments[first(assign.dependences)]
assign.data = tr(gf.data)
end
@inline dosmap(params::Parameters) = Parameters{(:t, :U, :mu)}(params.t, params.U, -params.U/2)
@inline dosmap(params::Parameters) = Parameters{(:t, :U, :μ)}(params.t, params.U, -params.U/2)

@testset "Framework" begin
vca = VCA(1.0, 8.0, 4)
Expand All @@ -192,8 +192,8 @@ end
@test vca == deepcopy(vca)
@test isequal(vca, deepcopy(vca))
@test Parameters(vca) == vca.parameters
@test repr(vca, (:U)) == "test(VCA)_1.0"
@test repr(vca) == "test(VCA)_1.0_8.0"
@test repr(vca, (:U)) == "test(VCA)-t(1.0)"
@test repr(vca) == "test(VCA)-t(1.0)U(8.0)"

add!(vca, :GF, GF(0))
rex = r"Action DOS\(DOS\)\: time consumed [0-9]*\.[0-9]*(e[+-][0-9]*)*s."
Expand All @@ -205,12 +205,12 @@ end
@test Parameters(dos) == dos.parameters
@test valtype(dos) == valtype(typeof(dos)) == Float
@test dos.data == 32.0
@test dos.action.mu == -3.5
@test nameof(vca, dos) == "test(VCA)_1.0_7.0_DOS"
@test dos.action.μ == -3.5
@test nameof(vca, dos) == "test(VCA)-t(1.0)U(7.0)-DOS"

update!(dos, U=6.0)
vca(:DOS, info=false)
@test dos.parameters == (t=1.0, U=6.0)
@test dos.data == 28.0
@test dos.action.mu == -3.0
@test dos.action.μ == -3.0
end

0 comments on commit a945407

Please sign in to comment.