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

Use CombinatorialPolyhedron to obtain faces lattice of polyhedra #28982

Closed
kliem opened this issue Jan 10, 2020 · 55 comments
Closed

Use CombinatorialPolyhedron to obtain faces lattice of polyhedra #28982

kliem opened this issue Jan 10, 2020 · 55 comments

Comments

@kliem
Copy link
Contributor

kliem commented Jan 10, 2020

We use CombinatorialPolyhedron to compute the face lattice of a polyhedron.

Along the way we implement hasse_diagram for CombinatorialPolyhedron and Polyhedron_base.

Instead of caching face_lattice, we cache hasse_diagram now.

This is much slower, but removes a memory leak. As hasse_diagram is hardly used with #28646, this seems to be reasonable.

Caching the face lattice does create a memory leak:

sage: import gc
sage: P = polytopes.cube()
sage: P.my_face_lattice = P.face_lattice()
sage: n = get_memory_usage()
sage: P = polytopes.cube()
sage: P.my_face_lattice = P.face_lattice()
sage: _ = gc.collect()
sage: n == get_memory_usage()
False

Depends on #29583

CC: @jplab @LaisRast

Component: geometry

Keywords: polyhedron, face lattice

Author: Jonathan Kliem

Branch/Commit: 6b7b5b6

Reviewer: Jean-Philippe Labbé, Matthias Koeppe

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

@kliem kliem added this to the sage-9.1 milestone Jan 10, 2020
@kliem
Copy link
Contributor Author

kliem commented Jan 10, 2020

Branch: public/28982

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 10, 2020

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

242f34fadd hasse_diagram to combinatorial polyhedron
af84439implemented method hasse diagram for polyhedra
cfb153duse combinatorial polyhedron to obtain face lattice of polyhedron

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 10, 2020

Commit: cfb153d

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 14, 2020

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

41254c2fixed pyflakes warnings

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 14, 2020

Changed commit from cfb153d to 41254c2

@kliem
Copy link
Contributor Author

kliem commented Feb 12, 2020

comment:5

I changed to face lattice not to be set up with linear extension anymore.


New commits:

261feffadd hasse_diagram to combinatorial polyhedron
721cff6implemented method hasse diagram for polyhedra
0768b90use combinatorial polyhedron to obtain face lattice of polyhedron
c82545ffixed pyflakes warnings
f249c9dfixed failing doctest; face lattice can compute whether it is eulerian again

@kliem
Copy link
Contributor Author

kliem commented Feb 12, 2020

Changed branch from public/28982 to public/28982-reb

@kliem
Copy link
Contributor Author

kliem commented Feb 12, 2020

Changed commit from 41254c2 to f249c9d

@jplab
Copy link

jplab commented Feb 14, 2020

comment:6

Few comments:

-        Test that face lattice give no memory leak::
+        Test that computing the face lattice does not lead to a memory leak::
-        Return the hasse diagram of ``self``.
+        Return the hasse diagram of the face lattice of ``self``.

I will go more in depth soon.

Does this mean that we can remove the file hasse_diagram.py?

@kliem
Copy link
Contributor Author

kliem commented Feb 14, 2020

Changed commit from f249c9d to f44afa2

@kliem
Copy link
Contributor Author

kliem commented Feb 14, 2020

New commits:

ef69d37add hasse_diagram to combinatorial polyhedron
919af02implemented method hasse diagram for polyhedra
f040df6use combinatorial polyhedron to obtain face lattice of polyhedron
f9f7a42fixed pyflakes warnings
f306cd0fixed failing doctest; face lattice can compute whether it is eulerian again
f44afa2improved documentation

@kliem
Copy link
Contributor Author

kliem commented Feb 14, 2020

Changed branch from public/28982-reb to public/28982-reb2

@kliem

This comment has been minimized.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 14, 2020

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

e9b3201improved doctest, gc.collect should be run before the test as well

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 14, 2020

Changed commit from f44afa2 to e9b3201

@mkoeppe
Copy link
Contributor

mkoeppe commented Apr 14, 2020

comment:10

Batch modifying tickets that will likely not be ready for 9.1, based on a review of the ticket title, branch/review status, and last modification date.

@mkoeppe mkoeppe modified the milestones: sage-9.1, sage-9.2 Apr 14, 2020
@jplab
Copy link

jplab commented Apr 20, 2020

Reviewer: Jean-Philippe Labbé

@jplab
Copy link

jplab commented Apr 20, 2020

comment:11

Suggestions:

+        .. NOTE::
-            The face lattice is not cached, as long as this would create a memory leak.
+            The face lattice is not cached, as long as this creates a memory leak, see :trac:`28982`.

Hasse is a lastname, so you can capitalize it within the documentation.

Could the function below have more information? Like which order is meant to be simulated here? Inclusion or lex on indices of vertices, etc? Just one more sentence to specify might be nice?

+    def __lt__(self, other):
+        r"""
+        Compare faces of the same polyhedron.
+
+        EXAMPLES::
+
+            sage: P = polytopes.simplex()
+            sage: C = CombinatorialPolyhedron(P)
+            sage: F1 = C.face_by_face_lattice_index(0)
+            sage: F2 = C.face_by_face_lattice_index(1)
+            sage: F1 < F2
+            True
+        """
+        return hash(self) < hash(other)

Is there a reason why the hasse diagram of the combinatorial polyhedron is not cached?

@kliem
Copy link
Contributor Author

kliem commented Apr 20, 2020

New commits:

e7093ebMerge branch 'public/28982-reb2' of git://trac.sagemath.org/sage into public/28982-reb3
b559ca1cache hasse_diagram of combinatorial polyhedron
2fb6746improved documentation
92842beexplain __lt__

@kliem
Copy link
Contributor Author

kliem commented Apr 20, 2020

Changed branch from public/28982-reb2 to public/28982-reb3

@kliem
Copy link
Contributor Author

kliem commented Apr 20, 2020

Changed commit from e9b3201 to 92842be

@kliem
Copy link
Contributor Author

kliem commented Aug 13, 2020

comment:26

Needs rebase (build fails).

@kliem
Copy link
Contributor Author

kliem commented Aug 13, 2020

Changed branch from public/28982-reb6 to public/28982-reb7

@kliem
Copy link
Contributor Author

kliem commented Aug 13, 2020

New commits:

4596af9Merge branch 'public/28982-reb6' of git://trac.sagemath.org/sage into public/28982-reb7
2297474import DiGraph in time

@kliem
Copy link
Contributor Author

kliem commented Aug 13, 2020

Changed commit from f4e1dec to 2297474

@mkoeppe
Copy link
Contributor

mkoeppe commented Aug 27, 2020

comment:28
+    if polyhedron.dimension() == 0:
+        # In case of the 0-dimensional polyhedron,
+        # there is a facets but no inequality.
+        H_indices = tuple(range(n_equations))
+

The comment needs rewording

@kliem
Copy link
Contributor Author

kliem commented Aug 27, 2020

Changed commit from 2297474 to 92487de

@kliem
Copy link
Contributor Author

kliem commented Aug 27, 2020

Changed branch from public/28982-reb7 to public/28982-reb8

@kliem
Copy link
Contributor Author

kliem commented Aug 27, 2020

New commits:

52b634fMerge branch 'public/28982-reb7' of git://trac.sagemath.org/sage into public/28982-reb8
92487deimproved comment

@mkoeppe
Copy link
Contributor

mkoeppe commented Aug 30, 2020

comment:31
+    def __lt__(self, other):
+        r"""
+        Compare faces of the same polyhedron.
+
+        This is a helper function.
+        In order to construct a Hasse diagram (a digraph) with combinatorial faces,
+        we must define some order relation that is compatible with the Hasse diagram.
+
+        Any order relation compatible with ordering by dimension is suitable.
+        We us :meth:`__hash__` to define the relation.

I don't fully understand what's happening in that hash function. If one uses the face iterator in non-dual mode, is the resulting order relation still correct?

@mkoeppe
Copy link
Contributor

mkoeppe commented Aug 30, 2020

Changed reviewer from Jean-Philippe Labbé to Jean-Philippe Labbé, Matthias Koeppe

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2020

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

6b7b5b6make hash function consistent with dual mode

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2020

Changed commit from 92487de to 6b7b5b6

@kliem
Copy link
Contributor Author

kliem commented Aug 31, 2020

comment:33

Replying to @mkoeppe:

+    def __lt__(self, other):
+        r"""
+        Compare faces of the same polyhedron.
+
+        This is a helper function.
+        In order to construct a Hasse diagram (a digraph) with combinatorial faces,
+        we must define some order relation that is compatible with the Hasse diagram.
+
+        Any order relation compatible with ordering by dimension is suitable.
+        We us :meth:`__hash__` to define the relation.

I don't fully understand what's happening in that hash function. If one uses the face iterator in non-dual mode, is the resulting order relation still correct?

You are right.
I'm surprised it worked that way.
The hash function should be consistent now. And __lt__ returns None if the faces are clearly incompatible.
What's nice about this hash function, if I understand it correctly, is that it allows to store faces in sets etc.

@kliem
Copy link
Contributor Author

kliem commented Aug 31, 2020

comment:35

Thank you.

@vbraun
Copy link
Member

vbraun commented Sep 6, 2020

Changed branch from public/28982-reb8 to 6b7b5b6

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

4 participants