Skip to content

fix: identify drive-cycle steps by their contents, not their shortened repr - #6018

Open
brosaplanella wants to merge 1 commit into
mainfrom
fix/experiment-drive-cycle-identity
Open

brosaplanella wants to merge 1 commit into
mainfrom
fix/experiment-drive-cycle-identity

Conversation

@brosaplanella

@brosaplanella brosaplanella commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

numpy shortens the repr of large arrays, so steps with long drive cycles that differ only away from their ends were merged into one.

Description

Steps were identified by text: Experiment keyed its processed steps on repr(step), and BaseStep.__eq__, __hash__ and basic_repr used hash_args, built from f"{value}". numpy shortens the repr of arrays over 1000 entries to their first and last three rows, so two drive cycles of over 500 rows that differ only in between gave the same step. Experiment replaced the second with a copy of the first, and the simulation ran the first drive cycle twice, in both experiment modes, with no error or warning.

Changes

  • hash_args identifies an array value by its shape, dtype and SHA-256 digest (_value_identity in base_step.py), so __eq__, __hash__ and basic_repr tell such steps apart. The model and branch keys in Simulation use basic_repr, so they follow. Other values keep their text, and repr is unchanged, for display.
  • Experiment keys the processed steps on (repr(step), step.basic_repr()) for step objects, rather than on repr(step) alone, so steps keep every argument that repr shows and still tell long drive cycles apart. String steps keep their repr key.

Tests

  • TestExperimentSteps.test_drive_cycles_differing_in_the_middle_not_equal: equal drive cycles give equal steps and hashes, and drive cycles that differ in the middle do not.
  • TestSimulationExperiment.test_drive_cycles_differing_in_the_middle[legacy/unified]: the experiment keeps both steps, and the second runs at 5 A at t = 500 s.

Fixes #6017

Type of change

Bug fix

Important checks:

Please confirm the following before marking the PR as ready for review:

  • No style issues: nox -s pre-commit
  • All tests pass: nox -s tests
  • The documentation builds: nox -s doctests
  • Code is commented for hard-to-understand areas
  • Tests added that prove fix is effective or that feature works
  • If you are adding or changing a model in the zoo, you have read the policy.

…d repr

numpy shortens the repr of large arrays, so steps with long drive cycles that
differ only away from their ends were merged into one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@brosaplanella
brosaplanella marked this pull request as ready for review November 1, 2026 10:34
@brosaplanella
brosaplanella requested a review from a team as a code owner November 1, 2026 10:34
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

ProjectPyBaMM
Branchfix/experiment-drive-cycle-identity
Testbedbare-metal

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

🐰 View full continuous benchmarking report in Bencher

@codecov

codecov Bot commented Nov 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.22%. Comparing base (8e54b57) to head (d6153e0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6018      +/-   ##
==========================================
- Coverage   98.23%   98.22%   -0.01%     
==========================================
  Files         350      350              
  Lines       36173    36184      +11     
==========================================
+ Hits        35533    35543      +10     
- Misses        640      641       +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.

This branch has not been deployed

No deployments
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.

[Bug]: Experiment steps with long drive cycles that differ only in the middle are treated as the same step

1 participant