MPh-py / MPh

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

GUI does not pop up when starting client #88

Closed MagAtOQ closed 2 years ago

MagAtOQ commented 2 years ago

Hi there,

I decided this morning to start with MPh.

I'm running python 3.10.4 via anaconda under win10. I installed the required MPh package using pip and it added as expected the JPype package. So far so good.

Using the following code:

import mph
client = mph.start(cores=1)

I would expect the COMSOL client to pop up... but no... it doesn't. I see the client object appearing in my variable explorer... and that's it. Clicking on the variable to get it's content is raising an error:

Output from spyder call 'get_cwd':
Exception in comms call get_value:

  File "C:\Users\MatthieuGaudet\anaconda3\envs\Comsol_Friendly\lib\site-packages\spyder_kernels\comms\commbase.py", line 347, in _handle_remote_call
    self._set_call_return_value(msg_dict, return_value)

  File "C:\Users\MatthieuGaudet\anaconda3\envs\Comsol_Friendly\lib\site-packages\spyder_kernels\comms\commbase.py", line 384, in _set_call_return_value
    self._send_message('remote_call_reply', content=content, data=data,

  File "C:\Users\MatthieuGaudet\anaconda3\envs\Comsol_Friendly\lib\site-packages\spyder_kernels\comms\frontendcomm.py", line 109, in _send_message
    return super(FrontendComm, self)._send_message(*args, **kwargs)

  File "C:\Users\MatthieuGaudet\anaconda3\envs\Comsol_Friendly\lib\site-packages\spyder_kernels\comms\commbase.py", line 247, in _send_message
    buffers = [cloudpickle.dumps(

  File "C:\Users\MatthieuGaudet\anaconda3\envs\Comsol_Friendly\lib\site-packages\cloudpickle\cloudpickle_fast.py", line 73, in dumps
    cp.dump(obj)

  File "C:\Users\MatthieuGaudet\anaconda3\envs\Comsol_Friendly\lib\site-packages\cloudpickle\cloudpickle_fast.py", line 602, in dump
    return Pickler.dump(self, obj)

TypeError: cannot pickle '_jpype._JField' object

Is there a reason for that? I know that Anaconda is not always letting the python code interacting with the other softwares for security reasons. Could it be the reason?

In any case, thanks for your help.

All the best

Matthieu

john-hen commented 2 years ago

Hi Matthieu. I don't know what your Spyder GUI (I assume) does there, but I wouldn't expect the Comsol client to "pop up". If there's no error message when you run client = mph.start(), then you have the client reference and you're good to go.

MagAtOQ commented 2 years ago

Dear John-hen, I went through the all process presented in the tutorial and all went well, indeed. I guess that the "problem" is related to the sentence used, that is potentially misleading

The start() function returns a client object, i.e. an instance of the Client class. It takes roughly ten seconds for the client to spin up.

Or maybe it is my english language that is to poor to correctly understand "spin up".

But you are confirming that the comsol GUI will not show up... and if even started, the GUI will not be influenced by the python command transfered via MPh. I did a small test modifiying the value of a parameter when the GUI was started with the equivalent model but it doesn't seem to have any effect in the GUI. In other words, it is not a "liveLink", right?

Actually, is there any possible problem of starting both in parallel... I should maybe avoid this.

In any case, you clarified my main concern.

Thanks for this very useful implementation.

With regards

MG

john-hen commented 2 years ago

Spinning up just means that the client is starting, though it implies that it takes a bit. No, there is no GUI window. Though MPh does do essentially the same as the Matlab LiveLink. I just don't call it that because it strikes me as a marketing term. As far as I'm concerned, the Matlab LiveLink is the Comsol add-on product that gives you access to the Matlab API.

MPh would be the "Python LiveLink" if it were a Comsol product. But it's not.

As with the Matlab API, you don't automatically control the same model that you see in the GUI. Then you simply have two different Comsol clients that have loaded the same model file from disk. There isn't really a problem with that, I usually do that as well (and used to do that back when I used the Matlab LiveLink), you just have to be careful when saving changes to the model file. Whichever client writes the file last, with whatever state of the model they currently have in memory, that's what ends up on disk.

It is however possible to control the model you see in the GUI. The process is the same as for Matlab. So you will need a Comsol Multiphysics server instance that holds the model, and then have the GUI client as well as the Python client connect to that same server instance.