Skip to content

Conversation

pipliggins
Copy link
Contributor

When solving with output_variables & sensitivities, sensitivities for variables >= 1D only ever wrote to row 0 of each variable's slice (indexing with dvar_k gives the variable index, not the internal row). This also had the effect of offsetting the index locations of 0D variables further down the output_variable list, causing their associated sensitivities to be incorrect once the sensitivity array is reshaped and passed back to python.

This fix adds an inner row loop to store the entire array for non-scalar variables.

Associated pybamm issue: #5058 and PR with test for this behaviour: #5118

@pipliggins pipliggins marked this pull request as ready for review July 16, 2025 13:38
@pipliggins pipliggins requested a review from a team as a code owner July 16, 2025 13:38
Copy link
Contributor

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @pipliggins for fixing this! Looking at the indexing is making my head hurt. While its in your head, can you write some comments detailing what this function does and how the indexing works?

@pipliggins pipliggins requested a review from martinjrobins July 18, 2025 13:47
Copy link
Contributor

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, thanks @pipliggins

@MarcBerliner MarcBerliner enabled auto-merge (squash) August 22, 2025 19:47
@MarcBerliner MarcBerliner merged commit 4ffb853 into pybamm-team:main Aug 22, 2025
19 checks passed
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.

4 participants