question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
h-g-scommented, Nov 21, 2019

Hello Otávio !

Currently we throw an exception when an specific property of a variable (the solution value x) is accessed, since the debugger is probably trying to access all properties we have this problem…

I think that the behaviour could be changed to just return None as solution value when no optimization is performed. I’ll include this change in the next release.

Cheers,

Haroldo

Haroldo Gambini Santos Computing Department Universidade Federal de Ouro Preto - UFOP email: haroldo@ufop.edu.br Haroldo.GambiniSantos@cs.kuleuven.be home/research page: www.decom.ufop.br/haroldo

It has long been an axiom of mine that the little things are infinitely the most important. – Sir Arthur Conan Doyle, “A Case of Identity”

On Wed, 20 Nov 2019, Otávio Augusto Silva wrote:

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?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, orunsubscribe.[AB4VZOQHN473EXM6FJ7JUZTQUXXB5A5CNFSM4JP4AJ72YY3PNVWWK3TUL52HS4D FUVEXG43VMWVGG33NNVSW45C7NFSM4H27DLLQ.gif]

0reactions
otavio-silvacommented, Jan 3, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debug Python code - Visual Studio (Windows) - Microsoft Learn
Open a command window in Visual Studio using the View > Other Windows > Command Window menu command. · Enter the following command:...
Read more >
Debugging configurations for Python apps in Visual Studio Code
Sets a debug property that must be known to the debug server before the client connects. Such properties can be used directly in...
Read more >
Python's assert: Debug and Test Your Code Like a Pro
When Not to Use Assertions? Understanding Python's assert Statements. The Syntax of the assert Statement; The AssertionError Exception.
Read more >
A comprehensive guide to debugging Python scripts in VS Code
The basics · Variables Pane — here we can easily inspect the variables which are created while running the script. · Watch Pane...
Read more >
Changelog — Python 3.11.1 documentation
gh-98783: Fix multiple crashes in debug mode when str subclasses ... gh-96352: Fix AttributeError missing name and obj attributes in object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found