quantumlib / Qualtran

Qᴜᴀʟᴛʀᴀɴ is a Python library for expressing and analyzing Fault Tolerant Quantum algorithms.
https://qualtran.readthedocs.io/en/latest/
Apache License 2.0
132 stars 35 forks source link

Generalize `symbolics.prod` to allow `SymbolicFloat` or `SymbolicInt` #1101

Closed charlesyuan314 closed 3 days ago

charlesyuan314 commented 3 days ago

Prior to this change, symbolics.prod only accepted SymbolicInt arguments and returned SymbolicInt. Now, it also accepts SymbolicFloat to return SymbolicFloat.

The function also now accepts an iterator rather than being variadic, matching the interface of built-in sum.

This goal is achieved via a new type variable SymbolicT. There does not seem to be a correct approach using @overload instead due to limitations of mypy, which does not consider float | Expr and int | Expr to be two valid overloads for a function since int is automatically promoted to float.