Skip to content

Commit 3e72e12

Browse files
Sébastien LoiselSébastien Loisel
authored andcommitted
Fix docs build: declare StaticArrays in the docs environment
The GitHub docs build failed with 'Package StaticArrays not found in current path'. docs/make.jl includes jump/MultiGridBarrierJuMP.jl, which does 'using StaticArrays', but docs/Project.toml never listed StaticArrays as a direct dependency. Unlike the test environment (which inherits the package's [deps], StaticArrays among them), the docs environment is standalone: dev-ing the package in does not promote its deps to direct deps, so a top-level 'using StaticArrays' is unresolvable. It built locally only because the gitignored docs/Manifest.toml happened to have it wired; CI resolves fresh from Project.toml and failed. - docs/Project.toml: add StaticArrays (the fix) and LinearAlgebra (stdlib; added for self-documentation of what the included module loads). - jump/MultiGridBarrierJuMP.jl: implement JuMP's AbstractModel print hooks (objective_function_string, constraints_string, _nl_subexpression_string) so printing a model renders a native formulation instead of a MethodError from JuMP's print(::IO, ::AbstractModel) path.
1 parent 9a60f3f commit 3e72e12

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
4+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
45
MultiGridBarrier = "9e2c1f1d-9131-4ad4-b32f-bd2a0b0ecd1e"
56
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
7+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

jump/MultiGridBarrierJuMP.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,4 +1019,54 @@ solver_log(m::MGBModel) = (_checksolved(m); m.sol.log)
10191019
JuMP.set_attribute(m::MGBModel, k::String, v) = (m.attrs[k] = v; nothing)
10201020
JuMP.get_attribute(m::MGBModel, k::String) = get(m.attrs, k, nothing)
10211021

1022+
# ---------------------------------------------------------------------------
1023+
# Pretty-printing. JuMP's `print(model)` / `show(::MIME"text/plain")` route
1024+
# through `JuMP._print_model`, which requires an AbstractModel to implement
1025+
# these three string hooks. Implementing them (rather than only Base.show)
1026+
# means a bare `m` at the REPL renders as a native JuMP-style formulation
1027+
# instead of a MethodError. Per-node (spatial) coefficients have no scalar
1028+
# form, so they print as `⟨coef⟩`.
1029+
# ---------------------------------------------------------------------------
1030+
1031+
_atom_string(m::MGBModel, key::Tuple{Int,Symbol}) =
1032+
key[2] === :id ? String(m.comps[key[1]].name) :
1033+
"deriv($(m.comps[key[1]].name), :$(key[2]))"
1034+
1035+
_coef_string(c::CoefVal) = _isuniform(c) ? string(c.scalar) : "⟨coef⟩"
1036+
1037+
function _terms_string(m::MGBModel, terms, constant)
1038+
parts = String[_coef_string(c) * "*" * _atom_string(m, k) for (k, c) in terms]
1039+
s = isempty(parts) ? "0" : join(parts, " + ")
1040+
(constant === nothing || _iszeroval(constant)) ? s : s * " + " * _coef_string(constant)
1041+
end
1042+
_row_string(m::MGBModel, r::Row) = _terms_string(m, r.terms, r.constant)
1043+
1044+
function JuMP.objective_function_string(::MIME, m::MGBModel{T}) where {T}
1045+
m.objexpr === nothing && return "0"
1046+
"∫(" * _terms_string(m, m.objexpr.terms, m.objexpr.constant) * ") dx"
1047+
end
1048+
1049+
function JuMP.constraints_string(::MIME, m::MGBModel{T}) where {T}
1050+
out = String[]
1051+
for c in m.cons
1052+
region = c.pairs === nothing ? "" : " on $(length(c.pairs)) node(s)"
1053+
if c.settag[1] === :eq
1054+
comp = first(keys(c.rows[1].terms))[1]
1055+
push!(out, "$(m.comps[comp].name) == ⟨data⟩" * region)
1056+
elseif c.settag[1] === :nonneg
1057+
for r in c.rows
1058+
push!(out, _row_string(m, r) * " ≥ 0" * region)
1059+
end
1060+
elseif c.settag[1] === :power
1061+
p = c.settag[2]
1062+
pdesc = p isa Real ? string(p) : "p(x)"
1063+
q = String[_row_string(m, r) for r in c.rows[1:end-1]]
1064+
push!(out, "($(_row_string(m, c.rows[end]))) ≥ ‖($(join(q, ", ")))‖^$pdesc" * region)
1065+
end
1066+
end
1067+
return out
1068+
end
1069+
1070+
JuMP._nl_subexpression_string(::MIME, ::MGBModel) = String[]
1071+
10221072
end # module

0 commit comments

Comments
 (0)