|
| 1 | +# Managing Simulators with S3 Storage |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Yaptide supports two simulation engines: **SHIELD-HIT12A** and **FLUKA**. This document explains the simulator management system, how binaries are stored and deployed, and how to manage different simulator versions. |
| 6 | + |
| 7 | +## Architecture and Logic |
| 8 | + |
| 9 | +Yaptide implements a deployment strategy for managing simulation engine binaries. In the demo mode, when S3 environment variables are not configured in the `.env` file (or are missing from the environment), the system automatically downloads a constrained demo version of SHIELD-HIT12A directly from [shieldhit.org](https://shieldhit.org). This demo build is intended for development and validation, uses a fixed random number generator seed, enforces a 10,000 primary particle limit, and remains unencrypted because it is public. |
| 10 | + |
| 11 | +In production mode, when S3 credentials are configured in the `.env` file, the system retrieves full-featured simulator binaries from S3-compatible object storage. SHIELD-HIT12A and FLUKA binaries are stored in encrypted form; the decryption password and salt are supplied via the `.env` file and must match the values used during upload. This mode provides unrestricted functionality (custom random seeds, unlimited primaries) and retains a graceful fallback: if S3 download fails or credentials are unavailable, the system automatically falls back to the demo SHIELD-HIT12A build. |
| 12 | + |
| 13 | +## Flow During Container Startup |
| 14 | + |
| 15 | +The `yaptide-simulation-worker` container is built from [yaptide/Dockerfile-simulation-worker](https://github.com/yaptide/yaptide/blob/master/Dockerfile-simulation-worker) and invokes the startup script [yaptide/run_simulation_worker.sh](https://github.com/yaptide/yaptide/blob/master/run_simulation_worker.sh), which in turn calls the simulator manager [yaptide/yaptide/admin/simulators.py](https://github.com/yaptide/yaptide/blob/master/yaptide/admin/simulators.py). All required configuration is expected in the `.env` file; if a variable is absent there, the runtime environment is consulted, and if still missing a fallback path is taken. |
| 16 | + |
| 17 | +SHIELD-HIT12A is always initialized: the script first attempts to fetch and decrypt the encrypted binary from S3 using `S3_ENDPOINT`, `S3_ACCESS_KEY`, `S3_SECRET_KEY`, `S3_SHIELDHIT_BUCKET`, `S3_SHIELDHIT_KEY`, and the decryption parameters `S3_ENCRYPTION_PASSWORD` and `S3_ENCRYPTION_SALT` from `.env` or the environment. If any of these are unavailable or the download fails, the process falls back to downloading the public demo build from shieldhit.org and installs it into `/simulators/shieldhit12a/bin`. |
| 18 | + |
| 19 | +FLUKA is initialized only when `S3_FLUKA_BUCKET` and `S3_FLUKA_KEY` are provided in `.env` or the environment; the payload is encrypted and decrypted with the same password and salt variables. If these variables are absent, FLUKA installation is skipped, allowing deployments that rely solely on SHIELD-HIT12A. |
| 20 | + |
| 21 | +## Simulator Management Command Reference |
| 22 | + |
| 23 | +**Note:** The simulation binaries are compiled for Linux. All commands should be executed on Linux or within Windows Subsystem for Linux (WSL). Running on native Windows will not work. |
| 24 | + |
| 25 | +Use the project virtual environment managed by Poetry (see [Backend: For developers](for_developers.md) for installation and activation). The `simulators.py` CLI manages encrypted simulator binaries: it downloads SHIELD-HIT12A (with demo fallback), optionally downloads FLUKA, uploads encrypted artifacts to S3, and provides encrypt/decrypt helpers. Run `--help` to list commands: |
| 26 | + |
| 27 | +```bash |
| 28 | +poetry run ./yaptide/admin/simulators.py --help |
| 29 | +``` |
| 30 | + |
| 31 | +For command-specific options, append `--help`, e.g.: |
| 32 | + |
| 33 | +```bash |
| 34 | +poetry run ./yaptide/admin/simulators.py download-shieldhit --help |
| 35 | +``` |
| 36 | + |
| 37 | + |
| 38 | +### Available Commands |
| 39 | + |
| 40 | +Most S3 parameters are read from environment variables (see [Environment Variables Configuration](#environment-variables-configuration) below). Run each command with `--help` for full options: |
| 41 | + |
| 42 | +#### Download SHIELD-HIT12A from S3 (with demo fallback) |
| 43 | + |
| 44 | +Retrieve the SHIELD-HIT12A binary from S3 storage and decrypt it locally. If S3 is unavailable, the system falls back to the public demo version: |
| 45 | + |
| 46 | +```bash |
| 47 | +poetry run ./yaptide/admin/simulators.py download-shieldhit --dir ./download --decrypt |
| 48 | +``` |
| 49 | + |
| 50 | +Confirm successful download by listing the directory: |
| 51 | + |
| 52 | +```bash |
| 53 | +ls -lh ./download |
| 54 | +``` |
| 55 | + |
| 56 | +Verify the binary version matches your expectations: |
| 57 | +```bash |
| 58 | +./download/shieldhit --version |
| 59 | +``` |
| 60 | + |
| 61 | +Optionally validate the binary inside the simulation worker container (mounting read-only at a non-standard path to isolate from production simulators): |
| 62 | +```bash |
| 63 | +docker run --rm -it \ |
| 64 | + -v "$(pwd)/download/shieldhit:/opt/test/shieldhit:ro" \ |
| 65 | + --entrypoint /bin/bash yaptide_simulation_worker \ |
| 66 | + -c "/opt/test/shieldhit --version" |
| 67 | +``` |
| 68 | + |
| 69 | +For additional configuration options and parameters: |
| 70 | + |
| 71 | +```bash |
| 72 | +poetry run ./yaptide/admin/simulators.py download-shieldhit --help |
| 73 | +``` |
| 74 | + |
| 75 | +#### Retrieve FLUKA from S3 (encrypted) |
| 76 | + |
| 77 | +Download and decrypt the FLUKA binary from S3 storage. Requires valid S3 credentials configured in `.env`: |
| 78 | + |
| 79 | +```bash |
| 80 | +poetry run ./yaptide/admin/simulators.py download-fluka --dir ./download |
| 81 | +``` |
| 82 | + |
| 83 | +For additional configuration options: |
| 84 | + |
| 85 | +```bash |
| 86 | +poetry run ./yaptide/admin/simulators.py download-fluka --help |
| 87 | +``` |
| 88 | + |
| 89 | +#### Upload Simulator Binary to S3 |
| 90 | + |
| 91 | +Upload a compiled simulator binary to S3-compatible storage with optional encryption: |
| 92 | + |
| 93 | +```bash |
| 94 | +poetry run ./yaptide/admin/simulators.py upload --bucket my-bucket --file ./shieldhit --encrypt |
| 95 | +``` |
| 96 | + |
| 97 | +For additional configuration options: |
| 98 | + |
| 99 | +```bash |
| 100 | +poetry run ./yaptide/admin/simulators.py upload --help |
| 101 | +``` |
| 102 | + |
| 103 | +#### Encrypt File |
| 104 | + |
| 105 | +Manually encrypt a binary: |
| 106 | + |
| 107 | +```bash |
| 108 | +poetry run ./yaptide/admin/simulators.py encrypt --infile ./shieldhit --outfile ./shieldhit.encrypted --password my-pass --salt my-salt |
| 109 | +``` |
| 110 | + |
| 111 | +See options: |
| 112 | + |
| 113 | +```bash |
| 114 | +poetry run ./yaptide/admin/simulators.py encrypt --help |
| 115 | +``` |
| 116 | + |
| 117 | +#### Decrypt File |
| 118 | + |
| 119 | +Manually decrypt a binary: |
| 120 | + |
| 121 | +```bash |
| 122 | +poetry run ./yaptide/admin/simulators.py decrypt --infile ./shieldhit.encrypted --outfile ./shieldhit --password my-pass --salt my-salt |
| 123 | +``` |
| 124 | + |
| 125 | +See options: |
| 126 | + |
| 127 | +```bash |
| 128 | +poetry run ./yaptide/admin/simulators.py decrypt --help |
| 129 | +``` |
| 130 | + |
| 131 | +## Practical Examples |
| 132 | + |
| 133 | +### Uploading a New SHIELD-HIT12A Version |
| 134 | + |
| 135 | +Step-by-step example assuming SHIELD-HIT12A sources live in `$HOME/workspace/shieldhit`. |
| 136 | + |
| 137 | +**1) Compile the binary (from the source dir)** |
| 138 | + |
| 139 | +Enter the source tree: |
| 140 | +```bash |
| 141 | +cd "$HOME/workspace/shieldhit" |
| 142 | +``` |
| 143 | + |
| 144 | +Compile with gfortran: |
| 145 | +```bash |
| 146 | +make gfortran -j |
| 147 | +``` |
| 148 | + |
| 149 | +After build, the binary should be `./shieldhit`. Check its version: |
| 150 | + |
| 151 | +Verify binary version: |
| 152 | +```bash |
| 153 | +./shieldhit --version |
| 154 | +# Expected shape (example): |
| 155 | +# SHIELD-HIT12A |
| 156 | +# Version: v1.1.0-8-g4ea3f147 |
| 157 | +# Build date: Tue, 20 Jan 2026 11:28:34 +0100 |
| 158 | +# SHIELD-HIT12A is up to date. |
| 159 | +``` |
| 160 | + |
| 161 | +Optionally rename to capture host/build metadata (recommended): |
| 162 | + |
| 163 | +```bash |
| 164 | +mv ./shieldhit ./shieldhit-lenovo-dev-g4ea3f147-make-gfortran |
| 165 | +``` |
| 166 | + |
| 167 | +**2) Upload to S3 with encryption (run from project root `yaptide/`)** |
| 168 | + |
| 169 | +Switch to project root: |
| 170 | +```bash |
| 171 | +cd "$HOME/workspace/yaptide" |
| 172 | +``` |
| 173 | + |
| 174 | +Upload with encryption to S3: |
| 175 | +```bash |
| 176 | +poetry run ./yaptide/admin/simulators.py upload \ |
| 177 | + --bucket shieldhit \ |
| 178 | + --file "$HOME/workspace/shieldhit/shieldhit-lenovo-dev-g4ea3f147-make-gfortran" \ |
| 179 | + --encrypt |
| 180 | +``` |
| 181 | + |
| 182 | +**3) Verify download and execution** |
| 183 | + |
| 184 | +Prepare temp download directory: |
| 185 | +```bash |
| 186 | +mkdir -p /tmp/sh-download |
| 187 | +``` |
| 188 | + |
| 189 | +Download and decrypt from S3: |
| 190 | +```bash |
| 191 | +poetry run ./yaptide/admin/simulators.py download-shieldhit --dir /tmp/sh-download --decrypt |
| 192 | +``` |
| 193 | + |
| 194 | +Run version check on downloaded binary: |
| 195 | +```bash |
| 196 | +/tmp/sh-download/shieldhit --version |
| 197 | +``` |
| 198 | + |
| 199 | +If you want to validate inside the simulation worker container (without overwriting in-container simulators): |
| 200 | + |
| 201 | +```bash |
| 202 | +docker run --rm -it \ |
| 203 | + -v "/tmp/sh-download/shieldhit:/opt/test/shieldhit:ro" \ |
| 204 | + --entrypoint /bin/bash yaptide_simulation_worker \ |
| 205 | + -c "/opt/test/shieldhit --version" |
| 206 | +``` |
| 207 | + |
| 208 | +## Environment Variables Configuration |
| 209 | + |
| 210 | +For S3-based deployment, configure these environment variables (`.env` file): |
| 211 | + |
| 212 | +```bash |
| 213 | +# S3 General Configuration |
| 214 | +S3_ENDPOINT=s3.mycompany.com |
| 215 | +S3_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE |
| 216 | +S3_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY |
| 217 | + |
| 218 | +# SHIELD-HIT12A Configuration |
| 219 | +S3_SHIELDHIT_BUCKET=yaptide-simulators |
| 220 | +S3_SHIELDHIT_KEY=shieldhit_latest |
| 221 | + |
| 222 | +# FLUKA Configuration |
| 223 | +S3_FLUKA_BUCKET=yaptide-simulators-fluka |
| 224 | +S3_FLUKA_KEY=fluka_v2024.tar.gz.encrypted |
| 225 | + |
| 226 | +# Encryption Configuration |
| 227 | +S3_ENCRYPTION_PASSWORD=my-secure-password |
| 228 | +S3_ENCRYPTION_SALT=my-salt-value |
| 229 | +``` |
0 commit comments