Skip to main content

A computation graph micro-framework providing seamless lazy and concurrent evaluation.

Project description

Overview

othoz-paragraph is a pure Python micro-framework supporting seamless lazy and concurrent evaluation of computation graphs.

In essence, the package allows to write functional code directly in Python: statements merely specify relationships among variables through operations. Evaluation of any variable given the values of other variables is then de facto:

  • lazy: only operations participating in the determination of the requested value are executed,

  • concurrent: operations can be executed by a thread pool of arbitrary size.

In addition, relationships among variables can be traversed in both directions, allowing a form of backpropagation of information through the computation network that would be cumbersome to implement in an imperative manner.

A glossary is provided below, which should clarify most concepts implemented in this module. Note that the usage of some terms may slightly differ from their standard definitions, reading it through before diving into the code is therefore highly recommended irrespective of the reader’s familiarity with the topic.

Getting started

Computation graphs are bipartite graphs, where vertices of a one type, the variables (of type Variable), are connected together exclusively through vertices of another type, the operations (or simply ops, of type Op).

In paragraph, turning a regular Python function into an op is as simple as decorating it:

>>> @op
... def f(a, b):
...     return a * b

The operation can then be applied to objects of both Variable and non-Variable type as follows:

>>> v1 = Variable("v1")
>>> v2 = f(2, v1)

Ops differ from regular Python functions in their behavior upon receiving an argument of type Variable. In such a case, they are not executed, but instead pack the knowledge required for deferred execution into an instance of Variable, and return this variable. Then, a variable can be evaluated by invoking the function paragraph.session.evaluate and passing in initialization values for the input variables alongside the target variable:

>>> value = evaluate([v2], args={v1: 4})

Going further

For more information please consult the documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paragraph-1.0.0a2.tar.gz (27.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page