HomLab Solver for Single Non-Intersecting Graphs.
Project description
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: arandom.Randominstance 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, orNoneif 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:
typemust be"homlab".nmust be2.- 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_1andid_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
0or1.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file homlab_solver-0.1.1.tar.gz.
File metadata
- Download URL: homlab_solver-0.1.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfd00e9d3531844b1d32b7bbff633ee6f7e9f4439e1c4439595202d7bd0d47f1
|
|
| MD5 |
56abf5b2562bb849669d99aaf9fdc443
|
|
| BLAKE2b-256 |
5c499918a239397cd7d74e704c3989ef1e017d58c5989391c3203aaf45efa3bf
|
File details
Details for the file homlab_solver-0.1.1-py3-none-any.whl.
File metadata
- Download URL: homlab_solver-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
809461077b3cce97723309ee03fbd5dad7bc11a4d8b260ab59e1a6259ffc622c
|
|
| MD5 |
11837182a2d8c19f61d0b44471345b02
|
|
| BLAKE2b-256 |
51d09c2a73d2b1c44f6acf2537ba0c3ba46d692a2b1da75862299aefd7d5afda
|