Skip to content

Conversation

@ytdHuang
Copy link
Member

@ytdHuang ytdHuang commented Jan 6, 2025

Checklist

Thank you for contributing to QuantumToolbox.jl! Please make sure you have finished the following tasks before opening the PR.

  • Please read Contributing to QuantumToolbox.jl.
  • Any code changes were done in a way that does not break public API.
  • Appropriate tests were added and tested locally by running: make test.
  • Any code changes should be julia formatted by running: make format.
  • All documents (in docs/ folder) related to code changes were updated and able to build locally by running: make docs.
  • (If necessary) the CHANGELOG.md should be updated (regarding to the code changes) and built by running: make changelog.

Request for a review after you have completed all the tasks. If you have not finished them all, you can also open a Draft Pull Request to let the others know this on-going work.

Description

The current show for Qobj tuples print as the following style:

julia> a = destroy(2);
julia> (a, a', a + a')
(Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 SparseMatrixCSC{ComplexF64, Int64} with 1 stored entry:
     ⋅      1.0+0.0im
     ⋅          ⋅    , Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 Adjoint{ComplexF64, SparseMatrixCSC{ComplexF64, Int64}} with 1 stored entry:
     ⋅          ⋅    
 1.0-0.0im      ⋅    , Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=true
2×2 SparseMatrixCSC{ComplexF64, Int64} with 2 stored entries:
     ⋅      1.0+0.0im
 1.0+0.0im      ⋅    )
julia> (a, QobjEvo(a))
(Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 SparseMatrixCSC{ComplexF64, Int64} with 1 stored entry:
     ⋅      1.0+0.0im
     ⋅          ⋅    , Quantum Object Evo.:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false   isconstant=true
MatrixOperator(2 × 2))

With this PR, every Qobj / QobjEvo prints from a new line, that is:

julia> (a, a', a + a')
(
Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 SparseMatrixCSC{ComplexF64, Int64} with 1 stored entry:
     ⋅      1.0+0.0im
     ⋅          ⋅    , 
Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 Adjoint{ComplexF64, SparseMatrixCSC{ComplexF64, Int64}} with 1 stored entry:
     ⋅          ⋅    
 1.0-0.0im      ⋅    , 
Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=true
2×2 SparseMatrixCSC{ComplexF64, Int64} with 2 stored entries:
     ⋅      1.0+0.0im
 1.0+0.0im      ⋅    )
julia> (a, QobjEvo(a))
(
Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 SparseMatrixCSC{ComplexF64, Int64} with 1 stored entry:
     ⋅      1.0+0.0im
     ⋅          ⋅    , 
Quantum Object Evo.:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false   isconstant=true
MatrixOperator(2 × 2))

This is useful when checking the c_ops, e_ops, and so on, when they are in Tuple type.

Also, for Vector and SVector:

julia> [a, a', a + a']
3-element Vector{QuantumObject{MT, OperatorQuantumObject, 1} where MT<:AbstractArray}:
 
Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 SparseMatrixCSC{ComplexF64, Int64} with 1 stored entry:
     ⋅      1.0+0.0im
     ⋅          ⋅    
 
Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 Adjoint{ComplexF64, SparseMatrixCSC{ComplexF64, Int64}} with 1 stored entry:
     ⋅          ⋅    
 1.0-0.0im      ⋅    
 
Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=true
2×2 SparseMatrixCSC{ComplexF64, Int64} with 2 stored entries:
     ⋅      1.0+0.0im
 1.0+0.0im      ⋅
julia> SVector{3}([a, a', a + a'])
3-element SVector{3, QuantumObject{MT, OperatorQuantumObject, 1} where MT<:AbstractArray} with indices SOneTo(3):
 
Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 SparseMatrixCSC{ComplexF64, Int64} with 1 stored entry:
     ⋅      1.0+0.0im
     ⋅          ⋅    
 
Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 Adjoint{ComplexF64, SparseMatrixCSC{ComplexF64, Int64}} with 1 stored entry:
     ⋅          ⋅    
 1.0-0.0im      ⋅    
 
Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=true
2×2 SparseMatrixCSC{ComplexF64, Int64} with 2 stored entries:
     ⋅      1.0+0.0im
 1.0+0.0im      ⋅

@ytdHuang ytdHuang added the Skip ChangeLog Skip changelog update check in PR label Jan 6, 2025
@codecov
Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.14%. Comparing base (270d3f6) to head (22bbfb9).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #365   +/-   ##
=======================================
  Coverage   93.14%   93.14%           
=======================================
  Files          41       41           
  Lines        2684     2684           
=======================================
  Hits         2500     2500           
  Misses        184      184           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@albertomercurio
Copy link
Member

Don't we simply fix it if we define the Base.show method with a break line at the end?

@ytdHuang
Copy link
Member Author

ytdHuang commented Jan 6, 2025

Don't we simply fix it if we define the Base.show method with a break line at the end?

If we add \n after showing AbstractQuantumObject, it will become:

(Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 SparseMatrixCSC{ComplexF64, Int64} with 1 stored entry:
     ⋅      1.0+0.0im
     ⋅          ⋅    
, Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 Adjoint{ComplexF64, SparseMatrixCSC{ComplexF64, Int64}} with 1 stored entry:
     ⋅          ⋅    
 1.0-0.0im      ⋅    
, Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=true
2×2 SparseMatrixCSC{ComplexF64, Int64} with 2 stored entries:
     ⋅      1.0+0.0im
 1.0+0.0im      ⋅    
)

which the comma , will be in the beginning of the line.

So I think it would be better to add it before.

Also, this separates the output of the first two lines of Vector{Qobj}, namely

julia> [a, a', a + a']
3-element Vector{QuantumObject{MT, OperatorQuantumObject, 1} where MT<:AbstractArray}:
 
Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
...

@albertomercurio
Copy link
Member

Ok, you just did the opposite, i.e. suing a line break in the beginning, right?

@ytdHuang
Copy link
Member Author

ytdHuang commented Jan 7, 2025

Ok, you just did the opposite, i.e. suing a line break in the beginning, right?

Yes, that's all I did.
The rest of the changes are for the doctests.

@albertomercurio albertomercurio merged commit 5b08c04 into qutip:main Jan 7, 2025
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip ChangeLog Skip changelog update check in PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants