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

Model printing is rather verbose #3651

Closed
LebedevRI opened this issue Jan 14, 2024 · 5 comments · Fixed by #3686
Closed

Model printing is rather verbose #3651

LebedevRI opened this issue Jan 14, 2024 · 5 comments · Fixed by #3686
Labels
Category: Printing Related to printing

Comments

@LebedevRI
Copy link
Contributor

LebedevRI commented Jan 14, 2024

Consider something as simple as

model = Model();
@variable(model, 0 <= x[1:100, 1:100] <= 10, Int)
print(model)

This produces ~30k lines of output.

Given that each x[i] can even have it's own type,
i can't imagine solving this is too simple,
but surely this can be improved?

(I've encountered this the hard way, with chrome tab crashing
(and, you can't even increase per-tab memory limits nowadays!),
and had to fix it by manually going into .ipynb notebook...)

@odow
Copy link
Member

odow commented Jan 15, 2024

We don't recommend print(model) for large models. But perhaps we should figure out a way to truncate the output.

We don't have any plans to improve the output, like detecting sets and printing stylized models. At one point (many years ago) JuMP used to do that, but it proved too complicated and fragile to maintain.

@odow odow added the Category: Printing Related to printing label Jan 15, 2024
@odow
Copy link
Member

odow commented Jan 15, 2024

We'd have to decide if truncating printing by default is breaking though.

I'm imagining something like:

function _print_model(io::IO, model::AbstractModel; force::Bool)
    N = num_variables(model)
    if N > 100 && !force
        @warn(
            "There a $N variables in the model. Printing may produce an " *
            "undesirably large amount of output. To force printing, use " *
            "`print(model; force = true)`"
        )
        return
    end

@LebedevRI
Copy link
Contributor Author

Right, lossily truncating the output is of course not always wanted.
I understand that this issue is rather a nitpick.

I'm imagining something like:

This should also count number of constraints perhaps.

@odow
Copy link
Member

odow commented Jan 15, 2024

Here are some related issues where we have discussed this previously #3574, #2171, #795

I think the issue is that there is no one-size-fits-all approach to what people want from print(model).

What did you want or expect to happen in the original case?

@LebedevRI
Copy link
Contributor Author

I suppose i knew it would be printed the way it did,
but i suppose i would've expected it to be printed in more succinct, non-unrolled, form.

I suppose i should look more into https://jump.dev/MathOptInterface.jl/stable/reference/standard_form/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Printing Related to printing
Development

Successfully merging a pull request may close this issue.

2 participants