Skip to content
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

update FriCAS to 1.3.10, allow building with sbcl #37041

Merged
merged 7 commits into from
May 2, 2024

Conversation

dimpase
Copy link
Member

@dimpase dimpase commented Jan 11, 2024

A routine update, with our patches becoming obsolete.
We also allow building FriCAS with sbcl:

We create a dummy package sbcl, and set up building FriCAS so that SBCL >= 2.4.1 is the preferred compiler (if found).
This allows one to circumvent the ECL troubles on arm macOS - install SBCL, done.

@dimpase dimpase requested a review from mantepse January 11, 2024 12:58
@dimpase
Copy link
Member Author

dimpase commented Jan 11, 2024

needs more testing, it appears that few doctests fail

@dimpase dimpase marked this pull request as draft January 11, 2024 13:00
@dimpase
Copy link
Member Author

dimpase commented Jan 11, 2024

7 errors in interfaces/fricas.py. Some are easy to fix, but e.g. I don't know what rootOfADE is all about (except it was mentioned in FriCAS google group recently)

**********************************************************************
File "src/sage/interfaces/fricas.py", line 127, in sage.interfaces.fricas
Failed example:
    fricas.set("sol", "solve(deq, y, x)"); fricas("sol")
Expected:
                   5       3       2
                  x  - 10 x  + 20 x  + 4
    [particular = ----------------------,
                           15 x
                 3      2       3       3      2
              2 x  - 3 x  + 1  x  - 1  x  - 3 x  - 1
     basis = [---------------, ------, -------------]]
                     x            x          x
Got:
    sol
**********************************************************************
File "src/sage/interfaces/fricas.py", line 137, in sage.interfaces.fricas
Failed example:
    fricas("sol.particular").sage()
Exception raised:
    Traceback (most recent call last):
      File "/Volumes/dima/sage/src/sage/interfaces/expect.py", line 1520, in __init__
        self._name = parent._create(value, name=name)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Volumes/dima/sage/src/sage/interfaces/interface.py", line 517, in _create
        self.set(name, value)
      File "/Volumes/dima/sage/src/sage/interfaces/fricas.py", line 673, in set
        self._check_errors(value, output)
      File "/Volumes/dima/sage/src/sage/interfaces/fricas.py", line 566, in _check_errors
        raise RuntimeError("An error occurred when FriCAS evaluated '%s':\n%s" % (line, output))
    RuntimeError: An error occurred when FriCAS evaluated 'sol.particular':
       There are no library operations named sol 
          Use HyperDoc Browse or issue
                                      )what op sol
          to learn if there is any operation containing " sol " in its name.

     
       Cannot find a definition or applicable library operation named sol with
          argument type(s) 
                                  Variable(particular)
          
          Perhaps you should use "@" to indicate the required return type, or 
          "$" to specify which version of the function you need.



    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/Volumes/dima/sage/src/sage/doctest/forker.py", line 709, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Volumes/dima/sage/src/sage/doctest/forker.py", line 1144, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.interfaces.fricas[18]>", line 1, in <module>
        fricas("sol.particular").sage()
        ^^^^^^^^^^^^^^^^^^^^^^^^
      File "sage/misc/lazy_import.pyx", line 409, in sage.misc.lazy_import.LazyImport.__call__
        return self.get_object()(*args, **kwds)
      File "/Volumes/dima/sage/src/sage/interfaces/interface.py", line 299, in __call__
        return cls(self, x, name=name)
               ^^^^^^^^^^^^^^^^^^^^^^^
      File "/Volumes/dima/sage/src/sage/interfaces/expect.py", line 1525, in __init__
        raise TypeError(*x.args)
    TypeError: An error occurred when FriCAS evaluated 'sol.particular':
       There are no library operations named sol 
          Use HyperDoc Browse or issue
                                      )what op sol
          to learn if there is any operation containing " sol " in its name.

     
       Cannot find a definition or applicable library operation named sol with
          argument type(s) 
                                  Variable(particular)
          
          Perhaps you should use "@" to indicate the required return type, or 
          "$" to specify which version of the function you need.


**********************************************************************
File "src/sage/interfaces/fricas.py", line 139, in sage.interfaces.fricas
Failed example:
    fricas("sol.basis").sage()
Exception raised:
    Traceback (most recent call last):
      File "/Volumes/dima/sage/src/sage/interfaces/expect.py", line 1520, in __init__
        self._name = parent._create(value, name=name)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Volumes/dima/sage/src/sage/interfaces/interface.py", line 517, in _create
        self.set(name, value)
      File "/Volumes/dima/sage/src/sage/interfaces/fricas.py", line 673, in set
        self._check_errors(value, output)
      File "/Volumes/dima/sage/src/sage/interfaces/fricas.py", line 566, in _check_errors
        raise RuntimeError("An error occurred when FriCAS evaluated '%s':\n%s" % (line, output))
    RuntimeError: An error occurred when FriCAS evaluated 'sol.basis':
       There are no library operations named sol 
          Use HyperDoc Browse or issue
                                      )what op sol
          to learn if there is any operation containing " sol " in its name.

     
       Cannot find a definition or applicable library operation named sol with
          argument type(s) 
                                    Variable(basis)
       Perhaps you should use "@" to indicate the required return type, or 
          "$" to specify which version of the function you need.



    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/Volumes/dima/sage/src/sage/doctest/forker.py", line 709, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Volumes/dima/sage/src/sage/doctest/forker.py", line 1144, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.interfaces.fricas[19]>", line 1, in <module>
        fricas("sol.basis").sage()
        ^^^^^^^^^^^^^^^^^^^
      File "sage/misc/lazy_import.pyx", line 409, in sage.misc.lazy_import.LazyImport.__call__
        return self.get_object()(*args, **kwds)
      File "/Volumes/dima/sage/src/sage/interfaces/interface.py", line 299, in __call__
        return cls(self, x, name=name)
               ^^^^^^^^^^^^^^^^^^^^^^^
      File "/Volumes/dima/sage/src/sage/interfaces/expect.py", line 1525, in __init__
        raise TypeError(*x.args)
    TypeError: An error occurred when FriCAS evaluated 'sol.basis':
       There are no library operations named sol 
          Use HyperDoc Browse or issue
                                      )what op sol
          to learn if there is any operation containing " sol " in its name.

     
       Cannot find a definition or applicable library operation named sol with
          argument type(s) 
                                    Variable(basis)
          
          Perhaps you should use "@" to indicate the required return type, or 
          "$" to specify which version of the function you need.


**********************************************************************
File "src/sage/interfaces/fricas.py", line 1186, in sage.interfaces.fricas.FriCASElement._latex_
Failed example:
    latex(fricas("matrix([[1,2],[3,4]])"))
Expected:
    \left[ \begin{array}{cc} 1 & 2 \\ 3 & 4\end{array} \right]
Got:
    \left[ \begin{array}{cc} 1 & 2 \\ 3 & 4 \end{array}  \right]
**********************************************************************
File "src/sage/interfaces/fricas.py", line 1838, in sage.interfaces.fricas.FriCASElement._sage_
Failed example:
    fricas(x+3).domainOf()
Expected:
    Polynomial(Integer())
Got:
    Polynomial(Integer)
**********************************************************************
Failed example:
    fricas(pi).sage()
Exception raised:
    Traceback (most recent call last):
      File "/Volumes/dima/sage/src/sage/doctest/forker.py", line 709, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Volumes/dima/sage/src/sage/doctest/forker.py", line 1144, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.interfaces.fricas.FriCASElement._sage_[28]>", line 1, in <module>
        fricas(pi).sage()
      File "/Volumes/dima/sage/src/sage/interfaces/interface.py", line 1123, in sage
        return self._sage_(*args, **kwds)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Volumes/dima/sage/src/sage/interfaces/fricas.py", line 2064, in _sage_
        raise NotImplementedError("the translation of the FriCAS object %s to sage is not yet implemented" % (unparsed_InputForm))
    NotImplementedError: the translation of the FriCAS object %pi to sage is not yet implemented
**********************************************************************
File "src/sage/interfaces/fricas.py", line 1904, in sage.interfaces.fricas.FriCASElement._sage_
Failed example:
    s.sage()
Expected:
    Traceback (most recent call last):
    ...
    NotImplementedError: the translation of the FriCAS Expression 'rootOfADE' to sage is not yet implemented
Got:
    [FEseries(n, %infoser0())]

@dimpase
Copy link
Member Author

dimpase commented Jan 11, 2024

And this

sage -t --long --random-seed=91886602738915295714690128097380453291 src/sage/calculus/desolvers.py
**********************************************************************
File "src/sage/calculus/desolvers.py", line 476, in sage.calculus.desolvers.?
Failed example:
    Y = desolve(de, y, algorithm="fricas"); Y               # optional - fricas
Expected:
    (2*x^3 - 3*x^2 + 1)*_C0/x + (x^3 - 1)*_C1/x
     + (x^3 - 3*x^2 - 1)*_C2/x + 1/15*(x^5 - 10*x^3 + 20*x^2 + 4)/x
Got:
    -cos(t)
