floating point (xeon/gentoo only?) weirdness with cvxopt ('sage' vs 'sage --python' difference)

41 views
Skip to first unread message

Dima Pasechnik

unread,
Dec 9, 2015, 11:04:45 AM12/9/15
to sage-devel
Are floating point settings (some low level flags???)
subtly different for Sage's Python and Sage itself? Namely, the same code succeeds or fails, depending on whether
it is invoked in Sage's Python, or in Sage proper (with preparser(False)).

It is an iterative procedure (call to solvers.sdp() below)  that for first few steps behaves identically, but then there is divergence - it completes correctly in Python, but fails, after many
iterations,  in Sage.  I can only reproduce it on a Xeon machine running Gentoo Linux (the sage4 patchbot at U.Ghent). This was 1st uncovered while
testing #16929.

Here is the complete code (in Sage you also need preparser(False) first).

################################
from cvxopt import matrix, solvers
c = matrix([1.,-1.])
G =  [ matrix([[1., 2., 2., 3.],   [3., 4., 4., 5.]]) ]
G += [ matrix([[1., 1., 1., 1.], [2., 2., 2., 2.]]) ]
G += [ matrix([[-1.],  [0.]]) ]
G += [ matrix([[0.],  [-1.]]) ]
h =  [ matrix([[5., 6.], [6., 7.]]) ]
h += [ matrix([[3., 3.], [3., 3.]]) ]
h += [ matrix([[0.]]) ]
h += [ matrix([[0.]]) ]
sol = solvers.sdp(c, Gs=G, hs=h)
print(sol['x'])
##################################
# in sage I get 'Terminated (maximum number of iterations reached).' (after 100 iterations)
# in sage --python I get 'Optimal solution found.' (after 26 iterations)
# divergence happens around iteration 17 or 18
#

Thanks,
Dima


Volker Braun

unread,
Dec 9, 2015, 11:51:45 AM12/9/15
to sage-devel
Can you compare the floating point rounding modes at entry and exit of solvers.sdp?

Dima Pasechnik

unread,
Dec 9, 2015, 2:37:31 PM12/9/15
to sage-devel
On Wednesday, 9 December 2015 16:51:45 UTC, Volker Braun wrote:
Can you compare the floating point rounding modes at entry and exit of solvers.sdp?

I cannot reproduce it anymore. I don't know, I ran

sage: from decimal import getcontext
sage: getcontext()
Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999999, Emax=999999999, capitals=1, flags=[], traps=[DivisionByZero, Overflow, InvalidOperation])

and the same in Sage's Python --- the only difference was the order of entries in traps[]. (The order of these things appears to be sort of random, on another
machine I tried, too)

And then this chunk of code started to work in Sage, just like this.
(I tried to get another copy of Sage, and it still worked)
Cosmic rays? Dying hardware? No idea...

Dima



 
Reply all
Reply to author
Forward
0 new messages