Skip to content

Commit

Permalink
deps: update rand to v0.9 and rand_distr to v0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Armavica committed Jan 29, 2025
1 parent 4926deb commit 1af8025
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 25 deletions.
70 changes: 55 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ keywords = ["gillespie-algorithm", "systems-biology", "stochastic", "scientific-

[dependencies]
pyo3 = { version = "0.23.3", features = ["extension-module"] }
rand = { version = "0.8.5", features = ["small_rng"] }
rand_distr = "0.4.3"
rand = "0.9.0"
rand_distr = "0.5.0"
winnow = "0.6.24"

[features]
Expand Down
6 changes: 3 additions & 3 deletions src/gillespie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl Gillespie {
species: species.as_ref().to_vec(),
t: 0.,
reactions: Vec::new(),
rng: SmallRng::from_entropy(),
rng: SmallRng::from_os_rng(),
sparse,
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ impl Gillespie {
return;
}
self.t += self.rng.sample::<f64, _>(Exp1) / total_rate;
let chosen_rate = total_rate * self.rng.gen::<f64>();
let chosen_rate = total_rate * self.rng.random::<f64>();

// let ireaction = choose_rate_sum(chosen_rate, &rates);
// let ireaction = choose_rate_for(chosen_rate, &rates);
Expand Down Expand Up @@ -297,7 +297,7 @@ impl Gillespie {
self.t = tmax;
return;
}
let chosen_rate = total_rate * self.rng.gen::<f64>();
let chosen_rate = total_rate * self.rng.random::<f64>();

//let ireaction = choose_rate_sum(chosen_rate, &rates);
//let ireaction = choose_rate_for(chosen_rate, &rates);
Expand Down
6 changes: 3 additions & 3 deletions src/gillespie_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ macro_rules! define_system {
$($species: 0,)*
$($param: f64::NAN,)*
t: 0.,
rng: $crate::rand::rngs::SmallRng::from_entropy()
rng: $crate::rand::rngs::SmallRng::from_os_rng()
}
}
/// Seeds the random number generator.
Expand All @@ -90,7 +90,7 @@ macro_rules! define_system {
$($species: 0,)*
$($param,)*
t: 0.,
rng: $crate::rand::rngs::SmallRng::from_entropy()
rng: $crate::rand::rngs::SmallRng::from_os_rng()
}
}
/// Simulates the problem until `t = tmax`.
Expand All @@ -113,7 +113,7 @@ macro_rules! define_system {
self.t = tmax;
return
}
let reaction_choice = total_rate * self.rng.gen::<f64>();
let reaction_choice = total_rate * self.rng.random::<f64>();
$crate::_choice!(self reaction_choice 0.;
$($rname:
$($($nr)? $r)? $(+ $($tnr)? $tr)* =>
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rebop.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def test_fixed_seed() -> None:
ds = sir.run({"S": 999, "I": 1}, tmax=250, nb_steps=250, rng=42)

assert ds.S[-1] == 0
assert ds.I[-1] == 182
assert ds.R[-1] == 818
assert ds.I[-1] == 227
assert ds.R[-1] == 773


@pytest.mark.parametrize("seed", range(10))
Expand Down

0 comments on commit 1af8025

Please sign in to comment.