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

Convenience function for writing to a file #395

Closed
ericphanson opened this issue Aug 5, 2020 · 2 comments · Fixed by #531
Closed

Convenience function for writing to a file #395

ericphanson opened this issue Aug 5, 2020 · 2 comments · Fixed by #531

Comments

@ericphanson
Copy link
Collaborator

Now that Convex.jl is backed by MOI, we can take advantage of its ability to write to file formats (https://jump.dev/MathOptInterface.jl/stable/apimanual/#File-formats-1). It's actually pretty easy to do this already, e.g.

using Convex, COSMO
x = HermitianSemidefinite(2)
p = minimize( real(tr(x)), tr(x * [1.0 im; -im 0]) == 0, x[1,1] == 1)
solve!(p, COSMO.Optimizer)

using MathOptInterface
const MOI = MathOptInterface
dest = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_SDPA)
src = p.model
MOI.copy_to(MOI.Bridges.full_bridge_optimizer(dest, Float64), src)
MOI.write_to_file(dest, "file.sdpa")

and now the model has been written to file.sdpa. I deliberately chose a slightly complicated problem with PSD constraints and complex numbers to show that that isn't an issue; Convex.jl's extended formulations and MOI's bridges lower everything to a simple problem that gets written to the file. This file could then be used to solve the problem with solvers that are not yet connected to MOI, or uploaded to https://neos-server.org/neos/, etc.

We could make this simpler to use; for example, it might not be obvious that one needs to solve the problem first (which is when Convex.jl does its reformulations and populates p.model with the MOI model). Providing an API like Convex.write_to_file(p::Problem, filename::String) could work, as MOI.FileFormats.Model already supports guessing the file format by name.

Note that

x = HermitianSemidefinite(2)
p = minimize( real(tr(x)), tr(x * [1.0 im; -im 0]) == 0, x[1,1] == 1)

is already a readable and compact representation of the problem, and along with a Project.toml and Manifest.toml, is a fully reproducible way to describe the problem, so I think in many cases code is a good way to save the problem, but in a few cases this functionality could be really helpful. For example, it would've helped us quickly start solving problems with Convex.jl and SDPA-GMP instead of needing to wrap the solver first (which we did in https://github.com/ericphanson/SDPAFamily.jl).

This is pretty easy to add but I will at least wait for #393.

@odow
Copy link
Member

odow commented Dec 1, 2020

Cool to see this works. Obligatory link to https://github.com/odow/NEOS.jl.

@ericphanson
Copy link
Collaborator Author

Ah cool, I hadn't seen NEOS.jl!

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

Successfully merging a pull request may close this issue.

2 participants