MATLAB.jl icon indicating copy to clipboard operation
MATLAB.jl copied to clipboard

function callbacks

Open andrewning opened this issue 8 years ago • 7 comments

Is it possible to pass in a Julia function and have matlab call it. Like calling matlab's fzero for example. I don't need fzero, it's just a simple example. I couldn't find a way to do it, but thought I'd ask.

andrewning avatar Feb 04 '17 01:02 andrewning

You'll need https://github.com/twadleigh/mexjulia for that I believe

musm avatar Feb 07 '17 16:02 musm

I believe mexjulia let's me go the other way, call Julia with a callback into a matlab function. I'm looking for the opposite. It might work to combine both packages although I haven't tested that. I'm guessing it would open up a new Julia instance in the callback.

andrewning avatar Feb 07 '17 19:02 andrewning

Not sure on your application, but one option is to splice in the value of the julia function if that is all you need. Another way that @ChrisRackauckas did (see https://github.com/JuliaDiffEq/MATLABDiffEq.jl/blob/master/src/MATLABDiffEq.jl) was to translate the julia function to matlab syntax (obviously this has to make sense and in general won't but for his application it worked well enough)

musm avatar Feb 07 '17 19:02 musm

Thanks. I'm not sure what you mean by splice in the value of the function. The latter doesn't work for my application.

The goal is to use fmincon and have it call a julia function. I realize there are optimizers in Julia, and I've wrapped another commercial optimizer as well, but I'd like to be able to use fmincon on Julia functions as another option and for benchmarking purposes. I was able to write a Python wrapper than enabled me to call fmincon from Python with callbacks into a Python function. I was hoping to do something similar with Julia.

andrewning avatar Feb 08 '17 00:02 andrewning

unfortunately that's not currently possible using MATLAB.jl . I'm not sure if it would be possible to implement something like that using mexjulia and then getting back the results into julia cc @twadleigh , but it would be a nice feature.

musm avatar Feb 08 '17 21:02 musm

Hmm this may actually be possible to implement, although perhaps not super straightforward.

musm avatar Aug 07 '17 05:08 musm

Just implemented this for fmincon with a combination of MATLAB.jl and mexjulia. See https://github.com/byuflowlab/Fmincon.jl. I had to revive mexjulia (update to Julia 1.0) to get it to work, (which I reformatted as a Julia package). The updated mexjulia is at https://github.com/byuflowlab/Mex.jl

taylormcd avatar Jul 16 '19 21:07 taylormcd