jfricas 2.0.0

21 views
Skip to first unread message

Ralf Hemmecke

unread,
Jul 22, 2023, 12:15:54 PM7/22/23
to fricas-devel
I've just uploaded jfricas to pypi.org.

Now (if you have a FRICASsys with Hunchentoot included) and FriCAS
version 1.3.9, then the installation of jfricas simplifies to

pip install jupyter
pip install jfricas

I hope nobody will find a problem.

Ralf

Grégory Vanuxem

unread,
Jul 22, 2023, 2:04:38 PM7/22/23
to fricas...@googlegroups.com
Thanks Ralf, that's a good thing! 

I'll test it for sure, I have already installed the 2.0.0 version from you Git repository but this way is very simpler now so.

I encountered a strange thing with :Void function and loading a JS plotting library, internally, no JS in the string-stream, but this is with  unofficial work. I'll check and if that's reproducible with usual  spad files I will come back to you and report. 

BTW, I had a question, have you tried to check if the src/input/*. input files, the REGRESS0 "variable" as of now in Makefile. in, run easily?

I can check when time permits. If I ask that this is because for another purpose but transferable to Jupyter Notebook I guess I wanted to load via Julia support in FriCaAS the plotly library but the loading never returns back. 

BTW 2, I wonder if jupyter supports internally JS plotting libraries. In such a way adding say a Jupyter module you would be able to call plotting function. Jupyter supports rich notebook apparently. 

__
Greg

--
You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/3b12ccd6-00fd-9ab6-50c0-6c5e372751cc%40hemmecke.org.

Grégory Vanuxem

unread,
Jul 22, 2023, 2:19:43 PM7/22/23
to fricas...@googlegroups.com
I am busy right now but here is the output.
Don't waste your time though, it's probably not related to jfricas, I
don't know.


-----------------------------------------------------------------------------
Issue )copyright to view copyright notices.
Issue )summary for a summary of useful system commands.
Issue )quit to leave FriCAS and return to shell.
-----------------------------------------------------------------------------

Value = T
Value = WEBSPAD::FRICAS-ACCEPTOR

[W 20:11:42.088 NotebookApp] Replacing stale connection:
23176f31-cb8a-420d-b7cd-fef71c7f8bf2:d7e1f9d93d3e4e638440eca9d2b8e848
[I 20:11:42.089 NotebookApp] Starting buffering for
23176f31-cb8a-420d-b7cd-fef71c7f8bf2:d7e1f9d93d3e4e638440eca9d2b8e848
[I 20:11:42.092 NotebookApp] Restoring connection for
23176f31-cb8a-420d-b7cd-fef71c7f8bf2:d7e1f9d93d3e4e638440eca9d2b8e848
[IPKernelApp] WARNING | Unknown message type: 'comm_open'
[IPKernelApp] WARNING | Unknown message type: 'comm_msg'
[W 20:11:42.699 NotebookApp] 404 GET
/static/components/codemirror/mode/spad/spad.js?v=20230722200956
(127.0.0.1) 23.580000ms
referer=http://localhost:8888/notebooks/Untitled.ipynb?kernel_name=jfricas
[I 20:13:20.899 NotebookApp] Saving file at /Untitled.ipynb
/home/greg/.local/lib/python3.11/site-packages/nbformat/__init__.py:129:
MissingIDFieldWarning: Code cell is missing an id field, this will
become a hard error in future nbformat versions. You may want to use
`normalize()` on your notebooks before validations (available since
nbformat 5.1.4). Previous versions of nbformat are fixing this issue
transparently, and will stop doing so in the future.
validate(nb)
/home/greg/.local/lib/python3.11/site-packages/notebook/services/contents/manager.py:353:
MissingIDFieldWarning: Code cell is missing an id field, this will
become a hard error in future nbformat versions. You may want to use
`normalize()` on your notebooks before validations (available since
nbformat 5.1.4). Previous versions of nbformat are fixing this issue
transparently, and will stop doing so in the future.
validate_nb(model['content'])
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
File "/home/greg/.local/lib/python3.11/site-packages/ipykernel/kernelbase.py",
line 409, in dispatch_shell
await result
File "/home/greg/.local/lib/python3.11/site-packages/ipykernel/kernelbase.py",
line 720, in execute_request
reply_content = self.do_execute(
^^^^^^^^^^^^^^^^
File "/home/greg/.local/lib/python3.11/site-packages/jfricas/fricaskernel.py",
line 212, in do_execute
r = self.server.put(block)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/greg/.local/lib/python3.11/site-packages/jfricas/fricaskernel.py",
line 77, in put
self.output = json.loads(data.rstrip('\\n'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
File "/home/greg/.local/lib/python3.11/site-packages/ipykernel/kernelbase.py",
line 409, in dispatch_shell
await result
File "/home/greg/.local/lib/python3.11/site-packages/ipykernel/kernelbase.py",
line 720, in execute_request
reply_content = self.do_execute(
^^^^^^^^^^^^^^^^
File "/home/greg/.local/lib/python3.11/site-packages/jfricas/fricaskernel.py",
line 212, in do_execute
r = self.server.put(block)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/greg/.local/lib/python3.11/site-packages/jfricas/fricaskernel.py",
line 77, in put
self.output = json.loads(data.rstrip('\\n'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[I 20:15:20.942 NotebookApp] Saving file at /Untitled.ipynb

__
Greg

Grégory Vanuxem

unread,
Jul 22, 2023, 2:55:10 PM7/22/23
to fricas...@googlegroups.com
Attached is a picture showing the same commands, in Jupyter's notebook
vs in a terminal.
I do not expect a graphic in the notebook of course but as you can see
with the 'star'
in front of 'Entrée' (input), computation never ends.
(I stopped the process after several minutes whereas that is not needed)

The two first system commands, if executed via a spad routine
'jlEvalString', produce the same.

Regards,
__
Greg
notebook_vs_terminal.jpg

Ralf Hemmecke

unread,
Jul 22, 2023, 6:35:52 PM7/22/23
to fricas...@googlegroups.com
On 22.07.23 20:54, Grégory Vanuxem wrote:> Attached is a picture showing
the same commands, in Jupyter's notebook
> vs in a terminal.
> I do not expect a graphic in the notebook of course but as you can see
> with the 'star'
> in front of 'Entrée' (input), computation never ends.
> (I stopped the process after several minutes whereas that is not needed)
>
> The two first system commands, if executed via a spad routine
> 'jlEvalString', produce the same.
In your picture I see a ")ju" system command. What is this? I don't find
it in i-syscmd.boot.

Ralf

Grégory Vanuxem

unread,
Jul 23, 2023, 6:45:32 AM7/23/23
to fricas...@googlegroups.com
Hi Ralf, *,

This is just a shortcut to call Julia[1] directly. In fact this is equivalent to the spad
routine 'jlEvalString' in an extension I develop.
I use it principally to set, for example, the number of threads used by BLAS or
switch to MKL (Intel Math Kernel Library) instead of OpenBLAS.
From src/doc/htext/ug16.htex:

******************************
(1) -> )help julia
====================================================================
A.14.  )julia
====================================================================

User Level Required:  interpreter

Command Syntax:

  -  )julia [juliaExpression]

Command Description:

This command is used to evaluate single expressions by the Julia system.
The juliaExpression is read by the Julia reader and evaluated.

)julia print(Base.VERSION)

If the LinearAlgebra package is loaded:

)julia using LinearAlgebra
)julia nthreads = BLAS.get_num_threads()
)julia BLAS.set_num_threads(8)

Its equivalent in Spad is jlEvalString.

The )ju abbreviation calls this system command.

Also See:
o )juliad
o )lisp
==============================================================

But this is not the point, sorry it was a bad example. I just checked what I told you
yesterday and I think I have found a reproducible way to trigger the issue mentioned.
If you ')read' in a FriCAS notebook src/input/bugs2008.input all is right
Bad things happen with bugs2009.input.

Regards,
__
Greg


It's very easy to test if you want this Julia extension. Just clone the jlfricas
branch from gvanuxem GitHub repositories:
$git clone -depth=1 -b jlfricas 1 https://github.com/gvanuxem/fricas.git

Not a lot of code is added and it should be up to date with official
FriCAS. At configure time, as far as the julia binary is in PATH and
libjulia.so in LD_LIBRARY_PATH (?) adding --enable-julia will do
necessary tricks. If SBCL or Clozure CL can load Hunchentoot
(Lisp require) you have an option to add it too. Otherwise hsbcl will help.
In fact even a FriCAS binary compiled with Julia extension support
can find libjulia.so I think.

See README for details on SBCL caveats.

--
You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.

Ralf Hemmecke

unread,
Jul 23, 2023, 11:05:22 AM7/23/23
to fricas...@googlegroups.com
On 23.07.23 12:44, Grégory Vanuxem wrote:
> Hi Ralf, *,
>
> This is just a shortcut to call Julia[1] directly.
> )julia print(Base.VERSION)

Aha.

Did you know that within jfricas you can easily call python stuff via

)python 1+1

?

Well, to implement this was too easy since fricaskernel.py runs on
python anyway.

But you seem to be starting a julia process and then connect to it, right?

I browsed a bit through your julia-addition-patches.
It seems that they need cleaning up. Webspad shouldn't be in there.

Before I can test your stuff, I need to install Juila. Unfortunately,
Ubuntu 22.04 does not (yet) seem to have a julia.deb package.

Ralf

Ralf Hemmecke

unread,
Jul 23, 2023, 11:50:05 AM7/23/23
to fricas...@googlegroups.com
> If you ')read' in a FriCAS notebook src/input/bugs2008.input all is right
> Bad things happen with bugs2009.input.

Hmmmm... right, but certainly, bugs2009.input was never intended to be
read by jfricas.

The [*] that appears in Jupyter does not necessarily mean that the
process runs indefinitely. It just indicates that jupyter did not get a
proper answer yet. This can either be because the FriCAS computation is
still running or there happens some error in the computation and FriCAS
stops and goes into the debugger and thus does not contact Jupyter to
tell that something went wrong.

The latter is the source of the problem with ")read bugs2009.input".

In order to see the FriCAS side I do not start the fricaskernel.py in
the default way, but rather edit it at the end.

Search for where you have installed jfricas.
You probably find it close to where jupyter is:

type jupyter
/home/hemmecke/HDD/hemmecke/software/virtualenv/jfricas/bin/jupyter

In my case it is

/home/hemmecke/HDD/hemmecke/software/virtualenv/jfricas/lib/python3.10/site-packages/jfricas

In this directory edit fricaskernels.py and comment out

## pid = Popen(['fricas','-eval',prereq,'-eval',start])

I usually use the last suggestion there:

pid = Popen(['gnome-terminal', '--title=jfricas', '--'] +
['fricas','-nosman','-eval',prereq,'-eval',start])

Make sure you have gnome-terminal installed. (I also tried other
terminal applications, but only was successful with gnome-terminal.)
Anyway, it starts the terminal and from there it starts fricas in
-nosman mode. The terminal contains basically exactly the fricas session
that you see inside FriCAS, only that usual output of FriCAS commands
are caught by jfricas and not shown in the terminal. However, in case of
an error (FriCAS jumps into the lisp debugger) you have a chance to look
at the terminal and clean things up outside of jupyter. From within
jfricas, I have no idea how to handle such fall-into-debugger errors.

BTW, when I )read bugs.input and afterwards (even with the [*] in that
cell) enter 1+1 into a new cell, I get some results back *and* also the
result 2.

Actually, I do not know how jfricas can contact the running fricas
session (and run additional commands) when FriCAS is in the debugger.

Anyway, if you have jupytext installed, you can open bugs2009.input as a
jupyter notebook and then execute the commands step by step via SHIFT-ENTER.

Ralf

Grégory Vanuxem

unread,
Jul 23, 2023, 1:36:21 PM7/23/23
to fricas...@googlegroups.com
Ralf,

I will probably look at this later but at first glance I would say
this issue comes from jfricas. Personally I test the Jupyter notebook
via a terminal with 'jupyter notebook' and choose the FriCAS
kernel. And if I execute ')read bugs2008' I get no output in the
terminal whereas
with ')ju plotly' or )read bugs2009' the notebook process barfs:

bugs2008 and after bugs2009:
================================================
openServer result 0
FriCAS Computer Algebra System
Version: FriCAS 2023-06-17
Timestamp: mer. 19 juil. 2023 19:47:21 CEST
-----------------------------------------------------------------------------
Issue )copyright to view copyright notices.
Issue )summary for a summary of useful system commands.
Issue )quit to leave FriCAS and return to shell.
-----------------------------------------------------------------------------

Value = T
Value = WEBSPAD::FRICAS-ACCEPTOR

[W 19:22:26.349 NotebookApp] Replacing stale connection:
5cb49a39-9070-4c39-8b41-b1ee72c259af:c8c2372d614e4eb2992f0108bc70b3c3
[I 19:22:26.350 NotebookApp] Starting buffering for
5cb49a39-9070-4c39-8b41-b1ee72c259af:c8c2372d614e4eb2992f0108bc70b3c3
[I 19:22:26.352 NotebookApp] Restoring connection for
5cb49a39-9070-4c39-8b41-b1ee72c259af:c8c2372d614e4eb2992f0108bc70b3c3
[IPKernelApp] WARNING | Unknown message type: 'comm_open'
[IPKernelApp] WARNING | Unknown message type: 'comm_msg'
[W 19:22:26.931 NotebookApp] 404 GET
/static/components/codemirror/mode/spad/spad.js?v=20230723192115
(127.0.0.1) 7.290000ms
referer=http://localhost:8888/notebooks/Untitled.ipynb?kernel_name=jfricas

Several seconds later the terminal prints:
[I 19:24:05.255 NotebookApp] Saving file at /Untitled.ipynb
/home/greg/.local/lib/python3.11/site-packages/nbformat/__init__.py:129:
MissingIDFieldWarning: Code cell is missing an id field, this will
become a hard error in future nbformat versions. You may want to use
`normalize()` on your notebooks before validations (available since
nbformat 5.1.4). Previous versions of nbformat are fixing this issue
transparently, and will stop doing so in the future.
validate(nb)
/home/greg/.local/lib/python3.11/site-packages/notebook/services/contents/manager.py:353:
MissingIDFieldWarning: Code cell is missing an id field, this will
become a hard error in future nbformat versions. You may want to use
`normalize()` on your notebooks before validations (available since
nbformat 5.1.4). Previous versions of nbformat are fixing this issue
transparently, and will stop doing so in the future.
validate_nb(model['content'])

It's saving Untitled.ipynb

And now, in the same notebook session, ')read bugs2009':
And no output in the notebook. It seems jfricas stops processing the
command because
of an error in its side. I can evaluate bugs2009.input until
completion in a terminal for information.

To also be investigated I think .
__
Greg
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/b6a716bf-0d34-a696-2a36-90f4c9a2d9e1%40hemmecke.org.

Ralf Hemmecke

unread,
Jul 23, 2023, 1:51:47 PM7/23/23
to fricas...@googlegroups.com
Do you use

pid = Popen(['gnome-terminal', '--title=jfricas', '--'] +
['fricas','-nosman','-eval',prereq,'-eval',start])

now?

Note, we have the terminal where you enter "jupyter notebook" and
another one that is started when you open an .ipynb notebook.

Ralf

Grégory Vanuxem

unread,
Jul 23, 2023, 2:48:24 PM7/23/23
to fricas...@googlegroups.com
Le dim. 23 juil. 2023 à 17:05, Ralf Hemmecke <ra...@hemmecke.org> a écrit :
>
> On 23.07.23 12:44, Grégory Vanuxem wrote:
> > Hi Ralf, *,
> >
> > This is just a shortcut to call Julia[1] directly.
> > )julia print(Base.VERSION)
>
> Aha.
>
> Did you know that within jfricas you can easily call python stuff via
>
> )python 1+1
>
> ?

Not at all. Thanks for the info :)

>
> Well, to implement this was too easy since fricaskernel.py runs on
> python anyway.
>
> But you seem to be starting a julia process and then connect to it, right?

No, I use the library interface. As Waldek did for GMP, the library, here libjulia.so, is loaded by the underlying LISP, and I just need to initialize it. Two threads (I have two cores on this machine) are started. This is configurable though. So a 'top -H'  shows three FRICASsys process instead of one. I don't know what is going on behind the scenes. The exported routines available are in julia.h:

> I browsed a bit through your julia-addition-patches.
> It seems that they need cleaning up. Webspad shouldn't be in there.

Right, it can now be removed, it was there as an eventual utility, and to keep it in the tree. In fact I deleted jfricas 2.0.0 built from source and installed it with pip. 


> Before I can test your stuff, I need to install Juila. Unfortunately,
> Ubuntu 22.04 does not (yet) seem to have a julia.deb package.

I would say, forget that. Debian package maintainers tried but I presume they abandoned it. It was a real mess. The Debian policy is to, first separate binaries, libraries, and development stuff (-dev) and, importantly, there mustn't be redundancy between packages. Nor conflicts, files or library versions of course. I am sure you know that. The pain happens for example with llvm package maintainers and julia package maintainers, they were not synchro and tons of issues emerged. In fact, the Julia policy is diametrically opposed. All is included in Julia and even if you build it from scratch the build process will download their dependencies and build them with the modifiers -Wl, -rpath, (runtime library search path). If you want I can give a link to a simple julia-1.9.2.deb binary package or you can use 'dpkg-deb --build' in a prepared tree. You just have to put a DEBIAN/control in it (attached for example). So, something like:

$mkdir julia-1.9.2
$mkdir julia-1.9.2/DEBIAN
copy control in the DEBIAN directory
$mkdir julia-1.9.2/usr
eventually mkdir julia-1.9.2/usr/local ... /usr/local/bin
etc. etc, i.e. tree of your binary app and your app in it

$dpkg-deb --build julia-1.9.2.deb

This is not the correct way of course, it allows just to install a binary tarball that can be easily deleted.
__
Greg

>
> Ralf
>
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
control

Ralf Hemmecke

unread,
Jul 23, 2023, 4:56:45 PM7/23/23
to fricas...@googlegroups.com
I more or less get the same output as you (just that I don´t see
^^^^^^^^^^^^^^^^^^.

But as I said, this bugs2009.input deliberately creates an error. And
this is what jfricas cannot handle. Any errors of the kind where FriCAS
jumps into the lisp debugger are bad.

In my gnome-terminal that is attached to the session, I see the following:

Value = T
Value = WEBSPAD::FRICAS-ACCEPTOR
(1) -> [2023-07-23 22:47:14 [ERROR]] An arithmetic error
SB-KERNEL:FLOATING-POINT-EXCEPTION was signalled.
No traps are enabled? How can this be?

Backtrace for: #<SB-THREAD:THREAD "hunchentoot-worker-127.0.0.1:39328"
RUNNING {1003AA3673}>
0: (TRIVIAL-BACKTRACE:PRINT-BACKTRACE-TO-STREAM
#<SB-IMPL::STRING-OUTPUT-STREAM {7F2DCC68BBF3}>)
1: (HUNCHENTOOT::GET-BACKTRACE)
2: ((FLET "H0" :IN HUNCHENTOOT:HANDLE-REQUEST)
#<SB-KERNEL:FLOATING-POINT-EXCEPTION {100688F113}>)
3: (SB-KERNEL::%SIGNAL #<SB-KERNEL:FLOATING-POINT-EXCEPTION {100688F113}>)
4: (ERROR SB-KERNEL:FLOATING-POINT-EXCEPTION :OPERATION NIL :OPERANDS NIL)
5: ((FLET SB-UNIX::BODY :IN SB-VM:SIGFPE-HANDLER))
6: (SB-UNIX::WITH-DEFERRABLE-SIGNALS-UNBLOCKED T #<FUNCTION (FLET
SB-UNIX::BODY :IN SB-VM:SIGFPE-HANDLER) {7F2DCC68BF2B}>)
7: (SB-VM:SIGFPE-HANDLER #<unused argument> #.(SB-SYS:INT-SAP
#X7F2DCC68C3B0) #.(SB-SYS:INT-SAP #X7F2DCC68C280))
8: ((FLET SB-THREAD::EXEC :IN SB-SYS:INVOKE-INTERRUPTION))
9: ((FLET "WITHOUT-INTERRUPTS-BODY-1" :IN SB-SYS:INVOKE-INTERRUPTION))
10: (SB-SYS:INVOKE-INTERRUPTION #<FUNCTION (FLET SB-UNIX::INTERRUPTION
:IN SB-UNIX::%INSTALL-HANDLER) {7F2DCC68C0BB}>)
11: ((FLET SB-UNIX::RUN-HANDLER :IN SB-UNIX::%INSTALL-HANDLER) 8
#.(SB-SYS:INT-SAP #X7F2DCC68C3B0) #.(SB-SYS:INT-SAP #X7F2DCC68C280))
12: ("foreign function: call_into_lisp")
13: ("foreign function: funcall3")
14: ("foreign function: interrupt_handle_now_handler")

Because

)set break resume

at the beginning of bugs2009, it is not so bad for the fricas session,
but still jfricas cannot (currently) handle this case.

I'll see whether some day jfricas can deal with it.

Thanks for reporting.

Ralf

Grégory Vanuxem

unread,
Jul 23, 2023, 6:24:20 PM7/23/23
to fricas...@googlegroups.com
Oh, interesting. I will also look at this when time permits.

__
Greg

--
You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.

Waldek Hebisch

unread,
Jul 25, 2023, 11:36:13 AM7/25/23
to fricas...@googlegroups.com
Well, what you see is part of making good interface. Either you
disable ')set break break' or you handle terminal interactions
needed for debugger. And of course make sure that normal
eeror handlers work.

BTW: That is part of reason why I do not want more Lisp code:
low level messing with various things at Lisp level (done by
Lisp libraries) may interact badly with our runtime support.
So instead of working on interesting symbolic functionality
we need to spend work on system support.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages