Skip to content

Commit

Permalink
Add options to TN graph creator
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzmbrzl committed Feb 12, 2024
1 parent 0affb2d commit 6168690
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion examples/tensor_network_graphs/tensor_network_graphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,38 @@ std::optional<TensorNetwork> to_network(const ExprPtr &expr) {
}
}

void print_help() {
std::wcout << "Helper to generate dot (GraphViz) representations of tensor network graphs.\n";
std::wcout << "Usage:\n";
std::wcout << " <exe> [options] <network 1> [<network 2> [... [<network N>] ] ]\n";
std::wcout << "Options:\n";
std::wcout << " --help Shows this help message\n";
std::wcout << " --no-named Treat all indices as unnamed (even if they are external)\n";
}

int main(int argc, char **argv) {

set_locale();
mbpt::set_default_convention();

bool use_named_indices = true;
const TensorNetwork::named_indices_t empty_named_indices;

if (argc <= 1) {
print_help();
return 1;
}

for (std::size_t i = 1; i < static_cast<std::size_t>(argc); ++i) {
std::wstring current = from_utf8(argv[i]);
if (current == L"--help") {
print_help();
return 0;
} else if (current == L"--no-named") {
use_named_indices = false;
continue;
}

ExprPtr expr;
try {
expr = parse_expr(current);
Expand All @@ -56,7 +81,7 @@ int main(int argc, char **argv) {
return 2;
}

TensorNetwork::Graph graph = network->create_graph();
TensorNetwork::Graph graph = network->create_graph(use_named_indices ? nullptr : &empty_named_indices);
std::wcout << "Graph for '" << current << "'\n";
graph.bliss_graph->write_dot(std::wcout, graph.vertex_labels);
}
Expand Down

0 comments on commit 6168690

Please sign in to comment.