Skip to content

Conversation

@egparedes
Copy link
Contributor

@egparedes egparedes commented Sep 1, 2025

Adding support for typed namedtuples and Dataclasses as basic containers structures for related Fields. Changes initially prototyped in #2211

egparedes added a commit that referenced this pull request Sep 4, 2025
Cleanups and small refactoring of the type system utilities in
preparation for the adding support for basic Python containers.

Stacked PRs:
- #2231
- #2232
Base automatically changed from cleanup-type-utils to main September 4, 2025 15:43
return extractors if extractors else None

def __postinit__(self) -> None:
def __post_init__(self) -> None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: add a pygrep expression in pre-commit to catch this (or check if ruff has a rule for this).

*self.program_type.definition.pos_or_kw_args.values(),
]
):
if isinstance(type_spec, ts.NamedTupleType):
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's a ts.TupleType that contains NamedTupleType, we have to generate an extractor.

Comment on lines 206 to 210
def extract(
container,
) -> NestedTuple[
PythonContainerValue
]: # TODO the input is NestedAnyContainer[PythonContainerValue], to be defined
Copy link
Contributor

Choose a reason for hiding this comment

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

possibly remove again once we have the extractor for all args

def __setitem__(self, index: AnyIndexSpec, value: Field | core_defs.ScalarT) -> None: ...


NumericValue: TypeAlias = core_defs.Scalar | Field
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
NumericValue: TypeAlias = core_defs.Scalar | Field
#: Elements of containers: TODO: use more examples
NumericValue: TypeAlias = core_defs.Scalar | Field

@havogt
Copy link
Contributor

havogt commented Oct 7, 2025

cscs-ci run

return len(self.types)


class NamedTupleType(TupleType):
Copy link
Contributor

Choose a reason for hiding this comment

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

Inheriting from TupleType is dangerous as NamedTuples can not be used in all places where tuples are allowed, but we check if something is a tuple by doing isinstance(..., TupleType)

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe call it StructType because due to the original_python_type it is not a just a NamedTuple anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe NamedCollectionType


class NamedTupleType(TupleType):
keys: list[str]
original_python_type: str # Format: '__module__:__qualname__' (used by pkgutil.resolve_name())
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a comment that described where is value may be used and where not. For example inside of the type_deduction is should never be used.

havogt added a commit that referenced this pull request Oct 20, 2025
#2285)

Preparation for #2232 to allow constructing different containers in
tree_map.
@egparedes egparedes marked this pull request as ready for review October 31, 2025 11:57
egparedes and others added 8 commits October 31, 2025 13:04
In case there is a view of a global array, we do not have a problem,
because we never modify the strides of globals. The problems start
when there is a view of a transient. The SDFG is constructed using C
order, which good for CPU. However, for GPU we go to FORTRAN order
 which is essentially swapping the memory order. But we can not only
do that for transients, but must also do it for views, which might be
difficult, because views can add or remove certain dimensions.

This PR does _not_ solve it, but instead generates an error if such a
case is detected.
## Description

We found that there was an issue with absolute k-indexing inside the
conditional of a while loop. This was due to a missing propagation of
the symbol-table into the conditional. This PR fixes that issue.


## Requirements

- [x] All fixes and/or new features come with corresponding tests.
- [ ] Important design decisions have been documented in the appropriate
ADR inside the [docs/development/ADRs/](docs/development/ADRs/README.md)
folder. N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants