Memory leak coming from MixedIntegerLinearProgram ???

121 views
Skip to first unread message

Saul Schleimer

unread,
Nov 2, 2016, 5:34:44 AM11/2/16
to sage-devel
Here is a bit of code:

# foo.py

def dot_prod(v, w):
    return sum(x*y for (x, y) in zip(v, w))

def get_polytope(M):
    q = MixedIntegerLinearProgram( maximization = False, solver = 'Coin' )
    w = q.new_variable(real = True, nonnegative = True)
    for v in M.rows():
        q.add_constraint( dot_prod(v, w) == 0 )
    return q.polyhedron()

M = Matrix([[1,0],[0,1]])

def fill_memory(n):
    for i in xrange(n):
        P = get_polytope(M)

Now I can do the following:

[Code]$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath Version 6.8, Release Date: 2015-07-26                     │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: attach('foo.py')
sage: get_memory_usage()
288.58984375
sage: fill_memory(2000); get_memory_usage()
300.5859375
sage: fill_memory(2000); get_memory_usage()
302.5859375
sage: fill_memory(2000); get_memory_usage()
303.5859375
sage: fill_memory(2000); get_memory_usage()
305.5859375

It seems like MixedIntegerLinearProgram is leaking memory.  This kills my computer during long computations.

Suggestions?

all the best,

saul

Sébastien Labbé

unread,
Nov 2, 2016, 7:22:43 AM11/2/16
to sage-devel
I get: "ImportError: No module named coin_backend".

Without solver='Coin', I get:

sage: get_memory_usage()
316.6015625
sage: fill_memory(2000)
sage: get_memory_usage()
341.578125
sage: fill_memory(2000)
sage: get_memory_usage()
341.578125
sage: fill_memory(2000)
sage: get_memory_usage()
341.578125
sage: fill_memory(2000)
sage: get_memory_usage()
341.578125
sage: fill_memory(2000)
sage: get_memory_usage()
341.578125

Dima Pasechnik

unread,
Nov 2, 2016, 8:23:27 AM11/2/16
to sage-devel
Good catch, so this leak is apparently in coin backend.
It's interesting to try all the backends for this...
 

Saul Schleimer

unread,
Nov 2, 2016, 11:15:54 AM11/2/16
to sage-devel
It seems that:

'CVXOPT', 'PPL', 'GLPK' don't leak 
'COIN' does
'CPLEX', 'Gurobi' are not yet installed on my machine

best,

saul

Sébastien Labbé

unread,
Nov 2, 2016, 12:43:39 PM11/2/16
to sage-devel
Can you check if the following also leaks?


def get_polytope(M):
    q = MixedIntegerLinearProgram( maximization = False, solver = 'Coin' )
    w = q.new_variable(real = True, nonnegative = True)
    for v in M.rows():
        q.add_constraint( dot_prod(v, w) == 0 )
    return None


def get_polytope(M):
    q = MixedIntegerLinearProgram( maximization = False, solver = 'Coin' )
    w = q.new_variable(real = True, nonnegative = True)

so that we can know if the problem is in "q.polyhedron()" or in "q.add_constraint(...)".

Saul Schleimer

unread,
Nov 2, 2016, 8:48:23 PM11/2/16
to sage-devel
Dear Sébastien - 

def get_polytope(M):
    q = MixedIntegerLinearProgram( maximization = False, solver = 'Coin' )
    w = q.new_variable(real = True, nonnegative = True)
    for v in M.rows():
        q.add_constraint( dot_prod(v, w) == 0 )
    return None

This also leaks.
 
def get_polytope(M):
    q = MixedIntegerLinearProgram( maximization = False, solver = 'Coin' )
    w = q.new_variable(real = True, nonnegative = True)

This doesn't. 

s.

Sébastien Labbé

unread,
Nov 3, 2016, 3:11:49 AM11/3/16
to sage-devel
Therefore, this should also leak:

def get_polytope():

    q = MixedIntegerLinearProgram( maximization = False, solver = 'Coin' )
    w = q.new_variable(real = True, nonnegative = True)
    q.add_constraint( w[0] == 0 )
    q.add_constraint( w[1] == 0 )


def fill_memory(n):
    for i in xrange(n):
        get_polytope()

fill_memory(2000)

The following does not:

def get_polytope():

    q = MixedIntegerLinearProgram( maximization = False, solver = 'Coin' )
    w = q.new_variable(real = True, nonnegative = True)

Does the following also leak ?

def get_polytope():

    q = MixedIntegerLinearProgram( maximization = False, solver = 'Coin' )
    w = q.new_variable(real = True, nonnegative = True)
    q.add_constraint( w[0] == 0 )

Sébastien

Saul Schleimer

unread,
Nov 3, 2016, 9:18:34 PM11/3/16
to sage-devel

This also appears to leak memory: 

def get_polytope():
    q = MixedIntegerLinearProgram( maximization = False, solver = 'Coin' )
    w = q.new_variable(real = True, nonnegative = True) 
    q.add_constraint( w[0] == 0 )

def fill_memory(n):
    for i in xrange(n):
        P = get_polytope()

best,

saul

Dima Pasechnik

unread,
Nov 4, 2016, 3:09:21 PM11/4/16
to sage-devel
I have created https://trac.sagemath.org/ticket/21825 to track this.

Sébastien Labbé

unread,
Nov 4, 2016, 3:11:27 PM11/4/16
to sage-devel

Sébastien Labbé

unread,
Nov 4, 2016, 3:23:16 PM11/4/16
to sage-devel
Oups! closing #21826 as duplicate!
 

Dima Pasechnik

unread,
Nov 4, 2016, 3:24:09 PM11/4/16
to sage-devel


On Friday, November 4, 2016 at 7:11:27 PM UTC, Sébastien Labbé wrote:
OK, I've reviewed it already :-)  
Reply all
Reply to author
Forward
0 new messages