Skip to main content

A package for lazy evaluation and caching to optimize scientific analysis workflows.

Project description

LatenPy

LatenPy is a Python package that provides elegant lazy evaluation and computation caching with automatic dependency tracking. It's designed to help you optimize complex computational workflows by deferring expensive calculations until they're needed and caching results efficiently.

PyPI version Documentation Status Python Versions License: GPL v3 Tests codecov

Full Documentation | GitHub | PyPI

Features

  • 🦥 Lazy Evaluation: Defer computations until their results are actually needed
  • 📦 Automatic Caching: Cache computation results for reuse
  • 🔄 Dependency Tracking: Automatically track and manage computational dependencies
  • 📊 Visualization: Visualize computation graphs to understand dependencies
  • 🎯 Smart Recomputation: Only recompute results when dependencies change
  • 📝 Rich Statistics: Track computation and access patterns

Installation

pip install latenpy

Documentation

Comprehensive documentation is available at Read the Docs, including:

  • Quick Start Guide: Get up and running with basic examples
  • Core Concepts: Learn about Latent Objects, Dependency Tracking, and Caching
  • API Reference: Detailed documentation of all classes and functions
  • Advanced Usage: Topics like cache management, dependency graph analysis, and performance optimization
  • Examples: Real-world examples including scientific computing and data processing pipelines

To build the documentation locally:

cd docs
make html

The built documentation will be available in docs/build/html/index.html.

Quick Start

Here's a simple example showing how to use LatenPy:

from latenpy import latent

@latent
def expensive_calculation(x):
    return x ** 2

@latent
def complex_operation(a, b):
    return a + b

# Create lazy computations
calc1 = expensive_calculation(5)
calc2 = expensive_calculation(10)
result = complex_operation(calc1, calc2)

# Nothing is computed yet!
# Computation happens only when we call .compute()
final_result = result.compute()  # 125

Advanced Features

Dependency Visualization

LatenPy can visualize your computation graph:

from latenpy import visualize

# Visualize the computation graph
G = result.get_dependency_graph()
visualize(G)

Computation Statistics

Track detailed statistics about your computations:

# Get computation statistics
stats = result.latent_data.stats
print(stats)
# {
#     "computed": True,
#     "compute_count": 1,
#     "access_count": 1,
#     "last_compute": "2024-03-21 10:30:00",
#     "last_access": "2024-03-21 10:30:00",
#     "age": 42.0
# }

Nested Computations

LatenPy handles nested data structures automatically:

@latent
def process_list(items):
    return [x * 2 for x in items]

@latent
def sum_results(processed):
    return sum(processed)

# Works with nested structures
data = process_list([1, 2, 3])
total = sum_results(data)
result = total.compute()  # 12

Key Concepts

  • Latent Objects: Wrap functions and their arguments for lazy evaluation
  • Dependency Graph: Automatically tracks relationships between computations
  • Smart Caching: Results are cached and only recomputed when necessary
  • Computation Control: Fine-grained control over when and how computations occur

Use Cases

  • 🔬 Scientific Computing: Manage complex computational pipelines
  • 📊 Data Analysis: Optimize data processing workflows
  • 🔄 Parameter Studies: Flexibly modify inputs and track changes in results

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

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

latenpy-0.0.2.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

latenpy-0.0.2-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file latenpy-0.0.2.tar.gz.

File metadata

  • Download URL: latenpy-0.0.2.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for latenpy-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d4ff7ff70d42b9b4c944c5e80bb94c8d5fbc4d42d363c0e459b43f1d6aa90578
MD5 1ef062be0eda9f829eaf1d326e5386b5
BLAKE2b-256 2b4e6f8cbca4b1289fe90fa49bf0d10d70c7502f4372ee64a389332e20d4572f

See more details on using hashes here.

File details

Details for the file latenpy-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: latenpy-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for latenpy-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 59d76ebb0d618b16e4e807a8e554d427e4dbc74ef46c6ad113294de1cceaa3d0
MD5 3b68da65628974d37c517abad8d90191
BLAKE2b-256 e60336dd1ef7b14f793d225fd7a1cf418d2d9647377973facd129a6878d510ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page