Skip to content

Raise error for unknown parameter_values - #3132

Merged
rtimms merged 5 commits into
pybamm-team:developfrom
tommaull:develop
Jul 11, 2023
Merged

rtimms merged 5 commits into
pybamm-team:developfrom
tommaull:develop

Conversation

@tommaull

@tommaull tommaull commented Jul 10, 2023 •

Copy link
Copy Markdown
Contributor

added else statement to inform user of an invalid parameter set

Description

Added else statement to inform user of an invalid parameter set in parameter_values.py

In response to #3063 - Raise error for unknown parameter sets

Fixes # (3063)

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 (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
  • The documentation builds: $ python run-tests.py --doctest

You can run unit and doctests together at once, using $ python run-tests.py --quick.

Further checks:

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

tommaull and others added 2 commits July 7, 2023 13:58
added else to inform user of an invalid parameter set
@tommaull
tommaull marked this pull request as draft July 10, 2023 09:14
@tommaull

Copy link
Copy Markdown
Contributor Author

Ran unit tests, FAILED (failures=1, skipped=62)
FAIL: test_symbol_visualise (test_expression_tree.test_symbol.TestSymbol)

Traceback (most recent call last):
File "C:\Users\tom.maull\Desktop\PybammDev\PyBaMM\tests\testcase.py", line 29, in wrapped
return method(*args, **kwargs)
File "C:\Users\tom.maull\Desktop\PybammDev\PyBaMM\tests\unit\test_expression_tree\test_symbol.py", line 393, in test_symbol_visualise
self.assertTrue(os.path.exists("test_visualize.png"))
AssertionError: False is not true

@tommaull

Copy link
Copy Markdown
Contributor Author

Doc test result:
(pybamm) C:\Users\tom.maull\Desktop\PybammDev\PyBaMM>python run-tests.py --doctest
Checking if docs can be built.
Traceback (most recent call last):
File "C:\Users\tom.maull\Desktop\PybammDev\PyBaMM\run-tests.py", line 427, in
run_doc_tests()
File "C:\Users\tom.maull\Desktop\PybammDev\PyBaMM\run-tests.py", line 68, in run_doc_tests
p = subprocess.Popen(
File "C:\Users\tom.maull\AppData\Local\mambaforge\envs\pybamm\lib\subprocess.py", line 951, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\tom.maull\AppData\Local\mambaforge\envs\pybamm\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

@rtimms rtimms left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for taking this on! After you've updated the code to raise an error can you also add a test in this file to confirm the error is raised when it should be. See here for an example.

The errors you are seeing locally are unrelated.

Comment thread pybamm/parameters/parameter_values.py Outdated
values.pop("chemistry", None)
self.update(values, check_already_exists=False)
else:
print("Invalid Parameter Set Value")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could you raise a ValueError here? E.g.

else:
    raise ValueError("helpful message")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@tommaull
tommaull requested a review from rtimms July 11, 2023 09:44

@rtimms rtimms left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks @tommaull looks good!

@rtimms

rtimms commented Jul 11, 2023

Copy link
Copy Markdown
Contributor

@all-contributors please add @tommaull for code and tests

@rtimms
rtimms marked this pull request as ready for review July 11, 2023 09:59
@allcontributors

Copy link
Copy Markdown
Contributor

@rtimms

I've put up a pull request to add @tommaull! 🎉

@rtimms

rtimms commented Jul 11, 2023

Copy link
Copy Markdown
Contributor

@tommaull sorry, forgot to say, could you also add an entry to the changelog? thanks!

@tommaull

Copy link
Copy Markdown
Contributor Author

changelog updated - sorry about that!

@codecov

codecov Bot commented Jul 11, 2023 •

Copy link
Copy Markdown

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (5486fce) 99.71% compared to head (10f9f46) 99.71%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3132   +/-   ##
========================================
  Coverage    99.71%   99.71%           
========================================
  Files          248      248           
  Lines        18747    18748    +1     
========================================
+ Hits         18693    18694    +1     
  Misses          54       54           
Impacted Files Coverage Δ
pybamm/parameters/parameter_values.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

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