MPh-py / MPh

Pythonic scripting interface for Comsol Multiphysics
https://mph.readthedocs.io
MIT License
274 stars 70 forks source link

Custom Comsol install locations on Linux #62

Closed louisreg closed 2 years ago

louisreg commented 2 years ago

Discussed in https://github.com/MPh-py/MPh/discussions/61

Originally posted by **louisreg** November 5, 2021 Hi, First of all many thanks for MPh-py. This is a great tool and it is very useful for us. We managed to get MPh-py running without any issue on our laptop. However, we tried to get it running on a dedicated linux server but we're having some issues because MPh-py does not find comsol-server. This is mainly because the installation directory is located in a weird location but we can't do anything about that. We managed to get it working by modifying your code and by writing the absolute path of comsol-server in your code. However this is not very convenient, especially if you release new versions of this code. Is it possible to put the absolute path as an argument of a function instead of letting the code finding itself? If not, would it be possible to add this feature? that would be very useful for us! Many thanks in advance best Louis
john-hen commented 2 years ago

I'll have to think how to implement that. On Linux, as opposed to Windows, there is no established mechanism to discover Comsol installations in custom locations. But we could maybe make it a config option. I think that's better than adding yet another optional argument to mph.start and mph.Client and mph.Server. Another way would be via an environment variable.

Out of curiosity, you can't even create a symlink in /usr/local on that Linux server?

(By the way, the library name is just "MPh". I went with "MPh-py" for the "organization", but only because the GitHub user name "MPh" was already taken.)

john-hen commented 2 years ago

Just to summarize the current implementation…The search on Linux considers all folders in /usr/local/ named comsol* which have a sub-folder named multiphysics. It then queries comsol server --version inside each folder to get the version of that installation. The reason we don't use the standard which command is that we want to find all installations, so that users may select one in Python code (which can be useful to run tests or benchmarks with the same model across different Comsol versions).

louisreg commented 2 years ago

Hi, Thanks for the response/explanations! A config option would be perfect for us! we could maybe create that symlink on the server we are currently using but we are planning to deploy our code on supercomputer were we have a very restricted access. Also, comsol is named comsol-xxx on the server for various reason, which is not helping the search I assume. Louis

john-hen commented 2 years ago

Adding a config option would require rewriting quite a bit of code, as I've just noticed. Because I'd then have to support this on all platforms. Or rather, I should. But it's not needed on Windows, and probably of little use on macOS. It would also require quite a bit of documentation, as I'd have to explain a number of things so that users know how to use the option. I'd rather keep things simple if that's possible, especially in the documentation.

If this is a permission problem, we could also just search ~/.local/ on Linux, in addition to /usr/local. Then you could create the symbolic link there, in the user's home directory, without sudo. (Even from Python, if need be.) That folder should already exist, at least it does on Ubuntu and Manjaro. This is much easier to implement and I'd just have to add something like this at the end of the Installation chapter:

If, on Linux, you do have a Comsol installation in a custom location, create a symbolic link in ~/.local that points to that Comsol folder and give the link a name that starts with comsol.

I think this is quite simple and very flexible. For example, the names of the actual Comsol folders wouldn't matter at all. Would that work for you?

byquip commented 2 years ago

Faced similar problem. Since "search_Linux()" method looking for over 'usr/local' folders it was not able to found my comsol folder at the cluster (/opt/software/comsol/comsol55/*). But after replacing in line 208 "/usr/local" for "/opt/software/comsol" it start works. Would be wonderful to create variable for this.

john-hen commented 2 years ago

Again, what's wrong with symbolic links?

Symbolic links are commonly used on Linux to resolve issues just like this. For example, python and python3 are symbolic links that point to the default Python executable. Or, on Ubuntu, /usr/local/man points to /usr/local/share/man, the folder that actually has all the man-pages in it.

Symbolic links would work the same on macOS, for the rare macOS user that would even consider putting Comsol in a custom location. And we don't need a solution for Windows as it's a non-issue there. So I think this should be solved the Linux way on Linux, instead of adding unnecessary complexity to library code.

louisreg commented 2 years ago

Hi John, Sorry for the late reply. Thanks for the suggestion. I can't create symlink to /usr/localbut ~/.local/ would work for me. I just replaced folders = [item for item in Path('/usr/local').iterdir() with folders = [item for item in Path(os.path.expanduser('~')+'/.local/').iterdir() and now it's working just fine. Many thanks Louis

john-hen commented 2 years ago

Okay, I'll publish a new release to support that then. We can just have it search both folders.

john-hen commented 2 years ago

Added in version 1.1.1, released today.