Skip to content

Float dtype scalars (pc.f64, pc.f32) have no arithmetic, so PyPHIR rejects them as angles with a raw TypeError #1342

Open

Description

@ciaranra

The float dtype scalars pc.f64 and pc.f32 support no arithmetic. As a result, PyPHIR fails with a raw TypeError when a gate angle is a float dtype scalar.

Reproduction

import pecos as pc
pc.f64(0.5) * 2.0          # TypeError: unsupported operand type(s) for *: 'pecos_rslib.dtypes.f64' and 'float'
pc.f64(0.5) * pc.f64(2.0)  # TypeError, same
pc.f64(0.5) + 1.0          # TypeError, same
float(pc.f64(0.5))         # 0.5

from pecos.reps.pyphir.pyphir import PyPHIR
prog = {"format": "PHIR/JSON", "version": "0.1.0", "ops": [
    {"data": "qvar_define", "data_type": "qubits", "variable": "q", "size": 1},
    {"qop": "RZ", "angles": [[pc.f64(0.5)], "rad"], "args": [["q", 0]]},
]}
PyPHIR.from_phir(prog)
# TypeError: unsupported operand type(s) for *: 'pecos_rslib.dtypes.f64' and 'int'
# (with unit "pi": ... and 'float')

The same program with a plain 0.5 works. Also, QuantumCircuit.append({"RZ": {0}}, angles=(pc.f64(0.5),)) fails with TypeError: Object of type f64 is not JSON serializable.

Cause

  • python/pecos-rslib/src/dtypes.rs gives the integer scalar types arithmetic dunders (__add__, __mul__, __rmul__, ...). The float scalars (f64 ~673, f32 ~801 on dev) define __float__ but no arithmetic.
  • PyPHIR.from_phir (python/quantum-pecos/src/pecos/reps/pyphir/pyphir.py ~150 on dev) computes angle * (pc.f64.pi if unit == "pi" else 1).

Direction

Give the float dtype scalars the same arithmetic as the integer scalars, with Python numbers and with each other, both directions. Check that PyPHIR, QuantumCircuit and the other angle ingress points accept them, or convert at the boundary with an actionable error. Related: #1313 (lossy float angle exits), #691 (angle ingress defects).

Found during the review of the #1314 work.

Activity

  1. added
    bugSomething isn't working
    pythonPull requests that update python code
    severity:mediumDegraded or awkward behavior with a workaround
    on Oct 18, 2026
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 workingpythonPull requests that update python codeseverity:mediumDegraded or awkward behavior with a workaround

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions