Skip to content

Commit

Permalink
Merge branch 'status_command' into 'master'
Browse files Browse the repository at this point in the history
Status command

See merge request npneq/inq!1171
  • Loading branch information
xavierandrade committed Dec 10, 2024
2 parents 70e7ce4 + f1ca0e7 commit 972817a
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/inq/inq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <interface/run.hpp>
#include <interface/species.hpp>
#include <interface/spectrum.hpp>
#include <interface/status.hpp>
#include <interface/theory.hpp>
#include <interface/units.hpp>
#include <interface/util.hpp>
Expand Down
98 changes: 98 additions & 0 deletions src/interface/status.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* -*- 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 <input/environment.hpp>
#include <interface/cell.hpp>
#include <interface/ions.hpp>
#include <interface/electrons.hpp>
#include <interface/kpoints.hpp>
#include <interface/ground_state.hpp>
#include <interface/results_ground_state.hpp>
#include <interface/real_time.hpp>
#include <interface/results_real_time.hpp>
#include <interface/species.hpp>
#include <interface/theory.hpp>

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::species.status();
interface::kpoints.status();
interface::electrons.status();
interface::theory.status();
interface::ground_state.status();
interface::results_ground_state.status();
interface::real_time.status();
interface::results_real_time.status();
}

template <typename ArgsType>
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 <class PythonModule>
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 <catch2/catch_all.hpp>

TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG) {

using namespace inq;
using namespace Catch::literals;

}
#endif
6 changes: 5 additions & 1 deletion src/interface/theory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
41 changes: 21 additions & 20 deletions src/main/inq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,14 @@ 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);

auto all_helpers =
interface::item(interface::units)
+ interface::item(interface::results);

if(argc == 1){
if(comm.root()) {
std::cout << "\n";
std::cout << "Usage: inq <command> [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::actions::normal_exit();
}

interface::history_file.add_entry(argc, argv);

auto quiet = false;
Expand All @@ -70,6 +55,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;
Expand Down Expand Up @@ -123,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());

Expand All @@ -133,10 +127,17 @@ int main(int argc, char* argv[]) {
if(args.size() == 0){
if(comm.root()) {
std::cout << "\n";
std::cout << "Usage: inq help <command>\n\n";
std::cout << "The 'help' command prints detailed information about other inq commands:\n\n";
std::cout << "Usage: inq <command> [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("-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 <command>\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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/options/electrons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/options/ground_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/options/real_time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions src/options/theory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion tests/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set -x #output commands to the terminal

#Test the help commands

inq
inq help
inq help clear
inq help cell
Expand Down

0 comments on commit 972817a

Please sign in to comment.