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

Use a shared matlab engine #59

Closed
rsp34 opened this issue Aug 31, 2023 · 5 comments
Closed

Use a shared matlab engine #59

rsp34 opened this issue Aug 31, 2023 · 5 comments
Assignees
Labels
answered Issue has been answered question Further information is requested

Comments

@rsp34
Copy link

rsp34 commented Aug 31, 2023

Enable the use of a shared engine as per https://uk.mathworks.com/help/matlab/ref/matlab.engine.shareengine.html

@prabhakk-mw prabhakk-mw added the question Further information is requested label Sep 1, 2023
@prabhakk-mw
Copy link
Member

prabhakk-mw commented Sep 1, 2023

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!

@prabhakk-mw prabhakk-mw added the answered Issue has been answered label Sep 1, 2023
@rsp34
Copy link
Author

rsp34 commented Sep 4, 2023

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.

@prabhakk-mw
Copy link
Member

prabhakk-mw commented Sep 4, 2023

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!

@prabhakk-mw
Copy link
Member

@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
Copy link
Author

rsp34 commented Sep 11, 2023

Thanks @prabhakk-mw!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered Issue has been answered question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants