Repository navigation
fix: keep a function's class when copying it without simplification - #5954
Merged
Merged
Conversation
This was referenced Oct 22, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5954 +/- ##
=======================================
Coverage 98.25% 98.25%
=======================================
Files 350 350
Lines 36102 36109 +7
=======================================
+ Hits 35471 35478 +7
Misses 631 631 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
BradyPlanden
marked this pull request as ready for review
October 22, 2026 15:35
Contributor
|
| Project | PyBaMM |
| Branch | stack/00-function-copy-fix |
| Testbed | bare-metal |
🐰 View full continuous benchmarking report in Bencher
⚠️ WARNING: Truncated view!The full continuous benchmarking report exceeds the maximum length allowed on this platform.
MarcBerliner
previously approved these changes
Oct 23, 2026
Function.create_copy(perform_simplifications=False) built a generic pybamm.Function, so pybamm.exp and the other specific functions lost their class and an Arcsinh2 copy could not be evaluated. Since #5779, ParameterValues takes that path for a parameter set loaded with Serialise.load_parameters. _function_new_copy now takes perform_simplifications, as _unary_new_copy does.
BradyPlanden
force-pushed
the
stack/00-function-copy-fix
branch
from
October 28, 2026 09:55
1d8fe32 to
743663a
Compare
rtimms
approved these changes
Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Function.create_copy(perform_simplifications=False)built a genericpybamm.Functioninstead of a copy of the original class.ParameterValuestakes this path for every function in a parameter set loaded withSerialise.load_parameters, since it rebuilds the tree withsimplify=False(#5779). After processing,pybamm.exp,pybamm.tanhand the other specific functions were genericFunctionnodes, and a copiedArcsinh2could not be evaluated.create_copyalways goes through_function_new_copy(children, perform_simplifications), which gains the flag onFunction,SpecificFunctionandRegPower. With the flag off, a copy keeps its class,RegPower.deltaandArcsinh2.eps.Arcsinh2is never simplified, so it ignores the flag._function_new_copyis private, but a subclass outside PyBaMM that overrides it with the old one-argument signature raisesTypeErroron every copy. AFunctionsubclass with no override still copies as a genericpybamm.Function, as onmain.This is the base of the Rust execution engine stack (#5732). The lowering in #5959 dispatches on a function's class and rejects a generic
Function, so without this fix a reloaded parameter set cannot be solved once #5966 makes"rust"the default. It uses nothing else from the stack and can merge on its own.Type of change
Bug fix, under
## Bug fixesinCHANGELOG.md.Key checklist
pre-commit runExp,Tanh,Arcsinh2andRegPowerkeeps its class, its replaced child anddelta, with and without simplification, and a copiedArcsinh2evaluates as the original; a saved and reloaded Marquis2019 parameter set keepsExpin a processed SPM, with no genericFunctionleftRust execution engine stack: proposal #5667, showcase #5732
Each PR is one commit on the one above it.
Function.create_copykeeps the function's class ← this PRRegPowerand uniform-grid interpolant lookups matchevaluatepybamm-core: expression graph, typed IR, interpreters, forward-mode ADpybamm-core:CompiledModel, coloured Jacobians, the C ABIpybamm.rustbindings, built into thepybammwheelSymbol.to_rustconvert_to_format = "rust"forScipySolver,AlgebraicSolverand EISpybammsolvers: IDAKLU over the C ABIIDAKLUSolveron rust modelspybamm-core: diffsol DAE solverpybamm.DiffsolSolver"rust"as the defaultconvert_to_format