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

Don't use is_package_installed('bliss') #21289

Closed
mantepse opened this issue Aug 19, 2016 · 47 comments
Closed

Don't use is_package_installed('bliss') #21289

mantepse opened this issue Aug 19, 2016 · 47 comments

Comments

@mantepse
Copy link
Contributor

In 6.9.beta5 I have:

sage: p = posets.IntegerPartitions(20)
sage: timeit("p.canonical_label()")
5 loops, best of 3: 180 ms per loop

whereas in 7.4.beta1

sage: timeit("p.canonical_label()")
5 loops, best of 3: 1.58 s per loop

CC: @jm58660 @fchapoton @jdemeyer @mkoeppe @tscrim

Component: graph theory

Author: Frédéric Chapoton

Branch/Commit: 253517d

Reviewer: François Bissey, Jeroen Demeyer

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

@mantepse mantepse added this to the sage-7.4 milestone Aug 19, 2016
@jm58660
Copy link
Mannequin

jm58660 mannequin commented Aug 19, 2016

comment:1

Can you check canonical label for plain graphs? Are you sure that you don't have Bliss installed in 6.9 but not in 7.4?

@mantepse
Copy link
Contributor Author

comment:2

(no, i haven't installed bliss in either version)

The problem is actually elsewhere:

sage: timeit('p._hasse_diagram.canonical_label(algorithm="sage")')
5 loops, best of 3: 93 ms per loop

In 7.4, all the time is eaten by

sage: timeit("is_package_installed('bliss')")
5 loops, best of 3: 1.37 s per loop

I think that Posets.canonical_label should also accept the optional argument algorithm.

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Aug 19, 2016

comment:3

Replying to @mantepse:

In 7.4, all the time is eaten by

sage: timeit("is_package_installed('bliss')")
5 loops, best of 3: 1.37 s per loop

Is the problem installed_packages()? On my system it seems to be the problem.

I think that Posets.canonical_label should also accept the optional argument algorithm.

True. I can add it, but let's first check what is wrong here.

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Aug 19, 2016

comment:4

I think I got it. It does

proc = subprocess.Popen(["pip", "list"], stdout=subprocess.PIPE)
stdout = proc.communicate()[0]
return dict((name.lower(), version) for name,version in PIP_VERSION.findall(stdout))

and this is clearly too much for every function call.

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Aug 19, 2016

comment:5

Jeroen is propably interested in this.

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Aug 19, 2016

comment:6

As the problem is now in the ticket #21291 and the keyword is added at #21293 we can close this one.

@jm58660 jm58660 mannequin removed this from the sage-7.4 milestone Aug 19, 2016
@jm58660 jm58660 mannequin added the s: needs review label Aug 19, 2016
@mantepse
Copy link
Contributor Author

Reviewer: Martin Rubey

@jdemeyer
Copy link

comment:9

Replying to @mantepse:

is_package_installed('bliss')

Don't do that. Use the Easier to ask for forgiveness than permission principle: assume that Bliss is installed and fail gracefully if not.

@jdemeyer jdemeyer added this to the sage-7.4 milestone Aug 19, 2016
@jdemeyer jdemeyer changed the title speed regression in Poset.canonical_label Don't use is_package_installed('bliss') Aug 19, 2016
@mantepse
Copy link
Contributor Author

comment:10

So all of these (except the ones in package) are wrong:

-*- mode: grep; default-directory: "~/sage-develop/src/sage/" -*-
Grep started at Fri Aug 19 13:31:58

grep -r -nH -e "is_package_installed(" *
databases/cremona.py:827:            elif is_package_installed('database_cremona_ellcurve'):
databases/cremona.py:1676:        if is_package_installed('database_cremona_ellcurve'):
game_theory/normal_form_game.py:1320:            if is_package_installed('lrslib'):
game_theory/normal_form_game.py:1326:            if not is_package_installed('lrslib'):
geometry/polyhedron/base.py:3694:        if not is_package_installed('lrslib'):
graphs/generic_graph.py:7877:            elif is_package_installed("python_igraph"):
graphs/generic_graph.py:20258:             is_package_installed('bliss'))):
graphs/generic_graph.py:20927:             is_package_installed('bliss') and
graphs/graph_generators.py:1199:        if not is_package_installed("buckygen"):
graphs/graph_generators.py:1284:        if not is_package_installed("benzene"):
graphs/graph_generators.py:1437:        if not is_package_installed("plantri"):
graphs/graph_generators.py:1636:        if not is_package_installed("plantri"):
graphs/graph_generators.py:1790:        if not is_package_installed("plantri"):
graphs/lovasz_theta.py:70:    if not is_package_installed('csdp'):
graphs/generators/classical_geometries.py:1292:    if not is_package_installed('gap_packages'):
groups/perm_gps/permgroup.py:193:        if not is_package_installed('gap_packages'):
groups/perm_gps/permgroup.py:1686:            if not is_package_installed('database_gap'):
groups/perm_gps/permgroup.py:1739:            if not is_package_installed('database_gap'):
groups/perm_gps/permgroup.py:4117:        if not is_package_installed('gap_packages'):
groups/generic.py:1407:        if not is_package_installed('database_gap'):
misc/package.py:294:def is_package_installed(package):
misc/package.py:300:        sage: is_package_installed('pari')
misc/package.py:305:        sage: is_package_installed('matplotli')
Übereinstimmungen in Binärdatei misc/package.pyc.
rings/polynomial/multi_polynomial_sequence.py:1432:                if not is_package_installed('fes'):

Grep finished (matches found) at Fri Aug 19 13:31:58

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Aug 19, 2016

comment:11

Why can't Sage just check installed packages on startup and make a list to some global variable?

@jdemeyer
Copy link

comment:12

Replying to @jm58660:

Why can't Sage just check installed packages on startup and make a list to some global variable?

Because that would be very slow, see #21291.

@mantepse
Copy link
Contributor Author

comment:13

Some are possibly OK, for example in cremona.py, because they only determine the error message.

However, that's not quite true either: if I'm going to catch an error, I possibly rely on it being thrown quickly...

@jdemeyer
Copy link

comment:14

Replying to @mantepse:

So all of these (except the ones in package) are wrong:

At least the ones which involve an OptionalExtension (like bliss) should be replaced by just importing the module.

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Aug 19, 2016

comment:15

Replying to @jdemeyer:

Replying to @jm58660:

Why can't Sage just check installed packages on startup and make a list to some global variable?

Because that would be very slow, see #21291.

Too slow to do it once at startup?

@mantepse
Copy link
Contributor Author

comment:16

Replying to @jdemeyer:

Replying to @jm58660:

Why can't Sage just check installed packages on startup and make a list to some global variable?

Because that would be very slow, see #21291.

I do not understand this answer. Compiling the list once does not take very long. The problem occurs only because sage is doing it over and over again.

@mantepse
Copy link
Contributor Author

comment:17

I do think however that we want to be able to pick up new packages without having to leave sage, don't we?

@jdemeyer
Copy link

comment:18

Replying to @mantepse:

Compiling the list once does not take very long.

Compiling the list once takes an extremely long time (almost 2 seconds on my machine).

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Aug 19, 2016

comment:19

Replying to @mantepse:

I do think however that we want to be able to pick up new packages without having to leave sage, don't we?

I don't think that it is an important feature. Would be nice, yes, but a minor issue.

@fchapoton
Copy link
Contributor

Branch: u/chapoton/21289

@fchapoton
Copy link
Contributor

Commit: 4d8b477

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 26, 2016

Changed commit from 4d8b477 to ec04bff

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 26, 2016

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

ec04bffforgot another bliss usage

@jdemeyer
Copy link

comment:33

Could you replace

raise ImportError("You must install the 'bliss' package to run this command.")

by

from sage.misc.package import PackageNotFoundError
raise PackageNotFoundError("bliss")

This will give a customized error message.

@jdemeyer
Copy link

Author: Frédéric Chapoton

@jdemeyer
Copy link

Changed reviewer from Martin Rubey to Jeroen Demeyer

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 26, 2016

Changed commit from ec04bff to 253517d

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 26, 2016

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

253517dusing PackageNotFoundError twice

@fchapoton
Copy link
Contributor

comment:35

done

@fchapoton
Copy link
Contributor

comment:36

ping ?

@jdemeyer
Copy link

comment:37

This looks good, but it just needs testing that it works both without and with bliss.

@jdemeyer
Copy link

comment:38

Let's wait for the patchbot...

@fchapoton
Copy link
Contributor

comment:39

ok, bot is green. Jeroen ?

@jdemeyer
Copy link

comment:40

I'll test it now on my computer with bliss installed.

@kiwifb
Copy link
Member

kiwifb commented Aug 28, 2016

comment:41

Given that this code is very close to the stuff I do in sage-on-gentoo with that file - may be Jeroen has been inspired by something he saw a while back :P - I would put this positive. But since Jeroen wants to try it, I'll let him push the button.

@jdemeyer
Copy link

Changed reviewer from Jeroen Demeyer to François Bissey, Jeroen Demeyer

@vbraun
Copy link
Member

vbraun commented Aug 30, 2016

Changed branch from u/chapoton/21289 to 253517d

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

5 participants