IPyKernel Crashes After Editing a Cell in Visual Studio Code
回答済みI created a simple model in a .ipynb file using the tutorial videos referenced in the Udemy course “A comprehensive introduction to mathematical optimization and Gurobi tailored to data scientists and problem solvers”.
This was my main.ipynb cell:
# DATA
# load or import DATA
import gurobipy as gp
categories = {"calories", "protein"}
minNutrition = {"calories": 1800, "protein":91}
maxNutrition = {"calories":2200, "protein":gp.GRB.INFINITY}
foods = {"salad", "ice cream"}
cost = {"salad": 2.49, "ice cream": 1.59}
nutritionValues = {
("salad", "calories") : 320,
("salad", "protein") : 31,
("ice cream", "calories") : 330,
("ice cream", "protein") : 8
}
# Model
# build our model
# define a model object
model = gp.Model("diet")
# introduce the vars to the model
food_quantities = model.addVars(foods, name = "quantity")
# define the objective function
totalCost = gp.quicksum(cost[f] * food_quantities[f] for f in foods)
model.setObjective(totalCost, gp.GRB.MINIMIZE)
# define the constraints
for c in categories:
categoryTotal = gp.quicksum(food_quantities[f] * nutritionValues[f,c] for f in foods)
model.addConstr(minNutrition[c] <= categoryTotal, name = "Total_" + c + "_Minimum")
model.addConstr(categoryTotal <= maxNutrition[c], name = "Total_"+c+"_Maximum")
# Optionally write out the model to a disk
model.write("Diet_Test.lp")
# Solve and Post-Process
model.optimize()
# Review the results
print(*[f"{f} : {food_quantities[f].X}\n" for f in foods])The program will run and output the correct information. If I, however, try to edit the cell by typing in it, the kernel will crash and leave an error message
The Kernel crashed while executing code in the current cell or a previous cell.
The Jupyter log does not provide helpful information.
[error] Disposing session as kernel process died ExitCode: undefined, Reason: [IPKernelApp]
The cell is editable without a kernel crash if I remove all lines under and including.
model = gp.Model("diet")
I don't encounter these issues with scikit-learn or SciPy. Additionally, text can be pasted and deleted without a kernel crash, but typing it will cause a crash.
I've been led to assume the crash has to do with kernel completions, and disabling it in Visual Studio Code does fix the issue.

In the meantime, I'm using Pylance for completions, but it would be nice to be able to use kernel completions instead as Pylance is slightly less intelligent when it comes to notebooks.
-
Hi Mirza,
I attempted to reproduce this issue but on my machine kernel completions causes no problems.
We possibly are using different Python version, OS, gurobipy version,
IPythonversion,ipykernelversion, VS Code version, Jupyter extension version, and Pylance extension version, so it will be hard to pin down the issue.My suggestion is to make sure you are running the latest version of VS Code and all relevant extensions and with a bit of luck the issue will disappear.
- Riley
0
サインインしてコメントを残してください。
コメント
1件のコメント