diff --git a/examples/tensor_network_graphs/tensor_network_graphs.cpp b/examples/tensor_network_graphs/tensor_network_graphs.cpp index f17315e29..a6cd73e1a 100644 --- a/examples/tensor_network_graphs/tensor_network_graphs.cpp +++ b/examples/tensor_network_graphs/tensor_network_graphs.cpp @@ -34,13 +34,38 @@ std::optional 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 << " [options] [ [... [] ] ]\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(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); @@ -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); }