Skip to main content

Run Python functions on powerful cloud servers with a simple decorator

Project description

NerdMegaCompute

Run compute-intensive Python functions in the cloud with a simple decorator.

Installation

From PyPI

Install via:

pip install nerd-mega-compute

Quick Start

  1. Set up your API key: Create a .env file in your project directory with:
API_KEY=your_api_key_here
  1. Decorate your function: Use the @cloud_compute decorator to run your function in the cloud:
from nerd_megacompute import cloud_compute

@cloud_compute(cores=8)  # Specify number of CPU cores
def my_intensive_function(data):
   result = process_data(data)  # Your compute-intensive code
   return result

result = my_intensive_function(my_data)

Example

Test a simple addition:

from nerd_megacompute import cloud_compute

@cloud_compute(cores=2)
def add_numbers(a, b):
   print("Starting simple addition...")
   result = a + b
   print(f"Result: {result}")
   return result

print("Running a simple test...")
result = add_numbers(40, 2)
print(f"The answer is {result}")

Features

  • Execute intensive tasks on cloud servers
  • Scale CPU cores for faster processing
  • Automatic data transfer to/from the cloud
  • Real-time progress updates

Configuration & Parameters

API Key & Debug Mode

Configure directly in code if not using a .env file:

from nerd_megacompute import set_api_key, set_debug_mode
set_api_key('your_api_key_here')
set_debug_mode(True)

@cloud_compute Parameters

  • cores (default: 8): Number of CPU cores in the cloud.
  • timeout (default: 1800): Maximum wait time in seconds.

Library Support & Restrictions

Your code can only use Python’s standard library or the following third-party libraries:

  • numpy, scipy, pandas, matplotlib, scikit-learn, jupyter
  • statsmodels, seaborn, pillow, opencv-python, scikit-image, tensorflow
  • torch, keras, xgboost, lightgbm, sympy, networkx, plotly, bokeh
  • numba, dask, h5py, tables, openpyxl, sqlalchemy, boto3, python-dotenv, requests

Why? This ensures compatibility and security in the cloud. Unsupported libraries may cause runtime errors.

Recommendations:

  • Verify usage of supported libraries.
  • Test locally with the same constraints.
  • For additional libraries, refactor the code or contact us.

Multi-Core Usage

Guidelines

  • Single-threaded code: Multiple cores won’t speed up functions not designed for parallel execution.

    @cloud_compute(cores=8)
    def single_threaded_function(data):
      return [process_item(item) for item in data]
    
  • Parallelized code: Use multi-threading or multi-processing to utilize more cores effectively.

    from multiprocessing import Pool
    
    @cloud_compute(cores=8)
    def multi_core_function(data):
      with Pool(8) as pool:
         result = pool.map(process_item, data)
      return result
    

Supported Core Configurations

This library currently supports AWS Batch with Fargate compute environments. The number of cores must be one of the following values:

  • 1 core
  • 2 cores
  • 4 cores
  • 8 cores
  • 16 cores

Tips

  • Optimize your code for parallel execution.
  • Experiment with different cores values to balance performance.

Limitations

  • Serialization: Both the function and its data must be serializable (using Python’s pickle module). Use only serializable types:

    • Serializable: Integers, floats, strings, booleans, None, lists, tuples, dictionaries, and custom objects without non-serializable attributes.
    • Not Serializable: Nested/lambda functions, open file handles, database connections, or objects with non-serializable attributes.

    Test serialization example:

    import pickle
    
    try:
      pickle.dumps(your_function_or_data)
      print("Serializable!")
    except pickle.PickleError:
      print("Not serializable!")
    
  • Hardware Constraints: The decorator is for CPU-based tasks. For GPU tasks, consider dedicated GPU cloud services.

  • Internet Requirement: An active internet connection is needed during function execution.

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

nerd_mega_compute-0.1.27.tar.gz (32.3 kB view details)

Uploaded Source

Built Distribution

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

nerd_mega_compute-0.1.27-py3-none-any.whl (40.7 kB view details)

Uploaded Python 3

File details

Details for the file nerd_mega_compute-0.1.27.tar.gz.

File metadata

  • Download URL: nerd_mega_compute-0.1.27.tar.gz
  • Upload date:
  • Size: 32.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for nerd_mega_compute-0.1.27.tar.gz
Algorithm Hash digest
SHA256 9ade8d1e8df02f6d2a09ec89c89f7d7e04ede7c07df1622ab112754ca376dfed
MD5 2f73eb73d05e15fbb35cf76bdae1843c
BLAKE2b-256 ab7f1aeb787bd86818e34f8d4bba9f5e3d69a9d9438b1c0a02813ed49384080a

See more details on using hashes here.

File details

Details for the file nerd_mega_compute-0.1.27-py3-none-any.whl.

File metadata

File hashes

Hashes for nerd_mega_compute-0.1.27-py3-none-any.whl
Algorithm Hash digest
SHA256 7043ade0402679b0fa32e7e31ca814a498ca739400b125c9e9d4b039759d2224
MD5 45ab491c585679cbaa571f14c05a65c0
BLAKE2b-256 2a9b10c5e67b85ad038a0b0d399a09df50b52e1786a25b1f0a2980c06bf5b248

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