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