Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
zarr-vectors-tools
Logo
zarr-vectors-tools

Getting Started

  • How this package relates to zarr-vectors-py
  • Installation
  • Quickstart
  • Concepts
  • The zvtools command line

Modules

  • Modules

Ingest Workflows

  • Ingest workflows
  • Point clouds
  • Single-cell and spatial omics
  • Lines
  • Tractography
  • Tractography at scale
  • Skeletons
  • Skeletons in EM
  • Graphs
  • Meshes
  • Cortical surfaces

Compose

  • Merging and splitting stores

Multiresolution

  • Multiresolution
  • Concepts: coarsening versus sparsity
  • Building pyramids
  • Coarsening strategies
  • Object selection
  • Cross-level links
  • Refreshing a pyramid

Algorithms

  • Algorithms
  • Graph search
  • Graph components
  • Graph clustering
  • Mesh summary
  • Mesh attributes
  • Mesh queries

Export Workflows

  • Export workflows
  • Point clouds
  • Single-cell and spatial omics
  • Streamlines
  • Skeletons
  • Meshes
  • Cortical surfaces

How-To Guides

  • Parallel and concurrent workflows
  • Choosing a compressor
  • Chunk and bin shape in this package’s workflows
  • Large-scale pipelines

Reference

  • Enrichments
  • Headers
  • Examples
  • Findings for zarr-vectors, from the merged-links migration + parallel pyramid work

Benchmarks

  • Benchmarks

API Reference

  • API reference
    • Ingest
    • Multiresolution
    • Algorithms
    • Export
    • Headers
    • CLI
Back to top
View this page
Edit this page

Graph search¶

Frontier search over a chunked graph (or skeleton) store. Both algorithms read the level’s links once per call into an array adjacency (compressed sparse rows: indptr, indices, weights).

At format 0.9.0 connectivity is a single family, so the adjacency comes from one whole-family read_link_arrays(delta=0) rather than a per-chunk pass followed by a separate cross-chunk merge. Edge weights come from read_link_attributes(level_group, weight_attr, delta=0), aligned row-for-row with the links by their shared (segment, cell) enumeration order; a length mismatch falls back to unit weights.

Warning

Older code and notes describe merging cross-chunk edges in from read_cross_chunk_links. That reader no longer exists, and reproducing the pattern against the merged family double-counts every intra-chunk edge. See the double-count trap in Algorithms.

bfs_distances — unweighted BFS¶

from zarr_vectors_tools.algorithms import bfs_distances

result = bfs_distances("graph.zv", source=0, max_distance=5)
result["distances"]      # (N,) int32 — -1 for unreached
result["predecessors"]   # (N,) int64 — lowest-numbered parent; -1 for source and unreached
source

Global vertex index to start from.

max_distance

Optional cutoff. Vertices beyond stay at -1. None runs until the connected component is exhausted.

shortest_path — Dijkstra / A*¶

from zarr_vectors_tools.algorithms import shortest_path

# Plain Dijkstra
res = shortest_path("graph.zv", source=0, target=42, weight="cost")
res["path"]      # list[int]
res["cost"]      # float, inf if unreachable
res["visited"]   # int — nodes popped from the queue

# A* with an admissible heuristic
def euclid_to_target(v):
    ...
res = shortest_path("graph.zv", source=0, target=42, heuristic=euclid_to_target)
source, target

Global vertex indices.

weight

Name of an edge attribute to use as the per-edge cost. None (default) means unit weights, which makes Dijkstra equivalent to BFS. Every edge, intra- or cross-chunk, reads its weight from link_attributes/<weight>/0/; without that family, weights are silently 1.

heuristic

Optional admissible lower-bound function node_index -> float. When supplied the search becomes A*.

Algorithm notes¶

Both functions build the full adjacency once. Memory is O(N + E): every edge contributes two entries (undirected), a parallel edge one pair per copy, and a self-loop two entries on its vertex.

  • BFS expands a whole frontier per step with numpy: gather the frontier’s neighbours, keep the unvisited ones, and give each its lowest-numbered parent. The distances equal a queue BFS’s, and the predecessors do not depend on edge order.

  • Dijkstra / A* keeps a heapq, over plain lists taken from the adjacency arrays, and stops when the target is popped. A stale entry (one pushed before a shorter route was found) is skipped on pop. A node can be reopened, so an admissible heuristic that is not consistent still finds the shortest path. Path reconstruction follows the predecessor chain from target back to source.

build_adjacency still returns the Python adjacency lists for callers that want them. The algorithms here and in Graph clustering use the array form directly.

See also¶

  • Algorithms index — write_back / per_object matrix.

  • Graph clustering

  • Parent: Graph spec

Next
Graph components
Previous
Algorithms
Copyright © 2024, BRIDGE Neuroscience. Aligned to the Zarr Vectors specification by Forrest Collman, Allen Institute for Brain Sciences.
Made with Sphinx and @pradyunsg's Furo
On this page
  • Graph search
    • bfs_distances — unweighted BFS
    • shortest_path — Dijkstra / A*
    • Algorithm notes
    • See also