refactor(SR): freeze compact legacy evidence package

Archive excluded experiments and superseded outputs so the active tree exposes only the auditable Kármán and Illusion workflow while preserving scientific provenance.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Frank14f
2026-08-06 22:16:53 +08:00
co-authored by Cursor
parent b702fb7300
commit 7323a235f4
576 changed files with 462 additions and 953 deletions
+49 -322
View File
@@ -1,358 +1,85 @@
# Article SR pipeline # Frozen SR pipeline
This is the authoritative execution and design document for `SR_analysis`. Read `README.md` first for the scientific summary and current conclusions. ## Authority
## 1. Method in one diagram The only active route is:
```mermaid
flowchart LR
contracts[Channel and causal contracts] --> data[PPO trajectories]
data --> perCase[Per-case broad discovery]
perCase --> joint[Within-objective joint discovery]
joint --> refit[Fixed-topology all-data refit]
refit --> safety[Static and replay safety]
safety --> shortCFD[Short serial CFD]
shortCFD --> standardCFD[200-step legacy DTW]
standardCFD --> longCFD[400-step duration check]
longCFD --> generalization[Unseen-condition CFD]
standardCFD --> steady[Steady-cloak calibration]
standardCFD --> ablation[Term deletion and scaling]
steady --> interpretation[Physical interpretation and limits]
generalization --> interpretation
ablation --> interpretation
```
The workflow has one scientific route:
```text ```text
stage_1_infer.py -> stage_2_fit.py -> stage_3_validate.py stage_1_infer.py -> stage_2_fit.py -> stage_3_validate.py
``` ```
Checks and diagnostics gate or interpret this route; they do not create a parallel pipeline. It covers Kármán and Illusion. The `steady` Stage 3/config scene is retained solely for the Article2 constant-rotation calibration used to interpret the Kármán rear constant. Current evidence is indexed by `results/README.md`; archived workflows are non-authoritative and may not execute.
## 1.1 Article2 extension commands ## Preconditions and immutable contracts
All CFD commands remain serialized and use physical GPU 2. `--device 0` is the logical device after masking. Use LegacyCelerisLab, its frozen PPO model, and the scene's frozen norm. Keep native body/action order `front, upper, lower`, native force order `front_fx, front_fy, upper_fx, upper_fy, lower_fx, lower_fy`, and sensor order upper/centre/lower `(u_x,u_y)`. Run `checks/order_contract.py` after any solver/kernel change and `checks/policy_replay.py` before admitting data.
The fit alignment is exactly `causal_post_state_to_next_action`: post-state `i` predicts decoded physical action `i+1`; no lag, derivative, split, or warm-up state crosses a trajectory boundary. Formula output is `alpha=omega/U0`. Canonical deployment is mapped-shared under reflection `G`: `alpha_F=(h_F(x)-h_F(Gx))/2`, `alpha_U=h_R(x)`, `alpha_L=-h_R(Gx)`.
The validation metric is exactly `legacy_dtw_v1_abs_n_unclipped` / `legacy_reference_cycle_vs_last_recorded_cycle`: estimate lag from transverse sensor channel 1 using the historical target/reference windows, circularly shift the full target, compute absolute normalized unclipped DTW independently for six channels, then average. Lag is alignment metadata, not a physical delay.
Interpret names literally: `Re_D=re_code/2` because the code Reynolds reference is `2D`; the Illusion `target_diameter` field is historically named but passed as the Legacy cylinder radius.
## Stage 1 — collect accepted trajectories
Environment: `pycuda_3_10`. CFD is serial. With physical GPU 2 masked, PyCUDA sees logical device 0; keep PPO inference on CPU.
```bash ```bash
CUDA_VISIBLE_DEVICES=2 PYTHONPATH=src conda run -n pycuda_3_10 \ CUDA_VISIBLE_DEVICES=2 PYTHONPATH=src conda run -n pycuda_3_10 python src/SR_analysis/stage_1_infer.py --group karman_trained --run-id <run> --device 0 --model-device cpu --steps 200 --norm-source existing
python src/SR_analysis/stage_3_validate.py --scene steady --mode constant \ CUDA_VISIBLE_DEVICES=2 PYTHONPATH=src conda run -n pycuda_3_10 python src/SR_analysis/stage_1_infer.py --group illusion_trained --run-id <run> --device 0 --model-device cpu --steps 200 --norm-source existing
--constant-alpha 0 -5 5 --device 0 --steps 200 \
--run-id article2-steady-sweep-a5-20260720
CUDA_VISIBLE_DEVICES=2 PYTHONPATH=src conda run -n pycuda_3_10 \
python src/SR_analysis/stage_3_validate.py --group karman_re50,karman_re100,karman_re200,karman_re400 \
--mode pysr --formula-front <front.json> --formula-rear <rear.json> \
--device 0 --steps 400 --run-id article2-long-karman-20260720
CUDA_VISIBLE_DEVICES=2 PYTHONPATH=src conda run -n pycuda_3_10 \
python src/SR_analysis/stage_3_validate.py --group karman_re25,karman_re70,karman_re150,karman_re300 \
--mode pysr --formula-front <front.json> --formula-rear <rear.json> \
--device 0 --steps 200 --run-id article2-gen-karman-20260720
``` ```
Illusion uses the corresponding article topology-A formulas and either the three training scenes for the duration test or `--group illusion_generalization`. Generalization PySR deployment does not require a PPO normalization file; target harmonics remain frozen per scene. Outputs are immutable beneath `data/runs/<run>/<objective>/<scene>/` and include config, manifest, hashes, frozen norm, target, controlled telemetry, and result; Kármán also retains uncontrolled data and Illusion target harmonics. The canonical accepted roots are the two `article-joint-data-*-20260718` families.
Export any Stage 1 or Stage 3 trajectory with: ## Stage 2 — discover then refit
Environment: `sr_env`. Start broad with `raw_complete` and `symmetry`; for Illusion compare `actual_only`, `target_only`, `actual_plus_target`, and `actual_plus_error`. Run per-case searches with multiple seeds, then joint searches only within one objective. Keep contiguous train/validation/blind diagnostics and case/trajectory-equal weighting.
```bash ```bash
PYTHONPATH=src conda run -n pycuda_3_10 python -m SR_analysis.tools.telemetry_to_csv \ PYTHONPATH=src conda run -n sr_env python src/SR_analysis/stage_2_fit.py --scenes karman_re50,karman_re100,karman_re200,karman_re400 --mode joint --run-id <discovery> --data-root src/SR_analysis/data/runs/article-joint-data-karman-20260718 --feature-set symmetry --feature-profile actual_only --deployment-architecture mapped_shared --fit-augmentation G --fit-purpose discovery --seed 0 --niterations 40 --smoke
--input <trajectory.npz> --target <target.npz> --output-dir <csv-dir> \
--scene <scene> --source ppo --sample-interval <SI> --conv-len <N>
``` ```
The exporter writes wide and long CSV files, target tables, manifests and legacy-DTW window convergence diagnostics. For Stage 3 telemetry use `--source sr`; embedded target sensors are used automatically. After topology recurs and survives diagnostics, freeze it and run `--fit-purpose fixed-topology-refit` with explicit front/rear topology expressions and discovery-parent paths. Only coefficients may change. Do not rewrite article parent paths or manifests. PySR score, Pareto complexity, blind R², and static safety are discovery evidence only.
Build the complete derived plotting package from immutable article artifacts with: ## Stage 3 — closed-loop acceptance
Environment: `pycuda_3_10`; run one CFD process at a time. Screen at 40 steps, then validate accepted candidates for 200 steps with a new immutable run ID.
```bash ```bash
PYTHONPATH=src conda run -n sr_env python -m SR_analysis.tools.prepare_plotting_data \ CUDA_VISIBLE_DEVICES=2 PYTHONPATH=src conda run -n pycuda_3_10 python src/SR_analysis/stage_3_validate.py --group karman_re50,karman_re100,karman_re200,karman_re400 --mode pysr --formula-front <front.json> --formula-rear <rear.json> --device 0 --steps 200 --run-id <run>
--output-dir src/SR_analysis/results/runs/article2-plotting-package-<date>
``` ```
This creates causal PPO-state predictions/residuals, feature and additive-term contributions, unified ablation/scaling summaries and steady-sweep time series. Render diagnostic PNG/PDF figures in an environment containing Matplotlib with `python -m SR_analysis.tools.plot_sr_diagnostics`. For 400-step PPO CFD, keep `--model-device cpu`; GPU 2 is reserved for the active PyCUDA context. Reject any case that is non-finite, terminates early, violates action/order/schema contracts, or lacks required provenance. Retain rejected telemetry. Closed-loop stability and exact legacy DTW outrank offline fit.
## 2. Design decisions ## Extensions and necessity tests
### Why fit PPO actions? Use the frozen accepted coefficients for 400-step duration runs, pointwise unseen Kármán Re-code and Illusion size-label conditions, the disturbance-free `steady` constant-rotation sweep, and deterministic additive-term deletion/coefficient scaling (`0, 0.5, 0.75, 1, 1.25, 1.5`). These are sampled deployments, not a continuous parameter law or statistical robustness study. A term is important only if deletion causes repeatable closed-loop degradation; scale zero must agree with deletion and parent formulas remain immutable.
The PPO policy supplies successful state-action trajectories. Fitting its dimensionless physical actions provides candidate feedback structures without rerunning symbolic search inside CFD. The fitted expression is a policy surrogate, not a NavierStokes equation. ## Publication exports
### Why not select the highest R² formula?
A candidate changes the closed-loop state distribution after deployment. A formula can imitate PPO actions well on recorded states and still drift or become unstable in CFD. R² and Pareto complexity are therefore used to discover recurring variables and topologies; CFD stability and legacy DTW decide closed-loop value.
### Why per-case before joint?
Per-case searches reveal whether variables and topologies recur across operating conditions. Joint search begins only after broad variables have been considered, preventing a compact hand-selected library from predetermining the mechanism.
### Why freeze topology before the final coefficient fit?
Unrestricted symbolic search on all rows would use the blind data for structure selection. The workflow first selects topology from discovery runs, then refits only its numerical constants using all accepted trajectories with case-equal and trajectory-equal weighting. The refit records its parent discovery artifact.
### Why exact G deployment?
The geometry and objective are reflection-symmetric, while the legacy PPO was not trained with an equivariance constraint. The final architecture deliberately imposes physical symmetry:
\[
\alpha_F(x)=\frac{h_F(x)-h_F(Gx)}{2},\quad
\alpha_U(x)=h_R(x),\quad
\alpha_L(x)=-h_R(Gx).
\]
This is physical symmetrization, not a claim that PPO itself is exactly equivariant. Three independent heads are retained only for diagnostic structure discovery.
### Why no automatic lag search?
For Illusion, target and actual forces share a causal deployment timeline. Cross-correlation can produce a statistically useful shift without identifying a physical delay. Temporal/derivative features are introduced only after controlled static-variable comparisons show insufficiency. DTW lag is reported as part of the legacy metric, not interpreted as control delay.
### Why separate Kármán and Illusion joint fits?
They are different objectives. Kármán seeks restoration of an incident wake; Illusion seeks a non-zero target wake. Joint means shared structure within one objective, not one formula across unrelated policies.
## 3. Contracts and gates
### Physical labels
Kármán names use `re_code`, whose reference length is `2D`; report \(Re_D=\texttt{re\_code}/2\) whenever the physical Reynolds number is intended. Illusion names are legacy target-size labels. Despite the historical field name `target_diameter`, the value is passed to `LegacyCelerisLab.add_cylinder` as its `radius` argument. Rear symmetric and antisymmetric force coordinates are half-sums and half-differences, so changing that convention would rescale fitted coefficients.
A run may proceed to fitting only when all applicable gates pass.
### Physical order gate
Canonical orders:
- body/action: `front, upper, lower`
- forces: `front_fx, front_fy, upper_fx, upper_fy, lower_fx, lower_fy`
- sensors: upper, centre, lower, each with streamwise/transverse components
Run after CFD/kernel changes:
```bash ```bash
CUDA_VISIBLE_DEVICES=2 PYTHONPATH=src conda run -n pycuda_3_10 \ PYTHONPATH=src conda run -n sr_env python -m SR_analysis.tools.prepare_plotting_data --output-dir src/SR_analysis/results/runs/article2-plotting-package-<date>
python -m SR_analysis.checks.order_contract \ PYTHONPATH=src conda run -n sr_env python -m SR_analysis.tools.plot_sr_diagnostics
--scene karman_re100 --device 0 \ PYTHONPATH=src conda run -n sr_env python -m SR_analysis.tools.plot_sr_presentation
--output src/SR_analysis/results/runs/<run_id>/karman_re100.json
``` ```
Repeat for `illusion_1L`. The impulse response is diagnostic; object IDs, centres and slot mapping define the contract. `telemetry_to_csv.py` exports Stage 1/3 trajectories and exact DTW-window diagnostics. `export_flow_comparison.py` defines the same-sample phase-matched field-comparison contract; generating flow fields requires separate serial GPU CFD and is not part of CPU verification.
### Temporal gate ## Acceptance hierarchy and claim limits
The article alignment is `causal_post_state_to_next_action`. Post-state `i` predicts normalized PPO action `i+1`. Warm-up rows are removed. Each trajectory is processed independently before stacking. 1. Contract and provenance integrity.
2. Finite closed-loop completion for every required case.
3. Exact legacy DTW at standard duration.
4. Duration and explicitly sampled unseen-condition behavior.
5. Deletion/scaling evidence for term necessity.
6. Physical interpretation, stated as limited by the preceding evidence.
### PPO wiring gate Supported: reproducible PPO-to-symbolic reduction; dominant Kármán rear counter-rotation with secondary rear-lift feedback; a finite symmetric Illusion numerical family; and pointwise Article2 extension at named samples. Unsupported: global/unique symbolic optimality, universal Re or size generalization, explicit Illusion target-tracking mechanism, necessity of every Illusion term, causal flow structures, or physical delay inferred from DTW lag.
## Exact CPU verification
```bash ```bash
PYTHONPATH=src conda run -n pycuda_3_10 \ PYTHONPATH=src conda run -n sr_env python -m pytest src/SR_analysis/tests -q
python -m SR_analysis.checks.policy_replay \ python3 -m compileall -q src/SR_analysis/configs.py src/SR_analysis/stage_1_infer.py src/SR_analysis/stage_2_fit.py src/SR_analysis/stage_3_validate.py src/SR_analysis/utils src/SR_analysis/checks src/SR_analysis/tools
--scene <scene> \ git diff --check -- src/SR_analysis
--trajectory <run>/<objective>/<scene>/controlled.npz \
--model-device cpu \
--output <result>.json
``` ```
The seven article trajectories passed with zero action replay error.
### Artifact gate
- Existing non-empty run directories are not overwritten.
- Formula strings, formula files, telemetry and validations carry hashes.
- Integrity audit never grants scientific promotion; `promotion_eligible` defaults to false.
- Failed and incomplete validations remain rejected evidence.
## 4. Stage 1: collect article data
Environment: `pycuda_3_10`. CFD is serial on physical GPU 2. Isolate physical GPU 2 with `CUDA_VISIBLE_DEVICES=2`, then select logical device 0.
Kármán:
```bash
CUDA_VISIBLE_DEVICES=2 PYTHONPATH=src conda run -n pycuda_3_10 \
python src/SR_analysis/stage_1_infer.py \
--group karman_trained \
--run-id <karman_data_run> \
--device 0 --model-device cpu --steps 200 --norm-source existing
```
Illusion:
```bash
CUDA_VISIBLE_DEVICES=2 PYTHONPATH=src conda run -n pycuda_3_10 \
python src/SR_analysis/stage_1_infer.py \
--group illusion_trained \
--run-id <illusion_data_run> \
--device 0 --model-device cpu --steps 200 --norm-source existing
```
Outputs:
```text
data/runs/<run_id>/<objective>/<scene>/
config.json
controlled.npz
manifest.json
norm.json
result.json
target.npz
target_harmonics.json # Illusion
uncontrolled.npz # Kármán Stage 1 baseline asset
```
The article run uses 200 recorded rows per scene and 197 aligned Stage 2 rows after warm-up/causal alignment.
## 5. Stage 2A: per-case broad discovery
Environment: `sr_env`.
Use complete variable representations first:
- `raw_complete`
- `symmetry`
For Illusion, compare:
- `actual_only`
- `target_only`
- `actual_plus_target`
- `actual_plus_error`
Example diagnostic three-head discovery:
```bash
PYTHONPATH=src conda run -n sr_env \
python src/SR_analysis/stage_2_fit.py \
--scene karman_re100 --mode per-scene \
--run-id <discovery_run> \
--data-root <karman_data_run_root> \
--feature-set symmetry --feature-profile actual_only \
--deployment-architecture three_head_independent \
--fit-augmentation none \
--fit-purpose discovery \
--seed 0 --niterations 20 --smoke
```
Repeat for at least three seeds. `--smoke` in the article discovery denotes the bounded PySR population/complexity configuration; the resulting candidates are still diagnostic until CFD validation.
Up to 25 retained Pareto candidates per fitted head record:
- expression and used variables
- complexity/loss/PySR score
- contiguous train/validation/blind R², MAE, RMSE and max error
- static finite-value probing over observed feature ranges (not a global action-range guarantee)
- seed, feature set, data and trajectory provenance
The blind block is not used for fitting.
## 6. Stage 2B: within-objective joint discovery
Kármán example:
```bash
PYTHONPATH=src conda run -n sr_env \
python src/SR_analysis/stage_2_fit.py \
--scenes karman_re50,karman_re100,karman_re200,karman_re400 \
--mode joint --run-id <joint_discovery_run> \
--data-root <karman_data_run_root> \
--feature-set symmetry --feature-profile actual_only \
--deployment-architecture mapped_shared \
--fit-augmentation G --fit-purpose discovery \
--seed 0 --niterations 40 --smoke
```
Illusion uses the three trained diameters and separate profile comparisons. Joint fitting is accepted only when scene objective, feature order, action order and action conversion contracts match.
If multiple data roots are accepted, provide repeated `--data-root` arguments or comma-separated `--data-roots`. Every trajectory is constructed and split independently. Joint PySR receives explicit case-equal, trajectory-equal sample weights.
## 7. Stage 2C: fixed-topology refit
Freeze a recurring topology before using all eligible rows. Example:
```bash
PYTHONPATH=src conda run -n sr_env \
python src/SR_analysis/stage_2_fit.py \
--scenes karman_re50,karman_re100,karman_re200,karman_re400 \
--mode joint --run-id <refit_run> \
--data-root <karman_data_run_root> \
--feature-set symmetry --feature-profile actual_only \
--deployment-architecture mapped_shared --fit-augmentation G \
--fit-purpose fixed-topology-refit \
'--front-topology-expression=-0.377*Cd_rear_a' \
'--rear-topology-expression=1.0*Cl_rear_s-3.398' \
--front-discovery-parent-path <joint_front.json> \
--rear-discovery-parent-path <joint_rear_shared_upper.json>
```
Only numerical constants are optimized. Outputs report aggregate, per-case and per-trajectory errors and retain discovery-parent hashes.
## 8. Stage 3: closed-loop screening
Environment: `pycuda_3_10`, physical GPU 2, one CFD process at a time.
Short screening:
```bash
CUDA_VISIBLE_DEVICES=2 PYTHONPATH=src conda run -n pycuda_3_10 \
python src/SR_analysis/stage_3_validate.py \
--group karman_re50,karman_re100,karman_re200,karman_re400 \
--mode pysr \
--formula-front <joint_front.json> \
--formula-rear <joint_rear_shared_upper.json> \
--device 0 --steps 40 --run-id <L2_run>
```
Standard validation changes `--steps` to 200 and uses a new run ID.
The only active metric is `legacy_dtw_v1_abs_n_unclipped`, reported under `legacy_reference_cycle_vs_last_recorded_cycle`. It estimates lag from transverse sensor channel 1 between target samples `conv_len:2*conv_len` and the final controlled `conv_len` samples, circularly shifts the complete target sequence, computes absolute normalized unclipped DTW similarity independently for all six sensor channels, and reports their arithmetic mean. The lag is an alignment parameter, not a physical delay. Every validation stores per-channel values, lag, action ranges, termination, telemetry hash, formula hashes, scene config and GPU identity.
A candidate is rejected if any training case becomes non-finite or terminates early. Averages do not hide case failures.
## 9. Term necessity and coefficient robustness
`utils/formula_schema.py` deterministically decomposes top-level additive terms and creates immutable formula variants.
For each shortlisted law:
1. delete each term;
2. delete physically linked groups where necessary;
3. scale each term with the preregistered grid `0, 0.5, 0.75, 1, 1.25, 1.5`;
4. run recorded-state shadow checks for finite values and action ranges;
5. send only informative variants to short CFD.
A term is called important only when deletion causes repeatable closed-loop degradation. Scale zero must agree with deletion. The parent formula is never mutated.
## 10. Article evidence and interpretation
The current authoritative evidence chain is indexed by `results/README.md` and ends at:
```text
results/runs/article-joint-sr-final-20260718/
readable_summary.txt
evidence_manifest.json
```
Current conclusions:
- Kármán: rear constant is dominant, rear lift feedback is secondary, tested front feedback is weak; high-Re performance remains a limitation.
- Illusion: a symmetric numerical family exists, but terms are replaceable and static target/error variables do not establish explicit target tracking; 1.5L is the weakest/different regime.
The manuscript draft must preserve these distinctions and must not import older historical numbers as current evidence.
## 11. Historical and inactive material
- `results/formulas/`, `results/validations/`, `scene_registry.json`, `old/` and old docs are `historical_frozen` context.
- `round1-legacy-v2-20260716-*` is diagnostic only because it predates the final force-order contract.
- `experiments/v5/` is a separate excluded experiment.
- `archive/stage4/` and `archive/stage_docs/` are inactive publication tooling/history.
- `diagnostics/` outputs do not become mechanism claims without closed-loop validation.
## 12. Tests
Run from the repository root:
```bash
PYTHONPATH=src conda run -n sr_env python -m pytest \
src/SR_analysis/tests tests/test_stage_3_validate.py -q
```
Expected result at the 2026-07-21 plotting-package revision: `88 passed`.
+34 -234
View File
@@ -1,254 +1,54 @@
# SR analysis: agent entry point # SR analysis
This directory contains the active symbolic-regression analysis for extracting compact control laws from the legacy PPO policies of the fluidic pinball. ## Authority and scope
**Start here, then read `PIPELINE.md`.** The active scientific workflow has exactly three entry points: This directory is the frozen symbolic-regression evidence package for the LegacyCelerisLab fluidic pinball. The active scientific scope is Kármán-cloak and Illusion PPO data collection, symbolic discovery/refit, closed-loop CFD validation, sampled duration/generalization extensions, term deletion/scaling, and canonical publication export. The disturbance-free `steady` scene remains only as the calibration used to interpret the Kármán rear constant.
1. `stage_1_infer.py` — collect run-scoped PPO trajectories. The authoritative evidence index is `results/README.md`; execution details are in `PIPELINE.md`. Material under `archive/` is historical, excluded, or non-authoritative.
2. `stage_2_fit.py` — discover and refit symbolic structures.
3. `stage_3_validate.py` — evaluate formulas in closed-loop CFD with the legacy DTW metric.
The current article evidence is indexed in `results/README.md`. The manuscript-ready SR section is `../../docs/JFM_WYQ/SR_Draft.md`. ## Three-stage workflow
## Scientific question 1. `stage_1_infer.py`: collect immutable, run-scoped Legacy PPO trajectories for trained Kármán and Illusion scenes.
2. `stage_2_fit.py`: perform broad per-case discovery, within-objective joint discovery, and fixed-topology all-data coefficient refit.
3. `stage_3_validate.py`: deploy PPO, symbolic, uncontrolled, or constant policies in serial Legacy CFD and evaluate the exact legacy DTW contract.
SR is not used to maximize imitation of PPO actions. It is used to determine whether successful PPO control contains a compact, symmetric and physically interpretable feedback structure that remains effective when deployed in CFD. The acceptance chain is data and wiring checks → offline discovery/Pareto diagnostics → frozen topology and coefficient refit → finite closed-loop CFD → 200-step acceptance → 400-step duration and sampled unseen-condition checks → term deletion/scaling. Offline R² helps discover structure; it does not accept a controller. Averages never override a non-finite or prematurely terminated case.
The selection chain is therefore: ## Scientific contracts
```text - **Solver/model/norm:** Stage 1 and Stage 3 use LegacyCelerisLab and the frozen legacy PPO models. Runtime PPO observations use the scene's frozen `data/karman/**/norm.json` or `data/illusion/**/norm.json`; PPO inference defaults to CPU while PyCUDA owns the CFD GPU.
PPO trajectories - **Native order:** bodies/actions are `front, upper, lower`; forces are front, upper, lower with `(x,y)` components; sensors are upper, centre, lower with `(u_x,u_y)` components. `checks/order_contract.py` is the runtime gate.
-> broad per-case variable/topology discovery using R² and Pareto fronts - **Causal alignment:** Stage 2 uses `causal_post_state_to_next_action`: recorded post-state `i` predicts action `i+1`. Warm-up and lag construction are trajectory-local and splits do not cross trajectories.
-> within-objective joint topology discovery - **Action units:** formulas output `alpha = omega/U0`. PPO normalized actions are decoded with the scene scale and bias before fitting; Stage 3 converts formula outputs back to `omega` for CFD.
-> fixed-topology coefficient refit using all accepted rows - **Mapped-shared deployment:** the canonical architecture is `alpha_F=(h_F(x)-h_F(Gx))/2`, `alpha_U=h_R(x)`, `alpha_L=-h_R(Gx)`. This imposes exact reflection symmetry; it is not a claim that PPO training was equivariant. Three independent heads are diagnostic only.
-> short and standard closed-loop CFD screening using legacy DTW - **Metric:** `legacy_dtw_v1_abs_n_unclipped`, reported as `legacy_reference_cycle_vs_last_recorded_cycle`, is the exact acceptance metric. Its fitted circular lag is part of the historical comparison algorithm, not a physical delay.
-> term-deletion and coefficient-scaling tests - **Names:** Kármán scene `re_code` uses reference length `2D`, so `Re_D=re_code/2`. Illusion labels such as `1L` are historical: the stored `target_diameter` value is passed to `add_cylinder` as a radius and must not be silently relabelled as a physical diameter.
-> physical interpretation and explicit limitations
```
R² is a discovery diagnostic. It is not the acceptance criterion. Closed-loop stability and DTW decide whether a candidate is useful; deletion and scaling tests decide whether its terms are necessary. ## Current claim and evidence chain
## Current article scope Accepted training data are `data/runs/article-joint-data-karman-20260718` (Re-code 50/100/200/400) and `data/runs/article-joint-data-illusion-20260718` (0.75L/1L/1.5L). Formula discovery, refits, accepted and rejected CFD, 400-step duration, sampled unseen points, deletion/scaling, steady calibration, and plotting are retained under `results/runs/article-*` and `results/runs/article2-*` because their manifests and parent paths are provenance dependencies.
Two objectives are fitted separately: The Kármán evidence supports a controller dominated by persistent rear counter-rotation, with secondary rear-lift feedback and weak tested front feedback. The steady sweep calibrates the rear constant's magnitude; it is not a third fitting objective. The Illusion result is a finite symmetric numerical family, but its terms are partly replaceable and it does not establish explicit target tracking. Neither result proves global symbolic optimality, causal flow mechanism, universal high-Re behavior, or distribution-wide generalization; Article2 supports only the explicitly sampled conditions.
- **Kármán cloaking:** `karman_re50`, `karman_re100`, `karman_re200`, `karman_re400`. ## Active package map
- **Illusion:** `illusion_0.75L`, `illusion_1L`, `illusion_1.5L`.
Kármán and Illusion are never pooled into one fit. The fitted evidence is limited to these seven training scenes. The coefficient-frozen 2026-07-20 extension tests additional Reynolds-number and target-size points, but those points did not participate in fitting or model selection. Vortex, V5 and historical figures remain outside the current article evidence. - Root: `configs.py`, the three stages, this README, and `PIPELINE.md`.
- `checks/`: order and policy-replay gates.
Seven new 200-step PPO trajectories were collected in: - `utils/`: active data, feature, symmetry, metric, formula, CFD, and provenance contracts.
- `tools/`: canonical plotting/export tools (`prepare_plotting_data.py`, `telemetry_to_csv.py`, both SR plotting modules, and `export_flow_comparison.py`).
- `data/runs/article-joint-data-karman-20260718/` - `tests/`: CPU contract tests.
- `data/runs/article-joint-data-illusion-20260718/` - `data/`: frozen Kármán/Illusion norms, steady calibration data, and the two accepted article data runs.
- `results/`: the evidence index and provenance-dependent `article-*`/`article2-*` families.
All seven passed exact recorded-state policy replay. The accepted data inventory is: - `archive/`: excluded experiments, diagnostics, old run families, superseded flat surfaces, and historical code/docs. Archive paths may be non-executable.
- `results/runs/article-joint-data-audit-20260718/data_inventory.json`
Historical and round-one assets are retained, but are not silently pooled with the article data. The old `round1-legacy-v2-20260716-*` formulas are diagnostic only because they predate the final force-order contract.
## Non-negotiable contracts
### Native order
The canonical body, force and action order is:
```text
front, upper, lower
```
Sensors are ordered upper, centre, lower. Verify runtime binding with `checks/order_contract.py` before collecting data after any CFD change.
### Alignment
The article workflow uses:
```text
causal_post_state_to_next_action
```
Recorded post-state `i` predicts action `i+1`. Each trajectory is built independently so lag features and contiguous splits never cross trajectory boundaries.
### Action definition
Formula outputs are dimensionless cylinder surface velocities:
\[
\alpha_i = \omega_i/U_0.
\]
Normalized PPO actions are decoded with the scene action scale and bias before fitting.
### Exact reflection symmetry
The article candidate uses mapped-shared deployment:
\[
\alpha_F(x)=\frac{h_F(x)-h_F(Gx)}{2},\qquad
\alpha_U(x)=h_R(x),\qquad
\alpha_L(x)=-h_R(Gx).
\]
The front projection is exactly odd. The lower action is generated from the shared upper law. Three-head-independent fitting exists only as a PPO-structure diagnostic and is not the final physical architecture.
Fit augmentation and deployment architecture are separate choices:
- `--fit-augmentation none|G`
- `--deployment-architecture mapped_shared|three_head_independent`
Hard G symmetry is a deliberate physical symmetrization; it is not presented as a property that the legacy PPO was trained to satisfy.
### Metric
The closed-loop metric is:
```text
legacy_dtw_v1_abs_n_unclipped
```
Its exact window is named:
```text
legacy_reference_cycle_vs_last_recorded_cycle
```
There are not separate “full” and “tail” DTW algorithms. Lag is part of the legacy comparison procedure and is not interpreted as a physical observation/control delay.
## Physical labels and units
The Kármán scene names contain the historical code Reynolds label `re_code`, defined with reference length `2D`; the cylinder-diameter Reynolds number is therefore \(Re_D=\texttt{re\_code}/2\). The Illusion names `0.75L`, `1L` and `1.5L` are legacy target-size labels: the stored `target_diameter` value is passed to `LegacyCelerisLab.add_cylinder` as a radius. Paper text must not silently reinterpret these labels as physical diameters.
SR uses dimensionless velocities and force coefficients, not the clipped PPO observation. Rear symmetry coordinates are half-sums and half-differences, for example
\[
C_{d,\mathrm{rear},s}=\frac{C_{d,U}+C_{d,L}}{2},\qquad
C_{d,\mathrm{rear},a}=\frac{C_{d,U}-C_{d,L}}{2},
\]
with the same convention for rear lift.
## Feature strategy
Broad discovery starts from complete, dimensionless variable representations:
- `raw_complete`: six velocity components and six cylinder-force components.
- `symmetry`: symmetric/antisymmetric velocity and force coordinates.
- `physics_reduced`: compact diagnostics only; it is not the starting point for article discovery.
Illusion comparisons use non-overlapping profiles:
- `actual_only`
- `target_only`
- `actual_plus_target`
- `actual_plus_error`
Target/error derivatives or other temporal features are added only after static variables are shown insufficient. Cross-correlation is never used to select a lag.
## Current results
### Kármán joint candidate
\[
\alpha_F=\operatorname{odd}\!\left[-0.381391\,C_{d,\mathrm{rear},a}\right],
\]
\[
\alpha_U=1.307782\,C_{l,\mathrm{rear},s}-3.431209,
\qquad
\alpha_L=-\alpha_U(Gx).
\]
Standard 200-step legacy DTW:
- Re50: `0.9543`
- Re100: `0.9427`
- Re200: `0.8560`
- Re400: `0.7827`
Deletion tests support the ordering:
```text
rear constant > rear lift feedback > front drag-asymmetry feedback
```
This is consistent with the physical hypothesis that persistent rear counter-rotation provides the principal downstream velocity-deficit compensation. The SR evidence ranks controller terms but does not establish the spatial momentum correction or causality; those claims require OID/CCD. The law is not uniformly strong at Re400 and must not be called universal.
### Illusion joint numerical candidate
\[
\alpha_F=\operatorname{odd}\!\left[-1.826604\,C_{d,\mathrm{rear},a}+2.064493\,C_{l,F}\right],
\]
\[
\alpha_U=1.254440\,C_{d,\mathrm{rear},a}-1.528074\,C_{l,F},
\qquad
\alpha_L=-\alpha_U(Gx).
\]
Standard 200-step legacy DTW:
- 0.75L: `0.8749`
- 1.0L: `0.9217`
- 1.5L: `0.8306`
Scaling tests show that the `Cl_F` terms dominate action magnitude; the `Cd_rear,a` terms are weaker and partly replaceable. Every one-term deletion remained stable, so the current expression is not a unique mechanism law. Target/error variables were available but were not selected stably by low-complexity static joint discovery. This is a numerical joint reference, not proof of explicit target tracking.
## What can and cannot be claimed
Supported:
- A complete, reproducible discovery-to-CFD-to-ablation workflow.
- Strong Kármán evidence for dominant rear counter-rotation and secondary rear lift feedback.
- A symmetric Illusion joint family that remains finite across all three trained target-size labels.
- R² and formula appearance alone are insufficient predictors of closed-loop value.
Not supported:
- Global symbolic optimality or uniqueness.
- A universal Kármán law at Re400.
- An explicit target-tracking mechanism for Illusion.
- Necessity of every Illusion term.
- Physical delay inferred from DTW lag or cross-correlation.
- Distribution-wide or universal generalization. The Article2 extension supports only finite pointwise deployment at its explicitly sampled unseen conditions.
## Directory map
```text
SR_analysis/
├── README.md # this agent entry point
├── PIPELINE.md # exact method, commands and design decisions
├── configs.py # scene and action contracts
├── stage_1_infer.py # PPO data collection
├── stage_2_fit.py # discovery and fixed-topology refit
├── stage_3_validate.py # closed-loop CFD and legacy DTW
├── checks/ # pre-fit physical/wiring gates
├── diagnostics/ # diagnostic-only analyses
├── utils/ # feature, G, formula, data and provenance contracts
├── tests/ # SR CPU contract tests
├── results/README.md # evidence index and result status
├── tools/ # integrity audit; audit is not scientific promotion
├── experiments/v5/ # excluded experimental pipeline
└── archive/ # inactive Stage 4 and historical guides
```
`old/`, `archive/`, `experiments/v5/`, historical formula directories and old reports are context only. They are not authoritative sources for article numbers.
## Environments and resource discipline
- Stage 1, policy replay and Stage 3: `pycuda_3_10`; PPO inference defaults to CPU so physical GPU 2 remains dedicated to the PyCUDA CFD context.
- Stage 2/PySR and coefficient refit: `sr_env`.
- CFD uses physical GPU 2 and is strictly serial.
- When `CUDA_VISIBLE_DEVICES=2`, the process uses logical device `0`; provenance records both visibility and GPU UUID rather than mislabelling the physical ordinal.
- Every run ID is immutable; failed telemetry is retained.
## Verification ## Verification
At the 2026-07-21 plotting-package revision, the SR contract suite contains 88 passing tests. Run from the repository root: From the repository root:
```bash ```bash
PYTHONPATH=src conda run -n sr_env python -m pytest \ PYTHONPATH=src conda run -n sr_env python -m pytest src/SR_analysis/tests -q
src/SR_analysis/tests tests/test_stage_3_validate.py -q python3 -m compileall -q src/SR_analysis/configs.py src/SR_analysis/stage_1_infer.py src/SR_analysis/stage_2_fit.py src/SR_analysis/stage_3_validate.py src/SR_analysis/utils src/SR_analysis/checks src/SR_analysis/tools
git diff --check -- src/SR_analysis
``` ```
See `PIPELINE.md` for reproducible commands and `results/README.md` for the exact evidence chain. No GPU CFD is part of this verification.
+12
View File
@@ -0,0 +1,12 @@
# SR archive
Content below this directory is historical, excluded from the active mainline, or non-authoritative. It is preserved to retain scientific history, rejected paths, diagnostics, and prior contracts; it must not be used as current article evidence without an explicit reconciliation.
Current evidence remains in:
- `../data/runs/article-joint-data-*` for accepted training trajectories;
- `../results/runs/article-*` and `../results/runs/article2-*` for discovery provenance, accepted/rejected CFD evidence, extensions, ablations, and publication outputs.
Archive categories include old code and stage guides, excluded V5 and Vortex work, diagnostic tools/results, superseded flat result surfaces, historical metadata/notes, and non-mainline data/run families. Archived files may retain historical absolute paths or imports and are not guaranteed to execute from their archived location.
To restore an archived workflow, use git history to recover the original tree and its contemporaneous environment and contracts. Do not move selected files back piecemeal or rewrite archived scientific artifacts merely to make them executable.

Before

Width:  |  Height:  |  Size: 412 KiB

After

Width:  |  Height:  |  Size: 412 KiB

Before

Width:  |  Height:  |  Size: 189 KiB

After

Width:  |  Height:  |  Size: 189 KiB

Before

Width:  |  Height:  |  Size: 234 KiB

After

Width:  |  Height:  |  Size: 234 KiB

Before

Width:  |  Height:  |  Size: 169 KiB

After

Width:  |  Height:  |  Size: 169 KiB

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

Before

Width:  |  Height:  |  Size: 167 KiB

After

Width:  |  Height:  |  Size: 167 KiB

Before

Width:  |  Height:  |  Size: 135 KiB

After

Width:  |  Height:  |  Size: 135 KiB

Before

Width:  |  Height:  |  Size: 299 KiB

After

Width:  |  Height:  |  Size: 299 KiB

Before

Width:  |  Height:  |  Size: 151 KiB

After

Width:  |  Height:  |  Size: 151 KiB

@@ -0,0 +1,196 @@
# SR Analysis: Symbolic Regression Report
## 1. Problem Definition
Deep reinforcement learning (DRL) can discover effective flow control strategies, but the resulting policies remain black boxes: they map high-dimensional sensor observations to actuator commands through opaque neural networks. This limits interpretability, transferability, and trust.
This work addresses the problem of **post-hoc white-box extraction** from trained DRL policies. Given a PPO policy that successfully achieves hydrodynamic cloaking or illusion on the fluidic pinball, we use symbolic regression (PySR) to discover compact, interpretable control laws of the form:
```
alpha = f(obs_features)
```
where `alpha = omega / U0` is the non-dimensional cylinder rotation, and `obs_features` are physically meaningful dimensionless quantities (forces, velocities, their derivatives).
The chain we analyze is:
```
obs -> act -> flow structure -> signature
```
Symbolic regression directly handles only `obs -> act`, but its value lies in revealing the physical feedback mechanisms the DRL agent has learned.
## 2. Methodology
### 2.1 Feature System
We construct three levels of dimensionless physical features from raw CFD sensor data:
| Level | Features | Dim | Description |
|-------|----------|:---:|-------------|
| Static | u_m, u_a, u_c, v_a, Cd_tot, Cd_rear, Cl_tot, Cl_diff | 8 | Current-step physics only |
| Phase-state | u_a, du_a/dt, Cl_tot, dCl_tot/dt, Cd_tot, Cd_rear | 6 | Oscillation phase + rate + drag feedback |
| Illusion-phase | Phase-state + Cd_err, Cl_err, dCd_err/dt, dCl_err/dt | 10 | Phase + error-state tracking |
### 2.2 Structural Constraints (v23)
To enforce physical consistency, we impose two constraints:
1. **Front no-bias**: `alpha_F = 0` when all features = 0. In a clean uniform flow, no corrective action should be needed.
2. **Rear shared-head with G-mirror**: The top and bottom cylinders are symmetric under the mirror operation G: `[aF, aT, aB] -> [-aF, -aB, -aT]`. The same function `h()` predicts `alpha_T`, and `alpha_B = -h(G(x))`.
### 2.3 PySR Symbolic Regression
PySR is a multi-population evolutionary algorithm that discovers symbolic expressions by optimizing a loss function. Key settings:
- **Output**: non-dimensional alpha (not physical omega), so formulas are scale-free
- **Operators**: +, -, *, /, sin, cos, exp
- **Constraints**: max complexity 20-40, Pareto front optimization
- **Validation**: one-step R-squared on held-out data, followed by CFD closed-loop as the final arbiter
### 2.4 CFD Closed-Loop Validation
The final judge of any formula is CFD closed-loop performance: the formula replaces the PPO policy to control the pinball cylinders, and the resulting sensor signals are compared to the target via DTW similarity. This catches issues invisible to one-step metrics (e.g., drift accumulation, distribution shift).
## 3. Karman Cloak Results
### 3.1 Cross-Re Joint Formula
Training on data from four Reynolds numbers (Re=50, 100, 200, 400) jointly yields:
**Front**:
```
alpha_F = daF_dt - 14.952 * mu * Cl_tot
```
**Top**:
```
alpha_T = 3.414 (constant)
```
**Physical interpretation**: The front cylinder action is driven by two terms:
1. `daF_dt`: Action momentum (rate of change of front action), capturing that the controller maintains consistent rotational direction.
2. `-14.952 * mu * Cl_tot`: Viscous-scaled lift feedback. As viscosity decreases (higher Re), the lift feedback weakens proportionally, naturally adapting to different flow regimes.
The rear cylinders rotate at constant speed, suggesting they provide a steady boat-tailing effect rather than active feedback.
### 3.2 CFD Validation
| Re | PPO Baseline | Joint Formula | % of PPO |
|:--:|:-----------:|:------------:|:--------:|
| 50 | 0.961 | 0.847 | 88.1% |
| 100 | 0.954 | 0.888 | 93.1% |
| 200 | 0.884 | 0.845 | 95.6% |
| 400 | 0.795 | 0.806 | 101.4% |
At Re=400, the symbolic formula actually outperforms the PPO policy at the default sampling interval. Testing revealed that Re=400 benefits from a shorter control interval (SI=400 instead of 800), improving formula performance to 0.819.
### 3.3 Per-Re Individual Formulas
Individual PySR fits at each Reynolds number achieve higher similarity (0.888-0.916) but produce structurally different formulas across Re, reflecting the flow's bifurcation cascade through the Re=50-400 range. The joint formula trades some per-Re performance for a unified expression valid across all conditions.
## 4. Illusion Results
### 4.1 Joint Formula (0.75L + 1.0L)
Training PySR on the combined data from two target cylinder diameters (0.75L and 1.0L) yields:
**Front** (no bias):
```
alpha_F = Cd_tot - Cd_err - 5.428 + 0.0098 * (du_a_dt + u_a)
```
**Top** (with bias):
```
alpha_T = (Cd_err - (Cd_rear - Cl_err)) * 0.535 + 2.782
```
**Physical interpretation** of the front formula:
1. `Cd_tot - Cd_err = target_Cd`: The controller tracks the desired target drag coefficient.
2. `-5.428`: Constant offset accounting for unit/calibration differences.
3. `0.0098 * (du_a_dt + u_a)`: Small phase-lead correction from cross-stream velocity asymmetry, fine-tuning the shedding phase.
The top cylinder uses error-state feedback: the difference between drag error and rear lift distribution.
### 4.2 Cross-Diameter Generalization
The joint formula, trained only on 0.75L and 1.0L, is tested on unseen target diameters:
| Diameter | Joint Formula | PPO Baseline | Status |
|:--------:|:------------:|:-----------:|--------|
| 0.5L | 0.854 | — | Generalization (unseen) |
| 0.6L | 0.939 | — | Generalization (unseen) |
| 0.75L | 0.978 | 0.980 | Trained |
| 0.8L | 0.908 | — | Generalization (unseen) |
| 1.0L | 0.970 | 0.975 | Trained |
| 1.2L | 0.849 | — | Generalization (unseen) |
| 1.5L | N/A | 0.945 | Non-SR regime |
| 2.0L | 0.676 | — | Degraded (unseen) |
The formula maintains near-PPO performance (similarity > 0.9) for diameters within +/-20% of the training range (0.6L-1.2L). Performance degrades sharply at 2.0L, where the required wake is fundamentally different from what the formula was designed to produce.
### 4.3 The 1.5L Special Case
The 1.5L illusion presents a distinct control regime:
- The PPO policy achieves high similarity (0.945) but uses **high-frequency periodic modulation** at f=0.24 in control space, which is 5.6x the target vortex shedding frequency.
- Action autocorrelation at lag-2 = -0.9, indicating the cylinders switch direction every two control steps.
- All linear correlations between features and actions are below 0.33, meaning no low-dimensional linear structure exists.
- PySR returns trivial solutions (`alpha_F_lag1 * 0.01`), confirming the current feature set cannot capture this mechanism.
This is documented as a **fundamentally non-fittable regime** under the current methodology, not a failure of the approach.
## 5. Structural Comparison: Karman vs. Illusion
The discovered formulas reveal fundamentally different control mechanisms:
| Aspect | Karman Cloak | Illusion |
|--------|------------|----------|
| **Objective** | Preserve incoming vortex street | Sculpt a new vortex street |
| **Dominant term** | Force feedback (Cl_tot) | Error tracking (Cd_err) |
| **Front mechanism** | Action momentum + viscous-scaled lift | Target drag tracking + phase correction |
| **Rear mechanism** | Constant rotation | Error-state feedback |
| **Re dependence** | Explicit via mu parameter | None (Re=100 only) |
This structural difference is expected: cloaking requires the controller to make the pinball "transparent" to passing vortices (force-neutral), while illusion requires the controller to actively generate a specific wake (force-matching).
## 6. Cross-Scene Generalization: Vortex Cloak
The Karman joint formula, trained exclusively on periodic vortex street data, is applied without modification to transient vortex cloaking tasks:
| Vortex | PPO (vortex-trained) | Karman Formula |
|:------:|:-------------------:|:--------------:|
| Lamb dipole | 0.942 | **0.949** |
| Taylor monopole | 0.916 | 0.905 |
The formula matches or exceeds the PPO baseline for the Lamb dipole, demonstrating that the discovered feedback structure captures a universal cloaking mechanism rather than a scene-specific strategy.
## 7. Discussion
### 7.1 The Force-Signature Separation
The structural difference between Karman and Illusion formulas mirrors the OID analysis finding that force-relevant and signature-relevant correction structures are systematically different. In Karman cloak, suppressing force variation IS the way to preserve the signature. In illusion, the agent must actively generate a force pattern that differs from its natural one.
### 7.2 Regime Boundaries
The cross-diameter generalization curve defines a clear regime boundary: the joint illusion formula works for target cylinders within approximately +/-20% of the training diameters. Beyond this, either the formula structure itself is insufficient (2.0L) or the PPO policy has entered a fundamentally different control regime (1.5L with high-frequency modulation).
### 7.3 Limitations
1. **Karman rear formula is constant** (alpha_T = 3.414): The joint formula did not extract meaningful feedback for the rear cylinders, despite PPO showing structured rear actions. This suggests the rear contribution is either encoded in higher-order interactions or is secondary to the front cylinder's dominant role.
2. **daB_dt artifact**: The PySR front formula includes a `daB_dt` term, but this reflects training distribution correlations (front and rear actions are correlated in PPO trajectories), not a causal relationship. At deployment, rear is constant, making this term zero.
3. **Illusion limited to Re=100**: The current illusion formulas are trained only at Re=100 (Re_D=50). Cross-Re generalization for illusion, analogous to the Karman joint formula with its mu-scaling term, is left for future work.
## 8. Conclusion
Symbolic regression successfully extracts compact, physically interpretable control laws from trained DRL policies for the fluidic pinball. The discovered formulas:
- Achieve CFD closed-loop performance within 5-15% of the PPO baseline for in-distribution scenes
- Generalize to unseen Reynolds numbers (Karman) and target diameters (Illusion) within defined regime boundaries
- Reveal fundamentally different feedback mechanisms for cloaking (force-feedback) vs illusion (error-tracking)
- Demonstrate cross-scene transfer: Karman formula generalizes to transient vortex cloaking tasks
The approach bridges the gap between black-box DRL performance and white-box interpretability, providing a path toward verifiable, transferable flow control strategies.

Some files were not shown because too many files have changed in this diff Show More