Opened 9 years ago

Closed 9 years ago

#10571 closed enhancement (fixed)

print protocol of Groebner basis computations via Singular and Magma

Reported by: malb Owned by: was
Priority: major Milestone: sage-4.6.2
Component: interfaces Keywords: magma, singular
Cc: wjp Merged in: sage-4.6.2.alpha4
Authors: Martin Albrecht Reviewers: Marshall Hampton
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by malb)

It would be nice if this would work:

sage: P.<x,y,z> = GF(32003)[]
sage: I = sage.rings.ideal.Katsura(P)
sage: _ = I.groebner_basis('magma', prot=True)
Homogeneous weights search
Number of variables: 3, nullity: 0
Exact search time: 0.000
Found best approx weight vector: [1 1 1]
Norm: 3, count: 1
Approx search time: 0.000
********************
FAUGERE F4 ALGORITHM
********************
Coefficient ring: GF(32003)
Rank: 3
Order: Graded Reverse Lexicographical
NEW hash table
Matrix kind: Modular FP
Datum size: 4
No queue sort
Initial length: 3
Inhomogeneous

Initial queue setup time: 0.000
Initial queue length: 2

*******
STEP 1
Basis length: 3, queue length: 2, step degree: 2, num pairs: 2
Basis total mons: 11, average length: 3.667
Number of pair polynomials: 2, at 8 column(s), 0.000
Average length for reductees: 3.50 [2], reductors: 4.00 [4]
Symbolic reduction time: 0.000, column sort time: 0.000
2 + 4 = 6 rows / 10 columns, 38.333% / 52.487% (3.8333/r)
Before ech memory: 7.8MB
Row sort time: 0.000
0.000 + 0.000 = 0.000 [2]
Delete 1 memory chunk(s); time: 0.000
Number of unused reductors: 1
After ech memory: 7.8MB
Queue insertion time: 0.000
Step 1 time: 0.000, [0.000], mat/total: 0.000/0.000 [0.000], mem: 7.8MB

*******
STEP 2
Basis length: 5, queue length: 1, step degree: 3, num pairs: 1
Basis total mons: 19, average length: 3.800
Number of pair polynomials: 1, at 6 column(s), 0.000
Average length for reductees: 4.00 [1], reductors: 4.00 [4]
Symbolic reduction time: 0.000, column sort time: 0.000
1 + 4 = 5 rows / 8 columns, 50% / 67.429% (4/r)
Before ech memory: 7.8MB
Row sort time: 0.000
0.000 + 0.000 = 0.000 [1]
Delete 1 memory chunk(s); time: 0.000
After ech memory: 7.8MB
Queue insertion time: 0.000
Step 2 time: 0.000, [0.001], mat/total: 0.000/0.000 [0.001], mem: 7.8MB

*******
STEP 3
Basis length: 6, queue length: 1, step degree: 4, num pairs: 1
Basis total mons: 23, average length: 3.833
Number of pair polynomials: 1, at 6 column(s), 0.000
Average length for reductees: 4.00 [1], reductors: 4.00 [6]
Symbolic reduction time: 0.000, column sort time: 0.000
1 + 6 = 7 rows / 9 columns, 44.444% / 63.243% (4/r)
Before ech memory: 7.8MB
Row sort time: 0.000
0.000 + 0.000 = 0.000 [0]
Delete 1 memory chunk(s); time: 0.000
After ech memory: 7.8MB
Queue insertion time: 0.000
Step 3 time: 0.000, [0.000], mat/total: 0.000/0.000 [0.001], mem: 7.8MB

Reduce 6 final polynomial(s) by 6
2 redundant polynomial(s) removed; time: 0.000
Interreduce 4 (out of 6) polynomial(s)
Symbolic reduction time: 0.000
Column sort time: 0.000
4 + 0 = 4 rows / 8 columns, 50% / 68.452% (4/r)
Row sort time: 0.000
0.000 + 0.000 = 0.000 [4]
Delete 1 memory chunk(s); time: 0.000
Total reduction time: 0.000
Reduction time: 0.000
Final number of polynomials: 4

