Metadata-Version: 2.4
Name: scigraphs-utils
Version: 0.2.0
Summary: Scientific graph layout utilities.
Author: Jose Marin
License: MIT License
        
        Copyright (c) 2026 Jose Marin
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/josemarinfarina/scigraphs-utils
Project-URL: Repository, https://github.com/josemarinfarina/scigraphs-utils
Project-URL: Issues, https://github.com/josemarinfarina/scigraphs-utils/issues
Keywords: graphviz,layout,graphs,sfdp,scientific-visualization
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: C++
Classifier: Topic :: Scientific/Engineering :: Visualization
Requires-Python: >=3.13
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: THIRD_PARTY_NOTICES.md
Requires-Dist: numpy>=2.1
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Provides-Extra: wheel
Requires-Dist: build>=1; extra == "wheel"
Requires-Dist: cibuildwheel>=2.22; extra == "wheel"
Dynamic: license-file

# scigraphs-utils

Utilities for scientific graph layouts.

The Python import package is `scigraphs_utils`.

```python
import numpy as np
from scigraphs_utils import sfdp_layout

edges = np.array([[0, 1], [1, 2], [2, 3]], dtype=np.int32)
xy = sfdp_layout(4, edges, seed=42, overlap="false", maxiter=100)
```

For Graphviz parameters that are not listed explicitly, pass them as keyword
arguments. They are forwarded as Graphviz graph attributes:

```python
from scigraphs_utils import graphviz_layout

xy = graphviz_layout(4, edges, engine="sfdp", start=42, K=1.2)
```

## Barnes-Hut forces

`quadtree_repulsion` exposes the repulsion term sfdp uses internally: Graphviz's
own `QuadTree_get_repulsive_force`, compiled into this package's extension. It
works on 2D and 3D points and is roughly two orders of magnitude faster than an
all-pairs numpy evaluation at a few thousand points.

```python
import numpy as np
from scigraphs_utils import quadtree_repulsion

points = np.random.default_rng(0).normal(size=(20_000, 3))
forces = quadtree_repulsion(points, theta=0.6)
```

`theta` is the Barnes-Hut opening angle (sfdp uses 0.6; smaller is more accurate
and slower, and `theta -> 0` converges to the exact all-pairs result). Pass
`weights=` for per-point masses, `p=` for a different force exponent, and
`return_counts=True` for Graphviz's interaction counters.

`quadtree_cells` returns the same tree flattened into arrays, so an overlay can
draw the cells the forces actually used instead of a uniform grid:

```python
from scigraphs_utils import quadtree_cells

cells = quadtree_cells(points)
cells.lower      # (cells, dim) lower corner
cells.size       # (cells,) edge length
cells.count      # (cells,) points per cell
cells.is_leaf    # (cells,) bool
```

Both functions build the tree the same way, so pass matching `weights` and
`max_level` to get the tree that produced a given force field.

## Development

The current MVP builds a native extension against a local Graphviz installation:

```bash
python -m pip install -e ".[test]"
pytest
```

To build against a private Graphviz prefix, run:

```bash
tools/build_graphviz.sh
GRAPHVIZ_PREFIX="$PWD/build/vendor/graphviz-install" python -m pip install -e ".[test]"
```

## Wheels

The project is configured for `cibuildwheel` CPython 3.13 builds. The wheel
build hook compiles a pinned Graphviz release into a private prefix and builds
the native extension against that prefix. On Linux, `auditwheel` then bundles
the required shared libraries into the wheel so users do not need Graphviz
installed at runtime.

```bash
python -m pip install ".[wheel]"
python -m cibuildwheel --output-dir wheelhouse
```

Pushing a `v*` tag runs `.github/workflows/publish.yml`, which builds the three
wheels and uploads them to PyPI through trusted publishing.

## Vendored Graphviz source

The quadtree is compiled from a copy of Graphviz's `lib/sparse/QuadTree.c` under
`vendor/graphviz/`, because those symbols are not exported from the layout
plugin. Those files stay under the Eclipse Public License — see
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) and
[vendor/graphviz/README.md](vendor/graphviz/README.md). When bumping
`vendor/graphviz.version`, run:

```bash
python tools/sync_quadtree.py
```
