Skip to content

Commit

Permalink
Add compat_check option to {Module,Manager}.connect() methods to enab…
Browse files Browse the repository at this point in the history
…le expensive compatibility checking to be turned off during emulation setup.
  • Loading branch information
lebedov committed Mar 18, 2015
1 parent 73d6c2d commit 00a8283
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
29 changes: 20 additions & 9 deletions neurokernel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def out_ids(self):
if self.patterns[m].is_connected(self.pat_ints[m][0],
self.pat_ints[m][1])]

def connect(self, m, pat, int_0, int_1):
def connect(self, m, pat, int_0, int_1, compat_check=True):
"""
Connect the current module instance to another module with a pattern instance.
Expand All @@ -264,6 +264,10 @@ def connect(self, m, pat, int_0, int_1):
int_0, int_1 : int
Which of the pattern's interface to connect to the current module
and the specified module, respectively.
compat_check : bool
Check whether the interfaces of the current and specified modules
are compatible with the specified pattern. This option is provided
because compatibility checking can be expensive.
"""

assert isinstance(m, BaseModule)
Expand All @@ -273,8 +277,11 @@ def connect(self, m, pat, int_0, int_1):

# Check compatibility of the interfaces exposed by the modules and the
# pattern:
assert self.interface.is_compatible(0, pat.interface, int_0, True)
assert m.interface.is_compatible(0, pat.interface, int_1, True)
if compat_check:
self.log_info('checking compatibility of modules {0} and {1} and'
' assigned pattern'.format(self.id, m.id))
assert self.interface.is_compatible(0, pat.interface, int_0, True)
assert m.interface.is_compatible(0, pat.interface, int_1, True)

# Check that no fan-in from different source modules occurs as a result
# of the new connection by getting the union of all connected input
Expand Down Expand Up @@ -1057,7 +1064,7 @@ def __init__(self, port_data=PORT_DATA, port_ctrl=PORT_CTRL,
# Set up process to handle time data:
self.time_listener = TimeListener(self.port_ctrl, self.port_time)

def connect(self, m_0, m_1, pat, int_0=0, int_1=1):
def connect(self, m_0, m_1, pat, int_0=0, int_1=1, compat_check=True):
"""
Connect two module instances with a Pattern instance.
Expand All @@ -1070,9 +1077,12 @@ def connect(self, m_0, m_1, pat, int_0=0, int_1=1):
int_0, int_1 : int
Which of the pattern's interfaces to connect to `m_0` and `m_1`,
respectively.
compat_check : bool
Check whether the interfaces of the specified modules
are compatible with the specified pattern. This option is provided
because compatibility checking can be expensive.
"""


assert isinstance(m_0, BaseModule) and isinstance(m_1, BaseModule)
assert isinstance(pat, Pattern)
assert int_0 in pat.interface_ids and int_1 in pat.interface_ids
Expand All @@ -1082,10 +1092,11 @@ def connect(self, m_0, m_1, pat, int_0=0, int_1=1):

# Check whether the interfaces exposed by the modules and the
# pattern share compatible subsets of ports:
self.log_info('checking compatibility of modules {0} and {1} and'
' assigned pattern'.format(m_0.id, m_1.id))
assert m_0.interface.is_compatible(0, pat.interface, int_0, True)
assert m_1.interface.is_compatible(0, pat.interface, int_1, True)
if compat_check:
self.log_info('checking compatibility of modules {0} and {1} and'
' assigned pattern'.format(m_0.id, m_1.id))
assert m_0.interface.is_compatible(0, pat.interface, int_0, True)
assert m_1.interface.is_compatible(0, pat.interface, int_1, True)

# Add the module and pattern instances to the internal dictionaries of
# the manager instance if they are not already there:
Expand Down
19 changes: 12 additions & 7 deletions neurokernel/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class Manager(BaseManager):
Table of data transmission connections between modules.
"""

def connect(self, m_0, m_1, pat, int_0=0, int_1=1):
def connect(self, m_0, m_1, pat, int_0=0, int_1=1, compat_check=True):
"""
Connect two module instances with a Pattern instance.
Expand All @@ -521,6 +521,10 @@ def connect(self, m_0, m_1, pat, int_0=0, int_1=1):
int_0, int_1 : int
Which of the pattern's interfaces to connect to `m_0` and `m_1`,
respectively.
compat_check : bool
Check whether the interfaces of the specified modules
are compatible with the specified pattern. This option is provided
because compatibility checking can be expensive.
"""

assert isinstance(m_0, BaseModule) and isinstance(m_1, BaseModule)
Expand All @@ -532,10 +536,11 @@ def connect(self, m_0, m_1, pat, int_0=0, int_1=1):

# Check whether the interfaces exposed by the modules and the
# pattern share compatible subsets of ports:
self.log_info('checking compatibility of modules {0} and {1} and'
' assigned pattern'.format(m_0.id, m_1.id))
assert m_0.interface.is_compatible(0, pat.interface, int_0, True)
assert m_1.interface.is_compatible(0, pat.interface, int_1, True)
if compat_check:
self.log_info('checking compatibility of modules {0} and {1} and'
' assigned pattern'.format(m_0.id, m_1.id))
assert m_0.interface.is_compatible(0, pat.interface, int_0, True)
assert m_1.interface.is_compatible(0, pat.interface, int_1, True)

# Find the ports common to each of the pattern's interfaces and the
# respective interfaces of the modules connected to them; these two sets
Expand Down Expand Up @@ -569,8 +574,8 @@ def connect(self, m_0, m_1, pat, int_0=0, int_1=1):

# Pass the pattern to the modules being connected:
self.log_info('passing connection pattern to modules {0} and {1}'.format(m_0.id, m_1.id))
m_0.connect(m_1, pat, int_0, int_1)
m_1.connect(m_0, pat, int_1, int_0)
m_0.connect(m_1, pat, int_0, int_1, compat_check)
m_1.connect(m_0, pat, int_1, int_0, compat_check)

# Update the routing table:
self.log_info('updating routing table')
Expand Down

0 comments on commit 00a8283

Please sign in to comment.