This repository contains the reference implementation of Physical-Constraint-Manifold Neural Operators (PCM-NO). PCM-NO constrains an autoregressive neural-operator transition using fixed layers derived from the discrete operators of a numerical solver:
The neural backbone predicts a candidate residual update. The tangent projection
The code supports the two configurations studied in the paper:
- P-NS: periodic forced two-dimensional flow with a spectral incompressibility constraint.
- LC: MAC-stored lid-driven cavity trajectories with joint incompressibility and prescribed-boundary constraints.
.
├── configs/ # Paper, smoke, stress, and ablation protocols
├── data/
│ ├── pns/ # P-NS downloader, metadata, checksum, sample
│ └── lc/ # LC downloader, metadata, checksum, sample
├── reproduction/ # Ordered reproduction commands
├── scripts/ # Training, evaluation, stress, diagnostics, plots
├── src/pcmno/
│ ├── data/ # Released-data loaders and solver generators
│ ├── models/ # FNO and matched ClawNO-style baseline
│ ├── operators/ # Spectral and MAC constraint operators
│ ├── diagnostics.py
│ ├── evaluation.py
│ ├── losses.py
│ ├── metrics.py
│ ├── stress.py
│ ├── training.py
│ └── transitions.py
└── tests/ # CPU unit tests for operators and transitions
Python 3.10 or later is recommended.
git clone https://github.com/yneversky/PCM-NO.git
cd PCM-NO
python -m pip install --upgrade pip
pip install -e .For development and unit tests:
pip install -e ".[dev]"
pytestCUDA is used automatically when available. Set runtime.device: cpu in a YAML configuration, or pass an override such as --set runtime.device=cpu, to force CPU execution.
The full datasets are distributed as GitHub Release assets and are not stored in Git history.
python data/pns/download_pns.py --repo yneversky/PCM-NO
python data/lc/download_lc.py --repo yneversky/PCM-NOThe downloaders place the files under:
data/pns/raw/
data/lc/raw/
and verify them against the tracked SHA256SUMS manifests. Dataset layouts, solver settings, and loading examples are documented in data/pns/README.md and data/lc/README.md.
The tracked sample files are intended only for loader checks and smoke runs. They must not be used to report paper results.
After the small samples are present:
bash reproduction/run_smoke.shThe smoke protocol trains a reduced PCM-NO model for one epoch on each sample dataset. It checks code paths and tensor compatibility rather than predictive performance.
Train one method and seed:
python scripts/train.py \
--config configs/pns_paper.yaml \
--method pcmno \
--seed 0Evaluate the validation-selected checkpoint:
python scripts/evaluate.py \
--config configs/pns_paper.yaml \
--method pcmno \
--seed 0The supported P-NS methods are:
fno, divreg, pino, finalproj, pcmno, clawno
clawno uses a scalar potential output followed by fixed spectral differentiation. It is an external structure-preserving comparison and is trained with the same autoregressive data loss and FNO-scale capacity.
python scripts/train.py \
--config configs/lc_paper.yaml \
--method pcmno \
--seed 0
python scripts/evaluate.py \
--config configs/lc_paper.yaml \
--method pcmno \
--seed 0The supported LC main methods are:
fno, divreg, pino, finalproj, pcmno
Run the complete three-seed main protocol with:
bash reproduction/run_main.shThis command is computationally expensive. Checkpoint resume is enabled in the paper configurations.
The default main output tree is:
outputs/main/
├── pns/
│ └── <method>/seed_<seed>/
│ ├── best.pt
│ ├── latest.pt
│ ├── history.csv
│ ├── resolved_config.json
│ └── evaluation/
│ ├── test_curve.csv
│ └── test_summary.json
└── lc/
└── <method>/seed_<seed>/
└── ...
best.pt is selected only from validation rollout error. Test data are not used for checkpoint selection.
The evaluators export complete rollout curves and the paper horizons (r\in{1,20,50}).
P-NS reports:
- relative state error
RelL2; - base-10 log normalized spectral divergence
LogDiv; - relative kinetic-energy error
EnergyRelErr.
LC reports:
- relative state error
RelL2; - base-10 log interior MAC divergence
LogDiv; - base-10 log prescribed-boundary residual
LogBC; - centerline velocity-profile error
ProfileErr.
Aggregate per-seed summaries with:
python scripts/aggregate_results.py \
--summaries outputs/main/pns/pcmno/seed_*/evaluation/test_summary.json \
--output outputs/main/pns_pcmno_summary.csvThe stress suite covers:
- P-NS Reynolds-number extrapolation;
- LC Reynolds-number extrapolation;
- LC lid-velocity shift;
- P-NS target-grid transfer to (128^2).
Copy configs/checkpoints.example.json to a local manifest and replace the paths with the desired validation-selected checkpoints. Then run:
python scripts/run_stress.py \
--config configs/stress.yaml \
--pns-config configs/pns_paper.yaml \
--lc-config configs/lc_paper.yaml \
--checkpoints checkpoints.jsonStress sets are generated from the same discrete solvers used for the released data. No stress-set tuning or test-time fine-tuning is performed.
The LC ablation isolates the internal PCM-NO components:
tangent_only: projected residual update without final state retraction;retraction_only: unconstrained residual update followed by retraction;div_only: divergence-only tangent projection and retraction, omitting prescribed-boundary constraints;pcmno: complete tangent projection and affine state retraction.
python scripts/run_ablation.py --config configs/lc_ablation.yamlThe public ablation configuration uses the exact separable DCT solve during training and validation and the paper CG solve for final evaluation. The full method can instead be referenced from the completed main experiment when reproducing the exact paper table.
python scripts/run_diagnostics.py \
--config configs/pns_paper.yaml \
--checkpoint outputs/main/pns/pcmno/seed_0/best.pt \
--diagnostic tangent \
--output-dir outputs/diagnostics/pnsThe exported statistics include raw and projected update errors, the removed normal-component energy fraction, and the normalized Pythagorean gap.
python scripts/run_diagnostics.py \
--config configs/lc_paper.yaml \
--checkpoint outputs/main/lc/pcmno/seed_0/best.pt \
--diagnostic residual-reset \
--output-dir outputs/diagnostics/lcThe two replay branches receive the same projected update sequence. TangentOnlyReplay omits the final state retraction, while FullReplay applies it after every step.
python scripts/run_diagnostics.py \
--config configs/lc_paper.yaml \
--checkpoint outputs/main/lc/pcmno/seed_0/best.pt \
--diagnostic projection-sensitivity \
--output-dir outputs/diagnostics/lc
python scripts/plot_projection_sensitivity.py \
--csv outputs/diagnostics/lc/lc_projection_sensitivity.csv \
--output outputs/diagnostics/lc/lc_projection_sensitivity.pdfPrepare a JSON mapping method names to checkpoints, then run:
python scripts/benchmark_runtime.py \
--config configs/pns_paper.yaml \
--checkpoints pns_checkpoints.json \
--batch-size 1 \
--batch-size 8 \
--output outputs/pns_runtime.csvThe benchmark advances learned transitions and reference solvers over the same saved physical interval. It excludes checkpoint loading and file I/O.
Long-rollout curves:
python scripts/make_figures.py long-rollout \
--curves outputs/main/pns/*/seed_*/evaluation/test_curve.csv \
outputs/main/lc/*/seed_*/evaluation/test_curve.csv \
--output figures/generated/long_rollout.pdfQualitative stress comparison:
python scripts/make_qualitative.py \
--config configs/pns_paper.yaml \
--data outputs/stress/data/pns_re/pns_re1000.pt \
--finalproj outputs/main/pns/finalproj/seed_0/best.pt \
--pcmno outputs/main/pns/pcmno/seed_0/best.pt \
--step 50 \
--output figures/generated/pns_re1000_fields.pdfThe displayed trajectory is selected by median final-step ground-truth kinetic energy, independently of model error.
The repository contains training and evaluation code, solver-based data generation, stress protocols, component ablations, mechanism diagnostics, runtime measurement, and figure export. Full paper-scale reproduction requires the released datasets, sufficient GPU time, and the paper configurations. Pretrained checkpoints are not required for training from scratch and are not assumed to be present unless released separately.
Please cite the PCM-NO paper when using this code or the released datasets. The final BibTeX entry will be added after the public preprint or proceedings record is available.