Skip to content

AaravMehta-07/Poly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Poly: Universal Polyglot AI Runtime

Poly is a production-grade execution engine for AI pipelines. It allows you to mix Python, Rust, C++, and JavaScript in a single pipeline file with shared memory, automatic orchestration, and zero glue code.


The "Two-Language Problem" Solved

Most AI companies struggle with a painful split:

  • Research Team: Writes Python (PyTorch/Jupyter). Slow, hard to deploy.
  • Infra Team: Re-writes everything in C++/Rust/JS for production.

Poly eliminates this rewrite. You can keep your research logic in Python and swap out just the heavy data processing steps to Rust or C++ without rewriting the entire pipeline or wrapping everything in microservices.

Why Poly?

  1. Zero-Copy Performance: Using Apache Arrow, data is shared in memory between Python, Rust, C++, and JS. No slow JSON serialization.
  2. Infrastructure as Code: Replace 5 Docker containers and airflow DAGs with one file.
  3. True Polyglot: First-class support for 4 languages: Python (ML), Rust (Data), C++ (Compute), JavaScript (IO/Web).

Quick Start

1. Prerequisites

  • Python 3.9+
  • Dependencies: pip install click lark networkx pyarrow rich pandas numpy
  • Optional Dependencies: pip install torch (Required for GPU Hardware Awareness)

2. Run the Demo

I included a master demo that runs a mixed-language pipeline.

python -m poly.cli.main run examples\master_demo.poly

What happens?

  1. Python loads data from CSV.
  2. Rust normalizes the data (Mocked if valid DLL not found).
  3. C++ extracts features (Mocked if valid DLL not found).
  4. Python trains a model using Numpy/Pandas.
  5. JavaScript sends the model to an API (Mocked/NodeIPC).
  6. Poly saves the final result to final_out.arrow.

The Poly DSL

Write your pipelines in a .poly file. The syntax is simple: variable = namespace.function(arguments)

Namespaces

  • py.: Call Python functions.
  • rs.: Call Rust functions (via FFI).
  • cpp.: Call C++ functions (via FFI).
  • js.: Call JavaScript functions (via IPC).
  • poly.: Built-in runtime utils.

Example (pipeline.poly)

# Load data using Python
raw_data = py.load_csv("data.csv")

# Clean using Rust (High performance)
clean_data = rs.clean_dataset(raw_data)

# Train model in Python (Ecosystem)
model = py.train(clean_data)

# Save output
poly.save(model, "result.arrow")

Developing Kernels

Poly allows you to bring your own code in any supported language.

1. Python Kernel

  • Location: examples/functions.py (or any python file in your working dir).
  • How it works: Poly dynamically imports this module.
  • Signature: Functions receive generic arguments. If an argument is a data reference (Arrow file), Poly automatically loads it as an Arrow Table/RecordBatch for you? Currently: Adapters handle file paths, but Python adapter auto-converts to PyArrow Table/Pandas DataFrame.

2. Rust Kernel

  • Location: examples/rust_kernel/.
  • Compilation:
    cargo build --release
    cp target/release/poly_functions.dll functions_rs.dll
  • Signature: Must be extern "C" and accepted *const c_char.
    #[no_mangle]
    pub extern "C" fn my_func(path: *const c_char) -> *mut c_char { ... }

3. C++ Kernel

  • Location: examples/cpp_kernel/.
  • Compilation:
    g++ -shared -o functions_cpp.dll examples/cpp_kernel/functions.cpp
  • Signature:
    extern "C" __declspec(dllexport) const char* my_func(const char* input);

Architecture

Shared Memory (The "Data Bridge")

Poly uses Apache Arrow IPC (Memory Mapped Files) to pass data between languages.

  • Zero-Copy: Large datasets are not copied between processes; they are mapped into memory.
  • Type Safety: Arrow schemas ensure data consistency across Rust, C++, and Python.

Orchestrator

The core engine (poly/runtime/engine.py) builds a Directed Acyclic Graph (DAG) of your pipeline, handles topological sorting, and dispatches execution to the appropriate language adapter.


Future Roadmap

  • Docker/Kubernetes Executors.
  • WASM Adapter.
  • Visual DAG Editor.

About Me

Aarav Mehta

About

Poly is a production-grade execution engine for AI pipelines. It allows you to mix Python, Rust, C++, and JavaScript in a single pipeline file with shared memory, automatic orchestration, and zero glue code.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages