Skip to content

Commit c48fae0

Browse files
authored
Improve deprecated functionality (#210)
1 parent bd2550f commit c48fae0

File tree

5 files changed

+47
-17
lines changed

5 files changed

+47
-17
lines changed

src/deprecated.jl

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,56 @@
11
#=
22
This file gathers all the deprecated names (structures, functions, or variables) which will be removed in the future major release.
33
4-
- Before the major release, the deprecated names will just throw errors when they are called.
4+
- Before the major release, the deprecated names will show warnings or just throw errors when they are called.
55
- If the deprecated names were once exported, we will still export them here until next major release.
66
- If we decide to push a major release, cleanup this file.
77
8-
Example:
9-
8+
Example 1 [throw errors if the deprecation is fundamental, and there is no replacement for it]:
9+
```
1010
export deprecated_foo
11+
deprecated_foo(args...; kwargs...) = error("`deprecated_foo` is deprecated and will be removed in next major release.")
12+
```
13+
14+
Example 2 ["force" show warning and tell the users that there is a replacement for the deprecated function]:
1115
16+
```
17+
export deprecated_foo
1218
function deprecated_foo(args...; kwargs...)
13-
error("`deprecated_foo` has been deprecated and will be removed in next major release, please use `new_foo` instead.")
19+
Base.depwarn("`deprecated_foo` is deprecated and will be removed in next major release, use `new_foo` instead.", :deprecated_foo, force = true)
20+
new_foo(args...; kwargs...)
1421
end
22+
```
1523
=#
1624

17-
export evolution, SteadyState, C
18-
19-
SteadyState(args...; kwargs...) = error("`SteadyState` has been deprecated, please use `steadystate` instead.")
25+
export SteadyState
26+
function SteadyState(args...; kwargs...)
27+
Base.depwarn(
28+
"`SteadyState` is deprecated and will be removed in next major release, use `steadystate` instead.",
29+
:SteadyState,
30+
force = true,
31+
)
32+
return steadystate(args...; kwargs...)
33+
end
2034

21-
evolution(args...; kwargs...) = error("`evolution` has been deprecated, please use `HEOMsolve` instead.")
35+
export evolution
36+
function evolution(args...; kwargs...)
37+
Base.depwarn(
38+
"`evolution` is deprecated and will be removed in next major release, use `HEOMsolve` instead.",
39+
:evolution,
40+
force = true,
41+
)
42+
return HEOMsolve(args...; kwargs...)
43+
end
2244

23-
C(args...; kwargs...) = error("`C` has been deprecated, please use `correlation_function` instead.")
45+
export C
46+
function C(args...)
47+
Base.depwarn(
48+
"`C` is deprecated and will be removed in next major release, use `correlation_function` instead.",
49+
:C,
50+
force = true,
51+
)
52+
return correlation_function(args...)
53+
end
2454

2555
_HEOMSuperOp_deprecated_method_error() = error(
2656
"Specifying `mul_basis = \"L\", \"R\", or \"LR\"` to `HEOMSuperOp` has been deprecated, try to construct system SuperOperator manually by using `spre`, `spost`, or `sprepost`.",

src/heom_matrices/HierarchyDict.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ Here is an example to use [`Bath`](@ref lib-Bath), [`Exponent`](@ref), [`Hierarc
288288
```julia
289289
L::M_Fermion; # suppose this is a fermion type of HEOM Liouvillian superoperator matrix you create
290290
HDict = L.hierarchy; # the hierarchy dictionary
291-
ados = SteadyState(L); # the stationary state (ADOs) for L
291+
ados = steadystate(L); # the stationary state (ADOs) for L
292292
293293
# Let's consider all the ADOs for first level
294294
idx_list = HDict.lvl2idx[1];

test/bath.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
types = ["bRI", "bRI", "bR", "bR", "bI", "bI", "bI"]
4343
@test length(b) == 7
4444
@test correlation_function(b, 0.183183)[1] correlation_function(bs, [0.183183])[1]
45-
@test_throws ErrorException C(bs, [0.183183])
45+
@test_logs (:warn,) C(bs, [0.183183]) # deprecated function
4646

4747
## check for η and γ list, and coupling operator
4848
η = Vector{ComplexF64}(undef, length(b))
@@ -82,7 +82,7 @@
8282
types = ["bA", "bA", "bA", "bA", "bA", "bE", "bE", "bE", "bE", "bE"]
8383
@test length(bs) == 10
8484
cp, cm = correlation_function(b, 0.183183)
85-
@test_throws ErrorException C(b, [0.183183])
85+
@test_logs (:warn,) C(b, [0.183183]) # deprecated function
8686
@test cp[1] 22.384506765987076 + 0.7399082821797519im
8787
@test cm[1] 26.994911851482776 - 0.799138487523946im
8888

@@ -136,7 +136,7 @@
136136
types = ["fA", "fA", "fA", "fA", "fA", "fE", "fE", "fE", "fE", "fE"]
137137
@test length(b) == 10
138138
cp, cm = correlation_function(b, 0.183183)
139-
@test_throws ErrorException C(b, [0.183183])
139+
@test_logs (:warn,) C(b, [0.183183]) # deprecated function
140140
@test cp[1] 22.384506765987076 + 0.7399082821797519im
141141
@test cm[1] 26.994911851482776 - 0.799138487523946im
142142
for (i, e) in enumerate(b)

test/stationary_state.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
mat = Qobj(zeros(ComplexF64, 2, 2))
3131
mat2 = Qobj(zeros(ComplexF64, 3, 3))
3232
bathf = Fermion_Lorentz_Pade(mat, 1, 1, 1, 1, 2)
33-
@test_throws ErrorException SteadyState(L)
34-
@test_throws ErrorException SteadyState(L, ψ0)
33+
@test_logs (:warn,) SteadyState(L) # deprecated function
34+
@test_logs (:warn,) SteadyState(L, ψ0) # deprecated function
3535
@test_throws ErrorException steadystate(M_Fermion(mat, 2, bathf, ODD; verbose = false))
3636
@test_throws ErrorException steadystate(M_Fermion(mat, 2, bathf, ODD; verbose = false), mat)
3737
@test_throws ErrorException steadystate(L, mat2)

test/time_evolution.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
ρ_list_p = getRho.(ados_list)
3434
@test show(devnull, MIME("text/plain"), sol_p) === nothing
3535
@test length(sol_p.ados) == 1
36-
@test_throws ErrorException evolution(L, ψ0, Δt, steps; verbose = false)
36+
@test_logs (:warn,) evolution(L, ψ0, Δt, steps; verbose = false) # deprecated function
3737
@test_throws ErrorException heomsolve(L, ρ_wrong, Δt, steps; verbose = false)
3838
@test_throws ErrorException heomsolve(L, ados_wrong1, Δt, steps; verbose = false)
3939
@test_throws ErrorException heomsolve(L, ados_wrong2, Δt, steps; verbose = false)
@@ -46,7 +46,7 @@
4646
ρ_list_e = getRho.(sol_e.ados)
4747
expvals_e = sol_e.expect
4848
@test show(devnull, MIME("text/plain"), sol_e) === nothing
49-
@test_throws ErrorException evolution(L, ψ0, tlist; progress_bar = Val(false))
49+
@test_logs (:warn,) evolution(L, ψ0, tlist; progress_bar = Val(false)) # deprecated function
5050
@test_throws ErrorException heomsolve(L, ψ0, tlist; verbose = true)
5151
@test_throws ErrorException heomsolve(L, ψ0, tlist; filename = "test")
5252
@test_throws DimensionMismatch heomsolve(L, ρ_wrong, tlist; progress_bar = Val(false))

0 commit comments

Comments
 (0)