Skip to main content

A Python-based framework for graphically integrating multiple Python algorithms

Project description

🐷 PyG: PyInGraph

A Python-based framework for graphically integrating multiple Python algorithms through a node-based computational graph system.

Overview

PyInGraph provides a flexible framework for creating and executing computational graphs where each node represents a Python algorithm block. The framework supports both local and remote module loading, making it ideal for distributed algorithm development and integration.

Features

  • Node-based Architecture: Create computational graphs using algorithm blocks as nodes
  • Remote Module Support: Load algorithm blocks from remote repositories via HTTP
  • Parameter Management: Flexible parameter loading and validation system
  • State Management: Support for stateful algorithm blocks with reset capabilities
  • NetworkX Integration: Built-in support for graph visualization and analysis
  • Time-based Simulation: Support for time-dependent algorithm execution

Installation

From Source

cd PyInGraph
pip install -e .

Dependencies

  • Python >= 3.7
  • numpy
  • matplotlib
  • networkx
  • httpimport
  • requests

Quick Start

Creating a Custom Algorithm Block

from pyingraph import BlockBase

class MyAlgorithmBlock(BlockBase):
    def __init__(self):
        super().__init__()
        self.state = 0
        self.attrNamesArr = ["gain", "offset"]  # Define required parameters
    
    def read_inputs(self, inputs: list) -> None:
        if len(inputs) != 1:
            raise ValueError("Expected exactly one input")
        self.input_value = inputs[0]
    
    def compute_outputs(self, time=None) -> list:
        self.state += 1
        result = self.input_value * self.gain + self.offset + self.state
        return [result]
    
    def reset(self) -> None:
        self.state = 0

Loading and Executing a Graph

from pyingraph import GraphLoader

# Load graph from JSON description
loader = GraphLoader("my_graph.json", flag_remote=False)
loader.load()

# Get nodes and edges
nodes = loader.get_nodes()
edges = loader.get_edges()

# Get NetworkX graph for visualization
nx_graph = loader.get_nx_graph()

Graph Description Format

Create a JSON file describing your computational graph:

{
  "nodes": [
    {
      "id": "node1",
      "name": "Input Block",
      "class_file": "my_algorithm_block.py",
      "class_name": "MyAlgorithmBlock",
      "parameters": {
        "gain": 2.0,
        "offset": 1.0
      }
    }
  ],
  "edges": [
    {
      "source_node_id": "node1",
      "target_node_id": "node2",
      "source_port_idx": 0,
      "target_port_idx": 0
    }
  ]
}

Core Components

BlockBase

The abstract base class for all algorithm blocks. Every custom block must inherit from BlockBase and implement:

  • __init__(): Initialize the block and define required parameters in attrNamesArr
  • read_inputs(inputs: list): Validate and store input values
  • compute_outputs(time: float): Perform the algorithm computation
  • reset(): Reset internal states (optional)

GraphLoader

Handles loading and instantiation of computational graphs from JSON descriptions. Supports:

  • Local module loading
  • Remote module loading via HTTP
  • Parameter validation and injection
  • NetworkX graph generation

Remote Module Support

PyInGraph supports loading algorithm blocks from remote repositories:

# Load graph with remote modules
loader = GraphLoader("http://example.com/graph.json", flag_remote=True)
loader.load()

In your JSON description, specify the remote folder URL:

{
  "nodes": [
    {
      "id": "remote_node",
      "folder_url": "http://example.com/algorithms/",
      "class_file": "remote_algorithm.py",
      "class_name": "RemoteAlgorithm",
      "parameters": {}
    }
  ]
}

Development

Running Tests

pip install -e ".[dev]"
pytest

Code Formatting

black src/
flake8 src/

API Reference

BlockBase Methods

  • read_parameters(parDict: dict): Load parameters from dictionary
  • read_inputs(inputs: list): Abstract method to read input values
  • compute_outputs(time: float): Abstract method to compute outputs
  • reset(): Abstract method to reset internal states

GraphLoader Methods

  • load(): Load and parse the graph description
  • get_nodes(): Get list of instantiated node objects
  • get_edges(): Get list of edge descriptions
  • get_nx_graph(): Get NetworkX DiGraph representation

License

MIT License - see LICENSE file for details.

Contributing

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

Support

For questions and support, please contact: bobobone@qq.com

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

pyingraph-0.1.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

pyingraph-0.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file pyingraph-0.1.0.tar.gz.

File metadata

  • Download URL: pyingraph-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyingraph-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1ae441d4ce4f0f1486343afe07ae27b7a425570e8f39ed02e1b2acc882377f6a
MD5 ecb9ea33de25271ab46062d28098be9e
BLAKE2b-256 72c666f6790030de856069750875453d38143dfb312faab0c32ca6fc41c25079

See more details on using hashes here.

File details

Details for the file pyingraph-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyingraph-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyingraph-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 582f74ba352a298b5c4a4805594762c51a336d9cca100b75c4f3bf566aa38a13
MD5 e14e4dadc82da330efca66f6a1aefdc2
BLAKE2b-256 64321493b9b0f9f9d5ddc4fc1481f21063fbc854148c03ae2d7be71fc5a9c8c6

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