Skip to content

Coupled GITT-EIS parameterisation - #975

Merged
NicolaCourtier merged 58 commits into
pybop-team:developfrom
Ombrini:gitt-eis
Nov 19, 2026
Merged

NicolaCourtier merged 58 commits into
pybop-team:developfrom
Ombrini:gitt-eis

Conversation

@Ombrini

@Ombrini Ombrini commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

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.Dataset on the Time [s] domain:

  • Time [s], Current [A], Voltage [V] — full length n_time
  • 2 x n_frequency real-valued impedance variables, also length n_time, non-NaN only
    at the rows where a spectrum was acquired.

EISSimulator gains a protocol and acquisition_indices arguments. Per evaluation it solves the time-domain trajectory once, then linearises about the state at each acquisition point. Because everything shares the Time [s] domain, the two cost measures combine with the existing pybop.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:

casadi.vertcat(*inputs.values())

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_problem in PyBaMM PR 6072.

WeightedCost sub-costs lost their individual targets. Problem.__init__ calls set_target(None), which fell through to target or self._target, where self._target is 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. Now target is None keeps each cost's own target.

Also in this PR

  • Build once, not per evaluation. _initialise_eis_matrices previously re-ran solver.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, mirroring Simulator._set_up_solution_method.
  • Plotting. pybop.plot.nyquist can produce one figure of Nyquist subplots — one per acquisition, equal aspect ratio — instead of one near-empty time series per variable. Adds equal_aspect to the plot backends.
  • pybop.pybamm.EISSimulator.set_output_variables is deliberately a no-op, with a comment explaining why: restricting the solver to output variables makes PyBaMM stop returning the state vector (sol.y comes 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 a FunctionParameter in Chen2020 with a hard-coded prefactor, so the example redefines the function with the prefactor exposed, following examples/scripts/getting_started/functional_parameters.py.

Type of change

New feature, plus two bug fixes.

Important checks:

  • No style issues: ruff check and ruff format clean over pybop/, tests/, examples/
  • All tests pass: nox -s tests — 542 passed, 26 skipped, with one failure that also occurs on develop without this branch's changes (see below)
  • The documentation builds: nox -s doctest — passed (1 passed, 549 skipped)
  • Code is commented for hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

New tests (tests/unit/test_simulator.py::TestCoupledEISSimulator):

Test What it pins
test_output_shape_and_zero_padding outputs are length n_time, non-zero only at acquisitions
test_matches_stationary_at_initial_state the spectrum at t=0 equals a stationary simulation's (exact, rtol=1e-10) — fails if the linearisation is wired up wrong
test_builds_once the model and constant matrices are set up once, not per evaluation

Plus tests/unit/test_cost.py::test_weighted_cost_keeps_distinct_targets for the WeightedCost fix.

Open questions for review

  • The example's weights=[1.0, 1e3] is a starting point chosen so that the two terms are comparable in magnitude, not a derived value.
  • The spectra are placed at the end of each rest (current zero, cell relaxed) rather than at the end of the current pulse. A non-zero current at an acquisition time warns rather than fails, since the Jacobian is still valid about that operating point — but the quasi-steady assumption behind EIS is only approximately met while the cell is still relaxing.

NicolaCourtier and others added 30 commits March 24, 2025 10:33
…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

codecov Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.21488% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.36%. Comparing base (64c6ca0) to head (c22d77d).
⚠️ Report is 13 commits behind head on develop.

Files with missing lines Patch % Lines
pybop/pybamm/eis_simulator.py 94.52% 4 Missing ⚠️
pybop/plot/nyquist.py 90.00% 2 Missing ⚠️
pybop/plot/backends/plotly.py 80.00% 1 Missing ⚠️
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.
📢 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.

@NicolaCourtier
NicolaCourtier self-requested a review September 3, 2026 14:36
@NicolaCourtier NicolaCourtier mentioned this pull request Oct 31, 2026

@NicolaCourtier NicolaCourtier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@NicolaCourtier
NicolaCourtier merged commit 5974ff6 into pybop-team:develop Nov 19, 2026
35 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.

2 participants