Skip to content

[breaking] remove SingleVariable - #1559

Merged
odow merged 9 commits into
masterfrom
od/rm-SingleVariable
Sep 1, 2021
Merged

odow merged 9 commits into
masterfrom
od/rm-SingleVariable

Conversation

@odow

@odow odow commented Aug 26, 2021 •

Copy link
Copy Markdown
Member

I think I lost the battle on SingleVariable, so here goes. Tests are broken because there are lots of manual changes still needed, but overall, the script covered most changes.

Closes #1472
Closes #1474

TODOs

  • Formatting
  • Deprecations
  • Proof-read doc changes (@matbesancon)

Script

create_regex(regex) = regex => s -> match(regex, s)[1]

regexes = [
    # Some type renames
    # TODO(odow): deprecate these
    "SingleVariableConstraintNameError" => "VariableIndexConstraintNameError",
    "SettingSingleVariableFunctionNotAllowed" => "SettingVariableIndexFunctionNotAllowed",
    "_ParsedSingleVariable" => "_ParsedVariableIndex",
    # Single find-and-replace for variables inside SingleVariable
    create_regex(r"MOI\.SingleVariable\(([a-zA-Z\.\[\]0-9]+?)\)"),
    create_regex(r"MOI\.SingleVariable\.\(([a-zA-Z\.\[\]0-9]+?)\)"),
    create_regex(r"SingleVariable\(([a-zA-Z\.\[\]0-9]+?)\)"),
    create_regex(r"SingleVariable\.\(([a-zA-Z\.\[\]0-9]+?)\)"),
    # Some safe changes, where there are now variables involved
    ", SingleVariable," => ", VariableIndex,",
    "isa SingleVariable`" => "isa VariableIndex`",
    "= SingleVariable`" => "= VariableIndex`",
    " SingleVariable " => " VariableIndex ",
    "SingleVariable functions" => "VariableIndex functions",
    "SingleVariable-in-" => "VariableIndex-in-",
    " SingleVariable-" => " VariableIndex-",
    "\"SingleVariable\"" => "\"VariableIndex\"",
    "SingleVariable's" => "VariableIndex's",
    "`SingleVariable`" => "`VariableIndex`",
    "`MOI.SingleVariable`" => "`MOI.VariableIndex`",
    "`MathOptInterface.SingleVariable`" => "`MathOptInterface.VariableIndex`",
    "= MOI.SingleVariable\n" => "= MOI.VariableIndex\n",
    "isa MOI.SingleVariable" => "isa MOI.VariableIndex",
    ", MOI.SingleVariable)" => ", MOI.VariableIndex)",
    "(MOI.SingleVariable, " => "(MOI.VariableIndex, ",
    "(MathOptInterface.SingleVariable, " => "(MathOptInterface.VariableIndex, ",
    "{MOI.SingleVariable" => "{MOI.VariableIndex",
    "{MathOptInterface.SingleVariable" => "{MathOptInterface.VariableIndex",
    "{SingleVariable" => "{VariableIndex",
    "MOI.SingleVariable}" => "MOI.VariableIndex}",
    " MOI.SingleVariable " => " MOI.VariableIndex ",
    "(SingleVariable," => "(VariableIndex,",
    "_SingleVariable_" => "_VariableIndex_",
    "_SingleVariable(" => "_VariableIndex(",
    "_SingleVariable)" => "_VariableIndex)",
    ", MOI.SingleVariable, " => ", MOI.VariableIndex, ",
    ",MOI.SingleVariable," => ",MOI.VariableIndex,",
    ",MathOptInterface.SingleVariable," => ",MathOptInterface.VariableIndex,",
    " SingleVariable\n" => " VariableIndex\n",
    "    SingleVariable," => "    VariableIndex,",
    "    MOI.SingleVariable," => "    MOI.VariableIndex,",
    " MOI.SingleVariable\n" => " MOI.VariableIndex\n",
    " ::MOI.SingleVariable" => " ::MOI.VariableIndex",
    # Specific method changes
    "MOI.SingleVariable(MOI.VariableIndex(1))" => "MOI.VariableIndex(1)",
    "MOI.SingleVariable(MOI.VariableIndex(ci.value))" => "MOI.VariableIndex(ci.value)",
    "MOI.SingleVariable.(λ)" => "λ",
    ", ::MOI.SingleVariable) where {T} = zero(T)" => ", ::MOI.VariableIndex) where {T} = zero(T)",
    "(::MOI.SingleVariable) = false" => "(::MOI.VariableIndex) = false",
    "MOI.SingleVariable(xij[offset+j])" => "xij[offset+j]",
    "MOI.SingleVariable(xij[offset_next+2j-1])" => "xij[offset_next+2j-1]",
    "MOI.SingleVariable(xij[offset_next+2j])" => "xij[offset_next+2j]",
    "MOI.SingleVariable(index_map(f.variable))" => "index_map(f.variable)",
    "MOI.SingleVariable(it.f.variables[output_index])" => "it.f.variables[output_index]",
    ", ::MOI.SingleVariable)" => ", ::MOI.VariableIndex)",
    "MOI.SingleVariable(scalar_vars[var_idx])" => "scalar_vars[var_idx]",
    "MOI.SingleVariable(bridge.variables[n+i.value])" => "bridge.variables[n+i.value]",
    "variables(func::MOI.SingleVariable) = func.variable" => "variables(x::MOI.VariableIndex) = x",
    "MOI.SingleVariable(_variable(bridge, i))" => "_variable(bridge, i)",
    "MOI.SingleVariable(data.scalar_vars[_read(io, Int)+1])" => "data.scalar_vars[_read(io, Int)+1]",
    "MOI.SingleVariable(name_map[object[\"variable\"]::String])" => "name_map[object[\"variable\"]::String]",
    ":SingleVariable" => ":VariableIndex",
    "function Base.:-(α::Number, f::MOI.SingleVariable)" => "function Base.:-(α::Number, f::MOI.VariableIndex)",
    "function Base.:+(α::Number, f::MOI.SingleVariable)" => "function Base.:+(α::Number, f::MOI.VariableIndex)",
    "operate!(::typeof(/), ::Type{T}, f::MOI.SingleVariable, α::T)" => "operate!(::typeof(/), ::Type{T}, f::MOI.VariableIndex, α::T)",
    "operate!(::typeof(*), ::Type{T}, f::MOI.SingleVariable, α::T)" => "operate!(::typeof(*), ::Type{T}, f::MOI.VariableIndex, α::T)",
    "Base.:+(f::MOI.SingleVariable, α::Number)" => "Base.:+(f::MOI.VariableIndex, α::Number)",
    "Base.:-(f::MOI.SingleVariable, α::Number)" => "Base.:-(f::MOI.VariableIndex, α::Number)",
    # We don't need these definitions
    "_NLExpr(x::MOI.SingleVariable) = _NLExpr(x.variable)" => "",
    "function operate(::typeof(imag), ::Type{T}, f::MOI.SingleVariable) where {T}\n    return zero(MOI.ScalarAffineFunction{T})\nend" => "",
]
for (root, dirs, files) in walkdir(".")
    for file in files
        if !(endswith(file, ".jl") || endswith(file, ".md"))
            continue
        end
        filename = joinpath(root, file)
        file = read(filename, String)
        if !occursin("SingleVariable", file)
            continue
        end
        for (regex, f) in regexes
            file = replace(file, regex => f)
        end
        write(filename, file)
    end
