Skip to content

Fix deprecated "electrode diffusivity" alias silently clobbering "particle diffusivity"#5642

Open
rtimms wants to merge 5 commits into
mainfrom
worktree-electrode-diffusivity-alias
Open

Fix deprecated "electrode diffusivity" alias silently clobbering "particle diffusivity"#5642
rtimms wants to merge 5 commits into
mainfrom
worktree-electrode-diffusivity-alias

Conversation

@rtimms

@rtimms rtimms commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Description

Setting or fitting "<phase> particle diffusivity [m2.s-1]" could have zero effect on the solved result: perturbing it changed nothing, because the deprecated "<phase> electrode diffusivity [m2.s-1]" alias silently overrode it. This bites hardest with BPX, since create_from_bpx produced a set containing both names for the same quantity.

Root cause

ParameterValues.check_parameter_values migrated the deprecated name to the current one by adding the new key without removing the deprecated one, and by unconditionally overwriting the current name:

values[new_param] = values.get(param)   # never deletes `param`; clobbers new_param

So a set could hold both names, and any re-normalisation (ParameterValues(dict(pv)), .update(...), serialisation round-trips common in fit harnesses) let the stale deprecated value overwrite a value the user set on the current name.

Fix

  • check_parameter_values: the deprecated diffusivity name now migrates with the current name taking precedence (setdefault) and the deprecated key removed, so the two can never coexist and clobber each other. The FuzzyDict lookup fallback is unchanged, so reads of the old name still resolve.
  • bpx.py: emit the current particle diffusivity name (and its activation energy) directly, so create_from_bpx yields a clean single-name set with no spurious DeprecationWarning.
  • Added regression tests for the migration (current name wins; deprecated key dropped) and for the BPX output.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Verification

  • After ParameterValues({"Negative electrode diffusivity [m2.s-1]": D}), keys() contains only the particle name; setting particle then round-tripping ParameterValues(dict(pv)) preserves the set value (no clobber).
  • create_from_bpx output contains only particle diffusivity names and emits no diffusivity deprecation warning.
  • Affected test files pass in isolation: test_bpx.py, test_parameter_values.py, test_util.py, test_parameter_values_serialisation.py.

🤖 Generated with Claude Code

…ticle diffusivity"

`ParameterValues.check_parameter_values` migrated the deprecated
"<X> electrode diffusivity [m2.s-1]" name to the current
"<X> particle diffusivity [m2.s-1]" by adding the new key without removing
the deprecated one and by unconditionally overwriting the current name. As a
result a parameter set could hold both names, and any re-normalisation
(copying, `update`, serialisation round-trips) let the stale deprecated value
overwrite a value the user set on the current name — silently no-opping
diffusivity fits. `create_from_bpx` made this the default by emitting both.

- `check_parameter_values`: the deprecated diffusivity name now migrates with
  the current name taking precedence (`setdefault`) and the deprecated key
  removed, so the two can never coexist. The `FuzzyDict` lookup fallback keeps
  reads of the old name working.
- `bpx.py`: emit the current "particle diffusivity" (and its activation energy)
  name directly, so `create_from_bpx` yields a clean single-name set with no
  spurious deprecation warning.
- Added regression tests for the migration and the BPX output.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rtimms rtimms requested a review from a team as a code owner July 7, 2026 09:54
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.09%. Comparing base (e929c3c) to head (741b31e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5642      +/-   ##
==========================================
- Coverage   98.10%   98.09%   -0.01%     
==========================================
  Files         339      339              
  Lines       32069    32075       +6     
==========================================
+ Hits        31460    31465       +5     
- Misses        609      610       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Per review, do not drop the deprecated '<X> electrode diffusivity [m2.s-1]'
key — custom models may still reference it, and the FuzzyDict fallback already
resolves reads. Fixing the clobber only needs the current name to take
precedence (setdefault), not deletion. Also warn when both names are set, and
leave the MSMR migration branch unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant