terraproof 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +356 -2
  3. package/bin/terraproof.js +4 -0
  4. package/dist/router/apply.js +147 -0
  5. package/dist/router/classify.js +111 -0
  6. package/dist/router/explain.js +9 -0
  7. package/dist/router/index.js +272 -0
  8. package/dist/router/resolve.js +239 -0
  9. package/dist/router/score.js +60 -0
  10. package/dist/router/types.js +1 -0
  11. package/dist/router/validate.js +81 -0
  12. package/instructions/engineering.md +14 -0
  13. package/instructions/security.md +14 -0
  14. package/instructions/simplicity.md +13 -0
  15. package/package.json +65 -4
  16. package/routing/DOMAIN_ROUTING.md +161 -0
  17. package/routing/ROUTER_DESIGN.md +173 -0
  18. package/routing/SKILL_MANIFEST.md +86 -0
  19. package/routing/checks.json +121 -0
  20. package/routing/collections.json +47 -0
  21. package/routing/registry.json +2211 -0
  22. package/routing/rules.json +64 -0
  23. package/skills/accuracy-assessment/SKILL.md +213 -0
  24. package/skills/accuracy-assessment/UPSTREAM.md +7 -0
  25. package/skills/accuracy-assessment/references/stratified-estimator.md +127 -0
  26. package/skills/accuracy-assessment/skill.json +103 -0
  27. package/skills/brainstorming/SKILL.md +250 -0
  28. package/skills/brainstorming/UPSTREAM.md +29 -0
  29. package/skills/brainstorming/scripts/frame-template.html +213 -0
  30. package/skills/brainstorming/scripts/helper.js +167 -0
  31. package/skills/brainstorming/scripts/server.cjs +723 -0
  32. package/skills/brainstorming/scripts/start-server.sh +209 -0
  33. package/skills/brainstorming/scripts/stop-server.sh +120 -0
  34. package/skills/brainstorming/skill.json +73 -0
  35. package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  36. package/skills/brainstorming/visual-companion.md +299 -0
  37. package/skills/crs-and-units/SKILL.md +200 -0
  38. package/skills/crs-and-units/UPSTREAM.md +7 -0
  39. package/skills/crs-and-units/skill.json +74 -0
  40. package/skills/design-postgis-tables/SKILL.md +494 -0
  41. package/skills/design-postgis-tables/UPSTREAM.md +21 -0
  42. package/skills/design-postgis-tables/skill.json +90 -0
  43. package/skills/gdal/SKILL.md +125 -0
  44. package/skills/gdal/UPSTREAM.md +22 -0
  45. package/skills/gdal/references/gdal-recipes.md +103 -0
  46. package/skills/gdal/skill.json +66 -0
  47. package/skills/geomaster/README.md +105 -0
  48. package/skills/geomaster/SKILL.md +366 -0
  49. package/skills/geomaster/UPSTREAM.md +21 -0
  50. package/skills/geomaster/references/advanced-gis.md +376 -0
  51. package/skills/geomaster/references/big-data.md +363 -0
  52. package/skills/geomaster/references/code-examples.md +531 -0
  53. package/skills/geomaster/references/coordinate-systems.md +364 -0
  54. package/skills/geomaster/references/core-libraries.md +273 -0
  55. package/skills/geomaster/references/data-sources.md +330 -0
  56. package/skills/geomaster/references/gis-software.md +369 -0
  57. package/skills/geomaster/references/industry-applications.md +420 -0
  58. package/skills/geomaster/references/machine-learning.md +462 -0
  59. package/skills/geomaster/references/programming-languages.md +456 -0
  60. package/skills/geomaster/references/remote-sensing.md +370 -0
  61. package/skills/geomaster/references/scientific-domains.md +416 -0
  62. package/skills/geomaster/references/specialized-topics.md +428 -0
  63. package/skills/geomaster/references/troubleshooting.md +439 -0
  64. package/skills/geomaster/skill.json +157 -0
  65. package/skills/geopandas/SKILL.md +250 -0
  66. package/skills/geopandas/UPSTREAM.md +22 -0
  67. package/skills/geopandas/references/crs-management.md +231 -0
  68. package/skills/geopandas/references/data-io.md +323 -0
  69. package/skills/geopandas/references/data-structures.md +207 -0
  70. package/skills/geopandas/references/geometric-operations.md +262 -0
  71. package/skills/geopandas/references/spatial-analysis.md +294 -0
  72. package/skills/geopandas/references/visualization.md +230 -0
  73. package/skills/geopandas/scripts/_common.py +605 -0
  74. package/skills/geopandas/scripts/crs_reprojection_plan.py +210 -0
  75. package/skills/geopandas/scripts/export_plan.py +305 -0
  76. package/skills/geopandas/scripts/geometry_validity_report.py +227 -0
  77. package/skills/geopandas/scripts/sensitive_coordinates_checklist.py +230 -0
  78. package/skills/geopandas/scripts/spatial_join_audit.py +368 -0
  79. package/skills/geopandas/scripts/vector_inventory.py +140 -0
  80. package/skills/geopandas/skill.json +116 -0
  81. package/skills/geoparquet-validation/SKILL.md +125 -0
  82. package/skills/geoparquet-validation/UPSTREAM.md +24 -0
  83. package/skills/geoparquet-validation/references/distribution-best-practices.md +118 -0
  84. package/skills/geoparquet-validation/references/gpio-commands.md +264 -0
  85. package/skills/geoparquet-validation/references/tool-comparison.md +155 -0
  86. package/skills/geoparquet-validation/skill.json +71 -0
  87. package/skills/geospatial-data-discovery/SKILL.md +49 -0
  88. package/skills/geospatial-data-discovery/UPSTREAM.md +15 -0
  89. package/skills/geospatial-data-discovery/skill.json +51 -0
  90. package/skills/geospatial-frontend/SKILL.md +86 -0
  91. package/skills/geospatial-frontend/UPSTREAM.md +23 -0
  92. package/skills/geospatial-frontend/references/design-system.md +283 -0
  93. package/skills/geospatial-frontend/references/user-preferences.md +96 -0
  94. package/skills/geospatial-frontend/skill.json +87 -0
  95. package/skills/geozarr/SKILL.md +244 -0
  96. package/skills/geozarr/UPSTREAM.md +21 -0
  97. package/skills/geozarr/skill.json +97 -0
  98. package/skills/networkx/SKILL.md +440 -0
  99. package/skills/networkx/UPSTREAM.md +22 -0
  100. package/skills/networkx/references/algorithms.md +384 -0
  101. package/skills/networkx/references/generators.md +385 -0
  102. package/skills/networkx/references/graph-basics.md +284 -0
  103. package/skills/networkx/references/io.md +457 -0
  104. package/skills/networkx/references/visualization.md +531 -0
  105. package/skills/networkx/skill.json +93 -0
  106. package/skills/raster-processing/SKILL.md +222 -0
  107. package/skills/raster-processing/UPSTREAM.md +7 -0
  108. package/skills/raster-processing/skill.json +81 -0
  109. package/skills/sar-basics/SKILL.md +202 -0
  110. package/skills/sar-basics/UPSTREAM.md +7 -0
  111. package/skills/sar-basics/references/calibration-lut.md +98 -0
  112. package/skills/sar-basics/skill.json +97 -0
  113. package/skills/satellite-preprocessing/SKILL.md +241 -0
  114. package/skills/satellite-preprocessing/UPSTREAM.md +7 -0
  115. package/skills/satellite-preprocessing/skill.json +84 -0
  116. package/skills/scientific-visualization/SKILL.md +285 -0
  117. package/skills/scientific-visualization/UPSTREAM.md +25 -0
  118. package/skills/scientific-visualization/assets/color_palettes.py +263 -0
  119. package/skills/scientific-visualization/assets/nature.mplstyle +68 -0
  120. package/skills/scientific-visualization/assets/presentation.mplstyle +68 -0
  121. package/skills/scientific-visualization/assets/publication.mplstyle +77 -0
  122. package/skills/scientific-visualization/assets/publisher_profiles.json +269 -0
  123. package/skills/scientific-visualization/references/color_palettes.md +227 -0
  124. package/skills/scientific-visualization/references/journal_requirements.md +169 -0
  125. package/skills/scientific-visualization/references/matplotlib_examples.md +336 -0
  126. package/skills/scientific-visualization/references/publication_guidelines.md +196 -0
  127. package/skills/scientific-visualization/references/sources.md +76 -0
  128. package/skills/scientific-visualization/scripts/_common.py +136 -0
  129. package/skills/scientific-visualization/scripts/export_plan.py +493 -0
  130. package/skills/scientific-visualization/scripts/figure_export.py +642 -0
  131. package/skills/scientific-visualization/scripts/image_metadata.py +731 -0
  132. package/skills/scientific-visualization/scripts/palette_audit.py +327 -0
  133. package/skills/scientific-visualization/scripts/style_presets.py +501 -0
  134. package/skills/scientific-visualization/scripts/style_preview.py +232 -0
  135. package/skills/scientific-visualization/skill.json +95 -0
  136. package/skills/spectral-indices/SKILL.md +235 -0
  137. package/skills/spectral-indices/UPSTREAM.md +7 -0
  138. package/skills/spectral-indices/skill.json +88 -0
  139. package/skills/stac-and-cloud-access/SKILL.md +209 -0
  140. package/skills/stac-and-cloud-access/UPSTREAM.md +7 -0
  141. package/skills/stac-and-cloud-access/references/run-manifest.md +94 -0
  142. package/skills/stac-and-cloud-access/skill.json +98 -0
  143. package/skills/statistical-analysis/SKILL.md +446 -0
  144. package/skills/statistical-analysis/UPSTREAM.md +24 -0
  145. package/skills/statistical-analysis/references/assumptions_and_diagnostics.md +379 -0
  146. package/skills/statistical-analysis/references/bayesian_statistics.md +686 -0
  147. package/skills/statistical-analysis/references/effect_sizes_and_power.md +649 -0
  148. package/skills/statistical-analysis/references/reporting_standards.md +482 -0
  149. package/skills/statistical-analysis/references/test_selection_guide.md +129 -0
  150. package/skills/statistical-analysis/scripts/assumption_checks.py +652 -0
  151. package/skills/statistical-analysis/skill.json +127 -0
  152. package/skills/systematic-debugging/SKILL.md +283 -0
  153. package/skills/systematic-debugging/UPSTREAM.md +28 -0
  154. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  155. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  156. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  157. package/skills/systematic-debugging/find-polluter.sh +72 -0
  158. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  159. package/skills/systematic-debugging/skill.json +88 -0
  160. package/skills/time-series-and-change/SKILL.md +217 -0
  161. package/skills/time-series-and-change/UPSTREAM.md +7 -0
  162. package/skills/time-series-and-change/references/change-methods.md +42 -0
  163. package/skills/time-series-and-change/skill.json +116 -0
  164. package/skills/vector-quality/SKILL.md +204 -0
  165. package/skills/vector-quality/UPSTREAM.md +7 -0
  166. package/skills/vector-quality/skill.json +82 -0
  167. package/skills/verification/SKILL.md +120 -0
  168. package/skills/verification/UPSTREAM.md +31 -0
  169. package/skills/verification/skill.json +67 -0
  170. package/skills/writing-plans/SKILL.md +171 -0
  171. package/skills/writing-plans/UPSTREAM.md +23 -0
  172. package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  173. package/skills/writing-plans/skill.json +80 -0
  174. package/sources/SOURCES.md +374 -0
  175. package/third_party/isaaccorley-geospatial-skills/LICENSE +176 -0
  176. package/third_party/isaaccorley-geospatial-skills/NOTICE.md +17 -0
  177. package/third_party/kdense-scientific-agent-skills/LICENSE +21 -0
  178. package/third_party/kdense-scientific-agent-skills/NOTICE.md +19 -0
  179. package/third_party/superpowers/LICENSE +21 -0
  180. package/third_party/superpowers/NOTICE.md +17 -0
  181. package/third_party/timescale-pg-aiguide/LICENSE +176 -0
  182. package/third_party/timescale-pg-aiguide/NOTICE.md +14 -0
