Skip to content

Commit

Permalink
Avoid panic from DumpRegister in circuit display (#1554)
Browse files Browse the repository at this point in the history
This avoids a panic on empty state that can happen when `DumpRegister`
is called on an empty state vector, such as when generating a circuit
without any underlying quantum simulation.
  • Loading branch information
swernli authored May 22, 2024
1 parent 57b2c47 commit ed2a8fc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/qsc_eval/src/intrinsic/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ pub fn split_state(
state: &[(BigUint, Complex64)],
qubit_count: usize,
) -> Result<Vec<(BigUint, Complex64)>, ()> {
// For an empty state, return an empty state.
// This handles cases where the underlying simulator doesn't track any quantum state.
if state.is_empty() {
return Ok(vec![]);
}

let mut dump_state = FxHashMap::default();
let mut other_state = FxHashMap::default();

Expand Down

0 comments on commit ed2a8fc

Please sign in to comment.