Opened 6 years ago

Closed 6 years ago

#21491 closed defect (fixed)

IndexError in integral_points_count of Polyhedron

Reported by: Sébastien Labbé Owned by:
Priority: major Milestone: sage-7.5
Component: geometry Keywords: days79
Cc: Matthias Köppe Merged in:
Authors: Sébastien Labbé Reviewers: Moritz Firsching, Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: ce82303 (Commits, GitHub, GitLab) Commit: ce82303ab9a0fd27576464c9a7f1900537b45d5e
Dependencies: Stopgaps:

Status badges

Description

With latte_int installed:

$ sage -experimental
...
latte_int...............................1.7.3 (1.7.3)
...

I get:

sage: eqns = [[-10, 0, 1], [-10, 1, 0]]
sage: P = Polyhedron(ieqs=[], eqns=eqns)
sage: P.integral_points_count()
...
sage/geometry/polyhedron/base.pyc in integral_points_count(self, verbose)
   4259             raise RuntimeError("LattE integrale failed (exit code {}) to execute {}".format(ret_code, ' '.join(args)) + err.strip())
   4260
-> 4261         return Integer(ans.splitlines()[-1])
   4262
   4263     def integral_points(self, threshold=100000):

IndexError: list index out of range

Same error with:

sage: P = Polyhedron(ieqs=[], eqns=[[-11,0,2],[-10,1,0]])
sage: P.vertices()
(A vertex at (10, 11/2),)

The culprit might be the empty string:

sage: "".splitlines()[-1]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-1-7faf349df14a> in <module>()
----> 1 "".splitlines()[-Integer(1)]

IndexError: list index out of range

Change History (16)

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

Cc: Matthias Köppe added

comment:2 Changed 6 years ago by Sébastien Labbé

Just to say that in both cases, latte_int gets the answer right.

1 in this case:

sage: P = Polyhedron(ieqs=[], eqns=[[-10, 0, 1], [-10, 1, 0]])
sage: P.integral_points_count(verbose=True)
This is LattE integrale 1.7.3
Available from http://www.math.ucdavis.edu/~latte/
...
Ax <= b, given as (b|-A):
=========================
[]

Ax = b, given as (b|-A):
========================
[-10 0 1]
[-10 1 0]

The number of lattice points is 1.
---------------------------------------------------------------------------
Traceback (most recent call last)
...
IndexError: list index out of range

0 in this case:

sage: P = Polyhedron(ieqs=[], eqns=[[-11,0,2],[-10,1,0]])
sage: P.integral_points_count(verbose=True)
This is LattE integrale 1.7.3
Available from http://www.math.ucdavis.edu/~latte/
...
Ax <= b, given as (b|-A):
=========================
[]

Ax = b, given as (b|-A):
========================
[-11 0 2]
[-10 1 0]

The number of lattice points is 0.
---------------------------------------------------------------------------
Traceback (most recent call last)
...
IndexError: list index out of range

comment:3 Changed 6 years ago by Sébastien Labbé

Authors: Sébastien Labbé
Branch: u/slabbe/21491
Commit: 27948e85f24bcf0c757bd4cee65143845194cb84
Status: newneeds_review

New commits:

27948e821491: using file numOfLatticePoints for integral_points_count method

comment:4 Changed 6 years ago by Moritz Firsching

This seems to work!

comment:5 Changed 6 years ago by Moritz Firsching

Status: needs_reviewpositive_review

comment:6 Changed 6 years ago by Sébastien Labbé

Keywords: days79 added

Thanks for the review!

comment:7 Changed 6 years ago by Sébastien Labbé

Reviewers: Moritz Minzlaff

comment:8 Changed 6 years ago by Travis Scrimshaw

Status: positive_reviewneeds_review

Since opening a file takes ~10x longer than a try/except block, I suggest the following:

        try:
            return Integer(ans.splitlines()[-1])
        except IndexError:
            with open(SAGE_TMP+'/numOfLatticePoints', 'r') as f:
                return Integer(f.read())

comment:9 Changed 6 years ago by Travis Scrimshaw

Status: needs_reviewneeds_work

comment:10 Changed 6 years ago by Moritz Firsching

Reviewers: Moritz MinzlaffMoritz Firsching

comment:11 Changed 6 years ago by git

Commit: 27948e85f24bcf0c757bd4cee65143845194cb84347aa90df56bd59874377452afc130b2c8981f23

Branch pushed to git repo; I updated commit sha1. New commits:

347aa9021491: catching the IndexError instead

comment:12 Changed 6 years ago by Travis Scrimshaw

Reviewers: Moritz FirschingMoritz Firsching, Travis Scrimshaw
Status: needs_workpositive_review

Thanks.

comment:13 Changed 6 years ago by Volker Braun

Status: positive_reviewneeds_work

Documentation doesn't build, see patchbot.

comment:14 Changed 6 years ago by Travis Scrimshaw

Branch: u/slabbe/21491u/tscrim/21491
Commit: 347aa90df56bd59874377452afc130b2c8981f23ce82303ab9a0fd27576464c9a7f1900537b45d5e
Milestone: sage-7.4sage-7.5
Status: needs_workpositive_review

Trivial fix TESTS:: -> TESTS:, so I'm allowing myself to set this back to positive review.


New commits:

b090df5Merge branch 'u/slabbe/21491' of trac.sagemath.org:sage into u/tsrcim/21491
ce82303Fixing doc for #21491.

comment:15 Changed 6 years ago by Sébastien Labbé

Thank you for fixing this Travis.

Sébastien

comment:16 Changed 6 years ago by Volker Braun

Branch: u/tscrim/21491ce82303ab9a0fd27576464c9a7f1900537b45d5e
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.