[Bug] on_loss validation error shows '{}' instead of the gate name

Open Beginner friendly
#4,187 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, rust
Domain
backend

Research direction

Start in qir_simulation.rs around lines 631–632, where the issue says the error string is built, and trace how the gate name reaches the on_loss validation message. Reproduce the Python example with NoiseConfig and LossPolicy.DEGRADE to confirm the literal {}. Done when the error names the gate (for example, cx) and the repro no longer reports the placeholder.

Written by the indexing model from the issue text.

Description

bug low-priority
  • Symptom: Bad error
  • Release 5a7b2ee32: Non-regression
  • Where: n/a · NoiseConfig API

Summary. Setting an unsupported on_loss policy (e.g. cx.on_loss = LossPolicy.DEGRADE) gives an error saying 'for the {} gate' instead of naming the gate.

Python repro

"""F31 (cosmetic): the on_loss validation error contains a literal, unformatted '{}' instead of the gate name."""
import sys
from qdk.simulation import NoiseConfig, LossPolicy

n = NoiseConfig()
try:
    n.cx.on_loss = LossPolicy.DEGRADE
except AttributeError as e:
    print(repr(str(e)), " (expected: 'for the cx gate')")
    if "{}" in str(e):
        print("VERDICT: REPRODUCED - error message contains an unformatted {} placeholder")
        sys.exit(1)
    print("VERDICT: NOT REPRODUCED - gate name is formatted into the message")
    sys.exit(0)
print("VERDICT: INCONCLUSIVE - DEGRADE was accepted for cx")
sys.exit(2)
Build Result Evidence
release 5a7b2ee32 bug present error message contains an unformatted {} placeholder
main 42c843a20 bug present error message contains an unformatted {} placeholder

Observed: 'The on_loss attribute for the {} gate only supports the following policies:\n SKIP\n PROPAGATE\n RESIDUAL_S_DAGGER'

Expected: the gate name ('cx') formatted into the message

Probable cause. qir_simulation.rs ~631-632 passes a '{}' placeholder to String::from instead of formatting in the gate name.

Originally reported as A140

Dominant language
Rust
Stars
1k
Forks
226
Avg merge
2d 9h
Merged PRs (30d)
72

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/qdk

All issues in microsoft/qdk

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.