Skip to content

[STIM] Support peek_loss - #3550

Open
João Boechat (joao-boechat) wants to merge 15 commits into
mainfrom
joaoboechat/support-peek-loss
Open

[STIM] Support peek_loss#3550
João Boechat (joao-boechat) wants to merge 15 commits into
mainfrom
joaoboechat/support-peek-loss

Conversation

@joao-boechat

@joao-boechat João Boechat (joao-boechat) commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Overview

This change adds end-to-end support for STIM's PEEK_LOSS instruction, allowing adaptive programs to report whether a qubit is lost without collapsing its state. The instruction produces a measurement-record result that can drive classical control while preserving the qubit for subsequent operations.

STIM compiler

  • Parses PEEK_LOSS, broadcasts it across qubit targets, allocates its result records, and lowers it to the __quantum__qis__peek_loss__body QIR intrinsic.
  • Tracks records produced by PEEK_LOSS so they can be used by normal classical controls while rejecting unsupported NOTLEAKED references to those records. The reason why we don't allow NOTLEAKED to reference a measurement record generated by PEEK_LOSS is simply because combining both instructions is ambiguous and doesn't make semantical sense.

Adaptive execution

  • Adds the PEEK_LOSS adaptive bytecode opcode and emits it from the Python adaptive-profile pass.
  • Extends the simulator interface and bytecode runtime with non-destructive loss inspection.
  • Implements the operation in the CPU full-state, stabilizer, and GPU full-state simulators, recording One for a lost qubit and Zero otherwise.

Comment thread source/compiler/stim_compiler/src/qir.rs Outdated

// PEEK_LOSS: Reports whether a qubit was lost, but doesn't
// collapse the state.
case OP_PEEK_LOSS {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being this is in the adaptive kernel, does this mean you can't use PEEK_LOSS in base profile programs? (Makes sense that you can't, we should just ensure that only adaptive programs are able to use it and give a useful error otherwise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user currently can only run this instruction via qdk-stim (unless they type QIR directly, which is unusual), and by default the qdk stim compiler only generates adaptive profile QIR. In the future, we might also generate base profile, and will look into this again.

@joao-boechat
João Boechat (joao-boechat) changed the base branch from main to joaoboechat/support-mpp-readout-noise August 19, 2026 21:52
Base automatically changed from joaoboechat/support-mpp-readout-noise to main August 20, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants