Opened 4 years ago

Last modified 3 years ago

#26363 closed defect — at Version 9

Reported by: Matthias Köppe Owned by:
Priority: major Milestone: sage-9.1
Component: geometry Keywords:
Cc: Jean-Philippe Labbé, Winfried Bruns, Travis Scrimshaw, gh-kliem Merged in:
Authors: Jonathan Kliem Reviewers:
Report Upstream: N/A Work issues:
Branch: public/26363 (Commits, GitHub, GitLab) Commit: a75d3b22d3ece100a0cdfa925644d9bd040cba3c
Dependencies: #28639 Stopgaps:

Status badges

Description (last modified by gh-kliem)

sage: P = polytopes.dodecahedron(backend='normaliz')
sage: P
A 3-dimensional polyhedron in (Number Field in sqrt5 with defining polynomial x^2 - 5)^3 defined as the convex hull of 20 vertices
TypeError: can't pickle PyCapsule objects

We fix this by removing the cone with __getstate__ on pickling.

On unpickling we use __setstate__ and _cone_from_Vrepresentation_and_Hrepresentation from #28639 to restore the cone.

Special care has to be taken in the following cases:

  • no inequalities (the cone can only be initialized from Vrep),
  • the empty polyhedron (cone is None in this case).

As the lines are recomputed, there is no guarantee that they appear in the same order in the normaliz cone. However, normaliz sorts the given lines anyway:

sage: P = Polyhedron(lines=[[1,0], [0,1]], backend='normaliz').lines()
(A line in the direction (1, 0), A line in the direction (0, 1))
sage: P = Polyhedron(lines=[[0,1], [1,0]], backend='normaliz').lines()
(A line in the direction (1, 0), A line in the direction (0, 1))
sage: P = Polyhedron(lines=[[1,1], [1,0]], backend='normaliz').lines()
(A line in the direction (1, 0), A line in the direction (0, 1))

Also, even if _normaliz_cone has the lines somewhat shuffled, this shouldn't be noticable as computations are invariant on which line we choose.

Change History (9)

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

Description: modified (diff)

comment:2 Changed 3 years ago by gh-kliem

One could define in Polyhedron_normaliz:

def __getstate__(self):
     state = super(Polyhedron_normaliz, self).__getstate__()
     # Remove the unpicklable entries.
     del state[1]['_normaliz_cone']
     return state

This constructs an object just as

sage: P = P.base_extend(P.base_ring(),backend='field')
sage: P.base_extend(P.base_ring(),backend='normaliz')

(but saving computed results)

However, one would need a method to recover _normaliz_cone (this method is needed anyway, to make the second thing work).

comment:3 Changed 3 years ago by Jean-Philippe Labbé

Cc: gh-kliem added

comment:4 Changed 3 years ago by gh-kliem

I think I know what to do about it.

  1. As mentioned one can just remove the cone on pickling. Then the loaded object is just as good as changing backend back and forth (and changing backend to normaliz should also work and still give us a cone or a way to retrive the cone).
  1. Next step would be do allow initialization of a cone from Vrepresentation and Hrepresentation. This works by homogenization of the input and explicitly giving a dehomogenization (this is the only way that Normaliz accepts precomputed data).

Note: I'm not proposing to allow to give both representations to normaliz by the user, but when changing fields or loading a stored object I think we should trust them to be correct.

  1. Once this is done, one can set up normaliz cone to be a lazy attribute.

comment:5 Changed 3 years ago by gh-kliem

Dependencies: #28639

In #28639 I will implement a method that generates the cone from both Vrep and Hrep (recomputing the lines, but thats ok I guess). I have tested this with a few polyhedra, but I have no idea, which examples can be tricky.

comment:6 Changed 3 years ago by gh-kliem

Description: modified (diff)
Milestone: sage-8.4sage-9.0

comment:7 Changed 3 years ago by gh-kliem

Authors: Jonathan Kliem
Branch: public/26363
Commit: 984cc62eb2b46b245dc93f5ca9dec983ec478531

New commits:

c42c907method to obtain cone from Vrep and Hrep
cc17f07added documentation to cone from normaliz data
a54cfd9Merge branch 'public/28639' of git:// into public/28639-reb
fc4c596alignment fix in docs
f42a4e2removed pickling restriction on normaliz tests
984cc62fixed pickling/unpickling of normaliz polyhedra

comment:8 Changed 3 years ago by git

Commit: 984cc62eb2b46b245dc93f5ca9dec983ec478531a75d3b22d3ece100a0cdfa925644d9bd040cba3c

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

a75d3b2take care of special cases

comment:9 Changed 3 years ago by gh-kliem

Description: modified (diff)
Status: newneeds_review

New commits:

a75d3b2take care of special cases
Note: See TracTickets for help on using tickets.