Number of pairs: 4
Total pair setup time: 0.000
Max num entries matrix: 7 by 9
Max num rows matrix: 7 by 9
Total symbolic reduction time: 0.000
Total column sort time: 0.000
Total row sort time: 0.000
Total matrix time: 0.000
Total new polys time: 0.000
Total queue update time: 0.000
Total Faugere F4 time: 0.000, real time: 0.001

It would also be nice if the protocol is printed live, i.e. whenever Magma prints a new line it is immediately displayed by Sage.

Attachments (1)

trac_10571.patch (36.8 KB) - added by malb 9 years ago.

Download all attachments as: .zip

Change History (20)

comment:1 Changed 9 years ago by malb

  • Description modified (diff)
  • Status changed from new to needs_review

comment:2 Changed 9 years ago by malb

With the attached patch, here's how Magma's output looks like:

sage: P.<x,y> = GF(32003)[]
sage: I = sage.rings.ideal.Katsura(P)
sage: _ = I.groebner_basis('magma', prot=True)
Append(~_sage_, 0);
Append(~_sage_, 0);
>>>_sage_[7]:=_sage_[8];
_sage_[7]:=_sage_[8];
>>>Append(~_sage_, 0);
Append(~_sage_, 0);
>>>_sage_[6]:=GroebnerBasis(_sage_[7]);
_sage_[6]:=GroebnerBasis(_sage_[7]);
Homogeneous weights search
Number of variables: 2, nullity: 0
Exact search time: 0.000
Found best approx weight vector: [1 1]
Norm: 2, count: 1
Approx search time: 0.000
********************
FAUGERE F4 ALGORITHM
********************
Coefficient ring: GF(32003)
Rank: 2
Order: Graded Reverse Lexicographical
NEW hash table
Matrix kind: Modular FP
Datum size: 4
No queue sort
Initial length: 2
Inhomogeneous

Initial queue setup time: 0.000
Initial queue length: 1

*******
STEP 1
Basis length: 2, queue length: 1, step degree: 2, num pairs: 1
Basis total mons: 6, average length: 3.000
Number of pair polynomials: 1, at 4 column(s), 0.000
Average length for reductees: 3.00 [1], reductors: 3.00 [3]
Symbolic reduction time: 0.000, column sort time: 0.000
1 + 3 = 4 rows / 6 columns, 50% / 65% (3/r)
Before ech memory: 7.8MB
Row sort time: 0.000
0.000 + 0.000 = 0.000 [1]
Delete 1 memory chunk(s); time: 0.000
Number of unused reductors: 1
After ech memory: 7.8MB
Queue insertion time: 0.000
Step 1 time: 0.000, [0.000], mat/total: 0.000/0.000 [0.000], mem: 7.8MB

Reduce 3 final polynomial(s) by 3
1 redundant polynomial(s) removed; time: 0.000
Interreduce 2 (out of 3) polynomial(s)
Symbolic reduction time: 0.000
Column sort time: 0.000
2 + 0 = 2 rows / 4 columns, 62.5% / 75% (2.5/r)
Row sort time: 0.000
0.000 + 0.000 = 0.000 [2]
Delete 1 memory chunk(s); time: 0.000
Total reduction time: 0.000
Reduction time: 0.000
Final number of polynomials: 2

Number of pairs: 1
Total pair setup time: 0.000
Max num entries matrix: 4 by 6
Max num rows matrix: 4 by 6
Total symbolic reduction time: 0.000
Total column sort time: 0.000
Total row sort time: 0.000
Total matrix time: 0.000
Total new polys time: 0.000
Total queue update time: 0.000
Total Faugere F4 time: 0.000, real time: 0.000
>>>_sage_[7]:=0;
_sage_[7]:=0;
>>>

And Singular via pexpect (libsingular worked already):

sage: _ = I.groebner_basis('singular', prot=True)
1+1995986538;
1995986539
> def sage25=groebner(sage22);
def sage25=groebner(sage22);
std in (32003),(x,y),(dp(2),C)
[4294967295:2]1s2s
(S:1)-
product criterion:1 chain criterion:0
> 

There's some crap surrounding the log, but this is already a big step up. Note that the update is also live. If we want we can write filter for Singular and Magma such that only the wanted lines are actually printed, but I think this should be left for another ticket. The attached patch also implements this:

