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

Fix the stackoverflow problem (Sourcery refactored) #8

Open
wants to merge 5 commits into
base: windows-test
Choose a base branch
from

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Dec 5, 2020

Pull Request #7 refactored by Sourcery.

Since the original Pull Request was opened as a fork in a contributor's
repository, we are unable to create a Pull Request branching from it.

To incorporate these changes, you can either:

  1. Merge this Pull Request instead of the original, or

  2. Ask your contributor to locally incorporate these commits and push them to
    the original Pull Request

    Incorporate changes via command line
    git fetch https://github.com/MarcoGorelli/pymc3 pull/7/head
    git merge --ff-only FETCH_HEAD
    git push

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

tl:dr: The hashable helper function did not appropiately deal with tuples (and the test case did not actually test the memoization).

In the process of prior-predictive sampling a model involving a DensityDist, the _compile_theano_function function was called with arguments (sd__log_, []).
The _compile_theano_function has a pm.memo.memoize-decorator, which relies on the pm.memo.hashable for hashing of typically unhashable objects.
The "hashable" function incorrectly handled tuples, eventually causing a stackoverflow error on Windows.
@sourcery-ai
Copy link
Author

sourcery-ai bot commented Dec 5, 2020

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.17%.

Quality metrics Before After Change
Complexity 19.10 😞 18.81 😞 -0.29 👍
Method Length 104.44 🙂 104.64 🙂 0.20 👎
Working memory 14.79 😞 14.77 😞 -0.02 👍
Quality 46.16% 😞 46.33% 😞 0.17% 👍
Other metrics Before After Change
Lines 4041 4062 21
Changed files Quality Before Quality After Quality Change
pymc3/memoize.py 68.67% 🙂 67.63% 🙂 -1.04% 👎
pymc3/sampling.py 28.39% 😞 28.37% 😞 -0.02% 👎
pymc3/util.py 69.59% 🙂 70.41% 🙂 0.82% 👍
pymc3/distributions/posterior_predictive.py 34.57% 😞 34.23% 😞 -0.34% 👎
pymc3/tests/test_memo.py 95.00% ⭐ 73.57% 🙂 -21.43% 👎
pymc3/tests/test_sampling.py 65.95% 🙂 65.97% 🙂 0.02% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
pymc3/sampling.py sample 83 ⛔ 883 ⛔ 32 ⛔ 1.10% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
pymc3/distributions/posterior_predictive.py _PosteriorPredictiveSampler.draw_value 74 ⛔ 496 ⛔ 35 ⛔ 1.69% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
pymc3/sampling.py sample_posterior_predictive 40 ⛔ 364 ⛔ 22 ⛔ 10.47% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
pymc3/distributions/posterior_predictive.py _PosteriorPredictiveSampler.draw_values 40 ⛔ 381 ⛔ 20 ⛔ 11.26% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
pymc3/sampling.py init_nuts 26 😞 736 ⛔ 28 ⛔ 12.82% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

@codecov-io
Copy link

codecov-io commented Dec 5, 2020

Codecov Report

❗ No coverage uploaded for pull request base (windows-test@73ca256). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff               @@
##             windows-test       #8   +/-   ##
===============================================
  Coverage                ?   87.64%           
===============================================
  Files                   ?       88           
  Lines                   ?    14346           
  Branches                ?        0           
===============================================
  Hits                    ?    12574           
  Misses                  ?     1772           
  Partials                ?        0           

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