JuliaLinearAlgebra / AlgebraicMultigrid.jl

Algebraic Multigrid in Julia
Other
116 stars 23 forks source link

Avoid printing numerical values of Coarse Solver when summarizing MultiLevel solver #85

Closed learning-chip closed 2 years ago

learning-chip commented 2 years ago

The "Coarse Solver" entry (printed to console when inspecting a MultiLevel solver) contains numerical values for pinv. This takes a lot of space and is hard to read (particularly in a Jupyter notebook).

The default example:

using AlgebraicMultigrid
A = poisson(1000)
ml = ruge_stuben(A)

shows:

Multilevel Solver
-----------------
Operator Complexity: 1.986
Grid Complexity: 1.986
No. of Levels: 8
Coarse Solver: AlgebraicMultigrid.Pinv{Float64}([93.98601398601403 80.55944055944069 67.1328671328673 53.7062937062939 40.279720279720436 26.853146853146935 13.42657342657344; 80.55944055944065 178.76523476523496 148.97102897102926 119.17682317682355 89.38261738261767 59.58841158841175 29.79420579420582; 67.13286713286729 148.9710289710293 230.80919080919125 184.64735264735313 138.48551448551484 92.32367632367648 46.1618381618382; 53.70629370629386 119.17682317682356 184.64735264735316 250.11788211788266 187.588411588412 125.0589410589412 62.529470529470565; 40.279720279720436 89.38261738261772 138.48551448551498 187.58841158841216 236.69130869130905 157.7942057942059 78.89710289710294; 26.853146853147013 59.58841158841189 92.32367632367674 125.05894105894147 157.79420579420605 190.5294705294706 95.2647352647353; 13.426573426573487 29.794205794205915 46.16183816183832 62.52947052947072 78.89710289710304 95.26473526473532 111.63236763236768])
Level     Unknowns     NonZeros
-----     --------     --------
    1         1000         2998 [50.35%]
    2          500         1498 [25.16%]
    3          250          748 [12.56%]
    4          125          373 [ 6.26%]
    5           62          184 [ 3.09%]
    6           31           91 [ 1.53%]
    7           15           43 [ 0.72%]
    8            7           19 [ 0.32%]

Related source code: https://github.com/JuliaLinearAlgebra/AlgebraicMultigrid.jl/blob/b40945a7c5c724f65b92b1a2611ca264df483101/src/multilevel.jl#L66-L68 https://github.com/JuliaLinearAlgebra/AlgebraicMultigrid.jl/blob/b40945a7c5c724f65b92b1a2611ca264df483101/src/multilevel.jl#L86-L96

One quick fix is to print typeof(ml.coarse_solver), instead of ml.coarse_solver, so that the summary is easier to read:

Multilevel Solver
-----------------
Operator Complexity: 1.986
Grid Complexity: 1.986
No. of Levels: 8
Coarse Solver: AlgebraicMultigrid.Pinv{Float64}
Level     Unknowns     NonZeros
-----     --------     --------
    1         1000         2998 [50.35%]
    2          500         1498 [25.16%]
    3          250          748 [12.56%]
    4          125          373 [ 6.26%]
    5           62          184 [ 3.09%]
    6           31           91 [ 1.53%]
    7           15           43 [ 0.72%]
    8            7           19 [ 0.32%]

This is also consistent with PyAMG which prints Coarse Solver: 'pinv2' without numerical values.

Package version

AlgebraicMultigrid@0.4.2

learning-chip commented 2 years ago

An even worse situation is when one creates a two-grid (not multi-grid) solver:

using AlgebraicMultigrid
A = poisson(1000)
ruge_stuben(A, max_levels=2)

In this case the coarsest A is fairly big, and millions of entries in Pinv are dumped to the screen, often killing the session

ranjanan commented 2 years ago

Fixed by https://github.com/JuliaLinearAlgebra/AlgebraicMultigrid.jl/commit/199b21fc65c1efc9a881f04e3396f455bc6aec7f