← All examples
16

Canonical Grid model

Native Graph V2

Closed kinds, typed views, immutable rewrites, declarative paths, partitions, bounded patterns, and fixed-point propagation.

Scale
Large
Source
16-graph-v2-native.grid
Length
99 lines
Collection
Advanced language
Level
Advanced
Runtime
Portable
Version
1.0.0

Watch it in Grid

See this model in motion.

Watch the model respond in the product, then inspect the exact source and checkpoints on this page.

What this model gives you

A typed road graph with filtered views, immutable rewrites, bounded path planning, patterns, partitions, contraction, and fixed-point distances.

25 min to study · Source reviewed 2026-08-25

Continue with guided practice

What to notice

  • Typed graph schemas
  • Immutable views and rewrites
  • Declarative path objectives
  • Resident Frames, patterns, partitions, and fixed points

Requirements

  • Graph V2 runtime
  • No connector
  • No network

Expected checkpoint

A known state for this walkthrough.

After loading the four-city, four-road graph with one closed edge.

Open roads
3R1C1
Normalized roads
3R1C2; closed ac deleted
Fastest cost
14 minutesR1C3; A→B→C→D
Fastest hops
3R1C4
01 · Type

The schema closes valid node and edge shapes

Road endpoints, kinds, minutes, capacity, and open state are checked before graph work publishes.

02 · Plan

Objectives describe paths without naming algorithms

The fastest route minimizes summed minutes while a second route maximizes bottleneck capacity.

03 · Project

Advanced results remain resident and inspectable

Paths, community membership, bounded patterns, contraction, and min-plus propagation publish Graph or Frame handles.

16-graph-v2-native.grid
Get Grid
MODEL "Native Graph V2"
DESCRIPTION "Closed kinds, typed views, immutable rewrites, declarative paths, partitions, bounded patterns, and fixed-point propagation."
VERSION "1.0.0"
TAGS "graph", "schema", "kind", "view", "rewrite", "path", "partition", "pattern", "fixpoint"

graph schema Roads {
  node kind City
  edge kind Road: City -> City
  node.kind: string
  edge.kind: string
  edge.minutes: number
  edge.capacity: number
  edge.open: boolean
}

graph roads: Roads = GRAPH(
  [
    ["node_id", "kind"],
    ["A", "City"],
    ["B", "City"],
    ["C", "City"],
    ["D", "City"]
  ] AS nodes,
  "node_id" AS node_id,
  ["kind"] AS node_properties,
  [
    ["edge_id", "from", "to", "kind", "minutes", "capacity", "open"],
    ["ab", "A", "B", "Road", 4, 20, TRUE],
    ["bc", "B", "C", "Road", 7, 8, TRUE],
    ["ac", "A", "C", "Road", 15, 30, FALSE],
    ["cd", "C", "D", "Road", 3, 12, TRUE]
  ] AS edges,
  "edge_id" AS edge_id,
  "from" AS from,
  "to" AS to,
  ["kind", "minutes", "capacity", "open"] AS edge_properties,
  TRUE AS directed
)

# A single selective scalar consumer lets Graph MIR fuse this view.
graph open_roads: Roads = roads {
  edge road where road.open = TRUE
}
R1C1 = GRAPH_EDGE_COUNT(open_roads)

# Rewrites are immutable and publish only after the complete bounded edit set validates.
graph normalized: Roads = rewrite roads limit 100:
  match (origin)-[closed where closed.open = FALSE]->(destination)
  delete closed
R1C2 = GRAPH_EDGE_COUNT(normalized)

# Source expresses the objective. EXPLAIN shows the chosen physical kernel.
path fastest = path in roads from "A" to "D"
  minimize sum(edge.minutes)
  limit 8 AS hops

path resilient = path in roads from "A" to "D"
  maximize min(edge.capacity)
  limit 8 AS hops

R1C3 = fastest.cost
R1C4 = fastest.hops
frame fastest_nodes = fastest.nodes
frame fastest_edges = fastest.edges

partition communities = partition nodes of roads by community(
  leiden AS method,
  modularity(1 AS resolution) AS objective,
  edge.capacity AS weight,
  directed AS direction,
  0 AS seed,
  all AS hierarchy,
  50 AS max_passes,
  16 AS max_levels,
  0.000000001 AS tolerance
)

frame community_membership = communities.members
frame community_summary = communities.summary

# Contraction consumes the resident partition, keeps cross-community edges as
# a deterministic multigraph, and exposes the quotient as another GraphHandle.
graph quotient = contract roads by communities
R1C5 = GRAPH_NODE_COUNT(quotient)

frame open_two_hop_routes = match roads limit 100:
  (origin)-[first where first.open = TRUE]->(middle)-[second where second.open = TRUE]->(destination)
  return origin as origin, middle as middle, destination as destination,
         first.minutes as first_minutes, second.minutes as second_minutes

frame travel_minutes = fixpoint in roads:
  using min_plus(edge.minutes AS weight)
  along AS direction
  1000000000 AS default
  0 AS seed "A"
  until max_delta < 0.000000001
  within 16 iterations

END MODEL