@@ -0,0 +1,440 @@
1
+ ---
2
+ name: networkx
3
+ description: Create, analyze, and visualize complex networks and graphs in Python with NetworkX. Use when working with network/graph data structures, computing graph algorithms (shortest paths, centrality, clustering), detecting communities, generating synthetic networks (random, scale-free, small-world), reading/writing graph file formats, or drawing network topologies. Common applications include social, biological, transportation, and citation networks.
4
+ license: 3-clause BSD license
5
+ metadata:
6
+ version: "1.1"
7
+ skill-author: K-Dense Inc.
8
+ ---
9
+
10
+ # NetworkX
11
+
12
+ ## Overview
13
+
14
+ NetworkX is a Python package for creating, manipulating, and analyzing complex networks and graphs. Use this skill when working with network or graph data structures, including social networks, biological networks, transportation systems, citation networks, knowledge graphs, or any system involving relationships between entities.
15
+
16
+ This skill targets NetworkX 3.x (current stable: 3.6, which requires Python >= 3.11). Several pre-3.0 APIs (`nx.info`, `nx.write_gpickle`, `nx.read_shp`) and the 3.4-era `nx.random_tree` no longer exist — current replacements are used throughout this skill.
17
+
18
+ ## When to Use This Skill
19
+
20
+ Invoke this skill when tasks involve:
21
+
22
+ - **Creating graphs**: Building network structures from data, adding nodes and edges with attributes
23
+ - **Graph analysis**: Computing centrality measures, finding shortest paths, detecting communities, measuring clustering
24
+ - **Graph algorithms**: Running standard algorithms like Dijkstra's, PageRank, minimum spanning trees, maximum flow
25
+ - **Network generation**: Creating synthetic networks (random, scale-free, small-world models) for testing or simulation
26
+ - **Graph I/O**: Reading from or writing to various formats (edge lists, GraphML, JSON, CSV, adjacency matrices)
27
+ - **Visualization**: Drawing and customizing network visualizations with matplotlib or interactive libraries
28
+ - **Network comparison**: Checking isomorphism, computing graph metrics, analyzing structural properties
29
+
30
+ ## Core Capabilities
31
+
32
+ ### 1. Graph Creation and Manipulation
33
+
34
+ NetworkX supports four main graph types:
35
+ - **Graph**: Undirected graphs with single edges
36
+ - **DiGraph**: Directed graphs with one-way connections
37
+ - **MultiGraph**: Undirected graphs allowing multiple edges between nodes
38
+ - **MultiDiGraph**: Directed graphs with multiple edges
39
+
40
+ Create graphs by:
41
+ ```python
42
+ import networkx as nx
43
+
44
+ # Create empty graph
45
+ G = nx.Graph()
46
+
47
+ # Add nodes (can be any hashable type)
48
+ G.add_node(1)
49
+ G.add_nodes_from([2, 3, 4])
50
+ G.add_node("protein_A", type='enzyme', weight=1.5)
51
+
52
+ # Add edges
53
+ G.add_edge(1, 2)
54
+ G.add_edges_from([(1, 3), (2, 4)])
55
+ G.add_edge(1, 4, weight=0.8, relation='interacts')
56
+ ```
57
+
58
+ **Reference**: See `references/graph-basics.md` for comprehensive guidance on creating, modifying, examining, and managing graph structures, including working with attributes and subgraphs.
59
+
60
+ ### 2. Graph Algorithms
61
+
62
+ NetworkX provides extensive algorithms for network analysis:
63
+
64
+ **Shortest Paths**:
65
+ ```python
66
+ # Find shortest path
67
+ path = nx.shortest_path(G, source=1, target=5)
68
+ length = nx.shortest_path_length(G, source=1, target=5, weight='weight')
69
+ ```
70
+
71
+ **Centrality Measures**:
72
+ ```python
73
+ # Degree centrality
74
+ degree_cent = nx.degree_centrality(G)
75
+
76
+ # Betweenness centrality
77
+ betweenness = nx.betweenness_centrality(G)
78
+
79
+ # PageRank
80
+ pagerank = nx.pagerank(G)
81
+ ```
82
+
83
+ **Community Detection**:
84
+ ```python
85
+ from networkx.algorithms import community
86
+
87
+ # Detect communities
88
+ communities = community.greedy_modularity_communities(G)
89
+ ```
90
+
91
+ **Connectivity**:
92
+ ```python
93
+ # Check connectivity
94
+ is_connected = nx.is_connected(G)
95
+
96
+ # Find connected components
97
+ components = list(nx.connected_components(G))
98
+ ```
99
+
100
+ **Reference**: See `references/algorithms.md` for detailed documentation on all available algorithms including shortest paths, centrality measures, clustering, community detection, flows, matching, tree algorithms, and graph traversal.
101
+
102
+ ### 3. Graph Generators
103
+
104
+ Create synthetic networks for testing, simulation, or modeling:
105
+
106
+ **Classic Graphs**:
107
+ ```python
108
+ # Complete graph
109
+ G = nx.complete_graph(n=10)
110
+
111
+ # Cycle graph
112
+ G = nx.cycle_graph(n=20)
113
+
114
+ # Known graphs
115
+ G = nx.karate_club_graph()
116
+ G = nx.petersen_graph()
117
+ ```
118
+
119
+ **Random Networks**:
120
+ ```python
121
+ # Erdős-Rényi random graph
122
+ G = nx.erdos_renyi_graph(n=100, p=0.1, seed=42)
123
+
124
+ # Barabási-Albert scale-free network
125
+ G = nx.barabasi_albert_graph(n=100, m=3, seed=42)
126
+
127
+ # Watts-Strogatz small-world network
128
+ G = nx.watts_strogatz_graph(n=100, k=6, p=0.1, seed=42)
129
+ ```
130
+
131
+ **Structured Networks**:
132
+ ```python
133
+ # Grid graph
134
+ G = nx.grid_2d_graph(m=5, n=7)
135
+
136
+ # Random tree (random_tree was removed in NetworkX 3.4)
137
+ G = nx.random_labeled_tree(100, seed=42)
138
+ ```
139
+
140
+ **Reference**: See `references/generators.md` for comprehensive coverage of all graph generators including classic, random, lattice, bipartite, and specialized network models with detailed parameters and use cases.
141
+
142
+ ### 4. Reading and Writing Graphs
143
+
144
+ NetworkX supports numerous file formats and data sources:
145
+
146
+ **File Formats**:
147
+ ```python
148
+ # Edge list
149
+ G = nx.read_edgelist('graph.edgelist')
150
+ nx.write_edgelist(G, 'graph.edgelist')
151
+
152
+ # GraphML (preserves attributes)
153
+ G = nx.read_graphml('graph.graphml')
154
+ nx.write_graphml(G, 'graph.graphml')
155
+
156
+ # GML
157
+ G = nx.read_gml('graph.gml')
158
+ nx.write_gml(G, 'graph.gml')
159
+
160
+ # JSON (node-link format; edge list is stored under the "edges" key
161
+ # since NetworkX 3.6 — older files may use "links", see references/io.md)
162
+ data = nx.node_link_data(G)
163
+ G = nx.node_link_graph(data)
164
+ ```
165
+
166
+ **Pandas Integration**:
167
+ ```python
168
+ import pandas as pd
169
+
170
+ # From DataFrame
171
+ df = pd.DataFrame({'source': [1, 2, 3], 'target': [2, 3, 4], 'weight': [0.5, 1.0, 0.75]})
172
+ G = nx.from_pandas_edgelist(df, 'source', 'target', edge_attr='weight')
173
+
174
+ # To DataFrame
175
+ df = nx.to_pandas_edgelist(G)
176
+ ```
177
+
178
+ **Matrix Formats**:
179
+ ```python
180
+ import numpy as np
181
+
182
+ # Adjacency matrix
183
+ A = nx.to_numpy_array(G)
184
+ G = nx.from_numpy_array(A)
185
+
186
+ # Sparse matrix
187
+ A = nx.to_scipy_sparse_array(G)
188
+ G = nx.from_scipy_sparse_array(A)
189
+ ```
190
+
191
+ **Reference**: See `references/io.md` for complete documentation on all I/O formats including CSV, SQL databases, Cytoscape, DOT, and guidance on format selection for different use cases.
192
+
193
+ ### 5. Visualization
194
+
195
+ Create clear and informative network visualizations:
196
+
197
+ **Basic Visualization**:
198
+ ```python
199
+ import matplotlib.pyplot as plt
200
+
201
+ # Simple draw
202
+ nx.draw(G, with_labels=True)
203
+ plt.show()
204
+
205
+ # With layout
206
+ pos = nx.spring_layout(G, seed=42)
207
+ nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500)
208
+ plt.show()
209
+ ```
210
+
211
+ **Customization**:
212
+ ```python
213
+ # Color by degree
214
+ node_colors = [G.degree(n) for n in G.nodes()]
215
+ nx.draw(G, node_color=node_colors, cmap=plt.cm.viridis)
216
+
217
+ # Size by centrality
218
+ centrality = nx.betweenness_centrality(G)
219
+ node_sizes = [3000 * centrality[n] for n in G.nodes()]
220
+ nx.draw(G, node_size=node_sizes)
221
+
222
+ # Edge weights
223
+ edge_widths = [3 * G[u][v].get('weight', 1) for u, v in G.edges()]
224
+ nx.draw(G, width=edge_widths)
225
+ ```
226
+
227
+ **Layout Algorithms**:
228
+ ```python
229
+ # Spring layout (force-directed)
230
+ pos = nx.spring_layout(G, seed=42)
231
+
232
+ # Circular layout
233
+ pos = nx.circular_layout(G)
234
+
235
+ # Kamada-Kawai layout
236
+ pos = nx.kamada_kawai_layout(G)
237
+
238
+ # Spectral layout
239
+ pos = nx.spectral_layout(G)
240
+ ```
241
+
242
+ **Publication Quality**:
243
+ ```python
244
+ plt.figure(figsize=(12, 8))
245
+ pos = nx.spring_layout(G, seed=42)
246
+ nx.draw(G, pos=pos, node_color='lightblue', node_size=500,
247
+ edge_color='gray', with_labels=True, font_size=10)
248
+ plt.title('Network Visualization', fontsize=16)
249
+ plt.axis('off')
250
+ plt.tight_layout()
251
+ plt.savefig('network.png', dpi=300, bbox_inches='tight')
252
+ plt.savefig('network.pdf', bbox_inches='tight') # Vector format
253
+ ```
254
+
255
+ **Reference**: See `references/visualization.md` for extensive documentation on visualization techniques including layout algorithms, customization options, interactive visualizations with Plotly and PyVis, 3D networks, and publication-quality figure creation.
256
+
257
+ ## Working with NetworkX
258
+
259
+ ### Installation
260
+
261
+ Ensure NetworkX is installed:
262
+ ```python
263
+ # Check if installed
264
+ import networkx as nx
265
+ print(nx.__version__)
266
+
267
+ # Install if needed (via bash)
268
+ # uv pip install networkx
269
+ # uv pip install networkx[default] # With optional dependencies
270
+ ```
271
+
272
+ ### Common Workflow Pattern
273
+
274
+ Most NetworkX tasks follow this pattern:
275
+
276
+ 1. **Create or Load Graph**:
277
+ ```python
278
+ # From scratch
279
+ G = nx.Graph()
280
+ G.add_edges_from([(1, 2), (2, 3), (3, 4)])
281
+
282
+ # Or load from file/data
283
+ G = nx.read_edgelist('data.txt')
284
+ ```
285
+
286
+ 2. **Examine Structure**:
287
+ ```python
288
+ print(f"Nodes: {G.number_of_nodes()}")
289
+ print(f"Edges: {G.number_of_edges()}")
290
+ print(f"Density: {nx.density(G)}")
291
+ print(f"Connected: {nx.is_connected(G)}")
292
+ ```
293
+
294
+ 3. **Analyze**:
295
+ ```python
296
+ # Compute metrics
297
+ degree_cent = nx.degree_centrality(G)
298
+ avg_clustering = nx.average_clustering(G)
299
+
300
+ # Find paths
301
+ path = nx.shortest_path(G, source=1, target=4)
302
+
303
+ # Detect communities
304
+ communities = community.greedy_modularity_communities(G)
305
+ ```
306
+
307
+ 4. **Visualize**:
308
+ ```python
309
+ pos = nx.spring_layout(G, seed=42)
310
+ nx.draw(G, pos=pos, with_labels=True)
311
+ plt.show()
312
+ ```
313
+
314
+ 5. **Export Results**:
315
+ ```python
316
+ # Save graph
317
+ nx.write_graphml(G, 'analyzed_network.graphml')
318
+
319
+ # Save metrics
320
+ df = pd.DataFrame({
321
+ 'node': list(degree_cent.keys()),
322
+ 'centrality': list(degree_cent.values())
323
+ })
324
+ df.to_csv('centrality_results.csv', index=False)
325
+ ```
326
+
327
+ ### Important Considerations
328
+
329
+ **Floating Point Precision**: When graphs contain floating-point numbers, all results are inherently approximate due to precision limitations. This can affect algorithm outcomes, particularly in minimum/maximum computations.
330
+
331
+ **Memory and Performance**: Each time a script runs, graph data must be loaded into memory. For large networks:
332
+ - Use appropriate data structures (sparse matrices for large sparse graphs)
333
+ - Consider loading only necessary subgraphs
334
+ - Use efficient file formats (pickle for Python objects, compressed formats)
335
+ - Leverage approximate algorithms for very large networks (e.g., `k` parameter in centrality calculations)
336
+ - For heavy workloads, NetworkX 3.x supports drop-in accelerated backends via the `backend=` keyword or `nx.config.backend_priority` — e.g. `nx-cugraph` (GPU), `nx-parallel` (multicore), `graphblas-algorithms` (sparse linear algebra). Install the backend package and pass `backend="cugraph"` (or similar) to supported functions; no algorithm code changes needed.
337
+
338
+ **Node and Edge Types**:
339
+ - Nodes can be any hashable Python object (numbers, strings, tuples, custom objects)
340
+ - Use meaningful identifiers for clarity
341
+ - When removing nodes, all incident edges are automatically removed
342
+
343
+ **Random Seeds**: Always set random seeds for reproducibility in random graph generation and force-directed layouts:
344
+ ```python
345
+ G = nx.erdos_renyi_graph(n=100, p=0.1, seed=42)
346
+ pos = nx.spring_layout(G, seed=42)
347
+ ```
348
+
349
+ ## Quick Reference
350
+
351
+ ### Basic Operations
352
+ ```python
353
+ # Create
354
+ G = nx.Graph()
355
+ G.add_edge(1, 2)
356
+
357
+ # Query
358
+ G.number_of_nodes()
359
+ G.number_of_edges()
360
+ G.degree(1)
361
+ list(G.neighbors(1))
362
+
363
+ # Check
364
+ G.has_node(1)
365
+ G.has_edge(1, 2)
366
+ nx.is_connected(G)
367
+
368
+ # Modify
369
+ G.remove_node(1)
370
+ G.remove_edge(1, 2)
371
+ G.clear()
372
+ ```
373
+
374
+ ### Essential Algorithms
375
+ ```python
376
+ # Paths
377
+ nx.shortest_path(G, source, target)
378
+ nx.all_pairs_shortest_path(G)
379
+
380
+ # Centrality
381
+ nx.degree_centrality(G)
382
+ nx.betweenness_centrality(G)
383
+ nx.closeness_centrality(G)
384
+ nx.pagerank(G)
385
+
386
+ # Clustering
387
+ nx.clustering(G)
388
+ nx.average_clustering(G)
389
+
390
+ # Components
391
+ nx.connected_components(G)
392
+ nx.strongly_connected_components(G) # Directed
393
+
394
+ # Community
395
+ community.greedy_modularity_communities(G)
396
+ ```
397
+
398
+ ### File I/O Quick Reference
399
+ ```python
400
+ # Read
401
+ nx.read_edgelist('file.txt')
402
+ nx.read_graphml('file.graphml')
403
+ nx.read_gml('file.gml')
404
+
405
+ # Write
406
+ nx.write_edgelist(G, 'file.txt')
407
+ nx.write_graphml(G, 'file.graphml')
408
+ nx.write_gml(G, 'file.gml')
409
+
410
+ # Pandas
411
+ nx.from_pandas_edgelist(df, 'source', 'target')
412
+ nx.to_pandas_edgelist(G)
413
+ ```
414
+
415
+ ## Resources
416
+
417
+ This skill includes comprehensive reference documentation:
418
+
419
+ ### references/graph-basics.md
420
+ Detailed guide on graph types, creating and modifying graphs, adding nodes and edges, managing attributes, examining structure, and working with subgraphs.
421
+
422
+ ### references/algorithms.md
423
+ Complete coverage of NetworkX algorithms including shortest paths, centrality measures, connectivity, clustering, community detection, flow algorithms, tree algorithms, matching, coloring, isomorphism, and graph traversal.
424
+
425
+ ### references/generators.md
426
+ Comprehensive documentation on graph generators including classic graphs, random models (Erdős-Rényi, Barabási-Albert, Watts-Strogatz), lattices, trees, social network models, and specialized generators.
427
+
428
+ ### references/io.md
429
+ Complete guide to reading and writing graphs in various formats: edge lists, adjacency lists, GraphML, GML, JSON, CSV, Pandas DataFrames, NumPy arrays, SciPy sparse matrices, database integration, and format selection guidelines.
430
+
431
+ ### references/visualization.md
432
+ Extensive documentation on visualization techniques including layout algorithms, customizing node and edge appearance, labels, interactive visualizations with Plotly and PyVis, 3D networks, bipartite layouts, and creating publication-quality figures.
433
+
434
+ ## Additional Resources
435
+
436
+ - **Official Documentation**: https://networkx.org/documentation/latest/
437
+ - **Tutorial**: https://networkx.org/documentation/latest/tutorial.html
438
+ - **Gallery**: https://networkx.org/documentation/latest/auto_examples/index.html
439
+ - **GitHub**: https://github.com/networkx/networkx
440
+
@@ -0,0 +1,22 @@
1
+ # Upstream Attribution
2
+
3
+ This skill is derived from the `networkx` skill in `K-Dense-AI/scientific-agent-skills`.
4
+
5
+ - **Upstream repository:** https://github.com/K-Dense-AI/scientific-agent-skills
6
+ - **Upstream path:** `skills/networkx/`
7
+ - **License:** 3-clause BSD (see [third_party/kdense-scientific-agent-skills/LICENSE](../../third_party/kdense-scientific-agent-skills/LICENSE))
8
+ - **Imported commit:** `390f5146bf3c1877cf15636a3dd7b775e4f0f185`
9
+ - **Import date:** 2026-08-25
10
+ - **Local path:** `skills/networkx/`
11
+
12
+ ## Imported Files
13
+
14
+ - `SKILL.md`
15
+ - `references/` (`algorithms.md`, `generators.md`, `graph-basics.md`, `io.md`, `visualization.md`)
16
+
17
+ ## Local modifications
18
+
19
+ Initial import:
20
+ - Local behavioral modifications: none (faithful vendoring, byte-for-byte identical to upstream).
21
+
22
+ Any future AgentLayer modifications must be documented here.