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

Segfault after deepcopy of MixedIntegerLinearProgram #15159

Closed
jvkersch opened this issue Sep 5, 2013 · 6 comments
Closed

Segfault after deepcopy of MixedIntegerLinearProgram #15159

jvkersch opened this issue Sep 5, 2013 · 6 comments

Comments

@jvkersch
Copy link
Contributor

jvkersch commented Sep 5, 2013

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?

Depends on #20414

CC: @videlec @vbraun @dimpase

Component: linear programming

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/15159

@jvkersch jvkersch added this to the sage-6.1 milestone Sep 5, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@mkoeppe
Copy link
Contributor

mkoeppe commented Apr 6, 2016

comment:4

Is deepcopy supposed to work?

@mkoeppe
Copy link
Contributor

mkoeppe commented Apr 11, 2016

comment:5

See also #20414

@mkoeppe
Copy link
Contributor

mkoeppe commented Apr 17, 2016

comment:6

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.

@mkoeppe
Copy link
Contributor

mkoeppe commented Apr 17, 2016

Dependencies: #20414

@mkoeppe
Copy link
Contributor

mkoeppe commented Apr 21, 2016

comment:7

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

@mkoeppe mkoeppe removed this from the sage-6.4 milestone Apr 21, 2016
@tscrim
Copy link
Collaborator

tscrim commented Apr 22, 2016

Reviewer: Travis Scrimshaw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants