Graphtik¶
(src: 3.1.0, git: v3.1.0 , Dec 06, 2019)
Lightweight computation graphs for Python¶
Graphtik is an an understandable and lightweight Python module for building and running ordered graphs of computations. The API posits a fair compromise between features and complexity, without precluding any. It can be used as is to build machine learning pipelines for data science projects. It should be extendable to act as the core for a custom ETL engine or a workflow-processor for interdependent files and processes.
Graphtik sprang from Graphkit to experiment with Python 3.6+ features.
- 1. Operations
- 2. Graph Composition
- 3. Plotting and Debugging
- 4. API Reference
- 5. Changes
- TODO
- v3.1.0 (6 Dec 2019, @ankostis): cooler
prune()
- v3.0.0 (2 Dec 2019, @ankostis): UNVARYING NetOperations, narrowed, API refact
- v2.3.0 (24 Nov 2019, @ankostis): Zoomable SVGs & more op jobs
- v2.2.0 (20 Nov 2019, @ankostis): enhance OPERATIONS & restruct their modules
- v2.1.1 (12 Nov 2019, @ankostis): global configs
- v2.1.0 (20 Oct 2019, @ankostis): DROP BW-compatible, Restruct modules/API, Plan perfect evictions
- v2.0.0b1 (15 Oct 2019, @ankostis): Rebranded as Graphtik for Python 3.6+
- v1.3.0 (Oct 2019, @ankostis): NEVER RELEASED: new DAG solver, better plotting & “sideffect”
- v1.2.4 (Mar 7, 2018)
- 1.2.2 (Mar 7, 2018, @huyng): Fixed versioning
- 1.2.1 (Feb 23, 2018, @huyng): Fixed multi-threading bug and faster compute through caching of find_necessary_steps
- 1.2.0 (Feb 13, 2018, @huyng)
- 1.1.0 (Nov 9, 2017, @huyng)
- 1.0.4 (Nov 3, 2017, @huyng): Networkx 2.0 compatibility
- 1.0.3 (Jan 31, 2017, @huyng): Make plotting dependencies optional
- 1.0.2 (Sep 29, 2016, @pumpikano): Merge pull request yahoo#5 from yahoo/remove-packaging-dep
- 1.0.1 (Aug 24, 2016)
- 1.0 (Aug 2, 2016, @robwhess)
Quick start¶
Here’s how to install:
pip install graphtik
OR with dependencies for plotting support (and you need to install Graphviz program separately with your OS tools):
pip install graphtik[plot]
Here’s a Python script with an example Graphtik computation graph that produces multiple outputs (a * b
, a - a * b
, and abs(a - a * b) ** 3
):
>>> from operator import mul, sub
>>> from functools import partial
>>> from graphtik import compose, operation
# Computes |a|^p.
>>> def abspow(a, p):
... c = abs(a) ** p
... return c
Compose the mul
, sub
, and abspow
functions into a computation graph:
>>> graphop = compose("graphop",
... operation(name="mul1", needs=["a", "b"], provides=["ab"])(mul),
... operation(name="sub1", needs=["a", "ab"], provides=["a_minus_ab"])(sub),
... operation(name="abspow1", needs=["a_minus_ab"], provides=["abs_a_minus_ab_cubed"])
... (partial(abspow, p=3))
... )
Run the graph-operation and request all of the outputs:
>>> graphop(**{'a': 2, 'b': 5})
{'a': 2, 'b': 5, 'ab': 10, 'a_minus_ab': -8, 'abs_a_minus_ab_cubed': 512}
Run the graph-operation and request a subset of the outputs:
>>> graphop.compute({'a': 2, 'b': 5}, outputs=["a_minus_ab"])
{'a_minus_ab': -8}
As you can see, any function can be used as an operation in Graphtik, even ones imported from system modules!