Skip to content

Map numpy values to vanilla Python values in to_ast #94

@braised-babbage

Description

@braised-babbage

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions