Skip to content

Commit 7957ef8

Browse files
committed
add type inferrence tests for QobjEvo
1 parent b26f6e3 commit 7957ef8

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

test/core-test/quantum_objects_evo.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,24 @@
119119
"Quantum Object Evo.: type=SuperOperator dims=$L_dims size=$L_size ishermitian=$L_isherm isconstant=$L_isconst\n$datastring"
120120
end
121121

122-
@testset "Type Inference (QuantumObject)" begin
122+
@testset "Type Inference (QobjEvo)" begin
123+
N = 4
123124
for T in [ComplexF32, ComplexF64]
124-
N = 4
125125
a = MatrixOperator(rand(T, N, N))
126126
@inferred QobjEvo(a)
127127
for type in [Operator, SuperOperator]
128128
@inferred QobjEvo(a, type = type)
129129
end
130130
end
131131

132+
a = destroy(N)
133+
coef1(p, t) = exp(-t)
134+
coef2(p::Vector, t) = sin(p[1] * t)
135+
coef3(p::NamedTuple, t) = cos(p.ω * t)
136+
@inferred QobjEvo(a, coef1)
137+
@inferred QobjEvo((a', coef2))
138+
@inferred QobjEvo((a' * a, (a, coef1), (a', coef2), (a + a', coef3)))
139+
132140
@testset "Math Operation" begin
133141
a = QobjEvo(destroy(20))
134142
σx = QobjEvo(sigmax())
@@ -206,9 +214,11 @@
206214
@test isconstant(L_td) == false
207215
@test issuper(L_td) == true
208216

209-
coef_wrong(t) = exp(-t)
217+
coef_wrong1(t) = nothing
218+
coef_wrong2(p, t::ComplexF64) = nothing
210219
@test_logs (:warn,) (:warn,) liouvillian(H_td * H_td) # warnings from lazy tensor
211-
@test_throws ArgumentError QobjEvo(a, coef_wrong)
220+
@test_throws ArgumentError QobjEvo(a, coef_wrong1)
221+
@test_throws ArgumentError QobjEvo(a, coef_wrong2)
212222
@test_throws MethodError QobjEvo([[a, coef1], a' * a, [a', coef2]])
213223
@test_throws ArgumentError H_td(ρvec, p, t)
214224
@test_throws ArgumentError cache_operator(H_td, ρvec)

0 commit comments

Comments
 (0)