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

MOI failure on nightly #260

Closed
odow opened this issue Feb 14, 2024 · 4 comments · Fixed by #261
Closed

MOI failure on nightly #260

odow opened this issue Feb 14, 2024 · 4 comments · Fixed by #261

Comments

@odow
Copy link
Member

odow commented Feb 14, 2024

When 2 * f is not f *2...

julia> import MathOptInterface as MOI

julia> import LinearAlgebra

julia> x = MOI.VariableIndex(1)
MOI.VariableIndex(1)

julia> f = LinearAlgebra.Symmetric([2*x*x 0; 0 0])
2×2 LinearAlgebra.Symmetric{MathOptInterface.ScalarQuadraticFunction{Int64}, Matrix{MathOptInterface.ScalarQuadraticFunction{Int64}}}:
 (0) + 2.0 MOI.VariableIndex(1)²  (0)
 (0)                              (0)

julia> MutableArithmetics.add_mul(f, 2, 2 * f)
2×2 LinearAlgebra.Symmetric{MathOptInterface.ScalarQuadraticFunction{Int64}, Matrix{MathOptInterface.ScalarQuadraticFunction{Int64}}}:
 (0) + 8.0 MOI.VariableIndex(1+ 2.0 MOI.VariableIndex(1)²  (0)
 (0)                                                          (0)

julia> MutableArithmetics.add_mul(f, 2, f * 2)
ERROR: UndefRefError: access to undefined reference
Stacktrace:
  [1] getindex
    @ ./essentials.jl:892 [inlined]
  [2] getindex
    @ ./array.jl:915 [inlined]
  [3] getindex
    @ ./multidimensional.jl:700 [inlined]
  [4] _broadcast_getindex
    @ ./broadcast.jl:639 [inlined]
  [5] _getindex
    @ ./broadcast.jl:670 [inlined]
  [6] _getindex
    @ ./broadcast.jl:669 [inlined]
  [7] _broadcast_getindex
    @ ./broadcast.jl:645 [inlined]
  [8] getindex
    @ ./broadcast.jl:605 [inlined]
  [9] macro expansion
    @ ./broadcast.jl:968 [inlined]
 [10] macro expansion
    @ ./simdloop.jl:77 [inlined]
 [11] copyto!
    @ ./broadcast.jl:967 [inlined]
 [12] copyto!
    @ ./broadcast.jl:920 [inlined]
 [13] copy
    @ ./broadcast.jl:892 [inlined]
 [14] materialize
    @ ./broadcast.jl:867 [inlined]
 [15] broadcast_preserving_zero_d
    @ ./broadcast.jl:856 [inlined]
 [16] *(A::Int64, B::Matrix{MathOptInterface.ScalarQuadraticFunction{Int64}})
    @ Base ./arraymath.jl:21
 [17] *
    @ ~/.julia/packages/MutableArithmetics/NIXlP/src/dispatch.jl:478 [inlined]
 [18] muladd(x::Int64, y::LinearAlgebra.Symmetric{MathOptInterface.ScalarQuadraticFunction{…}, Matrix{…}}, z::LinearAlgebra.Symmetric{MathOptInterface.ScalarQuadraticFunction{…}, Matrix{…}})
    @ Base.Math ./math.jl:1562
 [19] add_mul(a::LinearAlgebra.Symmetric{MathOptInterface.ScalarQuadraticFunction{…}, Matrix{…}}, b::Int64, c::LinearAlgebra.Symmetric{MathOptInterface.ScalarQuadraticFunction{…}, Matrix{…}})
    @ MutableArithmetics ~/.julia/packages/MutableArithmetics/NIXlP/src/MutableArithmetics.jl:27
 [20] top-level scope
    @ REPL[94]:1
Some type information was truncated. Use `show(err)` to see complete types.
@odow
Copy link
Member Author

odow commented Feb 14, 2024

julia> x = MOI.VariableIndex(1)
MOI.VariableIndex(1)

julia> f = LinearAlgebra.Symmetric([2*x*x 0; 0 0])
2×2 LinearAlgebra.Symmetric{MathOptInterface.ScalarQuadraticFunction{Int64}, Matrix{MathOptInterface.ScalarQuadraticFunction{Int64}}}:
 (0) + 2.0 MOI.VariableIndex(1)²  (0)
 (0)                              (0)

julia> 2 * (f * 2)
ERROR: UndefRefError: access to undefined reference
Stacktrace:
  [1] getindex
    @ ./essentials.jl:892 [inlined]
  [2] getindex
    @ ./array.jl:915 [inlined]
  [3] getindex
    @ ./multidimensional.jl:700 [inlined]
  [4] _broadcast_getindex
    @ ./broadcast.jl:639 [inlined]
  [5] _getindex
    @ ./broadcast.jl:670 [inlined]
  [6] _getindex
    @ ./broadcast.jl:669 [inlined]
  [7] _broadcast_getindex
    @ ./broadcast.jl:645 [inlined]
  [8] getindex
    @ ./broadcast.jl:605 [inlined]
  [9] macro expansion
    @ ./broadcast.jl:968 [inlined]
 [10] macro expansion
    @ ./simdloop.jl:77 [inlined]
 [11] copyto!
    @ ./broadcast.jl:967 [inlined]
 [12] copyto!
    @ ./broadcast.jl:920 [inlined]
 [13] copy
    @ ./broadcast.jl:892 [inlined]
 [14] materialize
    @ ./broadcast.jl:867 [inlined]
 [15] broadcast_preserving_zero_d
    @ ./broadcast.jl:856 [inlined]
 [16] *(A::Int64, B::Matrix{MathOptInterface.ScalarQuadraticFunction{Int64}})
    @ Base ./arraymath.jl:21
 [17] *::Int64, A::LinearAlgebra.Symmetric{MathOptInterface.ScalarQuadraticFunction{Int64}, Matrix{MathOptInterface.ScalarQuadraticFunction{Int64}}})
    @ MutableArithmetics ~/.julia/packages/MutableArithmetics/NIXlP/src/dispatch.jl:478
 [18] top-level scope
    @ REPL[102]:1

