From 7854d43eec2f301bf2191bceb732e282d2995487 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Mon, 12 Feb 2024 09:25:55 +0100 Subject: [PATCH] Format TN creator source code --- .../tensor_network_graphs.cpp | 123 +++++++++--------- 1 file changed, 64 insertions(+), 59 deletions(-) diff --git a/examples/tensor_network_graphs/tensor_network_graphs.cpp b/examples/tensor_network_graphs/tensor_network_graphs.cpp index a6cd73e1a..c3f977c8f 100644 --- a/examples/tensor_network_graphs/tensor_network_graphs.cpp +++ b/examples/tensor_network_graphs/tensor_network_graphs.cpp @@ -1,88 +1,93 @@ -#include #include #include +#include #include #include -#include #include #include -#include #include +#include #include +#include - using namespace sequant; +using namespace sequant; std::wstring from_utf8(std::string_view str) { - std::wstring_convert> converter; - return converter.from_bytes(std::string(str)); + std::wstring_convert> converter; + return converter.from_bytes(std::string(str)); } std::optional to_network(const ExprPtr &expr) { - if (expr.is()) { - return TensorNetwork({expr}); - } else if (expr.is()) { - for (const ExprPtr &factor : expr.as().factors()) { - if (!factor.is()) { - return {}; - } - } + if (expr.is()) { + return TensorNetwork({expr}); + } else if (expr.is()) { + for (const ExprPtr &factor : expr.as().factors()) { + if (!factor.is()) { + return {}; + } + } - return TensorNetwork(expr.as().factors()); - } else { - return {}; - } + return TensorNetwork(expr.as().factors()); + } else { + return {}; + } } 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"; + 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(); - set_locale(); - mbpt::set_default_convention(); - - bool use_named_indices = true; - const TensorNetwork::named_indices_t empty_named_indices; + bool use_named_indices = true; + const TensorNetwork::named_indices_t empty_named_indices; - if (argc <= 1) { - print_help(); - return 1; - } + 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; - } + 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); - } catch (const ParseError &e) { - std::wcout << "Failed to parse expression '" << current << "': " << e.what() << std::endl; - return 1; - } - assert(expr); + ExprPtr expr; + try { + expr = parse_expr(current); + } catch (const ParseError &e) { + std::wcout << "Failed to parse expression '" << current + << "': " << e.what() << std::endl; + return 1; + } + assert(expr); - std::optional network = to_network(expr); - if (!network.has_value()) { - std::wcout << "Failed to construct tensor network for input '" << current << "'" << std::endl; - return 2; - } + std::optional network = to_network(expr); + if (!network.has_value()) { + std::wcout << "Failed to construct tensor network for input '" << current + << "'" << std::endl; + return 2; + } - 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); - } + 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); + } }