From 8f1d1a3fc0776ef63b9e87d37c64030ad4900503 Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Mon, 9 Dec 2024 13:29:46 -0800 Subject: [PATCH 1/9] Add a status command that prints all currently defined parameters. --- src/inq/inq.hpp | 1 + src/interface/status.hpp | 94 ++++++++++++++++++++++++++++++++++++++++ src/main/inq.cpp | 1 + 3 files changed, 96 insertions(+) create mode 100644 src/interface/status.hpp diff --git a/src/inq/inq.hpp b/src/inq/inq.hpp index a068a4e3..950713e0 100644 --- a/src/inq/inq.hpp +++ b/src/inq/inq.hpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include diff --git a/src/interface/status.hpp b/src/interface/status.hpp new file mode 100644 index 00000000..700e3915 --- /dev/null +++ b/src/interface/status.hpp @@ -0,0 +1,94 @@ +/* -*- indent-tabs-mode: t -*- */ + +#ifndef INQ__INTERFACE__STATUS +#define INQ__INTERFACE__STATUS + +// Copyright (C) 2019-2024 Lawrence Livermore National Security, LLC., Xavier Andrade, Alfredo A. Correa +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace inq { +namespace interface { + +struct { + + constexpr auto name() const { + return "status"; + } + + constexpr auto one_line() const { + return "Shows the status of the currently simulation"; + } + + constexpr auto help() const { + return R""""( + +The 'status' command +================== + +Prints all the currently defined parameters and available results. + +)""""; + } + + static void status() { + interface::cell.status(); + interface::ions.status(); + interface::electrons.status(); + interface::kpoints.status(); + interface::ground_state.status(); + interface::results_ground_state.status(); + interface::real_time.status(); + interface::results_real_time.status(); + } + + template + void command(ArgsType const & args, bool quiet) const { + + using utils::str_to; + + if(args.size() == 0) { + status(); + actions::normal_exit(); + } + + if(input::environment::global().comm().root()) actions::error(input::environment::global().comm(), "Invalid syntax in the status command"); + } + +#ifdef INQ_PYTHON_INTERFACE + template + void python_interface(PythonModule & module) const { + module.def("status", &status); + } +#endif + +} const status; + +} +} +#endif + +#ifdef INQ_INTERFACE_STATUS_UNIT_TEST +#undef INQ_INTERFACE_STATUS_UNIT_TEST + +#include + +TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG) { + + using namespace inq; + using namespace Catch::literals; + +} +#endif diff --git a/src/main/inq.cpp b/src/main/inq.cpp index 0c1d38ad..021e1adb 100644 --- a/src/main/inq.cpp +++ b/src/main/inq.cpp @@ -32,6 +32,7 @@ int main(int argc, char* argv[]) { + interface::item(interface::run) + interface::item(interface::species) + interface::item(interface::spectrum) + + interface::item(interface::status) + interface::item(interface::theory) + interface::item(interface::util); From dfc30a2b176d7edabcc91061eb5d392442972951 Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Mon, 9 Dec 2024 14:20:13 -0800 Subject: [PATCH 2/9] Add a newline after the "* default value" line. --- src/interface/status.hpp | 2 +- src/options/electrons.hpp | 2 +- src/options/ground_state.hpp | 2 +- src/options/real_time.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/interface/status.hpp b/src/interface/status.hpp index 700e3915..9949873f 100644 --- a/src/interface/status.hpp +++ b/src/interface/status.hpp @@ -46,8 +46,8 @@ Prints all the currently defined parameters and available results. static void status() { interface::cell.status(); interface::ions.status(); - interface::electrons.status(); interface::kpoints.status(); + interface::electrons.status(); interface::ground_state.status(); interface::results_ground_state.status(); interface::real_time.status(); diff --git a/src/options/electrons.hpp b/src/options/electrons.hpp index 545e9c1f..065554c2 100644 --- a/src/options/electrons.hpp +++ b/src/options/electrons.hpp @@ -218,7 +218,7 @@ class electrons { if(not self.spin_.has_value()) out << " *"; out << "\n"; - out << "\n * default values" << std::endl; + out << "\n * default values\n" << std::endl; return out; } diff --git a/src/options/ground_state.hpp b/src/options/ground_state.hpp index 9db2ee82..16393746 100644 --- a/src/options/ground_state.hpp +++ b/src/options/ground_state.hpp @@ -212,7 +212,7 @@ class ground_state { if(not self.mixing_.has_value()) out << " *"; out << "\n"; - out << "\n * default values" << std::endl; + out << "\n * default values\n" << std::endl; return out; } diff --git a/src/options/real_time.hpp b/src/options/real_time.hpp index 6e29e2a1..091d96d6 100644 --- a/src/options/real_time.hpp +++ b/src/options/real_time.hpp @@ -265,7 +265,7 @@ class real_time { if(self.obs_.empty()) out << " *"; out << "\n"; - out << "\n * default values" << std::endl; + out << "\n * default values\n" << std::endl; return out; } From 050d40600c6f08e446639ce4be9986f408262e37 Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Mon, 9 Dec 2024 17:40:21 -0800 Subject: [PATCH 3/9] Print status when calling `inq` without arguments. --- src/main/inq.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/inq.cpp b/src/main/inq.cpp index 021e1adb..79b44cad 100644 --- a/src/main/inq.cpp +++ b/src/main/inq.cpp @@ -41,18 +41,7 @@ int main(int argc, char* argv[]) { + interface::item(interface::results); if(argc == 1){ - if(comm.root()) { - std::cout << "\n"; - std::cout << "Usage: inq [arguments]\n\n"; - std::cout << "The following commands are available:\n"; - std::cout << interface::list_item("help", "Prints detailed information about other commands"); - std::cout << all_commands.list(); - std::cout << "\n"; - std::cout << "And the following options:\n"; - std::cout << interface::list_item("-q,--quiet", "Run silently, do not print information unless explicitly asked to"); - std::cout << interface::list_item("-d,--debug", "Print debug information (useful for inq developers)"); - std::cout << std::endl; - } + interface::status.status(); interface::actions::normal_exit(); } @@ -134,10 +123,16 @@ int main(int argc, char* argv[]) { if(args.size() == 0){ if(comm.root()) { std::cout << "\n"; - std::cout << "Usage: inq help \n\n"; - std::cout << "The 'help' command prints detailed information about other inq commands:\n\n"; + std::cout << "Usage: inq [arguments]\n\n"; + std::cout << "The following commands are available:\n"; + std::cout << interface::list_item("help", "Prints detailed information about other commands"); std::cout << all_commands.list(); - std::cout << "\nThere is also some additional help topics you can read:\n\n"; + std::cout << "\n"; + std::cout << "And the following options:\n"; + std::cout << interface::list_item("-q,--quiet", "Run silently, do not print information unless explicitly asked to"); + std::cout << interface::list_item("-d,--debug", "Print debug information (useful for inq developers)"); + std::cout << "\nTo get more information about any command use: inq help \n"; + std::cout << "\nBesides commands, there is also some additional help topics you can read with 'help':\n\n"; std::cout << all_helpers.list(); std::cout << std::endl; } From 4d31943f095850638832336cbd243d92a8170f3a Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Mon, 9 Dec 2024 17:49:09 -0800 Subject: [PATCH 4/9] Add a -h option to inq. --- src/main/inq.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/inq.cpp b/src/main/inq.cpp index 79b44cad..32a81729 100644 --- a/src/main/inq.cpp +++ b/src/main/inq.cpp @@ -60,6 +60,11 @@ int main(int argc, char* argv[]) { for(int iarg = 1; iarg < argc; iarg++) { auto arg = std::string(argv[iarg]); + if(arg == "-h" or arg == "--help") { + args = {"help"}; + break; + } + if(arg == "-q" or arg == "--quiet") { quiet = true; continue; @@ -129,6 +134,7 @@ int main(int argc, char* argv[]) { std::cout << all_commands.list(); std::cout << "\n"; std::cout << "And the following options:\n"; + std::cout << interface::list_item("-h,--help", "Prints this help dialog"); std::cout << interface::list_item("-q,--quiet", "Run silently, do not print information unless explicitly asked to"); std::cout << interface::list_item("-d,--debug", "Print debug information (useful for inq developers)"); std::cout << "\nTo get more information about any command use: inq help \n"; From e949f4e04748d1f63490de2ef78e4e1e1389b43c Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Mon, 9 Dec 2024 17:54:35 -0800 Subject: [PATCH 5/9] Handle the no arguments case in a better way. --- src/main/inq.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/inq.cpp b/src/main/inq.cpp index 32a81729..c67054f3 100644 --- a/src/main/inq.cpp +++ b/src/main/inq.cpp @@ -40,11 +40,6 @@ int main(int argc, char* argv[]) { interface::item(interface::units) + interface::item(interface::results); - if(argc == 1){ - interface::status.status(); - interface::actions::normal_exit(); - } - interface::history_file.add_entry(argc, argv); auto quiet = false; @@ -118,7 +113,11 @@ int main(int argc, char* argv[]) { } std::cout << "|" << std::endl; } - + + if(args.size() == 0){ + args = {"status"}; + } + auto command = args[0]; args.erase(args.begin()); From 7a2541be7fd585f6ebd67e268768363b93a1956c Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Mon, 9 Dec 2024 18:13:31 -0800 Subject: [PATCH 6/9] Add a status member to theory. --- src/interface/theory.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/interface/theory.hpp b/src/interface/theory.hpp index e0367a84..0a62059e 100644 --- a/src/interface/theory.hpp +++ b/src/interface/theory.hpp @@ -121,10 +121,14 @@ These are the options available: )""""; } - void operator()() const { + static void status() { auto theo = options::theory::load(".inq/default_theory"); if(input::environment::global().comm().root()) std::cout << theo; } + + void operator()() const { + status(); + } void non_interacting() const{ auto theo = options::theory::load(".inq/default_theory").non_interacting(); From ceb27a1832614244ceb8366ae4d323b6e90fbba3 Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Mon, 9 Dec 2024 18:13:43 -0800 Subject: [PATCH 7/9] Improve the output for options::theory. --- src/options/theory.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/options/theory.hpp b/src/options/theory.hpp index 0b27aab5..90ae7584 100644 --- a/src/options/theory.hpp +++ b/src/options/theory.hpp @@ -165,13 +165,13 @@ class theory { out << "Theory:\n"; if(not self.hartree_potential() and self.exchange() == XC_NONE and self.correlation() == XC_NONE){ - out << " Non-interacting electrons" << std::endl; + out << " non-interacting electrons\n" << std::endl; return out; } if(self.hartree_potential() and self.exchange() == XC_NONE and self.correlation() == XC_NONE){ - out << " Hartree (with self-interaction)\n\n"; - out << " [1] D. R. Hartree, Math. Proc. Camb. Philos. Soc. 24 1, 111 (1928)" << std::endl; + out << " Hartree (with self-interaction)\n\n"; + out << " [1] D. R. Hartree, Math. Proc. Camb. Philos. Soc. 24 1, 111 (1928)\n" << std::endl; return out; } @@ -190,6 +190,8 @@ class theory { out << " " << c_func.family_name() << " - " << c_func.name() << "\n\n"; out << c_func.references(" ") << "\n"; } + + out << std::endl; return out; } From a3ac654092a1f0d589bf3392f23a322521bd144f Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Mon, 9 Dec 2024 18:14:05 -0800 Subject: [PATCH 8/9] Print the species and the theory for inq status. --- src/interface/status.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/interface/status.hpp b/src/interface/status.hpp index 9949873f..de752286 100644 --- a/src/interface/status.hpp +++ b/src/interface/status.hpp @@ -18,6 +18,8 @@ #include #include #include +#include +#include namespace inq { namespace interface { @@ -46,8 +48,10 @@ Prints all the currently defined parameters and available results. static void status() { interface::cell.status(); interface::ions.status(); + interface::species.status(); interface::kpoints.status(); interface::electrons.status(); + interface::theory.status(); interface::ground_state.status(); interface::results_ground_state.status(); interface::real_time.status(); From f1ca0e774927145296dcbfe7f44b906c862bd872 Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Tue, 10 Dec 2024 07:34:11 -0800 Subject: [PATCH 9/9] Do not run inq by itself for the moment, it fails for an empty directory. --- tests/help.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/help.sh b/tests/help.sh index 6d3578c1..fb9055f3 100755 --- a/tests/help.sh +++ b/tests/help.sh @@ -5,7 +5,6 @@ set -x #output commands to the terminal #Test the help commands -inq inq help inq help clear inq help cell