Opened 8 years ago
Closed 5 years ago
#15159 closed defect (fixed)
Segfault after deepcopy of MixedIntegerLinearProgram
Reported by: | jvkersch | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-duplicate/invalid/wontfix |
Component: | linear programming | Keywords: | |
Cc: | vdelecroix, vbraun, dimpase | Merged in: | |
Authors: | Reviewers: | Travis Scrimshaw | |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | #20414 | Stopgaps: |
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 8 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:2 Changed 7 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:3 Changed 7 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:4 Changed 5 years ago by
- Cc vdelecroix vbraun dimpase added
comment:5 Changed 5 years ago by
See also #20414
comment:6 Changed 5 years ago by
- Dependencies set to #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 5 years ago by
- Milestone changed from sage-6.4 to sage-duplicate/invalid/wontfix
- Status changed from new to needs_review
comment:8 Changed 5 years ago by
- Reviewers set to Travis Scrimshaw
- Status changed from needs_review to positive_review
comment:9 Changed 5 years ago by
- Resolution set to fixed
- Status changed from positive_review to closed
Is
deepcopy
supposed to work?