Skip to content

Commit 9589073

Browse files
committed
add show method for QobjEvo
1 parent 3357706 commit 9589073

File tree

4 files changed

+51
-22
lines changed

4 files changed

+51
-22
lines changed

src/QuantumToolbox.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import SciMLBase:
3535
import StochasticDiffEq: StochasticDiffEqAlgorithm, SRA1
3636
import SciMLOperators:
3737
AbstractSciMLOperator,
38+
AddedOperator,
3839
MatrixOperator,
3940
ScalarOperator,
4041
IdentityOperator,

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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,28 @@ 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+
" num_elements=",
130+
_get_SciMLOperator_num_elements(op_data),
131+
)
132+
return show(io, MIME("text/plain"), op_data)
133+
end
134+
_get_SciMLOperator_num_elements(A::AddedOperator) = length(A.ops)
135+
_get_SciMLOperator_num_elements(A::AbstractSciMLOperator) = 1
136+
115137
function QuantumObjectEvolution(data::AbstractSciMLOperator, type::QuantumObjectType, dims::Integer)
116138
return QuantumObjectEvolution(data, type, SVector{1,Int}(dims))
117139
end

test/core-test/quantum_objects_evo.jl

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,33 @@
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+
H_elements = 2
109+
@test opstring ==
110+
"Quantum Object Evo.: type=Operator dims=$H_dims size=$H_size ishermitian=$H_isherm isconstant=$H_isconst num_elements=$$H_elements\n$datastring"
111+
112+
L = QobjEvo(spre(a))
113+
opstring = sprint((t, s) -> show(t, "text/plain", s), L)
114+
datastring = sprint((t, s) -> show(t, "text/plain", s), L.data)
115+
L_dims = L.dims
116+
L_size = size(L)
117+
L_isherm = isherm(L)
118+
L_isconst = isconstant(L)
119+
H_elements = 1
120+
@test opstring ==
121+
"Quantum Object Evo.: type=SuperOperator dims=$L_dims size=$L_size ishermitian=$L_isherm isconstant=$L_isconst num_elements=$$L_elements\n$datastring"
122+
end
117123

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

0 commit comments

Comments
 (0)