toolchain: fix KeyError('num_fluids') in case-optimization fpp generation#1641
Conversation
…tion
case.py's __get_sim_fpp reads self.params["num_fluids"] by bracket, while
every other parameter in that case-optimization block uses .get(key, default).
The packer builds a dummy case with empty params (pack.py: input.load(None, {}, {}))
to enumerate configured targets for golden metadata; under --case-optimization
that flows into get_fpp and the bracket access raises KeyError('num_fluids').
This breaks './mfc.sh test --case-optimization' (golden harness) even though the
simulation itself runs correctly. Use .get("num_fluids", 1) to match the
surrounding lines.
There was a problem hiding this comment.
Pull request overview
Fixes a toolchain crash during case-optimization Fypp header generation when a “dummy” case is created with empty parameters (used by the golden packer to enumerate targets). This prevents KeyError('num_fluids') in Case.__get_sim_fpp while keeping behavior unchanged for real cases where num_fluids is set.
Changes:
- Replace direct
self.params["num_fluids"]access withself.params.get("num_fluids", 1)to avoidKeyErrorfor empty-param dummy cases.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1641 +/- ##
=======================================
Coverage 60.95% 60.95%
=======================================
Files 83 83
Lines 20003 20003
Branches 2983 2983
=======================================
Hits 12193 12193
Misses 5782 5782
Partials 2028 2028 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
apropos of little
|
Summary
Case.__get_sim_fpp(toolchain/mfc/case.py) readsself.params["num_fluids"]by direct subscript when emitting the case-optimization Fypp header, while every other parameter in that same block usesself.params.get(key, default).The packer constructs a dummy case with empty params to enumerate configured targets for the golden metadata file:
Under
--case-optimization, that empty-param case flows throughget_fpp→__get_sim_fpp, and the bare subscript raisesKeyError: 'num_fluids'.Impact
./mfc.sh test --case-optimizationfails for every golden case withError: 'num_fluids'— even though the case-optimized simulation itself builds and runs correctly. The failure is in the post-run golden-packing/metadata step, not the compiled binary (the run completes with exit 0 and correct output before the packer is invoked).CI's case-optimization job runs
./mfc.sh run --case-optimization+ a custom output check (.github/scripts/run_case_optimization.sh), not the golden harness, so it never hits this path — which is why it went unnoticed.Fix
One line, matching the
.get(..., default)pattern of every sibling in the same block (nb,weno_order,muscl_order, …):For the dummy empty case the default is only used to compute a throwaway staging slug (which won't match any real build and is skipped); for real cases
num_fluidsis present, so behavior is unchanged.Testing
./mfc.sh test --only <AMR golden> --case-optimization→KeyError: 'num_fluids'before the change; passes after.--case-optimization(2/2 on each backend) after the fix.