NWChemEx / NWChemEx/PluginPlay

Problem in adding multiple Python modules to ModuleManager

Open
#328 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
13
Forks
1
Avg merge
43m
Merged PRs (30d)
4

Description

I have been observing intermittent errors with Python modules like IndexError: map::at with mod.change_input() when I have more than one Python module in the module manager. The problem never happens if I have only one Python module, but happens randomly if I have more than one. I think the code below shows the root of the problem.

import pluginplay as pp
from py_test_pluginplay import OneInOneOut, OneIn, OneOut

ptype = OneInOneOut()
class test_module(pp.ModuleBase):
    """Basic PluginPlay module that satisfies OneInOneOut property type"""
    def __init__(self):
        pp.ModuleBase.__init__(self)
        self.description(self.__doc__)
        self.satisfies_property_type(ptype)

    def run_(self, inputs, submods):
        s, = ptype.unwrap_inputs(inputs)
        r = self.results()
        return ptype.wrap_results(r, s)

ptype = OneIn()
class test_module2(pp.ModuleBase):
    """Basic PluginPlay module that satisfies OneIn property type"""
    def __init__(self):
        pp.ModuleBase.__init__(self)
        self.description(self.__doc__)
        self.satisfies_property_type(ptype)

    def run_(self, inputs, submods):
        s, = ptype.unwrap_inputs(inputs)
        r = self.results()
        return ptype.wrap_results(r, s)
ptype = OneOut()
class test_module3(pp.ModuleBase):
    def __init__(self):
        pp.ModuleBase.__init__(self)
        self.satisfies_property_type(ptype)
        self.add_input('inp2')

    def run_(self, inputs, submods):
        r = self.results()
        return ptype.wrap_results(r)

mm = pp.ModuleManager()
mm.add_module('test_module', test_module())
mm.add_module('test_module2', test_module2())
mm.add_module('test_module3', test_module3())
for key in mm.keys():
    print(key, mm[key])
print(mm['test_module'] == mm['test_module2'])
print(mm.at('test_module') == mm.at('test_module2'))

If you run the Python code above several times, you will get something like:

(nwx) 01:15:00|nwx|test> python mm_test3.py
test_module <pluginplay.Module object at 0x7fafa0d2a330>
test_module2 <pluginplay.Module object at 0x7fafa0d24a70>
test_module3 <pluginplay.Module object at 0x7fafa0d1d970>
True
True
(nwx) 01:15:02|nwx|test> python mm_test3.py
test_module <pluginplay.Module object at 0x7f290c631530>
test_module2 <pluginplay.Module object at 0x7f290c631530>
test_module3 <pluginplay.Module object at 0x7f290c631530>
True
True

Somehow in the second run, test_modules that satisfy different property types are stored at the same memory location. Module comparison always returns True might be because the comparison operator not being exported, but I think main issue is that Python modules are not added to the module manager properly. Maybe this issue is related to #309 somehow.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report names ModuleManager, ModuleBase, and mod.change_input; first reproduce the supplied Python script repeatedly, then inspect the ModuleManager add_module/at path and related Python binding behavior, including issue #309. Done means distinct modules remain distinct across runs and the intermittent IndexError no longer occurs, with a regression test for multiple Python modules.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.