Opened 9 years ago

Closed 6 years ago

#15159 closed defect (fixed)

Segfault after deepcopy of MixedIntegerLinearProgram

Reported by: Joris Vankerschaver Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: linear programming Keywords:
Cc: Vincent Delecroix, Volker Braun, Dima Pasechnik Merged in:
Authors: Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #20414 Stopgaps:

Status badges

Description

I wanted to make a copy of a linear program and modify the copy somewhat further. Using deepcopy I get a segfault (tested under 5.12.beta4) running the following:

sage: p = MixedIntegerLinearProgram()
sage: w = p.new_variable()
sage: q = deepcopy(p)
sage: q.add_constraint(w[0] >= 0)
------------------------------------------------------------------------
------------------------------------------------------------------------
Unhandled SIGSEGV: A segmentation fault occurred in Sage.
This probably occurred because a *compiled* component of Sage has a bug
in it and is not properly wrapped with sig_on(), sig_off(). You might
want to run Sage under gdb with 'sage -gdb' to debug this.
Sage will now terminate.
------------------------------------------------------------------------

The same segfault happens when one instead defines a new variable for the new linear program and tries to add constraints in terms of that variable:

sage: p = MixedIntegerLinearProgram()
sage: q = deepcopy(p)
sage: w = q.new_variable()
sage: q.add_constraint(w[0] >= 0)

Everything works well when using copy instead of deepcopy. Nevertheless, could this be related to #11588?

Change History (9)

comment:1 Changed 9 years ago by For batch modifications

Milestone: sage-6.1sage-6.2

comment:2 Changed 9 years ago by For batch modifications

Milestone: sage-6.2sage-6.3

comment:3 Changed 8 years ago by For batch modifications

Milestone: sage-6.3sage-6.4

comment:4 Changed 7 years ago by Matthias Köppe

Cc: Vincent Delecroix Volker Braun Dima Pasechnik added

Is deepcopy supposed to work?

comment:5 Changed 7 years ago by Matthias Köppe

See also #20414

comment:6 Changed 7 years ago by Matthias Köppe

Dependencies: #20414

These segfaults happen because deepcopy does not copy the backend at all:

sage: p = MixedIntegerLinearProgram()
sage: w = p.new_variable()
sage: q = deepcopy(p)
sage: p.get_backend()
<sage.numerical.backends.coin_backend.CoinBackend object at 0x19e7be670>
sage: q.get_backend()

#20414 supplies the necessary __deepcopy__ methods.

However, the same example with copy instead of deepcopy also does not work, but for a different reason.

sage: p = MixedIntegerLinearProgram(solver='glpk')
sage: w = p.new_variable()
sage: q = copy(p)
sage: q.add_constraint(w[0] >= 0)
...
GLPKError: glp_set_mat_row: i = 1; len = 1; invalid row length 
Error detected in file glpapi01.c at line 760

What's happening in this example is that the variable w[0] is created in the wrong MIP -- in p; because w belongs to p and knows nothing about q. Then using that variable in q leads to an out-of-bounds error (with GLPK) or crash (with COIN) as reported in #19523, #19525, #20360.

If one creates the variable w[0] before copying (simply by "mentioning" it), then this code goes through:

sage: p = MixedIntegerLinearProgram()
sage: w = p.new_variable()
sage: w[0]
x_0
sage: sage: q = deepcopy(p)
sage: sage: q.add_constraint(w[0] >= 0)

We should conclude that copy (or deepcopy) of a MixedIntegerLinearProgram is not very useful because we can no longer (safely) access its variables. See #19523.

comment:7 Changed 7 years ago by Matthias Köppe

Milestone: sage-6.4sage-duplicate/invalid/wontfix
Status: newneeds_review

Fixed in #20414, #19525 / duplicate of #19523, #20360. Marking it as duplicate - needs review.

comment:8 Changed 7 years ago by Travis Scrimshaw

Reviewers: Travis Scrimshaw
Status: needs_reviewpositive_review

comment:9 Changed 6 years ago by Volker Braun

Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.