Installation¤
PICT consists of three parts:
| Part | Location | How you get it |
|---|---|---|
PISOtorch, the compiled C++/CUDA core (data structures, PISO operators, linear solvers, backward kernels) |
extensions/ |
compiled and installed into your environment with setup.py |
PISOtorch_simulation (simulation loop) and PISOtorch_diff (autograd wrappers) |
repository root | plain Python modules, imported from the repository root |
lib/ (grid generation, I/O, output, multi-block CNN layers, turbulence statistics) |
lib/ |
plain Python package, imported from the repository root |
Only the CUDA extension is installed. Run your scripts from the repository root, or add the repository root to your PYTHONPATH.
Requirements
- Linux and an NVIDIA GPU. PICT runs on a single GPU; all fields live in GPU memory.
- A PyTorch build together with a matching CUDA toolkit (
nvcc) and a compatiblegcc. The conda environment below provides all of them.
Setup with conda¤
The PICT solver and the CUDA toolkit are installed via conda, PyTorch via pip.
-
Install miniconda and clone the repository:
-
Create the environment from the
environment.txtin the repository and activate it: -
Install PyTorch for CUDA 12.8 and the matching CUDA toolkit:
-
Compile and install the custom CUDA kernels:
-
Check the installation (from the repository root):
Tested versions¤
PICT uses Python 3.10.x by default. To use another Python version, change it in environment.txt before creating the environment. PICT works with PyTorch on either CUDA 11 or CUDA 12. These combinations have been tested:
| PyTorch | CUDA |
|---|---|
| 1.13 | 11.8 |
| 2.6 | 11.8 |
| 2.7 | 11.8 |
| 2.7 | 12.8 |
For example, to use PyTorch 2.6 with CUDA 11.8, replace step 3 with:
pip3 install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu118
conda install cuda-toolkit=11.8 -c nvidia/label/cuda-11.8.0
Testing¤
This runs the tests of the compiled kernels: short PISO simulations on a set of test domains in forward and differentiable mode, gradcheck tests of the backward passes of the PISO operators, small optimizations through the solver, and domain copy/clone/save/load. The tests are extensive and take about 30 minutes. run_tests.py sets os.environ["CUDA_VISIBLE_DEVICES"]="0" at the top of the file; change it to an available GPU on your machine (use nvidia-smi to check GPU usage).
Note
As of April 2025, around 5 tests fail, but most of them should work.
The physical validation cases (plane Poiseuille flow and lid-driven cavities compared against reference data) are run with:
See Validation for the results.
Optional components¤
Simplex noise kernels. The turbulent channel flow example initializes its velocity with a Reichardt profile perturbed by curl noise, and the noise is computed by a second small extension:
This installs the SimplexNoiseVariations module: GPU noise fields in 2D and 3D (single precision), with simplex, Worley, fBm, ridged, gradient and curl variants.
VTK output. Simulation(log_vtk=True) writes VTK files through pyvista, which is already part of environment.txt.
Turbulence reference statistics. The channel-flow learning example needs the DNS statistics from the Torroja database, see Turbulent Channel Flow SGS Model.
Build issues¤
-
The wrong CUDA toolkit is picked up. PyTorch's extension builder takes the CUDA installation from the
CUDA_HOMEenvironment variable if it is set. If it finds a system-wide CUDA instead of the toolkit in your environment, the build fails with errors likeNo such file or directory: '/usr/lib/cuda/bin/nvcc'. Point it to the environment explicitly: -
PyTorch 1.13. With PyTorch 1.13, importing the module can fail with
ImportError: arg(): could not convert default argument into a Python object. PyTorch 1.13 bindsc10::optionalbut not itsnulloptdefault. Enable the smalltype_casterblock near the top ofextensions/PISOtorch.cpp(it is commented out and markedneeded for torch 1.13), then rebuild.
Troubleshooting¤
The environment setup should contain all tools and libraries in compatible versions, including the nvcc and gcc compilers. Versions matter and have to be compatible:
- the torch packages are built for a specific Python version,
- the torch version needs a specific CUDA version,
- the CUDA version dictates the
nvccand CUDA library versions, - the linear solver implementations need specific CUDA library versions,
nvcclimits the supportedgccversions.
In the default setup this means torch 2.7, CUDA (runtime, nvcc, libraries) 12.8, and gcc 6.0 to 11.5. If you update torch to a newer CUDA version, the CUDA version(s) might have to be updated accordingly, which in turn might require updating the solver to use newer library functions.
GCC: the wrong compiler is used
The conda-installed gcc does not supersede the system gcc. It has a different name like x86_64-conda-linux-gnu-cc, which should be set in the CC environment variable. It should be used automatically when running setup.py.
Sysconfig: _sysconfigdata_x86_64_conda_cos7_linux_gnu.py is missing
With some older Python versions, the _sysconfigdata_x86_64_conda_cos7_linux_gnu.py file needed to build the CUDA kernels was not generated. This might be caused by a Python 3.9.x version that is too old.
For the issues observed so far (cos7 required but only cos6 available), a workaround is to copy the file and replace cos6 with cos7 in the filename and in the file. The file is in $CONDA_PREFIX/lib/python3.x, with $CONDA_PREFIX being something like ~/miniconda3/envs/pisotorch:
Dynamic linker: a library is not found
The dynamic linker might not find required libraries (or specific versions of them), which shows up as a file-not-found error.
-
Make sure that the linker finds the libraries in the environment:
-
If the issue persists, the required library is missing from the environment.
To automate step 1, add the following to the file env_vars.sh in $CONDA_PREFIX/etc/conda/activate.d (create it if missing):
export OLD_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:${LD_LIBRARY_PATH}
and to the file of the same name in $CONDA_PREFIX/etc/conda/deactivate.d: