GithubHelp home page GithubHelp logo

Comments (1)

jrmlhermitte avatar jrmlhermitte commented on May 27, 2024

before doing so, I would suggest normalizing the input/output.
For ex:

class StreamDoc(dict):
    def __init__(self, *args, **kwargs):
        '''
              Normalizing inputs/outputs
              attributes : the metadata
              outputs : a dictionary of outputs
              argnames : a list of keys into dictionary of outputs of what the arguments are
              kwargnames : a list of keys into dictionary of outputs of what the kwargs are
        '''
        self['attributes'] = dict()
        self['outputs'] = dict(**kwargs)
        self['kwargnames'] = list(kwargs.keys())
        self['argnames'] = list()
        for i, arg in enumerate(args):
            key = "_arg{}".format(i)
            self['outputs'][key] = arg
            self['argnames'].append(key)
        # needed to distinguish that it is a StreamDoc by stream methods
        self['_StreamDoc'] = 'StreamDoc v1.0'
#... add methods to select/add /remove inputs/outputs, modify attributes etc

The reason why I mention this is that I think this would be coupled with the collections idea. A list of things coming from a stream could be interpreted in a few ways:

  1. ordered sequence in how to input arguments
  2. separate computations for each argument.

For example, method 1 would yield something like:

def add(a,b):
    return a + b

s1 = Stream()
s2 = s1.map(add)

s1.emit([1, 2, 'stop', 1, 3, 'stop'])
s2.sink(print)

whereas method 2 would be something like:

def add(a,b):
    return a + b

s1 = Stream()
s2 = s1.map(add)

#roughly...
s1.emit([StreamDoc(1,2), StreamDoc(1,3)])
s2.sink(print)

If adding collections, was one of these two methods in mind? Or is there another better way?
Just some thoughts. I'm inclined to go for method 2. We're currently using dask and have an object similar to that of method 2.

For method 2, putting the arguments into the function could be as simple as decorating the update routines. Something like:

def parse_streamdoc(name):
    def streamdoc_dec(f):
        def f_new(x, **kwargs_additional):
            args = list()
            for argkey in x['argnames']:
                args.append(x['outputs'][argkey])
           # same for kwargs
           kwargs.update(kwargs_additional)
           return f(*args, **kwargs)
        return f_new
    return stream_dec

etc...
we use something similar so it didn't require much time to post here (don't worry, I'm not making the assumption this library is something to depend on, but I'm hoping for it! :-) )

Anyway, I'd be happy to hear thoughts, and definitely would like to hear your insight on potential shortcomings of this approach as simply the ideas can help us on our end. (We're working on better shaping API for our experimental xray beamline)

from streamz.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.