Skip to content

improve display #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 11, 2025
Merged

improve display #40

merged 6 commits into from
Jun 11, 2025

Conversation

ogauthe
Copy link
Contributor

@ogauthe ogauthe commented Jun 10, 2025

This PR improves display for sectors U1, O2, SU2 and SU{N}. The objective is that the output of println(s::AbstractSector) can be directly copy pasted into RHEL to produce the same sector.

Copy link

codecov bot commented Jun 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.32%. Comparing base (8bb44b6) to head (f2256e8).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #40   +/-   ##
=======================================
  Coverage   94.32%   94.32%           
=======================================
  Files          20       20           
  Lines         775      776    +1     
=======================================
+ Hits          731      732    +1     
  Misses         44       44           
Flag Coverage Δ
docs 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mtfishman
Copy link
Member

Looks good, can you add a few tests? sprint is helpful for that, for example:

julia> sprint(show, [1, 2, 3]) == "[1, 2, 3]"
true

julia> sprint(show, MIME("text/plain"), [1, 2, 3]) == "3-element Vector{Int64}:\n 1\n 2\n 3"
true

@mtfishman mtfishman merged commit d42b2b5 into ITensor:main Jun 11, 2025
17 checks passed
@ogauthe ogauthe deleted the display branch June 11, 2025 18:08
@lkdvos
Copy link
Contributor

lkdvos commented Jun 11, 2025

I know this is already merged, but as a minor comment for possible improvements: if you print typeof(sector) instead of manually printing SU or U1 etc, julia actually has special handling to determine whether or not you have these types in your namespace. This can be helpful for the 2-arg case, since you are then more guaranteed to have a copy-pastable result:

module NotInNameSpace
    using GradedArrays: GradedArrays
    println(typeof(GradedArrays.O2(1))) # GradedArrays.O2
end

using GradedArrays: O2
println(typeof(O2(1))) # O2

@mtfishman
Copy link
Member

Good point, that sounds helpful to add. Base.summary could be helpful for that.

@ogauthe
Copy link
Contributor Author

ogauthe commented Jun 11, 2025

Here I do not display the full type to get an easier to read, less verbose output and hide implementation details:

julia> gradedrange([U1(1)× O2(1)×SU2(1//2)×SU{3}((1,0))=>1])
GradedArrays.GradedUnitRange{Int64, GradedArrays.SectorUnitRange{Int64, GradedArrays.SectorProduct{Tuple{U1{Int64}, O2, SU{2, 1}, SU{3, 2}}}, Base.OneTo{Int64}}, BlockedOneTo{Int64, Vector{Int64}}, Vector{Int64}}
SectorUnitRange (U1(1) × O2(1) × SU2(1/2) × SU{3}((1, 0))) => 1:12

julia> println(gradedrange([U1(1)× O2(1)×SU2(1//2)×SU{3}((1,0))=>1]))
GradedUnitRange[(U1(1) × O2(1) × SU2(1/2) × SU{3}((1, 0))) => 12]

Using typeof(sector) (or just removing Base.show specialization), one gets

julia> gradedrange([U1(1)× O2(1)×SU2(1//2)×SU{3}((1,0))=>1])
GradedArrays.GradedUnitRange{Int64, GradedArrays.SectorUnitRange{Int64, GradedArrays.SectorProduct{Tuple{U1{Int64}, O2, SU{2, 1}, SU{3, 2}}}, Base.OneTo{Int64}}, BlockedOneTo{Int64, Vector{Int64}}, Vector{Int64}}
SectorUnitRange (U1{Int64}(1) × O2(1) × SU{2, 1}((1,)) × SU{3, 2}((1, 0))) => 1:12

julia> println(gradedrange([U1(1)× O2(1)×SU2(1//2)×SU{3}((1,0))=>1]))
GradedUnitRange[(U1{Int64}(1) × O2(1) × SU{2, 1}((1,)) × SU{3, 2}((1, 0))) => 12]

Indeed to copy paste in RHEL I need to import the names. I have a weak preference for the current choice as I find it easier to read and parse.

@lkdvos
Copy link
Contributor

lkdvos commented Jun 11, 2025

I was definitely proposing this only for the 2-arg version, I agree that for 3-arg you want human-readable. I'm okay with either, just wanted to mention this.

@mtfishman
Copy link
Member

I think you could customize Base.summary to customize how the type names are printed to make them more compact like in this PR, and still keep the behavior Lukas suggested of having Julia prepend the module name if needed depending on the namespace. I also agree we should customize things depending on the context using 2-arg vs. 3-arg show.

But anyway, I don't think we need to do this right now, I think the printing change in this PR is good and we can keep in mind fancier things for the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants