pybamm-team / PyBaMM

Fast and flexible physics-based battery models in Python
https://www.pybamm.org/
BSD 3-Clause "New" or "Revised" License
876 stars 492 forks source link

Extend Step String Tagging Functionality #4177

Open mleot opened 3 weeks ago

mleot commented 3 weeks ago

Description

This is a feature request covering multiple related feature additions surrounding the pybamm.step.string tags functionality. Currently there is the ability to add tags to pybamm step strings, and there is the ability to search an experiment for the indices where specific tags exist. There is not currently any additional functionality of the step string tags. The proposed added functionality is the following:

Motivation

I believe these features are the would-be natural evolution of additional functionality surrounding step string tags. I believe the true utility of these step string tags come when you can use them to filter a solution object, or to filter data exported from a solution object.

Possible Implementation

Core Implementation

I believe there are a number of steps for the proposed core implementation.

  1. Add a property to the Solution class: .tags
  2. By default, when running an experiment, each time a step_solution is generated, the tags from the associated step (from the experiment) should then be assigned as a property to the Solution object
  3. The method Solution.get_data_dict() should export a 'Tags' column along with 'Cycle' and 'Step' columns.
  4. An additional method should be added: Solution.search_tags(), similar to Experiment.search_tag(), allowing for searching of one of many tags in the solution sub_solutions

Additional Features

I also believe there are a number of additional changes that may be useful to include as well

  1. The inclusion of tags in the __repr__ of the Solution object
  2. Similar to how tags would be associated with a Solution object (as a property), there may also be the properties .cycle and .step which are associated with a Solution when the solution results from an experiment.
  3. The Solution object holds the additional variables, accessible through the __getitem__() method, being "Cycle", "Step", and "Tags"

Remaining Questions

Additional context

No response

valentinsulzer commented 2 weeks ago

Should calling Solution.get_data_dict() when there are no tags result in returning an empty "Tags" column, or no "Tags" column at all?

I think an empty tags column is better for consistency