Skip to content

Commit f8de78e

Browse files
committed
use Base.depwarn for deprecated functionality
1 parent e8ec73f commit f8de78e

File tree

4 files changed

+89
-41
lines changed

4 files changed

+89
-41
lines changed

src/deprecated.jl

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,53 @@
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

1725
export FFTCorrelation
18-
export sparse_to_dense, dense_to_sparse
19-
2026
FFTCorrelation() = error(
21-
"`FFTCorrelation` has been deprecated and will be removed in next major release, please use `spectrum_correlation_fft` to calculate the spectrum with FFT method instead.",
27+
"`FFTCorrelation` is deprecated and will be removed in next major release, use `spectrum_correlation_fft` to calculate the spectrum with FFT method instead.",
2228
)
2329

24-
sparse_to_dense(args...) = error(
25-
"`sparse_to_dense` has been deprecated and will be removed in next major release, please use `to_dense` instead.",
26-
)
27-
dense_to_sparse(args...) = error(
28-
"`dense_to_sparse` has been deprecated and will be removed in next major release, please use `to_sparse` instead.",
29-
)
30+
export sparse_to_dense
31+
function sparse_to_dense(args...)
32+
Base.depwarn(
33+
"`sparse_to_dense` is deprecated and will be removed in next major release, use `to_dense` instead.",
34+
:sparse_to_dense,
35+
force = true,
36+
)
37+
return to_dense(args...)
38+
end
3039

31-
correlation_3op_2t(
40+
export dense_to_sparse
41+
function dense_to_sparse(args...)
42+
Base.depwarn(
43+
"`dense_to_sparse` is deprecated and will be removed in next major release, use `to_sparse` instead.",
44+
:dense_to_sparse,
45+
force = true,
46+
)
47+
return to_sparse(args...)
48+
end
49+
50+
function correlation_3op_2t(
3251
H::QuantumObject{HOpType},
3352
ψ0::QuantumObject{StateOpType},
3453
t_l::AbstractVector,
@@ -38,11 +57,16 @@ correlation_3op_2t(
3857
C::QuantumObject{Operator},
3958
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
4059
kwargs...,
41-
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}} = error(
42-
"The parameter order of `correlation_3op_2t` has been changed, please use `?correlation_3op_2t` to check the updated docstring.",
43-
)
60+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}}
61+
Base.depwarn(
62+
"The argument order of `correlation_3op_2t(H, ψ0, t_l, τ_l, A, B, C, c_ops)` is changed to `correlation_3op_2t(H, ψ0, t_l, τ_l, c_ops, A, B, C)`, use `?correlation_3op_2t` to check the updated docstring.",
63+
:correlation_3op_2t,
64+
force = true,
65+
)
66+
return correlation_3op_2t(H, ψ0, t_l, τ_l, c_ops, A, B, C; kwargs...)
67+
end
4468

45-
correlation_3op_1t(
69+
function correlation_3op_1t(
4670
H::QuantumObject{HOpType},
4771
ψ0::QuantumObject{StateOpType},
4872
τ_l::AbstractVector,
@@ -51,11 +75,16 @@ correlation_3op_1t(
5175
C::QuantumObject{Operator},
5276
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
5377
kwargs...,
54-
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}} = error(
55-
"The parameter order of `correlation_3op_1t` has been changed, please use `?correlation_3op_1t` to check the updated docstring.",
56-
)
78+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}}
79+
Base.depwarn(
80+
"The argument order of `correlation_3op_1t(H, ψ0, τ_l, A, B, C, c_ops)` is changed to `correlation_3op_1t(H, ψ0, τ_l, c_ops, A, B, C)`, use `?correlation_3op_1t` to check the updated docstring.",
81+
:correlation_3op_1t,
82+
force = true,
83+
)
84+
return correlation_3op_1t(H, ψ0, τ_l, c_ops, A, B, C; kwargs...)
85+
end
5786

58-
correlation_2op_2t(
87+
function correlation_2op_2t(
5988
H::QuantumObject{HOpType},
6089
ψ0::QuantumObject{StateOpType},
6190
t_l::AbstractVector,
@@ -65,11 +94,16 @@ correlation_2op_2t(
6594
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
6695
reverse::Bool = false,
6796
kwargs...,
68-
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}} = error(
69-
"The parameter order of `correlation_2op_2t` has been changed, please use `?correlation_2op_2t` to check the updated docstring.",
70-
)
97+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}}
98+
Base.depwarn(
99+
"The argument order of `correlation_2op_2t(H, ψ0, t_l, τ_l, A, B, c_ops)` is changed to `correlation_2op_2t(H, ψ0, t_l, τ_l, c_ops, A, B)`, use `?correlation_2op_2t` to check the updated docstring.",
100+
:correlation_2op_2t,
101+
force = true,
102+
)
103+
return correlation_2op_2t(H, ψ0, t_l, τ_l, c_ops, A, B; reverse = reverse, kwargs...)
104+
end
71105