sage: from sage.interfaces.expect import StdOutContext
sage: with StdOutContext(gp):
....:     gp('1+1')
....:     
sage=vector(1024,k,0);
sage=vector(1024,k,0);
? sage[1]=1+1;
sage[1]=1+1;
? print(sage[1])
print(sage[1])
2
? 2

which might be useful on its own.

comment:3 Changed 9 years ago by malb

The updated patch provides the following functionality:

Pretty printing for Singular logs

sage: P.<x,y> = GF(32003)[]
sage: I = sage.rings.ideal.Katsura(P)
sage: _ = I.groebner_basis('magma', prot="sage")
_ = I.groebner_basis('singular', prot="sage")
Leading term degree:  1.
Leading term degree:  2.

Highest degree reached during computation:  2.

And degree bounds for Magma:

sage: P.<x,y,z,a,b,c,w> = GF(32003)[]
sage: I = sage.rings.ideal.Cyclic(P)
sage: gbM = I.groebner_basis('magma', deg_bound=3)
sage: gbM
[y*z^2 - y*z*a + z^2*a + z*b*c - a*b*c - z^2*w - z*b*w + a*b*w + y*c*w + z*c*w + a*c*w + b*c*w + c^2*w - y*w^2 - 2*z*w^2 - a*w^2 - b*w^2 + c*w^2 - w^3, y^2 + y*a - z*a + y*b - a*b + y*c - b*c + 2*y*w + z*w + a*w + b*w + w^2, x + y + z + a + b + c + w]

comment:4 Changed 9 years ago by malb

This ticket depends on #1396.

comment:5 Changed 9 years ago by malb

Fixed parsing of 'std' logs.

comment:6 Changed 9 years ago by malb

  • the patch depends on #9599
  • the updated patch also parses Magma output.

comment:7 Changed 9 years ago by malb

Turns out 'slimgb' might print insufficient information for prot='sage' to work, so we throw a warning in that case. cf. http://groups.google.com/group/libsingular-devel/browse_thread/thread/a05725bc1312531c

comment:8 Changed 9 years ago by mhampton

  • Reviewers set to Marshall Hampton,
  • Status changed from needs_review to positive_review

wjp helped test this for magma and because of output changes, some doctests fail. Since that's beyond our control to some extent I am not too worried about it.

I tested everything in sage/rings and all standard doctests passed.

This is very helpful for exploring what algorithm to use, excellent addition.

comment:9 Changed 9 years ago by malb

Which Magma version is that? I could try to accommodate both versions? Perhaps in a different patch.

comment:10 Changed 9 years ago by mhampton

  • Cc wjp added

2.13-9

comment:11 Changed 9 years ago by malb

This is now #10631, or do you want this to be in the current patch?

comment:12 Changed 9 years ago by jdemeyer

  • Reviewers changed from Marshall Hampton, to Marshall Hampton
  • Status changed from positive_review to needs_work

All doctests involving magma should be marked

# optional - magma

comment:13 follow-up: Changed 9 years ago by malb

Okay, sorry for the oversight. Do I just change it back to positive review?

comment:14 in reply to: ↑ 13 Changed 9 years ago by jdemeyer

Replying to malb:

Okay, sorry for the oversight. Do I just change it back to positive review?

I will test it and if tests succeed, I will put back the positive review.

comment:15 Changed 9 years ago by jdemeyer

File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.6.2.alpha4/devel/sage-main/sage/interfaces/magma.py", line 2753:
    sage: _ = I.groebner_basis('magma',prot=True) indirect doctest, optional - magma
Exception raised:
    Traceback (most recent call last):
      File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.6.2.alpha4/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.6.2.alpha4/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.6.2.alpha4/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_81[4]>", line 1
         _ = I.groebner_basis('magma',prot=True) indirect doctest, optional - magma###line 2753:
    sage: _ = I.groebner_basis('magma',prot=True) indirect doctest, optional - magma
                                                        ^
     SyntaxError: invalid syntax

Changed 9 years ago by malb

comment:16 Changed 9 years ago by malb

That was because I'm an idiot. Fixed now.

comment:17 Changed 9 years ago by jdemeyer

  • Status changed from needs_work to needs_review

Doing a test again...

comment:18 Changed 9 years ago by jdemeyer

  • Status changed from needs_review to positive_review

comment:19 Changed 9 years ago by jdemeyer

  • Merged in set to sage-4.6.2.alpha4
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.