sagemath / sage

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

make doctests compatible with Macaulay2 1.17 #31773

Closed mwageringel closed 3 years ago

mwageringel commented 3 years ago

With Macaulay2 1.17, some doctests fail due to slight changes in the print representation.

Component: interfaces

Keywords: macaulay2

Author: Markus Wageringel

Branch: 919907a

Reviewer: Samuel Lelièvre

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

mwageringel commented 3 years ago

Commit: 919907a

mwageringel commented 3 years ago

Author: Markus Wageringel

mwageringel commented 3 years ago
comment:1

This should be compatible with older versions as well.


New commits:

919907a31773: make doctests compatible with Macaulay2 1.17
mwageringel commented 3 years ago

Branch: u/gh-mwageringel/31773

sheerluck commented 3 years ago
comment:2

I tried Macaulay2, version 1.17.2.1, from master branch.

Every [x...z] in 1.17 changed to [x..z] in 1.17.2.1

Example:

sage: str(macaulay2("QQ[x,y,z]/(x+y+z)"))
 QQ[x..z]
---------
x + y + z

sage: R.<x,y,z,w> = PolynomialRing(ZZ, 4)
sage: I = R.ideal([x*y-z^2, y^2-w^2])
sage: Q = R.quotient(I)
sage: Q._macaulay2_init_()
    ZZ[x..z, w]
-------------------
        2   2    2
(x*y - z , y  - w )
mwageringel commented 3 years ago
comment:3

Replying to @sheerluck:

I tried Macaulay2, version 1.17.2.1, from master branch.

Every [x...z] in 1.17 changed to [x..z] in 1.17.2.1

Yes, it is [x..z] on my end, too. I have used triple dots ... because they are interpreted as a generic placeholder by our doctesting framework. This way, the tests also pass with older versions of Macaulay2, as [x...z] also matches [x, y, z].

You can try to run the tests on the few files that contain Macaulay2 doctests like this:

./sage -t -l --optional=sage,macaulay2 $(git grep -l -i "optional.*macaulay2" | paste -sd " " -)
mwageringel commented 3 years ago

Changed keywords from none to macaulay2

slel commented 3 years ago

Reviewer: Samuel Lelièvre

slel commented 3 years ago
comment:4

Good.

By the way do you know how to use the M2 interface in Jupyter? Someone is asking at

sheerluck commented 3 years ago
comment:5

Replying to @slel:

By the way do you know how to use the M2 interface in Jupyter?

test if M2 is found

In [1]: import shutil
         shutil.which("M2")
Out[1]:
'/home/sheerluck/M2/install/bin/M2'

if shutil.which returns empty string, we need to add PATH to kernel:

1) jupyter-kernelspec list shows where sagemath kernel is

$ jupyter-kernelspec list
Available kernels:
...
sagemath          /usr/share/jupyter/kernels/sagemath

2) go there, open kernel.json, and after "language": "sage" add "env":

{
  ...
  "language": "sage",
  "env": {"PATH":"/home/sheerluck/M2/install/bin:$PATH"} 
}
mkoeppe commented 3 years ago
comment:6

Promoting 5 tickets that fix defects to "major" so that they have a chance to get merged

vbraun commented 3 years ago

Changed branch from u/gh-mwageringel/31773 to 919907a

aade5b53-bba9-4258-af2e-60701015159f commented 2 years ago

Changed commit from 919907a to none

aade5b53-bba9-4258-af2e-60701015159f commented 2 years ago
comment:8

Reply to gh-sheerluck: such addition to kernel.json to include paths to octave and Macaulay2's M2 does not allow me to use either octave or the macaulay2 from a jupyter notebook opened from SageMath-9.6 arm64 version under macOS 12.5.1 on an M1 Mac. What's wrong?

sheerluck commented 2 years ago
comment:9

Replying to @murrayE:

What's wrong?

we need to check several things

1) that M2 and octave work with full paths. If on some system M2 is installed in /opt/M2 and octave is installed in /opt/octave we need to check that /opt/M2/bin/M2 works and /opt/octave/bin/octave-cli works. M2 can fail to run with "/usr/lib64/libfactory-4.3.0.so not found" if singular was recently updated to 4.3.1

2) that before "env": {"PATH":"/opt/M2/bin/:/opt/octave/bin/:$PATH"} line there is a comma after "language": "sage":

 "display_name": "SageMath 9.7.beta8",
 "language": "sage",
 "env": {"PATH":"/opt/M2/bin/:/opt/octave/bin/:$PATH"}

3) that both paths are separated with colon: "PATH":"/opt/M2/bin/:/opt/octave/bin/:$PATH"

4) that sage -n jupyter starts without errors

5) that "display_name" from 2) is what we see in jupyter

6) that we get '/opt/M2/bin/M2' after

import shutil
shutil.which("M2")

7) that we get '/opt/octave/bin/octave-cli' after

import shutil
shutil.which("octave-cli")

If all that is checked, jupyter has to give us something like

In [1]: macaulay2("2+2")

Out[1]: 4

In [2]: octave.eval('2+2')

Out[2]: 'ans = 4'