ezmsg-org / ezmsg

Pure-Python DAG-based high-performance SHM-backed pub-sub and multi-processing pattern
https://ezmsg.readthedocs.io/en/latest/
MIT License
11 stars 5 forks source link

REQ: If `settings=` not provided to `Unit`'s `__init__`, then pass unknown *args and **kwargs to Unit's registered Settings #71

Closed cboulay closed 8 months ago

cboulay commented 9 months ago

To help with evangelizing, I would like to be able to say, "Writing the script is no more onerous than providing a yaml file containing a list of nodes with configurations and their connections. The script serves double-duty as your configuration file!"

The one hurdle to me saying that with confidence is the awkward pattern:

from ezmsg.my.proc import MyNode, MyNodeSettings

my_node = MyNode(MyNodeSettings(key1=value1, key2=value2))

I think that I can make the argument more convincingly if we didn't also need the MyNodeSettings class. i.e.,

from ezmsg.my.proc import MyNode

my_node = MyNode(key1=value1, key2=value2)

In the end, I'm hoping for something like the following:

import ezmsg.core as ez
from ezmsg.lsl.units import LSLInletUnit
from ezmsg.sigproc.butterworthfilter import ButterworthFilter
# ... other useful Units ...

def main(somepath: str = "/default/path", someswitch: str = "defualt switchvalue") -> None:
    comps = {
        "EEG_INLET": LSLInletUnit(stream_name="BrainVision RDA", stream_type="EEG"),
        "BPFILTER": ButterworthFilter(order=2, cuton=1, cutoff=70),
        # ... etc ...
    }
    ez.run(
        components=comps,
        connections=(
            (comps["EEG_INLET"].OUTPUT_SIGNAL, comps["BPFILTER"].INPUT_SIGNAL),
            (comps["BPFILTER"].OUTPUT_SIGNAL, comps["ETC"].INPUT_SIGNAL) 
        )
    )

if __name__ == "__main__":
    try:
        import typer  # instead of argparse
        typer.run(main)
    except ModuleNotFoundError:
        main()

If this can be achieved then it is no more complicated than yaml files I've seen in other BCI frameworks.

cboulay commented 8 months ago

I'll make a new issue about the .settings warnings.