Skip to content

Commit 07630ee

Browse files
authored
Merge pull request #18 from jlapeyre/gjl-set-verbose-in-config
Support setting verbose from config_from_theta_epsilon
2 parents 161f0d6 + 91cd8de commit 07630ee

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

examples/interface.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ fn main() {
1717
let theta = pi / 8.0;
1818
let epsilon = 1e-10;
1919
let seed = 1234;
20-
let mut gridsynth_config = config_from_theta_epsilon(theta, epsilon, seed);
20+
let verbose = false;
21+
let mut gridsynth_config = config_from_theta_epsilon(theta, epsilon, seed, verbose);
2122
let gates = gridsynth_gates(&mut gridsynth_config);
2223
println!("{}", gates);
2324
}

src/config.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ pub fn parse_decimal_with_exponent(input: &str) -> Option<(IBig, IBig)> {
6969
}
7070

7171
/// Creates the default config to easily call the code from other rust packages.
72-
pub fn config_from_theta_epsilon(theta: f64, epsilon: f64, seed: u64) -> GridSynthConfig {
72+
/// `seed` is used to set single RNG that is used through the call to `gridsynth`.
73+
pub fn config_from_theta_epsilon(
74+
theta: f64,
75+
epsilon: f64,
76+
seed: u64,
77+
verbose: bool,
78+
) -> GridSynthConfig {
7379
let (theta_num, theta_den) = parse_decimal_with_exponent(&theta.to_string()).unwrap();
7480
let theta = ib_to_bf_prec(theta_num) / ib_to_bf_prec(theta_den);
7581
let (epsilon_num, epsilon_den) = parse_decimal_with_exponent(&epsilon.to_string()).unwrap();
@@ -81,7 +87,6 @@ pub fn config_from_theta_epsilon(theta: f64, epsilon: f64, seed: u64) -> GridSyn
8187
let epsilon = ib_to_bf_prec(epsilon_num) / ib_to_bf_prec(epsilon_den);
8288
let diophantine_timeout = 200u128;
8389
let factoring_timeout = 50u128;
84-
let verbose = false;
8590
let time = false;
8691

8792
let rng: StdRng = SeedableRng::seed_from_u64(seed);

tests/integration_test.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ fn simple_test() {
88
let theta = pi / 8.0; // ≈ 0.39269908169872414
99
let epsilon = 1e-10;
1010
let seed = 1234;
11-
let mut gridsynth_config = config_from_theta_epsilon(theta, epsilon, seed);
11+
let verbose = false;
12+
let mut gridsynth_config = config_from_theta_epsilon(theta, epsilon, seed, verbose);
1213
let gates = gridsynth_gates(&mut gridsynth_config);
1314
let expected_gates = "HTHTSHTSHTHTSHTHTSHTHTHTSHTSHTHTHTHTHTHTSHTSHTHTSHTSHTSHTSHTHTSHTSHTSHTHTHTHTHTHTSHTSHTHTSHTSHTSHTHTHTSHTSHTSHTSHTSHTSHTSHTHTHTHTHTSHTSHTSHTSHTSHTSHTHTHTHTHTSHTHTSHTHTHTSHTSHTSHTHTSHTSHTHTSHTHTSHTSHTHTSHTHTHTSHTSHTSHTSHTHTHTHTSHTHTHTSHTHTSHTHTHTSHTHTSHTHTSHTXSSWWW";
1415
assert_eq!(gates, expected_gates);
@@ -25,8 +26,9 @@ fn simple_test2() {
2526

2627
let test_inputs = vec![(1234, gates1), (101, gates1), (1, gates1)];
2728

29+
let verbose = false;
2830
for (seed, expected_gates) in test_inputs {
29-
let mut gridsynth_config = config_from_theta_epsilon(theta, epsilon, seed);
31+
let mut gridsynth_config = config_from_theta_epsilon(theta, epsilon, seed, verbose);
3032
let gates = gridsynth_gates(&mut gridsynth_config);
3133
assert_eq!(gates, expected_gates, "Test failed for seed: {}", seed);
3234
}
@@ -40,10 +42,11 @@ fn pi_over_two_test() {
4042

4143
let epsilons = vec![1e-2, 1e-3, 1e-10];
4244

45+
let verbose = false;
4346
for epsilon in epsilons {
4447
let seeds = 100..300;
4548
for seed in seeds {
46-
let mut gridsynth_config = config_from_theta_epsilon(theta, epsilon, seed);
49+
let mut gridsynth_config = config_from_theta_epsilon(theta, epsilon, seed, verbose);
4750
let gates = gridsynth_gates(&mut gridsynth_config);
4851
let expected_gates = "SWWWWWWW";
4952
assert_eq!(gates, expected_gates);

0 commit comments

Comments
 (0)