-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/fast-hierarchical
- Loading branch information
Showing
33 changed files
with
644 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
MB__BATCH_SIZE=250_000 | ||
MB__BACKEND_TYPE=postgres | ||
MB__DATASETS_CONFIG=datasets.toml | ||
|
||
MB__POSTGRES__HOST=matchbox-postgres | ||
MB__POSTGRES__PORT=5432 | ||
MB__POSTGRES__USER=matchbox_user | ||
MB__POSTGRES__PASSWORD=matchbox_password | ||
MB__POSTGRES__DATABASE=matchbox | ||
MB__POSTGRES__DB_SCHEMA=mb | ||
|
||
API__ROOT=http://localhost:8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
MB__BATCH_SIZE=250_000 | ||
MB__BACKEND_TYPE=postgres | ||
MB__DATASETS_CONFIG=datasets.toml | ||
|
||
MB__POSTGRES__HOST=localhost | ||
MB__POSTGRES__PORT=5432 | ||
MB__POSTGRES__USER=matchbox_user | ||
MB__POSTGRES__PASSWORD=matchbox_password | ||
MB__POSTGRES__DATABASE=matchbox | ||
MB__POSTGRES__DB_SCHEMA=mb | ||
|
||
API__ROOT=http://localhost:8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
MB__BATCH_SIZE= | ||
MB__BACKEND_TYPE= | ||
MB__DATASETS_CONFIG= | ||
|
||
MB__POSTGRES__HOST= | ||
MB__POSTGRES__PORT= | ||
MB__POSTGRES__USER= | ||
MB__POSTGRES__PASSWORD= | ||
MB__POSTGRES__DATABASE= | ||
MB__POSTGRES__DB_SCHEMA= | ||
|
||
API__ROOT= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from matchbox.client.visualisation import draw_resolution_graph | ||
|
||
__all__ = ( | ||
# Visualisation | ||
draw_resolution_graph, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from os import getenv | ||
|
||
import httpx | ||
|
||
from matchbox.common.graph import ResolutionGraph | ||
|
||
|
||
def url(path: str) -> str: | ||
""" | ||
Return path prefixed by API root, determined from environment | ||
""" | ||
api_root = getenv("API__ROOT") | ||
if api_root is None: | ||
raise RuntimeError("API__ROOT needs to be defined in the environment") | ||
|
||
return api_root + path | ||
|
||
|
||
def get_resolution_graph() -> str: | ||
res = httpx.get(url("/report/resolutions")).json() | ||
return ResolutionGraph.model_validate(res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from enum import StrEnum | ||
|
||
import rustworkx as rx | ||
from matchbox.common.hash import hash_to_str | ||
from pydantic import BaseModel | ||
|
||
|
||
class ResolutionNodeKind(StrEnum): | ||
DATASET = "dataset" | ||
MODEL = "model" | ||
HUMAN = "human" | ||
|
||
|
||
class ResolutionNode(BaseModel): | ||
hash: bytes | ||
name: str | ||
kind: ResolutionNodeKind | ||
|
||
def __hash__(self): | ||
return hash(self.hash) | ||
|
||
|
||
class ResolutionEdge(BaseModel): | ||
parent: bytes | ||
child: bytes | ||
|
||
def __hash__(self): | ||
return hash((self.parent, self.child)) | ||
|
||
|
||
class ResolutionGraph(BaseModel): | ||
nodes: set[ResolutionNode] | ||
edges: set[ResolutionEdge] | ||
|
||
def to_rx(self) -> rx.PyDiGraph: | ||
nodes = {} | ||
G = rx.PyDiGraph() | ||
for n in self.nodes: | ||
node_data = {"id": hash_to_str(n.hash), "name": n.name, "kind": str(n.kind)} | ||
nodes[n.hash] = G.add_node(node_data) | ||
for e in self.edges: | ||
G.add_edge(nodes[e.parent], nodes[e.child], {}) | ||
return G |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# connectorx won't work on ARM or python-alpine | ||
FROM --platform=amd64 python:3.11 | ||
|
||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ | ||
|
||
WORKDIR /code | ||
|
||
# Enable bytecode compilation | ||
ENV UV_COMPILE_BYTECODE=1 | ||
|
||
# Copy from the cache instead of linking since it's a mounted volume | ||
ENV UV_LINK_MODE=copy | ||
|
||
# Install the project's dependencies using the lockfile and settings | ||
RUN --mount=type=cache,target=/root/.cache/uv \ | ||
--mount=type=bind,source=uv.lock,target=uv.lock \ | ||
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \ | ||
uv sync --frozen --all-extras --no-install-project --no-dev | ||
|
||
COPY ./environments/dev_docker.env /code/.env | ||
COPY ./uv.lock /code/uv.lock | ||
COPY ./pyproject.toml /code/pyproject.toml | ||
COPY ./src/matchbox /code/src/matchbox | ||
|
||
# Then, add the rest of the project source code and install it | ||
# Installing separately from its dependencies allows optimal layer caching | ||
RUN --mount=type=cache,target=/root/.cache/uv \ | ||
uv sync --frozen --all-extras --no-dev | ||
|
||
# Place executables in the environment at the front of the path | ||
ENV PATH="/code/.venv/bin:$PATH" | ||
|
||
# Uses `fastapi dev` to enable hot-reloading when the `watch` sync occurs | ||
# Uses `--host 0.0.0.0` to allow access from outside the container | ||
CMD ["fastapi", "dev", "--host", "0.0.0.0", "src/matchbox/server/api.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.