Quantum 3xplorer (Q3)
An AI-native quantum simulation engine
Loading...
Searching...
No Matches
main_utility.cpp
Go to the documentation of this file.
1/**
2 * q3_utility — Q3's utility binary: subcommands that consume a finished run's
3 * saved records rather than an input manifest.
4 *
5 * q3_utility interpolate <input.yml> evaluate a saved interpolation record
6 * along a k-path and/or on a DOS mesh
7 * q3_utility convert <save-directory> re-export a saved record (mean-field ->
8 * BerkeleyGW, interpolation -> Wannier90),
9 * or import Wannier90 files into one (--from)
10 * q3_utility volumetric <input.yml> a saved density, potential or band in a
11 * registered volumetric format (cube, xsf, ...)
12 *
13 * One binary with subcommands rather than one binary per task. The q3,
14 * q3_mpi and q3_gpu* names encode WHERE the engine runs, and a science- or
15 * format-facing suffix beside them (the former q3-wannier and q3-convert)
16 * mixed two axes on one name. Everything here is serial by construction --
17 * dense algebra on a few hundred orbitals, or file conversion -- so it never
18 * needs a variant. Each subcommand's implementation is one class under
19 * src/commands/; this file only dispatches.
20 */
21
22#include <exception>
23#include <string>
24#include <vector>
25
30#include "io/logger.hpp"
33
34using namespace q3;
35
36namespace {
37
38void print_usage() {
39 log::error("Usage: q3_utility [--log-level <level>] <subcommand> [arguments]");
40 log::error(" interpolate <input.yml> evaluate a saved interpolation record");
41 log::error(" convert <save-directory> re-export a saved record, or import Wannier90 files "
42 "(--from wannier90)");
43 log::error(" volumetric <input.yml> a saved density, potential or band as {}",
44 volumetric_field_writer_registry().canonical_names(", "));
45 log::error(" <subcommand> --help that subcommand's arguments");
46}
47
48} // namespace
49
50int main(int argc, char* argv[]) {
52 log::init();
53 std::vector<std::string> arguments(argv + 1, argv + argc);
54 if (arguments.size() >= 2 && arguments[0] == "--log-level") {
55 log::set_level(arguments[1]);
56 arguments.erase(arguments.begin(), arguments.begin() + 2);
57 }
58 if (arguments.empty()) {
59 print_usage();
60 return 1;
61 }
62 const std::string subcommand = arguments.front();
63 if (subcommand == "-h" || subcommand == "--help") {
64 print_usage();
65 return 0;
66 }
67 const std::vector<std::string> rest(arguments.begin() + 1, arguments.end());
68 try {
69 if (subcommand == "interpolate") {
70 return InterpolateCommand::run(rest);
71 }
72 if (subcommand == "convert") {
73 return ConvertCommand::run(rest);
74 }
75 if (subcommand == "volumetric") {
76 return VolumetricCommand::run(rest);
77 }
78 log::error("Unknown subcommand '{}'", subcommand);
79 print_usage();
80 return 1;
81 } catch (const DiagnosticError& error) {
82 /**
83 * The prose first, as for any error; then the failure's own lines,
84 * the code first, so a driver routes on the code while a reader
85 * still gets the sentence.
86 */
87 log::error("Error: {}", error.what());
88 for (const std::string& line : error.diagnostic_lines()) {
89 log::error("{}", line);
90 }
91 return 1;
92 } catch (const std::exception& error) {
93 log::error("Error: {}", error.what());
94 return 1;
95 }
96}
static int run(const std::vector< std::string > &arguments)
Returns the process exit code; argument errors print usage, everything else throws.
static int run(const std::vector< std::string > &arguments)
Returns the process exit code; argument errors print usage, everything else throws.
static int run(const std::vector< std::string > &arguments)
Returns the process exit code; argument errors print usage, everything else throws.
int main(int argc, char *argv[])
void register_all()
No add-on is compiled in, so there is nothing to register.
void print_usage(const std::string &binary_name)
Definition cli.hpp:140
void init(const std::string &log_file="")
Definition logger.hpp:59
void error(spdlog::format_string_t< Args... > fmt, Args &&... args)
Definition logger.hpp:192
void set_level(const std::string &level)
Set log level: "trace", "debug", "info", "warn", "error", "off".
Definition logger.hpp:94
Registry< NamedFactory< VolumetricFieldWriter > > & volumetric_field_writer_registry()
The registry create_volumetric_field_writer() builds writers from.
Definition factory.hpp:26