Getting started#
dynG is a C++17 library with a Python package on top. The Python package (pip install dyng)
contains the sequential and OpenMP backends and needs no GPU; the CUDA backend comes with the C++
build and, from 0.2, as the Python plugin wheels dyng-cu12 / dyng-cu13
(pip install "dyng[cu13]", Install).
A first result in ten lines, in Python:
import dyng
# A weighted directed graph: edges 0->1 (4), 0->2 (1), 2->1 (2), 1->3 (1).
g = dyng.Graph.from_edges([0, 0, 2, 1], [1, 2, 1, 3], [4, 1, 2, 1])
tree = dyng.sssp.compute(g, source=0) # shortest paths from vertex 0
print(tree.distances.tolist())
batch = dyng.EdgeBatch(insert=([2], [3], [1]), delete=([2], [1]))
stats = dyng.sssp.update(g, batch, tree) # applies the batch, repairs the tree
print(tree.distances.tolist(), stats.invalidated)
and in C++:
#include <dyng/dyng.hpp>
#include <iostream>
int main() {
auto res = dyng::resources::sequential(); // or openmp(), cuda()
dyng::edge_list<std::int32_t, std::int32_t> edges{4, {0, 0, 2, 1}, {1, 2, 1, 3}, {4, 1, 2, 1}, 1};
auto g = dyng::graph<>::from_edges(res, edges.view()); // 4 vertices, one weight per edge
auto tree = dyng::sssp::compute(res, g, /*source=*/0); // shortest paths from vertex 0
dyng::edge_batch<std::int32_t, std::int32_t> batch;
batch.delete_edge(2, 1);
batch.insert_edge(2, 3, {1});
auto st = dyng::sssp::update(res, g, batch.view(), tree); // applies the batch, repairs the tree
for (auto d : dyng::to_vector(res, tree.distances())) std::cout << d << ' ';
std::cout << "| invalidated " << st.invalidated << '\n';
}
Both are the README’s quickstarts, which the test suite runs (the Python one prints
[0, 3, 1, 4] and then [0, 4, 1, 2] 2, the C++ one 0 4 1 2 | invalidated 2).