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

OutPort reshape/flatten has compilation issue #163

Closed
2 of 7 tasks
bamsumit opened this issue Jan 20, 2022 · 1 comment
Closed
2 of 7 tasks

OutPort reshape/flatten has compilation issue #163

bamsumit opened this issue Jan 20, 2022 · 1 comment
Assignees
Labels
1-bug Something isn't working area: magma/compiler Issues with something in lava/magma/compiler

Comments

@bamsumit
Copy link
Contributor

Objective of issue:

Lava version:

  • 0.3.0 (feature release)
  • 0.2.1 (bug fixes)
  • 0.2.0 (current version)
  • 0.1.2

I'm submitting a ...

  • bug report
  • feature request
  • documentation request

Current behavior:

  • The compilation fails when flatten() is used.

Expected behavior:

  • It should run.

Steps to reproduce:

  • Code is below

Related code:

from typing import List
import numpy as np

from lava.magma.core.run_configs import RunConfig
from lava.magma.core.run_conditions import RunSteps
from lava.proc.io.source import RingBuffer as SendProcess
from lava.proc.io.sink import RingBuffer as ReceiveProcess
from lava.magma.core.model.py.model import PyLoihiProcessModel


class TestRunConfig(RunConfig):
    """Run configuration selects appropriate ProcessModel based on tag
    """
    def __init__(self, select_tag: str = 'fixed_pt'):
        super(TestRunConfig, self).__init__(custom_sync_domains=None)
        self.select_tag = select_tag

    def select(
        self, _, proc_models: List[PyLoihiProcessModel]
    ) -> PyLoihiProcessModel:
        for pm in proc_models:
            if self.select_tag in pm.tags:
                return pm
        raise AssertionError('No legal ProcessModel found.')


if __name__ == '__main__':
    num_steps = 10
    shape = (64, 32, 16)
    input = np.random.randint(256, size=shape + (num_steps,))
    input -= 128

    source = SendProcess(data=input)
    sink = ReceiveProcess(shape=(np.prod(shape), ), buffer=num_steps)
    source.out_ports.s_out.flatten().connect(sink.in_ports.a_in)

    run_condition = RunSteps(num_steps=num_steps)
    run_config = TestRunConfig(select_tag='floating_pt')
    sink.run(condition=run_condition, run_cfg=run_config)
    output = sink.data.get()
    sink.stop()

    expected = input.reshape([-1, num_steps])
    print(np.all(output == expected))

Other information:

Line numbers may be different. I had some local changes.

Traceback (most recent call last):
  File "test_permute.py", line 82, in <module>
    sink.run(condition=run_condition, run_cfg=run_config)
  File "/home/sshresth/lava-nc/lava/src/lava/magma/core/process/process.py", line 396, in run
    executable = self.compile(run_cfg)
  File "/home/sshresth/lava-nc/lava/src/lava/magma/core/process/process.py", line 345, in compile
    return compiler.compile(self, run_cfg)
  File "/home/sshresth/lava-nc/lava/src/lava/magma/compiler/compiler.py", line 998, in compile
    procs = self._find_processes(proc)
  File "/home/sshresth/lava-nc/lava/src/lava/magma/compiler/compiler.py", line 99, in _find_processes
    new_list.extend(self._find_processes(proc, seen_procs))
  File "/home/sshresth/lava-nc/lava/src/lava/magma/compiler/compiler.py", line 75, in _find_processes
    for in_port in proc.in_ports.members + proc.var_ports.members:
AttributeError: 'NoneType' object has no attribute 'in_ports'
@bamsumit bamsumit added 1-bug Something isn't working area: magma/compiler Issues with something in lava/magma/compiler help needed Extra attention is needed labels Jan 20, 2022
@mathisrichter
Copy link
Contributor

mathisrichter commented Feb 4, 2022

The same problem appears with all virtual ports.

This is because in the compiler method _find_processes() the virtual port object is interpreted as an AbstractPort object rather than a AbstractVirtualPort object. The issue is fixed by switching out the order of inheritance of the concrete virtual port classes from
class ReshapePort(AbstractPort, AbstractVirtualPort):
to
class ReshapePort(AbstractVirtualPort, AbstractPort):

This is being addressed as part of the implementation of virtual ports.

@mathisrichter mathisrichter self-assigned this Feb 4, 2022
@mathisrichter mathisrichter removed the help needed Extra attention is needed label Feb 4, 2022
mathisrichter added a commit to bamsumit/lava that referenced this issue Feb 4, 2022
mathisrichter added a commit that referenced this issue Feb 25, 2022
* permute initial implementation

Signed-off-by: bamsumit <[email protected]>

* Tests for permute ports

* Process property of virtual ports no longer returns None

Signed-off-by: Mathis Richter <[email protected]>

* Added initial run-unittest for flatten() from issue #163

Signed-off-by: Mathis Richter <[email protected]>

* User-level API for TransposePort with unit tests

Signed-off-by: Mathis Richter <[email protected]>

* Fixed typo

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for flatten() and concat_with()

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for virtual ports in Processes that are executed (wip)

Signed-off-by: Mathis Richter <[email protected]>

* Preliminary implementation of virtual ports between OutPort and InPort (wip)

Signed-off-by: Mathis Richter <[email protected]>

* Fixing unit tests after merge

Signed-off-by: Mathis Richter <[email protected]>

* Added support for virtual ports between an OutPort and InPort of two hierarchical Processes

Signed-off-by: Mathis Richter <[email protected]>

* Clean up, exceptions, and generic unit tests for virtual port topologies

Signed-off-by: Mathis Richter <[email protected]>

* Fixed linter issues

Signed-off-by: Mathis Richter <[email protected]>

* Raising an exception when executing ConcatPort

Signed-off-by: Mathis Richter <[email protected]>

Co-authored-by: bamsumit <[email protected]>
Co-authored-by: Marcus G K Williams <[email protected]>
mathisrichter added a commit that referenced this issue Mar 2, 2022
* permute initial implementation

Signed-off-by: bamsumit <[email protected]>

* Tests for permute ports

* Process property of virtual ports no longer returns None

Signed-off-by: Mathis Richter <[email protected]>

* Added initial run-unittest for flatten() from issue #163

Signed-off-by: Mathis Richter <[email protected]>

* User-level API for TransposePort with unit tests

Signed-off-by: Mathis Richter <[email protected]>

* Fixed typo

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for flatten() and concat_with()

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for virtual ports in Processes that are executed (wip)

Signed-off-by: Mathis Richter <[email protected]>

* Preliminary implementation of virtual ports between OutPort and InPort (wip)

Signed-off-by: Mathis Richter <[email protected]>

* Fixing unit tests after merge

Signed-off-by: Mathis Richter <[email protected]>

* Added support for virtual ports between an OutPort and InPort of two hierarchical Processes

Signed-off-by: Mathis Richter <[email protected]>

* Clean up, exceptions, and generic unit tests for virtual port topologies

Signed-off-by: Mathis Richter <[email protected]>

* Fixed linter issues

Signed-off-by: Mathis Richter <[email protected]>

* Raising an exception when executing ConcatPort

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for virtual ports between OutPorts and InPorts in hierarchical Processes.

Signed-off-by: Mathis Richter <[email protected]>

* RefPort writing to an explicit VarPort via a virtual port.

Signed-off-by: Mathis Richter <[email protected]>

* RefPort reading from an explicit VarPort via a virtual port.

Signed-off-by: Mathis Richter <[email protected]>

* Fixed linter error

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for virtual ports between RefPorts and VarPorts in hierarchical Processes.

Signed-off-by: Mathis Richter <[email protected]>

* Fixed a docstring

Signed-off-by: Mathis Richter <[email protected]>

* Added docstrings to methods get_transform_func_fwd/bwd.

Signed-off-by: Mathis Richter <[email protected]>

Co-authored-by: bamsumit <[email protected]>
Co-authored-by: Marcus G K Williams <[email protected]>
monkin77 pushed a commit to monkin77/thesis-lava that referenced this issue Jul 12, 2024
* permute initial implementation

Signed-off-by: bamsumit <[email protected]>

* Tests for permute ports

* Process property of virtual ports no longer returns None

Signed-off-by: Mathis Richter <[email protected]>

* Added initial run-unittest for flatten() from issue lava-nc#163

Signed-off-by: Mathis Richter <[email protected]>

* User-level API for TransposePort with unit tests

Signed-off-by: Mathis Richter <[email protected]>

* Fixed typo

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for flatten() and concat_with()

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for virtual ports in Processes that are executed (wip)

Signed-off-by: Mathis Richter <[email protected]>

* Preliminary implementation of virtual ports between OutPort and InPort (wip)

Signed-off-by: Mathis Richter <[email protected]>

* Fixing unit tests after merge

Signed-off-by: Mathis Richter <[email protected]>

* Added support for virtual ports between an OutPort and InPort of two hierarchical Processes

Signed-off-by: Mathis Richter <[email protected]>

* Clean up, exceptions, and generic unit tests for virtual port topologies

Signed-off-by: Mathis Richter <[email protected]>

* Fixed linter issues

Signed-off-by: Mathis Richter <[email protected]>

* Raising an exception when executing ConcatPort

Signed-off-by: Mathis Richter <[email protected]>

Co-authored-by: bamsumit <[email protected]>
Co-authored-by: Marcus G K Williams <[email protected]>
monkin77 pushed a commit to monkin77/thesis-lava that referenced this issue Jul 12, 2024
* permute initial implementation

Signed-off-by: bamsumit <[email protected]>

* Tests for permute ports

* Process property of virtual ports no longer returns None

Signed-off-by: Mathis Richter <[email protected]>

* Added initial run-unittest for flatten() from issue lava-nc#163

Signed-off-by: Mathis Richter <[email protected]>

* User-level API for TransposePort with unit tests

Signed-off-by: Mathis Richter <[email protected]>

* Fixed typo

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for flatten() and concat_with()

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for virtual ports in Processes that are executed (wip)

Signed-off-by: Mathis Richter <[email protected]>

* Preliminary implementation of virtual ports between OutPort and InPort (wip)

Signed-off-by: Mathis Richter <[email protected]>

* Fixing unit tests after merge

Signed-off-by: Mathis Richter <[email protected]>

* Added support for virtual ports between an OutPort and InPort of two hierarchical Processes

Signed-off-by: Mathis Richter <[email protected]>

* Clean up, exceptions, and generic unit tests for virtual port topologies

Signed-off-by: Mathis Richter <[email protected]>

* Fixed linter issues

Signed-off-by: Mathis Richter <[email protected]>

* Raising an exception when executing ConcatPort

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for virtual ports between OutPorts and InPorts in hierarchical Processes.

Signed-off-by: Mathis Richter <[email protected]>

* RefPort writing to an explicit VarPort via a virtual port.

Signed-off-by: Mathis Richter <[email protected]>

* RefPort reading from an explicit VarPort via a virtual port.

Signed-off-by: Mathis Richter <[email protected]>

* Fixed linter error

Signed-off-by: Mathis Richter <[email protected]>

* Unit tests for virtual ports between RefPorts and VarPorts in hierarchical Processes.

Signed-off-by: Mathis Richter <[email protected]>

* Fixed a docstring

Signed-off-by: Mathis Richter <[email protected]>

* Added docstrings to methods get_transform_func_fwd/bwd.

Signed-off-by: Mathis Richter <[email protected]>

Co-authored-by: bamsumit <[email protected]>
Co-authored-by: Marcus G K Williams <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1-bug Something isn't working area: magma/compiler Issues with something in lava/magma/compiler
Projects
None yet
Development

No branches or pull requests

5 participants