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

Replacing PyMC3 plots w/ Arviz plots & sigma Param change [Part 7] #19

Merged

Conversation

CloudChaoszero
Copy link
Contributor

Description

The following is a large PR breakdown of PR #16.

Replace PyMC3 dependent plots with arviz plots in case studies & examples.

Replace parameter sd with sigma (e.g. some examples have pm.Normal(...sd=...)

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@review-notebook-app
Copy link

review-notebook-app bot commented Jan 29, 2021

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2021-01-29T16:18:25Z
----------------------------------------------------------------

Where did the output of summary() go?


CloudChaoszero commented on 2021-02-02T05:15:43Z
----------------------------------------------------------------

I ignored this, as there was an error in the above cell that I was not able to run. I did not how to go about resolving it, seen below.

Section: "Create fine model and perform inference"

RuntimeError                              Traceback (most recent call last)
<ipython-input-23-17659000b718> in <module>
     29     method_names.append("Metropolis")
     30     traces.append(
---> 31         pm.sample(
     32             draws=ndraws,
     33             step=step_metropolis,
.........
~/opt/anaconda3/envs/pymc3-dev/lib/python3.8/site-packages/pymc3/parallel_sampling.py in recv_draw(processes, timeout)
    357             else:
    358                 error = RuntimeError("Chain %s failed." % proc.chain)
--> 359             raise error from old_error
    360         elif msg[0] == "writing_done":
    361             proc._readable = True

RuntimeError: Chain 0 failed.

CloudChaoszero commented on 2021-02-02T05:54:14Z
----------------------------------------------------------------

Small update:

I found this PR (#3844) and added:

        mp_ctx="forkserver",
        pickle_backend='dill',
        return_inferencedata=True

However, now I am getting the following:

Multiprocess sampling (2 chains in 2 jobs)
MLDA: [x, Intercept]

 0.00% [0/8000 00:00<00:00 Sampling 2 chains, 0 divergences]


RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/Users/CloudChaoszero/opt/anaconda3/envs/pymc3-dev/lib/python3.8/site-packages/theano/compile/function/types.py", line 970, in call
self.fn()
File "/Users/CloudChaoszero/opt/anaconda3/envs/pymc3-dev/lib/python3.8/site-packages/theano/gof/op.py", line 912, in rval
r = p(n, [x[0] for x in i], o)
File "<ipython-input-5-06c97d253f6f>", line 33, in perform
NameError: name 'np' is not defined

@review-notebook-app
Copy link

review-notebook-app bot commented Jan 29, 2021

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2021-01-29T16:18:25Z
----------------------------------------------------------------

Also misses the outputs of the samplers.


@review-notebook-app
Copy link

review-notebook-app bot commented Jan 29, 2021

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2021-01-29T16:18:26Z
----------------------------------------------------------------

no plot


CloudChaoszero commented on 2021-02-02T05:16:59Z
----------------------------------------------------------------

This and other parts of this file are subsequent to the error from the first comment, unfortunately. Let me know what next steps I should take in this case. :)

CloudChaoszero commented on 2021-02-07T06:43:24Z
----------------------------------------------------------------

acknowledeged now :D

@review-notebook-app
Copy link

review-notebook-app bot commented Jan 29, 2021

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2021-01-29T16:18:27Z
----------------------------------------------------------------

no plot


@@ -533,7 +533,7 @@
}
Copy link
Member

@twiecki twiecki Jan 29, 2021

Choose a reason for hiding this comment

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

Should probably add the model context to this and below to future proof this and get rid of the annoying warning.


Reply via ReviewNB

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. I quite didn't understand what the FutureWarning recommended, but I am happy to update the description as a PR.

Here was my take on what the FutureWarning recommended haha:

with model:
    trace2_az = az.from_pymc3(trace2)
az.summary(trace2_az)

Copy link
Member

twiecki commented Jan 29, 2021

Reviewed all of these, looks great but see comments.

Copy link
Contributor Author

I ignored this, as there was an error in the above cell that I was not able to run. I did not how to go about resolving it, seen below.

Section: "Create fine model and perform inference"

RuntimeError                              Traceback (most recent call last)
<ipython-input-23-17659000b718> in <module>
     29     method_names.append("Metropolis")
     30     traces.append(
---> 31         pm.sample(
     32             draws=ndraws,
     33             step=step_metropolis,
.........
~/opt/anaconda3/envs/pymc3-dev/lib/python3.8/site-packages/pymc3/parallel_sampling.py in recv_draw(processes, timeout)
    357             else:
    358                 error = RuntimeError("Chain %s failed." % proc.chain)
--> 359             raise error from old_error
    360         elif msg[0] == "writing_done":
    361             proc._readable = True

RuntimeError: Chain 0 failed.


View entire conversation on ReviewNB

Copy link
Contributor Author

This and other parts of this file are subsequent to the error from the first comment, unfortunately. Let me know what next steps I should take in this case. :)


View entire conversation on ReviewNB

Copy link
Contributor Author

Small update:

I found this PR and added:

        mp_ctx="forkserver",
        pickle_backend='dill',
        return_inferencedata=True

However, now I am getting the following:

Multiprocess sampling (2 chains in 2 jobs)
MLDA: [x, Intercept]

 0.00% [0/8000 00:00<00:00 Sampling 2 chains, 0 divergences]


RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/Users/CloudChaoszero/opt/anaconda3/envs/pymc3-dev/lib/python3.8/site-packages/theano/compile/function/types.py", line 970, in call
self.fn()
File "/Users/CloudChaoszero/opt/anaconda3/envs/pymc3-dev/lib/python3.8/site-packages/theano/gof/op.py", line 912, in rval
r = p(n, [x[0] for x in i], o)
File "<ipython-input-5-06c97d253f6f>", line 33, in perform
NameError: name 'np' is not defined


View entire conversation on ReviewNB

@twiecki
Copy link
Member

twiecki commented Feb 2, 2021

Can you try updating PyMC3 and Theano? Otherwise this seems like a Aesara bug. CC @brandonwillard

@brandonwillard
Copy link

That environment's version of Theano is too old; you can tell by the module name: theano.gof.op.

@CloudChaoszero
Copy link
Contributor Author

@brandonwillard Thanks for the response! Hmm, unfortunately I get some more errors. I updated the particular notebook to show the error, seen below.

(If the details are too much for this PR, I can submit a detailed issue in Aesara? Let me know!)


Adding these params in pm.sample()

    method_names.append("Metropolis")
    traces.append(
        pm.sample(
            draws=ndraws,
            step=step_metropolis,
            chains=nchains,
            tune=nburn,
            discard_tuned_samples=discard_tuning,
            random_seed=sampling_seed,
            start=MAP,
            mp_ctx="forkserver",
            pickle_backend='dill',
        )

I get
Screen Shot 2021-02-04 at 3 03 07 AM
due to dill pickle'ing. Well, I suspect that is the reason.

If I do not add the params

            mp_ctx="forkserver",
            pickle_backend='dill',

then I get a chained 0 error 😢

@brandonwillard
Copy link

Please, provide the complete trace as formatted markdown. If the trace is too large, it can be wrapped in HTML <details> tags (e.g. here).

@CloudChaoszero
Copy link
Contributor Author

CloudChaoszero commented Feb 7, 2021

@brandonwillard Thanks for that! (useful tip 🔥 )

Here is the Gist for when we use

            mp_ctx="forkserver",
            pickle_backend='dill',

https://gist.github.com/CloudChaoszero/2ffbc8efa6157786102c8a4659bf5c11


Here is the Gist for when we do not use the params, originally in the notebook
https://gist.github.com/CloudChaoszero/6078a62bad062cc9ab541e150c914d49

@brandonwillard
Copy link

I don't see any connections to Theano-PyMC, but a quick search did yield this open dill issue.

@CloudChaoszero
Copy link
Contributor Author

I don't see any connections to Theano-PyMC, but a quick search did yield this open dill issue.

@brandonwillard Thanks for checking it out. After some further research, I founda. workaround is to use cores param to help out with this. I found this workaround from the PyMC3 Discourse, found here.

Here is what I added at the end of each pm.sample():
cores != None...i.e.

            cores=1,
            mp_ctx="forkserver",

Copy link
Contributor Author

acknowledeged now :D


View entire conversation on ReviewNB

@CloudChaoszero
Copy link
Contributor Author

As a note, I updated my package dependencies and did more research this time on navigating the errors encountered with pymc3.

In particular, this PR uses cores=1 in pm.sample() and some other small changes.

  • Though the perf runs long, it was successfully. 😄
Deps
pymc3                     3.11.0                    dev_0    <develop>
theano-pymc               1.1.2                    pypi_0    pypi

@twiecki twiecki merged commit f624891 into pymc-devs:main Feb 7, 2021
@twiecki
Copy link
Member

twiecki commented Feb 7, 2021

Thanks @CloudChaoszero!

@CloudChaoszero CloudChaoszero deleted the replace-pymc3-arviz-plots_part7 branch April 5, 2021 01:53
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