Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SDFG.name a proper property #1289

Merged
merged 1 commit into from
Jun 29, 2023
Merged
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
26 changes: 3 additions & 23 deletions dace/sdfg/sdfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class SDFG(OrderedDiGraph[SDFGState, InterstateEdge]):
the `Memlet` class documentation.
"""

name = Property(dtype=str, desc="Name of the SDFG")
arg_names = ListProperty(element_type=str, desc='Ordered argument names (used for calling conventions).')
constants_prop = Property(dtype=dict, default={}, desc="Compile-time constants")
_arrays = Property(dtype=dict,
Expand Down Expand Up @@ -425,7 +426,7 @@ def __init__(self,
:param parent: The parent SDFG or SDFG state (for nested SDFGs).
"""
super(SDFG, self).__init__()
self._name = name
self.name = name
if name is not None and not validate_name(name):
raise InvalidSDFGError('Invalid SDFG name "%s"' % name, self, None)

Expand Down Expand Up @@ -1107,27 +1108,6 @@ def set_sourcecode(self, code: str, lang=None):
"""
self.sourcecode = {'code': code, 'language': lang}

@property
def name(self):
""" The name of this SDFG. """
if self._name != self._orig_name:
return self._name
newname = self._orig_name
numbers = []
for sdfg in self._sdfg_list:
if sdfg is not self and sdfg._orig_name == self._orig_name:
numbers.append(sdfg._num)
while self._num in numbers:
self._num += 1
if self._num > 0:
newname = '{}_{}'.format(self._orig_name, self._num)
self._name = newname
return newname

@name.setter
def name(self, newname: str):
self._name = newname

@property
def label(self):
""" The name of this SDFG. """
Expand Down Expand Up @@ -2240,7 +2220,7 @@ def compile(self, output_file=None, validate=True) -> \
# Rename SDFG to avoid runtime issues with clashing names
index = 0
while sdfg.is_loaded():
sdfg._name = f'{self._name}_{index}'
sdfg.name = f'{self.name}_{index}'
index += 1
if self.name != sdfg.name:
warnings.warn('SDFG "%s" is already loaded by another object, '
Expand Down