{"action":"created","comment":{"url":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/comments/352595004","pull_request_review_id":325236504,"id":352595004,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDM1MjU5NTAwNA==","diff_hunk":"@@ -119,6 +114,15 @@ Sampler(alg) = Sampler(alg, Selector())\n Sampler(alg, model::Model) = Sampler(alg, model, Selector())\n Sampler(alg, model::Model, s::Selector) = Sampler(alg, model, s)\n \n+abstract type AbstractContext end\n+struct DefaultContext <: AbstractContext end\n+struct LikelihoodContext <: AbstractContext end\n+struct BatchContext{Tctx, T} <: AbstractContext","path":"src/Turing.jl","position":75,"original_position":75,"commit_id":"22dab765a45105e43a9cf59398546c10f1c46a98","original_commit_id":"22dab765a45105e43a9cf59398546c10f1c46a98","user":{"login":"yebai","id":3279477,"node_id":"MDQ6VXNlcjMyNzk0Nzc=","avatar_url":"https://avatars2.githubusercontent.com/u/3279477?v=4","gravatar_id":"","url":"https://api.github.com/users/yebai","html_url":"https://github.com/yebai","followers_url":"https://api.github.com/users/yebai/followers","following_url":"https://api.github.com/users/yebai/following{/other_user}","gists_url":"https://api.github.com/users/yebai/gists{/gist_id}","starred_url":"https://api.github.com/users/yebai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yebai/subscriptions","organizations_url":"https://api.github.com/users/yebai/orgs","repos_url":"https://api.github.com/users/yebai/repos","events_url":"https://api.github.com/users/yebai/events{/privacy}","received_events_url":"https://api.github.com/users/yebai/received_events","type":"User","site_admin":false},"body":"cc @willtebbutt @trappmartin ","created_at":"2019-12-02T13:30:18Z","updated_at":"2019-12-02T13:30:18Z","html_url":"https://github.com/TuringLang/Turing.jl/pull/965#discussion_r352595004","pull_request_url":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/965","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/comments/352595004"},"html":{"href":"https://github.com/TuringLang/Turing.jl/pull/965#discussion_r352595004"},"pull_request":{"href":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/965"}},"in_reply_to_id":352594808},"pull_request":{"url":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/965","id":341836974,"node_id":"MDExOlB1bGxSZXF1ZXN0MzQxODM2OTc0","html_url":"https://github.com/TuringLang/Turing.jl/pull/965","diff_url":"https://github.com/TuringLang/Turing.jl/pull/965.diff","patch_url":"https://github.com/TuringLang/Turing.jl/pull/965.patch","issue_url":"https://api.github.com/repos/TuringLang/Turing.jl/issues/965","number":965,"state":"open","locked":false,"title":"Compiler 3.0","user":{"login":"mohamed82008","id":19524993,"node_id":"MDQ6VXNlcjE5NTI0OTkz","avatar_url":"https://avatars1.githubusercontent.com/u/19524993?v=4","gravatar_id":"","url":"https://api.github.com/users/mohamed82008","html_url":"https://github.com/mohamed82008","followers_url":"https://api.github.com/users/mohamed82008/followers","following_url":"https://api.github.com/users/mohamed82008/following{/other_user}","gists_url":"https://api.github.com/users/mohamed82008/gists{/gist_id}","starred_url":"https://api.github.com/users/mohamed82008/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mohamed82008/subscriptions","organizations_url":"https://api.github.com/users/mohamed82008/orgs","repos_url":"https://api.github.com/users/mohamed82008/repos","events_url":"https://api.github.com/users/mohamed82008/events{/privacy}","received_events_url":"https://api.github.com/users/mohamed82008/received_events","type":"User","site_admin":false},"body":"This WIP PR will include yet another refactor of the internals of Turing with the following main goals:\r\n1. Readability,\r\n2. Modularity to be able to move the compiler to DynamicPPL at some point,\r\n3. Flexibility and extensibility to enable the adding of features which are now tricky to implement, e.g. querying the likelihood, and finally\r\n4. Interoperability with other PPL approaches to enable interop with Soss, Gen and ProbabilityModels.\r\n\r\nThis PR currently implements the following features:\r\n- Full-fledged support for partially missing values with automatic differentiation. For example, the following will treat `x[1]` and `x[3]` as random variables and `x[2]` and `x[4]` as observations:\r\n```julia\r\n@model f(x) = begin\r\n    for i in 1:length(x)\r\n        x[i] ~ Normal()\r\n    end\r\nend\r\nsample(f([missing, 1.0, missing, 2.0]), NUTS(10, 0.65), 1000)\r\n``` \r\n- The way in which arguments to the model are handled was significantly changed. Every argument now needs to be defined either when constructing the model or by setting a default value that works the same way a default value works in Julia. When an input variable can be missing, its input value should be `missing`. This can be input when constructing the model or using the default value. If this missing variable is a vector and we need to loop or broadcast over it inside the model, the user needs to do: \r\n```julia\r\n@model f(x, ::Type{T} = Float64) where {T} = begin\r\n    if ismissing(x)\r\n        x = Vector{T}(undef, 10)\r\n    end\r\n    for i in 1:length(x)\r\n        x[i] ~ Normal()\r\n    end\r\nend\r\n```\r\nNote that any model argument whose value is not `missing` is not going to be handled as a random variable and will be treated as an observation. If an argument has no default value and is not input when constructing the `Turing.Model`, an error will be thrown. Note that the above `ismissing` if-block is only needed if we need to loop over `x`. If we only need `x ~ MvNormal(...)` or something similar, then there is no need to initialize it when `ismissing(x)` is true.\r\n- Running the model now happens in a context, `DefaultContext` by default to calculate the log joint probability. But we can also run the model in different contexts to evaluate variants of the `logp`. For example, I defined the `LikelihoodContext` which enables the computation of the log likelihood only instead of the log joint probability. Another context defined is the `BatchContext` that computes `logprior + s * loglikelihood`, where `s = npoints / batch_size`. This is important for stochastic (batch-based) gradient algorithms to be optimizing the original objective in the expectation, and not highly weighing the prior.\r\n- The user can now tap into the `VarInfo` object in the model definition using the macro `@varinfo()`. This is not a real macro and will throw if called outside the `@model` definition. However, inside the `@model` definition, one can use this to get a handle to the `VarInfo` object inside the model run for more advanced use cases. There is also `@logpdf()` which simply returns the current accumulated value of the log joint probability or whatever the context is having the model compute.\r\n- Random variable names are now _not_ baked into the `Turing.Model` type and can be passed by the user using the special distribution type `NamedDist(dist, name)`. So `x ~ NamedDist(dist, name)` will have the random variable named `name` not `x`. `name` can be a string or a `Turing.VarName`.\r\n- The `VarName` constructor is now very neat and intuitive. You can do `vn = Turing.@varname x[1,:][i]` to get a `VarName{:x}` with `vn.indexing == \"[1,Colon()][$i]\"`, whatever `i` is.\r\n- And last but not least, broadcasting the `~` symbol is now supported for both observations and random variables. One can do `x .~ dist` to mean that all elements of `x` are distributed according to `dist`. The main difference between `~` and `.~` in usage is that `~` doesn't assume the left-hand-side to be defined while `.~` does. So using `x .~ dist` when `x` wasn't previously defined will lead to an error. Broadcasting will work column-wise when `dist isa MultivariateDistribution` and `x isa AbstractMatrix` but not `AbstractMatrix{>:AbstractVector}`. If `x isa AbstractMatrix{Any}` for example, the broadcasting semantics here become ambiguous so we throw an error. This should not be an issue for most use cases.\r\n\r\nI still need to do more tests and rebase but I thought I should write this summary now because there will be no more features added to this PR, just fixes from now on.","created_at":"2019-11-17T09:47:15Z","updated_at":"2019-12-02T13:30:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b8f3de5d4f038d5a510c9d2a2636710a5b67d58d","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/965/commits","review_comments_url":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/965/comments","review_comment_url":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/TuringLang/Turing.jl/issues/965/comments","statuses_url":"https://api.github.com/repos/TuringLang/Turing.jl/statuses/22dab765a45105e43a9cf59398546c10f1c46a98","head":{"label":"TuringLang:mt/compiler3.0","ref":"mt/compiler3.0","sha":"22dab765a45105e43a9cf59398546c10f1c46a98","user":{"login":"TuringLang","id":26261527,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI2MjYxNTI3","avatar_url":"https://avatars1.githubusercontent.com/u/26261527?v=4","gravatar_id":"","url":"https://api.github.com/users/TuringLang","html_url":"https://github.com/TuringLang","followers_url":"https://api.github.com/users/TuringLang/followers","following_url":"https://api.github.com/users/TuringLang/following{/other_user}","gists_url":"https://api.github.com/users/TuringLang/gists{/gist_id}","starred_url":"https://api.github.com/users/TuringLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TuringLang/subscriptions","organizations_url":"https://api.github.com/users/TuringLang/orgs","repos_url":"https://api.github.com/users/TuringLang/repos","events_url":"https://api.github.com/users/TuringLang/events{/privacy}","received_events_url":"https://api.github.com/users/TuringLang/received_events","type":"Organization","site_admin":false},"repo":{"id":57377821,"node_id":"MDEwOlJlcG9zaXRvcnk1NzM3NzgyMQ==","name":"Turing.jl","full_name":"TuringLang/Turing.jl","private":false,"owner":{"login":"TuringLang","id":26261527,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI2MjYxNTI3","avatar_url":"https://avatars1.githubusercontent.com/u/26261527?v=4","gravatar_id":"","url":"https://api.github.com/users/TuringLang","html_url":"https://github.com/TuringLang","followers_url":"https://api.github.com/users/TuringLang/followers","following_url":"https://api.github.com/users/TuringLang/following{/other_user}","gists_url":"https://api.github.com/users/TuringLang/gists{/gist_id}","starred_url":"https://api.github.com/users/TuringLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TuringLang/subscriptions","organizations_url":"https://api.github.com/users/TuringLang/orgs","repos_url":"https://api.github.com/users/TuringLang/repos","events_url":"https://api.github.com/users/TuringLang/events{/privacy}","received_events_url":"https://api.github.com/users/TuringLang/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/TuringLang/Turing.jl","description":"A library for robust, efficient, general-purpose probabilistic programming","fork":false,"url":"https://api.github.com/repos/TuringLang/Turing.jl","forks_url":"https://api.github.com/repos/TuringLang/Turing.jl/forks","keys_url":"https://api.github.com/repos/TuringLang/Turing.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TuringLang/Turing.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TuringLang/Turing.jl/teams","hooks_url":"https://api.github.com/repos/TuringLang/Turing.jl/hooks","issue_events_url":"https://api.github.com/repos/TuringLang/Turing.jl/issues/events{/number}","events_url":"https://api.github.com/repos/TuringLang/Turing.jl/events","assignees_url":"https://api.github.com/repos/TuringLang/Turing.jl/assignees{/user}","branches_url":"https://api.github.com/repos/TuringLang/Turing.jl/branches{/branch}","tags_url":"https://api.github.com/repos/TuringLang/Turing.jl/tags","blobs_url":"https://api.github.com/repos/TuringLang/Turing.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TuringLang/Turing.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TuringLang/Turing.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/TuringLang/Turing.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TuringLang/Turing.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/TuringLang/Turing.jl/languages","stargazers_url":"https://api.github.com/repos/TuringLang/Turing.jl/stargazers","contributors_url":"https://api.github.com/repos/TuringLang/Turing.jl/contributors","subscribers_url":"https://api.github.com/repos/TuringLang/Turing.jl/subscribers","subscription_url":"https://api.github.com/repos/TuringLang/Turing.jl/subscription","commits_url":"https://api.github.com/repos/TuringLang/Turing.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/TuringLang/Turing.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/TuringLang/Turing.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/TuringLang/Turing.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/TuringLang/Turing.jl/contents/{+path}","compare_url":"https://api.github.com/repos/TuringLang/Turing.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TuringLang/Turing.jl/merges","archive_url":"https://api.github.com/repos/TuringLang/Turing.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TuringLang/Turing.jl/downloads","issues_url":"https://api.github.com/repos/TuringLang/Turing.jl/issues{/number}","pulls_url":"https://api.github.com/repos/TuringLang/Turing.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/TuringLang/Turing.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/TuringLang/Turing.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TuringLang/Turing.jl/labels{/name}","releases_url":"https://api.github.com/repos/TuringLang/Turing.jl/releases{/id}","deployments_url":"https://api.github.com/repos/TuringLang/Turing.jl/deployments","created_at":"2016-04-29T10:51:43Z","updated_at":"2019-12-01T15:53:11Z","pushed_at":"2019-12-02T03:16:53Z","git_url":"git://github.com/TuringLang/Turing.jl.git","ssh_url":"git@github.com:TuringLang/Turing.jl.git","clone_url":"https://github.com/TuringLang/Turing.jl.git","svn_url":"https://github.com/TuringLang/Turing.jl","homepage":"https://turing.ml","size":28623,"stargazers_count":584,"watchers_count":584,"language":"Julia","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":78,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":123,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":78,"open_issues":123,"watchers":584,"default_branch":"master"}},"base":{"label":"TuringLang:master","ref":"master","sha":"67959c664e61340dd4d6f1da0250c256c3074b71","user":{"login":"TuringLang","id":26261527,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI2MjYxNTI3","avatar_url":"https://avatars1.githubusercontent.com/u/26261527?v=4","gravatar_id":"","url":"https://api.github.com/users/TuringLang","html_url":"https://github.com/TuringLang","followers_url":"https://api.github.com/users/TuringLang/followers","following_url":"https://api.github.com/users/TuringLang/following{/other_user}","gists_url":"https://api.github.com/users/TuringLang/gists{/gist_id}","starred_url":"https://api.github.com/users/TuringLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TuringLang/subscriptions","organizations_url":"https://api.github.com/users/TuringLang/orgs","repos_url":"https://api.github.com/users/TuringLang/repos","events_url":"https://api.github.com/users/TuringLang/events{/privacy}","received_events_url":"https://api.github.com/users/TuringLang/received_events","type":"Organization","site_admin":false},"repo":{"id":57377821,"node_id":"MDEwOlJlcG9zaXRvcnk1NzM3NzgyMQ==","name":"Turing.jl","full_name":"TuringLang/Turing.jl","private":false,"owner":{"login":"TuringLang","id":26261527,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI2MjYxNTI3","avatar_url":"https://avatars1.githubusercontent.com/u/26261527?v=4","gravatar_id":"","url":"https://api.github.com/users/TuringLang","html_url":"https://github.com/TuringLang","followers_url":"https://api.github.com/users/TuringLang/followers","following_url":"https://api.github.com/users/TuringLang/following{/other_user}","gists_url":"https://api.github.com/users/TuringLang/gists{/gist_id}","starred_url":"https://api.github.com/users/TuringLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TuringLang/subscriptions","organizations_url":"https://api.github.com/users/TuringLang/orgs","repos_url":"https://api.github.com/users/TuringLang/repos","events_url":"https://api.github.com/users/TuringLang/events{/privacy}","received_events_url":"https://api.github.com/users/TuringLang/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/TuringLang/Turing.jl","description":"A library for robust, efficient, general-purpose probabilistic programming","fork":false,"url":"https://api.github.com/repos/TuringLang/Turing.jl","forks_url":"https://api.github.com/repos/TuringLang/Turing.jl/forks","keys_url":"https://api.github.com/repos/TuringLang/Turing.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TuringLang/Turing.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TuringLang/Turing.jl/teams","hooks_url":"https://api.github.com/repos/TuringLang/Turing.jl/hooks","issue_events_url":"https://api.github.com/repos/TuringLang/Turing.jl/issues/events{/number}","events_url":"https://api.github.com/repos/TuringLang/Turing.jl/events","assignees_url":"https://api.github.com/repos/TuringLang/Turing.jl/assignees{/user}","branches_url":"https://api.github.com/repos/TuringLang/Turing.jl/branches{/branch}","tags_url":"https://api.github.com/repos/TuringLang/Turing.jl/tags","blobs_url":"https://api.github.com/repos/TuringLang/Turing.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TuringLang/Turing.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TuringLang/Turing.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/TuringLang/Turing.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TuringLang/Turing.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/TuringLang/Turing.jl/languages","stargazers_url":"https://api.github.com/repos/TuringLang/Turing.jl/stargazers","contributors_url":"https://api.github.com/repos/TuringLang/Turing.jl/contributors","subscribers_url":"https://api.github.com/repos/TuringLang/Turing.jl/subscribers","subscription_url":"https://api.github.com/repos/TuringLang/Turing.jl/subscription","commits_url":"https://api.github.com/repos/TuringLang/Turing.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/TuringLang/Turing.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/TuringLang/Turing.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/TuringLang/Turing.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/TuringLang/Turing.jl/contents/{+path}","compare_url":"https://api.github.com/repos/TuringLang/Turing.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TuringLang/Turing.jl/merges","archive_url":"https://api.github.com/repos/TuringLang/Turing.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TuringLang/Turing.jl/downloads","issues_url":"https://api.github.com/repos/TuringLang/Turing.jl/issues{/number}","pulls_url":"https://api.github.com/repos/TuringLang/Turing.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/TuringLang/Turing.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/TuringLang/Turing.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TuringLang/Turing.jl/labels{/name}","releases_url":"https://api.github.com/repos/TuringLang/Turing.jl/releases{/id}","deployments_url":"https://api.github.com/repos/TuringLang/Turing.jl/deployments","created_at":"2016-04-29T10:51:43Z","updated_at":"2019-12-01T15:53:11Z","pushed_at":"2019-12-02T03:16:53Z","git_url":"git://github.com/TuringLang/Turing.jl.git","ssh_url":"git@github.com:TuringLang/Turing.jl.git","clone_url":"https://github.com/TuringLang/Turing.jl.git","svn_url":"https://github.com/TuringLang/Turing.jl","homepage":"https://turing.ml","size":28623,"stargazers_count":584,"watchers_count":584,"language":"Julia","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":78,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":123,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":78,"open_issues":123,"watchers":584,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/965"},"html":{"href":"https://github.com/TuringLang/Turing.jl/pull/965"},"issue":{"href":"https://api.github.com/repos/TuringLang/Turing.jl/issues/965"},"comments":{"href":"https://api.github.com/repos/TuringLang/Turing.jl/issues/965/comments"},"review_comments":{"href":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/965/comments"},"review_comment":{"href":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/TuringLang/Turing.jl/pulls/965/commits"},"statuses":{"href":"https://api.github.com/repos/TuringLang/Turing.jl/statuses/22dab765a45105e43a9cf59398546c10f1c46a98"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"yebai"}}