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

Clean up exports #2474

Merged
merged 30 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e5d182f
Regroup exports by package
penelopeysm Jan 21, 2025
b4ad4ae
Export DynamicPPL.returned and DynamicPPL.prefix
penelopeysm Jan 21, 2025
df41231
Stop exporting @logprob_str and @prob_str
penelopeysm Jan 21, 2025
d914e21
Remove DynamicPPL module export
penelopeysm Jan 21, 2025
a8c8601
Remove DynamicPPL.LogDensityFunction re-export
penelopeysm Jan 21, 2025
a86ac33
Remove BernoulliLogit, drop support for Distributions < 0.25.77
penelopeysm Jan 21, 2025
e6e5961
Stop blanket re-exporting Libtask and Bijectors
penelopeysm Jan 21, 2025
98e53de
Manually specify AbstractMCMC exports
penelopeysm Jan 21, 2025
2d48540
Format
penelopeysm Jan 21, 2025
efdf364
Remove Bijectors.ordered export
penelopeysm Jan 21, 2025
e3c9695
Re-export LinearAlgebra.I
penelopeysm Jan 21, 2025
e9c7cb5
Replace Turing.Model -> DynamicPPL.Model
penelopeysm Jan 21, 2025
473cc91
Merge branch 'main' into py/imports
penelopeysm Mar 17, 2025
8a7826f
Merge remote-tracking branch 'origin/breaking' into py/imports
penelopeysm Mar 17, 2025
b1f8185
Format
penelopeysm Mar 17, 2025
5a36964
Keep exporting LogDensityFunction
penelopeysm Mar 17, 2025
9d5e605
Add note in docs
penelopeysm Mar 17, 2025
433c36d
Align Turing exports with docs API page
penelopeysm Mar 17, 2025
1d036a1
Fix things like `predict` on docs API page
penelopeysm Mar 17, 2025
ea4f977
Fix a Gibbs test
mhauru Mar 17, 2025
2bbd1c3
Format
penelopeysm Mar 17, 2025
b6ccbee
Fix missing Bijectors import
penelopeysm Mar 17, 2025
df854dd
Update docs/src/api.md
penelopeysm Mar 18, 2025
8fac6e4
Update docs/src/api.md
penelopeysm Mar 18, 2025
171091d
Clean up broken docs links, remove unneeded deps
penelopeysm Mar 18, 2025
74fd3b9
Format
penelopeysm Mar 18, 2025
763f203
Add changelog entry for exports
penelopeysm Mar 18, 2025
e119b66
Clean up exports in essential/Essential
penelopeysm Mar 18, 2025
f0dd06a
Apply suggestions from code review
penelopeysm Mar 18, 2025
1cf5270
Merge branch 'breaking' into py/imports
penelopeysm Mar 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ Turing.jl v0.37 uses DynamicPPL v0.35, which brings with it several breaking cha