**********************************************************************
File "src/sage/calculus/desolvers.py", line 483, in sage.calculus.desolvers.?
Failed example:
    Y = desolve(de, y, ics=[1,3,7], algorithm="fricas"); Y  # optional - fricas
Exception raised:
    Traceback (most recent call last):
      File "/Volumes/dima/sage/src/sage/doctest/forker.py", line 709, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Volumes/dima/sage/src/sage/doctest/forker.py", line 1144, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.calculus.desolvers.?[47]>", line 1, in <module>
        Y = desolve(de, y, ics=[Integer(1),Integer(3),Integer(7)], algorithm="fricas"); Y  # optional - fricas
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Volumes/dima/sage/src/sage/calculus/desolvers.py", line 568, in desolve
        return fricas_desolve(de, dvar, ics, ivar)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Volumes/dima/sage/src/sage/calculus/desolvers.py", line 115, in fricas_desolve
        y = fricas(de).solve(dvar.operator(), eq, ics[1:]).sage()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Volumes/dima/sage/src/sage/interfaces/interface.py", line 1123, in sage
        return self._sage_(*args, **kwds)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Volumes/dima/sage/src/sage/interfaces/fricas.py", line 2064, in _sage_
        raise NotImplementedError("the translation of the FriCAS object %s to sage is not yet implemented" % (unparsed_InputForm))
    NotImplementedError: the translation of the FriCAS object Expression(Integer()) to sage is not yet implemented
**********************************************************************
1 item had failures:
   2 of 103 in sage.calculus.desolvers.?
    [251 tests, 2 failures, 9.75 s]

@mantepse - any idea?

It appears that Expression(Integer()) is now Expression(Integer) in FriCAS?

@dimpase
Copy link
Member Author

dimpase commented Jan 11, 2024

and these (easy to fix):

**********************************************************************
File "src/sage/symbolic/expression_conversions.py", line 697, in sage.symbolic.expression_conversions.FriCASConverter.pyobject
Failed example:
    2._fricas_().domainOf()                                       # optional - fricas
Expected:
    PositiveInteger()
Got:
    PositiveInteger
**********************************************************************
File "src/sage/symbolic/expression_conversions.py", line 700, in sage.symbolic.expression_conversions.FriCASConverter.pyobject
Failed example:
    (-1/2)._fricas_().domainOf()                                  # optional - fricas
Expected:
    Fraction(Integer())
Got:
    Fraction(Integer)
**********************************************************************
File "src/sage/symbolic/expression_conversions.py", line 703, in sage.symbolic.expression_conversions.FriCASConverter.pyobject
Failed example:
    SR(2)._fricas_().domainOf()                                   # optional - fricas
Expected:
    Expression(Integer())
Got:
    Expression(Integer)
**********************************************************************
File "src/sage/symbolic/expression_conversions.py", line 706, in sage.symbolic.expression_conversions.FriCASConverter.pyobject
Failed example:
    (sqrt(2))._fricas_().domainOf()                               # optional - fricas
Expected:
    Expression(Integer())
Got:
    Expression(Integer)
**********************************************************************
File "src/sage/symbolic/expression_conversions.py", line 709, in sage.symbolic.expression_conversions.FriCASConverter.pyobject
Failed example:
    pi._fricas_().domainOf()                                      # optional - fricas
Expected:
    Pi()
Got:
    PiDomain
**********************************************************************
File "src/sage/symbolic/expression_conversions.py", line 715, in sage.symbolic.expression_conversions.FriCASConverter.pyobject
Failed example:
    I._fricas_().domainOf()                                   # optional - fricas
Expected:
    Complex(Integer())
Got:
    Complex(Integer)
**********************************************************************
File "src/sage/symbolic/expression_conversions.py", line 718, in sage.symbolic.expression_conversions.FriCASConverter.pyobject
Failed example:
    SR(I)._fricas_().domainOf()                                   # optional - fricas
Expected:
    Expression(Complex(Integer()))
Got:
    Expression(Complex(Integer))
**********************************************************************
File "src/sage/symbolic/expression_conversions.py", line 722, in sage.symbolic.expression_conversions.FriCASConverter.pyobject
Failed example:
    ex._fricas_().domainOf()                                      # optional - fricas
Expected:
    Expression(Complex(Integer()))
Got:
    Expression(Complex(Integer))
**********************************************************************
File "src/sage/symbolic/expression_conversions.py", line 761, in sage.symbolic.expression_conversions.FriCASConverter.symbol
Failed example:
    (x^2)._fricas_().domainOf()                                   # optional - fricas
Expected:
    Expression(Integer())
