Skip to main content

A framework for building MLOps pipelines

Project description

Anacostia

Welcome to Anacostia. Anacostia is a framework for creating machine learning operations (MLOps) pipelines. I believe the process of creating MLOps pipelines today are too difficult; thus, this is my attempt at simplifying the entire process.

Notes for contributors and developers

If you are interested in contributing to Anacostia, please see CONTRIBUTORS.md. If you are interested in building your own plugins for Anacostia and contributing to the Anacostia ecosystem, please see DEVELOPERS.md.

Basic Anacostia Concepts & Terminology:

Anacostia works by allowing you to define a pipeline as a directed acyclic graph (DAG). Each node in the DAG is nothing more than a continuously running thread that does the following:

  1. Waits for enough data to become available in a resource or waits for signals received from other nodes.
  2. Executes a job.
  3. Sends a signal to another node upon completion of its job.

The edges of the DAG dictates which child nodes are listening for signals from which parent nodes.

There are fundamentally three types of nodes in Anacostia:

  1. Metadata store nodes: stores tracking information about each time the pipeline executes (i.e., a run).
    • The metadata store is responsible for storing information like the start/end time of the run, metadata information about all the nodes in the pipeline, etc.
  2. Resource nodes: think of a "resource" as the inputs and outputs of your pipeline.
    • A resource can be a folder on a local filesystem, an S3 bucket, an API endpoint, a database, etc.
    • An "input resource" is a resource that is monitored for changes. When there is enough data in the input resource, it triggers the pipeline to start executing.
    • An "output resource" is a resource that is not monitored for changes. This is a resource that stores artifacts produced by the pipeline.
    • The data in each resource resides only in that resource, it is never moved to another resource.
    • Other nodes can interact with the data in that resource via calls to its API.
  3. Action nodes: executes a job in your pipeline. Examples of jobs include tasks like: data preprocessing, retraining a model on new data, evaluating a model on new data, etc.

Every node in Anacostia is inherited from these three basic nodes.

A couple things that distinguish Anacostia from other MLOps solutions:

  1. Anacostia is meant to be ran locally. Of course you can run an Anacostia Pipeline in the cloud, but it is designed to be ran locally.
  2. Pipelines in Anacostia can be built incrementally. Start with building the simplest pipeline possible; just one metadata store node, one input resource node, and one action node; e.g., an alerting system that monitors a resource and then sends an email notification whenever there is a certain amount of data available. From there, add in an output resource node to build something like a data preprocessing pipeline and then add in more nodes for retraining and evaluation to create a model retraining pipeline.
  3. Because every node in the Anacostia ecosystem derives from one of the three base nodes, Anacostia provides a format for a common API; thus, allowing for users to swap one node out for another node. This is great for experimentation and evaluating different solutions for your pipeline (e.g., swap out a sqlite metadata store for a redis metadata store).

Installation

Requirements: Python 3.11 or greater, if you need to update Python, see CONTRIBUTORS.md

pip install anacostia-pipeline

Example Usage

  1. Put the following python code inside a python file.
  2. Name the file simplest_test.py (there is no reason you cannot name the file something else, but for the sake of simplicity, just name it simplest_test.py).
  3. Run it in terminal like so: python simplest_test.py.
import os
import logging
import shutil
from typing import List

from anacostia_pipeline.nodes.metadata.node import BaseMetadataStoreNode
from anacostia_pipeline.nodes.node import BaseNode
from anacostia_pipeline.nodes.actions.node import BaseActionNode

from anacostia_pipeline.pipelines.root.pipeline import RootPipeline
from anacostia_pipeline.pipelines.root.server import RootPipelineServer

from anacostia_pipeline.nodes.resources.filesystem.node import FilesystemStoreNode
from anacostia_pipeline.nodes.metadata.sqlite.node import SqliteMetadataStoreNode



logging_tests_path = "./testing_artifacts/logging_tests"
if os.path.exists(logging_tests_path) is True:
    shutil.rmtree(logging_tests_path)
