spcl / spcl/dace

Deepcopying a nested SDFG does not copy constants

Open
#1,375 2 comments 0 reactions 0 assignees Claimed by @tbennun View on GitHub
Dominant language
Python
Stars
593
Forks
163
Avg merge
2d 23h
Merged PRs (30d)
60

Description

**Describe the bug**
If one deepcopy a SDFG of a nested SDFG where there are constants defined in the parent SDFG which are also present in the nested SDFG, they are not anymore after the deepcopy

**To Reproduce**
Execute the following code
```python
import copy

import dace
from dace.memlet import Memlet

def main():
sdfg = dace.SDFG('sdfg_copy_test')
KLEV = dace.symbol('KLEV')
sdfg.add_array('A', [KLEV], dace.float64)
sdfg.add_array('B', [KLEV], dace.float64)
state = sdfg.add_state()

nsdfg_sdfg = dace.SDFG('sdfg_copy_test_nested')
nsdfg_sdfg.add_array('A', [KLEV], dace.float64)
nsdfg_sdfg.add_array('B', [KLEV], dace.float64)
nsdfg_state = nsdfg_sdfg.add_state()

nsdfg_state.add_mapped_tasklet(
name="block_map",
map_ranges={"JK": "0:KLEV"},
inputs={"A": Memlet(data='A', subset='JK')},
outputs={"B": Memlet(data='B', subset='JK')},
code='b = a'
)

state.add_nested_sdfg(nsdfg_sdfg, sdfg, {'A'}, {'B'})

# Either works
# sdfg.specialize({'KLEV': 13})
sdfg.add_constant('KLEV', 13)
print(nsdfg_sdfg.constants)
sdfg_copy = copy.deepcopy(nsdfg_sdfg)
print(sdfg_copy.constants)

if __name__ == '__main__':
main()
```
This will print
```
{'KLEV': 13}
{}
```

**Expected behavior**
Expect it to print:
```
{'KLEV': 13}
{'KLEV': 13}
```

Contributor guide

Open the contributing guide

Research direction

Start by running the reproduction in main() and inspect the SDFG deepcopy path around copy.deepcopy(nsdfg_sdfg), SDFG.add_constant, and the constants attribute. Done means the copied nested SDFG retains {'KLEV': 13}, matching the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.