|
| 1 | +# NFDI Benchmark Setup on macOS with Docker |
| 2 | + |
| 3 | +Kratos Multiphysics is **not natively supported on macOS**, so we use Docker to run it. Below is a step-by-step guide to set up and run the NFDI Benchmark workflow on a Mac with Apple Silicon (ARM) architecture. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 1. Choose a Base Docker Image |
| 8 | + |
| 9 | +Kratos is distributed only for **x86_64 (amd64) Linux**. Since Apple Silicon uses ARM, we need to emulate x86_64 in Docker: |
| 10 | + |
| 11 | +```dockerfile |
| 12 | +FROM --platform=linux/amd64 ubuntu:22.04 |
| 13 | +``` |
| 14 | + |
| 15 | +This `--platform=linux/amd64` flag ensures Docker emulates an x86_64 environment, allowing Kratos to run correctly. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## 2. Build the Docker Image |
| 20 | + |
| 21 | +Navigate to the repository folder and build the Docker image: |
| 22 | + |
| 23 | +```bash |
| 24 | +cd ~/NFDI_benchmark/NFDI4IngModelValidationPlatform |
| 25 | +docker build -t nfdi_benchmark -f dockerfiles/Dockerfile |
| 26 | +``` |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## 3. Run the Docker Container |
| 31 | + |
| 32 | +Run the container and mount the local repository inside it: |
| 33 | +```bash |
| 34 | +docker run --platform linux/amd64 -it \ |
| 35 | + --name nfdi_benchmark_container \ |
| 36 | + -v $(pwd):/NFDI_Benchmark \ |
| 37 | + nfdi_benchmark:latest |
| 38 | +``` |
| 39 | + |
| 40 | +This makes the local repository available inside the container and opens an interactive shell. |
| 41 | + |
| 42 | +To rerun the same container |
| 43 | +```bash |
| 44 | +docker start -ai <con_id> |
| 45 | +``` |
| 46 | + |
| 47 | +> **Note:** Docker containers do not start with an interactive login shell, so `conda activate` does not work immediately. We must initialize Conda first. |
| 48 | +
|
| 49 | +```bash |
| 50 | +# Initialize Conda |
| 51 | +source /opt/miniforge/etc/profile.d/conda.sh |
| 52 | + |
| 53 | +# Activate the model-validation environment |
| 54 | +conda activate model-validation |
| 55 | + |
| 56 | +# Navigate to the benchmark folder |
| 57 | +cd benchmarks/linear-elastic-plate-with-hole |
| 58 | +``` |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## 4. Generate Configuration and Run Workflow |
| 63 | + |
| 64 | +Generate configuration files: |
| 65 | + |
| 66 | +```bash |
| 67 | +python generate_config.py |
| 68 | +``` |
| 69 | + |
| 70 | +Run the Snakemake workflow: |
| 71 | + |
| 72 | +```bash |
| 73 | +snakemake --use-conda --force --cores all |
| 74 | +``` |
| 75 | + |
| 76 | +Snakemake will look for a `Snakefile` inside `linear-elastic-plate-with-hole` and execute it. |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## 5. Pre-build Conda Environments (Workaround for Architecture Issues) |
| 81 | + |
| 82 | +Snakemake’s automatic Conda environment creation fails under Docker emulation due to architecture mismatches. The solution is to pre-create the environments manually. |
| 83 | + |
| 84 | +### 5.1 Kratos Environment |
| 85 | + |
| 86 | +```bash |
| 87 | +source /opt/miniforge/etc/profile.d/conda.sh |
| 88 | +mamba env create -n kratos-sim -f kratos/environment_simulation.yml |
| 89 | +conda activate kratos-sim |
| 90 | + |
| 91 | +# Test Kratos installation |
| 92 | +python -c "import KratosMultiphysics; print(KratosMultiphysics.__version__)" |
| 93 | +``` |
| 94 | + |
| 95 | +### 5.2 FEniCS Environment |
| 96 | + |
| 97 | +FEniCS can fail when running multiple threads under emulation, so we limit it to a single thread: |
| 98 | + |
| 99 | +```bash |
| 100 | +mamba env create -f fenics/environment_simulation.yml -n fenics-sim |
| 101 | +conda activate fenics-sim |
| 102 | + |
| 103 | +# Limit threads to avoid OpenMP/QEMU errors |
| 104 | +export OMP_NUM_THREADS=1 |
| 105 | +export KMP_AFFINITY=disabled |
| 106 | + |
| 107 | +# Test FEniCS installation |
| 108 | +python -c "import dolfinx; print('FEniCSx imported OK')" |
| 109 | +``` |
| 110 | + |
| 111 | +### 5.3 Mesh Environment |
| 112 | + |
| 113 | +```bash |
| 114 | +conda deactivate |
| 115 | +mamba env create -f environment_mesh.yml -n mesh |
| 116 | +``` |
| 117 | + |
| 118 | +### 5.4 Postprocessing Environment |
| 119 | + |
| 120 | +```bash |
| 121 | +mamba env create -f environment_postprocessing.yml -n postprocessing |
| 122 | +``` |
| 123 | + |
| 124 | +> Once these environments are created, Snakemake will skip environment creation, significantly speeding up workflow execution. |
| 125 | +
|
| 126 | +--- |
| 127 | + |
| 128 | +## 6. Re-run Snakemake Using Pre-built Environments |
| 129 | + |
| 130 | +```bash |
| 131 | +snakemake --use-conda --cores all |
| 132 | +``` |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +## 7. Generate Metadata / Provenance Report |
| 137 | + |
| 138 | +```bash |
| 139 | +snakemake --use-conda --force --cores all \ |
| 140 | + --reporter metadata4ing \ |
| 141 | + --report-metadata4ing-paramscript parameter_extractor.py \ |
| 142 | + --report-metadata4ing-filename metadata4ing_provenance |
| 143 | +``` |
| 144 | + |
| 145 | +This updates all metadata and provenance information without re-running the simulations. |
| 146 | + |
| 147 | +--- |
| 148 | + |
| 149 | +## 8. Extract Snakemake Outputs (Optional) |
| 150 | + |
| 151 | +```bash |
| 152 | +mkdir -p ./metadata4ing_provenance |
| 153 | +unzip -o ./metadata4ing_provenance.zip -d ./metadata4ing_provenance |
| 154 | +``` |
| 155 | + |
| 156 | +--- |
| 157 | + |
| 158 | +## 9. Plot Results |
| 159 | + |
| 160 | +```bash |
| 161 | +python plot_provenance.py ./metadata4ing_provenance |
| 162 | +``` |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +✅ **Notes / Tips:** |
| 167 | +- Always initialize Conda inside the Docker container before activating environments. |
| 168 | +- Limit FEniCS to a single thread on macOS with ARM to avoid OpenMP errors. |
| 169 | +- Pre-building environments avoids repeated environment creation and reduces workflow runtime. |
| 170 | + |
0 commit comments