Skip to content

Commit df3b4f7

Browse files
authored
Add show method for QobjEvo (#272)
2 parents f5b87fd + b36d18c commit df3b4f7

File tree

3 files changed

+44
-22
lines changed

3 files changed

+44
-22
lines changed

src/qobj/quantum_object.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function Base.show(
140140
return show(io, MIME("text/plain"), op_data)
141141
end
142142

143-
function Base.show(io::IO, QO::AbstractQuantumObject)
143+
function Base.show(io::IO, QO::QuantumObject)
144144
op_data = QO.data
145145
println(
146146
io,

src/qobj/quantum_object_evo.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ struct QuantumObjectEvolution{
112112
end
113113
end
114114

115+
function Base.show(io::IO, QO::QuantumObjectEvolution)
116+
op_data = QO.data
117+
println(
118+
io,
119+
"Quantum Object Evo.: type=",
120+
QO.type,
121+
" dims=",
122+
QO.dims,
123+
" size=",
124+
size(op_data),
125+
" ishermitian=",
126+
ishermitian(op_data),
127+
" isconstant=",
128+
isconstant(op_data),
129+
)
130+
return show(io, MIME("text/plain"), op_data)
131+
end
132+
115133
function QuantumObjectEvolution(data::AbstractSciMLOperator, type::QuantumObjectType, dims::Integer)
116134
return QuantumObjectEvolution(data, type, SVector{1,Int}(dims))
117135
end

test/core-test/quantum_objects_evo.jl

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,31 @@
9393
@test issymmetric(Z) == true
9494
end
9595

96-
# TODO: Implement a new show method for QuantumObjectEvolution
97-
# @testset "REPL show" begin
98-
# N = 10
99-
# a = QobjEvo(destroy(N))
100-
101-
# opstring = sprint((t, s) -> show(t, "text/plain", s), a)
102-
# datastring = sprint((t, s) -> show(t, "text/plain", s), a.data)
103-
# a_dims = a.dims
104-
# a_size = size(a)
105-
# a_isherm = isherm(a)
106-
# @test opstring ==
107-
# "Quantum Object: type=Operator dims=$a_dims size=$a_size ishermitian=$a_isherm\n$datastring"
108-
109-
# a = spre(a)
110-
# opstring = sprint((t, s) -> show(t, "text/plain", s), a)
111-
# datastring = sprint((t, s) -> show(t, "text/plain", s), a.data)
112-
# a_dims = a.dims
113-
# a_size = size(a)
114-
# a_isherm = isherm(a)
115-
# @test opstring == "Quantum Object: type=SuperOperator dims=$a_dims size=$a_size\n$datastring"
116-
# end
96+
@testset "REPL show" begin
97+
N = 10
98+
a = destroy(N)
99+
coef(p, t) = exp(-1im * t)
100+
H = QobjEvo((a' * a, (a, coef)))
101+
102+
opstring = sprint((t, s) -> show(t, "text/plain", s), H)
103+
datastring = sprint((t, s) -> show(t, "text/plain", s), H.data)
104+
H_dims = H.dims
105+
H_size = size(H)
106+
H_isherm = isherm(H)
107+
H_isconst = isconstant(H)
108+
@test opstring ==
109+
"Quantum Object Evo.: type=Operator dims=$H_dims size=$H_size ishermitian=$H_isherm isconstant=$H_isconst\n$datastring"
110+
111+
L = QobjEvo(spre(a))
112+
opstring = sprint((t, s) -> show(t, "text/plain", s), L)
113+
datastring = sprint((t, s) -> show(t, "text/plain", s), L.data)
114+
L_dims = L.dims
115+
L_size = size(L)
116+
L_isherm = isherm(L)
117+
L_isconst = isconstant(L)
118+
@test opstring ==
119+
"Quantum Object Evo.: type=SuperOperator dims=$L_dims size=$L_size ishermitian=$L_isherm isconstant=$L_isconst\n$datastring"
120+
end
117121

118122
@testset "Type Inference (QuantumObject)" begin
119123
for T in [ComplexF32, ComplexF64]

0 commit comments

Comments
 (0)