Skip to content

Commit

Permalink
fix(optimizer): bad variance on zero noise input on levelled op
Browse files Browse the repository at this point in the history
  • Loading branch information
rudy-6-4 committed Apr 3, 2024
1 parent 9e82a04 commit 15b2291
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -845,3 +845,17 @@ fn test_maximal_multi() {
// note: we have a 5% relative margin since dag complexity is slightly better than v0
assert!(sol.complexity < 1.05 * (sol_ref.complexity / expected_speedup));
}

#[test]
fn test_bug_with_zero_noise() {
let complexity = LevelledComplexity::ZERO;
let out_shape = Shape::number();
let mut dag = unparametrized::OperationDag::new();
let v0 = dag.add_input(2, &out_shape);
let v1 = dag.add_levelled_op([v0], complexity, 0.0, &out_shape, "comment");
let v2 = dag.add_levelled_op([v1], complexity, 1.0, &out_shape, "comment");
let v3 = dag.add_unsafe_cast(v2, 1);
let _ = dag.add_lut(v3, FunctionTable { values: vec![] }, 1);
let sol = optimize(&dag, &None, 0);
assert!(sol.is_some());
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ impl SymbolicVariance {
// replace all current_max by new_coeff
// multiply everything else by new_coeff / current_max
let mut new = self.clone();
if current_max == 0.0 {
return new;
}
for cell in &mut new.coeffs.values {
if *cell == current_max {
*cell = new_coeff;
Expand Down

0 comments on commit 15b2291

Please sign in to comment.