The interaction between Julia and C# is infrequent
The data communicated are mainly arrays (1d or Nd) rather than complicated custom structures (like a full-fledged class in C#); otherwise, it is difficult to implement the pack/unpack operations in two different languages.
I just started working on a small project in which C# implements the UI (in WPF) and Julia provides the computing core (mainly optimization with JuMP). Your sharing helps a lot.
It looks cool. Could you please explain the main idea under the interoperation between Julia and C#? It seems that the workhorse is jl_eval_string, but how can I pass an array to it (which may be built by the C# part via interaction with the user)?
Besides, I heard that eval in Julia is of low efficiency. Does it matter here?
Yes, actually, I started everything by reading what you did (you project doTimetable is cite above), though I did not see anything about pointers and other complex stuffā¦
@Shuhua In my current code, I duplicate all the custom structure definitions between the two implementations, and I create a custom JsonConverter that acts recusrively.
I will try to refactor a bit and post it here, or maybe create a github repo, I have to seeā¦
Iāve been thinking of attempting this kind of thing for a while also (C# for front-end GUI and graphics and Julia for a back-end ācomputation and analytical engineā) but Iām really just starting out and nowhere close to where you have already gotten and/or oheil got with his doTimeTable application. Thereās just not a lot out there on this so I applaud both of your persistence!
Just throwing this out there and not knowing too much about it myself yet, but what about leveraging the Arrow binary format to pass data back and forth? I believe the idea is it was designed exactly for this kind of passing binary data around and be an independent, language-agnostic format whereby binary Arrow data created in language A should ājust workā to be read in by language B. It even looks to support streaming.
Although it looks like not every language fully supports all defined features yet according to this status page, Julia and C# do both appear to already support many of the most basic data types as well as Arrow file and stream formats.
Yep, thatās pretty much my conclusions too, there is nothing much out there about C# and julia. Thanks for the applause !
I personally checked Arrow myself, but currently neither the C# nor the Julia implementations support tensors so no vector or no matrix storage, which was my main concern.
I also tested MsgPack that worked fine until ND-arrays / tensors were involved.
The BSON was also a bummer at first but at least I found sources to develop my own C# formatter/resolver.
The overall message is JSON/BSON is very generic but only defines the grammar, understand only separators and basic syntax, but the specification does not consider specific objects such as tensors in a unified manner between implementations.
On the other side, Arrow or MsgPack degine very specific objects, but just do not currently support ND arrays as far as I can tell.
Is there some workaround possible for tensors/matrix, at least vectors with e.g. āListā that Julia and C# support (note āLarge Listā and āFixed Size Binaryā not supported by Julia, but not C#)?
I see Julia is the only language with full data type support for Arrow, even with one more than C++ (and @quinnj should be proud of making Julia (official) Arrow work). But (Sparse) Tensor, that neither language support is in another section āIPC Formatā (where Julia still has next best support after C++, and C# least). I do see āthe Python, R, Ruby and C/GLib libraries follow the C++ Arrow library.ā Does that mean e.g. tensors too (for e.g. Python)? [Then for other sections after that one, Julia support drops off, I suppose all those also apply to e.g. Python.]
Often Julia prefers Julia-only code, and there was maybe a good reason for Arrow.jl. I suppose the C++ Arrow library could have been wrapper in Julia (and C#?), and still could, for as good support as for C++ and Python. Curious why wasnāt done.
Iām not sure if thereās anything to learn from e.g. this package with āThe aim is to serialize only the numeric weightsā, i.e. a vector, using Arrow.jl:
As inspired by the Interoperability with .NET, I have made some attempt to embed Julia inside a C# (or .NET in general) program. Though the raw C API is a little verbose, it seems feasible. I have prepared a series of brief tutorials for a beginner and for my own reference. Please check JuliaCSharp/Embedding at main Ā· ShuhuaGao/JuliaCSharp Ā· GitHub. Hope it helps. Any feedback is welcome.
The plan next is to craft a .NET library that provides some wrapper classes to hide all these C API details. I have found a preliminary attempt here: GitHub - WangyuHello/JuliaSharp: C# Interop for Julia , which may serve as an initial reference.
Interesting thread, I was just thinking about this. Especially since Microsoft is taking C# UIs cross-platform with MAUI. Also not a big fan of Julia-native UI solutions available right now. Iād like to replace a MATLAB-created GUI.
It provides interop from C# to Julia and Julia to C# (Julia ā C# is far more primitive atm though).
I see you have some C interface backend, I have been working on the frontend as well if you want to take a look. Mind if I use some of your work for my JLArray etc?
Please feel free to take the code in my repo. Regarding JLArray, maybe it is better to map a Julia array to math.net array or from the opposite side to leverage the matrix functions therein.
I would like to provide help, but currently I am working on a paper. I will join your efforts ASAP.
ps. Would you please enable the discussion panel in your repo? Previously I got some difficulty in automatic memory handling and would like to learn from you.
Hmm, regardless of the current state of development, it could be relevant to set it there so that potential contributors can share their efforts, donāt you think ?