Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more information to error when drive cycle starts at t>0 #3756

Merged
merged 10 commits into from
Jan 24, 2024

Conversation

R-Yash
Copy link
Contributor

@R-Yash R-Yash commented Jan 22, 2024

Description

When a drive cycle starts at t>0, the current error thrown seems confusing. The changes made gives drive cycle a name and throws relevant exception when t>0. The documentation is changed accordingly to reflect this fact

Fixes #3612

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:

  • 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)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ python run-tests.py --quick (or $ 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

Copy link
Sponsor Member

@brosaplanella brosaplanella left a comment

Choose a reason for hiding this comment

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

Just a small comment, but looks good overall. Can you also please add a line to the CHANGELOG?

CHANGELOG.md Outdated Show resolved Hide resolved
@kratman
Copy link
Contributor

kratman commented Jan 22, 2024

@R-Yash I hope you don't mind, but I synced with develop so it would be ready for merging

@R-Yash
Copy link
Contributor Author

R-Yash commented Jan 22, 2024

@kratman Thanks

Copy link

codecov bot commented Jan 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2f4a928) 99.59% compared to head (21c460f) 99.59%.
Report is 3 commits behind head on develop.

❗ Current head 21c460f differs from pull request most recent head c13f153. Consider uploading reports for the commit c13f153 to get more accurate results

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3756   +/-   ##
========================================
  Coverage    99.59%   99.59%           
========================================
  Files          258      258           
  Lines        20823    20827    +4     
========================================
+ Hits         20738    20742    +4     
  Misses          85       85           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kratman
Copy link
Contributor

kratman commented Jan 22, 2024

@R-Yash Can you add a test to cover that exception?

@R-Yash
Copy link
Contributor Author

R-Yash commented Jan 22, 2024

@kratman How do I do that? I am a bit new to testcases.

@kratman
Copy link
Contributor

kratman commented Jan 22, 2024

You need to make a test that calls the function where the error is located, and passes in a time that is not zero. You can look at existing tests for that function to see if there is something you can adapt

@R-Yash
Copy link
Contributor Author

R-Yash commented Jan 22, 2024

@kratman
Can I modify this existing function ?

def test_start_times(self):
        # Test start_times
        step = pybamm.step._Step(
            "current", 1, duration=3600, start_time=datetime(2020, 1, 1, 0, 0, 0)
        )
        self.assertEqual(step.start_time, datetime(2020, 1, 1, 0, 0, 0))

        # Test bad start_times
        with self.assertRaisesRegex(TypeError, "`start_time` should be"):
            pybamm.step._Step("current", 1, duration=3600, start_time="bad start_time")

@kratman
Copy link
Contributor

kratman commented Jan 22, 2024

@kratman
Can I modify this existing function ?

def test_start_times(self):
        # Test start_times
        step = pybamm.step._Step(
            "current", 1, duration=3600, start_time=datetime(2020, 1, 1, 0, 0, 0)
        )
        self.assertEqual(step.start_time, datetime(2020, 1, 1, 0, 0, 0))

        # Test bad start_times
        with self.assertRaisesRegex(TypeError, "`start_time` should be"):
            pybamm.step._Step("current", 1, duration=3600, start_time="bad start_time")

Usually it is good to write a new test. A test like a function should have a single purpose. In this case you just want to test that an error is thrown. It will probably require a "with" statement looking for the thrown exception.

If you are really stuck then we can discuss on slack, but I recommend you give it a shot on your own first

@R-Yash
Copy link
Contributor Author

R-Yash commented Jan 24, 2024

@kratman I have added a test. Please take a look

Copy link
Contributor

@kratman kratman left a comment

Choose a reason for hiding this comment

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

Seems good as long as the tests pass

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@arjxn-py arjxn-py left a comment

Choose a reason for hiding this comment

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

Thanks @R-Yash Looks good, Just a small changelog suggestion.
Also waiting on tests before merging.

CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Arjun <arjunverma.oc@gmail.com>
@arjxn-py arjxn-py merged commit c93570f into pybamm-team:develop Jan 24, 2024
39 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.

More informative error extrapolation drive cycle
4 participants