@@ -563,7 +563,7 @@ impl<T: TraceStorage> ChainProcess<T> {
563563 let ( stop_marker_tx, stop_marker_rx) = channel ( ) ;
564564
565565 let mut rng = ChaCha8Rng :: seed_from_u64 ( seed) ;
566- rng. set_stream ( chain_id) ;
566+ rng. set_stream ( chain_id + 1 ) ;
567567
568568 let chain_trace = Arc :: new ( Mutex :: new ( Some ( chain_trace) ) ) ;
569569 let progress = Arc :: new ( Mutex :: new ( ChainProgress :: new (
@@ -578,7 +578,9 @@ impl<T: TraceStorage> ChainProcess<T> {
578578 let progress = progress_inner;
579579
580580 let mut sample = move || {
581- let logp = model. math ( ) . context ( "Failed to create model density" ) ?;
581+ let logp = model
582+ . math ( & mut rng)
583+ . context ( "Failed to create model density" ) ?;
582584 let dim = logp. dim ( ) ;
583585
584586 let mut sampler = settings. new_chain ( chain_id, logp, & mut rng) ;
@@ -660,7 +662,7 @@ impl<T: TraceStorage> ChainProcess<T> {
660662
661663 let result = sample ( ) ;
662664
663- // We intentially ignore errors here, because this means some other
665+ // We intentionally ignore errors here, because this means some other
664666 // chain already failed, and should have reported the error.
665667 let _ = results. send ( result) ;
666668 drop ( results) ;
@@ -748,7 +750,12 @@ impl<F: Send + 'static> Sampler<F> {
748750 let results = results_tx;
749751 let mut chains = Vec :: with_capacity ( settings. num_chains ( ) ) ;
750752
751- let math = model_ref. math ( ) . context ( "Could not create model density" ) ?;
753+ let mut rng = ChaCha8Rng :: seed_from_u64 ( settings. seed ( ) ) ;
754+ rng. set_stream ( 0 ) ;
755+
756+ let math = model_ref
757+ . math ( & mut rng)
758+ . context ( "Could not create model density" ) ?;
752759 let trace = trace_config
753760 . new_trace ( settings_ref, & math)
754761 . context ( "Could not create trace object" ) ?;
@@ -961,6 +968,7 @@ pub mod test_logps {
961968 } ;
962969 use anyhow:: Result ;
963970 use nuts_storable:: HasDims ;
971+ use rand:: Rng ;
964972 use thiserror:: Error ;
965973
966974 #[ derive( Clone , Debug ) ]
@@ -1102,7 +1110,7 @@ pub mod test_logps {
11021110 {
11031111 type Math < ' model > = CpuMath < & ' model F > ;
11041112
1105- fn math ( & self ) -> Result < Self :: Math < ' _ > > {
1113+ fn math < R : Rng + ? Sized > ( & self , _rng : & mut R ) -> Result < Self :: Math < ' _ > > {
11061114 Ok ( CpuMath :: new ( & self . logp ) )
11071115 }
11081116
0 commit comments