Skip to content

Reduce JIT-heavy structural test coverage in transformation tests#659

Open
mlange05 wants to merge 11 commits intomainfrom
chore/reduce-jit-transform-loop-tests
Open

Reduce JIT-heavy structural test coverage in transformation tests#659
mlange05 wants to merge 11 commits intomainfrom
chore/reduce-jit-transform-loop-tests

Conversation

@mlange05
Copy link
Copy Markdown
Collaborator

Summary

  • replace several JIT-backed transformation tests with structural IR assertions in loop, region, outline, and loop-blocking test modules
  • keep targeted JIT smoke tests for cases where runtime semantics still add meaningful coverage
  • add AGENTS guidance for using Loki's native symbol, expression, and numeric comparison support in structural tests

Details

This change reduces the amount of runtime compilation used in tests whose main purpose is to validate transformation structure rather than compiled behavior.

The refactor focuses on:

  • loki/transformations/tests/test_transform_loop.py
  • loki/transformations/tests/test_transform_region.py
  • loki/transformations/extract/tests/test_outline.py
  • loki/transformations/tests/test_loop_blocking.py

Across these files, simple end-to-end JIT checks are replaced with direct assertions on:

  • assignments
  • loop variables and bounds
  • outlined calls and inferred arguments
  • promoted variables and shapes
  • blocked array accesses

The remaining JIT tests act as smoke coverage for cases that still benefit from runtime validation, such as:

  • dataflow-sensitive promotion behavior
  • more complex fusion/fission interactions
  • cross-module import behavior
  • derived-type and associate handling
  • higher-dimensional blocking cases

The branch also updates the local testing style to prefer Loki's native comparison semantics over stringification in structural assertions, and documents that guidance in AGENTS.md.

Validation

  • pytest loki/transformations/tests/test_transform_loop.py
  • pytest loki/transformations/tests/test_transform_region.py
  • pytest loki/transformations/extract/tests/test_outline.py
  • pytest loki/transformations/tests/test_loop_blocking.py

Reduce the JIT burden in transform loop tests by validating transformed loop structure directly in the IR. Keep a small runtime smoke suite for the subtle fusion, fission and unroll interactions that still need end-to-end coverage.
Reduce runtime compilation in transform region tests by checking hoisted assignment and loop structure directly in the IR. Keep the pragma-inlining and promotion cases as end-to-end smoke tests because they still provide valuable semantic coverage.
Rename the local assignment helper and compare Loki assignment nodes directly instead of stringifying lhs and rhs expressions. This keeps the structural assertions aligned with Loki's native symbol and expression comparison support.
Rename the local assignment helper in transform loop tests and compare Loki assignment nodes directly instead of stringifying expressions. This keeps the IR assertions aligned with Loki's native symbol and expression comparison support.
Rename the local loop helpers to reflect native Loki node comparisons and stop stringifying loop variables and literal bounds in the transform loop and region tests. This keeps the structural IR assertions aligned with Loki's native comparison behavior for symbols, expressions and numeric literals.
Use native Loki comparisons for conditional expressions and variable shapes in the transform loop tests instead of stringifying those IR nodes. This finishes the recent cleanup toward structural assertions that rely on Loki's native comparison support.
Reduce runtime compilation in outline transformation tests by asserting outlined routines, calls and inferred arguments directly in the IR. Keep the imports, derived-type and associate cases as end-to-end smoke tests because they still provide valuable semantic coverage across module boundaries and richer argument handling.
Reduce runtime compilation in the loop blocking tests by checking split loop structure, generated helper variables and blocked array accesses directly in the IR. Keep the multi-intent and higher-dimensional blocking cases as end-to-end smoke tests because they still provide useful semantic coverage.
@github-actions
Copy link
Copy Markdown

Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/659/index.html

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.35%. Comparing base (b711b95) to head (c22171a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #659      +/-   ##
==========================================
- Coverage   96.39%   96.35%   -0.04%     
==========================================
  Files         266      266              
  Lines       46418    45925     -493     
==========================================
- Hits        44745    44252     -493     
  Misses       1673     1673              
Flag Coverage Δ
lint_rules 96.40% <ø> (ø)
loki 96.35% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Remove redundant imports and drop unused parametrization from the transformed IR-only test cases. This keeps the structural tests lint-clean without carrying runtime-oriented parameters that no longer affect coverage.
@mlange05 mlange05 requested a review from awnawab March 25, 2026 13:59

c = a + b
end subroutine test_outline
end subroutine test_outline
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: the subroutine closing statement should have the same indent as the opening

a(i) = real(i, kind=8)
end do
end subroutine test_1d_splitting
end subroutine test_1d_splitting
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: same comment about end statement indentation

assert np.array_equal(a, a_ref), "a should be equal to a_ref=(1, 2, ..., n)"

clean_test(filepath)
assert loop_symbols(routine.ir) == [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a test that verifies if the value of the inner loop upper bound is indeed block_size

assert np.array_equal(a, a_ref), "a should be equal to a_ref=(1, 2, ..., n)"

clean_test(filepath)
assert loop_symbols(routine.ir) == [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about block_size

assert np.array_equal(b, b_ref), "b should equal b_ref"

clean_test(filepath)
assert loop_symbols(routine.ir) == [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same block_size comment

assert np.array_equal(a, a_ref), "a should be equal to a_ref=(1, 2, ..., n)"

clean_test(filepath)
assert loop_symbols(routine.ir) == [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same block_size comment

end do
end do
end subroutine transform_loop_interchange
end subroutine transform_loop_interchange
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: mismatched end statement indentation

end do
end do
end subroutine transform_loop_interchange_project
end subroutine transform_loop_interchange_project
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: same here

@awnawab
Copy link
Copy Markdown
Contributor

awnawab commented Mar 31, 2026

Thanks a lot @mlange05 for this cleanup 🙏 and congrats on your first agentic PR 😉 I've left a couple of minor comments on where I think the test coverage should be expanded, but apart from that this is essentially G2G 👌

@mlange05
Copy link
Copy Markdown
Collaborator Author

mlange05 commented Apr 1, 2026

@awnawab Well spotted. Should all be addressed now.

Copy link
Copy Markdown
Contributor

@awnawab awnawab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the prompt fixes, this is now G2G 👌

@mlange05 mlange05 added the ready to merge This PR has been approved and is ready to be merged label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge This PR has been approved and is ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants