Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion capgen/generator/group_cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
ResolvedCall,
ResolvedGroup,
ResolvedSubcycle,
_render_value_expr,
_root_symbol,
iter_phase_calls,
iter_phase_subcycles,
Expand Down Expand Up @@ -179,7 +180,12 @@ def _dim_decl_local(dimensions: List[str], host_dict) -> str:
locals_.append('{}:{}'.format(lb, ub))
else:
entry = host_dict.get(std_name) if host_dict else None
locals_.append(entry.local_name if entry is not None else std_name)
# ``access_path``, not ``local_name`` so that a DDT-component dimension
# (``GFS_Control%levs`` for ``vertical_layer_dimension``) is resolved.
locals_.append(
_render_value_expr(entry, host_dict)
if entry is not None else std_name
)
return ', dimension({})'.format(', '.join(locals_))


Expand Down
21 changes: 20 additions & 1 deletion unit-tests/test_suite_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2693,12 +2693,31 @@ def test_horizontal_dimension_uses_chunk_bounds(self):
)

def test_vertical_dim_uses_local_name(self):
# No special case for vertical dims — host's local name only.
# No special case for vertical dims. For a plain module-level host
# var the access path and the local name are the same string.
self.assertEqual(
_dim_decl_local(['vertical_layer_dimension'], self.hd),
', dimension(nlev)',
)

def test_ddt_component_dim_uses_full_access_path(self):
"""A DDT-component dimension must be declared with the full DDT
walk. ``local_name`` alone (``levs``) names nothing in the group
cap's scope, so the temp is sized from an undefined symbol — the
transform's assignments were right and only its declaration wrong."""
from metadata.variable_resolver import HostVarEntry
hd = dict(self.hd)
hd['vertical_layer_dimension'] = HostVarEntry(
'vertical_layer_dimension', 'levs', 'GFS_Control%levs',
None, 'integer', '', 'count', [], False, False, '',
)
self.assertEqual(
_dim_decl_local(
['horizontal_dimension', 'vertical_layer_dimension'], hd,
),
', dimension(lb:ub, GFS_Control%levs)',
)

def test_mixed_horiz_vert(self):
self.assertEqual(
_dim_decl_local(
Expand Down
Loading