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

Raise error for unknown parameter_values #3132

Merged
merged 5 commits into from
Jul 11, 2023
Merged

Conversation

tommaull
Copy link
Contributor

@tommaull tommaull commented Jul 10, 2023

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
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
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

Copy link
Contributor

@rtimms rtimms left a comment

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.

values = pybamm.parameter_sets[values]
values.pop("chemistry", None)
self.update(values, check_already_exists=False)
else:
print("Invalid Parameter Set Value")
Copy link
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
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
Copy link
Contributor

@rtimms rtimms left a comment

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
Copy link
Contributor

rtimms commented Jul 11, 2023

@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
Contributor

@rtimms

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

@rtimms
Copy link
Contributor

rtimms commented Jul 11, 2023

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

@tommaull
Copy link
Contributor Author

changelog updated - sorry about that!

@codecov
Copy link

codecov bot commented Jul 11, 2023

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.

@rtimms rtimms merged commit e67977a into pybamm-team:develop Jul 11, 2023
17 of 19 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.

None yet

2 participants