Excercise 4 code compiling issue; paraview module not found
ChristianZaeh opened this issue · comments
Iḿ using VS code with the jupyter notebook extension. When compiling the code copied from the excercise 4 folder:
from glob import glob
from os.path import join
import torch as pt
import matplotlib.pyplot as plt
from flowtorch.data import FOAMDataloader
#
# adjust the path if necessary
#
cases = glob("./boundary_layer_1D_variation/Ub_*")
cases = sorted(cases, key=lambda case: float(case.split("_")[-1]))
loader = FOAMDataloader(cases[0])
y = loader.vertices[:, 1]
u_x = pt.zeros((y.shape[0], len(cases)))
for i, case in enumerate(cases):
loader = FOAMDataloader(case)
u_x[:, i] = loader.load_snapshot("U", loader.write_times[-1])[:, 0]
Ubar = pt.tensor([float(case.split("_")[-1]) for case in cases])
print("Shape of data matrix: ", u_x.shape)
# creating a plot
delta, nu = 0.5, 1.0e-5
Re = pt.tensor([Ub.item()*2*delta/nu for Ub in Ubar])
for i, Ub in enumerate(Ubar):
plt.plot(u_x[:, i], y, label=r"$Re={:1.0f}$".format(round(Re[i].item(), 0)))
plt.xlabel(r"$u_x$")
plt.ylabel(r"$y$")
plt.xlim(0.0, 1.1)
plt.ylim(-0.01, 0.5)
plt.legend(loc="upper center", ncol=4, bbox_to_anchor=[0.5, 1.3])
plt.show()
I get the following error message:
ModuleNotFoundError Traceback (most recent call last)
Cell In [1], line 5
3 import torch as pt
4 import matplotlib.pyplot as plt
----> 5 from flowtorch.data import FOAMDataloader
7 #
8 # adjust the path if necessary
9 #
10 cases = glob("./boundary_layer_1D_variation/Ub_*")
File ~/ml-cfd/lib/python3.10/site-packages/flowtorch/data/__init__.py:7
5 from .psp_dataloader import PSPDataloader
6 from .tau_dataloader import TAUDataloader, TAUConfig
----> 7 from .tecplot_dataloader import TecplotDataloader
8 from .selection_tools import mask_box, mask_sphere
9 from .outlier_tools import iqr_outlier_replacement
File ~/ml-cfd/lib/python3.10/site-packages/flowtorch/data/tecplot_dataloader.py:10
8 # third party packages
9 import torch as pt
---> 10 from paraview import servermanager as sm
11 from paraview.vtk.numpy_interface import dataset_adapter as dsa
12 from paraview.simple import VisItTecplotBinaryReader
ModuleNotFoundError: No module named 'paraview'
I already reinstalled the python environment and also paraview and still get the error. I assume my virtual environment doesnt regognize the libraries but I couldn
t fix it. Do I have to manually add the paraview libraries to the pythonpath?
Thank you for the help!
Hi @ChristianZaeh,
did you re-installed the flowtorch
library as described at the top of lecture 4 + 5 ? You can also check out issue #20 and #25 for further information.
If you already installed the correct version of flowtorch
and this didn't solve the issue please let me know.
Regards
Janis
Hello @JanisGeise,
no I missed that, but I still get the error.
Regards
Christian
Hi @ChristianZaeh,
in VS code, can you check if you selected the correct interpreter / virtual environment for executing this script? From the error message ~/ml-cfd/lib/python3.10/site-packages/flowtorch/data/tecplot_dataloader.py:10
it looks like you are currently using python3.10
in your IDE. The virtual environment should be python3.8.10
.
Another option would be to try executing the script from a terminal using the virtual environment to make sure all dependencies are installed correctly. If the execution from a terminal works, then this should be an issue with the settings in VS code.
Regards,
Janis
Hi @JanisGeise,
I installed the virtual environment with sudo apt install python3-venv
and python3 -m venv ml-cfd
. In this case the 3.10 version gets installed. I thought, according to the tutorial tutorial in excercise 1, that this is not a problem.
When I try to use sudo apt install python3.8-venv
I get the errors Unable to locate package python3.8-venv
and Couldn't find any package by glob 'python3.8-venv'
Regards,
Christian
ok, that's weird, the script in general should work with python3.10
as well (but there may occur conflicts in future exercises when using python3.10
). The only suggestion I have at the moment is to remove and then re-create the ml-cfd
environment from scratch. Otherwise, it's probably a good idea to ask @AndreWeiner at tomorrow's exercise.
Regards,
Janis
Hi @ChristianZaeh,
first, please follow again the instructions provided in the notebook step by step:
# starting from the top-level lecture folder
# enter the Python environment
source ml-cfd/bin/activate
# now you should be in the environment
# remove the old version of flowTorch
pip uninstall flowtorch
# install the latest version
pip install git+https://github.com/FlowModelingControl/flowtorch.git@aweiner
Now, navigate into the notebook folder, open jupyter lab, and open the ml_intro.ipynb notebook:
(ml-cfd) your_name@your_host:~/path/to/ml-cfd-lecture$ cd notebooks
(ml-cfd) your_name@your_host:~/path/to/ml-cfd-lecture$ jupyter-lab
Now the execution should work.
When working in vscode, make sure you are using the correct environment (upper right corner in the picture below). If a different environment is displayed, click on the displayed name and choose ml-cfd (Python...)
Best, Andre