Repository navigation
Coupled GITT-EIS parameterisation - #975
Merged
Merged
Conversation
…ality - Introduced a new example script for parameter estimation from GITT experiments with operando EIS. - Enhanced the EISSimulator class to support operando simulations and added methods for handling impedance data. - Updated the WeightedCost class to maintain distinct targets for different cost functions. - Added unit tests for the operando EIS simulator to ensure correct functionality and output.
…able handling, and enhance plotting capabilities
…e operando EIS file, and update method names for clarity
The previous commit stacked the input values alphabetically, on the assumption that pybamm orders a built model's input parameters that way. That is wrong here: the alphabetical ordering comes from BaseSolver._set_up_model_inputs(), which is part of the solve path and is bypassed by _set_up_matrices(). The Jacobian is compiled by solver.set_up(), whose parameter vector follows the order of the inputs dict it is handed (base_solver.py, _get_vars_for_processing), so the values must be stacked in that same order. Sorting therefore reintroduced the swap it was meant to fix whenever the caller's dict order was not alphabetical.
The compiled Jacobian expects the input values in the order used by the solver.set_up() call which compiled it, and the two paths disagreed. In a stationary simulation only _set_up_matrices() compiles the functions, using the caller's dict order. In a coupled simulation the time-domain solve runs first and recompiles the shared built model through pybamm's BaseSolver._set_up_model_inputs(), which sorts by name, so the sorted order wins. Neither static choice was correct for both paths: the previous commit fixed the stationary case and broke the coupled one, giving 396.7 Ohm instead of 38.3 Ohm at low frequency. _set_up_matrices() now sorts as well, so both paths and _jacobian() agree on one order. Adds a regression test over both modes, which fails on either of the two earlier variants.
When a geometric parameter is fitted, the time-domain solve goes through Simulator._simulate_with_rebuild, which sets _simulation back to None when it returns. _solve_along_protocol set up the constant matrices before that solve, so _jacobian then found no simulation and raised AttributeError. Only the coupled path was affected; a stationary simulation never calls the time-domain solver. The matrices are now set up after the time-domain solve, which also matches the ordering the compiled Jacobian expects.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #975 +/- ##
===========================================
+ Coverage 93.32% 93.36% +0.04%
===========================================
Files 84 84
Lines 6842 6952 +110
===========================================
+ Hits 6385 6491 +106
- Misses 457 461 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
NicolaCourtier
self-requested a review
September 3, 2026 14:36
Merged
NicolaCourtier
approved these changes
Nov 13, 2026
NicolaCourtier
left a comment
Member
There was a problem hiding this comment.
gitt_eis.py is a really nice example, thanks @Ombrini!
I have refactored the data structure and the plotting for easier maintenance. I am approving these changes. If you would like to add/retain any other changes, please feel free to open another PR! The bug fixes were separated out and merged prior to the last release (v26.10) - thanks for these as well.
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
Adds coupled GITT-EIS parameterisation: the ability to fit a model against a time-domain voltage trace and impedance spectra measured at chosen points along that trace, in a single optimisation. The motivating case is a GITT experiment with a spectrum acquired at the end of each pulse, where the relaxation constrains transport and the charge-transfer arc constrains kinetics — two parameters that are hard to separate from either measurement alone.
How it works
The design leans on the fact that the cost layer is domain-agnostic but length-strict.
So both data types live in one
pybop.Dataseton theTime [s]domain:Time [s],Current [A],Voltage [V]— full lengthn_time2 x n_frequencyreal-valued impedance variables, also lengthn_time, non-NaN onlyat the rows where a spectrum was acquired.
EISSimulatorgains aprotocolandacquisition_indicesarguments. Per evaluation it solves the time-domain trajectory once, then linearises about the state at each acquisition point. Because everything shares theTime [s]domain, the two cost measures combine with the existingpybop.WeightedCost, which provides the relative weighting — no new cost class.Bug fixes included
Input parameters were stacked in the wrong order (pre-existing). PyBaMM orders a built model's input parameters alphabetically (
base_solver.py,ordered_inputs_names = sorted(...)), but the EIS code stacked them in the caller's dict order:With one fitted parameter this cannot go wrong, which is why it went unnoticed. With two whose dict order is not alphabetical, the values are swapped and the model is evaluated at the wrong point — in the new example, diffusivity and the exchange-current prefactor were exchanged. Values are now sorted by name before stacking.
Note: the same issue has now been fixed in PyBaMM's own
EISSimulation._build_matrix_problemin PyBaMM PR 6072.WeightedCostsub-costs lost their individual targets.Problem.__init__callsset_target(None), which fell through totarget or self._target, whereself._targetis the flattened union of the sub-cost targets. Its first element is a string, so it was broadcast to every cost, and each cost then evaluated all targets. Nowtarget is Nonekeeps each cost's own target.Also in this PR
_initialise_eis_matricespreviously re-ransolver.set_up()and rebuilt the mass matrix and forcing vector on every evaluation, although neither depends on the inputs or the operating point. These are now set up once, mirroringSimulator._set_up_solution_method.pybop.plot.nyquistcan produce one figure of Nyquist subplots — one per acquisition, equal aspect ratio — instead of one near-empty time series per variable. Addsequal_aspectto the plot backends.pybop.pybamm.EISSimulator.set_output_variablesis deliberately a no-op, with a comment explaining why: restricting the solver to output variables makes PyBaMM stop returning the state vector (sol.ycomes back with shape(0, N)), and the state vector is exactly what the linearisation needs.New example
examples/scripts/battery_parameterisation/gitt_eis.py— simulates a GITT experiment, computes a spectrum about the state at the end of each pulse, assembles the combined dataset, and recovers the positive-electrode diffusivity and exchange-current prefactor. The latter is aFunctionParameterin Chen2020 with a hard-coded prefactor, so the example redefines the function with the prefactor exposed, followingexamples/scripts/getting_started/functional_parameters.py.Type of change
New feature, plus two bug fixes.
Important checks:
ruff checkandruff formatclean overpybop/,tests/,examples/nox -s tests— 542 passed, 26 skipped, with one failure that also occurs ondevelopwithout this branch's changes (see below)nox -s doctest— passed (1 passed, 549 skipped)New tests (
tests/unit/test_simulator.py::TestCoupledEISSimulator):test_output_shape_and_zero_paddingn_time, non-zero only at acquisitionstest_matches_stationary_at_initial_statet=0equals a stationary simulation's (exact,rtol=1e-10) — fails if the linearisation is wired up wrongtest_builds_oncePlus
tests/unit/test_cost.py::test_weighted_cost_keeps_distinct_targetsfor theWeightedCostfix.Open questions for review
weights=[1.0, 1e3]is a starting point chosen so that the two terms are comparable in magnitude, not a derived value.