Ask Your Question
3

gap calls seem to consume a lot of time

asked 2011-04-02 06:30:45 -0500

parzan gravatar image

updated 2011-06-21 03:45:56 -0500

I am trying to migrate some code from GAP to sage, and the overhead for calls to GAP procedures is enormous. Here is an example:

----------------------------------------------------------------------
| Sage Version 4.6.2, Release Date: 2011-02-25                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: def test1():
....:     for x in xrange(100): gap.eval('G:=Group([(1,2,3)])')
....:     
sage: def test2():
....:     gap.eval('for x in [1..100] do G:=Group([(1,2,3)]);od')
....:     
sage: timeit('test1()')
5 loops, best of 3: 810 ms per loop
sage: timeit('test2()')
25 loops, best of 3: 12.6 ms per loop

Is there anything I am doing wrong?

I tried some profiling, which indicated that most of the time is consumed by "select.select".

Any help will be most welcome.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2011-04-02 07:24:39 -0500

DSM gravatar image

Yep, the gap interface is pretty slow, due to the I/O approach (hence the time in select.select). Fortunately for lots of use cases this isn't the bottleneck, but in some cases it can be, more's the pity. Work on a faster Cythonic interface is progressing -- see http://trac.sagemath.org/sage_trac/ti... -- but it's not quite there yet.

Instead of calling a gap function explicitly to build a permutation group, it's more idiomatic Sage to write

G = PermutationGroup([(1,2,3)])

which can be a little faster (~2x, maybe). Underlying problem is still there, though.

edit flag offensive delete link more

Comments

Thanks for replying! Actually, the code I gave was just for example. The functions I'm interested in are within a GAP package called FGA (free group algorithms), and I don't think there is any parallel in sage (but I'll be glad to be corrected). In any case, the libGAP link gives me something to wait for!

parzan gravatar imageparzan ( 2011-04-02 11:49:54 -0500 )edit

libGAP is feature-complete. You are more than welcome to test the current version and help review it.

Volker gravatar imageVolker ( 2011-04-03 13:51:44 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-04-02 06:30:45 -0500

Seen: 195 times

Last updated: Apr 02 '11