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

ABC for convex sets #31919

Closed
mkoeppe opened this issue Jun 6, 2021 · 65 comments
Closed

ABC for convex sets #31919

mkoeppe opened this issue Jun 6, 2021 · 65 comments

Comments

@mkoeppe
Copy link
Contributor

mkoeppe commented Jun 6, 2021

We create a base class ConvexSet_base with abstract methods to define an API for convex sets (convex subsets of a finite dimensional topological R-vector space such as R^n).

We use it to test/unify the API of Polyhedron, ConvexRationalPolyhedralCone, LatticePolytope, RelativeInterior (#31916)

See also:

Depends on #31916

CC: @kliem @yuan-zhou @jplab @tscrim @novoselt @orlitzky

Component: geometry

Author: Matthias Koeppe

Branch/Commit: 686d0af

Reviewer: Jonathan Kliem

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

@mkoeppe mkoeppe added this to the sage-9.4 milestone Jun 6, 2021
@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 6, 2021

Branch: u/mkoeppe/abc_for_convex_sets

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2021

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

e67f753ConvexRationalPolyhedralCone: Add method is_empty and aliases is_full_dimensional, is_universe
770fdcdLatticePolytopeClass, IntegralRayCollection: Make ambient_dim an alias for lattice_dim
b2ac639ConvexSet_base.dim: New
ccc8421ConvexSet_base.is_compact, ConvexSet_compact: New

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2021

Commit: ccc8421

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 7, 2021

Author: Matthias Koeppe

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 7, 2021

Dependencies: #31916

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2021

Changed commit from ccc8421 to 4bac2fe

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2021

Branch pushed to git repo; I updated commit sha1. Last 10 new commits:

9df2104sage.geometry.relative_interior: Move here from sage.geometry.polyhedron.relint
b8bfe20ConvexRationalPolyhedralCone: Add methods interior, relative_interior
6869673relative_interior: Fix for dimension 0
021d073RelativeInterior: Add documentation, tests, comparison methods, method relative_interior
8f38e04ConvexRationalPolyhedralCone.interior, relative_interior: Add doctests
5f9c852RelativeInterior.interior: New
5c089ecRelativeInterior.__eq__, __ne__: Handle comparisons with objects of other types
86ce301Polyhedron_base.is_relatively_open: New; fix relative_interior for affine subspaces
42adcedMerge #31916
4bac2feRelativeInterior: Subclass ConvexSet_relatively_open, add missing methods

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2021

Changed commit from 4bac2fe to 1e8dd09

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2021

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

216cb81ConvexRationalPolyhedralCone.is_relatively_open: New, fix ConvexRationalPolyhedralCone.relative_interior for linear subspaces
1e8dd09Merge #31916

@mkoeppe

This comment has been minimized.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2021

Changed commit from 1e8dd09 to 3f4acb3

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2021

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

44cde1esrc/doc/en/reference/discrete_geometry/index.rst: Add sage/geometry/relative_interior
fa4c2d2Whitespace fixes
3f4acb3Merge #31916

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2021

Changed commit from 3f4acb3 to dede9de

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2021

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

dede9desrc/doc/en/reference/discrete_geometry/index.rst: Add sage/geometry/convex_set

@kliem
Copy link
Contributor

kliem commented Jun 8, 2021

comment:11

Missing doctest.

+    def is_empty(self):
+        """
+        Return whether ``self`` is the empty set.
+
+        Because a cone always contains the origin, this method returns ``False``.
+        """
+        return False

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 8, 2021

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

007e6fdConvexRationalPolyhedralCone.is_empty: Add doctest

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 8, 2021

Changed commit from dede9de to 007e6fd

@kliem
Copy link
Contributor

kliem commented Jun 9, 2021

comment:13

I guess it is back on needs review.

@kliem
Copy link
Contributor

kliem commented Jun 9, 2021

comment:14

Can you please add doctests for src/sage/geometry/convex_set.py yet.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 10, 2021

Changed commit from 007e6fd to 6a0baac

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 10, 2021

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

73e39ceConvexRationalPolyhedralCone.is_compact: Define
92f0610ConvexSet_open: New
03a31efPolyhedron_base.is_full_dimensional: Merge into ConvexSet_base.is_full_dimensional
a71507eConvexSet_base: Add some doctests
3a83182ConvexSet_base.relative_interior: New
6a0baacConvexSet_base._test_convex_set: New

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 12, 2021

Changed commit from 30ebaf5 to fcf2a32

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 12, 2021

Changed commit from fcf2a32 to 1448835

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 12, 2021

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

6bef52bConvexSet_base._test_convex_set: Run the testsuite of relint
1448835RelativeInterior.ambient, ambient_vector_space, is_universe: New

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 12, 2021

Changed commit from 1448835 to 8ff6457

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 12, 2021

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

8ff6457Polyhedron_base.interior: Handle the empty polyhedron correctly

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 12, 2021

comment:36

Replying to @kliem:

Replying to @mkoeppe:

Replying to @kliem:

  • Why have you removed the test suite on the relative interior of the empty polyhedron?

The reason for this is the assumption in is_closed

I see. I think it should be fixed then. Either we drop the requirement of being identical in the test suite or we add another clause for Polyhedron_base.relative_interior:

    if not self.is_full_dimensional():
+       if self.is_empty():
+           return self
        return self.parent().element_class(self.parent(), None, None)
    return self.relative_interior()

I have made a similar fix

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 12, 2021

comment:37

Replying to @kliem:

This is one reason why I improved sage --fixdoctests to work for error messages as well.

Yes, this was a great improvement!

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 12, 2021

Changed commit from 8ff6457 to 148016f

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 12, 2021

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

148016fPolyhedron_base.product: Add doctest for alias 'cartesian_product'

@kliem
Copy link
Contributor

kliem commented Jun 12, 2021

comment:39
sage -t --long --warn-long 111.1 --random-seed=0 relative_interior.py
**********************************************************************
File "relative_interior.py", line 82, in sage.geometry.relative_interior.RelativeInterior.ambient
Failed example:
    ri_segment.ambient()
Exception raised:
    Traceback (most recent call last):
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.geometry.relative_interior.RelativeInterior.ambient[2]>", line 1, in <module>
        ri_segment.ambient()
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-packages/sage/geometry/relative_interior.py", line 84, in ambient
        return self._polyhedron.ambient()
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-packages/sage/geometry/polyhedron/base_ZZ.py", line 51, in __getattribute__
        return super(Polyhedron_ZZ, self).__getattribute__(name)
      File "sage/structure/element.pyx", line 493, in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4708)
        return self.getattr_from_category(name)
      File "sage/structure/element.pyx", line 506, in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/element.c:4820)
        return getattr_from_other_class(self, cls, name)
      File "sage/cpython/getattr.pyx", line 367, in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2551)
        raise AttributeError(dummy_error_message)
    AttributeError: 'Polyhedra_ZZ_ppl_with_category.element_class' object has no attribute 'ambient'
