• Stars
    star
    233
  • Rank 172,230 (Top 4 %)
  • Language
    Python
  • License
    Other
  • Created about 12 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Runtime compiler for numerical Python

Parakeet

This project is no longer being maintained.

Parakeet was a runtime accelerator for an array-oriented subset of Python. In retrospect, I don't think that whole-function type specialization at the AST level is a scalable approach to speeding up a sufficiently large subset of Python. General-purpose Python code should probably be accelerated using a bytecode JIT, whereas high-performance numerical code should use a DSL with explicit parallel operators.

Example

To accelerate a function, wrap it with Parakeet's @jit decorator:

import numpy as np 
from parakeet import jit 

alpha = 0.5
beta = 0.3
x = np.array([1,2,3])
y = np.tanh(x * alpha) + beta
   
@jit
def fast(x, alpha = 0.5, beta = 0.3):
  return np.tanh(x * alpha) + beta 
   
@jit 
def loopy(x, alpha = 0.5, beta = 0.3):
  y = np.empty_like(x, dtype = float)
  for i in xrange(len(x)):
    y[i] = np.tanh(x[i] * alpha) + beta
  return y
     
@jit
def comprehension(x, alpha = 0.5, beta = 0.3):
  return np.array([np.tanh(xi*alpha) + beta for xi in x])
  
assert np.allclose(fast(x), y)
assert np.allclose(loopy(x), y)
assert np.allclose(comprehension(x), y)

Install

You should be able to install Parakeet from its PyPI package by running:

pip install parakeet

Dependencies

Parakeet is written for Python 2.7 (sorry internet) and depends on:

The default backend (which uses OpenMP) requires gcc 4.4+.

Windows: If you have a 32-bit Windows install, your compiler should come from Cygwin or MinGW. Getting Parakeet working on 64-bit Windows is non-trivial and seems to require colossal hacks.

Mac OS X: By default, your machine probably either has only clang or an outdated version of gcc. You can get a more recent version using HomeBrew

If you want to use the CUDA backend, you need to have an NVIDIA graphics card and install both the CUDA Toolkit and PyCUDA.

How does it work?

Your untyped function gets used as a template from which multiple type specializations are generated (for each distinct set of input types). These typed functions are then churned through many optimizations before finally getting translated into native code.

More information

Supported language features

Parakeet cannot accelerate arbitrary Python code, it only supports a limited subset of the language:

  • Scalar operations (i.e. x + 3 * y)
  • Control flow (if-statements, loops, etc...)
  • Nested functions and lambdas
  • Tuples
  • Slices
  • NumPy array expressions (i.e. x[1:, :] + 2 * y[:-1, ::2])
  • Some NumPy library functions like np.ones and np.sin (look at the mappings module for a full list)
  • List literals (interpreted as array construction)
  • List comprehensions (interpreted as array comprehensions)
  • Parakeet's higher order array operations like parakeet.imap, parakeet.scan, and parakeet.allpairs

Backends

Parakeet currently supports compilation to sequential C, multi-core C with OpenMP (default), or LLVM (deprecated). To switch between these options change parakeet.config.backend to one of:

  • "openmp": compiles with gcc, parallel operators run across multiple cores (default)
  • "c": lowers all parallel operators to loops, compile sequential code with gcc
  • "cuda": launch parallel operations on the GPU (experimental)
  • "llvm": older backend, has fallen behind and some programs may not work
  • "interp" : pure Python intepreter used for debugging optimizations, only try this if you think CPython is about 10,000x too fast for your taste

More Repositories

1

fancyimpute

Multivariate imputation and matrix completion algorithms implemented in Python
Python
1,242
star
2

ocaml_llvm

Toy compiler for OCaml Meetup
OCaml
67
star
3

moving_pictures

Create a movie from a sequence of images in Python (uses PIL and ffmpeg)
Python
42
star
4

knnimpute

Python implementations of kNN imputation
Python
31
star
5

striate

Convolutional Neural Networks in Python
C++
28
star
6

shiver

A multi-threaded work queue for LLVM functions
Python
14
star
7

dsltools

Helpers for DSL construction in Python
Python
13
star
8

texture_synthesis

Repetitive pretty pictures on demand
MATLAB
11
star
9

genepool

Framework for writing evolutionary optimization algorithms in OCaml
OCaml
11
star
10

parakeet-retired

Parallelizing Runtime for Array Languages
OCaml
9
star
11

arma

Estimating ARMA model parameters using stochastic gradient descent
Python
6
star
12

adversarial-impute

Possibly ill-fated experimented with Generative Adversarial Imputation
Python
5
star
13

immuno

Predicting immunogenicity of short peptides
Python
4
star
14

censored_regression

Linear regression with lower-bound labels
Python
4
star
15

deep-learning-for-bio

Deep Learning for Biology
4
star
16

attention-in-neural-networks

Code for Miami ML meetup on Attention in Neural Networks
Jupyter Notebook
3
star
17

mhcpred

MHC Binding Prediction
Python
3
star
18

brainmets

Survival prediction for brain metastases
Python
3
star
19

bytestar

Analyze Python bytecode using an SSA control flow graph representation
Python
3
star
20

ml-experiments

Experiments with Jax, PyTorch and variable length sequence models
Jupyter Notebook
3
star
21

nnseq

Multi-sequence learning using recurrent neural networks
2
star
22

simple-somatic-variant-calling

A simple genomics "pipeline" implemented via shell scripts
Shell
2
star
23

data-experiments

Python
2
star
24

immunesearch

Search for peptide substrings in IEDB T-cell assay data
Python
1
star
25

interval

Conversion between genomic interval/coordinate systems
Python
1
star
26

vec

Simple vector expression language implemented in Python
1
star
27

image-experiments

Jupyter Notebook
1
star
28

prototype-pan-allele-class2

Prototype of a pan-allele Class II MHC binding predictor
Jupyter Notebook
1
star
29

msmhc

Looking for "dark matter" of the MHC ligandome in mass specta
Python
1
star
30

yoclo

You Only Command Line Once
Python
1
star