PyBaMM icon indicating copy to clipboard operation
PyBaMM copied to clipboard

Improved option checking for tuples

Open medha-14 opened this issue 1 year ago • 6 comments

Description

Fixes #3303

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Optimization (back-end change that speeds up the code)
  • [ ] Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • [x] No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • [x] All tests pass: $ python -m pytest (or $ nox -s tests)
  • [ ] The documentation builds: $ python -m pytest --doctest-plus src (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ nox -s quick.

Further checks:

  • [ ] Code is commented, particularly in hard-to-understand areas
  • [ ] Tests added that prove fix is effective or that feature works

medha-14 avatar Dec 23 '24 07:12 medha-14

I have implemented better option checking by creating an ensure_tuple method. This method automatically converts any string-based options into tuples, ensuring consistent handling of options.

medha-14 avatar Dec 23 '24 07:12 medha-14

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.68%. Comparing base (298e306) to head (d47d2e5).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4707      +/-   ##
===========================================
- Coverage    98.71%   98.68%   -0.03%     
===========================================
  Files          304      304              
  Lines        23495    23495              
===========================================
- Hits         23193    23186       -7     
- Misses         302      309       +7     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: 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.

codecov[bot] avatar Dec 23 '24 11:12 codecov[bot]

Would it be wrong to assume that all options passed can be expressed in two ways:

If a single value is passed for an option, it would look like this:

options = {
    "working electrode": "both",
}

If multiple values are passed, it would be structured like this:

options = {
    "SEI": ("none", "constant"),
}

Are these the only two possibilities? or should we consider some different input formats as well?

medha-14 avatar Dec 25 '24 13:12 medha-14

@medha-14 yes, those are the only two options. I think what I had in mind here is that all the options that can be tuples should be converted to tuples in-place at the start, then we can always just treat them like they will be tuples. You could add a new constant that is a list of all the options that can be tuples.

rtimms avatar Jan 02 '25 11:01 rtimms

Is it essential to convert the options to tuples beforehand? In my recent commit, I addressed the issue by updating:

if options["particle size"] == "distribution"

to this

if "distribution" in options["particle size"] :

Like in the commit i made This approach works for both string and tuple options. Please let me know if I am overlooking anything.

medha-14 avatar Jan 12 '25 07:01 medha-14

Sorry for taking too long to respond, I’ve added the requested tests and fixed the failing ones.

medha-14 avatar Mar 06 '25 11:03 medha-14