Skip to content

Commit 1886dd6

Browse files
committed
update to rand v0.9
1 parent 8eed906 commit 1886dd6

File tree

4 files changed

+128
-25
lines changed

4 files changed

+128
-25
lines changed

Cargo.lock

Lines changed: 116 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ crate-type = ["cdylib"]
1212
bit-set = "0.8"
1313
ordered-float = "5.0"
1414
pyo3 = "0.23"
15-
rand = "0.8"
15+
rand = "0.9"
1616
rustc-hash = "2.1"
1717

1818
[profile.release]

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,28 @@ The following benchmarks illustrate performance and may be a useful comparison p
7070

7171
---
7272

73-
First, the runtime of the optimal algorithm on random 3-regular graphs,
73+
First, the runtime of the optimal algorithm on random 3-regular graphs,
7474
with all bond sizes set to 2, for different `mimimize` targets:
7575

7676
<img src="https://github.com/user-attachments/assets/e1b906a8-e234-4558-b183-7141c41beb24" width="400">
7777

7878
Taken over 20 instances, lines show mean and bands show standard error on mean. Note how much easier it is
7979
to find optimal paths for the *maximum* intermediate size or cost only (vs. *total* for all contractions).
80-
While the runtime generally scales exponentially, for some specific geometries it might reduce to
80+
While the runtime generally scales exponentially, for some specific geometries it might reduce to
8181
polynomial.
8282

8383
---
8484

8585
For very large graphs, the `random_greedy` optimizer is appropriate, and there is a tradeoff between how
86-
long one lets it run (`ntrials`) and the best cost it achieves. Here we plot these for various
87-
$N=L\times L$ square grid graphs, with all bond sizes set to 2, for different `ntrials`
86+
long one lets it run (`ntrials`) and the best cost it achieves. Here we plot these for various
87+
$N=L\times L$ square grid graphs, with all bond sizes set to 2, for different `ntrials`
8888
(labelled on each marker):
8989

9090
<img src="https://github.com/user-attachments/assets/e319b5cf-25ea-4273-aa0f-4f3acb3beaa6" width="400">
9191

9292
Again, data is taken over 20 runs, with lines and bands showing mean and standard error on the mean.
9393
In most cases 32-64 trials is sufficient to achieve close to convergence, but for larger or harder
94-
graphs you may need more. The empirical scaling of the random-greedy algorithm is very roughly
94+
graphs you may need more. The empirical scaling of the random-greedy algorithm is very roughly
9595
$\mathcal{O}(N^{1.5})$ here.
9696

9797
---

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl ContractionProcessor {
425425
let mut rng = if coeff_t != 0.0 {
426426
Some(match seed {
427427
Some(seed) => rand::rngs::StdRng::seed_from_u64(seed),
428-
None => rand::rngs::StdRng::from_entropy(),
428+
None => rand::rngs::StdRng::from_os_rng(),
429429
})
430430
} else {
431431
// zero temp - no need for rng
@@ -434,7 +434,7 @@ impl ContractionProcessor {
434434

435435
let mut local_score = |sa: Score, sb: Score, sab: Score| -> Score {
436436
let gumbel = if let Some(rng) = &mut rng {
437-
coeff_t * -f32::ln(-f32::ln(rng.gen()))
437+
coeff_t * -f32::ln(-f32::ln(rng.random()))
438438
} else {
439439
0.0 as f32
440440
};
@@ -1130,9 +1130,9 @@ fn optimize_random_greedy_track_flops(
11301130

11311131
let mut rng = match seed {
11321132
Some(seed) => rand::rngs::StdRng::seed_from_u64(seed),
1133-
None => rand::rngs::StdRng::from_entropy(),
1133+
None => rand::rngs::StdRng::from_os_rng(),
11341134
};
1135-
let seeds = (0..ntrials).map(|_| rng.gen()).collect::<Vec<u64>>();
1135+
let seeds = (0..ntrials).map(|_| rng.random()).collect::<Vec<u64>>();
11361136

11371137
let n: usize = inputs.len();
11381138
// construct processor and perform simplifications once
@@ -1151,14 +1151,14 @@ fn optimize_random_greedy_track_flops(
11511151
let costmod = if is_const_costmod {
11521152
costmod_min
11531153
} else {
1154-
costmod_min + rng.gen::<f32>() * costmod_diff
1154+
costmod_min + rng.random::<f32>() * costmod_diff
11551155
};
11561156

11571157
// log-uniform sample for temperature
11581158
let temperature = if is_const_temp {
11591159
temp_min
11601160
} else {
1161-
f32::exp(log_temp_min + rng.gen::<f32>() * log_temp_diff)
1161+
f32::exp(log_temp_min + rng.random::<f32>() * log_temp_diff)
11621162
};
11631163

11641164
// greedily contract each connected subgraph

0 commit comments

Comments
 (0)