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

The function pretty_stats cannot read solver_specific flags #149

Closed
DoctorDro opened this issue Feb 28, 2024 · 4 comments
Closed

The function pretty_stats cannot read solver_specific flags #149

DoctorDro opened this issue Feb 28, 2024 · 4 comments

Comments

@DoctorDro
Copy link
Contributor

Dear all,
I am running benchmarks on some JuMP problems. Some of them are nonconvex and during the course of iterations I have a way of storing a nonconvex certificate. This however, is not standard and has to be stored in solver_specific flags using the commands:

stats = GenericExecutionStats(nlp, status=status, solution=x, objective=fx, dual_feas=norm(∇fx), iter=iter, elapsed_time=Δt)
set_solver_specific!(stats, Symbol("isConvex"), is_convex)
return stats

However, I get an error when I try the following

stats = bmark_solvers( solvers, problems, skipif=prob -> (!unconstrained(prob) || get_nvar(prob) > 1000 || get_nvar(prob) < 2))

combined_stats = DataFrame(
    name           = stats[:newton].name,
    nvars          = stats[:newton].nvar,
    convex         = stats[:newton].solver_specific[:isConvex],
    newton_iters   = stats[:newton].iter,
)

pretty_stats(combined_stats)

Any ideas how the DataFrame could read whether the problem is convex or not ?

@tmigot
Copy link
Member

tmigot commented Feb 28, 2024

Hi @DoctorDro !

I tried to make a reproducible example and it seems to work! Note that you can access the solver specific fields directly stats[:newton].isConvex. Does that solve your problem?

using NLPModelsTest
using DataFrames, SolverCore, SolverBenchmark

function newton(nlp)
stats = GenericExecutionStats(nlp)
set_solver_specific!(stats, Symbol("isConvex"), :is_convex)
return stats
end

solvers = Dict(
    :newton => newton
)
problems = [NLPModelsTest.BROWNDEN()]
stats = bmark_solvers(solvers, problems)

combined_stats = DataFrame(
    name           = stats[:newton].name,
    nvars          = stats[:newton].nvar,
    convex         = stats[:newton].isConvex,
    newton_iters   = stats[:newton].iter,
)

pretty_stats(combined_stats)

@DoctorDro
Copy link
Contributor Author

Hi @DoctorDro !

I tried to make a reproducible example and it seems to work! Note that you can access the solver specific fields directly stats[:newton].isConvex. Does that solve your problem?

using NLPModelsTest
using DataFrames, SolverCore, SolverBenchmark

function newton(nlp)
stats = GenericExecutionStats(nlp)
set_solver_specific!(stats, Symbol("isConvex"), :is_convex)
return stats
end

solvers = Dict(
    :newton => newton
)
problems = [NLPModelsTest.BROWNDEN()]
stats = bmark_solvers(solvers, problems)

combined_stats = DataFrame(
    name           = stats[:newton].name,
    nvars          = stats[:newton].nvar,
    convex         = stats[:newton].isConvex,
    newton_iters   = stats[:newton].iter,
)

pretty_stats(combined_stats)

You are amazing! Thanks! I was missing the : in :is_convex on top of other things. Have a hard time understanding symbols and other goodies Julia has introduced. Different logic that I have to get used to. Is there any version of pretty_stats which writes the output on a file or so?

@dpo
Copy link
Member

dpo commented Feb 28, 2024

Yes, you can pass an IOStream to pretty_stats:

* `io::IO`: an IO stream to which the table will be output (default: `stdout`);
(e.g., an open file).

Example:

pretty_stats(io, df[!, cols], col_formatters = fmts, hdr_override = header, tf = tf_markdown)

@tmigot
Copy link
Member

tmigot commented Mar 1, 2024

@DoctorDro I close this as I think we answer your questions. I opened a new issue to add the missing info in the documentation.

@tmigot tmigot closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants