Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show no quantum state when debugging code with no qubits #1953

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading