Skip to main content

Arcbound

Collection of tools to arrange bound methods into a graph.

Arcbound contains a series of decorators to aid data-driven programming, where the methods and properties of a class are abstracted as nodes on a graph, inter-connected by arcs (directed edges).

Installation

pip install arcbound

Usage example

import math
from typing import Tuple, Union

import arcbound as ab
import attr

@ab.graph
@attr.s(auto_attribs=True)
class QuadraticSolver(object):
    """ Calculates the solutions to a given quadratic equation.

    Input parameters:
        a: Quadratic coefficient.
        b: Linear coefficient.
        c: Constant.
    """
    a: float = 0.
    b: float = 0.
    c: float = 0.

    # Here we explicitly define the coefficient arcs.
    @property
    @ab.arcs(a="a", b="b", c="c")
    def discriminant(self, a: float, b: float, c: float) -> float:
        """ Discriminant of the quadratic equation; used to determine the
        number of roots and if they are rational.
        """
        return b * b - 4 * a * c

    # Here we use the auto_arcs decorator to automatically link to the
    # property of the same name.
    @property
    @ab.auto_arcs()
    def roots(
        self,
        a: float,
        b: float,
        discriminant: float
    ) -> Tuple[Union[float, complex], ...]:
        """ Returns the root(s) of the equation.
        """
        if discriminant == 0:
            roots = (-b / (2 * a),)

        elif discriminant > 0:
            roots = (
                (-b + math.sqrt(discriminant)) / (2 * a),
                (-b - math.sqrt(discriminant)) / (2 * a),
            )

        else:
            real = -b / (2 * a)
            imag = math.sqrt(-discriminant) / (2 * a)
            roots = (
                complex(real, imag),
                complex(real, -imag)
            )

        return roots

    # Since this property is not decorated with an arcbound decorator, a node
    # is not generated on the arcbound_graph.
    @property
    def number_of_roots(self) -> int:
        """ Returns the number of roots.
        """
        discriminant = self.discriminant

        return (
            1 if discriminant == 0. else
            2
        )


quad_solver = QuadraticSolver(a=1, b=4, c=3)

quad_solver.roots
# (-1,0, -3.0)

# Create a function that solves for the discriminant of a quadratic equation.
# Retains the defaults of a=1, b=4, and c=3 from the quad_solver object.
discriminant_solver = quad_solver.get_arcbound_node("discriminant")
discriminant_solver(a=2, b=4)
# -8

quad_solver.visualize_arcbound_graph()

arcbound_graph

Metadata

Release files for arcbound 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for arcbound 0.0.5
File Size Uploaded
arcbound-0.0.5.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for arcbound 0.0.5
File Interpreter ABI Platform
arcbound-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 30.1 kB

Release files / arcbound-0.0.5.tar.gz

Download URL arcbound-0.0.5.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
29dbde949fca4b1a24ae38fd6f4eb1aa4e33b23393cabe0fc965677a86446104
BLAKE2b-256 checksum
How to use checksums
a3faf858f8b84a5803645eb0a5e6e2515cad6c216b483e7f39a8731c1e75ed89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

Release files / arcbound-0.0.5-py3-none-any.whl

Download URL arcbound-0.0.5-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5ff551d0ff5d91a56029cd787d8e8620ec36b066b72c939fc21fc801c188ef4
BLAKE2b-256 checksum
How to use checksums
6ede9a20a9222c20fe806c59e0e1bf79fbb98248c62216d36dfaca8aea990c24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page