warp icon indicating copy to clipboard operation
warp copied to clipboard

[BUG] from __future__ import annotations breaks warp

Open koen-v opened this issue 1 year ago • 1 comments

Bug Description

When I add from __future__ import annotations

to a warp script, the kernel wont compile, the first thing I hit is in: python\warp\types.py

;'str' object has no attribute '__module__'

removing the annotations import makes it go away

Thanks, Koen

System Information

Windows 11, Python 3.10

koen-v avatar Jul 05 '24 19:07 koen-v

A quick look at the issue shows that the type annotations get turned into strings with from __future__ import annotations (postponed evaluation of annotations), which interferes with the Warp Var.type variables created for the kernel parameters. Here's a minimal example :

from __future__ import annotations

import warp as wp

wp.init()


@wp.kernel
def test_kernel(a: wp.array(dtype=wp.float32)):
    i = wp.tid()


test_array = wp.empty(shape=(10,), dtype=wp.float32)

wp.launch(test_kernel, test_array.shape, inputs=[test_array])

wp.synchronize()

@christophercrouzet: Can you look into if we can support this use case?

shi-eric avatar Jul 05 '24 21:07 shi-eric

Hi @koen-v, thanks for reporting this issue!

We've just merged some changes in e10a583 to add support for from __future__ import annotations. It's available in the branch main for now and will be part of the next release.

christophercrouzet avatar Jul 14 '24 19:07 christophercrouzet

great, thank you!

koen-v avatar Jul 15 '24 00:07 koen-v