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

Fixes for sympy update #4253

Merged
merged 2 commits into from
Jul 9, 2024
Merged

Fixes for sympy update #4253

merged 2 commits into from
Jul 9, 2024

Conversation

kratman
Copy link
Contributor

@kratman kratman commented Jul 8, 2024

Description

SymPy updated and seems to no longer recognize PyBaMM symbols as strings.

It gets to this block (N.B. warning text was edited for readability):

    if not isinstance(a, str):
        try:
            a = str(a)
        except Exception as exc:
            raise SympifyError(a, exc)
        sympy_deprecation_warning("The string fallback in sympify() is deprecated.")

Then fails due to an exception. Even if it did convert to a string, it would have caused a deprecation warning.

Failing tests looked like this:

a = pybamm.Symbol("a", domain="test")
self.assertEqual(pybamm.Arcsinh(a).to_equation(), sympy.asinh(a))

There seemed to be two options:

  1. Add a pybamm.Symbol._sympy_() method. This would be basically identical to pybamm.Symbol.to_equation(), and would not be a good test.
  2. Explicitly put the expected string into the sympy function. This works as a test of pybamm.Symbol.to_equation() by confirming that pybamm.Symbol.print_name() returns the original name, but could be a bit redundant.

I went with option (2) since it keeps the tests working, but it could be good to determine if pybamm.Symbol.print_name() and pybamm.Symbol.to_equation() could be just replaced by a pybamm.Symbol._sympy_()method.

Type of change

  • 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

@kratman kratman self-assigned this Jul 8, 2024
@kratman
Copy link
Contributor Author

kratman commented Jul 8, 2024

When this passes CI then it should fix the CI in #4250 and replace #4252

Copy link

codecov bot commented Jul 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.54%. Comparing base (4486522) to head (2cb22dd).
Report is 216 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4253      +/-   ##
===========================================
- Coverage    99.55%   99.54%   -0.02%     
===========================================
  Files          288      288              
  Lines        21886    21886              
===========================================
- Hits         21789    21786       -3     
- Misses          97      100       +3     

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

@kratman kratman marked this pull request as ready for review July 8, 2024 22:39
@kratman kratman requested a review from a team July 8, 2024 22:43
@brosaplanella
Copy link
Member

Looks good, happy to approve once coverage passes.

@kratman
Copy link
Contributor Author

kratman commented Jul 9, 2024

@brosaplanella I am pretty sure that failure is a false positive. It is the same failure in #4252, which does not change any code

@kratman kratman merged commit 0cc59d9 into pybamm-team:develop Jul 9, 2024
25 of 26 checks passed
@kratman kratman deleted the fix/sympy branch July 9, 2024 16:04
kratman added a commit that referenced this pull request Jul 11, 2024
kratman added a commit that referenced this pull request Jul 12, 2024
prady0t pushed a commit to prady0t/PyBaMM that referenced this pull request Jul 26, 2024
js1tr3 pushed a commit to js1tr3/PyBaMM that referenced this pull request Aug 12, 2024
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.

3 participants