os.makedirs(logging_tests_path)

log_path = f"{logging_tests_path}/anacostia.log"
logging.basicConfig(
    level=logging.DEBUG,
    format='%(asctime)s - %(levelname)s - %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S',
    filename=log_path,
    filemode='a'
)
logger = logging.getLogger(__name__)


metadata_store_path = f"{logging_tests_path}/metadata_store"
data_store_path = f"{logging_tests_path}/data_store"


class MonitoringDataStoreNode(FilesystemStoreNode):
    def __init__(
        self, name: str, resource_path: str, metadata_store: BaseMetadataStoreNode, 
        init_state: str = "new", max_old_samples: int = None
    ) -> None:
        super().__init__(name, resource_path, metadata_store, init_state, max_old_samples)

class LoggingNode(BaseActionNode):
    def __init__(
        self, name: str, metadata_store: BaseMetadataStoreNode, predecessors: List[BaseNode] = None
    ) -> None:
        super().__init__(name=name, predecessors=predecessors, wait_for_connection=True)
        self.metadata_store = metadata_store
    
    async def execute(self, *args, **kwargs) -> bool:
        self.log("Logging node executed", level="INFO")
        return True

metadata_store = SqliteMetadataStoreNode(name="metadata_store", uri=f"{metadata_store_path}/metadata.db")
data_store = MonitoringDataStoreNode("data_store", data_store_path, metadata_store)
logging_node = LoggingNode("logging_node", metadata_store=metadata_store, predecessors=[data_store])

pipeline = RootPipeline(nodes=[metadata_store, data_store, logging_node], loggers=logger)

if __name__ == "__main__":
    webserver = RootPipelineServer(name="test_pipeline", pipeline=pipeline, host="127.0.0.1", port=8000, logger=logger)
    webserver.run()

To trigger the pipeline:

  1. Put the following code inside another python file.
  2. Name the file create_files.py (again, there is no reason you cannot name the file something else, but for the sake of simplicity, just name it create_files.py).
  3. Open up a new terminal and run the file like so: python create_files.py.
import time

logging_tests_path = "./testing_artifacts/logging_tests"
data_store_path = f"{logging_tests_path}/data_store"

def create_file(file_path, content):
    try:
        with open(file_path, 'w') as file:
            file.write(content)
        print(f"File '{file_path}' created successfully.")
    except Exception as e:
        print(f"Error creating the file: {e}")

for i in range(10):
    create_file(f"{data_store_path}/test_file{i}.txt", f"test file {i}")
    time.sleep(1.5)

To view the pipeline executing:

  1. Open your browser (preferably Chrome) and navigate to http://127.0.0.1:8000

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

anacostia_pipeline-0.4.1.tar.gz (435.8 kB view details)

Uploaded Source

Built Distribution

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

anacostia_pipeline-0.4.1-py3-none-any.whl (447.3 kB view details)

Uploaded Python 3

File details

Details for the file anacostia_pipeline-0.4.1.tar.gz.

File metadata

  • Download URL: anacostia_pipeline-0.4.1.tar.gz
  • Upload date:
  • Size: 435.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for anacostia_pipeline-0.4.1.tar.gz
Algorithm Hash digest
SHA256 be98497c47824e42e63f1c33946fe7375279a516d4e2820101236bccf20cf7fa
MD5 ba0b96ec376e3b8d1e152849ec618332
BLAKE2b-256 d22b330690e3fbc9a84bb9eef1ad391bc4918c8e8601c5ee7f8c0c5015e10634

See more details on using hashes here.

File details

Details for the file anacostia_pipeline-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for anacostia_pipeline-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bd0f6f0a82f60581a13341c5345268ee48e7c99c29bcfa23530adbfd89c85f51
MD5 5cec5b10cde08b7582f5579b9c02a9bc
BLAKE2b-256 b3e057543225005d38dd424a4112e33e03fbf406e6d34e886854ca584aa9f24f

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