Giter Site home page Giter Site logo

pickfun's Introduction

PickFun

A python decorator and higher-order function for checkpointing functions. PickFun (pickle function) saves the result of a function to a checkpoint file on disk. If your program returns to the same line, it will load the result from the checkpoint file rather than running the function again.

WARNING

PickFun obtaining the result from the checkpoint file is not conditional on the function being passed the same arguments as the invocation when the checkpoint file was created. This package was designed for simple linear scripts (such as Jupyter notebooks), where looping does not occur, but system restarts can break up long running computations.

Usage

There are two ways to use pickfun.

  1. Decorate a function:

    import pickfun
    
    @pickfun.checkpoint
    def square(x):
        return x * x
    
    square(3)
  2. Call your function from a higher-order function:

    import pickfun
    pickfun.checkpoint(sum)([1, 2])

Method (1) is best if you are adding a checkpoint to your own function and you want the checkpoint active on every call to that function. Method (2) is for when you can't directly decorate a function (because it is someone eles's code and you don't want to wrap the function) or if you only want checkpoints active on a subset of the function invocations.

If either of the above examples are run twice, the first invocation will execute the called function and write a checkpoint file. A second invocation will load the previous result of the square or sum function from the checkpoint file.

Checkpoint files

The checkpoint files are written to the current working directory and are named '.<source file name>:<line number>:<function name>.ckpnt'. They are python pickle files.

Development setup

  1. git clone https://github.com/wholtz/pickfun && cd pickfun
  2. Install poetry with curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
  3. Install pyenv with curl https://pyenv.run | bash
  4. Use pyenv to install the most recent versions of Python 3.8.x and 3.9.x with pyenv install 3.8.8 && pyenv install 3.9.2 && pyenv local
  5. poetry install
  6. poetry run nox

pickfun's People

Contributors

wholtz avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.