Opened 5 years ago

Closed 5 years ago

#21491 closed defect (fixed)

IndexError in integral_points_count of Polyhedron

Reported by: slabbe Owned by:
Priority: major Milestone: sage-7.5
Component: geometry Keywords: days79
Cc: mkoeppe 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 5 years ago by mkoeppe

  • Cc mkoeppe added

comment:2 Changed 5 years ago by slabbe

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 5 years ago by slabbe

  • Authors set to Sébastien Labbé
  • Branch set to u/slabbe/21491
  • Commit set to 27948e85f24bcf0c757bd4cee65143845194cb84
  • Status changed from new to needs_review

New commits:

27948e821491: using file numOfLatticePoints for integral_points_count method

comment:4 Changed 5 years ago by moritz

This seems to work!

comment:5 Changed 5 years ago by moritz

  • Status changed from needs_review to positive_review

comment:6 Changed 5 years ago by slabbe

  • Keywords days79 added

Thanks for the review!

comment:7 Changed 5 years ago by slabbe

  • Reviewers set to Moritz Minzlaff

comment:8 Changed 5 years ago by tscrim

  • Status changed from positive_review to needs_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 5 years ago by tscrim

  • Status changed from needs_review to needs_work

comment:10 Changed 5 years ago by moritz

  • Reviewers changed from Moritz Minzlaff to Moritz Firsching

comment:11 Changed 5 years ago by git

  • Commit changed from 27948e85f24bcf0c757bd4cee65143845194cb84 to 347aa90df56bd59874377452afc130b2c8981f23

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

347aa9021491: catching the IndexError instead

comment:12 Changed 5 years ago by tscrim

  • Reviewers changed from Moritz Firsching to Moritz Firsching, Travis Scrimshaw
  • Status changed from needs_work to positive_review

Thanks.

comment:13 Changed 5 years ago by vbraun

  • Status changed from positive_review to needs_work

Documentation doesn't build, see patchbot.

comment:14 Changed 5 years ago by tscrim

  • Branch changed from u/slabbe/21491 to u/tscrim/21491
  • Commit changed from 347aa90df56bd59874377452afc130b2c8981f23 to ce82303ab9a0fd27576464c9a7f1900537b45d5e
  • Milestone changed from sage-7.4 to sage-7.5
  • Status changed from needs_work to positive_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 5 years ago by slabbe

Thank you for fixing this Travis.

Sébastien

comment:16 Changed 5 years ago by vbraun

  • Branch changed from u/tscrim/21491 to ce82303ab9a0fd27576464c9a7f1900537b45d5e
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.