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

Stupid waste of time in graphs 1 #15704

Closed
nathanncohen mannequin opened this issue Jan 21, 2014 · 32 comments
Closed

Stupid waste of time in graphs 1 #15704

nathanncohen mannequin opened this issue Jan 21, 2014 · 32 comments

Comments

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jan 21, 2014

............

The point is that MY computations are never long because of the add/remove edge functions. I should pay more attention T_T

Before

sage: g = graphs.RandomGNP(1500,.4)
sage: edges = g.edges(labels=False)
sage: %time Graph(edges)
CPU times: user 2.50 s, sys: 0.03 s, total: 2.52 s
Wall time: 2.55 s
Graph on 1500 vertices
sage: h = Graph()
sage: %time h.add_edges(edges)
CPU times: user 4.90 s, sys: 0.02 s, total: 4.92 s
Wall time: 4.93 s

After

sage: g = graphs.RandomGNP(1500,.4)
sage: edges = g.edges(labels=False)
sage: %time Graph(edges)
CPU times: user 2.12 s, sys: 0.02 s, total: 2.14 s
Wall time: 2.16 s
Graph on 1500 vertices
sage: h = Graph()
sage: %time h.add_edges(edges)
CPU times: user 1.48 s, sys: 0.02 s, total: 1.50 s
Wall time: 1.52 s

Nathann

CC: @sagetrac-azi

Component: graph theory

Author: Nathann Cohen

Branch/Commit: 297b1b3

Reviewer: Vincent Delecroix

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

@nathanncohen nathanncohen mannequin added this to the sage-6.1 milestone Jan 21, 2014
@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 21, 2014

Branch: u/ncohen/15604

@nathanncohen nathanncohen mannequin added the s: needs review label Jan 21, 2014
@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 21, 2014

comment:2

This is the kind of patches that breaks code everywhere in Sage. We better wait for the patchbot to say it passes tests before getting it in.

Nathann

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 21, 2014

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

ce049batrac 15704: Stupid waste of time in graphs 1

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 21, 2014

Commit: ce049ba

@kcrisman
Copy link
Member

comment:4

I think you should have something documenting what happens with the old "bad" behavior. I assume it raises a well-formed error that tells people exactly what to do?

Also, it's not clear from the diff whether there are now no examples of adding edges with 2-tuples, which I assume is still supported.

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 22, 2014

comment:5

Yo !

I think you should have something documenting what happens with the old "bad" behavior. I assume it raises a well-formed error that tells people exactly what to do?

Well, it raises the same error as u,v=1. To be honest I was afraid of adding a try/catch around the loop for the exception is a ValueError, and I don't it to catch a ValueError in _backend.add_edge if there is one.

sage: g = Graph()                
sage: g.add_edges([(0,1),(0,1,1)])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-edffa551e119> in <module>()
----> 1 g.add_edges([(Integer(0),Integer(1)),(Integer(0),Integer(1),Integer(1))])

/home/ncohen/.Sage/local/lib/python2.7/site-packages/sage/graphs/generic_graph.pyc in add_edges(self, edges)
   8970         else:
   8971             self._backend.add_edge(e0[0], e0[1], None, self._directed)
-> 8972             for u,v in it:
   8973                 self._backend.add_edge(u, v, None, self._directed)
   8974 

ValueError: too many values to unpack

I hope it will be explicit enough for the users, and that they will notice they feed the loop with heterogeneous data.

As for testing add_edges() with only pairs, not only it is still supported but I think most calls to this function only feed pairs :-P

I added a commit.

Nathann

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 22, 2014

Changed branch from u/ncohen/15604 to u/ncohen/15704

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 22, 2014

Changed commit from ce049ba to none

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2014

Commit: 037c189

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2014

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

ce049batrac 15704: Stupid waste of time in graphs 1
037c189trac #15704: Adding a doctest

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 22, 2014

comment:8

A commit to haul what we sow.

Nathann

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2014

