Skip to main content

homlab-solver

homlab-solver is a small Python package for solving a single non-intersecting HomLab diagram stored as JSON.

The package currently exposes a Python API. It does not define a command-line entry point yet.

Requirements

  • Python 3.10 or newer
  • No runtime dependencies outside the Python standard library

Installation

After the package is published to PyPI:

python -m pip install homlab-solver

For local development from this repository:

python -m pip install -e .

Quick Start

import random

from homlab_solver import solve_single_json

rng = random.Random(42)
result = solve_single_json("test.json", rng=rng)

if result.msg:
    raise RuntimeError(result.msg)

print(result.ans)

You can run the same example from a shell:

python - <<'PY'
import random
from homlab_solver import solve_single_json

result = solve_single_json("test.json", rng=random.Random(42))

if result.msg:
    raise SystemExit(result.msg)

print(result.ans)
PY

With the sample test.json in this repository, the output is:

(-A^2-A^(-2)) * C[-1, 1, -2]

API

solve_single_json(filepath, rng, loop_value="(-A^2-A^(-2))", eps=1e-8)

Solves one HomLab JSON file.

Parameters:

  • filepath: path to a HomLab JSON file.
  • rng: a random.Random instance used for small geometric perturbations and randomized ray tests. Pass a seeded instance when you need reproducible output.
  • loop_value: symbolic value used for each free loop.
  • eps: floating-point tolerance for geometric predicates.

Returns a SolverObject with:

  • ans: the computed symbolic answer, or None if solving failed.
  • msg: an empty string on success, or an error message on failure.

Input JSON

The solver expects a JSON object describing a single HomLab diagram. At minimum, the file must include:

{
  "type": "homlab",
  "n": 2,
  "hs": {
    "handle_genus_0000000": {"x": 0.5, "y": 0.35},
    "handle_genus_0000001": {"x": 1.35, "y": 0.35},
    "handle_border_0000000": {"x": 0.5, "y": -0.2},
    "handle_border_0000001": {"x": 1.35, "y": -0.2}
  },
  "ns": {
    "node_0000000": {"x": 0.0, "y": 0.0}
  },
  "es": {
    "edge_0000000": {
      "id_1": "handle_genus_0000000",
      "id_2": "node_0000000"
    }
  }
}

Important constraints:

  • type must be "homlab".
  • n must be 2.
  • The four handle IDs shown above are required by the current solver.
  • Normal node IDs should start with node_.
  • Handle IDs should start with handle_.
  • Edge objects must contain id_1 and id_2.
  • IDs starting with # are treated as special metadata and ignored by the solving step.
  • Non-handle nodes are expected to have degree 2.
  • Handle nodes are expected to have degree 0 or 1.

Building

This project uses poetry-core as its build backend. To build a source distribution and wheel:

python -m pip install --upgrade build
python -m build

The generated artifacts will be written to dist/.

Before uploading to PyPI, check the package metadata:

python -m pip install --upgrade twine
python -m twine check dist/*

Upload to PyPI:

python -m twine upload dist/*

License

This project is licensed under the MIT License. See LICENSE for details.

Metadata

Release files for homlab-solver 0.1.1

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

Source distribution (sdist)

Source distribution for homlab-solver 0.1.1
File Size Uploaded
homlab_solver-0.1.1.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for homlab-solver 0.1.1
File Interpreter ABI Platform
homlab_solver-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / homlab_solver-0.1.1.tar.gz

Download URL homlab_solver-0.1.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
bfd00e9d3531844b1d32b7bbff633ee6f7e9f4439e1c4439595202d7bd0d47f1
BLAKE2b-256 checksum
How to use checksums
5c499918a239397cd7d74e704c3989ef1e017d58c5989391c3203aaf45efa3bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.11.15 Windows/10

Release files / homlab_solver-0.1.1-py3-none-any.whl

Download URL homlab_solver-0.1.1-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
809461077b3cce97723309ee03fbd5dad7bc11a4d8b260ab59e1a6259ffc622c
BLAKE2b-256 checksum
How to use checksums
51d09c2a73d2b1c44f6acf2537ba0c3ba46d692a2b1da75862299aefd7d5afda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.11.15 Windows/10

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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