Skip to content

Commit

Permalink
Make SDFG.name a proper property (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad authored Jun 29, 2023
1 parent d534553 commit 672fc30
Showing 1 changed file with 3 additions and 23 deletions.
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

0 comments on commit 672fc30

Please sign in to comment.