**********************************************************************
File "relative_interior.py", line 96, in sage.geometry.relative_interior.RelativeInterior.ambient_vector_space
Failed example:
    ri_segment.ambient_vector_space()
Exception raised:
    Traceback (most recent call last):
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.geometry.relative_interior.RelativeInterior.ambient_vector_space[2]>", line 1, in <module>
        ri_segment.ambient_vector_space()
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-packages/sage/geometry/relative_interior.py", line 98, in ambient_vector_space
        return self._polyhedron.ambient_vector_space(base_field=base_field)
      File "/home/jonathan/Applications/sage/local/lib/python3.8/site-packages/sage/geometry/polyhedron/base_ZZ.py", line 51, in __getattribute__
        return super(Polyhedron_ZZ, self).__getattribute__(name)
      File "sage/structure/element.pyx", line 493, in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4708)
        return self.getattr_from_category(name)
      File "sage/structure/element.pyx", line 506, in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/element.c:4820)
        return getattr_from_other_class(self, cls, name)
      File "sage/cpython/getattr.pyx", line 367, in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2551)
        raise AttributeError(dummy_error_message)
    AttributeError: 'Polyhedra_ZZ_ppl_with_category.element_class' object has no attribute 'ambient_vector_space'
**********************************************************************
2 items had failures:
   1 of   4 in sage.geometry.relative_interior.RelativeInterior.ambient
   1 of   4 in sage.geometry.relative_interior.RelativeInterior.ambient_vector_space
    [59 tests, 2 failures, 0.13 s]
----------------------------------------------------------------------
sage -t --long --warn-long 111.1 --random-seed=0 relative_interior.py  # 2 doctests failed

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 12, 2021

Changed commit from 148016f to 686d0af

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 12, 2021

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

6ab5677RelativeInterior.is_universe: New
c085d30Polyhedron_base.interior: Handle the empty polyhedron correctly
686d0afPolyhedron_base.product: Add doctest for alias 'cartesian_product'

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 12, 2021

comment:41

Cherry-picking 1448835 from #31959 was a mistake, thanks for catching this.
Let's see what the patchbot thinks now

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 13, 2021

comment:42

Patchbot is green modulo the unrelated src/sage/misc/package.py failure

@kliem
Copy link
Contributor

kliem commented Jun 13, 2021

comment:43

We could replace the imports in lattice_polytope.py and cone.py by lazy imports:

========== startup_modules ==========

--- 9.4.beta1

+++ 9.4.beta1 + #31919


-Total count: 1762
+Total count: 1764
+New:
+sage.geometry.convex_set
+    sage.geometry.relative_interior
+====================

+sage.geometry.convex_set

+sage.geometry.relative_interior

-startup_modules Passed
+startup_modules Failed

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 13, 2021

comment:44

Fine with me if you want to make this change

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 13, 2021

comment:45

Actually I think after #31705 this won't matter

@kliem
Copy link
Contributor

kliem commented Jun 14, 2021

comment:46

Replying to @mkoeppe:

Actually I think after #31705 this won't matter

Yes, that's right.

@kliem
Copy link
Contributor

kliem commented Jun 14, 2021

comment:47

One tiny thing about RelativeInterior.interior: It should return self, if the relative interior is full-dimensional. This is currently the case, because the method relative_interior is cached for polyhedra and cones. Maybe it is cleaner to immediately catch the case. But it is not really needed.

Either way, LGTM.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 14, 2021

comment:48

Thank you!

We can make refinements to RelativeInterior in a later ticket. For now I prefer the version as is.

@mkoeppe

This comment has been minimized.

@vbraun
Copy link
Member

vbraun commented Jun 29, 2021

Changed branch from u/mkoeppe/abc_for_convex_sets to 686d0af

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

3 participants