Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Preparations for releasing v1.3.0 #30

Open
wants to merge 146 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
617e577
FIX(build): py2 needs pinning networkx-2.2
ankostis Sep 28, 2019
f58d148
FIX(#13): BUG in plot-diagram writtin from PY2 era,
ankostis Sep 29, 2019
c75a2c0
doc(#13): sample code to plot workflow diagram in intro
ankostis Sep 29, 2019
a005bd6
enh(plot): provide help msg on supported file-exts
ankostis Sep 29, 2019
506be80
FEAT: +TOKEN modifier for side-effect functions
ankostis Sep 28, 2019
4e6d543
fix(func): 1-item outs broke with token modifiers...
ankostis Sep 28, 2019
62cf0a0
refact(token): undo adding of new `modifier` class...
ankostis Sep 28, 2019
47c6c1d
enh(token.TC): test 2 reversed token workflows
ankostis Sep 28, 2019
94b7291
ENH(OPTIONAL): optionals per OPERATION, not to NEEDs...
ankostis Sep 30, 2019
52c0d77
enh(test): + x2 TC breaking UNSATISFIED operations...
ankostis Sep 30, 2019
bc4c221
ENH(net,#18): ignore UN-SATISFIABLE operations with partial inputs
ankostis Sep 29, 2019
b8daa07
refact(net): drop old `dag` nx-package
ankostis Oct 1, 2019
12bdfe4
ENH(core): ORDERED SETs for DETERMINISTIC results
ankostis Oct 1, 2019
b8377ca
merge UNASTIFIABLE + ORDERED_SETs
ankostis Oct 1, 2019
489b32c
refact(net): simpilify del-instruction loop
ankostis Oct 1, 2019
b102d44
REFACT(unsatisfied): doubly-recursive func --> loop on topo-sorted
ankostis Oct 1, 2019
de02885
test(dag,#25): FAILing TC for overriding intermediate data
ankostis Oct 2, 2019
e1454fd
test(dag,#24): FAILing TC for over-pruning inetermediates when outs a…
ankostis Oct 2, 2019
3736738
MERGE (prune_unsatified, ordered_sets) into fix-pruning ...
ankostis Oct 2, 2019
c273068
DOC(net): explain DAG solution & compilation...
ankostis Oct 2, 2019
16d42f1
TEST(prune): +Failing x2 TCs multi-out must run but not...
ankostis Oct 2, 2019
b92f103
refact(dag): call compile() before compute.compute...
ankostis Oct 2, 2019
6d1884e
test(dag): +TC checking DeleteInst vary when inputs change
ankostis Oct 2, 2019
619cae7
ENH(net): move compile() after SOLVE DAG ...
ankostis Oct 2, 2019
eff351d
REFACT(NET) COMPILE+COMPUTE...
ankostis Oct 2, 2019
d959485
doc(net): explain new DAG SOLUTION
ankostis Oct 2, 2019
17eb2fd
FIX(net): new Ops invalidate execution-plan cache...
ankostis Oct 3, 2019
0830b7c
ENH(DAG): NEW SOLVER
ankostis Oct 3, 2019
32409f6
enh(build): replace numpy with pytest...
ankostis Oct 3, 2019
f606ed1
feat(build): add pip-extras [test]
ankostis Oct 3, 2019
0dc1293
WIP/FIX(prune,#26): PIN intermediate inputs if operation before must run
ankostis Oct 3, 2019
06f6554
REFACT(net): part 3 of new dag-solver & pin refactoring
ankostis Oct 4, 2019
1cc733e
enh(CI): +PY3.6 where dicts are stable
ankostis Oct 4, 2019
cd1370b
TEST(plot,ci): test plotting; pip install extras in Travis
ankostis Sep 29, 2019
f676662
fix(plot): don't create file on unsupported formats
ankostis Sep 29, 2019
65d1816
enh(plot.TC): expose supported writers and TC on them
ankostis Sep 29, 2019
d403783
WIP/FIX(PIN): PARALLEL DELs decide on PRUNED-dag (not full)...
ankostis Oct 4, 2019
64e0028
WIP/+ExecPlan class...
ankostis Oct 4, 2019
4e55b30
enh(build,ci): use pytest in travis
ankostis Oct 3, 2019
47b50f6
fix(plot): NetOp did not return pydot instance
ankostis Oct 4, 2019
b1d02a1
refact(plot): extract plot function out of Network class...
ankostis Oct 4, 2019
c11af2a
fix(plot): matplotlib plot was failing in PY3 due IO io misuse
ankostis Oct 4, 2019
344490b
FEAT(plot): overlay Execution STEPS on diagrams
ankostis Oct 5, 2019
23ef81e
ENH(plot): +inputs, +outputs, +solution modify plotting
ankostis Oct 5, 2019
4e8601c
refact(plot.TC): move plot tests to early beggining
ankostis Oct 5, 2019
834a8b0
doc(plot): tell supported formats in doctest, +TC
ankostis Oct 5, 2019
c2e28a4
doc(plot): add legend & example; docstring in netop.plot()
ankostis Oct 5, 2019
e38c8ad
enh(plot): mark optional "needs"
ankostis Oct 5, 2019
d855bf6
ENH(plot): visual enhamcents on nodes & edges
ankostis Oct 5, 2019
ca5d243
test(plot): enhance plot test to try all #13 features;
ankostis Oct 5, 2019
f25f189
test(optional): +x1 TC to check selective optionals with same out...
ankostis Oct 5, 2019
a2de9ef
doc(plot); explain also params in user-facing API
ankostis Oct 5, 2019
dc5a21a
FIX(PLOT.TC): TC was always testing PNG, ...
ankostis Oct 5, 2019
782d9b9
fix(plot): don't require Matplotlib if no Window asked
ankostis Oct 5, 2019
7d389c3
test(plot): check also matplotlib show=True
ankostis Oct 5, 2019
3fe0b40
ENH(plot): return SVG rendered in JUPYTER, ...
ankostis Oct 5, 2019
1471551
refact(plot.TC): avoid writting multiple temp-files
ankostis Oct 5, 2019
af7ae0f
MERGE PYTEST into PLOT to parametrize TCs.
ankostis Oct 5, 2019
b440196
fix(build): reuse dependencies definitions
ankostis Oct 5, 2019
bde9b64
REFACT(plot.TC): PYTESTize and parametrize
ankostis Oct 5, 2019
8e361e6
REFACT(PLOT): MOVE PLOT in own module
ankostis Oct 5, 2019
b08a363
DROP PY3.4 - add PY3.6, PY3.7...
ankostis Oct 5, 2019
3a87959
refact(plot): separate graphviz building from IO
ankostis Oct 5, 2019
17f18c2
MERGE ENHANCED-PLOTS into REFACT-ExecutionPlan to debug issues
ankostis Oct 5, 2019
4d250d3
DROP(net): list/show layers not needed, repr() is ok
ankostis Oct 5, 2019
18191e4
ENH(plot,net): +plot() on ExecPlan; +PlotMixin ...
ankostis Oct 5, 2019
7341529
enh(plan): repr()
ankostis Oct 6, 2019
231ada5
refact(plot): reorder formats-list with io
ankostis Oct 6, 2019
80f110a
FIX(plot): distinguish Del/Pin cmds; +choice utils
ankostis Oct 6, 2019
32eaa80
refact(plot): inline imports, not to cycle with base...
ankostis Oct 6, 2019
4b70cfb
refact(plot): move PlotMixin base-->plot module to group edit
ankostis Oct 6, 2019
b4fa5e0
enh(plot): +`title` arg at the bottom
ankostis Oct 6, 2019
c6f2155
FIX(plot): failing if steps not a list/ is none
ankostis Oct 6, 2019
ec69090
ENH(plan,plot): executed operations drawn as filled
ankostis Oct 6, 2019
24a3d1e
FIX(net): revived last_plan was never set (HEAD~13: 64e0028)
ankostis Oct 6, 2019
77fc887
refact(plot): reodred build-dot utils above use
ankostis Oct 6, 2019
da087df
doc(plot): move centrally all API doc on PlotMixin; Style
ankostis Oct 6, 2019
ac73bbb
FEAT(plot,plan): +yellow broken links on original graph
ankostis Oct 6, 2019
c2829a3
refact(plot): PlotMixin --> Plotter, _plotter() --> _plot()
ankostis Oct 6, 2019
c61947b
TEST(PLOT): Check also ExecPlan
ankostis Oct 6, 2019
434d4e2
REFACT(PLOT): Plotter builds dot & renders...
ankostis Oct 6, 2019
dabc787
ENH(plan.polt): CLUSTER pruned nodes
ankostis Oct 6, 2019
c5b9167
FIX(plot): VISUAL fixes & COLOR-palettes:
ankostis Oct 7, 2019
1d443ce
ENH(netop): mark all its needs as OPTIONAL
ankostis Oct 7, 2019
77bec49
FIX(NET): were FORGETTING PRUNED ASKED-OUTPUTs...
ankostis Oct 7, 2019
89e4edb
ENH(plot,TC): pipeline delegates to last_plan, if exists
ankostis Oct 7, 2019
cef7526
FIX(plot.TC): formats-TC were testing dot-file, not rendered...
ankostis Oct 7, 2019
f9b2415
enh(net): prune also isolate data
ankostis Oct 7, 2019
fce0515
FIX(<PY3.5): ORDERED DiGRAPH for old Python to fix TCs
ankostis Oct 7, 2019
d8ba34f
ENH(plot): switch oval<-->circle ops/netops
ankostis Oct 7, 2019
e8fec22
feat(plot): +legend & TC
ankostis Oct 7, 2019
7a87d61
Rebrand TOKENS --> SIDEFFECTS
ankostis Oct 7, 2019
53c6ce5
DOC(PLOT): +sample GRAPH & LEGEND into README...
ankostis Oct 7, 2019
ff754a1
DROP(plot) jupyter kw, simpler to monkeypath Dot class...
ankostis Oct 7, 2019
f787f26
FIX(plot): LEGEND mistakes, SVGize, egg graphs, ...
ankostis Oct 8, 2019
5cf7189
FIX(DOC): don't use `graph` in sample code, crash DOT, +more ...
ankostis Oct 8, 2019
7f637fe
chore(git): .gitignore plot images in root folder
ankostis Oct 8, 2019
ae01163
chore(TCs): mark SLOW tests, when in hurry, +`setup.cfg`
ankostis Oct 8, 2019
64838a5
FIX(TCs): MERGE TCs were not ASSERTING...
ankostis Oct 8, 2019
8c41066
FIX(MERGE): broken by NEW_DAG_SOLVER (#26 ...
ankostis Oct 8, 2019
6b452f7
MERGE NEW_SOLVER + PLOT --> SIDEFFECTS + OPTS in DAG
ankostis Oct 8, 2019
3e06148
FIX(sideffect.TX): old TC was not with unsatisfied in mind,
ankostis Oct 7, 2019
b515d50
FEAT(TCs): +check DOCTESTs ...
ankostis Oct 8, 2019
34543c9
fix(TCs): enable assertions in compatibility TCs
ankostis Oct 9, 2019
c104a17
FIX(func, TC): operation __repr__ fails with partial args...
ankostis Oct 9, 2019
63432f3
enh: make repr(ExecPlan) sorter
ankostis Oct 9, 2019
1ac3ac2
ENH(net): annotate OP-EXCEPTIONS with ExecPlan...
ankostis Oct 9, 2019
9d6bb92
enh(travis): pytest -v implied(~) when many test-files
ankostis Oct 9, 2019
26ea7bf
DOC: sphinx fixes and +INTERNALS section
ankostis Oct 9, 2019
6c7a3bf
fix(build): +pytest-sphinx plugin
ankostis Oct 9, 2019
fb6abf7
enh(build): set README as PyPi landing page
ankostis Oct 9, 2019
e6cd195
drop(site): rtd_theme is the default for sphinx
ankostis Oct 9, 2019
a4aed58
doc(changes): +issues in v1.2.4 (old) release by yahoo
ankostis Oct 9, 2019
35b365b
feat(site): include CHANGES sections
ankostis Oct 9, 2019
6b84122
doc(changes): +FLOWCHART dot-file for v1.2.4
ankostis Oct 9, 2019
ed1d500
doc(changes): +FLOWCHART-v1.3.0
ankostis Oct 9, 2019
554cd3e
enh(site): sphins-extlinks extension for GH-issue links
ankostis Oct 9, 2019
20fd385
chore: add myself to the authors
ankostis Oct 9, 2019
6aaa6da
DOC: update package coordinates in `setup.py`
ankostis Oct 9, 2019
b97563e
DOC(BADGES): more of them
ankostis Oct 9, 2019
ababd26
DOC(changes): v1.2.4
ankostis Oct 9, 2019
18bdb88
doc(changes): mark dates of all old pypi-releases.
ankostis Oct 9, 2019
510a9cd
chore(ver): bump version 1.2.4-->1.3.0
ankostis Oct 9, 2019
7bd3f85
minor leftovers (refact & docs)
ankostis Oct 9, 2019
df6c3ee
STYLE: BLACKen code format
ankostis Oct 9, 2019
94a7626
DOC(api): automodules
ankostis Oct 9, 2019
f68220b
enh(api): import also modifiers from base package
ankostis Oct 9, 2019
cb3297f
doc: add project coords in package __strings__
ankostis Oct 10, 2019
e67ee96
fix(TC): pytest mark xfail(PY<36) due to unstable dicts
ankostis Oct 10, 2019
ac7ec46
enh(ops): __repr__ listify needs/provides...
ankostis Oct 11, 2019
ddf9b59
enh(modifiers): no __slots__, repr() tell their class
ankostis Oct 11, 2019
6c0e15c
REVERT(#20, 94b7291): not asking edges for OPTIONALs ...
ankostis Oct 11, 2019
6ccb075
fix(op): syntax when bad parallel-method choice given
ankostis Oct 11, 2019
3089071
doc(CHANGES): backport history from GitHub-releaes
ankostis Oct 11, 2019
88c68e9
fix(doc): reorder chapters, changes at the bottom, ...
ankostis Oct 11, 2019
14edbf7
ENH(plot): show SIDEFFECTS on diagrams, MORE
ankostis Oct 11, 2019
a38826e
FIX(PyPi): +TC to check if REAME valid markdown, ...
ankostis Oct 11, 2019
01178c1
feat(build): add build.sh script because ...
ankostis Oct 11, 2019
5195714
DOC: improved Opening of the Project
ankostis Oct 11, 2019
4d1d979
fix(pytest): list test items or --ignore=setup.py not working....
ankostis Oct 11, 2019
313b241
fic(doc): CODE in README was broken unbackquoted
ankostis Oct 11, 2019
58e5112
ENH(ops): ANNNOTATE func-ERRORS with internal data,..
ankostis Oct 11, 2019
536d31b
FIX(doc): README were not PyPi-validating
ankostis Oct 11, 2019
0508558
doc(plot): explain how to reset plot to bare-bone
ankostis Oct 11, 2019
c25082e
DOC(plot): MOVE plot + debug sections to own CHAPTER
ankostis Oct 11, 2019
863c7eb
refact(doc): simplify composition.rst name
ankostis Oct 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ docs/_build/

# PyBuilder
target/

# Plots genersated when running sample code
/*.png
/*.svg
/*.pdf
24 changes: 20 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,35 @@ language: python

python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"

addons:
apt:
packages:
- graphviz


install:
- pip install Sphinx sphinx_rtd_theme codecov packaging
- pip install Sphinx codecov packaging
- "python -c $'import os, packaging.version as version\\nv = version.parse(os.environ.get(\"TRAVIS_TAG\", \"1.0\")).public\\nwith open(\"VERSION\", \"w\") as f: f.write(v)'"
- python setup.py install
- pip install -e .[test]
- cd docs
- make clean html
- cd ..

script:
- python setup.py nosetests --with-coverage --cover-package=graphkit
# OVERRIDE pytest-defaults adopted in `setup.cfg`:
#
# Run doctests in latest Python; certainly not < PY3.6 due to unstable dicts.
# Also give `-m 'slow or not slow'` since `not slow` adopted in `setup.cfg`.
- |
if [[ "$TRAVIS_PYTHON_VERSION" = '3.7' ]]; then
pytest --cov=graphkit -m 'slow or not slow'
else
pytest --cov=graphkit test/
fi

deploy:
provider: pypi
Expand Down
208 changes: 208 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#########
Changelog
#########

v1.3.0 (Oct 2019): New DAG solver, better plotting & "sideffect"
================================================================

Kept external API (hopefully) the same, but revamped pruning algorithm and
refactored network compute/compile structure, so results may change; significantly
enhanced plotting. The only new feature actually is the :class:`sideffect`` modifier.

Network:
--------

+ FIX(:gh:`18`, :gh:`26`, :gh:`29`, :gh:`17`, :gh:`20`): Revamped DAG SOLVER
to fix bad pruning described in :gh:`24` & :gh:`25`

Pruning now works by breaking incoming provide-links to any given
intermedediate inputs dropping operations with partial inputs or without outputs.

The end result is that operations in the graph that do not have all inputs satisfied,
they are skipped (in v1.2.4 they crashed).

Also started annotating edges with optional/sideffects, to make proper use of
the underlying ``networkx`` graph.

|v130-flowchart|

+ REFACT(:gh:`21`, :gh:`29`): Refactored Network and introduced :class:`ExecutionPlan` to keep
compilation results (the old ``steps`` list, plus input/output names).

Moved also the check for when to evict a value, from running the execution-plan,
to whenbuilding it; thus, execute methods don't need outputs anymore.

+ ENH(:gh:`26`): "Pin* input values that may be overriten by calculated ones.

This required the introduction of the new :class:`PinInstruction` in
the execution plan.

+ FIX(:gh:`23`, :gh:`22`-2.4.3): Keep consistent order of ``networkx.DiGraph``
and *sets*, to generate deterministic solutions.

*Unfortunately*, it non-determinism has not been fixed in < PY3.5, just
reduced the frequency of `spurious failures
<https://travis-ci.org/yahoo/graphkit/builds/594729787>`_, caused by
unstable dicts, and the use of subgraphs.

+ enh: Mark outputs produced by :class:`NetworkOperation`'s needs as ``optional``.
TODO: subgraph network-operations would not be fully functional until
*"optional outpus"* are dealt with (see :gh:`22`-2.5).

+ enh: Annotate operation exceptions with ``ExecutionPlan`` to aid debug sessions,

+ drop: methods ``list_layers()``/``show layers()`` not needed, ``repr()`` is
a better replacement.


Plotting:
---------

+ ENH(:gh:`13`, :gh:`26`, :gh:`29`): Now network remembers last plan and uses that
to overlay graphs with the internals of the planing and execution: |sample-plot|


- execution-steps & order
- delete & pin instructions
- given inputs & asked outputs
- solution values (just if they are present)
- "optional" needs & broken links during pruning

+ REFACT: Move all API doc on plotting in a single module, splitted in 2 phases,
build DOT & render DOT

+ FIX(:gh:`13`): bring plot writing into files up-to-date from PY2; do not create plot-file
if given file-extension is not supported.

+ FEAT: path `pydot library <https://pypi.org/project/pydot/>`_ to support rendering
in *Jupyter notebooks*.



Testing & other code:
---------------------

- Increased coverage from 77% --> 90%.

+ ENH(:gh:`28`): use ``pytest``, to facilitate TCs parametrization.

+ ENH(:gh:`30`): Doctest all code; enabled many assertions that were just print-outs
in v1.2.4.

+ FIX: ``operation.__repr__()`` was crashing when not all arguments
had been set - a condition frequtnly met during debugging session or failed
TCs (inspired by @syamajala's 309338340).

+ enh: Sped up parallel/multihtread TCs by reducing delays & repetitions.

.. tip::
You need ``pytest -m slow`` to run those slow tests.



Chore & Docs:
-------------

+ FEAT: add changelog in ``CHANGES.rst`` file, containing flowcharts
to compare versions ``v1.2.4 <--> v1.3..0``.
+ enh: updated site & documentation for all new features, comparing with v1.2.4.
+ enh(:gh:`30`): added "API reference' chapter.
+ drop(build): ``sphinx_rtd_theme`` library is the default theme for Sphinx now.
+ enh(build): Add ``test`` *pip extras*.
+ sound: https://www.youtube.com/watch?v=-527VazA4IQ,
https://www.youtube.com/watch?v=8J182LRi8sU&t=43s



v1.2.4 (Mar 7, 2018)
====================

+ Issues in pruning algorithm: :gh:`24`, :gh:`25`
+ Blocking bug in plotting code for Python-3.x.
+ Test-cases without assertions (just prints).

|v124-flowchart|



1.2.2 (Mar 7, 2018, @huyng): Fixed versioning
=============================================

Versioning now is manually specified to avoid bug where the version
was not being correctly reflected on pip install deployments



1.2.1 (Feb 23, 2018, @huyng): Fixed multi-threading bug and faster compute through caching of `find_necessary_steps`
====================================================================================================================

We've introduced a cache to avoid computing find_necessary_steps multiple times
during each inference call.

This has 2 benefits:

+ It reduces computation time of the compute call
+ It avoids a subtle multi-threading bug in networkx when accessing the graph
from a high number of threads.



1.2.0 (Feb 13, 2018, @huyng)
============================

Added `set_execution_method('parallel')` for execution of graphs in parallel.


1.1.0 (Nov 9, 2017, @huyng)
===========================

Update setup.py


1.0.4 (Nov 3, 2017, @huyng): Networkx 2.0 compatibility
=======================================================

Minor Bug Fixes:

+ Compatibility fix for networkx 2.0
+ `net.times` now only stores timing info from the most recent run


1.0.3 (Jan 31, 2017, @huyng): Make plotting dependencies optional
=================================================================

+ Merge pull request :gh:`6` from yahoo/plot-optional
+ make plotting dependencies optional


1.0.2 (Sep 29, 2016, @pumpikano): Merge pull request :gh:`5` from yahoo/remove-packaging-dep
============================================================================================

+ Remove 'packaging' as dependency


1.0.1 (Aug 24, 2016)
====================

1.0 (Aug 2, 2016, @robwhess)
============================

First public release in PyPi & GitHub.

+ Merge pull request :gh:`3` from robwhess/travis-build
+ Travis build


.. _substitutions:


.. |sample-plot| image:: docs/source/images/sample_plot.svg
:alt: sample graphkit plot
:width: 120px
:align: bottom
.. |v130-flowchart| image:: docs/source/images/GraphkitFlowchart-v1.3.0.svg
:alt: graphkit-v1.3.0 flowchart
:scale: 75%
.. |v124-flowchart| image:: docs/source/images/GraphkitFlowchart-v1.2.4.svg
:alt: graphkit-v1.2.4 flowchart
:scale: 75%
91 changes: 63 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,91 @@
# GraphKit

[![PyPI version](https://badge.fury.io/py/graphkit.svg)](https://badge.fury.io/py/graphkit) [![Build Status](https://travis-ci.org/yahoo/graphkit.svg?branch=master)](https://travis-ci.org/yahoo/graphkit) [![codecov](https://codecov.io/gh/yahoo/graphkit/branch/master/graph/badge.svg)](https://codecov.io/gh/yahoo/graphkit)
[![Latest version in PyPI](https://img.shields.io/pypi/v/graphkit.svg?label=PyPi%20version)](https://img.shields.io/pypi/v/graphkit.svg?label=PyPi%20version)
[![Latest version in GitHub](https://img.shields.io/github/v/release/yahoo/graphkit.svg?label=GitHub%20release&include_prereleases)](https://img.shields.io/github/v/release/yahoo/graphkit.svg?label=GitHub%20release&include_prereleases)
[![Supported Python versions of latest release in PyPi](https://img.shields.io/pypi/pyversions/graphkit.svg?label=Python)](https://img.shields.io/pypi/pyversions/graphkit.svg?label=Python)
[![Build Status](https://travis-ci.org/yahoo/graphkit.svg?branch=master)](https://travis-ci.org/yahoo/graphkit)
[![codecov](https://codecov.io/gh/yahoo/graphkit/branch/master/graph/badge.svg)](https://codecov.io/gh/yahoo/graphkit)
[![License](https://img.shields.io/pypi/l/graphkit.svg)](https://img.shields.io/pypi/l/graphkit.svg)

[![Github watchers](https://img.shields.io/github/watchers/yahoo/graphkit.svg?style=social)](https://img.shields.io/github/watchers/yahoo/graphkit.svg?style=social)
[![Github stargazers](https://img.shields.io/github/stars/yahoo/graphkit.svg?style=social)](https://img.shields.io/github/stars/yahoo/graphkit.svg?style=social)
[![Github forks](https://img.shields.io/github/forks/yahoo/graphkit.svg?style=social)](https://img.shields.io/github/forks/yahoo/graphkit.svg?style=social)
[![Issues count](http://img.shields.io/github/issues/yahoo/graphkit.svg?style=social)](http://img.shields.io/github/issues/yahoo/graphkit.svg?style=social)

[Full Documentation](https://pythonhosted.org/graphkit/)

> It's a DAG all the way down

![Sample graph](docs/source/images/test_pruning_not_overrides_given_intermediate-asked.png "Sample graph")

## Lightweight computation graphs for Python

GraphKit is a lightweight Python module for creating and running ordered graphs of computations, where the nodes of the graph correspond to computational operations, and the edges correspond to output --> input dependencies between those operations. Such graphs are useful in computer vision, machine learning, and many other domains.
GraphKit 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 might be of use in computer vision, machine learning and other data science domains,
or become the core of a custom ETL pipelne.

## Quick start

Here's how to install:

```
pip install graphkit
```
pip install graphkit

Here's a Python script with an example GraphKit computation graph that produces multiple outputs (`a * b`, `a - a * b`, and `abs(a - a * b) ** 3`):
OR with dependencies for plotting support (and you need to install [`Graphviz`](https://graphviz.org)
program separately with your OS tools):

```
from operator import mul, sub
from graphkit import compose, operation
pip install graphkit[plot]

# Computes |a|^p.
def abspow(a, p):
c = abs(a) ** p
return c
Here's a Python script with an example GraphKit computation graph that produces
multiple outputs (`a * b`, `a - a * b`, and `abs(a - a * b) ** 3`):

# Compose the mul, sub, and abspow operations into a computation graph.
graph = compose(name="graph")(
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"], params={"p": 3})(abspow)
)
>>> from operator import mul, sub
>>> from graphkit import compose, operation

# Run the graph and request all of the outputs.
out = graph({'a': 2, 'b': 5})
>>> # Computes |a|^p.
>>> def abspow(a, p):
... c = abs(a) ** p
... return c

# Prints "{'a': 2, 'a_minus_ab': -8, 'b': 5, 'ab': 10, 'abs_a_minus_ab_cubed': 512}".
print(out)
>>> # Compose the mul, sub, and abspow operations into a computation graph.
>>> graphop = compose(name="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"], params={"p": 3})(abspow)
... )

# Run the graph and request a subset of the outputs.
out = graph({'a': 2, 'b': 5}, outputs=["a_minus_ab"])
>>> # Run the graph and request all of the outputs.
>>> out = graphop({'a': 2, 'b': 5})
>>> print(out)
{'a': 2, 'b': 5, 'ab': 10, 'a_minus_ab': -8, 'abs_a_minus_ab_cubed': 512}

# Prints "{'a_minus_ab': -8}".
print(out)
```
>>> # Run the graph and request a subset of the outputs.
>>> out = graphop({'a': 2, 'b': 5}, outputs=["a_minus_ab"])
>>> print(out)
{'a_minus_ab': -8}


As you can see, any function can be used as an operation in GraphKit, even ones imported from system modules!


## Plotting

For debugging the above graph-operation you may plot the *execution plan*
of the last computation it using these methods:

```python
graphop.plot(show=True) # open a matplotlib window
graphop.plot("intro.svg") # other supported formats: png, jpg, pdf, ...
graphop.plot() # without arguments return a pydot.DOT object
graphop.plot(solution=out) # annotate graph with solution values
```

![Intro graph](docs/source/images/intro.svg "Intro graph")
![Graphkit Legend](docs/source/images/GraphkitLegend.svg "Graphkit Legend")

> **TIP:** The `pydot.Dot` instances returned by `plot()` are rendered as SVG in *Jupyter/IPython*.

# License

Code licensed under the Apache License, Version 2.0 license. See LICENSE file for terms.
6 changes: 6 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# clean, or invalid files in packages
rm -vrf ./build/* ./dist/* ./*.pyc ./*.tgz ./*.egg-info
python setup.py sdist bdist_wheel

Loading