Skip to content

ProcessModels Cannot Be Found Through Relative Imports #902

@kds300

Description

@kds300

Describe the bug
If a process model is defined using a relative import, the function ProcGroupDiGraphs._find_proc_models() fails to find it.

To reproduce current behavior
Steps to reproduce the behavior:

  • File structure:
package/
|- __init__.py
|- proc/
|      |- process.py
|      |- models.py

  • process.py
from lava.magma.core.process.process import AbstractProcess

class TestProcess(AbstractProcess):
    """Test process for proc-model search"""
  • models.py
from lava.magma.core.model.model import AbstractProcessModel
from lava.magma.core.decorator import implements
from lava.magma.core.sync.protocols.loihi_protocol import LoihiProtocol

from .process import TestProcess


@implements(proc=TestProcess, protocol=LoihiProtocol)
class TestModelRelative(AbstractProcessModel):
    """Process model defined using relative import of Process."""
  • When running a network with TestProcess,
Cannot import module 'modules' when searching ProcessModels for Process 'TestProcess'.

Expected behavior
The compiler finds the associated process model.

Environment (please complete the following information):

  • Device: Laptop
  • OS: Ubuntu
  • Lava version: 0.10.0

Additional context
I believe the issue stems from using file paths for importing the modules containing process models. When importing this way, relative imports do not work since the information about the parent module is lost. This can be avoided by importing the modules by name and adding the appropriate prefixes when iterating through submodules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    0-needs-reviewFor all new issues1-bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions