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

Replacement of sage/libs/ppl.pyx by pplpy #23024

Closed
vinklein mannequin opened this issue May 18, 2017 · 255 comments
Closed

Replacement of sage/libs/ppl.pyx by pplpy #23024

vinklein mannequin opened this issue May 18, 2017 · 255 comments

Comments

@vinklein
Copy link
Mannequin

vinklein mannequin commented May 18, 2017

The Sage wrappers around ppl are now superseded by the standalone pplpy (Python/Cython compatible). This ticket proposes to replace src/sage/libs/ppl.pyx extension with pplpy. For this, we

  • create a new standard package pplpy
  • upgrade gmpy2 from optional to standard
  • replace the Sage code calling sage/libs/ppl.pyx to call pplpy
  • make appropriate deprecation for sage.libs.ppl

Tarball for pplpy: pplpy-0.8.4.tar.gz

Upstream: Reported upstream. Developers acknowledge bug.

CC: @videlec @kiwifb @embray @slel

Component: packages: standard

Keywords: thursdaysbdx, ppl, pplpy, upgrade

Author: Vincent Klein

Branch: 829317e

Reviewer: Dima Pasechnik, François Bissey, Vincent Delecroix, Jeroen Demeyer, Erik Bray

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

@vinklein vinklein mannequin added this to the sage-8.0 milestone May 18, 2017
@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 18, 2017

Changed dependencies from #229 to #22928

@vinklein vinklein mannequin added the t: enhancement label May 18, 2017
@videlec

This comment has been minimized.

@videlec

This comment has been minimized.

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Jun 7, 2017

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2017

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

f8bf274Updating checksum for pplpy pkg

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2017

Commit: f8bf274

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Jun 7, 2017

comment:7

For testing purpose you can use the following tarball of pplpy (outdated, use the one in the ticket's description)

@videlec
Copy link
Contributor

videlec commented Jun 7, 2017

comment:8

Salut Vincent,

Your branch appears in red which means that there are merge issues (possibly trivial). Would be better to rebase it on the latest beta.

@videlec
Copy link
Contributor

videlec commented Jun 7, 2017

comment:9
  1. Pickling should be fixed
-        sage: TestSuite(Asso).run()
+        sage: TestSuite(Asso).run(skip='_test_pickling')

It works with pplpy used from Python

>>> x = ppl.Variable(0)
>>> y = ppl.Variable(1)
>>> z = ppl.Variable(2)
>>> gs.insert(ppl.point(x+y+2*z))
>>> gs.insert(ppl.point(x-y))
>>> gs.insert(ppl.point(z))
>>> P = ppl.C_Polyhedron(gs)
>>> import pickle
>>> pickle.loads(pickle.dumps(P)) == P
True
  1. I don't see the point of the function mpz_to_sage_integer. You can just do [Integer(x) for x in my_mpz_list]. For example
v_coords = (1,) + tuple(mpz_to_sage_integer(v.coefficients()))

can be replaced by

v_coords = (1,) + tuple(Integer(c) for c in v.coefficients())

Moreover, the name is confusing since the fuction converts a list of mpz integers.

  1. Some possible simplifications
  • In ppl_backend.pyx:
    Integer(g.coefficient(Variable(variable))) / Integer(g.divisor()) ->
    Rational(g.coefficient(Variable(variable)) / g.divisor())

  • In ppl_lattice_polytope.py: assert Integer(v.divisor()).is_one() -> assert v.divisor() == 1

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2017

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

f19f81eInteger and rational constructors support gmpy2 params
cd8ef5dremove OptionalExtension sage.libs.gmpy2
8ced5d3remove get_gmpy2_path()
674fe62Add few doctests
2ed4f95Use of MPZ_Check and MPQ_Check functions from gmpy2 C-API
b4f0c26Add pplpy as a standard package
257c330Replace sage.libs.ppl with pplpy package
636051fRemove sage.libs.ppl extension
f52b3d4Modify associahedron doctest
dffa134Updating checksum for pplpy pkg

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2017

Changed commit from f8bf274 to dffa134

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Jun 7, 2017

comment:11

Replying to @videlec:

  1. Some possible simplifications
  • In ppl_backend.pyx:
    Integer(g.coefficient(Variable(variable))) / Integer(g.divisor()) ->
    Rational(g.coefficient(Variable(variable)) / g.divisor())

  • In ppl_lattice_polytope.py: assert Integer(v.divisor()).is_one() -> assert v.divisor() == 1

It will be nice, but coercion for gmpy2 types is required for doing this (#23052).

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2017

Changed commit from dffa134 to b3563eb

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2017

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

b3563ebremove mpz_to_sage_integer function

@videlec
Copy link
Contributor

videlec commented Jun 7, 2017

comment:13

Replying to @vinklein:

Replying to @videlec:

  1. Some possible simplifications
  • In ppl_backend.pyx:
    Integer(g.coefficient(Variable(variable))) / Integer(g.divisor()) ->
    Rational(g.coefficient(Variable(variable)) / g.divisor())

  • In ppl_lattice_polytope.py: assert Integer(v.divisor()).is_one() -> assert v.divisor() == 1

It will be nice, but coercion for gmpy2 types is required for doing this (#23052).

Where? The first involves a direct call Rational(mpq_type) and the second comparison between mpz and Python integer. Which operation is mixing gmpy2 types with Sage types?

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Jun 8, 2017

comment:14

Replying to @videlec:

Where? The first involves a direct call Rational(mpq_type) and the second comparison between mpz and Python integer. Which operation is mixing gmpy2 types with Sage types?

You're right, tests failures in ppl_backend.pyx with the suggested code are not coercion related. Forget my previous comment.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 8, 2017

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

3785bf4assert simplification ppl_lattice_polytope.py
d3875e7remove skip=('_test_pickling') option for pplpy polyhedron

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 8, 2017

Changed commit from b3563eb to d3875e7

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Jun 8, 2017

comment:16

As pplpy has evolved to fix pickling with cPickle download pplpy again to update your local package.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 9, 2017

Changed commit from d3875e7 to 7ae21f5

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 9, 2017

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

700f72cremove sage/libs/ppl from doctree
7ae21f5trac 23024 Bullet list indentation correction

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 15, 2017

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

08c7a72Add path of gmpy2 in include_dirs
359a0ffupdate checksum and package version
0d4fd2eInteger and rational constructors support gmpy2 params
7c66a7cremove OptionalExtension sage.libs.gmpy2
d143dderemove get_gmpy2_path()
2c56a3fAdd few doctests
e5264fdUse of MPZ_Check and MPQ_Check functions from gmpy2 C-API
504ab68Change way of creating a Rational from a mpz
072a15cadd __mpz__() to Rational
858c2e5trac 23024 update pplpy checksum

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 15, 2017

Changed commit from 7ae21f5 to 858c2e5

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Jun 15, 2017

comment:19

As pplpy has evolved to fix pickling with cPickle download ​pplpy again to update your local package.

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Nov 16, 2017

Changed dependencies from #22928 to #22928, #23309

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 17, 2017

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

1c1b971Replace sage.libs.ppl with pplpy package
2a1798eRemove sage.libs.ppl extension
d1b0b2fModify associahedron doctest
db21e1dUpdating checksum for pplpy pkg
eb215c3remove mpz_to_sage_integer function
53f30f3assert simplification ppl_lattice_polytope.py
f9a6415remove skip=('_test_pickling') option for pplpy polyhedron
924984cremove sage/libs/ppl from doctree
ce863ffupdate checksum, snapshot version update in setup.py
7a5812aAdd path of gmpy2 in include_dirs

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Feb 28, 2019

comment:204

Ok thank you for your help.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 28, 2019

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

76cfa5fTrac #23024: upgrade pplpy to 0.8.4
829317eTrac #23024: add a spkg-postrm script to clean...

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 28, 2019

Changed commit from b25b719 to 829317e

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Feb 28, 2019

comment:206

Upgrade to pplpy 0.8.4 and add a spkg-postrm script to clean the documentation.
A reviewer should validate ​829317e in order to set this ticket in positive review.

@vinklein vinklein mannequin removed their assignment Feb 28, 2019
@vinklein vinklein mannequin added s: needs review and removed s: needs work labels Feb 28, 2019
@videlec
Copy link
Contributor

videlec commented Feb 28, 2019

comment:209

doing some testing...

@videlec
Copy link
Contributor

videlec commented Feb 28, 2019

comment:210

spkg-postrm works as expected. Thanks Vincent!

@slel
Copy link
Member

slel commented Mar 1, 2019

comment:211

Adding "upgrade" to keywords to emphasize the need to upload new tarball to our download mirrors.

@slel

This comment has been minimized.

@slel
Copy link
Member

slel commented Mar 1, 2019

Changed keywords from thursdaysbdx, ppl, pplpy to thursdaysbdx, ppl, pplpy, upgrade

@vbraun
Copy link
Member

vbraun commented Mar 2, 2019

Changed branch from u/vklein/replacement_of_sage_libs_ppl_pyx_by_pplpy to 829317e

@novoselt
Copy link
Member

novoselt commented Mar 3, 2019

comment:213

There were several instances of removal similar to self._PPL_C_Polyhedron.set_immutable() - is this functionality no longer supported? This was done for objects that are cached and if a user ever modifies the polyhedron, things will get wrong.

@novoselt
Copy link
Member

novoselt commented Mar 3, 2019

Changed commit from 829317e to none

@videlec
Copy link
Contributor

videlec commented Mar 3, 2019

comment:214

Replying to @novoselt:

There were several instances of removal similar to self._PPL_C_Polyhedron.set_immutable() - is this functionality no longer supported? This was done for objects that are cached and if a user ever modifies the polyhedron, things will get wrong.

Indeed, it is not supported anymore. Also you can not cache a PPL_C_Polyhedron: https://gitlab.com/videlec/pplpy/blob/master/ppl/polyhedron.pyx#L86-102

In sage, the pplpy polyhedra are only used as attribute from which the user is not supposed to have direct access (unless she knows very well what she is doing). The higher level Polyhedron_base still implements this mutability flag.

Could you give a concrete example of a problematic behavior?

@novoselt
Copy link
Member

novoselt commented Mar 4, 2019

comment:215

Well I don't have an example from "real life" given that these objects used to be immutable and that I generally knew what I am doing, but the situation I have described is not at all impossible. Although the method returning PPL representation is underscored. There is also a discrepancy with documentation at
https://github.com/sagemath/sage-prod/blob/develop/src/sage/geometry/cone.py#L1373
which claims that supplied polytope will be made immutable.

@videlec
Copy link
Contributor

videlec commented Mar 4, 2019

comment:216

Please continue the discussion at #27423 since this ticket is closed.

@jdemeyer
Copy link

Changed reviewer from Dima Pasechnik, François Bissey, ​Vincent Delecroix, Jeroen Demeyer, Erik Bray to Dima Pasechnik, François Bissey, Vincent Delecroix, Jeroen Demeyer, Erik Bray

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

8 participants