Skip to content

Commit 2856c76

Browse files
authored
Show no quantum state when debugging code with no qubits (#1953)
Instead of showing a single bit zero state, this change makes the debugger quantum state view show a message when no qubits are allocated on the system: ![image](https://github.com/user-attachments/assets/25612e0f-a886-4396-b729-db5b90a7c160) Fixes #1922
1 parent d14d6c2 commit 2856c76

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

vscode/src/debugger/session.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,22 @@ export class QscDebugSession extends LoggingDebugSession {
795795
{},
796796
);
797797
const state = await this.debugService.captureQuantumState();
798+
799+
// When there is no quantum state, return a single variable with a message
800+
// for the user.
801+
if (state.length == 0) {
802+
response.body = {
803+
variables: [
804+
{
805+
name: "None",
806+
value: "No qubits allocated",
807+
variablesReference: 0,
808+
},
809+
],
810+
};
811+
break;
812+
}
813+
798814
const variables: DebugProtocol.Variable[] = state.map((entry) => {
799815
const variable: DebugProtocol.Variable = {
800816
name: entry.name,

wasm/src/debug_service.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ impl DebugService {
3838

3939
pub fn capture_quantum_state(&mut self) -> IQuantumStateList {
4040
let state = self.debugger_mut().capture_quantum_state();
41-
let entries = state
42-
.0
43-
.iter()
44-
.map(|(id, value)| QuantumState {
45-
name: qsc::format_state_id(id, state.1),
46-
value: fmt_complex(value),
47-
})
48-
.collect::<Vec<_>>();
41+
let entries = if state.1 > 0 {
42+
state
43+
.0
44+
.iter()
45+
.map(|(id, value)| QuantumState {
46+
name: qsc::format_state_id(id, state.1),
47+
value: fmt_complex(value),
48+
})
49+
.collect::<Vec<_>>()
50+
} else {
51+
Vec::new()
52+
};
4953

5054
QuantumStateList { entries }.into()
5155
}

0 commit comments

Comments
 (0)