For more details about all of the above, see the changelog of DynamicPPL [here](https://github.com/TuringLang/DynamicPPL.jl/releases/tag/v0.35.0).

### Export list

Turing.jl's export list has been cleaned up a fair bit. This affects what is imported into your namespace when you do an unqualified `using Turing`. You may need to import things more explicitly than before.

- The `DynamicPPL` and `AbstractMCMC` modules are no longer exported. You will need to `import DynamicPPL` or `using DynamicPPL: DynamicPPL` (likewise `AbstractMCMC`) yourself, which in turn means that they have to be made available in your project environment.

- `@logprob_str` and `@prob_str` have been removed following a long deprecation period.
- We no longer re-export everything from `Bijectors` and `Libtask`. To get around this, add `using Bijectors` or `using Libtask` at the top of your script (but we recommend using more selective imports).

+ We no longer export `Bijectors.ordered`. If you were using `ordered`, even Bijectors does not (currently) export this. You will have to manually import it with `using Bijectors: ordered`.

On the other hand, we have added a few more exports:

- `DynamicPPL.returned` and `DynamicPPL.prefix` are exported (for use with submodels).
- `LinearAlgebra.I` is exported for convenience.

# Release 0.36.0

## Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ BangBang = "0.4.2"
Bijectors = "0.14, 0.15"
Compat = "4.15.0"
DataStructures = "0.18"
Distributions = "0.23.3, 0.24, 0.25"
Distributions = "0.25.77"
DistributionsAD = "0.6"
DocStringExtensions = "0.8, 0.9"
DynamicHMC = "3.4"
Expand Down
3 changes: 0 additions & 3 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
[deps]
Bijectors = "76274a88-744f-5084-9051-94815aaf08c4"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterInterLinks = "d12716ef-a0f6-4df4-a9f1-a5a34e75c656"
DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
13 changes: 5 additions & 8 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
using Documenter
using Turing
# Need to import Distributions and Bijectors to generate docs for functions
# from those packages.
using Distributions
using Bijectors
using DynamicPPL

using DocumenterInterLinks

links = InterLinks(
"DynamicPPL" => "https://turinglang.org/DynamicPPL.jl/stable/objects.inv",
"AbstractPPL" => "https://turinglang.org/AbstractPPL.jl/dev/objects.inv",
"AbstractPPL" => "https://turinglang.org/AbstractPPL.jl/stable/objects.inv",
"LinearAlgebra" => "https://docs.julialang.org/en/v1/objects.inv",
"AbstractMCMC" => "https://turinglang.org/AbstractMCMC.jl/stable/objects.inv",
"ADTypes" => "https://sciml.github.io/ADTypes.jl/stable/objects.inv",
"AdvancedVI" => "https://turinglang.org/AdvancedVI.jl/v0.2.8/objects.inv",
"DistributionsAD" => "https://turinglang.org/DistributionsAD.jl/stable/objects.inv",
"OrderedCollections" => "https://juliacollections.github.io/OrderedCollections.jl/stable/objects.inv",
)

# Doctest setup
DocMeta.setdocmeta!(Turing, :DocTestSetup, :(using Turing); recursive=true)

makedocs(;
sitename="Turing",
modules=[Turing, Distributions, Bijectors],
modules=[Turing],
pages=[
"Home" => "index.md",
"API" => "api.md",
"Submodule APIs" =>
["Inference" => "api/Inference.md", "Optimisation" => "api/Optimisation.md"],
],
checkdocs=:exports,
# checkdocs_ignored_modules=[Turing, Distributions, DynamicPPL, AbstractPPL, Bijectors],
doctest=false,
warnonly=true,
plugins=[links],
Expand Down
75 changes: 32 additions & 43 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ Turing.jl directly re-exports the entire public API of the following packages:

- [Distributions.jl](https://juliastats.org/Distributions.jl)
- [MCMCChains.jl](https://turinglang.org/MCMCChains.jl)
- [AbstractMCMC.jl](https://turinglang.org/AbstractMCMC.jl)
- [Bijectors.jl](https://turinglang.org/Bijectors.jl)
- [Libtask.jl](https://github.com/TuringLang/Libtask.jl)

Please see the individual packages for their documentation.

## Individual exports and re-exports

**All** of the following symbols are exported unqualified by Turing, even though the documentation suggests that many of them are qualified.
In this API documentation, for the sake of clarity, we have listed the module that actually defines each of the exported symbols.
Note, however, that **all** of the following symbols are exported unqualified by Turing.
That means, for example, you can just write

```julia
Expand All @@ -37,17 +35,22 @@ even though [`Prior()`](@ref) is actually defined in the `Turing.Inference` modu

### Modelling

| Exported symbol | Documentation | Description |
|:--------------- |:----------------------------------- |:-------------------------------------------- |
| `@model` | [`DynamicPPL.@model`](@extref) | Define a probabilistic model |
| `@varname` | [`AbstractPPL.@varname`](@extref) | Generate a `VarName` from a Julia expression |
| `to_submodel` | [`DynamicPPL.to_submodel`](@extref) | Define a submodel |
| Exported symbol | Documentation | Description |
|:-------------------- |:------------------------------------------ |:-------------------------------------------------------------------------------------------- |
| `@model` | [`DynamicPPL.@model`](@extref) | Define a probabilistic model |
| `@varname` | [`AbstractPPL.@varname`](@extref) | Generate a `VarName` from a Julia expression |
| `to_submodel` | [`DynamicPPL.to_submodel`](@extref) | Define a submodel |
| `prefix` | [`DynamicPPL.prefix`](@extref) | Prefix all variable names in a model with a given symbol |
| `LogDensityFunction` | [`DynamicPPL.LogDensityFunction`](@extref) | A struct containing all information about how to evaluate a model. Mostly for advanced users |

### Inference

| Exported symbol | Documentation | Description |
|:--------------- |:------------------------------------------------------------------------------------------------ |:------------------- |
| `sample` | [`StatsBase.sample`](https://turinglang.org/AbstractMCMC.jl/stable/api/#Sampling-a-single-chain) | Sample from a model |
| Exported symbol | Documentation | Description |
|:----------------- |:------------------------------------------------------------------------------------------------ |:---------------------------------- |
| `sample` | [`StatsBase.sample`](https://turinglang.org/AbstractMCMC.jl/stable/api/#Sampling-a-single-chain) | Sample from a model |
| `MCMCThreads` | [`AbstractMCMC.MCMCThreads`](@extref) | Run MCMC using multiple threads |
| `MCMCDistributed` | [`AbstractMCMC.MCMCDistributed`](@extref) | Run MCMC using multiple processes |
| `MCMCSerial` | [`AbstractMCMC.MCMCSerial`](@extref) | Run MCMC using without parallelism |

### Samplers

Expand All @@ -68,6 +71,7 @@ even though [`Prior()`](@ref) is actually defined in the `Turing.Inference` modu
| `SMC` | [`Turing.Inference.SMC`](@ref) | Sequential Monte Carlo |
| `PG` | [`Turing.Inference.PG`](@ref) | Particle Gibbs |
| `CSMC` | [`Turing.Inference.CSMC`](@ref) | The same as PG |
| `RepeatSampler` | [`Turing.Inference.RepeatSampler`](@ref) | A sampler that runs multiple times on the same variable |
| `externalsampler` | [`Turing.Inference.externalsampler`](@ref) | Wrap an external sampler for use in Turing |

### Variational inference
Expand Down Expand Up @@ -108,52 +112,37 @@ OrderedLogistic
LogPoisson
```

`BernoulliLogit` is part of Distributions.jl since version 0.25.77.
If you are using an older version of Distributions where this isn't defined, Turing will export the same distribution.

```@docs
Distributions.BernoulliLogit
```

### Tools to work with distributions

| Exported symbol | Documentation | Description |
|:--------------- |:-------------------------------------- |:-------------------------------------------------------------- |
| `I` | [`LinearAlgebra.I`](@extref) | Identity matrix |
| `filldist` | [`DistributionsAD.filldist`](@extref) | Create a product distribution from a distribution and integers |
| `arraydist` | [`DistributionsAD.arraydist`](@extref) | Create a product distribution from an array of distributions |
| `NamedDist` | [`DynamicPPL.NamedDist`](@extref) | A distribution that carries the name of the variable |

### Predictions

```@docs
DynamicPPL.predict
```
| Exported symbol | Documentation | Description |
|:--------------- |:--------------------------------------------------------------------------------- |:------------------------------------------------------- |
| `predict` | [`StatsAPI.predict`](https://turinglang.org/DynamicPPL.jl/stable/api/#Predicting) | Generate samples from posterior predictive distribution |

### Querying model probabilities and quantities

Please see the [generated quantities](https://turinglang.org/docs/tutorials/usage-generated-quantities/) and [probability interface](https://turinglang.org/docs/tutorials/usage-probability-interface/) guides for more information.

| Exported symbol | Documentation | Description |
|:-------------------------- |:--------------------------------------------------------------------------------------------------------------------------------- |:--------------------------------------------------------------- |
| `generated_quantities` | [`DynamicPPL.generated_quantities`](@extref) | Calculate additional quantities defined in a model |
| `pointwise_loglikelihoods` | [`DynamicPPL.pointwise_loglikelihoods`](@extref) | Compute log likelihoods for each sample in a chain |
| `logprior` | [`DynamicPPL.logprior`](@extref) | Compute log prior probability |
| `logjoint` | [`DynamicPPL.logjoint`](@extref) | Compute log joint probability |
| `LogDensityFunction` | [`DynamicPPL.LogDensityFunction`](@extref) | Wrap a Turing model to satisfy LogDensityFunctions.jl interface |
| `condition` | [`AbstractPPL.condition`](@extref) | Condition a model on data |
| `decondition` | [`AbstractPPL.decondition`](@extref) | Remove conditioning on data |
| `conditioned` | [`DynamicPPL.conditioned`](@extref) | Return the conditioned values of a model |
| `fix` | [`DynamicPPL.fix`](@extref) | Fix the value of a variable |
| `unfix` | [`DynamicPPL.unfix`](@extref) | Unfix the value of a variable |
| `OrderedDict` | [`OrderedCollections.OrderedDict`](https://juliacollections.github.io/OrderedCollections.jl/dev/ordered_containers/#OrderedDicts) | An ordered dictionary |

### Extra re-exports from Bijectors

Note that Bijectors itself does not export `ordered`.

```@docs
Bijectors.ordered
```
| Exported symbol | Documentation | Description |
|:-------------------------- |:---------------------------------------------------------------------------------------------------------------------------- |:-------------------------------------------------- |
| `returned` | [`DynamicPPL.returned`](https://turinglang.org/DynamicPPL.jl/stable/api/#DynamicPPL.returned-Tuple%7BModel,%20NamedTuple%7D) | Calculate additional quantities defined in a model |
| `pointwise_loglikelihoods` | [`DynamicPPL.pointwise_loglikelihoods`](@extref) | Compute log likelihoods for each sample in a chain |
| `logprior` | [`DynamicPPL.logprior`](@extref) | Compute log prior probability |
| `logjoint` | [`DynamicPPL.logjoint`](@extref) | Compute log joint probability |
| `condition` | [`AbstractPPL.condition`](@extref) | Condition a model on data |
| `decondition` | [`AbstractPPL.decondition`](@extref) | Remove conditioning on data |
| `conditioned` | [`DynamicPPL.conditioned`](@extref) | Return the conditioned values of a model |
| `fix` | [`DynamicPPL.fix`](@extref) | Fix the value of a variable |
| `unfix` | [`DynamicPPL.unfix`](@extref) | Unfix the value of a variable |
| `OrderedDict` | [`OrderedCollections.OrderedDict`](@extref) | An ordered dictionary |

### Point estimates

Expand Down
78 changes: 48 additions & 30 deletions src/Turing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ using Reexport, ForwardDiff
using DistributionsAD, Bijectors, StatsFuns, SpecialFunctions
using Statistics, LinearAlgebra
using Libtask
@reexport using Distributions, MCMCChains, Libtask, AbstractMCMC, Bijectors
@reexport using Distributions, MCMCChains
using Compat: pkgversion

using AdvancedVI: AdvancedVI
using DynamicPPL: DynamicPPL, LogDensityFunction
using DynamicPPL: DynamicPPL
import DynamicPPL: NoDist, NamedDist
using LogDensityProblems: LogDensityProblems
using NamedArrays: NamedArrays
using Accessors: Accessors
using StatsAPI: StatsAPI
using StatsBase: StatsBase
using AbstractMCMC

using Accessors: Accessors

using Printf: Printf
using Random: Random
using LinearAlgebra: I

using ADTypes: ADTypes

Expand Down Expand Up @@ -64,75 +66,91 @@ include("deprecated.jl") # to be removed in the next minor version release
using DynamicPPL:
pointwise_loglikelihoods,
generated_quantities,
returned,
logprior,
logjoint,
condition,
decondition,
fix,
unfix,
conditioned,
to_submodel
to_submodel,
LogDensityFunction
using StatsBase: predict
using Bijectors: ordered
using OrderedCollections: OrderedDict

# Turing essentials - modelling macros and inference algorithms
export @model, # modelling
export
# DEPRECATED
@submodel,
generated_quantities,
# Modelling - AbstractPPL and DynamicPPL
@model,
@varname,
@submodel, # Deprecated
to_submodel,
DynamicPPL,
Prior, # Sampling from the prior
MH, # classic sampling
prefix,
LogDensityFunction,
# Sampling - AbstractMCMC
sample,
MCMCThreads,
MCMCDistributed,
MCMCSerial,
# Samplers - Turing.Inference
Prior,
MH,
Emcee,
ESS,
Gibbs,
HMC, # Hamiltonian-like sampling
HMC,
SGLD,
SGHMC,
PolynomialStepsize,
HMCDA,
NUTS,
PolynomialStepsize,
IS, # particle-based sampling
IS,
SMC,
CSMC,
PG,
CSMC,
RepeatSampler,
vi, # variational inference
ADVI,
sample, # inference
@logprob_str, # TODO: Remove, see https://github.com/TuringLang/DynamicPPL.jl/issues/356
@prob_str, # TODO: Remove, see https://github.com/TuringLang/DynamicPPL.jl/issues/356
externalsampler,
AutoForwardDiff, # ADTypes
# Variational inference - AdvancedVI
vi,
ADVI,
# ADTypes
AutoForwardDiff,
AutoReverseDiff,
AutoMooncake,
setprogress!, # debugging
# Debugging - Turing
setprogress!,
# Distributions
Flat,
FlatPos,
BinomialLogit,
BernoulliLogit, # Part of Distributions >= 0.25.77
OrderedLogistic,
LogPoisson,
filldist,
arraydist,
NamedDist, # Exports from DynamicPPL
# Tools to work with Distributions
I, # LinearAlgebra
filldist, # DistributionsAD
arraydist, # DistributionsAD
NamedDist, # DynamicPPL
# Predictions - DynamicPPL
predict,
# Querying model probabilities - DynamicPPL
returned,
pointwise_loglikelihoods,
generated_quantities,
logprior,
loglikelihood,
logjoint,
LogDensityFunction,
condition,
decondition,
conditioned,
fix,
unfix,
conditioned,
OrderedDict,
ordered, # Exports from Bijectors
OrderedDict, # OrderedCollections
# Point estimates - Turing.Optimisation
# The MAP and MLE exports are only needed for the Optim.jl interface.
maximum_a_posteriori,
maximum_likelihood,
# The MAP and MLE exports are only needed for the Optim.jl interface.
MAP,
MLE

Expand Down
Loading
Loading