Skip to content

Fix the inference of the function coloring for static compilation - #340

Open
amontoison wants to merge 1 commit into
mainfrom
c_interface
Open

Fix the inference of the function coloring for static compilation#340
amontoison wants to merge 1 commit into
mainfrom
c_interface

Conversation

@amontoison

@amontoison amontoison commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

@gdalle I will open a follow-up PR with C and Fortran interfaces but we first need to fix the inference of the function coloring.

@amontoison
amontoison requested a review from gdalle September 5, 2026 04:16
@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.61%. Comparing base (e8d80d6) to head (8625abb).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #340      +/-   ##
==========================================
- Coverage   99.20%   97.61%   -1.60%     
==========================================
  Files          21       21              
  Lines        2151     2219      +68     
==========================================
+ Hits         2134     2166      +32     
- Misses         17       53      +36     

☔ View full report in Codecov by Harness.
📢 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.

Comment thread test/static_compilation.jl
Comment thread src/interface.jl
problem::ColoringProblem,
algo::GreedyColoringAlgorithm;
decompression_eltype::Type{R}=Float64,
decompression_eltype::Type=Float64,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The rationale behind the type annotation was to force specialization: https://docs.julialang.org/en/v1/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing

Not sure how this change makes anything better in that regard, I would have thought it makes things worse?

@amontoison amontoison Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Me too and it is the contrary that is happening, the compiler widen the type to DataType internally from what I unserstand if we keep Type{R} and we don't have the inference in 3 cases.

I am wondering if it is because the argument with the specialization is a keyword argument.

@amontoison
amontoison requested a review from gdalle September 9, 2026 04:05
@@ -0,0 +1,47 @@
# Guard for static compilation (`juliac --trim=safe`).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was wondering why our existing type stability tests didn't catch this: it's because we didn't pass the decompression_eltype. I think it would be better to add that kwarg to the existing test block here?

@test_opt coloring(
A,
ColoringProblem(; structure, partition),
GreedyColoringAlgorithm(order; decompression),
)
@test_opt coloring(
A,
ColoringProblem(; structure, partition),
GreedyColoringAlgorithm((NaturalOrder(), order); decompression),
)
@inferred coloring(
A,
ColoringProblem(; structure, partition),
GreedyColoringAlgorithm(order; decompression),
)
@inferred coloring(
A,
ColoringProblem(; structure, partition),
GreedyColoringAlgorithm((NaturalOrder(), order); decompression),
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch Guillaume!
We don't have the stability tests (from JET) in Julia 1.12 but I tested on main + Julia 1.10 + decompression_eltype:

Test Summary:                                                                 |  Pass  Fail  Error  Broken  Total      Time
SparseMatrixColorings                                                         | 64392    66     33      31  64522  12m01.6s
  Code quality                                                                |    13                          13   2m48.7s
    Aqua                                                                      |    11                          11   2m23.4s
    JET                                                                       |     1                           1     19.1s
    Doctests                                                                  |     1                           1      6.2s
  Internals                                                                   |  9269                   24   9293   1m10.2s
    Graph                                                                     |  8068                        8068      5.2s
    Forest                                                                    |    20                          20      0.5s
    Order                                                                     |   526                         526     19.7s
    Check                                                                     |    70                          70      7.1s
    Matrices                                                                  |    20                          20      1.6s
    Constructors                                                              |     7                           7      0.0s
    Result                                                                    |   483                         483      0.9s
    Constant coloring                                                         |    18                          18      0.4s
    Optimal coloring                                                          |     1                   24     25     23.0s
    ADTypes coloring algorithms                                               |    10                          10      3.5s
    Visualization                                                             |    46                          46      8.1s
  Correctness                                                                 | 54200                    5  54205   4m39.2s
    Small instances                                                           |  3008                        3008   1m26.0s
    Random instances                                                          | 47256                       47256   1m32.8s
    Structured matrices                                                       |  3627                        3627     24.4s
    Instances with known colorings                                            |    12                          12      1.1s
    SuiteSparse                                                               |   297                    5    302   1m14.8s
  Performance                                                                 |   910    66     33       2   1011   3m21.2s
    Type stability                                                            |   855    66     33            954   2m52.9s
      Sparse coloring                                                         |    69    66     33            168     49.5s
        ADTypes                                                               |     3                           3      6.2s
        nonsymmetric - column - direct                                        |    22                          22      4.8s
        nonsymmetric - row - direct                                           |    22                          22      2.9s
        symmetric - column - direct                                           |    22                          22      3.1s
        symmetric - column - substitution                                     |          22     11             33     17.5s
          order = NaturalOrder()                                              |           2      1              3     12.6s
          order = RandomOrder{TaskLocalRNG, Nothing}(TaskLocalRNG(), nothing) |           2      1              3      0.6s
          order = LargestFirst()                                              |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:back, :high2low, false}()          |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:back, :high2low, true}()           |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:back, :low2high, false}()          |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:back, :low2high, true}()           |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:forward, :low2high, false}()       |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:forward, :low2high, true}()        |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:forward, :high2low, false}()       |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:forward, :high2low, true}()        |           2      1              3      0.5s
        nonsymmetric - bidirectional - direct                                 |          22     11             33      7.4s
          order = NaturalOrder()                                              |           2      1              3      0.6s
          order = RandomOrder{TaskLocalRNG, Nothing}(TaskLocalRNG(), nothing) |           2      1              3      0.6s
          order = LargestFirst()                                              |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:back, :high2low, false}()          |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:back, :high2low, true}()           |           2      1              3      0.8s
          order = DynamicDegreeBasedOrder{:back, :low2high, false}()          |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:back, :low2high, true}()           |           2      1              3      0.8s
          order = DynamicDegreeBasedOrder{:forward, :low2high, false}()       |           2      1              3      0.5s
          order = DynamicDegreeBasedOrder{:forward, :low2high, true}()        |           2      1              3      0.7s
          order = DynamicDegreeBasedOrder{:forward, :high2low, false}()       |           2      1              3      0.8s
          order = DynamicDegreeBasedOrder{:forward, :high2low, true}()        |           2      1              3      0.8s
        nonsymmetric - bidirectional - substitution                           |          22     11             33      7.6s
          order = NaturalOrder()                                              |           2      1              3      0.7s
          order = RandomOrder{TaskLocalRNG, Nothing}(TaskLocalRNG(), nothing) |           2      1              3      0.7s
          order = LargestFirst()                                              |           2      1              3      0.7s
          order = DynamicDegreeBasedOrder{:back, :high2low, false}()          |           2      1              3      0.7s
          order = DynamicDegreeBasedOrder{:back, :high2low, true}()           |           2      1              3      0.7s
          order = DynamicDegreeBasedOrder{:back, :low2high, false}()          |           2      1              3      0.6s
          order = DynamicDegreeBasedOrder{:back, :low2high, true}()           |           2      1              3      0.7s
          order = DynamicDegreeBasedOrder{:forward, :low2high, false}()       |           2      1              3      0.6s
          order = DynamicDegreeBasedOrder{:forward, :low2high, true}()        |           2      1              3      0.7s
          order = DynamicDegreeBasedOrder{:forward, :high2low, false}()       |           2      1              3      0.8s
          order = DynamicDegreeBasedOrder{:forward, :high2low, true}()        |           2      1              3      0.7s
      Structured coloring                                                     |     8                           8      0.7s
      Sparse decompression                                                    |   528                         528     50.2s
      Structured decompression                                                |     8                           8      3.4s
      Single precision                                                        |   242                         242     59.8s
    Allocations                                                               |    55                    2     57     28.3s
ERROR: LoadError: Some tests did not pass: 64392 passed, 66 failed, 33 errored, 31 broken.
in expression starting at /home/amontois/SparseMatrixColorings.jl/test/runtests.jl:10
ERROR: Package SparseMatrixColorings errored during testing

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.

2 participants