Got:
    Expression(Integer)

@mantepse
Copy link
Collaborator

rootOfADE was renamed to FEseries (because the name was misleading). This means that this string needs to be replaced in fricas.py. If we want to allow users to use older FriCAS, we could also do a work around.

For the other failures, I need to install the new fricas and put aside some other work. I can do so, but I'd rather finish some other stuff first.

@dimpase
Copy link
Member Author

dimpase commented Jan 11, 2024

I'll fix the easy things.

@oldk1331
Copy link

Yes, there is rootOfADE renamed to FEseries and a new printer for types in FriCAS release 1.3.10.

BTW, what does it take to make FriCAS from an optional package to a standard package?

@dimpase
Copy link
Member Author

dimpase commented Jan 12, 2024

Yes, there is rootOfADE renamed to FEseries and a new printer for types in FriCAS release 1.3.10.

BTW, what does it take to make FriCAS from an optional package to a standard package?

We need to hold a vote on this on the sage-develop mailing list. I'll do this now.

@dimpase
Copy link
Member Author

dimpase commented Jan 12, 2024

there is a discrepancy between SBCL-compiled and ECL-compiled FriCAS 1.3.10.
Namely, the ECL-compiled one does, instead of inverting the power-series:

sage: x = fricas("x::TaylorSeries Fraction Integer")
sage: y = fricas("y::TaylorSeries Fraction Integer")
sage: 2*(1+2*x+sqrt(1-4*x)-2*x*y).recip()

                       2
----------------------------------------------
 +-------------+
\|- 4 sage0 + 1  - 2 sage0 sage1 + 2 sage0 + 1

this is seen as

File "src/sage/interfaces/fricas.py", line 166, in sage.interfaces.fricas
Failed example:
    2*(1+2*x+sqrt(1-4*x)-2*x*y).recip()

This is on M1-macOS machine with ECL 23.9.9. Building on the same machine FriCAS with SBCL produces a working, for this example, FriCAS. This error is not observed on x86_64 Linux and FriCAS 1.3.10 built with ECL 21.2.1 or ECL 23.9.9.

@mantepse
Copy link
Collaborator

mantepse commented Jan 12, 2024

works for me, but I don't have a Mac.

(and thank you!)

@dimpase
Copy link
Member Author

dimpase commented Jan 13, 2024

works for me, but I don't have a Mac.

it also works on a x86_64 macOS, so that's really a very specific bug. I'll look more into it.

@oldk1331
Copy link

oldk1331 commented Feb 3, 2024

there is a discrepancy between SBCL-compiled and ECL-compiled FriCAS 1.3.10. Namely, the ECL-compiled one does, instead of inverting the power-series:

sage: x = fricas("x::TaylorSeries Fraction Integer")
sage: y = fricas("y::TaylorSeries Fraction Integer")
sage: 2*(1+2*x+sqrt(1-4*x)-2*x*y).recip()

                       2
----------------------------------------------
 +-------------+
\|- 4 sage0 + 1  - 2 sage0 sage1 + 2 sage0 + 1

this is seen as

File "src/sage/interfaces/fricas.py", line 166, in sage.interfaces.fricas
Failed example:
    2*(1+2*x+sqrt(1-4*x)-2*x*y).recip()

This is on M1-macOS machine with ECL 23.9.9. Building on the same machine FriCAS with SBCL produces a working, for this example, FriCAS. This error is not observed on x86_64 Linux and FriCAS 1.3.10 built with ECL 21.2.1 or ECL 23.9.9.

Does this error happen with M1-macOS with fricas-1.3.9 and ECL-23.9.9? How about M1-macOS with fricas-1.3.10 and ECL-21.2.1?

@mantepse
Copy link
Collaborator

Could someone report on the status of this? (I do not have access to macos) It would be such a shame.

@dimpase
Copy link
Member Author

dimpase commented Feb 12, 2024

at the moment, with a recent bunch of macOS tools on M1, fricas in Sage just doesn't build:

;;; Style warning:
;;;   in file define.clisp, position 165810
;;;   at (DEFUN DomainSubstitutionFunction,Subst ...)
;;;   ! Variable $extraParms was undefined. Compiler assumes it is a global.thread_suspend failed

;;; Internal error:
;;;   ** Error code 6 when executing
;;; (EXT:RUN-PROGRAM "clang" ("-I." "-I/opt/homebrew/Cellar/ecl/23.9.9/include/" "-I/opt/homebrew/opt/gmp/include" "-I/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/include" "-I/opt/homebrew/opt/bdw-gc/include" "-g" "-O2" "-fPIC" "-fno-common" "-D_THREAD_SAFE" "-Ddarwin" "-O2" "-c" "define.c" "-o" "define.o")):
;;; make[5]: *** [define.o] Error 1
make[4]: *** [all-interpsys] Error 2
make[3]: *** [all-src] Error 2
********************************************************************************
Error building fricas-1.3.10

