oqpy
oqpy copied to clipboard
Map numpy values to vanilla Python values in `to_ast`
OpenQASM AST holds Python values of various types. In particular, numeric types are annotated as int
, float
, bool
etc, but many users work with numpy or other analogues of these. As a result, oqpy's to_ast
can generate OpenQASM AST that does not satisfy the typing requirements.
For example, a BooleanLiteral
should wrap a Python bool
. oqpy is more permissive here, as it allows a np.bool_
(https://github.com/openqasm/oqpy/blob/main/oqpy/base.py#L513C1-L514C1). But then
>>> isinstance(np.bool_(True), bool)
False
Similarly we should convert numpy floating point or integer values to vanilla Python values.