Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next: np.bool_ argument handling broken in gtfn backend #1861

Open
nfarabullini opened this issue Feb 13, 2025 · 2 comments · May be fixed by #1870
Open

next: np.bool_ argument handling broken in gtfn backend #1861

nfarabullini opened this issue Feb 13, 2025 · 2 comments · May be fixed by #1870
Labels
gt4py.next Issues concerning the new version with support for non-cartesian grids.

Comments

@nfarabullini
Copy link
Contributor

nfarabullini commented Feb 13, 2025

The following test outputs an unexpected error:

@pytest.mark.datatest
def test_bool_fo(icon_grid, backend):
    import gt4py.next as gtx
    from icon4py.model.common.utils import data_allocation
    from icon4py.model.common import field_type_aliases as fa
    from gt4py.next.ffront.fbuiltins import broadcast
    import numpy as np
    @gtx.field_operator
    def bool_fo(val: bool) -> fa.EdgeField[bool]:
        return broadcast(val, (EdgeDim,))
    val = np.bool_(True)
    f = data_allocation.zero_field(icon_grid, dims.EdgeDim, dtype=bool)
    bool_fo.with_backend(backend)(val, out=f, offset_provider={})

Error:

>       bool_fo.with_backend(backend)(val, out=f, offset_provider={})

dycore_tests/test_velocity_advection.py:474: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../../.venv/lib/python3.10/site-packages/gt4py/next/ffront/decorator.py:604: in __call__
    return self.backend(
../../../../.venv/lib/python3.10/site-packages/gt4py/next/backend.py:157: in __call__
    self.jit(program, *args, **kwargs)(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

offset_provider = {}
out = NumPyArrayField(_domain=Domain(dims=(Dimension(value='Edge', kind=<DimensionKind.HORIZONTAL: 'horizontal'>),), ranges=(UnitRange(0, 31558),)), _ndarray=array([False, False, False, ..., False, False, False]))
args = (False, NumPyArrayField(_domain=Domain(dims=(Dimension(value='Edge', kind=<DimensionKind.HORIZONTAL: 'horizontal'>),), ranges=(UnitRange(0, 31558),)), _ndarray=array([False, False, False, ..., False, False, False])))
converted_args = [False, (array([False, False, False, ..., False, False, False]), (0,))]

    def decorated_program(
        *args: Any,
        offset_provider: dict[str, common.Connectivity | common.Dimension],
        out: Any = None,
    ) -> None:
        if out is not None:
            args = (*args, out)
        converted_args = [convert_arg(arg) for arg in args]
        conn_args = extract_connectivity_args(offset_provider, device)
        # generate implicit domain size arguments only if necessary, using `iter_size_args()`
>       return inp(
            *converted_args,
            *(arguments.iter_size_args(args) if inp.implicit_domain else ()),
            *conn_args,
        )
E       TypeError: __field_operator_bool_fo(): incompatible function arguments. The following argument types are supported:
E           1. __field_operator_bool_fo(arg0: bool, arg1: tuple[ndarray[dtype=bool, shape=(*)], tuple[int]], arg2: int, /) -> None
E       
E       Invoked with types: bool_, tuple, int

../../../../.venv/lib/python3.10/site-packages/gt4py/next/program_processors/runners/gtfn.py:59: TypeError
@tehrengruber tehrengruber changed the title np.bool_ not processed within the gtfn backend next: np.bool_ argument handling broken in gtfn backend Feb 13, 2025
@havogt
Copy link
Contributor

havogt commented Feb 17, 2025

nanobind lacks support for casting np.bool to C++ bool. See wjakob/nanobind#936.

@havogt
Copy link
Contributor

havogt commented Feb 17, 2025

Since most likely nanobind doesn't want the ugly np.bool cast, we should just wrap bool args with a bool() cast.

@havogt havogt linked a pull request Feb 17, 2025 that will close this issue
@romanc romanc added the gt4py.next Issues concerning the new version with support for non-cartesian grids. label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gt4py.next Issues concerning the new version with support for non-cartesian grids.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants