Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function callbacks #106

Open
andrewning opened this issue Feb 4, 2017 · 7 comments
Open

function callbacks #106

andrewning opened this issue Feb 4, 2017 · 7 comments

Comments

@andrewning
Copy link

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.

@musm
Copy link
Collaborator

musm commented Feb 7, 2017

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

@andrewning
Copy link
Author

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.

@musm
Copy link
Collaborator

musm commented Feb 7, 2017

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)

@andrewning
Copy link
Author

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.

@musm
Copy link
Collaborator

musm commented Feb 8, 2017

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
Copy link
Collaborator

musm commented Aug 7, 2017

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

@taylormcd
Copy link
Contributor

taylormcd commented Jul 16, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants