From b34758dd03a751bd2023890cb66798f022adba7f Mon Sep 17 00:00:00 2001 From: Luis Ferraz Date: Fri, 3 Mar 2023 16:54:49 +0100 Subject: [PATCH 1/6] get access to basic param types --- limbus/core/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/limbus/core/__init__.py b/limbus/core/__init__.py index bf12b30..16799e0 100644 --- a/limbus/core/__init__.py +++ b/limbus/core/__init__.py @@ -1,6 +1,6 @@ from limbus.core.component import Component, iterations_manager from limbus.core.states import ComponentState, PipelineState, VerboseMode -from limbus.core.param import NoValue, Param, Reference +from limbus.core.param import NoValue, Param, Reference, InputParam, OutputParam from limbus.core.params import Params, InputParams, OutputParams from limbus.core.pipeline import Pipeline from limbus.core.app import App @@ -18,5 +18,7 @@ "Reference", "InputParams", "OutputParams", + "InputParam", + "OutputParam", "Param", "NoValue"] From 84b934dda62db03e87c1db63eeb4d11238ac0cdc Mon Sep 17 00:00:00 2001 From: Luis Ferraz Date: Fri, 3 Mar 2023 16:55:11 +0100 Subject: [PATCH 2/6] update examples with typing --- examples/defining_cmps.py | 41 +++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/examples/defining_cmps.py b/examples/defining_cmps.py index 26b4a49..93805fa 100644 --- a/examples/defining_cmps.py +++ b/examples/defining_cmps.py @@ -2,7 +2,7 @@ from typing import List, Any import asyncio -from limbus.core import Component, Params, InputParams, OutputParams, ComponentState, VerboseMode +from limbus.core import Component, InputParams, OutputParams, ComponentState, VerboseMode, OutputParam, InputParam from limbus.core.pipeline import Pipeline @@ -10,13 +10,24 @@ # --------------------- class Add(Component): """Add two numbers.""" + # NOTE: type definition is optional, but it helps with the intellisense. ;) + class InputsTyping(OutputParams): # noqa: D106 + a: InputParam + b: InputParam + + class OutputsTyping(OutputParams): # noqa: D106 + out: OutputParam + + inputs: InputsTyping # type: ignore + outputs: OutputsTyping # type: ignore + @staticmethod - def register_inputs(inputs: Params) -> None: # noqa: D102 + def register_inputs(inputs: InputParams) -> None: # noqa: D102 inputs.declare("a", int) inputs.declare("b", int) @staticmethod - def register_outputs(outputs: Params) -> None: # noqa: D102 + def register_outputs(outputs: OutputParams) -> None: # noqa: D102 outputs.declare("out", int) async def forward(self) -> ComponentState: # noqa: D102 @@ -28,8 +39,14 @@ async def forward(self) -> ComponentState: # noqa: D102 class Printer(Component): """Prints the input to the console.""" + # NOTE: type definition is optional, but it helps with the intellisense. ;) + class InputsTyping(OutputParams): # noqa: D106 + inp: InputParam + + inputs: InputsTyping # type: ignore + @staticmethod - def register_inputs(inputs: Params) -> None: # noqa: D102 + def register_inputs(inputs: InputParams) -> None: # noqa: D102 inputs.declare("inp", Any) async def forward(self) -> ComponentState: # noqa: D102 @@ -40,6 +57,12 @@ async def forward(self) -> ComponentState: # noqa: D102 class Data(Component): """Data source of inf numbers.""" + # NOTE: type definition is optional, but it helps with the intellisense. ;) + class OutputsTyping(OutputParams): # noqa: D106 + out: OutputParam + + outputs: OutputsTyping # type: ignore + def __init__(self, name: str, initial_value: int = 0): super().__init__(name) self._initial_value: int = initial_value @@ -57,6 +80,16 @@ async def forward(self) -> ComponentState: # noqa: D102 class Acc(Component): """Accumulate data in a list.""" + # NOTE: type definition is optional, but it helps with the intellisense. ;) + class InputsTyping(OutputParams): # noqa: D106 + inp: InputParam + + class OutputsTyping(OutputParams): # noqa: D106 + out: OutputParam + + inputs: InputsTyping # type: ignore + outputs: OutputsTyping # type: ignore + def __init__(self, name: str, elements: int = 1): super().__init__(name) self._elements: int = elements From 98e0739c228e0c417b329f187eae15ff5df0f7ff Mon Sep 17 00:00:00 2001 From: Luis Ferraz Date: Fri, 3 Mar 2023 16:55:32 +0100 Subject: [PATCH 3/6] improve readme --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/README.md b/README.md index 63421e7..396aa34 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,57 @@ class MyApp(App): MyApp().run(1) ``` +## Component definition + +Creating your own components is pretty easy, you just need to inherit from `limbus.Component` and implement some methods (see some examples in `examples/defining_cmps.py`). + +The `Component` class has the next main methods: +- `__init__`: where you can add class parameters to your component. +- `register_inputs`: where you need to declare the input pins of your component. +- `register_outputs`: where you need to declare the output pins of your component. +- `register_properties`: where you can declare properties that can be changed during the execution. +- `forward`: where you must to define the logic of your component (mandatory). + +For a detailed list of `Component` methods and attributes, please check `limbus/core/component.py`. + +**Note** that if you want intellisense (at least in `VSCode` you will need to define the `input` and `output` types). + +Let's see a very simple example that sumns 2 integers: + +```python +class Add(Component): + """Add two numbers.""" + # NOTE: type definition is optional, but it helps with the intellisense. ;) + class InputsTyping(OutputParams): + a: InputParam + b: InputParam + + class OutputsTyping(OutputParams): + out: OutputParam + + inputs: InputsTyping + outputs: OutputsTyping + + @staticmethod + def register_inputs(inputs: InputParams) -> None: + # Here you need to declare the input parameters and their default values (if they have). + inputs.declare("a", int) + inputs.declare("b", int) + + @staticmethod + def register_outputs(outputs: OutputParams) -> None: + # Here you need to declare the output parameters. + outputs.declare("out", int) + + async def forward(self) -> ComponentState: + # Here you must to define the logic of your component. + a, b = await asyncio.gather( + self.inputs.a.receive(), + self.inputs.b.receive() + ) + await self.outputs.out.send(a + b) + return ComponentState.OK +``` ## Installation ### from PyPI: From c35367ddcb8aa4cedd5ccff3f0fe43286c053718 Mon Sep 17 00:00:00 2001 From: Luis Ferraz Date: Fri, 3 Mar 2023 16:56:08 +0100 Subject: [PATCH 4/6] increase version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index eed2a9b..5387f46 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup(name='limbus', - version='0.1.3', + version='0.1.4', description='High level interface to create Pytorch Graphs.', long_description=open('README.md').read(), long_description_content_type='text/markdown', From 78c5f6ea9ad6333fb46634a4c4eb3bcde3fc13cf Mon Sep 17 00:00:00 2001 From: Luis Ferraz Date: Fri, 3 Mar 2023 20:21:13 +0100 Subject: [PATCH 5/6] improve readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99cead7..3b39edd 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ For a detailed list of `Component` methods and attributes, please check `limbus/ **Note** that if you want intellisense (at least in `VSCode` you will need to define the `input` and `output` types). -Let's see a very simple example that sumns 2 integers: +Let's see a very simple example that sums 2 integers: ```python class Add(Component): From 73533ebfefcd5f97fefa860c3c50685bc22aa135 Mon Sep 17 00:00:00 2001 From: Luis Ferraz Date: Sat, 11 Mar 2023 23:40:52 +0100 Subject: [PATCH 6/6] grammar --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b39edd..dba858c 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ The `Component` class has the next main methods: - `register_inputs`: where you need to declare the input pins of your component. - `register_outputs`: where you need to declare the output pins of your component. - `register_properties`: where you can declare properties that can be changed during the execution. -- `forward`: where you must to define the logic of your component (mandatory). +- `forward`: where you must define the logic of your component (mandatory). For a detailed list of `Component` methods and attributes, please check `limbus/core/component.py`.