Skip to main content

Implementation of a computation graph

Project description

Pensieve

Harry Potter: "What is it?"

Albus Dumbledore: "This? It is called a Pensieve. I sometimes find, and I am sure you know the feeling, that I simply have too many thoughts and memories crammed into my mind."

Harry Potter: "Er,"

Albus Dumbledore: "I use the Pensieve. One simply siphons the excess thoughts from one's mind, pours them into the basin, and examines them at one's leisure. It becomes easier to spot patterns and links, you understand, when they are in this form."

Picture of Pensieve

Pensieve for Data

In J. K. Rowling's amazing world of magic, "a witch or wizard can extract their own or another's memories, store them in the Pensieve, and review them later. It also relieves the mind when it becomes cluttered with information. Anyone can examine the memories in the Pensieve, which also allows viewers to fully immerse themselves in the memories" 1.

Dealing with data during data wrangling and model generation in data science is like dealing with memories except that there is a lot more of back and forth and iteration when dealing with data. You constantly update parameters of your models, improve your data wrangling, and make changes to the ways you visualize or store data. As with most processes in data science, each step along the way may take a long time to finish which forces you to avoid rerunning everything from scratch; this approach is very error-prone as some of the processes depend on others. To solve this problem I came up with the idea of a Computation Graph where the nodes represent data objects and the direction of edges indicate the dependency between them.

After using Pensieve for some time myself, I have found it to be beneficial in several ways:

  • Reduces errors in data wrangling and model creation
  • Organizes data objects
  • Makes data transfer easier
  • Makes data processing more coherent
  • Facilitates the reproduction of data and models
  • Most importantly relieves the mind

Installation

pip install pensieve

Usage

from pensieve import Pensieve
pensieve = Pensieve()

Storing a Memory without Precursors

pensieve.store(key='integers', content=list(range(10)))

Storing a Memory with One Precursor

pensieve.store(
    key='odd_integers', precursors=['integers'],
    function=lambda numbers: [x for x in numbers if x%2==1]
)

Storing a Memory with More than One Precursor

pensieve.store(
    key='even_integers', 
    precursors=['integers', 'odd_integers'],
    function=lambda precursors: [
        x for x in precursors['integers'] 
        if x not in precursors['odd_integers']
    ]
)

Retrieving a Memory

pensieve['integers']
# output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

pensieve['even_integers']
# output: [0, 2, 4, 6, 8]

Changing a Memory

When you change a memory in Pensieve all successors get notified and marked as stale but not updated immediately. As soon as a successor of a changed memory is needed it will be updated based on its relationship with its precursor memories.

# changing one memory affects all successors
pensieve.store(key='integers', content=list(range(16)))
pensieve['integers']
# output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

pensieve['even_integers']
# output: [0, 2, 4, 6, 8, 10, 12, 14]

Save and Load

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

pensieve-2.0.5.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

pensieve-2.0.5-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file pensieve-2.0.5.tar.gz.

File metadata

  • Download URL: pensieve-2.0.5.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for pensieve-2.0.5.tar.gz
Algorithm Hash digest
SHA256 3bfacf858f498d01c2bdfbec88a5a010043ba5c4a1bacfb3044a5d55a7796d3f
MD5 0df61f0854e5c8b6d77368fe951986ab
BLAKE2b-256 dce6d29798cfa65bf8fe1b93722a85bbd6dd6781e90dd6cd33d3b7a454f3cf45

See more details on using hashes here.

File details

Details for the file pensieve-2.0.5-py3-none-any.whl.

File metadata

  • Download URL: pensieve-2.0.5-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for pensieve-2.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e82caee2fa3fba9c9811912389352dbf76b95742b15901b9f1ed24801f4aabad
MD5 2883c5370907c24c4bc4a45df756de7e
BLAKE2b-256 5f93eac112ec195d7dc062240a30afd334bfeab4a7a68e1880d3ee7e67cc8950

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