72-
correlation_2op_1t(
106+
function correlation_2op_1t(
73107
H::QuantumObject{HOpType},
74108
ψ0::QuantumObject{StateOpType},
75109
τ_l::AbstractVector,
@@ -78,10 +112,21 @@ correlation_2op_1t(
78112
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
79113
reverse::Bool = false,
80114
kwargs...,
81-
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}} = error(
82-
"The parameter order of `correlation_2op_1t` has been changed, please use `?correlation_2op_1t` to check the updated docstring.",
83-
)
115+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}}
116+
Base.depwarn(
117+
"The argument order of `correlation_2op_1t(H, ψ0, τ_l, A, B, c_ops)` is changed to `correlation_2op_1t(H, ψ0, τ_l, c_ops, A, B)`, use `?correlation_2op_1t` to check the updated docstring.",
118+
:correlation_2op_1t,
119+
force = true,
120+
)
121+
return correlation_2op_1t(H, ψ0, τ_l, c_ops, A, B; reverse = reverse, kwargs...)
122+
end
84123

85-
MultiSiteOperator(dims::Union{AbstractVector,Tuple}, pairs::Pair{<:Integer,<:QuantumObject}...) = error(
86-
"`MultiSiteOperator` has been deprecated and will be removed in next major release, please use `multisite_operator` instead.",
87-
)
124+
export MultiSiteOperator
125+
function MultiSiteOperator(args...)
126+
Base.depwarn(
127+
"`MultiSiteOperator` is deprecated and will be removed in next major release, use `multisite_operator` instead.",
128+
:MultiSiteOperator,
129+
force = true,
130+
)
131+
return multisite_operator(args...)
132+
end

test/core-test/correlations_and_spectrum.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@
6868
@test_throws ArgumentError correlation_3op_2t(H, nothing, t_wrong2, t_wrong1, c_ops, Id, a', a)
6969
@test_throws ArgumentError correlation_3op_2t(H, nothing, t_wrong2, t_wrong2, c_ops, Id, a', a)
7070

71-
@testset "Deprecated Errors" begin
71+
@testset "Deprecated Errors and Warnings" begin
7272
ρ0 = rand_dm(N)
73+
t_l = [0.0, 1.0] # make time list shorter
7374
@test_throws ErrorException FFTCorrelation()
74-
@test_throws ErrorException correlation_3op_2t(H, ρ0, t_l, t_l, a, a', a, c_ops)
75-
@test_throws ErrorException correlation_3op_1t(H, ρ0, t_l, a, a', a, c_ops)
76-
@test_throws ErrorException correlation_2op_2t(H, ρ0, t_l, t_l, a', a, c_ops)
77-
@test_throws ErrorException correlation_2op_1t(H, ρ0, t_l, a', a, c_ops)
75+
@test_logs (:warn,) correlation_3op_2t(H, ρ0, t_l, t_l, a, a', a, c_ops; progress_bar = Val(false))
76+
@test_logs (:warn,) correlation_3op_1t(H, ρ0, t_l, a, a', a, c_ops; progress_bar = Val(false))
77+
@test_logs (:warn,) correlation_2op_2t(H, ρ0, t_l, t_l, a', a, c_ops; progress_bar = Val(false))
78+
@test_logs (:warn,) correlation_2op_1t(H, ρ0, t_l, a', a, c_ops; progress_bar = Val(false))
7879
end
7980
end

test/core-test/low_rank_dynamics.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
tl = range(0, 10, 100)
6161

6262
# Full solution
63-
sol_me = mesolve(H, ρ, tl, c_ops; e_ops = [e_ops...])
63+
sol_me = mesolve(H, ρ, tl, c_ops; e_ops = [e_ops...], progress_bar = Val(false))
6464
Strue = entropy_vn(sol_me.states[end], base = 2) / latt.N
6565

6666
# Low rank solution
@@ -82,4 +82,6 @@
8282

8383
@test real(sol_me.expect[1, :]) real(sol_lr.expect[1, :]) atol = 1e-1
8484
@test S_lr Strue atol = 1e-1
85+
86+
@test_logs (:warn,) MultiSiteOperator(latt, 1 => sigmax()) # deprecated warning
8587
end

test/core-test/quantum_objects.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@
351351
@test typeof(SparseMatrixCSC(Ms).data) == SparseMatrixCSC{Int64,Int64}
352352
@test typeof(SparseMatrixCSC{ComplexF64}(Ms).data) == SparseMatrixCSC{ComplexF64,Int64}
353353

354-
@testset "Deprecated Errors" begin
355-
@test_throws ErrorException sparse_to_dense(vs)
356-
@test_throws ErrorException dense_to_sparse(vd)
354+
@testset "Deprecated Warnings" begin
355+
@test_logs (:warn,) sparse_to_dense(vs)
356+
@test_logs (:warn,) dense_to_sparse(vd)
357357
end
358358
end
359359

0 commit comments

Comments
 (0)