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

Pymc3 Plot & Diagnostics & Arviz Dependency #4397

Merged

Conversation

CloudChaoszero
Copy link
Contributor

@CloudChaoszero CloudChaoszero commented Jan 1, 2021

Description

This PR starts the (Breakchange) removal of PyMC3 Plots and Diagnostics process referred in #4371, and relying on referred functionality from Arviz. See an example from the quote below

Plots and diagnostics are still accessible via PyMC3 but are actually implemented by ArviZ now. Although this was a good call when ArviZ was still nascent, now this causes confusion for new comers and overhead for devs, who have to mirror the functions in ArviZ, which is more work when ArviZ adds or changes functions (e.g pm.hpd vs. az.hdi).

The Implementation Process

Add Deprecation warning to one remaining (plot) function

Add a DeprecateWarning to function plot_posterior_predictive_glm

V4 3.11 implementation

  1. Remove Diagnostics (pymc3/stats), incrementally
  2. Remove Plots (pymc3/plots), incrementally
  3. Test
  4. Ensure Jupyter Notebook examples in pymc3-examples is updated as well

Notes

  • what are the (breaking) changes that this PR makes?

  • important background, or details about the implementation

  • are the changes—especially new features—covered by tests and docstrings?

  • consider adding/updating relevant example notebooks

  • right before it's ready to merge, mention the PR in the RELEASE-NOTES.md

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@CloudChaoszero CloudChaoszero changed the base branch from v4 to master January 1, 2021 11:01
@CloudChaoszero
Copy link
Contributor Author

Note to self: Is v4 the base branch?

@codecov
Copy link

codecov bot commented Jan 1, 2021

Codecov Report

Merging #4397 (1337d1b) into master (2824027) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #4397    +/-   ##
========================================
  Coverage   88.17%   88.17%            
========================================
  Files          88       87     -1     
  Lines       14563    14338   -225     
========================================
- Hits        12841    12643   -198     
+ Misses       1722     1695    -27     
Impacted Files Coverage Δ
pymc3/sampling.py 89.72% <ø> (+0.10%) ⬆️
pymc3/step_methods/mlda.py 95.50% <ø> (-0.02%) ⬇️
pymc3/plots/__init__.py 100.00% <100.00%> (+46.93%) ⬆️
pymc3/plots/posteriorplot.py 96.00% <100.00%> (+0.34%) ⬆️
pymc3/tests/sampler_fixtures.py 96.80% <100.00%> (-0.20%) ⬇️
pymc3/step_methods/hmc/integration.py 89.79% <0.00%> (-2.05%) ⬇️
pymc3/distributions/discrete.py 94.25% <0.00%> (-1.75%) ⬇️
pymc3/variational/approximations.py 80.19% <0.00%> (-1.74%) ⬇️
pymc3/step_methods/gibbs.py 40.00% <0.00%> (-1.47%) ⬇️
pymc3/tests/helpers.py 60.34% <0.00%> (-1.33%) ⬇️
... and 37 more

@twiecki twiecki added this to the vNext (3.11.0) milestone Jan 2, 2021
@twiecki
Copy link
Member

twiecki commented Jan 2, 2021

Thanks @CloudChaoszero! I think we should make sure to also change the pymc-examples so that people can still run those fine. That should probably happen before we release with this change.

@CloudChaoszero
Copy link
Contributor Author

Thanks @CloudChaoszero! I think we should make sure to also change the pymc-examples so that people can still run those fine. That should probably happen before we release with this change.

Sounds great. I'll proceed with that in the pymc-examples, and after update this branch.

Copy link
Member

@OriolAbril OriolAbril left a comment

Choose a reason for hiding this comment

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

Everything looks good so far, I only have a minor suggestion about the api page. I'm looking forward to have the example notebooks updated.

docs/source/api.rst Outdated Show resolved Hide resolved
@CloudChaoszero CloudChaoszero marked this pull request as ready for review January 4, 2021 17:39
Copy link
Member

@michaelosthege michaelosthege left a comment

Choose a reason for hiding this comment

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

Hi @CloudChaoszero ,
I think this PR should move forward and get merged before the 3.11.0 release. We should keep just the plot_posterior_predictive_glm (and its tests) around because there is no replacement for it.

I think it's fair to remove the other plotting and stats functions, because we advertised ArviZ for a long time and even though they did not have deprecation warnings, their replacement is just a minor inconvenience for the users. 3.11 will bring much more severe breaking changes than this.

pymc3/plots/posteriorplot.py Outdated Show resolved Hide resolved
docs/source/api.rst Outdated Show resolved Hide resolved
@CloudChaoszero
Copy link
Contributor Author

Thanks for the feedback y'all! 😄

Alright, so I implemented the following, based on reviews:

3.11

This PR is against master for 3.11 release.

Documentation

@OriolAbril
Added the plots section back into the documentation. Also, I changed the description to focus on arviz, but PyMC3 does offer plot_posterior_predictive_glm , seen below:

Screen Shot 2021-01-17 at 2 41 30 AM

Keeping the plot_posterior_predictive_glm Function

@michaelosthege I went ahead and added a warning to plot_posterior_predictive_glm

    warnings.warn(
        "The `plot_posterior_predictive_glm` function will migrate to Arviz in a future release. "
        "\nKeep up to date with `ArviZ <https://arviz-devs.github.io/arviz/>`_ for future updates.",
        DeprecationWarning,
    )

@AlexAndorra Question: Are there any other Arviz diagnostics dependencies I should consider, outside of the plots topic?

Copy link
Contributor

@AlexAndorra AlexAndorra left a comment

Choose a reason for hiding this comment

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

Thanks @CloudChaoszero, starting to look good!
I added a few comments and suggestions below to make it ready to merge 😉

docs/source/about.rst Outdated Show resolved Hide resolved
docs/source/api/plots.rst Outdated Show resolved Hide resolved
docs/source/api/plots.rst Outdated Show resolved Hide resolved
docs/source/api/stats.rst Outdated Show resolved Hide resolved
pymc3/plots/__init__.py Outdated Show resolved Hide resolved
pymc3/plots/__init__.py Outdated Show resolved Hide resolved
@michaelosthege
Copy link
Member

@CloudChaoszero please try to bundle the commits. Every commit that is pushed causes the entire test pipeline to run, resulting in a lot of unnecessary compute.

When committing suggested changes from Github use the "add suggestion to batch" and when committing locally, try to push all commits at the same time - unless you want to trigger the CI for some specific reason.

Many currently running CI jobs can probably be cancelled..

@CloudChaoszero
Copy link
Contributor Author

please try to bundle the commits. Every commit that is pushed causes the entire test pipeline to run, resulting in a lot of unnecessary compute.....

@michaelosthege Whoops, pardon! 😅 Thanks for the additional details.


@AlexAndorra Updated the PR. I am (slowly) also working on pymc-example PR to update docs, regarding this change.

Copy link
Contributor

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Nice - barring a couple of nitpicks, this looks good to me

@@ -1,4 +1,4 @@
# Copyright 2020 The PyMC Developers
# Copyright 2021 The PyMC Developers
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this needs to change (and if it does, I think the change needs doing for the whole codebase?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, let's not change that here then

"exploratory analysis of Bayesian models." See https://arviz-devs.github.io/arviz/
for details on plots.
Plots are delegated to the `ArviZ <https://arviz-devs.github.io/arviz/>`_ library, a general purpose library for
"exploratory analysis of Bayesian models." For more details, see https://arviz-devs.github.io/arviz/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"exploratory analysis of Bayesian models." For more details, see https://arviz-devs.github.io/arviz/
"exploratory analysis of Bayesian models". For more details, see https://arviz-devs.github.io/arviz/ .

Copy link
Member

Choose a reason for hiding this comment

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

I would actually remove the " in exploratory analysis of Bayesian models.

Plots are delegated to the `ArviZ <https://arviz-devs.github.io/arviz/>`_ library, a general purpose library for
"exploratory analysis of Bayesian models." For more details, see https://arviz-devs.github.io/arviz/

Only the `plot_posterior_predictive_glm` is kept in the PyMC code base for now, but it'll will move to ArviZ once the latter adds features for regression plot.
Copy link
Contributor

@MarcoGorelli MarcoGorelli Jan 17, 2021

Choose a reason for hiding this comment

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

Suggested change
Only the `plot_posterior_predictive_glm` is kept in the PyMC code base for now, but it'll will move to ArviZ once the latter adds features for regression plot.
Only `plot_posterior_predictive_glm` is kept in the PyMC code base for now, but it will move to ArviZ once the latter adds features for regression plots.

Copy link
Contributor

@AlexAndorra AlexAndorra 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 the quick update @CloudChaoszero ! Still a few typos to iron out

- :func:`pymc3.densityplot <arviz:arviz.plot_density>`
- :func:`pymc3.pairplot <arviz:arviz.plot_pair>`
.. warning::
The `plot_posterior_predictive_glm` function will removed in a future PyMC3 release.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The `plot_posterior_predictive_glm` function will removed in a future PyMC3 release.
The `plot_posterior_predictive_glm` function will be removed in a future PyMC3 release.

@@ -1,4 +1,4 @@
# Copyright 2020 The PyMC Developers
# Copyright 2021 The PyMC Developers
Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, let's not change that here then

"exploratory analysis of Bayesian models." See https://arviz-devs.github.io/arviz/
for details on plots.
Plots are delegated to the `ArviZ <https://arviz-devs.github.io/arviz/>`_ library, a general purpose library for
"exploratory analysis of Bayesian models." For more details, see https://arviz-devs.github.io/arviz/
Copy link
Member

Choose a reason for hiding this comment

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

I would actually remove the " in exploratory analysis of Bayesian models.

- :func:`pymc3.kdeplot <arviz:arviz.plot_kde>`
- :func:`pymc3.densityplot <arviz:arviz.plot_density>`
- :func:`pymc3.pairplot <arviz:arviz.plot_pair>`
.. warning::
Copy link
Member

Choose a reason for hiding this comment

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

I would not use an sphinx warning here but inside its api docs.

"""Plot posterior predictive of a linear model.

    Parameters
    ----------
    trace : arviz.InferenceData or MultiTrace
        Output of pm.sample()
    eval : array_like
        Array over which to evaluate lm
    lm : function, default: linear function
        Function mapping parameters at different points
        to their respective outputs.
            input: point, sample
            output: estimated value
    samples : int, default=30
        How many posterior samples to draw.
    kwargs : mapping, optional
        Additional keyword arguments are passed to ``matplotlib.pyplot.plot()``.

    Warnings
    --------
    The `plot_posterior_predictive_glm` function will removed in a future PyMC3 release.
    """

something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds great @OriolAbril I added it. However, the Warning did not show in my local version. 🤷

Screen Shot 2021-01-17 at 10 21 45 PM

@CloudChaoszero
Copy link
Contributor Author

Sounds great @AlexAndorra. I went ahead and also updated the plots docs to have the warning be withing the plot_posterior_predictive_glm , from recommendation from @ OriolAbril.

Example
Screen Shot 2021-01-17 at 10 21 45 PM

@CloudChaoszero CloudChaoszero changed the title [WIP] Pymc3 Plot & Diagnostics & Arviz Dependency Pymc3 Plot & Diagnostics & Arviz Dependency Jan 18, 2021
Copy link
Member

@OriolAbril OriolAbril left a comment

Choose a reason for hiding this comment

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

I take the warning in the api docs is working with the current docstring? The two images without the warning are the same and don't match the docstring text. Other than that everything looks great

pymc3/plots/posteriorplot.py Show resolved Hide resolved
🔥 Remove arviz plots
* Remove directly imported arviz plots used in pymc3 plots

🔥 Remove all plots from PyMC3 Plots module

🔥 Remove PyMC3 plots references in Docs

🎨 Mention Plotting & Diagnostics in API page and remove plots reference in __init__.py

⏪ Revert posterior_plot function, test, and docs

🎨 Add deprecation warning to posterior_plot function

🎨 Add context on plot import and import back into __init__.py

✏️ Add warning and details of posterior_plot added

Update docs/source/api/plots.rst

Co-authored-by: Alexandre ANDORRA <andorra.alexandre@gmail.com>

Update docs/source/api/plots.rst

Co-authored-by: Alexandre ANDORRA <andorra.alexandre@gmail.com>

Update pymc3/plots/__init__.py

Co-authored-by: Alexandre ANDORRA <andorra.alexandre@gmail.com>

Update pymc3/plots/__init__.py

Co-authored-by: Alexandre ANDORRA <andorra.alexandre@gmail.com>

✏️ Update docs to add stats.rst details

✏️ Minor docs notation for posterioplot function(s)

📝 Add breakline before docstring title
Copy link
Contributor

@AlexAndorra AlexAndorra left a comment

Choose a reason for hiding this comment

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

Thanks @CloudChaoszero ! Found one last typo. And does the warning display in the plot docs now?

pymc3/plots/posteriorplot.py Outdated Show resolved Hide resolved
docs/source/api/plots.rst Outdated Show resolved Hide resolved
@CloudChaoszero
Copy link
Contributor Author

CloudChaoszero commented Jan 18, 2021

And does the warning display in the plot docs now?

Done! And @AlexAndorra I believe not.
However, that was in my local build. Unsure if the same will be displayed.

  • Quite odd that the Warnings section did not show. We do have the DeprecateWarning in the function though... 🤷 haha

Screen Shot 2021-01-18 at 2 24 38 AM

@AlexAndorra
Copy link
Contributor

Yeah but we definitely need this warning in the docs as well. And I don't see why it would not work for you locally but work when we recompile the new docs. What do you think @OriolAbril ?
The last thing we can do is add back the warning in the docs text (as well as keep it in the function docstrings).

@MarcoGorelli
Copy link
Contributor

@CloudChaoszero did you do make clean before rebuilding? It appears fine for me

image

@CloudChaoszero
Copy link
Contributor Author

@CloudChaoszero did you do make clean before rebuilding? It appears fine for me

@MarcoGorelli Hmm, maybe not. But yeah, that looks good to me! 👏 thanks for verifying.

CC: @AlexAndorra

Copy link
Contributor

@AlexAndorra AlexAndorra left a comment

Choose a reason for hiding this comment

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

Aaaah, perfect then, thanks for chiming in with some doc magic @MarcoGorelli 🧙‍♂️
This is good to merge now 🥳 Thanks @CloudChaoszero !

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.

Remove Plots & Diagnostics from PyMC Code Base
6 participants