π§ This 3D Reservoir PINN Simulator Streamlit application leverages Physics-Informed Neural Networks (PINNs) to model pressure dynamics within a 3D reservoir. It tackles a complex 3D partial differential equation (PDE) for single-phase fluid flow, seamlessly integrating sparse data, boundary conditions, and initial conditions as part of the loss function of the neural network architecture.
What you can do with the simulator:
- βοΈ Input your own reservoir parameters.
- π§ Train new PINN models or load existing ones.
- π Visualize pressure fields with static slices and dynamic animations.
- π£οΈ Query pressure values using cutting-edge LLMs (Deepseek and OpenAI)
- π Track experiments and manage models with MLflow integration.
- π Explore a detailed Jupyter Notebook explaining the PINN implementation.
- π Input Parameters: Configure reservoir settings like porosity, permeability, viscosity, compressibility, injection rate, well position, base pressure, and pressure scale.
- πΎ Data Upload: Easily upload CSV files (x, y, z, t, p columns) or use the provided
data/reservoir_data.csv. Visualize your data with a 3D scatter plot in the sidebar! - ποΈ Model Training: Train new PINN models with real-time loss updates displayed in the sidebar integrated with MLflow.
- π Model Loading: Load previously trained models directly from MLflow runs for quick visualizations and querying.
- πΌοΈ Visualization: Generate static 2D slices of the pressure field at user-defined times and z-levels.
- π¬ Animation: Create captivating animated GIFs showcasing the evolution of the pressure field over time.
- π€ LLM Queries: Interact with your simulation by querying pressure at specific 3D coordinates (x, y, z, t) using DeepSeek or OpenAI LLMs.
- π MLflow Tracking: Keep track of all your experiments! Parameters, metrics (losses), and artifacts (models, loss plots) are logged for comprehensive experiment management.
- π³ Docker Support: Run the entire application in a GPU-compatible Docker container for easy deployment and reproducibility.
reservoir_pinn_simulator/
βββ .env.example # π Template for environment variables
βββ .gitignore # π Git ignore file
βββ README.md # π This awesome project documentation
βββ requirements.txt # π Python dependencies, including mlflow
βββ Dockerfile # π³ Docker configuration for GPU support
βββ data/
β βββ reservoir_data.csv # π Default dataset with 50 pressure points
βββ notebooks/
β βββ reservoir_pinn_notebook.ipynb # π Jupyter Notebook explaining PINN
βββ src/
β βββ __init__.py # π¦ Makes src a Python package
β βββ api/
β β βββ __init__.py
β β βββ server.py # π FastAPI server for LLM queries
β βββ models/
β β βββ __init__.py
β β βββ pinn.py # π§ PINN model definition
β βββ utils/
β β βββ __init__.py
β β βββ plotting.py # π Plotting functions for 3D visualization
β β βββ training.py # πͺ PINN training logic
β βββ app.py # π Streamlit app with training and loading
βββ assets/
β βββ reservoir_demo.gif # ποΈ Demo video of simulator
βββ mlruns/ # mlflow Auto-generated by MLflow for experiment tracking
- π Python 3.12+: Required for local setup.
- π³ Docker: For containerized deployment (with NVIDIA Container Toolkit for GPU support).
- π» GPU (Optional): NVIDIA GPU with CUDA 11.8 for accelerated training.
- π§ Ollama: For local DeepSeek R1 1.5B LLM.
- πΌοΈ Pillow: For GIF animation rendering (included in
requirements.txt). - π MLflow: For experiment tracking and model persistence.
- πAnaconda: For managing python environment.
-
Clone the Repository:
git clone https://github.com/Danny024/reservoir_pinn_simulator.git cd reservoir_pinn_simulator -
Set up PYTHONPATH (Important!):
export PYTHONPATH=$PYTHONPATH:/path/to/your/reservoir_pinn_simulator
-
Create a Conda Environment:
conda create -n reservoir_simulator python=3.12 conda activate reservoir_simulator
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Environment:
- Copy
.env.exampleto.env:cp .env.example .env
- Edit
.envto add your OpenAI API key (optional):Leave blank if you plan to use DeepSeek:OPENAI_API_KEY=your_openai_api_key_here
OPENAI_API_KEY=
- Copy
-
Install and Configure Ollama:
- Install Ollama: https://ollama.ai
- Pull DeepSeek model:
ollama pull deepseek-r1:1.5b
- Start Ollama server (usually runs in the background after installation, but you can manually start if needed):
ollama serve
-
Prepare Assets:
- Ensure
assets/pinn_architecture.pngexists. You can generate it usingnotebooks/reservoir_pinn_notebook.ipynbor provide a placeholder image.
- Ensure
-
Run MLflow Server:
#mlflow server --host 0.0.0.0 --port 5000 --backend-store-uri file://$(pwd)/mlruns --default-artifact-root file://$(pwd)/artifacts mlfow ui -
Run FastAPI Server (for LLM queries):
uvicorn src.api.server:app --host 0.0.0.0 --port 8000
-
Run Streamlit App:
streamlit run src/app.py
-
Install Docker and NVIDIA Container Toolkit:
- Docker (Ubuntu):
sudo apt-get update sudo apt-get install -y docker.io sudo systemctl start docker sudo systemctl enable docker - NVIDIA Container Toolkit (for GPU support):
curl -fsSL [https://nvidia.github.io/libnvidia-container/gpgkey](https://nvidia.github.io/libnvidia-container/gpgkey) | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \ && curl -s -L [https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list](https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list) | \ sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list sudo apt-get update sudo apt-get install -y nvidia-container-toolkit sudo nvidia-ctk runtime configure --runtime=docker sudo systemctl restart docker
- Docker (Ubuntu):
-
Build Docker Image:
docker build -t reservoir-pinn-simulator . -
Run Docker Container:
- With GPU:
docker run --gpus all -p 8501:8501 -p 8000:8000 -p 5000:5000 -p 11434:11434 reservoir-pinn-simulator
- CPU-only:
docker run -p 8501:8501 -p 8000:8000 -p 5000:5000 -p 11434:11434 reservoir-pinn-simulator
(The internal Ollama server within Docker typically runs on port 11434)
- With GPU:
-
Persist MLflow Data (Optional): You can manually create directories on your host machine if they don't exist:
mkdir -p mlruns artifacts
Then run the container with volume mounts:
docker run --gpus all -p 8501:8501 -p 8000:8000 -p 5000:5000 -p 11434:11434 \ -v $(pwd)/mlruns:/app/mlruns \ -v $(pwd)/artifacts:/app/artifacts \ reservoir-pinn-simulator
-
Access the Application:
- Streamlit GUI: http://localhost:8501
- MLflow UI: http://localhost:5000
- (Ollama usually runs on
http://localhost:11434if run locally, or is accessed internally within Docker)
-
βοΈ Configure Parameters:
- In the "Reservoir Parameters" section of the Streamlit app, set values for
$\phi$ (porosity),$k$ (permeability),$\mu$ (viscosity),$c_t$ (total compressibility),$q_0$ (injection rate), well position,$p_{base}$ , and$p_{scale}$ .
- In the "Reservoir Parameters" section of the Streamlit app, set values for
-
πΎ Upload Data:
- Upload a CSV file containing columns:
x, y, z, t, p. - Alternatively, use the default
data/reservoir_data.csv. - A 3D scatter plot of the uploaded data points will appear in the sidebar.
- Upload a CSV file containing columns:
-
π§ Train or Load Model:
- Train New Model: Navigate to "Training Parameters", specify the number of epochs, and click "Train Model". Monitor training losses and the MLflow run ID in the sidebar.
- Load Trained Model: Select an existing MLflow run ID from the dropdown and click "Load Trained Model" to use a pre-trained model.
-
π Visualize Pressure:
- Go to the "Visualize 3D Pressure Field Slice" section.
- Select the desired time (
$t$ ) and z-slice level. - Click "Visualize Pressure Field" to see the 2D slice.
-
π¬ Generate Animation:
- In the "Generate 3D Pressure Field Animation" section, choose a z-slice.
- Click "Generate Pressure Animation" to create and view an animated GIF of the pressure field evolving over time.
-
π£οΈ Query Pressure with LLM:
- Head to the "Query Pressure with LLM" section.
- Select either "DeepSeek" or "OpenAI" as your LLM provider.
- Enter your query in natural language (e.g., "What is the pressure at x=0.5, y=0.5, z=0.5, t=0.5?").
- Click "Submit Query" to get the pressure prediction.
-
π Access Runs: Open your MLflow UI (default: http://localhost:5000) to view the
3D_Reservoir_PINNexperiment. Here you can find:-
Parameters:
$p_{base}$ ,$p_{scale}$ , learning rate, epochs, etc. - Metrics: Training losses (e.g., total loss, PDE loss, data loss).
- Artifacts: Saved model files, loss plots.
-
Parameters:
-
π Load Models Programmatically: Use the run ID (visible in the Streamlit sidebar or MLflow UI) to load models in your Python scripts or notebooks:
import mlflow.pytorch run_id = "<your_run_id>" # Replace with actual run ID model_uri = f"runs:/{run_id}/model" model = mlflow.pytorch.load_model(model_uri)
- βοΈ Compare Runs: Utilize the MLflow UI to compare different training runs based on their loss metrics and configured parameters. This is invaluable for hyperparameter tuning and model selection!
-
ModuleNotFoundError:- Ensure all dependencies from
requirements.txtare installed in your active environment:pip install -r requirements.txt. - Verify
PYTHONPATHis set correctly if running locally.
- Ensure all dependencies from
-
MLflow Issues:
- Confirm the MLflow server is running and accessible (default:
http://localhost:5000). - Check the
mlruns/directory for experiment data. Ensure it's correctly mounted if using Docker with persistent storage.
- Confirm the MLflow server is running and accessible (default:
-
Docker Build Fails:
- Make sure all necessary files exist (e.g.,
data/reservoir_data.csv,assets/pinn_architecture.png). - Verify you have internet access for downloading packages and base images during the build.
- Make sure all necessary files exist (e.g.,
-
Docker Container Fails to Start/Run:
- Check container logs for errors:
docker logs <container_id_or_name>. - Port Conflicts: If ports 8501, 8000, 5000, or 11434 are already in use on your host, map to different host ports. For example:
Then access Streamlit at
docker run --gpus all -p 8502:8501 -p 8001:8000 -p 5001:5000 -p 11435:11434 reservoir-pinn-simulator
http://localhost:8502, FastAPI athttp://localhost:8001, etc.
- Check container logs for errors:
-
GPU Issues (Docker):
- Ensure NVIDIA drivers are correctly installed on your host machine.
- Verify the NVIDIA Container Toolkit is properly installed and configured. Test with:
This command should output GPU information if everything is set up correctly.
docker run --gpus all nvidia/cuda:11.8.0-base-ubuntu22.04 nvidia-smi
-
Ollama Fails / LLM Issues:
- Local: Ensure the Ollama server is running (
ollama serve). Confirm you've pulled the model (ollama pull deepseek-coder:1.3bor similar). - Docker: Check container logs for messages related to Ollama starting or model pulling. The Dockerfile attempts to pull the model during the build.
- If using OpenAI, ensure your
OPENAI_API_KEYin the.envfile is correct and has credit.
- Local: Ensure the Ollama server is running (
-
GIF Animation Issues:
- Make sure the
pillowlibrary is installed:pip show pillow. It should be included inrequirements.txt.
- Make sure the
- Make use of real reservoir dataset
- Design PDE for multiphase flow
- Write Code base in C++ and C# for high performance and efficiency
This project is licensed under the MIT License. See the LICENSE
