mathworks / matlab-proxy

Python® package enables you to open a MATLAB® desktop in a web browser tab.
Other
47 stars 23 forks source link

matlab module #19

Closed jhgoebbert closed 1 year ago

jhgoebbert commented 1 year ago

Hi,

thank you for this great plugin! It is fantastic to integrate it to our existing web portal for the users of our hpc systems.

The software is installed on the system as modules as there are hundreds of packages available in different versions: https://github.com/easybuilders/JSC/tree/2023/Golden_Repo Also MATLAB is a module which can be loaded by authorized users.

For integration into other tools a wrapper script ensures that the required MATLAB module is loaded before matlab is called. This wrapper script is located at the location of the matlab-proxy module and is not part of the MATLAB installation. Therefore, mwi.validators.terminate_on_invalid_matlab_root_path(..) fails as it cannot find VersionInfo.xml at that place.

I just commented the calls of mwi.validators.terminate_on_invalid_matlab_root_path(..) and get_matlab_version(..) returns None if VersionInfo.xml is not found. That seems to work fine.

Perhaps one could find a way to officially support matlab-wrappers by matlab-proxy. ... ?

prabhakk-mw commented 1 year ago

Hi @jhgoebbert

Thank you for reaching out!

As of v0.7.3 of matlab-proxy, the package should contain the ability to set the path to the matlab executable using the environment variable MWI_CUSTOM_MATLAB_ROOT.

For more information, please see Custom MATLAB Root in the Advanced-Usage.md.

Assuming that you are able to modify the scripts that are used to launch the proxy, is it possible to set this environment variable to point to the directory (aka matlab root) in which matlab is installed? This would need to be done before the matlab-proxy-app executable is launched.

Please let us know if the usage of this environment variable resolves the issue for this use case.

jhgoebbert commented 1 year ago

Hi @prabhakk-mw thank you for your answer.

I have seen MWI_CUSTOM_MATLAB_ROOT. That helps for every setup where you have a fixed location of the Matlab installation. This is not the case at our side as we install software from a central place as modules on multiple systems. This is also the case for MATLAB.

So I created a matlab-wrapper which looks like this:

#!/bin/bash

# Load required modules
module purge
module load Stages/2023
module load GCCcore/.11.3.0
module load MATLAB
module load XServer/21.1.6

matlab "$@"

Problem here is, that the location of VersionInfo.xml can not be derived from the location of matlab.

My current solution is to disable the VersionCheck completely but I haven't fully checked yet what side-effects that might have. Or perhaps you have a better solution ...

diff -Naur 0.7.1.orig/GCCcore-11.3.0-2023.3.6/matlabproxy/matlab-proxy-0.7.4/matlab_proxy/settings.py 0.7.1/GCCcore-11.3.0-2023.3.6/matlabproxy/matlab-proxy-0.7.4/matlab_proxy/settings.py
--- 0.7.1.orig/GCCcore-11.3.0-2023.3.6/matlabproxy/matlab-proxy-0.7.4/matlab_proxy/settings.py  2023-08-24 13:52:26.000000000 +0200
+++ 0.7.1/GCCcore-11.3.0-2023.3.6/matlabproxy/matlab-proxy-0.7.4/matlab_proxy/settings.py       2023-08-27 22:54:27.491557356 +0200
@@ -37,10 +37,10 @@
     if custom_matlab_root_path:
         matlab_root_path = Path(custom_matlab_root_path)

-        # Terminate process if invalid Custom Path was provided!
-        mwi.validators.terminate_on_invalid_matlab_root_path(
-            matlab_root_path, is_custom_matlab_root=True
-        )
+        ## Terminate process if invalid Custom Path was provided!
+        #mwi.validators.terminate_on_invalid_matlab_root_path(
+        #    matlab_root_path, is_custom_matlab_root=True
+        #)

         # Generate executable path from root path
         matlab_executable_path = matlab_root_path / "bin" / "matlab"
@@ -57,9 +57,9 @@

     if matlab_executable_path:
         matlab_root_path = Path(matlab_executable_path).resolve().parent.parent
-        mwi.validators.terminate_on_invalid_matlab_root_path(
-            matlab_root_path, is_custom_matlab_root=False
-        )
+        #mwi.validators.terminate_on_invalid_matlab_root_path(
+        #    matlab_root_path, is_custom_matlab_root=False
+        #)
         logger.info(
             f"Found MATLAB Executable: {matlab_executable_path} with Root: {matlab_root_path}"
         )
@@ -87,6 +87,9 @@
         return None

     version_info_file_path = Path(matlab_root_path) / VERSION_INFO_FILE_NAME
+    if not os.path.exists(version_info_file_path):
+        return None
+
     tree = ET.parse(version_info_file_path)
     root = tree.getroot()
diningPhilosopher64 commented 1 year ago

Hi @jhgoebbert,

As you mentioned that you already have a matlab-proxy module, it would be possible to circumvent your existing matlab-wrapper script by loading the MATLAB module in matlab-proxy module even if the location of MATLAB installation is not fixed.

Below is a sample code for acheiving this:

#%Module1.0######################################################################
##
## matlab-proxy modulefile
##

proc ModulesHelp { } {
    puts stderr "\tThe matlab-proxy Module\n"
    puts stderr "\tThis module loads the MATLAB module for matlab-proxy"
}

module-whatis   "This module loads the MATLAB module for matlab-proxy"

# Load required modules for MATLAB
module purge
module load Stages/2023
module load GCCcore/.11.3.0
module load MATLAB
module load XServer/21.1.6

# Now the matlab executable available on system PATH. 

# In case the matlab executable on path is a softlink, resolve it
set matlabSoftLink [exec which matlab]
set resolvedMatlabExecPath [file readlink $matlabSoftLink]

# Get MATLAB root directory
set matlabRootDir [file dirname [file dirname $resolvedMatlabExecPath]]

# Set the environment variable for matlab-proxy to use
setenv MWI_CUSTOM_MATLAB_ROOT $matlabRootDir

# By setting the MWI_CUSTOM_MATLAB_ROOT environment variable, matlab-proxy should be 
# able to find the VersionInfo.xml file 

# Optionally, add matlab-proxy-app executable to system PATH

Please let us know if the sample code snippet does not solve the issue.

jhgoebbert commented 1 year ago

Hi @diningPhilosopher64

thank you for your idea - and technical, yes, this would be possible. But I think the patch is the better solution for us.

We do not want to load the MATLAB module to just include the MATLAB-launcher-icon in JupyterLab. We want to load the MATLAB module when the launcher-icon gets clicked - not before. This keeps the JupyterLab environment as independent as possible from other features which can be loaded through it.

Hence, it would be great if you can make matlab-proxy not fail if VersionInfo.xml is missing.

prabhakk-mw commented 1 year ago

@jhgoebbert We've updated the proxy to not require the VersionInfo.xml check unless one is using Online Licensing. Please let us know v0.9.0 of matlab-proxy solves this issue for you.

jhgoebbert commented 1 year ago

Great! I have installed and tested it. It works 👍