From ed2a8fcab06acea8e2b8fcaf64f109bbd979f403 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Tue, 21 May 2024 23:00:09 -0700 Subject: [PATCH] Avoid panic from `DumpRegister` in circuit display (#1554) 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. --- compiler/qsc_eval/src/intrinsic/utils.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/qsc_eval/src/intrinsic/utils.rs b/compiler/qsc_eval/src/intrinsic/utils.rs index 1314a82083..1dfea3375a 100644 --- a/compiler/qsc_eval/src/intrinsic/utils.rs +++ b/compiler/qsc_eval/src/intrinsic/utils.rs @@ -15,6 +15,12 @@ pub fn split_state( state: &[(BigUint, Complex64)], qubit_count: usize, ) -> Result, ()> { + // 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();