sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.22k stars 424 forks source link

Singular functions via libSingular #6628

Closed malb closed 14 years ago

malb commented 15 years ago

The attached patch implements the following:

sage: P = PolynomialRing(GF(127),10,'x')
sage: I = Ideal(P.random_element() for _ in range(3000))
sage: from sage.libs.singular.function import singular_function, lib
sage: groebner = singular_function('groebner')
sage: %time groebner(I)
CPU times: user 0.07 s, sys: 0.00 s, total: 0.08 s
Wall time: 0.08 s
[1]

For comparison, the Singular pexpect interface needs almost two seconds for the same task (due to string parsing on both ends, IPC, etc.)

sage: %time I.groebner_basis()
CPU times: user 0.96 s, sys: 0.24 s, total: 1.21 s
Wall time: 1.92 s
[1]

This patch requires an updated Singular SPKG (see below).

CC: @burcin

Component: commutative algebra

Keywords: singular, libsingular, commutative algebra

Author: Michael Brickenstein, Martin Albrecht

Reviewer: Alex Ghitza

Merged: Sage 4.1.2.alpha0

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

malb commented 15 years ago
comment:1
malb commented 15 years ago
comment:3

Burcin, I just replaced the patch to fix a doctest failure.

malb commented 15 years ago
comment:4

Btw. this also works now:

sage: from sage.libs.singular.function import singular_function, lib
sage: groebner = singular_function('groebner')
sage: groebner?
Type:           SingularLibraryFunction
Base Class:     <type 'sage.libs.singular.function.SingularLibraryFunction'>
String Form:    groebner (singular function)
Namespace:      Interactive
File:           /usr/local/sage-4.1/local/lib/python2.6/site-packages/sage/libs/singular/function.so
Docstring:

    groebner
    --------

    Procedure from library `standard.lib' (*note standard_lib::).

    *Syntax:*
         `groebner (' ideal_expression `)'
         `groebner (' module_expression `)'
         `groebner (' ideal_expression`,' int_expression `)'
         `groebner (' module_expression`,' int_expression `)'
...
1998e663-c3b5-4cf6-92c3-7f1771ca5185 commented 15 years ago
comment:5

Hi! It looks very promosing. However, I have difficulties to apply the patch. Using sage-4.1.0 and the updated singular spkg:

I tried it with and without the refactoring patch, also using a fresh installation:

sage -hg import ~/Downloads/libsingular_functions.patch 
applying /Users/michael/Downloads/libsingular_functions.patch
patching file module_list.py
Hunk #1 FAILED at 441
1 out of 1 hunks FAILED -- saving rejects to file module_list.py.rej
unable to find 'sage/libs/singular/polynomial.pyx' for patching
1 out of 1 hunks FAILED -- saving rejects to file sage/libs/singular/polynomial.pyx.rej
patching file sage/libs/singular/singular-cdefs.pxi
Hunk #3 FAILED at 207
Hunk #4 succeeded at 215 with fuzz 2 (offset -43 lines).
Hunk #7 FAILED at 853
2 out of 7 hunks FAILED -- saving rejects to file sage/libs/singular/singular-cdefs.pxi.rej
patching file sage/libs/singular/singular.pxd
Hunk #1 FAILED at 0
Hunk #2 FAILED at 26
2 out of 2 hunks FAILED -- saving rejects to file sage/libs/singular/singular.pxd.rej
patching file sage/libs/singular/singular.pyx
Hunk #1 FAILED at 24
Hunk #2 succeeded at 514 with fuzz 2 (offset -15 lines).
Hunk #3 FAILED at 593
2 out of 3 hunks FAILED -- saving rejects to file sage/libs/singular/singular.pyx.rej
patching file sage/rings/polynomial/multi_polynomial_libsingular.pyx
Hunk #1 FAILED at 1906
Hunk #2 FAILED at 2019
2 out of 2 hunks FAILED -- saving rejects to file sage/rings/polynomial/multi_polynomial_libsingular.pyx.rej

Michael

malb commented 15 years ago
comment:6

Hi Michael, this is strange, here is what works for me

I have no failed hunks etc. with that.

1998e663-c3b5-4cf6-92c3-7f1771ca5185 commented 15 years ago
comment:7

I am happy with the refactoring of my code :-). I played with it and I like it. From the Singular side, this nontrivial patch looks fine.

1998e663-c3b5-4cf6-92c3-7f1771ca5185 commented 15 years ago
comment:8

Here some different timings with even better factor: opposite kind of example: very tiny input, output and almost nothing to compute, replaces some singular interpreter call via pexpect with libsingular kernel function call

from sage.libs.singular import function as sf
intersect=sf.SingularKernelFunction("intersect")
sage: P.<x,y,z>=QQ[]
sage: j=P.ideal(x,z)
sage: i=P.ideal(x,y)
sage: timeit("z=i.intersection(j)")
125 loops, best of 3: 5.12 ms per loop
sage: timeit("z=intersect(i,j)")
625 loops, best of 3: 60.9 µs per loop
malb commented 14 years ago
comment:9

It seems this patch makes docbuild choke because

groebner
--------

is contained in one docstring.

malb commented 14 years ago
comment:10

fixed in updated patch.

malb commented 14 years ago
comment:11

On IRC:

[13:02] <mvngu> malb: The package singular-3-1-0-4-20090723.spkg compiles OK on t2!
malb commented 14 years ago

Attachment: libsingular_functions.patch.gz

fixing docstring issue

aghitza commented 14 years ago

Attachment: trac_6628-referee.patch.gz

apply after the previous patch

aghitza commented 14 years ago
comment:12

This stuff is great! I've attached a small referee patch that fixes some very minor typos.

I will note that line 280 of singular-cdefs.pxi is not entirely confidence-inspiring, but I believe the best way to test and refine this stuff is to get it into Sage and start using it a lot.

Note to the release manager: as pointed out above, one must first merge the new Singular spkg, and the patch(es) at #6596.

aghitza commented 14 years ago

Reviewer: Alex Ghitza

malb commented 14 years ago
comment:13

The referee patch looks good. I think the next step would be to port stuff in multi_polynomial_ideal.py to use this new stuff and see what happens.

aghitza commented 14 years ago
comment:14

Replying to @malb:

The referee patch looks good. I think the next step would be to port stuff in multi_polynomial_ideal.py to use this new stuff and see what happens.

Indeed. I'm expecting awesomeness (more Singular functionality readily exposed in Sage), speed, and the occasional bug fix.

I'll try to have a look at #6596 soon, but it's a bit bigger, and it will probably take a few days.

1998e663-c3b5-4cf6-92c3-7f1771ca5185 commented 14 years ago
comment:15

regarding 280: I was a little bit confused, as I thought it would be the same type in idrec and sleftv. But it's indeed void* in sleftv, so the code is correct, but the comment is wrong. Nothing dangerous, you can remove the warning. Michael

7c09a680-e216-4024-bb8e-9bfd4aa7f313 commented 14 years ago

Merged: Sage 4.1.2.alpha0

7c09a680-e216-4024-bb8e-9bfd4aa7f313 commented 14 years ago
comment:16

Merged both patches.