Skip to content

Conversation

@penelopeysm
Copy link
Member

Closes #2673

@github-actions
Copy link
Contributor

Turing.jl documentation for PR #2674 is available at:
https://TuringLang.github.io/Turing.jl/previews/PR2674/

@codecov
Copy link

codecov bot commented Sep 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.79%. Comparing base (296f654) to head (97ce752).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2674      +/-   ##
==========================================
- Coverage   85.86%   85.79%   -0.07%     
==========================================
  Files          22       22              
  Lines        1429     1422       -7     
==========================================
- Hits         1227     1220       -7     
  Misses        202      202              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coveralls
Copy link

coveralls commented Sep 11, 2025

Pull Request Test Coverage Report for Build 17642662193

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.08%) to 83.639%

Totals Coverage Status
Change from base Build 17557004860: -0.08%
Covered Lines: 1186
Relevant Lines: 1418

💛 - Coveralls

@penelopeysm penelopeysm requested a review from sunxd3 September 11, 2025 12:32
Copy link
Member

@sunxd3 sunxd3 left a comment

Choose a reason for hiding this comment

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

In general, no objection. The failed tests also look unrelated, so good.

On versioning, do you think this constitute a breaking change? Not saying I do, but worth second thought.

@penelopeysm
Copy link
Member Author

I think generally for random results we shouldn't guarantee the exact numerical results as being part of the API, but we should guarantee some statistical properties. Since this doesn't change convergence properties for MCMC I think it's fine to put as a bugfix. I guess this isn't an official policy though so maybe worth checking if we all agree?

@sunxd3
Copy link
Member

sunxd3 commented Sep 11, 2025

My concern is the behavior of initialization. Before this PR, the initialization wasn't returned in the chain.

@penelopeysm
Copy link
Member Author

There is actually a subtle change that I just realised with this: when the initial state is included, then there are no sampler stats for the first entry in the chain (because the sampler hasn't run). That means they all get a value of missing.

Because MCMCChains requires a consistent eltype for all parameters + stats, this means that all the parameters are stored as Union{Float64,Missing}::

julia> using Turing; @model f() = x ~ Normal(); c = sample(f(), HMC(0.1, 5), 100)
Sampling 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:00:00
Chains MCMC chain (100×13×1 reshape(::Matrix{Union{Missing, Float64}}, 100, 13, 1) with eltype Union{Missing, Float64}):

Iterations        = 1:1:100
Number of chains  = 1
Samples per chain = 100
Wall duration     = 0.26 seconds
Compute duration  = 0.26 seconds
parameters        = x
internals         = hamiltonian_energy, n_steps, numerical_error, loglikelihood, hamiltonian_energy_error, is_accept, logprior, log_density, step_size, acceptance_rate, lp, nom_step_size

Use `describe(chains)` for summary statistics and quantiles.

julia> eltype(c[:x])
Union{Missing, Float64}

On main, eltype(c[:x]) would just return Float64.

This to me is not actually a Turing problem. It's an MCMCChains problem. But I wonder if that would factor into the decision.

@penelopeysm
Copy link
Member Author

i'll change the base to breaking and merge

@penelopeysm penelopeysm changed the base branch from main to breaking September 18, 2025 18:23
@penelopeysm penelopeysm merged commit ff8d01e into breaking Sep 19, 2025
@penelopeysm penelopeysm deleted the py/no-initial-step branch September 19, 2025 09:15
penelopeysm added a commit that referenced this pull request Oct 22, 2025
* Bump minor version

* Do not take an initial step before starting the chain in HMC (#2674)

* Do not take an initial step before starting the chain in HMC

* Fix some tests

* update changelog

* Compatibility with DynamicPPL 0.38 + InitContext (#2676)

* Import `varname_leaves` etc from AbstractPPL instead

* initial updates for InitContext

* More fixes

* Fix pMCMC

* Fix Gibbs

* More fixes, reexport InitFrom

* Fix a bunch of tests; I'll let CI tell me what's still broken...

* Remove comment

* Fix more tests

* More test fixes

* Fix more tests

* fix GeneralizedExtremeValue numerical test

* fix sample method

* fix ESS reproducibility

* Fix externalsampler test correctly

* Fix everything (I _think_)

* Add changelog

* Fix remaining tests (for real this time)

* Specify default chain type in Turing

* fix DPPL revision

* Fix changelog to mention unwrapped NT / Dict for initial_params

* Remove references to islinked, set_flag, unset_flag

* use `setleafcontext(::Model, ::AbstractContext)`

* Fix for upstream removal of default_chain_type

* Add clarifying comment for IS test

* Revert ESS test (and add some numerical accuracy checks)

* istrans -> is_transformed

* Remove `loadstate` and `resume_from`

* Remove a Sampler test

* Paper over one crack

* fix `resume_from`

* remove a `Sampler` test

* Update HISTORY.md

Co-authored-by: Markus Hauru <[email protected]>

* Remove `Sampler`, remove `InferenceAlgorithm`, transfer `initialstep`, `init_strategy`, and other functions from DynamicPPL to Turing (#2689)

* Remove `Sampler` and move its interface to Turing

* Test fixes (this is admittedly quite tiring)

* Fix a couple of Gibbs tests (no doubt there are more)

* actually fix the Gibbs ones

* actually fix it this time

* fix typo

* point to breaking

* Improve loadstate implementation

* Re-add tests that were removed from DynamicPPL

* Fix qualifier in src/mcmc/external_sampler.jl

Co-authored-by: Xianda Sun <[email protected]>

* Remove the default argument for initial_params

* Remove DynamicPPL sources

---------

Co-authored-by: Xianda Sun <[email protected]>

* Fix a word in changelog

* Improve changelog

* Add PNTDist to changelog

---------

Co-authored-by: Markus Hauru <[email protected]>
Co-authored-by: Xianda Sun <[email protected]>

* Fix all docs warnings

---------

Co-authored-by: Markus Hauru <[email protected]>
Co-authored-by: Markus Hauru <[email protected]>
Co-authored-by: Xianda Sun <[email protected]>
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.

Fixing initial_params when using NUTS does not fix the initial parameters

4 participants