trulsf / UnitJuMP.jl

Julia package allowing unit modelling in JuMP using Unitful
MIT License
20 stars 1 forks source link

Open design questions #6

Open odow opened 2 years ago

odow commented 2 years ago

Here are some open design questions that aren't really bugs or features requests, but more things to think about. Resolving them will probably need changes to JuMP.

What happens if some coefficients are missing units?

using UnitJuMP
model = Model()
@variable(model, x >= 0, u"m/s")
@variable(model, x >= 0, u"m/s")
@constraint(model, x <= 1)                  # Option 1
@constraint(model, x <= 1u"m/s")            # Option 2
@constraint(model, x <= 1, u"ft/s")         # Option 3
@constraint(model, x <= 1u"m/s", u"ft/s")   # Option 4

Currently, only options 2 and 4 are supported. That seems like the right answer. We should favor strictness.

How to handle units in expressions and the objective?

JuMP allows tagging and extending variables and constraints, but not expressions and the objective function:

using UnitJuMP
model = Model()
@variable(model, x >= 0, u"m/s")
expr = @expression(model, x + 1u"m/s")
@objective(model, Min, expr)
# Potential syntax
expr = @expression(model, x + 1u"m/s", u"f/s")
@objective(model, Min, expr, u"f/s")

objective_value ignores units

I don't know what we could do about this:

julia> using UnitJuMP, HiGHS

julia> model = Model(HiGHS.Optimizer);

julia> @variable(model, x >= 1.2, u"m/s")
x m s⁻¹

julia> obj = @objective(model, Min, 2 * x + 1u"m/s")
2 x + 1 [m s⁻¹]

julia> optimize!(model)
Presolving model
0 rows, 0 cols, 0 nonzeros
0 rows, 0 cols, 0 nonzeros
Presolve : Reductions: rows 0(-0); columns 0(-1); elements 0(-0) - Reduced to empty
Solving the original LP from the solution after postsolve
Solving an unconstrained LP with 1 columns
Model   status      : Optimal
Objective value     :  3.4000000000e+00
HiGHS run time      :          0.00

julia> objective_value(model)
3.4

julia> value(obj)
3.4 m s⁻¹