Skip to main content

Manage, maintain and reuse complex function graphs without the hassle.

Project description

Fn Graph

Manage, maintain and reuse complex function graphs without the hassle.

Installation

pip install fn_graph

Outline of the problem

In complex domains, like financial modelling or data-science, modellers and programmers often have complex logic that needs to be re-used in multiple environments. For example a financial analyst may write a model in a notebook, which then must be placed in a production environment (normally through rewriting the notebook which was not written in a modular or easy to use manner), after which changes need to made, which must be done in the notebook environment, which then need to be moved back into production. This is the stuff of nightmare fuel for everyone involved.

To make this process easier the best option is to break functionality into small reusable functions, that can be referenced in both the notebook environment and the production environment. Now you unfortunately you have this bag of small functions whose relationships you have to manage. There are few ways to do this. Assume we have the functions below:

def get_a():
    return 5

def get_b(a):
    return a * 5

def get_c(a, b):
    return a * b

Option 1 - Directly compose at call site:

a = get_a()
b = get_b(a)
c = get_c(a, b)

Pros: The modeller can easily see intermediate results
Cons: Now this potentially complex network of function calls has to be copied and pasted between notebooks and production

Option 2 - Wrap it up in a function that pass around

def composed_c():
    a = get_a()
    b = get_b(a)
    return  get_c(a, b)

Pros: This is easy to reference from both the notebook and production
Cons: The modeller cannot see the intermediate results, so it can be difficult to debug (this is a big problem if you are working with big multi-dimensional objects that you may want to visualize, a debugger does not cut it)

Option 3 - Directly call functions from each other

def get_a():
    return 5

def get_b(a):
    return get_a() * 5

def get_c():
    return get_a() * get_b()

Pros: This is easy to reference from both the notebook and production
Cons: The modeller cannot see the intermediate results and functions cannot be reused.

None of these are great. Fn Graph would solve it like this.

from fn_graph import Composer

def a():
    return 5

def b(a):
    return a * 5

def c(a, b):
    return a * b

composer = Composer().update(a, b, c)

# Call any result
composer.c() # 125
composer.a() # 5

composer.graphviz()

Graph of composer

The composer can then be easily passed around in both the production and notebook environment. It can do much more than this.

Features

  • Manage complex function graphs, including using namespaces.
  • Update composers to gradually build more and more complex logic.
  • Enable incredible function reuse.
  • Visualize logic to make knowledge sharing easier.
  • Perform graph operations on composers to dynamically rewire your logic
  • Manage calculation life cycle, with hooks, and have access to all intermediary calculations.
  • Cache results, either within a single session, or between sessions in development mode. Using the development cache intelligently invalidate the cache when code changes .

Similar projects

Dask

Dask is a light-weight parallel computing library. Importantly it has a Pandas compliant interface. You may want to use Dask inside FnGraph.

Airflow

Airflow is a task manager. It is used to run a series of generally large tasks in an order that meets their dependencies, potentially over multiple machines. It has a whole scheduling and management apparatus around it. Fn Graph is not trying to do this. Fn Graph is about making complex logic more manageable, and easier to move between development and production. You may well want to use Fn Graph inside your airflow tasks.

Luigi

Luigi is a Python module that helps you build complex pipelines of batch jobs. It handles dependency resolution, workflow management, visualization etc. It also comes with Hadoop support built in.

Luigi is about big batch jobs, and managing the distribution and scheduling of them. In the same way that airflow works ate a higher level to FnGraph, so does luigi.

d6tflow

d6tflow is very similar to FnGraph. It is based on Luigi. The primary difference is the way the function graphs are composed. d6tflow graphs can be very difficult to reuse (but do have some greater flexibility). It also allows for parallel execution. FnGraph is trying to make very complex pipelines or very complex models easier to mange, build, and productionise.

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

fn_graph-0.1.2.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fn_graph-0.1.2-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file fn_graph-0.1.2.tar.gz.

File metadata

  • Download URL: fn_graph-0.1.2.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.5 Linux/4.15.0-72-generic

File hashes

Hashes for fn_graph-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7a86f9bfd6dcb235b049e475358d63b18661dbbaf28fa90a364983adbbc773c2
MD5 cd05837513a5e80e52c17470fe64efec
BLAKE2b-256 28211e2edd167fb5b23ea9018f6d85ece2b67e47f63f6f92b4f7a8aa18c8c961

See more details on using hashes here.

File details

Details for the file fn_graph-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fn_graph-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.5 Linux/4.15.0-72-generic

File hashes

Hashes for fn_graph-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2c2c2df72e070f76deaa83fbcf35f91e8bc6243c2bb770507eefa2af401650f0
MD5 4c73bd2021a4c6e03feb56309bc0ef74
BLAKE2b-256 4afb04867b78a14c97114666cfd0d6b06104e2148cdecdc543f3f649cfe37523

See more details on using hashes here.

Supported by

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