Request for some tests on different architecture/OS. FriCAS with a minimal interface to Julia - personal work in progress

19 views
Skip to first unread message

Grégory Vanuxem

unread,
Jan 8, 2025, 12:12:51 PM1/8/25
to fricas...@googlegroups.com
--- LONG MAIL --

Hello here,

I am requesting some testing for FriCAS with minimal support of Julia
behind the scenes using libjulia. A work in progress I am working on
among other FriCAS related things. I call it jlFriCAS as of now.
Thanks to Qian for his work on GitHub CIs (Actions tab) which allowed
me to automatically build this work on arch/OS that I do not have
access to.

Julia, https://julialang.org/, is necessary of course to load
dynamically libjulia.(.so | .dll | .dylib). You can build it if the
julia(.exe) executable is in your PATH. For simplicity I have tagged
some binaries on GitHub built from the GitHub CI upload (you can use
checksums to check their content if necessary, see Actions tab,I have
only changed the names of some archives). The x86_64 Linux is built
with all options set, Hunchentoot, HTML doc using Sphinx, Aldor
support etc... './configure --help' shows them. All versions are built
using SBCL as Common LISP backend.
https://github.com/gvanuxem/jlfricas/releases/tag/snaphot-20241216

I would be very happy if you can download one or more of them and use
some simple functions with your settings, see below for two main
functions that interest me a lot, this addon uses two ways to
interface Julia.

I am testing this work with 'make check' on GitHub using CIs. For
macOS I use 'julia-actions/setup-julia@latest' for CIs. But 'brew
install julia' worked too. Since macOS version 13 it is more difficult
to load the Julia library. For Windows julia.exe needs to be available
in your PATH, the same directory contains libjulia.dll. For x86_64
Linux, I provide a .deb package. Every binaries are build by GitHub
from GitHub source code, so source and commit are available (no
security problem):

https://github.com/gvanuxem/jlfricas

For Windows I still have a .iss file (Inno Setup Script Wizard
script). I will eventually adapt it, make a self install executable
wizard for my snapshot binaries (testing purpose) and send the .iss
script here for the contrib/ directory for example. Nevertheless,
thanks again to Qian, clicking on FRICASsys after unzipping the
archive starts jlFriCAS and the function jf64 does its job for
example, I just checked (JuliaFloat64 is supported at underlying C and
Lisp levels as a Lisp DoubleFloat).

The Julia binaries are available here:
https://julialang.org/downloads/. I tried juliaup on GitHub CIs for
macOS without success but I do not have filesystem access to macOS so
that's not easy to understand why, but 'brew install julia' does the
job, see https://formulae.brew.sh/formula/julia

About the internals, to resume things, I implemented two ways to use
Julia in FriCAS, the first interface uses the underlying CL FFI, only
SBCL and Clozure CL are supported actually. For data, JuliaInt64 uses
(signed-byte 64) for arrays or the same implementation than
SingeInteger in FriCAS for scalars. JuliaFloat32 and JuliaFloat64 use
Lisp single-float and double-float CL type. A wrapper in C interfaces
the CL FFI to use directly some specific operations in Julia. For
scalars data are passed by values, for arrays, via the CL FFI from the
underlying CL implementation, a C pointer is passed to Julia using
libjulia available operations. The principal goal is efficiency, so
even if some special scalar functions are added to FriCAS using Julia,
the main part is operating on arrays (vectors or matrices). Usual
linear algebra operations are provided using BLAS and LAPACK. a ')show
JuliaF64LinearAlgebra' will show you somes for 64bit arrays. Julia
uses internally the hardware optimized OpenBlas library which
historically comes from the Goto BLAS library (autotuned at startup
contrary to Atlas which used to tune the library a build time
depending on your processor). This library can be changed at run time,
for example with my Intel processor I can use MKL (called Intel oneAPI
as of now), with jlUsing "MKL".

The second interface is completely different. It implements a very
simple Common Lisp class 'jlref' that holds a reference to every
object used in Julia but created in FriCAS, and its Julia type. The
manipulated Julia objects are used in FriCAS using this reference and
the real data, arrays for example, but virtually everything in Julia,
are in the Julia processes (multithreaded).






