Spaces:
Sleeping
Sleeping
File size: 9,561 Bytes
310e4a9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | # CDPR Simulator β runbook
Two execution modes, two workflows each. The CLI is the guaranteed
fallback whenever the browser path misbehaves.
```
+----------------------------------------+
| You β PowerShell or browser |
+----------------+------------------------+
|
+------------------------+--------------------------+
| |
v v
+-------------+ +---------------------+
| PowerShell | | Browser (Streamlit) |
| CLI scripts | | + FastAPI on Render|
+------+------+ +----------+----------+
| |
v v
+-------------+ +----------------+ +-----------------+
| scripts/ | | streamlit_app | | cdpr.interface |
| run_simu | | gui.py | | .api (FastAPI) |
| train_csv | | upload panel | | /simulate /plot |
| compare | | | | /workspace |
+-----+-------+ +--------+-------+ +--------+--------+
| | |
+---------+---------------+--------------------------+
|
v
+------------------+
| cdpr scientific | <-- single source of truth (numpy/scipy)
| core | 195 tests, both 3.11 and 3.12 green
+------------------+
```
## Mode 1 β defined-trajectory simulation
### PowerShell
```powershell
# Defaults: ipanema_class, circle, 1.5 s, dt = 2 ms.
python scripts\run_simulation.py
# Full-circle 2-revolution sweep with the parameters from the directive.
python scripts\run_simulation.py `
--robot ipanema_class `
--kind circle `
--radius 1.0 `
--duration 125 `
--dt 1e-3 `
--center 0 0 0.5 `
--open
# Any robot x any trajectory --- 4 x 4 combinations all validated.
python scripts\run_simulation.py --robot cogiro_class --kind lissajous --duration 30 --open
python scripts\run_simulation.py --robot planar_translational --kind line --duration 2
python scripts\run_simulation.py --robot point_mass_3d --kind hold --duration 1
# No plots --- CSV + manifest only (~5 s for a 125 s run).
python scripts\run_simulation.py --duration 125 --no-plots
```
Output (per run) under `out/<robot>-<kind>-<timestamp>/`:
| Artifact | Notes |
|---|---|
| `timeseries.csv` | t, px/py/pz, qx/qy/qz/qw, vx/vy/vz, wx/wy/wz, L1..Lm, T1..Tm |
| `manifest.json` | git hash + python + request + runtime |
| `position.png` | translational components |
| `velocity.png` | linear velocity components |
| `angular_velocity.png` | wx, wy, wz |
| `acceleration.png` | finite-difference from velocity |
| `cable_tensions.png` | per-cable, with bound shading |
| `cable_lengths.png` | per-cable length over time |
| `cable_stretch.png` | (L β Lβ) per cable [mm] |
| `tracking_error.png` | βp β p_refβ |
| `rms_error_evolution.png` | cumulative RMS |
| `condition_number.png` | ΞΊβ of the structure matrix |
| `trajectory_xy.png` | actual + reference projection |
| `trajectory_xz.png` | actual + reference projection |
| `trajectory_yz.png` | actual + reference projection |
| `scene_3d.png` | end-of-run 3D scene with tension heatmap |
13 figure files per run for circle/line/lissajous; 12 for hold (no
tracking-error overlay).
### Browser
1. Open the live console: `https://cdprsimulator-a5u8bciz6tsnsxegg8zys2.streamlit.app`.
2. Configure the sidebar widgets (robot, kind, duration, dt, β¦).
3. Click **Run simulation** in the top action bar.
4. Each tab carries a **Render** button β figures are lazy because the
free Streamlit Cloud worker has only ~1 GB. The 3D scene tab is
marked *heavy* and is opt-in.
5. The **Diagnostics** expander at the bottom reports build id +
Streamlit version + matplotlib backend + session-state keys.
6. If the page ever blanks: set the `CDPR_GUI_DIAG=1` secret in
Streamlit Cloud β Settings β Secrets and reboot. The page swaps to
a one-button counter that confirms whether the worker itself is
healthy. While Streamlit Cloud is misbehaving, use the CLI above.
### FastAPI (deployed on Render)
```powershell
# Warm the worker (~50 s cold start the first time).
.\scripts\call_render.ps1 -Action health
# Run a simulation through the deployed API.
.\scripts\call_render.ps1 -Action simulate -Robot ipanema_class -Kind circle
# Render a plot server-side, save the returned PNG locally, open it.
.\scripts\call_render.ps1 -Action plot -PlotKind cable_tensions -OpenPng
# Workspace scan.
.\scripts\call_render.ps1 -Action workspace -Robot ipanema_class
```
Outputs land in `out\render-<timestamp>\`.
## Mode 2 β CSV-driven training / replay / comparison
### PowerShell
The same `timeseries.csv` produced in Mode 1 is the input here. Five
workflows; the ones whose extras are not installed exit cleanly with
the install hint (never with a silent traceback).
```powershell
# Analytic replay --- no extras needed, near-machine-precision against
# the recorded tensions.
python scripts\train_from_csv.py `
--input out\<robot>-<kind>-<stamp>\timeseries.csv `
--model replay
# Supervised MLP inverse-dynamics fit.
python scripts\train_from_csv.py `
--input out\<stamp>\timeseries.csv `
--model mlp --epochs 80
# Physics-informed variant.
python scripts\train_from_csv.py `
--input out\<stamp>\timeseries.csv `
--model pinn --epochs 80
# PPO evaluation (requires cdpr[rl]).
python scripts\train_from_csv.py `
--input out\<stamp>\timeseries.csv `
--model ppo --rl-steps 5000 --eval-episodes 3
# SAC evaluation.
python scripts\train_from_csv.py `
--input out\<stamp>\timeseries.csv `
--model sac --rl-steps 5000 --eval-episodes 3
# Cross-model comparison (runs each as a subprocess, ranks by RMSE).
python scripts\compare_models.py `
--input out\<stamp>\timeseries.csv `
--models replay mlp pinn `
--out out\compare-<stamp> `
--epochs 80
```
Per-model output under `out\<stamp>\<model>\` (or under
`out\compare-<stamp>\<model>\` when launched through the comparator):
* `loss.png` β training / validation loss
* `pred_vs_truth.png` β predicted vs recorded cable tensions
* `residuals.png` β error histogram + per-cable boxplot
* `metrics.json` β RMSE / MAE / per-cable error
* `manifest.json` β git hash + python + hyper-params
Comparison root (`out\compare-<stamp>\`):
* `compare_rmse.png` β per-model RMSE bar chart (log scale)
* `compare_runtime.png` β per-model wall time
* `compare_overview.png` β mean tension overlay vs ground truth
* `compare_table.png` β model / RMSE / wall-time table
* `ranking.json` β sorted ranking
* `compare_metrics.json` β full per-model metric blob
### Browser
The Streamlit upload panel now mirrors Mode 2 inline:
1. Run a Mode-1 simulation (CLI or browser); copy / drop the
`timeseries.csv` into the **Phase 2 β upload an experimental log**
block at the bottom of the page.
2. The CSV head appears as a 50-row preview.
3. Click **Quick PINN fit** β runs a 30-epoch supervised fit (~1 s
on the deployed worker) and displays the loss + prediction overlay
inline. RMSE / MAE land in the displayed metrics JSON.
4. Click **Quick replay** β replays the sidebar configuration's
analytic trajectory against the CSV's tension columns and overlays
them.
5. **Clear analysis** wipes the cached figures so the worker memory
stays light.
## Local FastAPI + local Streamlit
```powershell
# Backend on http://localhost:8000
uvicorn cdpr.interface.api:app --reload --port 8000
# Console (in another terminal) on http://localhost:8501
streamlit run streamlit_app.py
```
When the local Streamlit is running, set `$env:CDPR_GUI_FRUGAL=0`
beforehand to lift the default-duration cap from 0.5 s to 1.5 s.
## Diagnostics that exist when things go wrong
| Symptom | First check | Recovery path |
|---|---|---|
| Streamlit Cloud page blank | Browser hard-refresh (Ctrl+F5) | Set `CDPR_GUI_DIAG=1` in Streamlit Cloud β Settings β Secrets, reboot. If the diagnostic page also blanks, the worker is unhealthy β use the CLI escape hatches above. |
| Render `/simulate` returns 502 | The free tier slept after 15 min idle | Wait ~50 s; the first `Action health` call wakes it. |
| CLI `--model pinn` says "torch not installed" | The dev install was viz/data only | `pip install -e ".[learn]"` |
| CLI `--model ppo` says "stable_baselines3 not installed" | Same | `pip install -e ".[rl]"` |
| CI flagged a test | GH Actions β latest run β expand "Run pytest" | The `-v --tb=short` flags surface the failing test name and traceback. |
## Service URLs
| Layer | URL |
|---|---|
| GitHub repo | <https://github.com/Tachia/cdpr_simulator> |
| Render FastAPI | <https://cdpr-api.onrender.com> (`/health`, `/robots`, `/simulate`, `/plot`, `/workspace`, `/docs`) |
| Cloudflare Pages docs | <https://cdpr-simulator.pages.dev> |
| Streamlit research console | <https://cdprsimulator-a5u8bciz6tsnsxegg8zys2.streamlit.app> |
| Supabase Postgres | `db.nohbtlhhisfiajjsbguy.supabase.co` (CLI only) |
| GitHub Actions CI | <https://github.com/Tachia/cdpr_simulator/actions> |
|