end

@odow
odow force-pushed the od/rm-SingleVariable branch 2 times, most recently from 267b219 to d0c93b5 Compare August 26, 2021 08:06
@matbesancon

matbesancon commented Aug 26, 2021 •

Copy link
Copy Markdown
Contributor

@odow

odow commented Aug 26, 2021

Copy link
Copy Markdown
Member Author

The preview only works if the docs finish building, and if you have merge rights on the repository. In the case, the docs failed to build.

@odow odow added the breaking label Aug 27, 2021
@odow odow added this to the v0.10 milestone Aug 27, 2021
@matbesancon

Copy link
Copy Markdown
Contributor

interesting failure of the tests:
the way types are displayed includes a space, as in MyStruct{Param1, Param2} which is often not present in the current doctests. This causes them to fail when building the doc. The problem is that I'm not sure there will be a behavior passing on all Julia versions. Shouldn't this have been caught before whenever building the tests on 1.6?

image

@odow
odow force-pushed the od/rm-SingleVariable branch from 21e88f0 to d23ce31 Compare August 31, 2021 02:31
odow and others added 4 commits August 31, 2021 14:59
@odow
odow force-pushed the od/rm-SingleVariable branch from ef333ce to c2678ce Compare August 31, 2021 02:59
@odow

odow commented Aug 31, 2021

Copy link
Copy Markdown
Member Author

@odow odow changed the title [breaking] WIP: remove SingleVariable [breaking] remove SingleVariable Aug 31, 2021
@odow

odow commented Aug 31, 2021

Copy link
Copy Markdown
Member Author

Okay. CI is finally passing on this one.

@odow
odow requested a review from blegat August 31, 2021 03:40
## Types

```@docs
VariableIndex

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.

Why removing this ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's also in another place, I would have kept here too probably

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's in the Standard Form section. It's a toss-up where it should go. We have a problem that it's both an index and a function. We're confusing the abstraction.

Comment thread src/Bridges/Objective/slack.jl Resolved
Comment thread src/Bridges/Variable/free.jl Resolved
Comment thread src/Bridges/Variable/rsoc_to_psd.jl Resolved
Comment thread src/Bridges/Variable/set_map.jl Resolved
Comment thread src/Bridges/Variable/vectorize.jl Resolved
Comment thread src/DeprecatedTest/modellike.jl Resolved
Comment thread src/DeprecatedTest/modellike.jl Resolved
Comment thread src/DeprecatedTest/modellike.jl Resolved
Comment thread test/Utilities/variable_container.jl Resolved
Comment thread test/Utilities/variable_container.jl Resolved
Comment thread test/constraints.jl Resolved
Comment thread test/errors.jl Resolved
Comment thread test/errors.jl Resolved
Comment thread test/errors.jl Resolved
Comment thread test/errors.jl Resolved
Comment thread test/errors.jl Resolved
Comment thread test/errors.jl Resolved
Comment thread test/errors.jl Resolved
Comment thread test/errors.jl Resolved
Comment thread test/errors.jl Resolved
Comment thread test/functions.jl Resolved
Comment thread test/functions.jl Resolved
Comment thread test/functions.jl Resolved
@blegat

blegat commented Aug 31, 2021

Copy link
Copy Markdown
Member

Nice to see 700 lines go away! I looked over the changes and left comments.
Most of them are due to

fx = MOI.SingleVariable(x)
... fx ...

being transformed into

fx = x
... fx ...

while it should now be

... x ...

One could argue that it would better be done in another PR. Catching these was much easier by looking through the diff of this PR though which is why I proceeded this way.

This was referenced Aug 31, 2021
Comment thread NEWS.md Resolved
@odow

odow commented Aug 31, 2021

Copy link
Copy Markdown
Member Author

Nice to see 700 lines go away

This is a bit misleading. The code reduction is due to formatting fitting on a single line, not a reduction in code complexity.

@odow

odow commented Sep 1, 2021

Copy link
Copy Markdown
Member Author

Last chance for objections. I vote we merge this and fix any remaining tweaks in a separate PR. It's too hard to review this monster.

@odow
odow merged commit 1c5d82a into master Sep 1, 2021
@odow
odow deleted the od/rm-SingleVariable branch September 1, 2021 21:10
@odow

odow commented Sep 1, 2021

Copy link
Copy Markdown
Member Author

Well. There goes that.

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

Labels

Development

Successfully merging this pull request may close these issues.

Get rid of SingleVariable

3 participants