juliainterop / mathlink.jl Goto Github PK
View Code? Open in Web Editor NEWJulia language interface for Mathematica/Wolfram Engine
License: Other
Julia language interface for Mathematica/Wolfram Engine
License: Other
Another problem with GeoPosition (for example).. Thx a lot for a soluce...
coucher = W```
Sunrise[GeoPosition[{48.41, -6.11}], DateObject[{2022,9, 8, 0, 0}]]
---> ParseError: KaTeX parse error: Unexpected end of input in a macro argument, expected '}' at end of input: \fbox{\text{Minute: }\text{Thu 8 Sep 2022 07:51}\text{GMT}+2$}$
Is interoperability between Symbolics and MathLink an idea? The usecase is exploratory work in a jupyter or Pluto notebook. Even when the algebra isn't that difficult, I appreciate the comfort of a CAS checking my work. If I want to do something beyond the capabilities of Symbolics.jl, an easy translation from a Symbolics expression to a MathLink expression, and back, would be perfect.
Variables, matrices, basic math (+-*/^), trigonometry, and a flexible way of defining adhoc mapping between functions?
(Why do something manually in 15 minutes that you can spend 15 hours to automate?)
In a Mathematica notebook, every line that doesn't end with ;
will be displayed/ returned.
This is handled differently in MathLink
where only one return value is possible.
MWE:
W```
a = 1;
b = 2
c = 3
``` |> weval
┌ Warning: Set::write: Tag Times in 2 c is Protected.
└ @ MathLink ~/.julia/packages/MathLink/6K9ao/src/eval.jl:16
3
I would expect to get the tuple (2, 3)
back.
Hey, I am the chair at JuliaCon 2023, where we recently announced Dr. Stephen Wolfram is a keynote speaker.
I know that the folks at Wolfram are super excited about this package, and I was wondering if there was a wishlist for them in order to help this package.
Is easy--all that needs to be changed is the value of mlib in low_level.jl. In my case, I just set mlib="/usr/local/Wolfram/Mathematica/10.1/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/libML64i4", and so far things work. Just thought I'd let you know, since it's an easy fix, and there seem to be other users of Mathematica 10* on linux who had the same issue.
When I tried to use mathlink to get hypergeometircfunction's taylorSeries and uesed it to optimize ,it got warning.
The precision issue indeed influnce my experinement,How can I solve it?
Warning: General::munfl:
│ Exp[-999.803] is too small to represent as a normalized machine number;
│ precision may be lost.
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
Hi I installed Julia 1.10 on my Mac M2 and now MathLink seems to be broken.
`julia> using MathLink
julia> weval(WSin[Pi/3]
)
ERROR: LoadError: AssertionError: nextpacket(defaultlink) == PKT_INPUTNAME
Stacktrace:
[1] _defaultlink()
@ MathLink ~/.julia/packages/MathLink/Ehhv0/src/link.jl:99
[2] weval
@ ~/.julia/packages/MathLink/Ehhv0/src/eval.jl:52 [inlined]
[3] weval
@ ~/.julia/packages/MathLink/Ehhv0/src/eval.jl:53 [inlined]
[4] parseexpr(str::String)
@ MathLink ~/.julia/packages/MathLink/Ehhv0/src/eval.jl:68
[5] var"@W_cmd"(source::LineNumberNode, module::Module, str::Any)
@ MathLink ~/.julia/packages/MathLink/Ehhv0/src/eval.jl:96
in expression starting at REPL[7]:1
`
Any idea what is going on?
Thanks!
Gani -
The following does fails in julia
function v_bud(m, nl, ns)
W"Set"(W"nl",nl) |> weval
W"Set"(W"ns",ns) |> weval
W"Set"(W"mm",m ) |> weval
W```
v[n1_, n2_] := Module[{r1, r1s, r2, R1, R2},
r2 = R1/(2 m R1 - 1);
r1s = R1 /. Solve[n1 R1^2 + n2 r2^2 == 1, R1];
r1 = r1s[[FirstPosition[r1s /. m -> Sqrt[n1 + n2],
n_ /; n == 1/Sqrt[n1 + n2]]]] // Simplify;
r2 = r2 /. R1 -> r1 // Simplify;
n1 r1^3 + n2 (r2)^3
];
Chop@(v[nl,ns]/.m->mm)[[1]]
``` |> weval
end # function
v_bud(5,2,1)
Running this in mathematica is fine: (same definition of v
)
Chop@(v[2,1]/.m->5)[[1]]
I cannot really explain why, I thought it is the number type, but even converting everything to floats is fine in Mathematica (with warning) but picking the right solution fails in julia.
Hi. Is there a particular reason why the library has chosen not to overload the basic arithmetic operator such as +,-,*,/?
Currently need to add some biolerpate code at the top to e able to things like
x=W"x"
y=W"y"
z=x+y
w=x-y
import Base.+
import Base.*
import Base.-
import Base./
+(a::MathLink.WSymbol,b::MathLink.WSymbol)=weval(W"Plus"(a,b))
+(a::MathLink.WExpr,b::MathLink.WSymbol)=weval(W"Plus"(a,b))
+(a::MathLink.WExpr,b::MathLink.WExpr)=weval(W"Plus"(a,b))
-(a::MathLink.WSymbol)=weval(W"Minus"(a))
-(a::MathLink.WExpr)=weval(W"Minus"(a))
-(a::MathLink.WSymbol,b::MathLink.WSymbol)=weval(W"Plus"(a,W"Minus"(b)))
-(a::MathLink.WExpr,b::MathLink.WSymbol)=weval(W"Plus"(a,W"Minus"(b)))
-(a::MathLink.WExpr,b::MathLink.WExpr)=weval(W"Plus"(a,W"Minus"(b)))
*(a::MathLink.WExpr,b::MathLink.WExpr)=weval(W"Times"(a,b))
*(a::MathLink.WSymbol,b::MathLink.WExpr)=weval(W"Times"(a,b))
*(a::MathLink.WExpr,b::MathLink.WSymbol)=weval(W"Times"(a,b))
*(a::MathLink.WSymbol,b::MathLink.WSymbol)=weval(W"Times"(a,b))
/(a::MathLink.WSymbol,b::MathLink.WSymbol)=weval(W"Times"(a, W"Power"(b, -1)))
/(a::MathLink.WExpr,b::Number)=weval(W"Times"(a, W"Power"(b, -1)))
Trying to run some code via pythontex yields
ERROR: LoadError: LoadError: AssertionError: nextpacket(defaultlink) == PKT_INPUTNAME
Stacktrace:
[1] _defaultlink at /Users/christ/.julia/packages/MathLink/H6aX1/src/link.jl:54 [inlined]
[2] weval(::Type, ::MathLink.WExpr) at /Users/christ/.julia/packages/MathLink/H6aX1/src/eval.jl:34
[3] weval at /Users/christ/.julia/packages/MathLink/H6aX1/src/eval.jl:35 [inlined]
[4] parseexpr(::String) at /Users/christ/.julia/packages/MathLink/H6aX1/src/eval.jl:45
[5] @W_cmd(::LineNumberNode, ::Module, ::Any) at /Users/christ/.julia/packages/MathLink/H6aX1/src/eval.jl:50
[6] include at ./boot.jl:328 [inlined]
[7] include_relative(::Module, ::String) at ./loading.jl:1094
[8] include(::Module, ::String) at ./Base.jl:31
[9] exec_options(::Base.JLOptions) at ./client.jl:295
[10] _start() at ./client.jl:464
* PythonTeX stderr - unknown on line 59 in "morphologies.tex":
in expression starting at <outputdir>/jl_default_default.jl:224
Any ideas what the problem is and/ or how to fix it?
The main technical challenge is figuring out what is the element type of the array. This isn't documented, but see:
At the interface level, there are two main challenges:
List
, but can be different).So it would probably make sense to define a new type (WArrayExpr
) to store these?
This looks like it could be useful:
https://github.com/WolframResearch/wolfram-app-discovery-rs
we could build it as a JLL?
Unfortunately it doesn't give the dynamic library out of the box, see
WolframResearch/wolfram-app-discovery-rs#50
Say I have a WExpr
stored in variable m
Why do I need two round of weval
to do a substitution?:
julia> m = W"a"
julia> W"ReplaceAll"(m, W"Rule"(W"a", 1)) |> weval
W"Hold"(W"ReplaceAll"(W"a", W"List"(W"Rule"(W"a", 1))))
julia> W"ReplaceAll"(m, W"Rule"(W"a", 1)) |> weval |> weval
1
On my Windows machine, using MathLink
errors because .julia\packages\MathLink\Ehhv0/deps/deps.jl does not exist.
The path delimiter should be fixed. I will open a PR.
How Can I convert W"List"(0.02) to Float64(0.02) in Julia
Is it possible to avoid unecessary memory allocation when using weval(W"Func"(pars)).Even native Methematica Func will need memory and this cause trouble for millions times of calculation.
I upgraded my Mathematica version to 12 on macOS and this involved activating a new license.
Now executing W"Sin"(2) |> weval
hangs indefinetly and I get
/Users/*/Library/Mathematica/Licensing/mathpass:6:
password file "/Users/*/Library/Mathematica/Licensing/mathpass".
Invalid password.
How can I fix this?
When I type using MathLink
into my julia terminal, the following error occurs. I've even tried to add the relevant paths as mentioned in the readme but the error still shows up. What could be wrong? I'm using Mathematica version 12 and julia version 1.3.1.
ERROR: InitError: error compiling init: could not load library ""
The specified module could not be found.
Stacktrace:
[1] _include_from_serialized(::String, ::Array{Any,1}) at .\loading.jl:692 [2] >_require_search_from_serialized(::Base.PkgId, ::String) at .\loading.jl:776 [3] >_require(::Base.PkgId) at .\loading.jl:1001
[4] require(::Base.PkgId) at .\loading.jl:922
[5] require(::Module, ::Symbol) at .\loading.jl:917
during initialization of module MathLink
caused by [exception 1]
could not load library ""
The specified module could not be found.
Stacktrace:
[1] _include_from_serialized(::String, ::Array{Any,1}) at .\loading.jl:692
[2] _require_search_from_serialized(::Base.PkgId, ::String) at .\loading.jl:776
[3] _require(::Base.PkgId) at .\loading.jl:1001
[4] require(::Base.PkgId) at .\loading.jl:922
[5] require(::Module, ::Symbol) at .\loading.jl:917
Currently arbitrary precision values are represented by WReal
and WInteger
types, which are basically string representations. Should we automatically convert these to BigFloat
/BigInt
s? The main downside is the additional overhead of parsing, and the potentially lossy binary/decimal conversion in the case of WReal
.
MathLink seems to be deprecated nowadays compared to the WSTP interface. Do you have any comments on why you chose MathLink over WSTP?
cc: @simonbyrne, @rpestourie
I see there are two PRs, that aim for making this work on 1.x. Is there any way I can help? What are the missing pieces?
Would be a shame to see this getting purged.
error msg
[ Info: Precompiling MathLink [18c93696-a329-5786-9845-8443133fa0b4]
ERROR: LoadError: SystemError: opening file "/Users/ /.julia/packages/MathLink/r23jC/deps/deps.jl": No such file or directory
Stacktrace:
[1] systemerror(p::String, errno::Int32; extrainfo::Nothing)
@ Base ./error.jl:176
[2] #systemerror#80
@ ./error.jl:175 [inlined]
[3] systemerror
@ ./error.jl:175 [inlined]
[4] open(fname::String; lock::Bool, read::Nothing, write::Nothing, create::Nothing, truncate::Nothing, append::Nothing)
@ Base ./iostream.jl:293
[5] open
@ ./iostream.jl:275 [inlined]
[6] open(f::Base.var"#387#388"{String}, args::String; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Base ./io.jl:382
[7] open
@ ./io.jl:381 [inlined]
[8] read
@ ./io.jl:462 [inlined]
[9] _include(mapexpr::Function, mod::Module, _path::String)
@ Base ./loading.jl:1484
[10] include(mod::Module, _path::String)
@ Base ./Base.jl:419
[11] include(x::String)
@ MathLink ~/.julia/packages/MathLink/r23jC/src/MathLink.jl:1
[12] top-level scope
@ ~/.julia/packages/MathLink/r23jC/src/MathLink.jl:7
[13] include
@ ./Base.jl:419 [inlined]
[14] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)
@ Base ./loading.jl:1554
[15] top-level scope
@ stdin:1
in expression starting at /Users/ /.julia/packages/MathLink/r23jC/src/MathLink.jl:1
in expression starting at stdin:1
ERROR: LoadError: Failed to precompile MathLink [18c93696-a329-5786-9845-8443133fa0b4] to /Users/kangjiayin/.julia/compiled/v1.8/MathLink/jl_Y2Dvgx.
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool)
@ Base ./loading.jl:1705
[3] compilecache
@ ./loading.jl:1649 [inlined]
[4] _require(pkg::Base.PkgId)
@ Base ./loading.jl:1337
[5] _require_prelocked(uuidkey::Base.PkgId)
@ Base ./loading.jl:1200
[6] macro expansion
@ ./loading.jl:1180 [inlined]
[7] macro expansion
@ ./lock.jl:223 [inlined]
[8] require(into::Module, mod::Symbol)
@ Base ./loading.jl:1144
[9] include(fname::String)
@ Base.MainInclude ./client.jl:476
[10] top-level scope
@ ~/Desktop/program/julia/DSE_BSEt/src/readmeson.jl:14
Julia v v1.8
mathlink [18c93696] MathLink v0.5.0
Need to make sure library/kernel finding code works with both Mathematica and Wolfram Engine on Linux and Windows.
Shouldn't this package be registered with METADATA?
Being able to convert WExpr
s to julia Expr
, such that you can define julia functions, that you derived using Mathematica functions would be very nice to have.
Hi:
Is there a way to parse outputs like these into julia?
W"Association"(W"Rule"("baseSalary", W"Quantity"(220000, "USDollars")), W"Rule"("position", "F"))
Thanks,
Gani -
At the moment Irrationals have to be converted to floats before passing.
W"Sin"(pi) # Error
W"Sin"(float(pi)) # fine
W"Sin"(W"Pi") # also fine
there's a problem with MathLink.set_texOutput(false) | (or true)
-->
julia> using MathLink
julia> MathLink.set_texOutput(false)
ERROR: UndefVarError: set_texOutput not defined
Stacktrace:
[1] getproperty(x::Module, f::Symbol)
@ Base ./Base.jl:31
[2] top-level scope
@ REPL[2]:1
W2Julia expects an Expr to be returned, not WExpr.
Expr(:call , funcDict[ wexpr.head.name],[W2Julia(arg) for arg in wexpr.args])
or use W2JuliaExpr instead
W2JuliaExpr(wexpr::WExpr)=Expr(
:call,
haskey(funcDict, wexpr.head.name) ? funcDict[wexpr.head.name] : wexpr.head.name,
[W2JuliaExpr(arg) for arg in wexpr.args]...
)
W2JuliaExpr(wexpr::WSymbol) = Symbol(wexpr.name)
W2JuliaExpr(wexpr::Number) = wexpr
add Expr2Fcn to convert WExpr into a usable function.
getSymbols(sym::Symbol) = sym in values(funcDict) ? Vector{Symbol}() : [sym]
getSymbols(sym::Number) = Vector{Symbol}()
function getSymbols(expr::Expr)
r = [getSymbols(exp) for exp in expr.args]
rnew = []
for rr in r::Vector
append!(rnew, rr)
end
unique(rnew)
end
Expr2Fcn(expr::Expr,vars::Expr) = eval(Expr(:(->), vars, expr))
Expr2Fcn(expr::Expr) = Expr2Fcn(expr, Expr(:tuple, getSymbols(expr)...))
Expr2Fcn(wexpr::WExpr)= Expr2Fcn(W2JuliaExpr(wexpr))
Expr2Fcn(weval(W`mathematica expression`))
using MathLink
a=weval(W"Series"(HypergeometricFunctions.pFq((2,), (0.2,),W"z"),(W"z",-1,50)))
Closest candidates are:
(::Type{T})(!Matched::AbstractChar) where T<:Union{AbstractChar, Number}
@ Base char.jl:50
(::Type{T})(!Matched::Base.TwicePrecision) where T<:Number
@ Base twiceprecision.jl:266
(::Type{T})(!Matched::Complex) where T<:Real
@ Base complex.jl:44
...
Hi All,
Really interesting repo. Could this package possibly be used to call Julia code from Mathematica? From what I understand, the MathLink library for C/C++ allows for this functionality.
http://edenwaith.com/development/tutorials/mathlink/ML_Tut.pdf
If not, what would need to be added to enable this functionality? Anywhere I should go looking? Would it be possible to statically compile a Julia script and run it inside Mathematica? In the same spirit as Mathematica.jl, I'm looking for a low-hassle way of calling a Julia function inside of Mathematica as if it were native Mathematica. I see that this is possible with MATLAB: https://github.com/rsmenon/MATLink
Hi I am trying to install MathLink.jl on Windows 10. I have a full version of Mathematica 12.3, but I do not think it contains any "libML64.dll/ libML32.dll" file as mentioned in the installation package. The closest is ml64i4.dll
located in C:\Program Files\Wolfram Research\Mathematica\12.3\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\SystemAdditions
and I set this folder as MathLink dynamic library
. However, after installation when I run using MathLink
, I get the error InitError: could not load library "C:\Program Files\Wolfram Research\Mathematica\12.3\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\SystemAdditions"
.
It works for me when I use ml64i4.dll
, which is different from what's mentioned in the README. Does it need to be updated? The one in the README doesn't exist in my Wolfram Engine installation.
How do we extract numbers from lists? More generally, how are we supposed to use various return values in Julia?
For example, this code returns a list of lists:
weval(W`Table[N[MathieuCharacteristicB[m, q]], {q, 195, 201, 1/10}, {m, 16, 22, 2}]`)
I'd be happy to put an example in the README on how to do this.
@unix ...
macro in low_level.jl
sets the mathlink path for Linux, but it overrides the path for OS X assigned in the line before. @unix
is valid for both platforms and replacing it with @linux
should fix it. #5
Currently you can't interpolate into W_cmd's, quoting from the PR:
W`Sin[$(1+1)]` # W"Sin"(2)The main challenge with this is that
$
is allowed to be used in a variable name (see >here). I'm not sure how best to do this, but perhaps open a new issue to discuss it.
Originally posted by @simonbyrne in #19 (comment)
I tried to use MathLink on MacBook with a M1 and I use Mathematica 12.3, which is a x86 (64bit) version and I get the following error:
ERROR: InitError: could not load library "/Applications/Mathematica.app/Contents/Frameworks/mathlink.framework/mathlink"
dlopen(/Applications/Mathematica.app/Contents/Frameworks/mathlink.framework/mathlink, 0x0001): tried: '/Applications/Mathematica.app/Contents/Frameworks/mathlink.framework/mathlink' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Mathematica.app/Contents/Frameworks/mathlink.framework/mathlink' (no such file), '/Applications/Mathematica.app/Contents/Frameworks/mathlink.framework/mathlink' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/Library/Frameworks/mathlink.framework/mathlink' (no such file), '/System/Library/Frameworks/mathlink.framework/mathlink' (no such file, not in dyld cache), '/Applications/Mathematica.app/Contents/Frameworks/mathlink.framework/Versions/4/mathlink' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Mathematica.app/Contents/Frameworks/mathlink.framework/Versions/4/mathlink' (no such file), '/Applications/Mathematica.app/Contents/Frameworks/mathlink.framework/Versions/4/mathlink' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/Library/Frameworks/mathlink.framework/Versions/4/mathlink' (no such file), '/System/Library/Frameworks/mathlink.framework/Versions/4/mathlink' (no such file, not in dyld cache)
Is it possible to use the x86_64 version of Mathematica with MathLink on a arm64 Mac or do I have to update Mathematica?
In REPL, I found some unintuitive behaviour of ==
W"Sin"(1) == W"Sin"(1) # => true
W`Sin[1]` == W`Sin[1]` # => false
W`Sin[1]` == W"Sin"(1) # => false
Is this a bug?
The current syntax is nice to write new code in julia using mathematica functions, but it is cumbersome to port existing code written in Mathematica.
Maybe a new string macro like
WL"Sin[1]" # -> WEpr
would be good. Since this probably requires a Mathematica parser it is quite a lot of work.
What is missing to get this registered?
Would be good to provide a convenient way to use the various plotting/graphics functions (perhaps making use of Julia MIME handling?).
Note that we would want to avoid unnecessarily copying data to Julia and back again, so we may want to make use of Loopback links
Is plotting supposed to work (I guess not?)?
weval(W"Plot[x^2, {x,0,2}]")
I get W"$Aborted"
.
Hi, while trying out MathLink.jl for Wolfram/Mathematica, I'm stuck on passing on arrays to be evaluated.
In Pluto;
a = 10;
weval(W`Sqrt[$a]`) gives right answer but if I do
a = collect(10:30)
weval(W`Sqrt[$a]`),
I get
Part::partd: Part specification Sqrt[[10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]] is longer than depth of object. Part::partd: Part specification Sqrt[[10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]] is longer than depth of object.
I tried different things, but stuck on how to proceed. Basically Mathematica/Wolfram Engine is looking for lists in the form {10,11,12,..} but $a passes [10,11,12..]
I'm finding MathLink.jl really neat but some sticking points exist.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.