@mantepse
Copy link
Collaborator

would you be willing to share this on fricas-devel? I don't have macos, unfortunately. I am guessing it is a FriCAS problem, not a SageMath-FriCAS problem, right?

@dimpase
Copy link
Member Author

dimpase commented Feb 12, 2024

I am away from kbd now, feel free to post anywhere.

By the way, fricas builds there OK with sbcl from Homebrew. Have not run tests yet

@mantepse
Copy link
Collaborator

The above is with ecl?

@dimpase
Copy link
Member Author

dimpase commented Feb 12, 2024

yes, the above is with ecl, the standard Sage setup

Copy link

github-actions bot commented Mar 19, 2024

Documentation preview for this PR (built with commit 4387983; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@dimpase
Copy link
Member Author

dimpase commented Mar 19, 2024

It does build on M1 with the latest (unreleased) ecl, https://gitlab.com/embeddable-common-lisp/ecl/-/merge_requests/324
(which seems to have other issues, though)

@dimpase
Copy link
Member Author

dimpase commented Mar 19, 2024

OK, also FriCAS-related errors on M1, mentioned above, are gone!

@mantepse
Copy link
Collaborator

I'm not sure I understand correctly. Is this ready to go? (I don't have a Mac)

@dimpase
Copy link
Member Author

dimpase commented Mar 19, 2024

not quite. to support macos on M1 (arm64),
we need one of the following:

  • patch for ecl (or an updated ecl), and a test for unpatched ecl
  • updated ecl / patched ecl, and updated Homebrew ecl
  • building FriCAS with sbcl on M1 macos

none of this is very fast to fix

@dimpase
Copy link
Member Author

dimpase commented Apr 18, 2024

we can have a hack for macOS (and not only).

Allow using sbcl to build FriCAS.
How about it?

@mantepse
Copy link
Collaborator

I have no idea how to do this.

@dimpase
Copy link
Member Author

dimpase commented Apr 18, 2024

I know how, it's not hard.

@dimpase dimpase marked this pull request as ready for review April 23, 2024 23:01
@dimpase
Copy link
Member Author

dimpase commented Apr 23, 2024

We create a dummy package sbcl, and set up building FriCAS so that SBCL >= 2.4.1 is the preferred compiler (if found).
This allows one to circumvent the ECL troubles on arm macOS - install SBCL, done.

@dimpase dimpase changed the title update FriCAS to 1.3.10 update FriCAS to 1.3.10, allow building with sbcl Apr 24, 2024
@dimpase
Copy link
Member Author

dimpase commented Apr 26, 2024

needs review

@mantepse
Copy link
Collaborator

Sorry, I'm a bit overloaded with other things.

One question: with this patch, sbcl is always preferred, if available, right?

Can you recall for me how to test the PR?

@dimpase
Copy link
Member Author

dimpase commented Apr 26, 2024

Sorry, I'm a bit overloaded with other things.

One question: with this patch, sbcl is always preferred, if available, right?

yes. Should I add an option to ./configure, something like --with-fricas-lisp=[sbcl | ecl] ?

Can you recall for me how to test the PR?

say, over the current develop branch (without fricas installed - if it's installed, you need to uninstall it: run
make fricas-clean && make fricas-uninstall)

git pull origin pull/37041/head
./bootstrap
./configure --enable-fricas
make build

should build fricas with sbcl (if available), else with ecl

Then you can run tests etc., e.g. ./sage -tp src/sage/interfaces/fricas.py

@mantepse
Copy link
Collaborator

On Ubuntu 22.04.4, the current sbcl is 2.1.11, so the patch builds with ECL. Is there a good reason not to allow this?

@dimpase
Copy link
Member Author

dimpase commented Apr 26, 2024

is this sbcl not too old for fricas? (i don't know)

@oldk1331
Copy link

FriCAS are compatible with very old SBCL versions.

The official binary for linux is built with 1.4.16.

@dimpase
Copy link
Member Author

dimpase commented Apr 27, 2024

OK, I'll lower the version requirements to 1.4.16.

Copy link
Collaborator

@mantepse mantepse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, works for me and looks good!

@vbraun vbraun merged commit ca1b5e6 into sagemath:develop May 2, 2024
15 of 36 checks passed
@mkoeppe mkoeppe added this to the sage-10.4 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants