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

Visual Code Python debugging tool crashes when trying to access "Model" object attributes before optimization #26

Open
otavio-silva opened this issue Nov 21, 2019 · 16 comments
Labels
bug Something isn't working cbc All items related to cbc

Comments

@otavio-silva
Copy link

Consider the following code to model the maximum independent set problem to solve the maximum clique using MIP and NetworkX:

import mip
import networkx

n = 2 ** 3
g = networkx.binomial_tree(n)
networkx.add_star(g, [i for i in range(n)])
g1 = networkx.complement(g)

model = mip.Model("Independent Set")
x = [model.add_var(var_type=mip.BINARY) for _ in range(len(g1.nodes))]
model.objective = mip.maximize(mip.xsum(x[i] for i in range(len(g1.nodes))))
for (i, j) in g1.edges:
	model += x[i] + x[j] <= 1
model.optimize()
selected = [i for i in range(len(g1.nodes)) if x[i].x >= 0.99]
print(selected)
g2 = g.subgraph(selected)

If I try to access the model variables in the watch section, it gives he following message on terminal:

Information not available, model was not optimized yet.

And then, the debugger dies. I believe this is not what should happen, some help with this?

@h-g-s
Copy link
Contributor

h-g-s commented Nov 21, 2019 via email

@otavio-silva
Copy link
Author

Thanks for the feedback, glad to see this issue being addressed!

@h-g-s
Copy link
Contributor

h-g-s commented Nov 30, 2019

should be fixed in 1.6, could you please check ?

@otavio-silva
Copy link
Author

I updated MIP and checked yesterday and the same behaviour continues

@h-g-s
Copy link
Contributor

h-g-s commented Dec 1, 2019 via email

@otavio-silva
Copy link
Author

I'm not sure, Visual Code shows my all attributes of the object, but I can't see any because the debugger dies before anything shows up. Not sure if relevant, but the same thing happens on Jupyter notebooks, if I use the tab key to show the attributes of the object, the kernel also dies.

@h-g-s
Copy link
Contributor

h-g-s commented Dec 2, 2019

The object that you tried to inspect in the debugger is a variable ? Right now (1.6) no exception is thrown while querying variable contents, so I don't know where to look

@otavio-silva
Copy link
Author

It is, in my example code it's the model variable, before running the model.optimize() line.

@h-g-s
Copy link
Contributor

h-g-s commented Dec 11, 2019

Hi @otavio-silva , could you provide your code (or better, an small example) where it happens so that I can check if this is solved ?

@otavio-silva
Copy link
Author

@h-g-s here's an example modelling the 0-1 Knapsack problem:

import mip

p = [825594, 1677009, 1676628, 1523970, 943972, 97426, 69666, 1296457, 1679693, 1902996, 1844992, 1049289, 1252836, 1319836, 953277, 2067538, 675367, 853655, 1826027, 65731, 901489, 577243, 466257, 369261]
w = [382745, 799601, 909247, 729069, 467902, 44328, 34610, 698150, 823460, 903959, 853665, 551830, 610856, 670702, 488960, 951111, 323046, 446298, 931161, 31385, 496951, 264724, 224916, 169684]
c = 6404180
n = len(w)

model = mip.Model("Knapsack")
x = [model.add_var(var_type=mip.BINARY) for _ in range(n)]
model.objective = mip.maximize(mip.xsum(p[i] * x[i] for i in range(n)))
model += mip.xsum(w[i] * x[i] for i in range(n)) <= c
model.optimize()
selected = [i for i in range(n) if x[i].x >= 0.99]
print(selected)

If I try to inspect the model variable before calling model.optimize(), the debugger dies. I'm using Visual Studio code.

@tuliotoffolo
Copy link
Contributor

Hi @otavio-silva,
I am trying to reproduce the error, however everything works fine for me. Can you provide me your python and Visual Studio Code versions?

screenshot

@otavio-silva
Copy link
Author

Sorry for the delay, here's the info:

Python-MIP package version 1.6.4
Python 3.7.5 (default, Oct 31 2019, 15:18:51) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Visual Studio Code 1.41.0
9579eda04fdb3a9bba2750f15193e5fafe16b959
x64

@h-g-s
Copy link
Contributor

h-g-s commented Dec 30, 2019

Hi @otavio-silva , just released 1.6.5. There was a case when dual information was being queried when it was not available that was fixed. Maybe this is the cause of your crash. Could you test it ?

@otavio-silva
Copy link
Author

I just tested it @h-g-s, and it still gives the same error, sadly.

@h-g-s
Copy link
Contributor

h-g-s commented Jan 3, 2020

hi @otavio-silva , just released 1.6.6 with a fix that may be related to this problem: querying the objective function without optimizing was crashing. Now it returns None if no solution is available. Could you please check again ?

@otavio-silva
Copy link
Author

I just tested it with the new version, there's still something causing crashes.

@sebheger sebheger added cbc All items related to cbc bug Something isn't working not reproducible If a bug/behaviour could not be reproduced labels May 8, 2022
@sebheger sebheger removed the not reproducible If a bug/behaviour could not be reproduced label Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cbc All items related to cbc
Projects
None yet
Development

No branches or pull requests

4 participants