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

Bugfix to enable monitoring aliased vars #675

Merged
merged 7 commits into from
May 2, 2023
Merged
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: 5 additions & 3 deletions src/lava/magma/core/process/ports/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,11 @@ def create_implicit_var_port(var: Var) -> "ImplicitVarPort":
vp.process = var.process
# VarPort name could shadow existing attribute
if hasattr(var.process, vp.name):
raise AssertionError(
"Name of implicit VarPort might conflict"
" with existing attribute.")
name = str(vp.name)
name_suffix = 1
while hasattr(var.process, vp.name):
vp.name = name + "_" + str(name_suffix)
name_suffix += 1
setattr(var.process, vp.name, vp)
var.process.var_ports.add_members({vp.name: vp})

Expand Down
21 changes: 17 additions & 4 deletions tests/lava/magma/core/process/ports/test_ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ class VarProcess(AbstractProcess):

def test_connect_RefPort_to_Var_process_conflict(self):
"""Checks connecting RefPort implicitly to Var, with registered
processes and conflicting names. -> AssertionError"""
processes and conflicting names. -> adding _k with k=1,2,3... to
the name."""

# Create a mock parent process
class VarProcess(AbstractProcess):
Expand All @@ -307,9 +308,21 @@ class VarProcess(AbstractProcess):
v.name = "existing_attr"

# ... and connect it directly via connect_var(..)
# The naming conflict should raise an AssertionError
with self.assertRaises(AssertionError):
rp.connect_var(v)
rp.connect_var(v)

# This has the same effect as connecting a RefPort explicitly via a
# VarPort to a Var...
self.assertEqual(rp.get_dst_vars(), [v])
# ... but still creates a VarPort implicitly
vp = rp.get_dst_ports()[0]
self.assertIsInstance(vp, VarPort)
# ... which wraps the original Var
self.assertEqual(vp.var, v)

# In this case, the VarPort inherits its name and parent process from
# the Var it wraps + _implicit_port + _k with k=1,2,3...
self.assertEqual(vp.name, "_" + v.name + "_implicit_port" + "_1")
self.assertEqual(vp.process, v.process)

@unittest.skip("Currently not supported")
def test_connect_RefPort_to_many_Vars(self):
Expand Down