- Greg

Grégory Vanuxem

unread,
Jan 8, 2025, 12:15:51 PM1/8/25
to fricas...@googlegroups.com
Error.

Sorry

Grégory Vanuxem

unread,
Jan 8, 2025, 12:28:33 PM1/8/25
to fricas...@googlegroups.com

It a draft

Ralf Hemmecke

unread,
Jan 8, 2025, 2:54:21 PM1/8/25
to fricas...@googlegroups.com
Hi Greg,

before I am going to install... do you have a couple of examples (some
.input files) that I then can use to check whether my installation works
and also as a demo how I can actually use functions from Julia.

Thank you
Ralf

Grégory Vanuxem

unread,
Jan 24, 2025, 1:01:50 PM1/24/25
to fricas...@googlegroups.com
Hello Ralf,

Sorry for the late reply, too a lot of bad things in my life... BTW I
have uploaded a new set of binaries at:

https://github.com/gvanuxem/jlfricas/releases/tag/snapshot-20250123

I forgot to mention here that, normally, for this work, Julia should
also contain the Nemo and SpecialFunctions packages, although the
latter isn't really necessary. Other packages also can give you some
goodies, see my code :). The configure script can help.
SpecialFunctions package is there because the first interface makes
extensive use of Float64s for BLAS and LAPACK, it can be seen as an
academic package. I've interfaced quite a few other things so I'm not
sure what kind of input or demo files you're looking for. Maybe you're
talking about the general Julia interface? Or how to use it (by
creating domains or packages for example, or in the interpreter) or
just the ‘first’ interface? Mainly BLAS/LAPACK and domains for their
element type. But to check if the interface works something like:

└─$ jlfricas
Checking for foreign routines
FRICAS="/usr/local/lib/fricas/target/x86_64-linux-gnu"
spad-lib="/usr/local/lib/fricas/target/x86_64-linux-gnu//lib/libspad.so"
foreign routines found
openServer result 0
FriCAS Computer Algebra System
Version: jlFriCAS 1.3.12-dev built with SBCL 2.5.0
Timestamp: mer. 22 janv. 2025 21:12:17 CET
-----------------------------------------------------------------------------
Issue )copyright to view copyright notices.
Issue )summary for a summary of useful system commands.
Issue )quit to leave FriCAS and return to shell.
-----------------------------------------------------------------------------


(1) -> v:=nrand(4)

(1)

1.2948785092864128
-0.2600763993207445
0.6410109567060678
-0.44690936186905317
Type: JuliaFloat64Vector
(2) -> norm v

(2) 1.5345921645958183
Type: JuliaFloat64
(3) -> norm normalize v

(3) 0.9999999999999998
Type: JuliaFloat64

Does the trick. 'jlfricas' is just another fricas script I wrote to
start FriCAS with readline support (reverse search in the interpreter,
automatic completion etc.) without starting HyperDoc at startup, it is
still available via the system command synonym ')hd' though.

Here the example was a little statistic oriented but for LinearAlgebra
more is available in the first interface (and even more with the
second interface):

(4) -> a:=urand01(4,4)

(4)

0.629447 0.264718 0.915014 0.914333
0.811584 0.195081 0.929777 0.970752
0.253974 0.556997 0.315226 0.60056
0.826752 0.0937633 0.941186 0.283772
Type: JuliaFloat64Matrix
(5) -> eigen a

(5)
[
values
=

-0.43037190667652964 + 0.0im
-0.2040803196935474 - 0.09131181759206322im
-0.2040803196935474 + 0.09131181759206322im
2.2620597041523545 + 0.0im
,

vectors
=

0.411756+0.0im 0.624533-0.0im 0.624533+0.0im -0.555356+0.0
im
0.39931+0.0im 0.393103+0.252091im 0.393103-0.252091im -0.595204+0.0
im
0.201061+0.0im -0.53757+0.122864im -0.53757-0.122864im -0.378601+0.0
im
-0.794093+0.0im -0.14518-0.258311im -0.14518+0.258311im -0.440423+0.0
im
]
Type: Record(values: JuliaComplexF64Vector,vectors: JuliaComplexF64Matrix)
(6) -> svd a

(6)
[
U
=

-0.56618 0.164946 0.291146 0.753304
-0.613163 0.0392248 0.454336 -0.645036
-0.29786 0.694143 -0.642814 -0.127419
-0.463413 -0.699586 -0.543693 0.0150175
,

sv
=

2.5684835347187795
0.6626479648305051
0.3023398520311132
0.09456855241209566
,

Vt
=

-0.511115 -0.186434 -0.630029 -0.554137
-0.40207 0.561921 -0.38064 0.614571
-0.200981 -0.804789 -0.0843898 0.552087
-0.732604 0.0424576 0.671607 -0.102145
]
Type: Record(U: JuliaFloat64Matrix,sv: JuliaFloat64Vector,Vt:
JuliaFloat64Matrix)

But if you speak about the general interface (data are in the Julia
process so, only a "pointer" is used to access them) here is an
example with a domain that I like a little:

(7) -> a:=jnecf 1/7

(7) 0.142857 {1/7}
Type: NemoExactComplexField
(8) -> sqrt %

(8) 0.377964 {(a)/7 where a = 2.64575 [a^2-7=0]}
Type: NemoExactComplexField
(9) -> %^2

(9) 0.142857 {1/7}
Type: NemoExactComplexField
(10) -> a:=jnecf(-1/7)

(10) -0.142857 {-1/7}
Type: NemoExactComplexField
(11) -> sqrt %

(11) 0.377964*I {(a)/7 where a = 2.64575*I [a^2+7=0]}
Type: NemoExactComplexField
(12) -> asin %

(12)
0.369499*I {-a*d where a = -0.369499 [Log(0.691080 {(2*b+c*d)/7})], b = 3.741
66 [b^2-14=0], c = 2.64575*I [c^2+7=0], d = I [d^2+1=0]}
Type: NemoExactComplexField

This domain uses a library added to FLINT that uses FLINT. There are a
lot more. Ball arithmetic is an example.

Otherwise, almost everything in Julia can be used, I think.

To finish this, the basic domain to use for the generic interface in
the interpreter is JuliaObject. A little example:

(13) -> jlUsing "Dates"

(13) true
Type: Boolean
(14) -> obj:=jobject "DateTime(2013,7,1)"

(14) 2013-07-01T00:00:00
Type: JuliaObject
(15) -> jlApply("dump",obj)
DateTime
instant: Dates.UTInstant{Millisecond}
periods: Millisecond
value: Int64 63508320000000

(15) nothing
Type: JuliaObject
(16) -> obj2:=jobject "DateTime(2010,7,1)"

(16) 2010-07-01T00:00:00
Type: JuliaObject
(17) -> jlType %

(17) "DateTime"
Type: String
(18) -> jlApply("-",obj,obj2)

(18) 94694400000 milliseconds
Type: JuliaObject
(20) -> obj:=jobject "Date(2013,7,1)"

(20) 2013-07-01
Type: JuliaObject
(21) -> obj2:=jobject "Date(2010,7,1)"

(21) 2010-07-01
Type: JuliaObject
(22) -> jlApply("-",obj,obj2)

(22) 1096 days
Type: JuliaObject

There are rooms of improvements I have to work on, I only coded an
architecture. I need to do an enormous code clean up.

So, please Ralf, what types of input or demo files you speak of. If
you think about documenting what I coded a la FriCAS book, I think I
can't there is too a lot of added code. I have only two hands ;)

- Greg

PS: I attached an .input file to check your installation ;)


Le mer. 8 janv. 2025 à 20:54, 'Ralf Hemmecke' via FriCAS - computer
algebra system <fricas...@googlegroups.com> a écrit :
> --
> 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 visit https://groups.google.com/d/msgid/fricas-devel/0509bc1e-143b-48e6-b825-4af9a8f07561%40hemmecke.org.
check.input
Reply all
Reply to author
Forward
0 new messages