Skip to content

Use arviz for plotting #3338

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

Merged
merged 7 commits into from
Mar 2, 2019
Merged

Use arviz for plotting #3338

merged 7 commits into from
Mar 2, 2019

Conversation

ColCarroll
Copy link
Member

This starts moving pymc3 plotting over to arviz. Other things I'd like to include in this PR:

  1. Update setup.py to include arviz as optional (pip install pymc3[all] or pip install pymc3[plots]?)
  2. Rerun at least a few notebooks to make sure the graphs are actually well supported.

This is still WIP because of arviz-devs/arviz#529

I am also making an issue for plot_posterior_predictive_glm, which is heavily used in the GLM notebooks, but not yet supported by arviz. I think there's interest in doing so, though!

Here's an example running under this PR (and the arviz PR). Note that as a side effect of this change, traceplot is more flexible.

image

@twiecki
Copy link
Member

twiecki commented Jan 14, 2019

image

@eigenfoo
Copy link
Member

Deleted code is debugged code!!

@aloctavodia
Copy link
Member

The documentation will be updated as part of this PR, or a separated one?

@canyon289
Copy link
Member

Wellll, the code has just shifted :)

But it has become more general purpose which is still a win!

@ColCarroll
Copy link
Member Author

  • Fixed f-string
  • The API docs for plots will now include a link to the ArviZ documentation
  • pip install pymc3[plots] will include arviz, otherwise it remains optional

az = _ArviZ()


autocorrplot = az.plot_autocorr
Copy link
Member

Choose a reason for hiding this comment

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

Its tempting to reconcile the names, but I suppose we should just leave things be.

Copy link
Member Author

Choose a reason for hiding this comment

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

from running through the first notebook, varnames --> var_names is the worst right now. I am a little tempted to add a decorator just for that case:

def map_args(func):
    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        if 'varnames' in kwargs and 'var_names' not in kwargs:
            warnings.warn('Keyword argument `varnames` renamed to `var_names`, and will be removed in pymc3 3.8.0')
            kwargs['var_names'] = kwargs.pop('varnames')
        return func(*args, **kwargs)
    return wrapped

Thoughts on that?

Copy link
Member

Choose a reason for hiding this comment

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

I think that's a good idea.

@twiecki
Copy link
Member

twiecki commented Jan 15, 2019

As the plan is to eventually remove this, we should probably also raise deprecation warnings. Ideally with the new call if that's not too cumbersome to do.

@ColCarroll
Copy link
Member Author

Wait... is the plan to eventually remove this? I guess in favor of just using arviz directly?

@fonnesbeck
Copy link
Member

fonnesbeck commented Jan 15, 2019

I think we should have pm.plot_trace (for example) that is pure Arviz and then have a mapping to pm.traceplot that converts the arguments as well, so that it behaves just as traceplot currently does.

I don't think we should deprecate traceplot, it should just remain available, but the documentation will describe plot_trace going forward. This will allow us to make the changes we want without breaking old code (or littering output with deprecations).

@ColCarroll
Copy link
Member Author

ah, neat -- I think I can just dump az.plots.__all__ into pm.plot.__all__ to get the "pure arviz" part of things. Then we can do custom stuff to pm.traceplot and the like.

@ColCarroll
Copy link
Member Author

Sorry for the long pause. I addressed these two issues:

  • both original names and arviz names work now. if we want to customize a plot, we can override the pymc3 name
  • I put a small deprecation warning function in (the same one from this discussion)

Here's a traceplot using both pm.plot_trace and pm.traceplot(..., var_names=...):

image

@fonnesbeck
Copy link
Member

Is this still a WIP?

@ColCarroll ColCarroll changed the title [WIP] Use arviz for plotting Use arviz for plotting Feb 15, 2019
@ColCarroll
Copy link
Member Author

Oops, changed the title - I think it is ready. Tab completion and docs come from arviz, and look ok to me.

I will mess with the tests tomorrow to get them passing. I haven't played around too much without arviz installed, which might be causing CI problems.

@twiecki
Copy link
Member

twiecki commented Feb 15, 2019

+++pip install -e .
Obtaining file:///home/travis/build/pymc-devs/pymc3
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/travis/build/pymc-devs/pymc3/setup.py", line 66
        tests_require=test_reqs,
                    ^
    SyntaxError: invalid syntax
    
    ----------------------------------------

@twiecki
Copy link
Member

twiecki commented Feb 15, 2019

Looks great. Needs a prominent line in the release notes.

We should probably also fix the docs, but certainly can do that in a separate PR.

@junpenglao
Copy link
Member

We should have a docathon week for update all docs ;-)

@ColCarroll
Copy link
Member Author

Looks like there was a surprising test failure because we are now picking up numpy 1.16.

@ColCarroll
Copy link
Member Author

This looks ready to merge again. There was a travis failure from trying to send data to coveralls.

@ericmjl
Copy link
Member

ericmjl commented Mar 2, 2019

I'm hitting the big green button!

@ericmjl ericmjl merged commit 1e282eb into pymc-devs:master Mar 2, 2019
@ericmjl
Copy link
Member

ericmjl commented Mar 2, 2019

Thanks @ColCarroll!

@twiecki
Copy link
Member

twiecki commented Mar 2, 2019

Niceeeee!

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.

8 participants