Skip to content

Commit

Permalink
refactor[next]: remove all FencilDefinitions from tests (#1773)
Browse files Browse the repository at this point in the history
  • Loading branch information
havogt authored Dec 6, 2024
1 parent 8b6abc2 commit 06813d5
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 211 deletions.
10 changes: 2 additions & 8 deletions src/gt4py/next/iterator/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,11 @@ def _input_validator(self: datamodels.DataModelTP, attribute: datamodels.Attribu
"scan",
"if_",
"index", # `index(dim)` creates a dim-field that has the current index at each point
"as_fieldop", # `as_fieldop(stencil, domain)` creates field_operator from stencil (domain is optional, but for now required for embedded execution)
*ARITHMETIC_BUILTINS,
*TYPEBUILTINS,
}

# only used in `Program`` not `FencilDefinition`
# TODO(havogt): restructure after refactoring to GTIR
GTIR_BUILTINS = {
*BUILTINS,
"as_fieldop", # `as_fieldop(stencil, domain)` creates field_operator from stencil (domain is optional, but for now required for embedded execution)
}


class FencilDefinition(Node, ValidatedSymbolTableTrait):
id: Coerced[SymbolName]
Expand Down Expand Up @@ -243,7 +237,7 @@ class Program(Node, ValidatedSymbolTableTrait):
implicit_domain: bool = False

_NODE_SYMBOLS_: ClassVar[List[Sym]] = [
Sym(id=name) for name in sorted(GTIR_BUILTINS)
Sym(id=name) for name in sorted(BUILTINS)
] # sorted for serialization stability


Expand Down
4 changes: 1 addition & 3 deletions src/gt4py/next/iterator/transforms/symbol_ref_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,4 @@ def collect_symbol_refs(


def get_user_defined_symbols(symtable: dict[eve.SymbolName, itir.Sym]) -> set[str]:
return {str(sym) for sym in symtable.keys()} - {
str(n.id) for n in itir.FencilDefinition._NODE_SYMBOLS_
}
return {str(sym) for sym in symtable.keys()} - {str(n.id) for n in itir.Program._NODE_SYMBOLS_}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ def testee_op(a: cases.IField) -> cases.IField:
def testee(a: cases.IField, out: cases.IField):
testee_op(a, out=out)

assert isinstance(testee.itir, (itir.Program, itir.FencilDefinition))
assert isinstance(
testee.with_backend(cartesian_case.backend).itir, (itir.Program, itir.FencilDefinition)
)
assert isinstance(testee.itir, itir.Program)
assert isinstance(testee.with_backend(cartesian_case.backend).itir, itir.Program)


def test_frozen(cartesian_case):
Expand Down
36 changes: 1 addition & 35 deletions tests/next_tests/unit_tests/iterator_tests/test_pretty_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# SPDX-License-Identifier: BSD-3-Clause

from gt4py.next.iterator import ir
from gt4py.next.iterator.pretty_parser import pparse
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.pretty_parser import pparse
from gt4py.next.type_system import type_specifications as ts


Expand Down Expand Up @@ -208,18 +208,6 @@ def test_temporary():
assert actual == expected


def test_stencil_closure():
testee = "y ← (deref)(x) @ cartesian_domain();"
expected = ir.StencilClosure(
domain=ir.FunCall(fun=ir.SymRef(id="cartesian_domain"), args=[]),
stencil=ir.SymRef(id="deref"),
output=ir.SymRef(id="y"),
inputs=[ir.SymRef(id="x")],
)
actual = pparse(testee)
assert actual == expected


def test_set_at():
testee = "y @ cartesian_domain() ← x;"
expected = ir.SetAt(
Expand Down Expand Up @@ -262,28 +250,6 @@ def test_if_stmt():
assert actual == expected


# TODO(havogt): remove after refactoring to GTIR
def test_fencil_definition():
testee = "f(d, x, y) {\n g = λ(x) → x;\n y ← (deref)(x) @ cartesian_domain();\n}"
expected = ir.FencilDefinition(
id="f",
function_definitions=[
ir.FunctionDefinition(id="g", params=[ir.Sym(id="x")], expr=ir.SymRef(id="x"))
],
params=[ir.Sym(id="d"), ir.Sym(id="x"), ir.Sym(id="y")],
closures=[
ir.StencilClosure(
domain=ir.FunCall(fun=ir.SymRef(id="cartesian_domain"), args=[]),
stencil=ir.SymRef(id="deref"),
output=ir.SymRef(id="y"),
inputs=[ir.SymRef(id="x")],
)
],
)
actual = pparse(testee)
assert actual == expected


def test_program():
testee = "f(d, x, y) {\n g = λ(x) → x;\n tmp = temporary(domain=cartesian_domain(), dtype=float64);\n y @ cartesian_domain() ← x;\n}"
expected = ir.Program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# SPDX-License-Identifier: BSD-3-Clause

from gt4py.next.iterator import ir
from gt4py.next.iterator.pretty_printer import PrettyPrinter, pformat
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.pretty_printer import PrettyPrinter, pformat
from gt4py.next.type_system import type_specifications as ts


Expand Down Expand Up @@ -313,18 +313,6 @@ def test_temporary():
assert actual == expected


def test_stencil_closure():
testee = ir.StencilClosure(
domain=ir.FunCall(fun=ir.SymRef(id="cartesian_domain"), args=[]),
stencil=ir.SymRef(id="deref"),
output=ir.SymRef(id="y"),
inputs=[ir.SymRef(id="x")],
)
expected = "y ← (deref)(x) @ cartesian_domain();"
actual = pformat(testee)
assert actual == expected


def test_set_at():
testee = ir.SetAt(
expr=ir.SymRef(id="x"),
Expand All @@ -336,28 +324,6 @@ def test_set_at():
assert actual == expected


# TODO(havogt): remove after refactoring.
def test_fencil_definition():
testee = ir.FencilDefinition(
id="f",
function_definitions=[
ir.FunctionDefinition(id="g", params=[ir.Sym(id="x")], expr=ir.SymRef(id="x"))
],
params=[ir.Sym(id="d"), ir.Sym(id="x"), ir.Sym(id="y")],
closures=[
ir.StencilClosure(
domain=ir.FunCall(fun=ir.SymRef(id="cartesian_domain"), args=[]),
stencil=ir.SymRef(id="deref"),
output=ir.SymRef(id="y"),
inputs=[ir.SymRef(id="x")],
)
],
)
actual = pformat(testee)
expected = "f(d, x, y) {\n g = λ(x) → x;\n y ← (deref)(x) @ cartesian_domain();\n}"
assert actual == expected


def test_program():
testee = ir.Program(
id="f",
Expand Down
Loading

0 comments on commit 06813d5

Please sign in to comment.