TuringLang / docs

Documentation and tutorials for the Turing language
https://turinglang.org/docs/
MIT License
229 stars 99 forks source link

Please help a new Julia user with an error in the 00-introduction notebook. #390

Closed CBrauer closed 1 year ago

CBrauer commented 1 year ago

I’m and new user of Julia and I am very interested in the “Turing Tutorials”. I have installed Julia 1.9.0 and I have followed the instructions on loading the tutorial notebooks. After adding the necessary packages. I then did a “Restart & Run All” under the Kernel menu of the “00-introduction” notebook. The execution got down to cell 11 and stopped with an error. turing I don't understand this error mesage. Any suggestions will be greatly appreciated. Charles Brauer CBrauer@CypressPoint.com

patrickm663 commented 1 year ago

Hi Charles

Did you come right with this? My first thought is that Turing.jl hasn't been loaded when this cell is run. If not, could you please provide the code you ran up until this point and I can try help debug?

Thanks, Patrick

CBrauer commented 1 year ago

Hi Patrick,

As you requested, I have attached the notebook.

Charles

From: Patrick Moehrke @.> Sent: Monday, June 12, 2023 12:15 PM To: TuringLang/TuringTutorials @.> Cc: Charles Brauer @.>; Author @.> Subject: Re: [TuringLang/TuringTutorials] Please help a new Julia user with an error in the 00-introduction notebook. (Issue #390)

Hi Charles

Did you come right with this? My first thought is that Turing.jl hasn't been loaded when this cell is run. If not, could you please provide the code you ran up until this point and I can try help debug?

Thanks, Patrick

— Reply to this email directly, view it on GitHub https://github.com/TuringLang/TuringTutorials/issues/390#issuecomment-1587932062 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKBS4VXV7YSMOQGTDTC3GLXK5TENANCNFSM6AAAAAAYIAO72A . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AAKBS4SN4GBV5PY5HRO77BTXK5TENA5CNFSM6AAAAAAYIAO72CWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTS6UXVZ4.gif Message ID: @. @.> >

patrickm663 commented 1 year ago

Hi @CBrauer

I don't believe the notebook is attached as I think the GitHub only retains the body of the email when replying to an Issue. Could you please add the code contained in your notebook in plain text that I can test it on my side?

Thanks. Patrick

CBrauer commented 1 year ago

Hi Patrick,

The notebook in question can be downloaded from: TuringTutorials/tutorials at master · TuringLang/TuringTutorials (github.com) https://github.com/TuringLang/TuringTutorials/tree/master/tutorials

I have attached a PDF of the notebook. It shows the cell in question.

Charles

From: Patrick Moehrke @.> Sent: Thursday, June 15, 2023 12:23 AM To: TuringLang/TuringTutorials @.> Cc: Charles Brauer @.>; Mention @.> Subject: Re: [TuringLang/TuringTutorials] Please help a new Julia user with an error in the 00-introduction notebook. (Issue #390)

Hi @CBrauer https://github.com/CBrauer

I don't believe the notebook is attached as I think the GitHub only retains the body of the email when replying to an Issue. Could you please add the code contained in your notebook in plain text that I can test it on my side?

Thanks. Patrick

— Reply to this email directly, view it on GitHub https://github.com/TuringLang/TuringTutorials/issues/390#issuecomment-1592501262 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKBS4WAPELWSAN5PS347CTXLKZ4HANCNFSM6AAAAAAYIAO72A . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AAKBS4WQSCT5RVMGGCBQVI3XLKZ4HA5CNFSM6AAAAAAYIAO72CWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTS65OSA4.gif Message ID: @. @.> >

patrickm663 commented 1 year ago

Hi Charles

Thank you, I had missed that it was a clean copy you're using. Unfortunately I don't receive your attatchments through GitHub Issues, but screenshots work. However, I suspect Turing isn't being loaded properly. Alternatively, Jupyter Notebooks isn't playing nice with macros.

Here is a minimum example you can test:

using Turing
using MCMCChains
using Distributions
using Random
using StatsPlots

# Create some coin flip data
N = 25
data = rand(Bernoulli(0.5), N);

# Check the average number of Heads
mean(data)

# Define our model and priors
@model function coin_flip(y)
    n = length(y)
    p ~ Beta(1, 1)
    y ~ filldist(Bernoulli(p), n)
    return Nothing
end

# Control how many samples we take
n_samples = 1_000
n_chains = 4

# Sample using NUTS, given our observations
chain = sample(coin_flip(data), NUTS(), MCMCThreads(), n_samples, n_chains)

# Plot the prior after sampling
plot(chain)

# Produce a summary table of our posteriors containing its mean, standard deviation, etc.
describe(chain)

Hope this helps!

Regards Patrick

CBrauer commented 1 year ago

Hi Patrick,

Thanks for the script. Here is a screen capture of your script running in a Julia 1.9.1 notebook. Notice that a plot was not produced and the "describe" did not work.

test

patrickm663 commented 1 year ago

Hi Charles

It seems the code ran end-to-end - so Turing worked here - however output only showed the last print to screen (Jupyter seems to supress multiple outputs I think unless they are explicit warnings, errors, console prints, etc.).

Perhaps try run describe and plot in separate cells? I also notice the mean call did not print to console. You can try seperate the code based off my line spaces and write them into separate cells and run it top to bottom. As a script however, I think the @show macro may work when not explicitly calling print.

Let me know if you are able to see the plots and summary tables!

CBrauer commented 1 year ago

Hi Patrick,

I did as you suggested, and I put the code in separate cells. Here is a screen capture of my running notebook: capture

Your code crashed the notebook. The execution never gets past the second cell.

You said that I should place the code in separate cells to see the plot output, and describe output. What if I executed the "test.jl" script in the Julia REPL? Would you expect the REPL to give the plot and describe print correctly? Well, it doesn't.

Here is what happens when I execute your code in the REPL:

julia> include("test.jl")
┌ Warning: Only a single thread available: MCMC chains are not sampled in parallel
└ @ AbstractMCMC C:\Julia-1.9.1\bin\packages\AbstractMCMC\bE6VB\src\sample.jl:296

┌ Info: Found initial step size
└   ϵ = 1.6
┌ Info: Found initial step size
└   ϵ = 0.8
┌ Info: Found initial step size
└   ϵ = 1.6
┌ Info: Found initial step size
└   ϵ = 0.8
Sampling (1 threads) 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:00:12
done.
julia>

As a new user to Julia, I'm getting rather discouraged.

Charles