Skip to content

Commit

Permalink
Show no quantum state when debugging code with no qubits
Browse files Browse the repository at this point in the history
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:

Fixes #1922
  • Loading branch information
swernli committed Oct 8, 2024
1 parent 0261bf6 commit 70fbb57
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
16 changes: 16 additions & 0 deletions vscode/src/debugger/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,22 @@ export class QscDebugSession extends LoggingDebugSession {
{},
);
const state = await this.debugService.captureQuantumState();

// When there is no quantum state, return a single variable with a message
// for the user.
if (state.length == 0) {
response.body = {
variables: [
{
name: "None",
value: "No qubits allocated",
variablesReference: 0,
},
],
};
break;
}

const variables: DebugProtocol.Variable[] = state.map((entry) => {
const variable: DebugProtocol.Variable = {
name: entry.name,
Expand Down
20 changes: 12 additions & 8 deletions wasm/src/debug_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ impl DebugService {

pub fn capture_quantum_state(&mut self) -> IQuantumStateList {
let state = self.debugger_mut().capture_quantum_state();
let entries = state
.0
.iter()
.map(|(id, value)| QuantumState {
name: qsc::format_state_id(id, state.1),
value: fmt_complex(value),
})
.collect::<Vec<_>>();
let entries = if state.1 > 0 {
state
.0
.iter()
.map(|(id, value)| QuantumState {
name: qsc::format_state_id(id, state.1),
value: fmt_complex(value),
})
.collect::<Vec<_>>()
} else {
Vec::new()
};

QuantumStateList { entries }.into()
}
Expand Down

0 comments on commit 70fbb57

Please sign in to comment.