gustavochm / phasepy

Other
82 stars 28 forks source link

Difficulty Installing PhasePy #21

Open tlorance opened 12 months ago

tlorance commented 12 months ago

I would like to start using phasepy for my LLE correlation and regression tasks. I have installed it via PyCharm (my preferred IDE) and PyCharm tells me it is functional. However, when I try to reproduce the LLE calculation found in the documentation, I am told that the references "component", "mixture", "preos", and "equilibrium" cannot be found (the precise error is Cannot find reference 'component' in 'phasepy.py | __init__.py', etc.) and that the reference "tpd_min" cannot be resolved; therefore, of course, the example script does not run. Can anyone tell me what I am doing wrong, or how to fix this bug (if that is what it is)?

gustavochm commented 11 months ago

Hey tlorance,

Could you please confirm which version of Python is used and which operative system? I believe the phasepy installation wasn't successful, probably due to the cython code. Phasepy uses Cython to speed up some calculations, requiring a C compiler. The C compiler can be obtained for Linux (e.g., apt-get), Mac OS (Xcode-tools) or for Windows, it can be obtained with a little more effort (https://cython.readthedocs.io/en/latest/src/quickstart/install.html). I have uploaded pre-compiled versions of Python 3.6, 3.7, 3.8 and 3.9 for Windows users. But not for Python 3.10 (as the last time I tried, there were some cython issues with Python 3.10)

Gustavo

tlorance commented 11 months ago

Dear Gustavo, I am using Python 3.9 via the PyCharm IDE; I have gcc installed (I have actually used the Xcode installation that comes with my Mac). Also, PyCharm shows Cython as an installed package. I did find something strange, however: I tried to navigate to the phasepy installation and my command line is now telling me that the python3.9 directory is not a directory. PyCharm still works and still says that that is where the python3.9 installation is located; I can see it in /usr/local/bin, but I can't cd into it. PyCharm also still recognizes phasepy as a package, even though it won't import from it. When I run ls -l, I get this line for python3.9: lrwxr-xr-x 1 ted admin 40 Sep 17 2021 python3.9 -> ../Cellar/python@3.9/3.9.7/bin/python3.9

gustavochm commented 11 months ago

Hey tlerance,

I haven't used PyCharm before, but if you are using MacOS, the installation shouldn't be a problem.
Does PyCharm use a local or other Python installation (from homebrew or conda, for example)? I use the phasepy in a conda environment (getting all the dependencies from conda) and compiled with Xcode GCC without any issues.

One thing you can try is first to uninstall phasepy from your current environment and then compile again from the local files. First, you need to get the source code directly from Git.

git clone https://github.com/gustavochm/phasepy.git

Make sure to use your desired environment. Then, in a terminal, go to the folder where the package was cloned and run the following:

pip install -e .

You should see all the logs from the compilation, and hopefully catch any errors.

Let me know how that goes.

Gustavo

tlorance commented 11 months ago

Something in the last couple of notes must have fixed it. I had complicated issues by creating a new project in PyCharm with a new virtual environment because I had reason to believe that the previous virtual environment had been corrupted. Unfortunately, I stupidly called my new test file "phasepy", so I think it was trying to import itself. It had not originally not been working when it was not in a file called "phasepy", so that wasn't the entire issue, but now that I fixed the filename and did the things you suggested, it is functional. Thank you very much for your time and patience.

tlorance commented 11 months ago

Now that I have it working, I have another question: what is the difference between the "lle" method and the "flash" method. I have tried both for the water-MTBE example, and they give very nearly identical results, but not quite identical, indicating to me that the algorithms may not be the same (and, if they are, the starting guess generators may not be the same – but I thought the use provided the starting guess...). I want to simulate ternary LLE phase plots for experimental data comparison purposes, so if there is a more stable or powerful algorithm, I would prefer to go with that one.

gustavochm commented 11 months ago

Dear tlorance,

I'm glad to read that phasepy is working now. Regardless of your question about the LLE calculation. You are right; in phasepy, you can either use the flash function or the lle function to compute the LLE. The two functions solve the phase equilibria as a flash problem (i.e., at a given global composition, temperature and pressure). The flash function includes two methods: solving the Rachford-Rice equation and updating the phase compositions using successive substitution or by minimizing the Gibbs free energy. This function is inspired by the book of Michelsen and Mollreup. See this example notebook for some more details. On the other hand, the lle function uses a modified flash that checks for equilibrium and stability of the phases simultaneously. Stability analysis is always necessary for LLE calculation. This function also minimizes Gibbs' free energy if the successive substitution is unsuccessful. See this example notebook for some more details.

If the calculation is successful, you should get similar results with both approaches. However, due to the tolerances of the solvers, the results could be slightly different.

I hope that helps. Gustavo