diff --git a/src/qobj/quantum_object.jl b/src/qobj/quantum_object.jl index 84e347851..3c0121dc3 100644 --- a/src/qobj/quantum_object.jl +++ b/src/qobj/quantum_object.jl @@ -140,7 +140,7 @@ function Base.show( return show(io, MIME("text/plain"), op_data) end -function Base.show(io::IO, QO::AbstractQuantumObject) +function Base.show(io::IO, QO::QuantumObject) op_data = QO.data println( io, diff --git a/src/qobj/quantum_object_evo.jl b/src/qobj/quantum_object_evo.jl index 9d25858e0..8786669b5 100644 --- a/src/qobj/quantum_object_evo.jl +++ b/src/qobj/quantum_object_evo.jl @@ -112,6 +112,24 @@ struct QuantumObjectEvolution{ end end +function Base.show(io::IO, QO::QuantumObjectEvolution) + op_data = QO.data + println( + io, + "Quantum Object Evo.: type=", + QO.type, + " dims=", + QO.dims, + " size=", + size(op_data), + " ishermitian=", + ishermitian(op_data), + " isconstant=", + isconstant(op_data), + ) + return show(io, MIME("text/plain"), op_data) +end + function QuantumObjectEvolution(data::AbstractSciMLOperator, type::QuantumObjectType, dims::Integer) return QuantumObjectEvolution(data, type, SVector{1,Int}(dims)) end diff --git a/test/core-test/quantum_objects_evo.jl b/test/core-test/quantum_objects_evo.jl index 933590e67..4d41df619 100644 --- a/test/core-test/quantum_objects_evo.jl +++ b/test/core-test/quantum_objects_evo.jl @@ -93,27 +93,31 @@ @test issymmetric(Z) == true end - # TODO: Implement a new show method for QuantumObjectEvolution - # @testset "REPL show" begin - # N = 10 - # a = QobjEvo(destroy(N)) - - # opstring = sprint((t, s) -> show(t, "text/plain", s), a) - # datastring = sprint((t, s) -> show(t, "text/plain", s), a.data) - # a_dims = a.dims - # a_size = size(a) - # a_isherm = isherm(a) - # @test opstring == - # "Quantum Object: type=Operator dims=$a_dims size=$a_size ishermitian=$a_isherm\n$datastring" - - # a = spre(a) - # opstring = sprint((t, s) -> show(t, "text/plain", s), a) - # datastring = sprint((t, s) -> show(t, "text/plain", s), a.data) - # a_dims = a.dims - # a_size = size(a) - # a_isherm = isherm(a) - # @test opstring == "Quantum Object: type=SuperOperator dims=$a_dims size=$a_size\n$datastring" - # end + @testset "REPL show" begin + N = 10 + a = destroy(N) + coef(p, t) = exp(-1im * t) + H = QobjEvo((a' * a, (a, coef))) + + opstring = sprint((t, s) -> show(t, "text/plain", s), H) + datastring = sprint((t, s) -> show(t, "text/plain", s), H.data) + H_dims = H.dims + H_size = size(H) + H_isherm = isherm(H) + H_isconst = isconstant(H) + @test opstring == + "Quantum Object Evo.: type=Operator dims=$H_dims size=$H_size ishermitian=$H_isherm isconstant=$H_isconst\n$datastring" + + L = QobjEvo(spre(a)) + opstring = sprint((t, s) -> show(t, "text/plain", s), L) + datastring = sprint((t, s) -> show(t, "text/plain", s), L.data) + L_dims = L.dims + L_size = size(L) + L_isherm = isherm(L) + L_isconst = isconstant(L) + @test opstring == + "Quantum Object Evo.: type=SuperOperator dims=$L_dims size=$L_size ishermitian=$L_isherm isconstant=$L_isconst\n$datastring" + end @testset "Type Inference (QuantumObject)" begin for T in [ComplexF32, ComplexF64]