Changed commit from 037c189 to 4056325

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2014

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

4056325Heeeeeeeeeeeeeeeeee

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 22, 2014

comment:10

OOps. Perhaps I should change the commit message :-PPPP

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2014

Changed commit from 4056325 to 499e287

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2014

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

ce049batrac 15704: Stupid waste of time in graphs 1
037c189trac #15704: Adding a doctest
499e287trac #15704: Changing add_edge to _backend.add_edge in the (Di)Graph constructor

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@videlec
Copy link
Contributor

videlec commented Apr 22, 2014

comment:13

Hi Nathann,

my branch: u/vdelecroix/15704

I simplified the add_edges. That way we can use the old syntax and is not much slower (as calling len is very cheap). What do you think?

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Apr 23, 2014

comment:14

Can you provide timings for this change ? If it is not that bad it is good to have indeed.

Nathann

@videlec
Copy link
Contributor

videlec commented Apr 23, 2014

comment:15

Replying to @nathanncohen:

Can you provide timings for this change ? If it is not that bad it is good to have indeed.

Here they are. Your version

sage: g = graphs.RandomGNP(1500,.4)
sage: edges = g.edges(labels=False)
sage: h = Graph()
sage: %time h.add_edges(edges)
CPU times: user 2.21 s, sys: 32 ms, total: 2.24 s
Wall time: 2.23 s

mine

sage: g = graphs.RandomGNP(1500,.4)
sage: edges = g.edges(labels=False)
sage: h = Graph()
sage: %time h.add_edges(edges)
CPU times: user 2.48 s, sys: 32 ms, total: 2.51 s
Wall time: 2.51 s

(Be careful the branch is not yet merged with 6.2.rc0 and sage -b is horribly long)

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Apr 23, 2014

comment:16

Hmmm.... 10%... I'd vote for the first version. What do you think ? Yours handles more case, but it would mean that input is a bit messy ?...

Nathann

@videlec
Copy link
Contributor

videlec commented Apr 23, 2014

comment:17

Replying to @nathanncohen:

Hmmm.... 10%... I'd vote for the first version. What do you think ? Yours handles more case, but it would mean that input is a bit messy ?...

    • 10% is a lot
    • the messy input was in the documentation before you removed it

The main question: is this function critical? Is there any piece of code that uses it intensively?

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Apr 23, 2014

comment:18

Well, I began to write those patches because Jernej was not able to build a Graph with Sage .... I do not think that it really is the bottleneck in any code, but if the error message is clear, I don't think anybody can really complain that Sage refuses inputs like G.add_edges([(0,1,'l'), (0,1)]).

So well. I'd go for the most efficient way to do it, given that I do not see this being a real problem for anybody.... I don't like to know that everybody loses 10% to prevent several users from cleaning their input a bit :-P

Nathann

@videlec
Copy link
Contributor

videlec commented Apr 23, 2014

comment:19

Then leeeeet's go!

Vincent

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Apr 23, 2014

comment:20

Thaaaaaanks !

Nathann

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@vbraun
Copy link
Member

vbraun commented May 7, 2014

comment:22

Reviewer name

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented May 7, 2014

Reviewer: Vincent Delecroix

@vbraun
Copy link
Member

vbraun commented May 8, 2014

comment:24

doctest failures after merge

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented May 8, 2014

comment:25

turns out some combinat code was feeding the function with non-uniform input.

Testing the whole Sage code... It would be cool if I could set up a patchbot on my office's computer, really :-/

Nathann

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 8, 2014

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

f66f5f2Merge branch 'u/ncohen/15704' of trac.sagemath.org:sage into tmp
297b1b3trac #15704: Broken doctests

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 8, 2014

Changed commit from 499e287 to 297b1b3

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented May 8, 2014

comment:27

Passes all long tests.

@vbraun
Copy link
Member

vbraun commented May 12, 2014

Changed branch from u/ncohen/15704 to 297b1b3

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