Skip to content

Commit 7eb1726

Browse files
authored
Simplify write_to_file so that it does not need an optimizer (#591)
1 parent ed63b35 commit 7eb1726

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

src/problems.jl

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -306,26 +306,17 @@ end
306306
307307
Write the current problem to the file at `filename`.
308308
309-
Requires solving the problem at least once using [`solve!`](@ref) to ensure that
310-
the problem is loaded into a MathOptInterface model.
311-
312309
The file format is inferred from the filename extension. Supported file
313310
types depend on the model type.
314311
315312
Currently, `Float64` is the only supported coefficient type. This may be
316313
relaxed in future if file formats support other types.
317314
"""
318315
function write_to_file(p::Problem{T}, filename::String) where {T<:Float64}
319-
if p.model === nothing
320-
msg = """
321-
Problem has not been loaded into a MathOptInterface model;
322-
call `solve!(problem, optimizer)` before writing problem to file.
323-
"""
324-
throw(ArgumentError(msg))
325-
end
316+
src = Context(p, MOI.Utilities.Model{T})
326317
dest = MOI.FileFormats.Model(; filename)
327318
model = MOI.Bridges.full_bridge_optimizer(dest, T)
328-
MOI.copy_to(model, p.model)
319+
MOI.copy_to(model, src.model)
329320
MOI.write_to_file(dest, filename)
330321
return
331322
end

test/test_utilities.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,6 @@ function test_write_to_file()
922922
p = minimize(logsumexp(x))
923923
dir = mktempdir()
924924
filename = joinpath(dir, "test.mof.json")
925-
@test_throws ArgumentError write_to_file(p, filename)
926-
solve!(p, SCS.Optimizer; silent_solver = true)
927925
write_to_file(p, filename)
928926
@test occursin("ExponentialCone", read(filename, String))
929927
p_int = minimize(logsumexp(x); numeric_type = Int)

0 commit comments

Comments
 (0)