← Back to Pull requests

feat[next]: Infer as_fieldop type without domain #1853

Closed
unknown closed this pull request without merging on May 18, 2025 13:09 UTC
View on GitHub
unknown unknown commented on Feb 07, 2025 11:10 UTC
Author

  • Extend the GTIR type inference to infer the type of as_fieldop calls that don't have a domain argument.

  • Avoids unnecessary promotion in the domain inference by using the now available type information, e.g. as_fieldop(deref)(vertex_field) will only get a Vertex domain also in cases when it is read from an as_fieldop on a Vertex, K domain.

  • The domain_inference of as_fieldop with scan was extended to keep the vertical dimensions.

  • PruneBroadcast was renamed to RemoveBroadcast, and the filename was changed as well.
  • Motivation:
    Previously, type inference was required to run after domain inference. An as_fieldop call as emitted by the frontend had no domain, and inferring the type of the domain was not possible, since there existed no global ordering relation of dimensions, e.g. for an as_fieldop operating on a Vertex and a K field it was unclear if the dimensions of the output are (Vertex, K) or (K, Vertex). This problem has many negative consequences in other places:

  • The domain inference was missing information on the dimensions of intermediate / temporary fields and as a result might promote unnecessary promote fields, e.g. an intermediate on K might be promoted to Vertex, K.

  • We could not run simplifications / transformations before inlining all (named) functions as they require domain inference which did not support them. As such the tree grows significantly before we simplifications, unnecessarily increasing transformation / compile times.

  • We had to run the collapse-tuple pass with partial type information, as it is required to run before domain inference (in order to remove field expressions that are never accessed).
  • The global ordering was already introduced in PR #1847.

    <!--
    TODOs:

  • Fix the unnecessary promotion in the domain inference by using the now available type information.

  • as_fieldop with scan without domain, e.g., test_fieldop_from_scan:

  • __field_operator_simple_scan_operator(out, __out_0_range) {
    out @ c⟨ KDimᵥ: [__out_0_range[0], __out_0_range[1][ ⟩
    ← as_fieldop(scan(λ(carry) → carry + 1.0, True, 1.0), cartesian_domain())();

    has an empty domain. A special case is implemented for that, which ensures, that the vertical dimensions are kept.
  • test_cse.py:test_scalar_extraction_inside_as_fieldop results in an Assertion Error for assert isinstance(subexpr.type, ts.TypeSpec) because subexpr.type = None when running it or debugging without breakpoints. There is however no error when setting a breakpoint in type_synthesizer.py:applied_as_fieldop.

  • test_program.py::test_index_builtin[None] - TypeError: broadcast() missing 1 required positional argument: 'dimensions'

  • test_icon_like_scan.py::test_solve_nonhydro_stencil_52_like_z_q_tup[gtfn.run_gtfn] - NotImplementedError: Tuple expressions with different domains is not supported yet.

  • test_type_inference.py::test_function_definition - AssertionError: Node bar already has a type Field[[IDim], float64] which differs from (IteratorType(position_dims=[Dimension(value='IDim', kind=<DimensionKind.HORIZONTAL: 'horizontal'>)], defined_dims=[Dimension(value='IDim', kind=<DimensionKind.HORIZONTAL: 'horizontal'>)], element_type=ScalarType(kind=<ScalarKind.FLOAT64: 11>, shape=None))) -> float64.

  • test_domain_inference.py::test_nested_let_arg_shadowed2 - TypeError: Error during coercion of given value 'in_field1' for field 'Sym.id'

  • test_domain_inference.py everything with tuple_get

  • test_execution.py::test_zero_dim_tuple_arg[simple_mesh-dace.run_dace_cpu] - TypeError: Expected an array of index expressions: got empty array or None

  • test_execution.py::test_implicit_broadcast_mixed_dim[dace.run_dace_cpu] - ValueError: not enough values to unpack (expected 3, got 0)

  • test_gt4py_builtins.py::test_reduction_expression_in_call[simple_mesh-dace.run_dace_cpu_noopt] - ValueError: not enough values to unpack (expected 3, got 0)

  • test_collapse_tuple.py::test_flatten_as_fieldop_args (and the two tests below) fail with: AssertionError: Node it already has a type IteratorType(position_dims=[Dimension(value='Vertex', kind=<DimensionKind.HORIZONTAL: 'horizontal'>)], defined_dims=[Dimension(value='Vertex', kind=<DimensionKind.HORIZONTAL: 'horizontal'>)], element_type=TupleType(types=[ScalarType(kind=<ScalarKind.INT32: 6>, shape=None), ScalarType(kind=<ScalarKind.INT32: 6>, shape=None)])) which differs from IteratorType(position_dims=[], defined_dims=[], element_type=TupleType(types=[ScalarType(kind=<ScalarKind.INT32: 6>, shape=None), ScalarType(kind=<ScalarKind.INT32: 6>, shape=None)])).

  • It passes when removing Vertex from the position_dims and the defined_dims, i.e.,
    it_type = it_ts.IteratorType(
            position_dims=[],
            defined_dims=[],
            element_type=ts.TupleType(types=[int_type, int_type]),
        )
    

  • test_solve_nonhydro_stencil_52_like_z_q_tup[gtfn.run_gtfn ] is failing now with

  • ../../../../../src/gt4py/next/iterator/transforms/global_tmps.py:62: AssertionError: assert cpm.is_call_to(tuple_expr, "make_tuple") because of changes in PR#1985 @tehrengruber: Fixed after commit 78dfe94.
    -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: SF-N Review duration: 144119m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1853"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%