You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Float dtype scalars (pc.f64, pc.f32) have no arithmetic, so PyPHIR rejects them as angles with a raw TypeError #1342
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
importpecosaspcpc.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, samepc.f64(0.5) +1.0# TypeError, samefloat(pc.f64(0.5)) # 0.5frompecos.reps.pyphir.pyphirimportPyPHIRprog= {"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).
Activity