Skip to main content

lightweight pipeline for numerical experiments

Project description

Overview

lwpipe provides a lightweight pipeline for numerical experiments. For example, this module can be used in preprocessing steps of machine learning. Preprocessing consists of several steps, some of which take time to execute. In this case, it is common in the trial-and-error stage, such as numerical experiments, to dump the calculation results of the computationally-intensive steps and load them in the later programs to reduce the time required when the later steps are changed. This module reduces boilerplate code for file IO in the use cases above.

Note that pipelines in this module do not have the concept of dependency between nodes (tasks), and nodes are executed sequentially.

Installation

from pypi:

pip install lwpipe

Usage

Minimal example (of course, no need to use this library..):

from lwpipe import Node, Pipeline

nodes = [
    Node(func=lambda x,y: x+y, inputs=(1,2)),
    Node(func=lambda x: x**2),
]

pipe = Pipeline(nodes)
outputs = pipe.run()
assert outputs[0] == 9

Example with interim data output:

from lwpipe import Node, Pipeline
from lwpipe.io import dump_pickle, load_pickle

def time_consuming_func(x):
    return x

nodes = [
    Node(
        func=time_consuming_func,
        inputs=100,
        outputs_dumper=dump_pickle,
        outputs_path="interim_data.pickle",
        outputs_loader=load_pickle, # needed to bypass this node
    ),
    Node(func=lambda x: x**2),
]

pipe = Pipeline(nodes)
outputs = pipe.run()
assert outputs[0] == 10000

Once the first node is executed, you can bypass the node by pipe.run(1) or pipe.run("square").

Multiple outputs with numpy:

import numpy as np
from lwpipe import Node, Pipeline
from lwpipe.io import dump_npy, load_npy

def split(x):
    return x[:5], x[5:]

nodes = [
    Node(
        func=split,
        inputs=np.arange(10),
        outputs=("former", "latter"),
        outputs_dumper=dump_npy,
        outputs_path=("df1.npy", "df2.npy"),
        outputs_loader=load_npy,
    ),
    Node(
        func=lambda x: x.mean(),
        name="former_mean",
        inputs="former", # calculated at the first node
        outputs="former_mean",
    ),
    Node(
        func=lambda x: x.mean(),
        name="latter_mean",
        inputs="latter", # calculated at the first node
        outputs="latter_mean",
    ),
]

pipe = Pipeline(nodes)
outputs = pipe.run()
assert outputs[0] == 7.0
# You can access interim results by "results" dict
assert pipe.results["former_mean"] == 2.0

Example with pandas:

import io
from lwpipe import Node, Pipeline
from lwpipe.io import load_csv_as_dataframe

csv = """A,B,C
1,2,3
4,5,6
7,8,9
"""

with io.StringIO(csv) as f:
    nodes = [
        Node(
            func=lambda df: df.mean(),
            inputs=f,
            inputs_loader=load_csv_as_dataframe,
        )
    ]

    pipe = Pipeline(nodes)
    outputs = pipe.run()
    assert outputs[0].to_list() == [4.0, 5.0, 6.0]

More examples are included in the test cases.

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

lwpipe-0.1.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

lwpipe-0.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file lwpipe-0.1.0.tar.gz.

File metadata

  • Download URL: lwpipe-0.1.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for lwpipe-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0c00de93c82bed67f80d701d4432345269cb163c09167e44359482b80207b0ef
MD5 4f1121be6a5c09bb7553a9e45e4f254e
BLAKE2b-256 9d2a2e7e32f382c9b1d2c723c33d3f0470aee7f907d95905f65d7b3a8b0b2542

See more details on using hashes here.

File details

Details for the file lwpipe-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lwpipe-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for lwpipe-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e35e5cc3aaa1d6eaa788a2c75029348b1838f042c12f0e9e93568b2e5f17de8f
MD5 b73822d83947121267020d734b98ab73
BLAKE2b-256 69b009ca8197e8f224fb886c8d5ddbf53d053a66646ecf07bd16a7ff741945db

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