Skip to content

Commit

Permalink
Merge pull request #92 from neuro-ml/dev
Browse files Browse the repository at this point in the history
closes #28 #91
  • Loading branch information
maxme1 authored Jun 27, 2023
2 parents d45f49c + 5bff8d5 commit d998a6c
Show file tree
Hide file tree
Showing 34 changed files with 580 additions and 406 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: '3.10'
- run: pip install -r docs/requirements.txt
- run: mkdocs gh-deploy --force
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: '3.10'

- id: get_version
name: Get the release version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [ '3.6', '3.7', '3.8', '3.9', '3.10', '3.11' ]
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11' ]

services:
redis:
Expand Down
2 changes: 1 addition & 1 deletion connectome/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.6.1'
__version__ = '0.7.0'
4 changes: 4 additions & 0 deletions connectome/cache/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MemoryCache(Cache):
def __init__(self, size: Union[int, None]):
super().__init__()
self._lock = Lock()
self.size = size
if size is not None:
self._cache = lrucache(size)
else:
Expand All @@ -31,3 +32,6 @@ def set(self, key: NodeHash, value: Any, context):
def clear(self):
with self._lock:
self._cache = {}

def __reduce__(self):
return self.__class__, (self.size,)
222 changes: 0 additions & 222 deletions connectome/containers/group.py

This file was deleted.

26 changes: 16 additions & 10 deletions connectome/engine/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from enum import Enum
from typing import Any, Collection, Dict, Generator, Iterable, NamedTuple, Optional, Sequence, Set, Tuple, Type, Union
Expand All @@ -8,6 +10,7 @@
__all__ = (
'Command', 'HashOutput', 'Request', 'Response', 'HashError',
'Edge', 'Node', 'Nodes', 'NodeSet', 'BoundEdge', 'BoundEdges', 'TreeNode', 'TreeNodes', 'Details',
'EvalGen', 'HashGen',
)


Expand All @@ -19,44 +22,47 @@ class Command(Enum):
HashOutput = Tuple[NodeHash, Any]
Request = Tuple # [RequestType, Any, ...]
Response = Union[NodeHash, Any, Tuple[NodeHash, Any]]
HashGen = Generator[Request, Response, HashOutput]
EvalGen = Generator[Request, Response, Any]


class Edge(ABC):
def __init__(self, arity: int):
self.arity = arity

@abstractmethod
def compute_hash(self) -> Generator[Request, Response, HashOutput]:
def compute_hash(self) -> HashGen:
""" Computes the hash of the output given the input hashes. """

@abstractmethod
def evaluate(self) -> Generator[Request, Response, Any]:
def evaluate(self) -> EvalGen:
""" Computes the output value. """

def hash_graph(self, inputs: NodeHashes) -> NodeHash:
""" Propagates the graph's hash without any control flow. """
# TODO: remove this check
assert len(inputs) == self.arity
return self._hash_graph(inputs)

@abstractmethod
def _hash_graph(self, inputs: NodeHashes) -> NodeHash:
""" Propagates the graph's hash without any control flow. """

def bind(self, inputs: Union['Node', 'Nodes'], output: 'Node') -> 'BoundEdge':
def bind(self, inputs: Union[Node, Nodes], output: Node) -> BoundEdge:
if isinstance(inputs, Node):
inputs = [inputs]
assert len(inputs) == self.arity, (len(inputs), self.arity)
return BoundEdge(self, inputs, output)


class Details:
def __init__(self, layer: Union[str, Type], parent: Optional['Details'] = None):
def __init__(self, layer: Union[str, Type], parent: Optional[Details] = None):
if isinstance(layer, type):
layer = layer.__name__
self.layer = layer
self.parent = parent

def update(self, mapping: Dict['Details', 'Details'], parent: Union['Details', None]):
def update(self, mapping: Dict[Details, Details], parent: Union[Details, None]):
""" Update the whole tree based on a mapping """
assert isinstance(parent, Details) or parent is None, parent
if self.parent is not None:
Expand All @@ -77,7 +83,7 @@ def __str__(self):
class TreeNode:
__slots__ = 'name', '_edge', 'details'

def __init__(self, name: str, edge: Optional[Tuple[Edge, Sequence['TreeNode']]],
def __init__(self, name: str, edge: Optional[Tuple[Edge, Sequence[TreeNode]]],
details: Union[Details, None] = None):
self.name, self._edge, self.details = name, edge, details

Expand All @@ -94,7 +100,7 @@ def parents(self):
return self._edge[1]

@classmethod
def from_edges(cls, edges: Iterable['BoundEdge']) -> Dict['Node', 'TreeNode']:
def from_edges(cls, edges: Iterable[BoundEdge]) -> Dict[Node, TreeNode]:
def update(node: Node):
if node in mapping:
return mapping[node]
Expand Down Expand Up @@ -122,13 +128,13 @@ def update(node: Node):
return mapping

@staticmethod
def to_edges(nodes: Iterable['TreeNode']) -> Sequence['BoundEdge']:
def to_edges(nodes: Iterable[TreeNode]) -> Sequence[BoundEdge]:
def reverse(node) -> Node:
if node not in _reversed:
_reversed[node] = Node(node.name, node.details)
return _reversed[node]

def visit(node: 'TreeNode'):
def visit(node: TreeNode):
if node in visited or node.is_leaf:
return
visited.add(node)
Expand Down Expand Up @@ -166,7 +172,7 @@ def __repr__(self):

class BoundEdge(NamedTuple):
edge: Edge
inputs: 'Nodes'
inputs: Nodes
output: Node


Expand Down
Loading

0 comments on commit d998a6c

Please sign in to comment.