@odow
Copy link
Member Author

odow commented Feb 14, 2024

julia> (2 * f).data
2×2 Matrix{MathOptInterface.ScalarQuadraticFunction{Int64}}:
 (0) + 4.0 MOI.VariableIndex(1)²  (0)
 (0)                              (0)

julia> (f * 2).data
2×2 Matrix{MathOptInterface.ScalarQuadraticFunction{Int64}}:
    (0) + 4.0 MOI.VariableIndex(1)²  (0)
 #undef                              (0)

@odow
Copy link
Member Author

odow commented Feb 14, 2024

On Julia 1.10

julia> (f * 2).data
2×2 Matrix{MathOptInterface.ScalarQuadraticFunction{Int64}}:
 (0) + 4.0 MOI.VariableIndex(1)²  (0)
 (0)                              (0)

julia> (2 * f).data
2×2 Matrix{MathOptInterface.ScalarQuadraticFunction{Int64}}:
 (0) + 4.0 MOI.VariableIndex(1)²  (0)
 (0)                              (0)

@odow
Copy link
Member Author

odow commented Feb 14, 2024

Looks like the cause was JuliaLang/julia#52942, which added an optimization to only modify the relevant upper or lower triangle. That's probably fair.

We need to update:

# Needed for Julia v1.0, otherwise, `broadcast(*, α, A)` gives a `Array` and
# not a `Symmetric`.
function Base.:*::Number, A::LinearAlgebra.Symmetric{<:AbstractMutable})
return LinearAlgebra.Symmetric(
α * parent(A),
LinearAlgebra.sym_uplo(A.uplo),
)
end
function Base.:*::Number, A::LinearAlgebra.Hermitian{<:AbstractMutable})
return LinearAlgebra.Hermitian(
α * parent(A),
LinearAlgebra.sym_uplo(A.uplo),
)
end
# Fix ambiguity identified by Aqua.jl.
function Base.:*::Real, A::LinearAlgebra.Hermitian{<:AbstractMutable})
return LinearAlgebra.Hermitian(
α * parent(A),
LinearAlgebra.sym_uplo(A.uplo),
)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant