Skip to content

pecos-phir-json quantum assertions are vacuous and the engine's results are wrong: X before Measure reads 0 #883

Description

@ciaranra

Summary

The pecos-phir-json end-to-end tests cannot fail on a wrong quantum result, and the engine's results are in fact wrong today. This is why #819 (register names discarded, every gate mis-addressed in multi-register programs) went unnoticed.

Evidence

Ten assertions across crates/pecos-phir-json/tests/ are guarded like this (quantum_operations.rs, test 1):

if shot.data.contains_key("output") {
    let value = shot.data.get("output").unwrap().as_u32();
    assert!(value == Some(0) || value == Some(1), ...);
} else {
    println!("WARNING: 'output' register not found in simulation results.");
    println!("This is expected until the simulation pipeline is fully fixed.");
}

A missing register prints a warning and passes; a present register passes for either outcome. Both branches are vacuous.

Running a minimal program through PhirJsonEngine::from_program(...).process(()) on dev at 7029965b1:

{"data":"qvar_define","data_type":"qubits","variable":"q","size":2},
{"data":"cvar_define","data_type":"i32","variable":"m","size":2},
{"qop":"X","args":[["q",0]],"returns":[]},
{"qop":"Measure","args":[["q",0],["q",1]],"returns":[["m",0],["m",1]]},
{"cop":"Result","args":["m"],"returns":["out"]}

yields out = "000". An X before a Measure on the same qubit must read 1. So either the standalone engine does not apply gates before measuring, or measurement outcomes do not reach the result registers.

Why it matters

grep -c "expected until the simulation pipeline" over that test directory returns 10. With every quantum assertion vacuous, no defect in gate application, qubit addressing or measurement routing in this engine can be caught by its own suite.

Suggested resolution

  1. Determine whether the standalone PhirJsonEngine is supposed to produce quantum results at all, or whether it requires an explicit simulator/engine-system wiring the tests do not perform. Document the answer at the entry point.
  2. Replace every vacuous assertion with a deterministic expectation (X then Measure reads 1; a Bell pair's two bits agree across shots), or mark the tests #[ignore] with the blocking issue named -- not a warning branch that passes.
  3. Until then, regression tests for this engine must observe at the IR or command layer, not end to end.

Provenance

Found while reproducing #819: the end-to-end probe was blind, and establishing a baseline (a plain X in a single register) showed the baseline itself reads 0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrustPull requests that update rust codeseverity:highBroken functionality or loud failure in a supported path

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions