Skip to content

Document fields of TreeSet#296

Merged
amontoison merged 5 commits intoJuliaDiff:mainfrom
blegat:treeset_doc
Jan 29, 2026
Merged

Document fields of TreeSet#296
amontoison merged 5 commits intoJuliaDiff:mainfrom
blegat:treeset_doc

Conversation

@blegat
Copy link
Contributor

@blegat blegat commented Jan 9, 2026

I needed to understand these from the implementation for the purpose of blegat/ArrayDiff.jl#19 so I thought I might as well document them now that I understand what they represent :)

@gdalle
Copy link
Member

gdalle commented Jan 9, 2026

Note that these are internal structs which were never meant for outside consumption. If you need them to be public, can you give some more detail as to why?

@gdalle
Copy link
Member

gdalle commented Jan 9, 2026

To clarify, more documentation, even for private objects, is always a good thing. I just wanna know if we can also make the public-facing API sufficient for your uses.

@blegat
Copy link
Contributor Author

blegat commented Jan 9, 2026

In JuMP, we compute the sparsity pattern of the Hessian of the objective I0, J0 and of each constraint Ik, Jk.
We then give the solver the concatenation vcat(I0, I1, ..., Im) and vcat(J0, J1, ..., Jm).
The, the solver give use a vector V which has the same length as the concatenation of the indices and we just need to fill it.
It seems the interface of SMC requires that we give a SparseMatrixCSC for the decompression:
https://github.com/gdalle/SparseMatrixColorings.jl/blob/31999f1409f5398ccd6224fb76f8dccdfe2d50c6/src/decompression.jl#L589
Instead, I would like for the objective and each constraint to just take a view of the corresponding part of V, and give it to SMC.
We can probably split this decompress! in two, one part that takes the nonzeros out of the SparseMatrixCSC and then redirects to another decompress! that just takes an AbstractVector of nonzeros and we we could use that second one from ArrayDiff

@gdalle
Copy link
Member

gdalle commented Jan 9, 2026

Yeah that sounds feasible, but I'm more worried about the view part. Why do you need a view of V, and what kind of view?

@amontoison
Copy link
Collaborator

It needs a continuous view because JuMP is doing a coloring for the Hessian of the objective and then for the Hessian of each constraints.
They are not doing like ADNLPModels where we do directly a coloring of the Hessian of the Lagrangian.
After the computation of the nonzeros of each compressed Hessian, they need to do the decompression in the related part of the vector V to recover the sparse Hessian.

@blegat I am right?

src/coloring.jl Outdated
"""
contains the reverse breadth first (BFS) traversal order for each tree in the forest.
More precisely, given an edge `(u, v)` of index `i`,
`reverse_bfs_order[i]` is either `(u, v)` or `(v, u)`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not right, i is not an edge index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now

# Number of edges treated
num_edges_treated = zero(T)

# reverse_bfs_orders contains the reverse breadth first (BFS) traversal order for each tree in the forest
Copy link
Collaborator

@amontoison amontoison Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep this comment.
What do think of:

# reverse_bfs_orders will contain the reverse breadth first (BFS) traversal order for each tree in the forest concatenated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simply moved it into the comment of the field of the struct. I feel that the definition of what reverse_bfs_orders will be should go there and here we should comment on why what we do achieve this

Copy link
Contributor Author

@blegat blegat Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new comment clarifying the confusion with the root of the Forest union-find datastructure that we thought we be useful during our discussion on the phone

src/coloring.jl Outdated
is_star::Vector{Bool}
"`tree_edge_indices[1]` is one and `tree_edge_indices[k+1] - tree_edge_indices[k]` is the number of edges in the `k`th tree"
tree_edge_indices::Vector{T}
"numbers of 2-colored trees for which trees sharing the same 2 colors have disjoint vertices"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think they have disjoint vertices. When the matrix is dense, we have n(n+1)/2 trees with two vertices (one for each edge) but only n vertices.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a red vertex u is adjacent to both a blue and yellow vertex then the red-blue tree and red-yellow tree have the u vertex in common so they don't have disjoint vertices

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahah, I contradicted myself in my reply. I meant disjoint edges indeed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it in the last commit

@amontoison amontoison added the documentation Improvements or additions to documentation label Jan 9, 2026
Co-authored-by: Alexis Montoison <35051714+amontoison@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Jan 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (31999f1) to head (20ab117).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #296    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           20        20            
  Lines         2027      2139   +112     
==========================================
+ Hits          2027      2139   +112     

☔ 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.

@amontoison amontoison merged commit 921c7a0 into JuliaDiff:main Jan 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants