sgn 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sgn-0.0.1/.gitignore ADDED
@@ -0,0 +1 @@
1
+ __pycache__
sgn-0.0.1/LICENSE ADDED
@@ -0,0 +1,375 @@
1
+ Copyright (c) 2024 Chad Hanna
2
+
3
+ Mozilla Public License Version 2.0
4
+ ==================================
5
+
6
+ 1. Definitions
7
+ --------------
8
+
9
+ 1.1. "Contributor"
10
+ means each individual or legal entity that creates, contributes to
11
+ the creation of, or owns Covered Software.
12
+
13
+ 1.2. "Contributor Version"
14
+ means the combination of the Contributions of others (if any) used
15
+ by a Contributor and that particular Contributor's Contribution.
16
+
17
+ 1.3. "Contribution"
18
+ means Covered Software of a particular Contributor.
19
+
20
+ 1.4. "Covered Software"
21
+ means Source Code Form to which the initial Contributor has attached
22
+ the notice in Exhibit A, the Executable Form of such Source Code
23
+ Form, and Modifications of such Source Code Form, in each case
24
+ including portions thereof.
25
+
26
+ 1.5. "Incompatible With Secondary Licenses"
27
+ means
28
+
29
+ (a) that the initial Contributor has attached the notice described
30
+ in Exhibit B to the Covered Software; or
31
+
32
+ (b) that the Covered Software was made available under the terms of
33
+ version 1.1 or earlier of the License, but not also under the
34
+ terms of a Secondary License.
35
+
36
+ 1.6. "Executable Form"
37
+ means any form of the work other than Source Code Form.
38
+
39
+ 1.7. "Larger Work"
40
+ means a work that combines Covered Software with other material, in
41
+ a separate file or files, that is not Covered Software.
42
+
43
+ 1.8. "License"
44
+ means this document.
45
+
46
+ 1.9. "Licensable"
47
+ means having the right to grant, to the maximum extent possible,
48
+ whether at the time of the initial grant or subsequently, any and
49
+ all of the rights conveyed by this License.
50
+
51
+ 1.10. "Modifications"
52
+ means any of the following:
53
+
54
+ (a) any file in Source Code Form that results from an addition to,
55
+ deletion from, or modification of the contents of Covered
56
+ Software; or
57
+
58
+ (b) any new file in Source Code Form that contains any Covered
59
+ Software.
60
+
61
+ 1.11. "Patent Claims" of a Contributor
62
+ means any patent claim(s), including without limitation, method,
63
+ process, and apparatus claims, in any patent Licensable by such
64
+ Contributor that would be infringed, but for the grant of the
65
+ License, by the making, using, selling, offering for sale, having
66
+ made, import, or transfer of either its Contributions or its
67
+ Contributor Version.
68
+
69
+ 1.12. "Secondary License"
70
+ means either the GNU General Public License, Version 2.0, the GNU
71
+ Lesser General Public License, Version 2.1, the GNU Affero General
72
+ Public License, Version 3.0, or any later versions of those
73
+ licenses.
74
+
75
+ 1.13. "Source Code Form"
76
+ means the form of the work preferred for making modifications.
77
+
78
+ 1.14. "You" (or "Your")
79
+ means an individual or a legal entity exercising rights under this
80
+ License. For legal entities, "You" includes any entity that
81
+ controls, is controlled by, or is under common control with You. For
82
+ purposes of this definition, "control" means (a) the power, direct
83
+ or indirect, to cause the direction or management of such entity,
84
+ whether by contract or otherwise, or (b) ownership of more than
85
+ fifty percent (50%) of the outstanding shares or beneficial
86
+ ownership of such entity.
87
+
88
+ 2. License Grants and Conditions
89
+ --------------------------------
90
+
91
+ 2.1. Grants
92
+
93
+ Each Contributor hereby grants You a world-wide, royalty-free,
94
+ non-exclusive license:
95
+
96
+ (a) under intellectual property rights (other than patent or trademark)
97
+ Licensable by such Contributor to use, reproduce, make available,
98
+ modify, display, perform, distribute, and otherwise exploit its
99
+ Contributions, either on an unmodified basis, with Modifications, or
100
+ as part of a Larger Work; and
101
+
102
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
103
+ for sale, have made, import, and otherwise transfer either its
104
+ Contributions or its Contributor Version.
105
+
106
+ 2.2. Effective Date
107
+
108
+ The licenses granted in Section 2.1 with respect to any Contribution
109
+ become effective for each Contribution on the date the Contributor first
110
+ distributes such Contribution.
111
+
112
+ 2.3. Limitations on Grant Scope
113
+
114
+ The licenses granted in this Section 2 are the only rights granted under
115
+ this License. No additional rights or licenses will be implied from the
116
+ distribution or licensing of Covered Software under this License.
117
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
118
+ Contributor:
119
+
120
+ (a) for any code that a Contributor has removed from Covered Software;
121
+ or
122
+
123
+ (b) for infringements caused by: (i) Your and any other third party's
124
+ modifications of Covered Software, or (ii) the combination of its
125
+ Contributions with other software (except as part of its Contributor
126
+ Version); or
127
+
128
+ (c) under Patent Claims infringed by Covered Software in the absence of
129
+ its Contributions.
130
+
131
+ This License does not grant any rights in the trademarks, service marks,
132
+ or logos of any Contributor (except as may be necessary to comply with
133
+ the notice requirements in Section 3.4).
134
+
135
+ 2.4. Subsequent Licenses
136
+
137
+ No Contributor makes additional grants as a result of Your choice to
138
+ distribute the Covered Software under a subsequent version of this
139
+ License (see Section 10.2) or under the terms of a Secondary License (if
140
+ permitted under the terms of Section 3.3).
141
+
142
+ 2.5. Representation
143
+
144
+ Each Contributor represents that the Contributor believes its
145
+ Contributions are its original creation(s) or it has sufficient rights
146
+ to grant the rights to its Contributions conveyed by this License.
147
+
148
+ 2.6. Fair Use
149
+
150
+ This License is not intended to limit any rights You have under
151
+ applicable copyright doctrines of fair use, fair dealing, or other
152
+ equivalents.
153
+
154
+ 2.7. Conditions
155
+
156
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
157
+ in Section 2.1.
158
+
159
+ 3. Responsibilities
160
+ -------------------
161
+
162
+ 3.1. Distribution of Source Form
163
+
164
+ All distribution of Covered Software in Source Code Form, including any
165
+ Modifications that You create or to which You contribute, must be under
166
+ the terms of this License. You must inform recipients that the Source
167
+ Code Form of the Covered Software is governed by the terms of this
168
+ License, and how they can obtain a copy of this License. You may not
169
+ attempt to alter or restrict the recipients' rights in the Source Code
170
+ Form.
171
+
172
+ 3.2. Distribution of Executable Form
173
+
174
+ If You distribute Covered Software in Executable Form then:
175
+
176
+ (a) such Covered Software must also be made available in Source Code
177
+ Form, as described in Section 3.1, and You must inform recipients of
178
+ the Executable Form how they can obtain a copy of such Source Code
179
+ Form by reasonable means in a timely manner, at a charge no more
180
+ than the cost of distribution to the recipient; and
181
+
182
+ (b) You may distribute such Executable Form under the terms of this
183
+ License, or sublicense it under different terms, provided that the
184
+ license for the Executable Form does not attempt to limit or alter
185
+ the recipients' rights in the Source Code Form under this License.
186
+
187
+ 3.3. Distribution of a Larger Work
188
+
189
+ You may create and distribute a Larger Work under terms of Your choice,
190
+ provided that You also comply with the requirements of this License for
191
+ the Covered Software. If the Larger Work is a combination of Covered
192
+ Software with a work governed by one or more Secondary Licenses, and the
193
+ Covered Software is not Incompatible With Secondary Licenses, this
194
+ License permits You to additionally distribute such Covered Software
195
+ under the terms of such Secondary License(s), so that the recipient of
196
+ the Larger Work may, at their option, further distribute the Covered
197
+ Software under the terms of either this License or such Secondary
198
+ License(s).
199
+
200
+ 3.4. Notices
201
+
202
+ You may not remove or alter the substance of any license notices
203
+ (including copyright notices, patent notices, disclaimers of warranty,
204
+ or limitations of liability) contained within the Source Code Form of
205
+ the Covered Software, except that You may alter any license notices to
206
+ the extent required to remedy known factual inaccuracies.
207
+
208
+ 3.5. Application of Additional Terms
209
+
210
+ You may choose to offer, and to charge a fee for, warranty, support,
211
+ indemnity or liability obligations to one or more recipients of Covered
212
+ Software. However, You may do so only on Your own behalf, and not on
213
+ behalf of any Contributor. You must make it absolutely clear that any
214
+ such warranty, support, indemnity, or liability obligation is offered by
215
+ You alone, and You hereby agree to indemnify every Contributor for any
216
+ liability incurred by such Contributor as a result of warranty, support,
217
+ indemnity or liability terms You offer. You may include additional
218
+ disclaimers of warranty and limitations of liability specific to any
219
+ jurisdiction.
220
+
221
+ 4. Inability to Comply Due to Statute or Regulation
222
+ ---------------------------------------------------
223
+
224
+ If it is impossible for You to comply with any of the terms of this
225
+ License with respect to some or all of the Covered Software due to
226
+ statute, judicial order, or regulation then You must: (a) comply with
227
+ the terms of this License to the maximum extent possible; and (b)
228
+ describe the limitations and the code they affect. Such description must
229
+ be placed in a text file included with all distributions of the Covered
230
+ Software under this License. Except to the extent prohibited by statute
231
+ or regulation, such description must be sufficiently detailed for a
232
+ recipient of ordinary skill to be able to understand it.
233
+
234
+ 5. Termination
235
+ --------------
236
+
237
+ 5.1. The rights granted under this License will terminate automatically
238
+ if You fail to comply with any of its terms. However, if You become
239
+ compliant, then the rights granted under this License from a particular
240
+ Contributor are reinstated (a) provisionally, unless and until such
241
+ Contributor explicitly and finally terminates Your grants, and (b) on an
242
+ ongoing basis, if such Contributor fails to notify You of the
243
+ non-compliance by some reasonable means prior to 60 days after You have
244
+ come back into compliance. Moreover, Your grants from a particular
245
+ Contributor are reinstated on an ongoing basis if such Contributor
246
+ notifies You of the non-compliance by some reasonable means, this is the
247
+ first time You have received notice of non-compliance with this License
248
+ from such Contributor, and You become compliant prior to 30 days after
249
+ Your receipt of the notice.
250
+
251
+ 5.2. If You initiate litigation against any entity by asserting a patent
252
+ infringement claim (excluding declaratory judgment actions,
253
+ counter-claims, and cross-claims) alleging that a Contributor Version
254
+ directly or indirectly infringes any patent, then the rights granted to
255
+ You by any and all Contributors for the Covered Software under Section
256
+ 2.1 of this License shall terminate.
257
+
258
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
259
+ end user license agreements (excluding distributors and resellers) which
260
+ have been validly granted by You or Your distributors under this License
261
+ prior to termination shall survive termination.
262
+
263
+ ************************************************************************
264
+ * *
265
+ * 6. Disclaimer of Warranty *
266
+ * ------------------------- *
267
+ * *
268
+ * Covered Software is provided under this License on an "as is" *
269
+ * basis, without warranty of any kind, either expressed, implied, or *
270
+ * statutory, including, without limitation, warranties that the *
271
+ * Covered Software is free of defects, merchantable, fit for a *
272
+ * particular purpose or non-infringing. The entire risk as to the *
273
+ * quality and performance of the Covered Software is with You. *
274
+ * Should any Covered Software prove defective in any respect, You *
275
+ * (not any Contributor) assume the cost of any necessary servicing, *
276
+ * repair, or correction. This disclaimer of warranty constitutes an *
277
+ * essential part of this License. No use of any Covered Software is *
278
+ * authorized under this License except under this disclaimer. *
279
+ * *
280
+ ************************************************************************
281
+
282
+ ************************************************************************
283
+ * *
284
+ * 7. Limitation of Liability *
285
+ * -------------------------- *
286
+ * *
287
+ * Under no circumstances and under no legal theory, whether tort *
288
+ * (including negligence), contract, or otherwise, shall any *
289
+ * Contributor, or anyone who distributes Covered Software as *
290
+ * permitted above, be liable to You for any direct, indirect, *
291
+ * special, incidental, or consequential damages of any character *
292
+ * including, without limitation, damages for lost profits, loss of *
293
+ * goodwill, work stoppage, computer failure or malfunction, or any *
294
+ * and all other commercial damages or losses, even if such party *
295
+ * shall have been informed of the possibility of such damages. This *
296
+ * limitation of liability shall not apply to liability for death or *
297
+ * personal injury resulting from such party's negligence to the *
298
+ * extent applicable law prohibits such limitation. Some *
299
+ * jurisdictions do not allow the exclusion or limitation of *
300
+ * incidental or consequential damages, so this exclusion and *
301
+ * limitation may not apply to You. *
302
+ * *
303
+ ************************************************************************
304
+
305
+ 8. Litigation
306
+ -------------
307
+
308
+ Any litigation relating to this License may be brought only in the
309
+ courts of a jurisdiction where the defendant maintains its principal
310
+ place of business and such litigation shall be governed by laws of that
311
+ jurisdiction, without reference to its conflict-of-law provisions.
312
+ Nothing in this Section shall prevent a party's ability to bring
313
+ cross-claims or counter-claims.
314
+
315
+ 9. Miscellaneous
316
+ ----------------
317
+
318
+ This License represents the complete agreement concerning the subject
319
+ matter hereof. If any provision of this License is held to be
320
+ unenforceable, such provision shall be reformed only to the extent
321
+ necessary to make it enforceable. Any law or regulation which provides
322
+ that the language of a contract shall be construed against the drafter
323
+ shall not be used to construe this License against a Contributor.
324
+
325
+ 10. Versions of the License
326
+ ---------------------------
327
+
328
+ 10.1. New Versions
329
+
330
+ Mozilla Foundation is the license steward. Except as provided in Section
331
+ 10.3, no one other than the license steward has the right to modify or
332
+ publish new versions of this License. Each version will be given a
333
+ distinguishing version number.
334
+
335
+ 10.2. Effect of New Versions
336
+
337
+ You may distribute the Covered Software under the terms of the version
338
+ of the License under which You originally received the Covered Software,
339
+ or under the terms of any subsequent version published by the license
340
+ steward.
341
+
342
+ 10.3. Modified Versions
343
+
344
+ If you create software not governed by this License, and you want to
345
+ create a new license for such software, you may create and use a
346
+ modified version of this License if you rename the license and remove
347
+ any references to the name of the license steward (except to note that
348
+ such modified license differs from this License).
349
+
350
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
351
+ Licenses
352
+
353
+ If You choose to distribute Source Code Form that is Incompatible With
354
+ Secondary Licenses under the terms of this version of the License, the
355
+ notice described in Exhibit B of this License must be attached.
356
+
357
+ Exhibit A - Source Code Form License Notice
358
+ -------------------------------------------
359
+
360
+ This Source Code Form is subject to the terms of the Mozilla Public
361
+ License, v. 2.0. If a copy of the MPL was not distributed with this
362
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
363
+
364
+ If it is not possible or desirable to put the notice in a particular
365
+ file, then You may include the notice in a location (such as a LICENSE
366
+ file in a relevant directory) where a recipient would be likely to look
367
+ for such a notice.
368
+
369
+ You may add additional accurate notices of copyright ownership.
370
+
371
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
372
+ ---------------------------------------------------------
373
+
374
+ This Source Code Form is "Incompatible With Secondary Licenses", as
375
+ defined by the Mozilla Public License, v. 2.0.
sgn-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.1
2
+ Name: sgn
3
+ Version: 0.0.1
4
+ Summary: Streaming Graph Navigator. A framework to help navigate buffers through a graph. The buffers must flow.
5
+ Home-page: https://git.ligo.org/greg/sgn
6
+ Author: Chad Hanna
7
+ Author-email: Chad Hanna <crh184@psu.edu>
8
+ Project-URL: Homepage, https://git.ligo.org/greg/sgn
9
+ Project-URL: Issues, https://git.ligo.org/greg/sgn/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+
17
+ # sgn
18
+
19
+ This is an attempt to sketch a streaming framework to replace some good aspects of gstlal.
20
+
21
+ There are the following concepts defined
22
+
23
+ - **Buffer**: An object designed to carry data through some execution graph
24
+ - **Source Pad**: An object that is designed to create a buffer when asked
25
+ - **Sink Pad**: An object that will receive a buffer when asked
26
+ - **Source Elements**: These manage the creation of buffers on one or more Pads with the assumption that they will be executed as part of a graph
27
+ - **Sink Elements**: These manage the consumption of buffers on one or more Pads with the assumption that they will be executed as part of a graph
28
+ - **Transform Elements**: These manage the consumption of buffers that immediately result in the production of new buffers.
29
+ - **Pipelines**: These manage the graph execution to pull buffers through the graph and potentially handle other events.
30
+
31
+ ## limitations
32
+
33
+ At the moment only single src / sink elements are supported for trivial linear graphs. There is a skeleton to start expanding it and it is written such that hopefully it will be possible.
34
+
35
+ ## Getting started
36
+
37
+ Clone the repo and run ```./test```
38
+
39
+ ```
40
+ e1-054675:greg-fw channa$ ./test
41
+ {'cnt': 1, 'name': 'transform'}
42
+ {'cnt': 2, 'name': 'transform'}
43
+ {'cnt': 3, 'name': 'transform'}
44
+ {'cnt': 4, 'name': 'transform'}
45
+ {'cnt': 5, 'name': 'transform'}
46
+ {'cnt': 6, 'name': 'transform'}
47
+ {'cnt': 7, 'name': 'transform'}
48
+ {'cnt': 8, 'name': 'transform'}
49
+ {'cnt': 9, 'name': 'transform'}
50
+ {'cnt': 10, 'name': 'transform'}
51
+ {'cnt': 11, 'name': 'transform'}
52
+ ...
53
+ ```
sgn-0.0.1/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # sgn
2
+
3
+ This is an attempt to sketch a streaming framework to replace some good aspects of gstlal.
4
+
5
+ There are the following concepts defined
6
+
7
+ - **Buffer**: An object designed to carry data through some execution graph
8
+ - **Source Pad**: An object that is designed to create a buffer when asked
9
+ - **Sink Pad**: An object that will receive a buffer when asked
10
+ - **Source Elements**: These manage the creation of buffers on one or more Pads with the assumption that they will be executed as part of a graph
11
+ - **Sink Elements**: These manage the consumption of buffers on one or more Pads with the assumption that they will be executed as part of a graph
12
+ - **Transform Elements**: These manage the consumption of buffers that immediately result in the production of new buffers.
13
+ - **Pipelines**: These manage the graph execution to pull buffers through the graph and potentially handle other events.
14
+
15
+ ## limitations
16
+
17
+ At the moment only single src / sink elements are supported for trivial linear graphs. There is a skeleton to start expanding it and it is written such that hopefully it will be possible.
18
+
19
+ ## Getting started
20
+
21
+ Clone the repo and run ```./test```
22
+
23
+ ```
24
+ e1-054675:greg-fw channa$ ./test
25
+ {'cnt': 1, 'name': 'transform'}
26
+ {'cnt': 2, 'name': 'transform'}
27
+ {'cnt': 3, 'name': 'transform'}
28
+ {'cnt': 4, 'name': 'transform'}
29
+ {'cnt': 5, 'name': 'transform'}
30
+ {'cnt': 6, 'name': 'transform'}
31
+ {'cnt': 7, 'name': 'transform'}
32
+ {'cnt': 8, 'name': 'transform'}
33
+ {'cnt': 9, 'name': 'transform'}
34
+ {'cnt': 10, 'name': 'transform'}
35
+ {'cnt': 11, 'name': 'transform'}
36
+ ...
37
+ ```
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=42",
4
+ "setuptools_scm[toml]>=3.4.3",
5
+ "wheel",
6
+ ]
7
+ build-backend = "setuptools.build_meta"
8
+
9
+
10
+ [project]
11
+ name = "sgn"
12
+ version = "0.0.1"
13
+ authors = [
14
+ { name="Chad Hanna", email="crh184@psu.edu" },
15
+ ]
16
+ description = "Streaming Graph Navigator. A framework to help navigate buffers through a graph. The buffers must flow."
17
+ readme = "README.md"
18
+ requires-python = ">=3.9"
19
+ classifiers = [
20
+ "Programming Language :: Python :: 3",
21
+ "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
22
+ "Operating System :: OS Independent",
23
+ ]
24
+
25
+ [project.urls]
26
+ Homepage = "https://git.ligo.org/greg/sgn"
27
+ Issues = "https://git.ligo.org/greg/sgn/issues"
sgn-0.0.1/setup.cfg ADDED
@@ -0,0 +1,37 @@
1
+ [metadata]
2
+ name = sgn
3
+ author = Chad Hanna
4
+ author_email = crh184@psu.edu
5
+ description = A framework to help navigate buffers through a graph. The buffers must flow.
6
+ long_description = file: README.md
7
+ long_description_content_type = text/markdown
8
+ url = https://git.ligo.org/greg/sgn
9
+ project_urls =
10
+ Bug Tracker = https://git.ligo.org/greg/sgn/-/issues
11
+ classifiers =
12
+ Programming Language :: Python :: 3
13
+ License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
14
+ Operating System :: OS Independent
15
+
16
+ [options]
17
+ package_dir =
18
+ = src
19
+ packages = find:
20
+ python_requires = >=3.9
21
+ include_package_data = True
22
+
23
+ [options.packages.find]
24
+ where = src
25
+
26
+ [flake8]
27
+ exclude = .git,docs,build,dist,test,*__init__.py,*_version.py, versioneer.py
28
+ max-line-length = 1000
29
+ ignore = E129 W504 W503 E203 E266
30
+
31
+ [tool:pytest]
32
+ addopts = -p no:warnings
33
+
34
+ [egg_info]
35
+ tag_build =
36
+ tag_date = 0
37
+
sgn-0.0.1/setup.py ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env python
2
+ import setuptools
3
+
4
+
5
+ if __name__ == "__main__":
6
+ setuptools.setup()
7
+
File without changes
@@ -0,0 +1,91 @@
1
+ from .. sources import *
2
+ from .. transforms import *
3
+ from .. sinks import *
4
+ import graphlib
5
+ import asyncio
6
+ import queue
7
+
8
+ class Pipeline(object):
9
+
10
+ src_elements = sources_registry
11
+ transform_elements = transforms_registry
12
+ sink_elements = sinks_registry
13
+
14
+ @initializer
15
+ def __init__(self, **kwargs):
16
+ """
17
+ Class to establish and excecute a graph of elements that will process buffers.
18
+
19
+ Registers methods to produce src, transform and sink elements and to assemble those elements
20
+ in a directed acyclic graph. Also establishes an event loop.
21
+ """
22
+ self.head = None
23
+ self.graph = {}
24
+ self.loop = asyncio.get_event_loop()
25
+ self.sources = {}
26
+ self.sinks = {}
27
+ self.transforms = {}
28
+ self.src_pads = {}
29
+ self.sink_pads = {} # FIXME populate this
30
+
31
+ for method in self.src_elements:
32
+ def _f(method = method, **kwargs):
33
+ self.head = eval("%s(**kwargs)" % method)
34
+ self.sources[self.head.name] = self.head
35
+ self.src_pads.update(self.head.src_pad_dict)
36
+ self.graph.update(self.head.graph)
37
+ return self
38
+ setattr(self, method, _f)
39
+ for method in self.transform_elements:
40
+ def _f(method = method, **kwargs):
41
+ t = eval("%s(**kwargs)" % method)
42
+ h = self.head if "src_pad_name" not in kwargs else self.src_pads[kwargs["src_pad_name"]]
43
+ t.link(h, **kwargs)
44
+ self.graph.update(t.graph)
45
+ self.head = t
46
+ self.transforms[self.head.name] = self.head
47
+ self.src_pads.update(self.head.src_pad_dict)
48
+ self.sink_pads.update(self.head.sink_pad_dict)
49
+ return self
50
+ setattr(self, method, _f)
51
+ for method in self.sink_elements:
52
+ def _f(method = method, **kwargs):
53
+ s = eval("%s(**kwargs)" % method)
54
+ h = self.head if "src_pad_name" not in kwargs else self.src_pads[kwargs["src_pad_name"]]
55
+ s.link(h, **kwargs)
56
+ self.sinks[s.name] = s
57
+ self.sink_pads.update(s.sink_pad_dict)
58
+ self.head = None
59
+ self.graph.update(s.graph)
60
+ return self
61
+ setattr(self, method, _f)
62
+
63
+ def link(self, **kwargs):
64
+ """
65
+ link a src pad to a sink pad when both are already added to this pipeline. "src_pad_name" and "sink_pad_name" are required.
66
+ """
67
+ assert "src_pad_name" in kwargs and "sink_pad_name" in kwargs
68
+ self.graph.update(self.sink_pads[kwargs["sink_pad_name"]].link(self.src_pads[kwargs["src_pad_name"]]))
69
+ return self
70
+
71
+ async def __execute_graphs(self):
72
+ # FIXME can we remove the outer while true and somehow use asyncio to schedule these in succession?
73
+ while not all(e.EOS for e in self.sinks.values()):
74
+ ts = graphlib.TopologicalSorter(self.graph)
75
+ ts.prepare()
76
+ done_nodes = queue.Queue() # blocks by default
77
+ while ts.is_active():
78
+ for node in ts.get_ready():
79
+ task = self.loop.create_task(node())
80
+ def callback(task, ts = ts, node = node, done_nodes = done_nodes):
81
+ ts.done(node)
82
+ done_nodes.put(node)
83
+ task.add_done_callback(callback)
84
+ await task
85
+ done_nodes.get() # blocks until at least one thing is done
86
+
87
+ def run(self):
88
+ """
89
+ Run the pipeline until End Of Stream (EOS)
90
+ """
91
+ return self.loop.run_until_complete(self.__execute_graphs())
@@ -0,0 +1,202 @@
1
+ from functools import wraps
2
+ import inspect
3
+
4
+ # These could be moved out someday to other modules
5
+
6
+ # From https://stackoverflow.com/questions/1389180/automatically-initialize-instance-variables
7
+ def initializer(func):
8
+ """
9
+ Automatically assigns the parameters.
10
+
11
+ >>> class process:
12
+ ... @initializer
13
+ ... def __init__(self, cmd, reachable=False, user='root'):
14
+ ... pass
15
+ >>> p = process('halt', True)
16
+ >>> p.cmd, p.reachable, p.user
17
+ ('halt', True, 'root')
18
+ """
19
+ names, varargs, keywords, defaults = inspect.getargspec(func)
20
+
21
+ @wraps(func)
22
+ def wrapper(self, *args, **kargs):
23
+ for name, arg in list(zip(names[1:], args)) + list(kargs.items()):
24
+ setattr(self, name, arg)
25
+
26
+ for name, default in zip(reversed(names), reversed(defaults or [])):
27
+ if not hasattr(self, name):
28
+ setattr(self, name, default)
29
+
30
+ func(self, *args, **kargs)
31
+
32
+ return wrapper
33
+
34
+ class Buffer(object):
35
+ """
36
+ A generic class to hold the basic unit of data that flows through a graph
37
+ """
38
+ @initializer
39
+ def __init__(self, **kwargs):
40
+ self.kwargs = kwargs
41
+ def __repr__(self):
42
+ return str(self.kwargs)
43
+
44
+ class Base(object):
45
+ """
46
+ A generic class from which all classes that participate in an execution
47
+ graph should be derived. It enforces a unique name and hashes based on that
48
+ name.
49
+ """
50
+ registry = set()
51
+
52
+ @initializer
53
+ def __init__(self, **kwargs):
54
+ """
55
+ name must be in kwargs and must not have been used by any derived class instance
56
+ """
57
+ assert "name" in kwargs
58
+ assert kwargs["name"] not in Base.registry
59
+ Base.registry.add(kwargs["name"])
60
+
61
+ def __hash__(self):
62
+ return hash(self.name)
63
+
64
+ def __eq__(self, other):
65
+ return hash(self) == hash(other)
66
+
67
+ def __repr__(self):
68
+ return self.name
69
+
70
+ class Pad(Base):
71
+ """
72
+ Pads are 1:1 with graph nodes but src and sink pads must be grouped into
73
+ elements in order to exchange data from sink->src. src->sink exchanges happen
74
+ between elements.
75
+ """
76
+ @initializer
77
+ def __init__(self, **kwargs):
78
+ """
79
+ A pad must belong to an element and that element must be provided as a
80
+ keyword argument called "element". The element must also provide a call
81
+ function that will be executed when the pad is called
82
+ """
83
+ assert "element" in kwargs and "call" in kwargs
84
+ super(Pad, self).__init__(**kwargs)
85
+
86
+
87
+ class SrcPad(Pad):
88
+ """
89
+ A pad that provides data through a buffer when asked
90
+ """
91
+ @initializer
92
+ def __init__(self, **kwargs):
93
+ super(SrcPad, self).__init__(**kwargs)
94
+
95
+ async def __call__(self):
96
+ """
97
+ When called, a source pad receives a buffer from the element that the
98
+ pad belongs to.
99
+ """
100
+ self.outbuf = self.call(pad = self)
101
+
102
+
103
+
104
+ class SinkPad(Pad):
105
+ """
106
+ A pad that receives data from a buffer when asked. When linked, it returns
107
+ a dictionary suitable for building a graph in graphlib.
108
+ """
109
+ @initializer
110
+ def __init__(self, **kwargs):
111
+ super(SinkPad, self).__init__(**kwargs)
112
+ def link(self, other):
113
+ """
114
+ Only sink pads can be linked. A sink pad can be linked to only one
115
+ source pad, but multiple sink pads may link to the same src pad.
116
+ Returns a dictionary of dependencies suitable for adding to a graphlib graph.
117
+ """
118
+ self.other = other
119
+ return {self: set((other,))}
120
+ async def __call__(self):
121
+ """
122
+ When called, a sink pad gets the buffer from the linked source pad and
123
+ then calls the element's provided call function. NOTE: pads must be called in
124
+ the correct order such that the upstream sources have new information by the
125
+ time call is invoked. This should be done within a directed acyclic graph such
126
+ as those provided by the apps.Pipeline class.
127
+ """
128
+ self.inbuf = self.other.outbuf
129
+ self.call(self, self.inbuf)
130
+
131
+ class Element(Base):
132
+ """
133
+ A basic container to hold src and sink pads. The assmption is that this
134
+ will be a base class for code that actually does something. It should never be
135
+ subclassed directly, instead subclass SrcElement, SinkElement or
136
+ TransformElement
137
+ """
138
+
139
+ @initializer
140
+ def __init__(self, **kwargs):
141
+ super(Element, self).__init__(**kwargs)
142
+ self.graph = {}
143
+ def link(self, other, **kwargs):
144
+ """
145
+ A element links to another element only on its sink pads. This function offers a few rules:
146
+
147
+ 1) If "other" is a source pad, it will be used
148
+ 2) otherwise, if "other" is an element it **must** have only one source pad
149
+ 3) you must specify a sink pad name if this element instance has more than one sink pad.
150
+
151
+ it updates the elements internal dictionary which is suitable for being
152
+ added to a graphlib graph.
153
+ """
154
+ sink_pads_by_name = {p.name:p for p in self.sink_pads}
155
+ if isinstance(other, Pad):
156
+ src_pad = other
157
+ else:
158
+ assert len(other.src_pads) == 1
159
+ src_pad = other.src_pads[0]
160
+ if "sink_pad_name" not in kwargs:
161
+ assert len(self.sink_pads) == 1
162
+ sink_pad = self.sink_pads[0]
163
+ else:
164
+ sink_pad = sink_pads_by_name[kwargs["sink_pad_name"]]
165
+ self.graph.update(sink_pad.link(src_pad))
166
+
167
+ class SrcElement(Element):
168
+ @initializer
169
+ def __init__(self, **kwargs):
170
+ """
171
+ "src_pads" (iterable) must be in kwargs. Every source pad is added to the graph with no dependencies.
172
+ """
173
+ assert "src_pads" in kwargs
174
+ super(SrcElement, self).__init__(**kwargs)
175
+ self.graph.update({s: set() for s in self.src_pads})
176
+ self.src_pad_dict = {p.name:p for p in self.src_pads}
177
+
178
+ class TransformElement(Element):
179
+ @initializer
180
+ def __init__(self, **kwargs):
181
+ """
182
+ Both "src_pads" and "sink_pads" must be in kwargs. All sink pads
183
+ depend on all source pads in a transform element. If you don't want that to be
184
+ true, write more than one transform element.
185
+ """
186
+ assert "src_pads" in kwargs and "sink_pads" in kwargs
187
+ super(TransformElement, self).__init__(**kwargs)
188
+ self.graph.update({s: set(self.sink_pads) for s in self.src_pads})
189
+ self.src_pad_dict = {p.name:p for p in self.src_pads}
190
+ self.sink_pad_dict = {p.name:p for p in self.sink_pads}
191
+
192
+
193
+ class SinkElement(Element):
194
+ @initializer
195
+ def __init__(self, **kwargs):
196
+ """
197
+ "sink_pads" must be in kwargs
198
+ """
199
+ assert "sink_pads" in kwargs
200
+ super(SinkElement, self).__init__(**kwargs)
201
+ self.graph = {}
202
+ self.sink_pad_dict = {p.name:p for p in self.sink_pads}
@@ -0,0 +1,29 @@
1
+ from ..base import *
2
+
3
+
4
+ class FakeSink(SinkElement):
5
+ @initializer
6
+ def __init__(self, **kwargs):
7
+ """
8
+ A fake sink element that has sink pads given by "channels" named
9
+ "name:channel:sink". "channels" is a required kwarg
10
+ """
11
+ kwargs["sink_pads"] = [SinkPad(name = "%s:%s:sink" % (kwargs["name"], channel), element=self, call = self.get_buffer) for channel in kwargs["channels"]]
12
+ super(FakeSink, self).__init__(**kwargs)
13
+ self.at_eos = {p:False for p in kwargs["sink_pads"]}
14
+ def get_buffer(self, pad, buf):
15
+ """
16
+ getting the buffer on the pad just modifies the name to show this final
17
+ graph point and the prints it to prove it all works.
18
+ """
19
+ self.inbuf = buf
20
+ self.at_eos[pad] = self.inbuf.EOS
21
+ print ("buffer flow: ", "%s -> '%s'" % (self.inbuf.name, pad.name))
22
+ @property
23
+ def EOS(self):
24
+ """
25
+ If buffers on any sink pads are End of Stream (EOS), then mark this whole element as EOS
26
+ """
27
+ return any(self.at_eos.values())
28
+
29
+ sinks_registry = ("FakeSink",)
@@ -0,0 +1,24 @@
1
+ from .. base import *
2
+
3
+
4
+ class FakeSrc(SrcElement):
5
+ @initializer
6
+ def __init__(self, **kwargs):
7
+ """
8
+ A fake source element "channels" are required and will be used to
9
+ create src pads with the name "name:channel:src". "num_buffers" is required and
10
+ sets how many buffers will be created before setting "EOS"
11
+ """
12
+ kwargs["src_pads"] = [SrcPad(name = "%s:%s:src" % (kwargs["name"], channel), element=self, call = self.new_buffer) for channel in kwargs["channels"]]
13
+ self.cnt = {p:0 for p in kwargs["src_pads"]}
14
+ super(FakeSrc, self).__init__(**kwargs)
15
+ def new_buffer(self, pad):
16
+ """
17
+ New buffers are created on "pad" with an instance specific count and a
18
+ name derived from the pad name. "EOS" is set if we have surpassed the requested
19
+ number of buffers.
20
+ """
21
+ self.cnt[pad] += 1
22
+ return Buffer(cnt = self.cnt, name = "'%s'" % pad.name, EOS = self.cnt[pad] > self.num_buffers)
23
+
24
+ sources_registry = ("FakeSrc",)
@@ -0,0 +1,27 @@
1
+ from .. base import *
2
+
3
+
4
+ class FakeTransform(TransformElement):
5
+ @initializer
6
+ def __init__(self, **kwargs):
7
+ """
8
+ A fake transform element with sink pads given by "in_channels" and source pads given by "out_channels". Names are "name:inchannel:sink" and "name:outchannel:src".
9
+ """
10
+ assert "in_channels" in kwargs and "out_channels" in kwargs
11
+ kwargs["src_pads"] = [SrcPad(name = "%s:%s:src" % (kwargs["name"], channel), element = self, call = self.transform_buffer) for channel in self.out_channels]
12
+ kwargs["sink_pads"] = [SinkPad(name = "%s:%s:sink" % (kwargs["name"], channel), element = self, call = self.get_buffer) for channel in self.in_channels]
13
+ super(FakeTransform, self).__init__(**kwargs)
14
+ self.inbuf = {}
15
+
16
+ def get_buffer(self, pad, buf):
17
+ self.inbuf[pad] = buf
18
+
19
+ def transform_buffer(self, pad):
20
+ """
21
+ The transform buffer just update the name to show the graph history.
22
+ Useful for proving it works. "EOS" is set if any input buffers are at EOS.
23
+ """
24
+ EOS = any(b.EOS for b in self.inbuf.values())
25
+ return Buffer(**{"cnt:%s" % b.name:b.cnt for b in self.inbuf.values()}, name = "%s -> '%s'" % ("+".join(b.name for b in self.inbuf.values()), pad.name), EOS = EOS)
26
+
27
+ transforms_registry = ("FakeTransform",)
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.1
2
+ Name: sgn
3
+ Version: 0.0.1
4
+ Summary: Streaming Graph Navigator. A framework to help navigate buffers through a graph. The buffers must flow.
5
+ Home-page: https://git.ligo.org/greg/sgn
6
+ Author: Chad Hanna
7
+ Author-email: Chad Hanna <crh184@psu.edu>
8
+ Project-URL: Homepage, https://git.ligo.org/greg/sgn
9
+ Project-URL: Issues, https://git.ligo.org/greg/sgn/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+
17
+ # sgn
18
+
19
+ This is an attempt to sketch a streaming framework to replace some good aspects of gstlal.
20
+
21
+ There are the following concepts defined
22
+
23
+ - **Buffer**: An object designed to carry data through some execution graph
24
+ - **Source Pad**: An object that is designed to create a buffer when asked
25
+ - **Sink Pad**: An object that will receive a buffer when asked
26
+ - **Source Elements**: These manage the creation of buffers on one or more Pads with the assumption that they will be executed as part of a graph
27
+ - **Sink Elements**: These manage the consumption of buffers on one or more Pads with the assumption that they will be executed as part of a graph
28
+ - **Transform Elements**: These manage the consumption of buffers that immediately result in the production of new buffers.
29
+ - **Pipelines**: These manage the graph execution to pull buffers through the graph and potentially handle other events.
30
+
31
+ ## limitations
32
+
33
+ At the moment only single src / sink elements are supported for trivial linear graphs. There is a skeleton to start expanding it and it is written such that hopefully it will be possible.
34
+
35
+ ## Getting started
36
+
37
+ Clone the repo and run ```./test```
38
+
39
+ ```
40
+ e1-054675:greg-fw channa$ ./test
41
+ {'cnt': 1, 'name': 'transform'}
42
+ {'cnt': 2, 'name': 'transform'}
43
+ {'cnt': 3, 'name': 'transform'}
44
+ {'cnt': 4, 'name': 'transform'}
45
+ {'cnt': 5, 'name': 'transform'}
46
+ {'cnt': 6, 'name': 'transform'}
47
+ {'cnt': 7, 'name': 'transform'}
48
+ {'cnt': 8, 'name': 'transform'}
49
+ {'cnt': 9, 'name': 'transform'}
50
+ {'cnt': 10, 'name': 'transform'}
51
+ {'cnt': 11, 'name': 'transform'}
52
+ ...
53
+ ```
@@ -0,0 +1,17 @@
1
+ .gitignore
2
+ LICENSE
3
+ README.md
4
+ pyproject.toml
5
+ setup.cfg
6
+ setup.py
7
+ test
8
+ src/sgn/__init__.py
9
+ src/sgn.egg-info/PKG-INFO
10
+ src/sgn.egg-info/SOURCES.txt
11
+ src/sgn.egg-info/dependency_links.txt
12
+ src/sgn.egg-info/top_level.txt
13
+ src/sgn/apps/__init__.py
14
+ src/sgn/base/__init__.py
15
+ src/sgn/sinks/__init__.py
16
+ src/sgn/sources/__init__.py
17
+ src/sgn/transforms/__init__.py
@@ -0,0 +1 @@
1
+ sgn
sgn-0.0.1/test ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env python3
2
+ from sgn.apps import Pipeline
3
+
4
+
5
+ pipeline = Pipeline()
6
+
7
+ #
8
+ # ------ ------
9
+ # | src1 | | src2 |
10
+ # ------ ------
11
+ # / \--------------- V1 | | K1
12
+ # H1 / \ L1 \ L1 | |
13
+ # ---------- ----------- ---------- ------------
14
+ # | H1trans1 | | L1trans1 | | L1trans2 | | V1K1trans1 |
15
+ # ---------- ----------- ---------- ------------
16
+ # \ / \ / /
17
+ # H1 \ / L1 L1 \ / V1 / K1
18
+ # ------ -----------
19
+ # | snk1 | | snk2 |
20
+ # ------ -----------
21
+ #
22
+
23
+
24
+ pipeline.FakeSrc(
25
+ name = "src1",
26
+ channels = ("H1","L1"),
27
+ num_buffers = 2
28
+ ).FakeTransform(
29
+ name = "H1trans1", src_pad_name = "src1:H1:src", in_channels = ("H1",), out_channels = ("H1",)
30
+ ).FakeSink(
31
+ name = "snk1",
32
+ channels = ("H1","L1"),
33
+ sink_pad_name = "snk1:H1:sink"
34
+ )
35
+
36
+ pipeline.FakeTransform(
37
+ name = "L1trans1",
38
+ src_pad_name = "src1:L1:src", in_channels = ("L1",), out_channels = ("L1",)
39
+ ).link(
40
+ src_pad_name = "L1trans1:L1:src",
41
+ sink_pad_name = "snk1:L1:sink"
42
+ )
43
+
44
+ pipeline.FakeTransform(
45
+ name = "L1trans2",
46
+ src_pad_name = "src1:L1:src",
47
+ head = "src1", in_channels = ("L1",), out_channels = ("L1",)
48
+ ).FakeSink(
49
+ name = "snk2",
50
+ channels = ("L1","V1","K1"),
51
+ sink_pad_name = "snk2:L1:sink"
52
+ )
53
+
54
+ pipeline.FakeSrc(
55
+ name = "src2",
56
+ channels = ("V1","K1"),
57
+ num_buffers = 2
58
+ ).FakeTransform(
59
+ name = "V1K1trans1", src_pad_name = "src2:V1:src", in_channels = ("V1","K1"), out_channels = ("V1","K1"), sink_pad_name = "V1K1trans1:V1:sink"
60
+ ).link(
61
+ src_pad_name = "src2:K1:src",
62
+ sink_pad_name = "V1K1trans1:K1:sink"
63
+ ).link(
64
+ src_pad_name = "V1K1trans1:K1:src",
65
+ sink_pad_name = "snk2:K1:sink"
66
+ ).link(
67
+ src_pad_name = "V1K1trans1:V1:src",
68
+ sink_pad_name = "snk2:V1:sink"
69
+ )
70
+
71
+ pipeline.run()