Skip to content

QASM-to-PHIR lowerings disagree on the classical register type: i64 in the Rust path, u32/u64 in the JSON path #868

Description

@ciaranra

crates/pecos-qasm/src/qasm_to_phir.rs (the VarDefineOp emitted per creg, around line 98) types every classical register as i64 regardless of width. crates/pecos-qasm/src/qasm_to_phir_json.rs (classical_register_dtype, around line 44) types the same register as u32 for widths up to 32 and u64 up to 64, and rejects wider ones. The two lowerings of the same program therefore disagree on the signedness of every classical variable.

OpenQASM 2 classical registers are arrays of bits interpreted as unsigned integers with bit 0 as the low-order bit (the spec's if(creg==int) compares against an nninteger), so the JSON path has it right. The Rust path's i64 is pinned by the PHIR fixtures in python/quantum-pecos/tests/pecos/regression/test_engines/test_rxy1q_conditional_gates.py ("data_type": "i64"), so changing it is a cross-language change with fixture updates and a check of how the Python PHIR interpreter treats i64 versus u64 variables. Kept out of #864 (the expression-evaluator fix for the same signedness confusion) for that reason.

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:lowCosmetic, docs, or rare edge case

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions