MPh-py / MPh

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

Add "Connection success" message #28

Closed gwiederhecker closed 3 years ago

gwiederhecker commented 3 years ago

John, I suggest including some sort of success message after connection is finished. I struggled a little to find out whether it was connected or not. For instance, I get the message:

>>> import mph
>>> client=mph.start()
Did not find Comsol executable.

Although the connection to the server was successful. I figured it out by running the discovery.py functions separately.

john-hen commented 3 years ago

The logic is, if mph.start() does not raise an exception, then it worked and the client is up and running. And connected to a server if you're on macOS, as I think you are.

What you're seeing is not an exception, it's an error reported by the logger, which by default is printed to the console. This is standard behavior when using Python's logging mechanism, which MPh does. That log output could also be redirected to a file, or be suppressed entirely. Like so:

import mph
import logging

logging.disable()
client = mph.start()

I don't know what causes this log error to appear. I can only reproduce it if I create an empty Comsol folder beside an existing one. Like on my Linux machine, Comsol 5.5 is installed in /usr/local/comsol55. (It would be in /Applications/COMSOL55 on macOS.) If I create /usr/local/comsol54 as well as an empty multiphysics folder inside that, I get that log error. Which is a warning, rather, as it would still find the Comsol executable in the 5.5 folder and therefore does not raise an exception. So this reproduces the behavior you're seeing. Maybe you have an orphaned Comsol folder from an installation that you've since removed? I can't think of any other explanation.

max3-2 commented 3 years ago

Can no reproduce, only by creating obviuosly damaged folders. Maybe there is a way to install COMSOL without the libraries for scripting? I would have to run the installer and see if this option exists

john-hen commented 3 years ago

The error is reported by this part of the code in discovery.py:

comsol = root/'bin'/'maci64'/'comsol'
if not comsol.exists():
    logger.error('Did not find Comsol executable.')
    continue

Where root is Applications/COMSOL*/Multiphysics. So it's definitely just the executable comsol that is missing in one of the expected locations. It can't have anything to do with the libraries. Because then the (log) error would have a different message.

john-hen commented 3 years ago

So in MPh 0.9.1, released today, I changed the level for these kind of log messages from ERROR to DEBUG. This way they will no longer pop up in the console by default.

@gwiederhecker I'd still be interested to know if my explanation attempt was correct. Only to have an idea if this kind of thing is commonplace or a rare scenario.