mathworks/jupyter-matlab-proxy

Use a shared matlab engine

rsp34 opened this issue · 5 comments

Hi @rsp34

It is already possible to use the matlab.engine.shareEngine through a jupyter notebook as long as:

  1. The MATLAB Engine for Python is installed in the same python environment as juptyer-matlab-proxy.
  2. One starts MATLAB through the kernel, and uses the MATLAB launched by the kernel from python through the MATLAB Engine for Python APIs.

Please refer to this Dockerfile from the mathworks-ref-arch/matlab-integration-for-jupyter as a reference to the installation steps required to install juptyer-matlab-proxy & matlabengineforpython

Shown below are the steps I took from a container built using the Dockerfile listed above to showcase this:

  1. Open a Terminal inside Jupyter to verify that the matlabengineforpython is installed:

image

  1. Open a note book using the MATLAB Kernel option:

image

  1. Execute the command matlab.engine.shareEngine inside this notebook. You might be asked to provide your license information if this is the first time you are running the integration.
    note: matlab.engine.shareEngine does not have any outputs on successful execution

image

  1. Open a notebook using the Python 3 (ipykernel) as shown below:

image

  1. Execute the command matlab.engine.connect_matlab to connect to the previously shared engine. See here for more information on this command.

image

I hope this helps, please let us know if you need any more information.

Thank you!

rsp34 commented

Thanks for the detailed instructions! 👍

However, I'm not sure this does what I ask. I would like to share the MATLAB engine from an instance of MATLAB running on my machine with the IDE open and then have the MATLAB kernel use this instance of MATLAB.

You are right, the steps I've detailed here will not accomplish what you are looking for.
The steps above are to enable usage of the MATLAB spawned through the kernel with the MATLAB Engine for Python, which can then be used from Python notebooks.

Your last comment gives me much more clarity as to what you are looking for.
If you don't mind, could you please open another issue with a detailed description of your usecase ?

I ask this, as the capability you are looking for is not achievable out of the box, and would require us to either build such a feature in, or, provide you with some scripts/code changes which might enable that.
Having another issue with that request would make it much easier for us to track its progress.

Thank you!

@rsp34 , I've created #64 to continue this thread. Please feel free to add any more information you'd like to provide into #64

Thank you!

rsp34 commented

Thanks @prabhakk-mw!