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

fix InexactError on conversion for HiGHS solver #26

Merged
merged 1 commit into from
Apr 21, 2023

Conversation

thchr
Copy link
Contributor

@thchr thchr commented Aug 30, 2022

I was trying out the HiGHS solver as an alternative to Cbc via

solver_positions(..., Zarate(ordering_solver=optimizer_with_attributes(HiGHS.Optimizer)))

For certain problems, this threw the following error:

ERROR: InexactError: Bool(-2.220446049250313e-16)
Stacktrace:
  [1] Bool(x::Float64)
    @ Base .\float.jl:158
  [2] (::LayeredLayouts.var"#is_before_func#44"{Vector{Any}})(n1::Int64, n2::Int64)
    @ LayeredLayouts C:\Users\tchr\.julia\dev\LayeredLayouts\src\zarate.jl:202
  [3] #1
    @ .\ordering.jl:133 [inlined]
  [4] lt
    @ .\ordering.jl:120 [inlined]
  [5] sort!(v::Vector{Int64}, lo::Int64, hi::Int64, #unused#::Base.Sort.InsertionSortAlg, o::Base.Order.Lt{Base.Order.var"#1#3"{LayeredLayouts.var"#is_before_func#44"{Vector{Any}}, typeof(identity)}})
    @ Base.Sort .\sort.jl:504
  [6] sort!(v::Vector{Int64}, lo::Int64, hi::Int64, a::Base.Sort.QuickSortAlg, o::Base.Order.Lt{Base.Order.var"#1#3"{LayeredLayouts.var"#is_before_func#44"{Vector{Any}}, typeof(identity)}})
    @ Base.Sort .\sort.jl:570
  [7] sort!
    @ .\sort.jl:660 [inlined]
  [8] #sort!#8
    @ .\sort.jl:721 [inlined]
  [9] order_layers!
    @ C:\Users\tchr\.julia\dev\LayeredLayouts\src\zarate.jl:204 [inlined]
 [10] solve_positions(layout::Zarate, original_graph::Graphs.SimpleGraphs.SimpleDiGraph{Int64}; force_layer::Vector{Pair{Int64, Int64}}, force_order::Vector{Pair{Int64, Int64}})
    @ LayeredLayouts C:\Users\tchr\.julia\dev\LayeredLayouts\src\zarate.jl:93
[...]

I imagine that the assumption that value(isbefore[n1][n2]) is an integer is not necessarily true for all solvers. This is a suggested fix for those cases.

@oxinabox
Copy link
Owner

thanks

@thchr
Copy link
Contributor Author

thchr commented Sep 20, 2022

Bump :)

@thchr
Copy link
Contributor Author

thchr commented Mar 21, 2023

Also a gentle bump on this: would be nice to be able to experiment with other solvers.

@oxinabox
Copy link
Owner

Oh, I totally forgot about this PR.
And recreated it in #34.
This closes #33

@oxinabox oxinabox merged commit 0ece91d into oxinabox:main Apr 21, 2023
@mtfishman
Copy link

mtfishman commented Jun 21, 2023

Unfortunately round(::Type{Bool}, ::Float64) isn't available in Julia 1.7 and below:

julia> round(Bool, 0.9)
ERROR: MethodError: no method matching trunc(::Type{Bool}, ::Float64)
Closest candidates are:
  trunc(::Type{Signed}, ::Float64) at /Applications/Julia-1.7.3.app/Contents/Resources/julia/share/julia/base/float.jl:358
  trunc(::Type{T}, ::Missing) where T at /Applications/Julia-1.7.3.app/Contents/Resources/julia/share/julia/base/missing.jl:154
  trunc(::Type{T}, ::Rational) where T at /Applications/Julia-1.7.3.app/Contents/Resources/julia/share/julia/base/rational.jl:455
  ...
Stacktrace:
 [1] round(#unused#::Type{Bool}, x::Float64)
   @ Base ./float.jl:369
 [2] top-level scope
   @ REPL[2]:1

julia> versioninfo()
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin21.4.0)
  CPU: Apple M1 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, westmere)

@mtfishman
Copy link

mtfishman commented Jun 21, 2023

Also it's not supported in Compat.jl but I made an issue for that: JuliaLang/Compat.jl#798.

@thchr
Copy link
Contributor Author

thchr commented Jun 21, 2023

I guess it could be conditionally added to LayeredLayouts by copying over its definition from Base:

if VERSION < v"1.8"
   round(::Type{Bool}, x::AbstractFloat) = (-0.5 <= x < 1.5) ? 0.5 < x : throw(InexactError(:round, Bool, x))
end

Alternatively, we could change round(Bool, value(is_before[n1][n2]))::Bool to convert(Bool, round(value(is_before[n1][n2])))::Bool.

@oxinabox
Copy link
Owner

@mtfishman please open new errors rather than commenting on PRs merged months ago.

oxinabox added a commit that referenced this pull request Jun 21, 2023
Fixes to work on pre-julia 1.7

As pointed out by  @mtfishman

in #26 (comment)
@mtfishman
Copy link

Sorry @oxinabox! It annoys me when people do that as well... Just wanted to comment before I forgot, I was planning on raising an issue/making a PR.

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