Skip to content

Add loss policies to NoiseConfig to express different kinds of behavior on lost qubits#3302

Open
orpuente-MS wants to merge 1 commit into
mainfrom
oscarpuente/qubit-loss-policies
Open

Add loss policies to NoiseConfig to express different kinds of behavior on lost qubits#3302
orpuente-MS wants to merge 1 commit into
mainfrom
oscarpuente/qubit-loss-policies

Conversation

@orpuente-MS

Copy link
Copy Markdown
Contributor

With this change, users are able to specify how gates should behave if at least one of their qubit operands is lost. Below is a comprehensive example, showing all 5 loss policies.

from qdk.simulation import NoiseConfig, LossPolicy
qir = ...

noise = NoiseConfig() 
noise.cz.on_loss  = LossPolicy.SKIP               # if one of the qubits is lost, skip the unitary
noise.cx.on_loss  = LossPolicy.PROPAGATE          # if one of the qubits is lost, loose the other one
noise.rxx.on_loss = LossPolicy.DEGRADE            # degrade to a single qubit gate: rx
noise.ryy.on_loss = LossPolicy.RESIDUAL_S_DAGGER  # apply an S_DAG to the remaining qubits
noise.rzz.on_loss = LossPolicy.APPLY_ANYWAY       # apply unitary anyways

# Works with all simulator types, in any profile.
run_qir(qir, shots=100, noise=noise, type="clifford")

@orpuente-MS orpuente-MS marked this pull request as ready for review June 12, 2026 20:01
#
# These exercise the per-gate `NoiseConfig.<gate>.on_loss` behavior. The
# `on_loss` policy is honored by the cpu (full-state) and clifford (stabilizer)
# simulators, so these tests are parametrized over just those two.

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.

Is this correct? Looks like GPU is included below.

@pytest.mark.parametrize("sim_type", LOSS_POLICY_SIM_TYPES)
def test_on_loss_swap_skip_keeps_state_but_swaps_loss_flag(sim_type):
# Overriding `swap.on_loss` to SKIP skips the SWAP unitary, but the loss
# flag is still exchanged. qs[0] keeps its reset |0> and qs[1] becomes lost.

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.

This one is interesting. Worth discussing more. Seems odd you would skip the unitary (which swaps the state) but still swap which is lost. Not sure if that would be physically possible.

// Loss policy values. These are stamped onto a gate op's `q3` field by the host
// (see `LossPolicy::as_u32` on the Rust side) and tell the shader how to handle
// the gate when one of its operands is lost. `0` means "no policy stamped",
// which the shader treats the same as SKIP.

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.

When I was looking at the enum I was wondering why the default value (0) wasn't skip. Is there a reason to start at 1 and leave 0 undefined/no-policy?

if (shot.qubit_state[q1].heat == -1.0) {
return true;
}
let is_2q = (op.id == OPID_CX || op.id == OPID_CY || op.id == OPID_CZ ||

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.

You already have is_1q_op defined (line 74). Can you just negate that? For now we only have 1q and 2q ops.

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