-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
Can't interrupt cleanly RecursivelyEnumeratedSet.graded_component #21312
Comments
This comment has been minimized.
This comment has been minimized.
comment:2
Maybe using https://github.com/sagemath/cysignals/blob/master/docs/source/index.rst#using-sig_check |
comment:3
It goes down to sage: def f(a):
....: sleep(0.05)
....: return [a-1,a+1]
sage: C = RecursivelyEnumeratedSet([0], f, structure='symmetric')
sage: it = C.graded_component_iterator()
sage: next(it)
{0}
sage: next(it)
{-1, 1}
sage: next(it)
{-2, 2}
sage: next(it)
{-3, 3}
sage: from cysignals.alarm import alarm
sage: alarm(0.02); next(it)
Traceback (most recent call last):
...
AlarmInterrupt:
sage: next(it)
Traceback (most recent call last):
...
StopIteration: |
comment:4
In essence this seems to be the same issue I came with in sage-devel: |
comment:5
I think I have an idea. We simply need to get rid of the |
New commits:
|
Commit: |
Branch: u/slabbe/21312 |
comment:7
Thanks for this fix; at first glance it looks ok to me, I will try to give it a more in-depth review soon. On a related topic: in my usual testing example I get a major slowdown replacing my custom made iterator with a Another thing: maybe |
comment:8
Great. Also, I created #21311 just this morning while looking at the code on github if you can have a look at it.
If you can provide a working example illustrating this, I will be curious in investigating it.
Great! Tell me you think it works. |
comment:9
To get the example I am thinking about you need to merge in #21254 and #19538.
and
(you need to recreate The speedup I get, I think, depend mostly on line 1961 and partly on line 1968 |
comment:10
In my experience, this kind of thing can be done by adding information into the nodes:
Then But I can't say if such an approach could work in your case. |
comment:11
The speedup seems to be very close to a factor of 2.
I would guess this is not a coincidence... I still do not see how lines 1961 or 1968 give a improvement by a factor of 2 ? |
comment:12
Can you try with my code but with line 1961 commented out and j!= i instead of j>i in line 1968? |
comment:13
Commenting out line 1961 and changing line 1968 as you suggest makes sage: from pandas import DataFrame
sage: df = DataFrame(index="E6 E7 E8".split())
sage: df['explore_to_depth'] = [2.53, 15.8, 124.]
sage: df['rec_enum_set'] = [2.91, 18.5, 141.]
sage: df['ratio'] = df.rec_enum_set / df.explore_to_depth
sage: df
explore_to_depth rec_enum_set ratio
E6 2.53000000000000 2.91000000000000 1.15019762845850
E7 15.8000000000000 18.5000000000000 1.17088607594937
E8 124.000000000000 141.000000000000 1.13709677419355 Are there other hypothesis you are using on the structure of the graph? |
comment:14
I do not think I am using any other assumption. Note that the main loop I would write without using the assumptions above would be
which should be slightly faster than the version you tested because it does not
|
comment:15
Ah! I am not sure how |
comment:16
I had already commented that line in my previous post, also since commenting only line 1961 gives a syntax error. The only difference with your suggestion was that I was using new_directions = [ j for j in allowed_dirs if j != i or new_sd.b_matrix()[j,i] != 0 ] instead of new_directions = [ j for j in allowed_dirs if j != i ] Replying to @Etn40ff:
An hypothesis that we can't do right now inside the code of list(succ(x)).index(y) == list(succ(y)).index(x) Also, the graph might not be k-regular (to make sure, that is the number of outgoing edges being constant). But we can use that hypothesis in the sage: A = ClusterAlgebra(['E',6])
sage: def succ(S):
....: p = S.path_from_initial_seed()
....: i = p[-1] if p else -1
....: return [S.mutate(j,inplace=False) for j in range(6) if j != i]
sage: seeds = RecursivelyEnumeratedSet([A.initial_seed()], succ, structure='symmetric')
sage: %time len(list(seeds))
CPU times: user 2.69 s, sys: 200 ms, total: 2.89 s
Wall time: 2.75 s
833 With this new sage: from pandas import DataFrame
sage: df = DataFrame(index="E6 E7 E8".split())
sage: df['explore_to_depth'] = [2.61, 16.1, 121.]
sage: df['rec_enum_set'] = [2.75, 16.9, 128.]
sage: df['ratio'] = df.rec_enum_set / df.explore_to_depth
sage: df
explore_to_depth rec_enum_set ratio
E6 2.61000000000000 2.75000000000000 1.05363984674330
E7 16.1000000000000 16.9000000000000 1.04968944099379
E8 121.000000000000 128.000000000000 1.05785123966942 |
comment:17
ok 5% may depend on your code being more general or storing more info. I'd be happy to live with it. Now the problem is: how do I enforce the other two assumptions? PS: This ticket was meant to solve an issue and we are discussing something else. I guess we better leave this open till we are done. |
comment:18
Meanwhile, I was managed to use the second assumption (if I am not mistaken): sage: A = ClusterAlgebra(['E',8])
sage: allowed_dirs = range(8)
sage: def succ(S):
....: p = S.path_from_initial_seed()
....: if p:
....: i = p[-1]
....: L = []
....: for j in allowed_dirs:
....: new_sd = S.mutate(j, inplace=False)
....: if j > i or new_sd.b_matrix()[j,i] != 0:
....: L.append(new_sd)
....: return L
....: else:
....: return [S.mutate(j,inplace=False) for j in allowed_dirs]
sage: seeds = RecursivelyEnumeratedSet([A.initial_seed()], succ) # not symmetric anymore right? but I do not get any significant improvement compare to just avoid branches sage: %time len(list(seeds))
CPU times: user 2min 8s, sys: 605 ms, total: 2min 8s
Wall time: 2min 8s
25080 which is the same (128 s) as above. |
comment:19
Replying to @Etn40ff:
I don't know if we can make the first assumption cleanly into the function We should test if it works and if it is worth it, and if so, create a new ticket for it.
I agree. I wait for a review of this ticket then:) |
comment:20
I had a look at the code and it seems good to me. I am waiting for sage to finish building before running On the other topic discussed in the comments of this ticket: I ended up keeping the implementation I had in #21254 with a |
Author: Sébastien Labbé |
comment:21
No problem. |
comment:22
Positive review. It does make sense for code such as #21254 to use Two consideration about speed:
|
Reviewer: Salvatore Stella |
comment:23
I will keep your comment 1) in mind for future evolvement of RecEnumSet.
Well you can set To adapt the parallel map reduce code to work on graphs that are not forest, some communication should be added between workers. But then, it becomes less easy to get efficient parallel computations. That question should be asked to Florent: Could their be a common set of already known nodes that is shared among the workers so that they could know if they find a new node or not? |
comment:24
Nothing good: say your function is symmetric then it will continuously bounce in between two elements. If I am not mistaken |
comment:25
Replying to @Etn40ff:
map/reduce? The code we discussed could benefit much from this. It is essential. I'm planning to write some analogous code for directed Using the forest hypothesis, a work stealing algorithm allows the perform the |
Changed branch from u/slabbe/21312 to |
Changed commit from |
comment:27
Replying to @hivert:
That's a bummer! I am not sure DAGs would could be used in my case either. One stray thought: can you use hashes for communication rather than the whole objects? You could get some mileage from the fact that you will be pickling a smaller amount of data. |
From the Iterators and KeyboardInterrupt discussion on sage-devel, here is a reproducable bug:
CC: @hivert
Component: combinatorics
Author: Sébastien Labbé
Branch:
6634754
Reviewer: Salvatore Stella
Issue created by migration from https://trac.sagemath.org/ticket/21312
The text was updated successfully, but these errors were encountered: