Skip to content
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

SparseMatrixCSC type conversion (sometimes) drops structural nonzeros #454

Open
sjdaines opened this issue Oct 11, 2023 · 0 comments
Open

Comments

@sjdaines
Copy link
Contributor

sjdaines commented Oct 11, 2023

Update: another surprising consequence of #190 that led to hours of debugging...

SparseMatrixCSC Float64.(A) drops structural nonzeros, but float(A) doesn't:

julia> A = SparseArrays.sparse([1 2 0; 0 0 3; 0 4 0])
julia> A[1, 1] = 0
julia> A
3×3 SparseArrays.SparseMatrixCSC{Int64, Int64} with 4 stored entries:
 0  2  ⋅
 ⋅  ⋅  3
 ⋅  4  ⋅

julia> Float64.(A)  # drops structural nonzeros !!
3×3 SparseArrays.SparseMatrixCSC{Float64, Int64} with 3 stored entries:
  ⋅   2.0   ⋅ 
  ⋅    ⋅   3.0
  ⋅   4.0   ⋅

julia> float(A) # OK ?!
3×3 SparseArrays.SparseMatrixCSC{Float64, Int64} with 4 stored entries:
 0.0  2.0   ⋅
  ⋅    ⋅   3.0
  ⋅   4.0   ⋅
sjdaines added a commit to PALEOtoolkit/PALEOmodel.jl that referenced this issue Oct 11, 2023
This also reveals a Julia issue (JuliaSparse/SparseArrays.jl#454),
where
    MultiFloats.Float64x2.(A)
doesn't preserve structural nonzeros
sjdaines added a commit to PALEOtoolkit/PALEOmodel.jl that referenced this issue Oct 12, 2023
* Add SteadyState.RestartSmallValuesCallback

Provides a callback function with signature

    rsvc(state, tmodel, deltat, model, modeldata)

that modifies `state` to reset variables with values < `modify_threshold`
to value `modify_val`, hence restarting the Newton solve from
`modify_val` on the next iteration.

* Add CheckValuesCallback

Provides a callback function with signature

    cvc(state, tmodel, deltat, model, modeldata)::Bool

that checks variables have `check_min_threshold` < values < `check_max_threshold`.

* Generalize CheckValuesCallback for use with NLsolve

* Add SolverFunctions.StepClampMultAll! callback

Requires https://github.com/PALEOtoolkit/NLsolve.jl newton_robustness branch,
with new option to NLsolve:
- apply_step! =  SolverFunctions.StepClampMultAll!(...)

* Add sparse linear solvers adapted to NLsolve interface

SolverFunctions.SparseLinsolveUMFPACK
SolverFunctions.SparseLinsolveSparspak64x2

* SparseLinsolveSparspak64x2 reuse symbolic factorization

This also reveals a Julia issue (JuliaSparse/SparseArrays.jl#454),
where
    MultiFloats.Float64x2.(A)
doesn't preserve structural nonzeros

* documentation fixes

* doc fix

* doc update
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

No branches or pull requests

1 participant