27#include "context/input_schema.hpp"
29#include <unordered_set>
35static std::ostringstream
36option_print_vector__(
const std::vector<T>& vec)
38 std::ostringstream out;
41 for (
auto i = 0u; i < vec.size(); i++) {
42 out <<
", " << vec[i];
55 for (
auto it : schema__.items()) {
58 if (it.value().contains(
"type") && it.value()[
"type"] !=
"object") {
60 if (it.value().contains(
"default")) {
61 output__[key] = it.value()[
"default"];
64 if (!output__.contains(key)) {
65 output__[key] = nlohmann::json{};
67 if (it.value().contains(
"properties")) {
78compose_json(nlohmann::json
const& schema__, nlohmann::json
const& in__, nlohmann::json& inout__)
80 std::unordered_set<std::string> visited;
82 for (
auto it : in__.items()) {
83 visited.insert(it.key());
86 for (
auto it : schema__.items()) {
90 auto found = visited.find(key);
91 if (found != visited.end()) {
96 if (it.value().contains(
"type") && it.value()[
"type"] !=
"object") {
97 if (in__.contains(key)) {
99 inout__[key] = in__[key];
102 if (it.value().contains(
"properties")) {
103 compose_json(it.value()[
"properties"], in__.contains(key) ? in__[key] : nlohmann::json{}, inout__[key]);
104 }
else if (in__.contains(key)) {
105 inout__[key] = in__[key];
107 inout__[key] = nlohmann::json();
113 if (!visited.empty()) {
114 std::stringstream ss;
115 ss <<
"The following configuration parameters were not recognized and ignored: ";
116 std::copy(visited.begin(), visited.end(), std::ostream_iterator<std::string>(ss,
" "));
128Config::import(nlohmann::json
const& in__)
131 compose_json(sirius::input_schema[
"properties"], in__, this->dict_);
138 if (input_schema.size() == 0) {
139 throw std::runtime_error(
"Dictionary not initialized\n");
148 if (input_schema.size() == 0) {
149 throw std::runtime_error(
"Dictionary not initialized\n");
151 return input_schema[
"properties"][section__][
"properties"];
157 auto json = read_json_from_file_or_string(str__);
170 cfg_.control().processing_unit(args__.
value(
"control.processing_unit",
cfg_.control().processing_unit()));
171 cfg_.control().mpi_grid_dims(args__.
value(
"control.mpi_grid_dims",
cfg_.control().mpi_grid_dims()));
172 cfg_.control().std_evp_solver_name(
173 args__.
value(
"control.std_evp_solver_name",
cfg_.control().std_evp_solver_name()));
174 cfg_.control().gen_evp_solver_name(
175 args__.
value(
"control.gen_evp_solver_name",
cfg_.control().gen_evp_solver_name()));
176 cfg_.control().fft_mode(args__.
value(
"control.fft_mode",
cfg_.control().fft_mode()));
177 cfg_.control().verbosity(args__.
value(
"control.verbosity",
cfg_.control().verbosity()));
178 cfg_.control().verification(args__.
value(
"control.verification",
cfg_.control().verification()));
180 cfg_.parameters().ngridk(args__.
value(
"parameters.ngridk",
cfg_.parameters().ngridk()));
181 cfg_.parameters().gamma_point(args__.
value(
"parameters.gamma_point",
cfg_.parameters().gamma_point()));
182 cfg_.parameters().pw_cutoff(args__.
value(
"parameters.pw_cutoff",
cfg_.parameters().pw_cutoff()));
183 cfg_.parameters().gk_cutoff(args__.
value(
"parameters.gk_cutoff",
cfg_.parameters().gk_cutoff()));
185 cfg_.iterative_solver().early_restart(
186 args__.
value(
"iterative_solver.early_restart",
cfg_.iterative_solver().early_restart()));
187 cfg_.mixer().beta(args__.
value(
"mixer.beta",
cfg_.mixer().beta()));
188 cfg_.mixer().type(args__.
value(
"mixer.type",
cfg_.mixer().type()));
192Simulation_parameters::core_relativity(std::string name__)
194 cfg_.parameters().core_relativity(name__);
199Simulation_parameters::valence_relativity(std::string name__)
201 cfg_.parameters().valence_relativity(name__);
206Simulation_parameters::processing_unit(std::string name__)
209 if (name__ ==
"auto") {
216 cfg_.control().processing_unit(name__);
221Simulation_parameters::smearing(std::string name__)
223 cfg_.parameters().smearing(name__);
224 smearing_ = smearing::get_smearing_t(name__);
228Simulation_parameters::electronic_structure_method(std::string name__)
230 cfg_.parameters().electronic_structure_method(name__);
232 std::map<std::string, electronic_structure_method_t> m = {
236 if (m.count(name__) == 0) {
238 s <<
"wrong type of electronic structure method: " << name__;
sddk::device_t processing_unit_
Type of the processing unit.
smearing::smearing_t smearing_
Type of occupation numbers smearing.
relativity_t valence_relativity_
Type of relativity for valence states.
void import(std::string const &str__)
Import parameters from a file or a serialized json string.
Config cfg_
All user-provided paramters are stored here.
relativity_t core_relativity_
Type of relativity for core states.
electronic_structure_method_t electronic_structure_method_
Type of electronic structure method.
Simple command line arguments handler.
T value(std::string const key__) const
Get a value or terminate if key is not found.
Contains declaration and implementation of mpi::Communicator class.
int num_devices()
Get the number of devices.
void copy(T *target__, T const *source__, size_t n__)
Copy memory inside a device.
Namespace of the SIRIUS library.
@ full_potential_lapwlo
Full potential linearized augmented plane waves with local orbitals.
@ pseudopotential
Pseudopotential (ultrasoft, norm-conserving, PAW).
void compose_json(nlohmann::json const &schema__, nlohmann::json const &in__, nlohmann::json &inout__)
Append the input dictionary to the existing dictionary.
nlohmann::json const & get_section_options(std::string const §ion__)
Get all possible options of a given input section. It is a json dictionary.
void compose_default_json(nlohmann::json const &schema__, nlohmann::json &output__)
Compose JSON dictionary with default parameters based on input schema.
nlohmann::json const & get_options_dictionary()
Get all possible options for initializing sirius. It is a json dictionary.
Contains definition and implementation of sirius::Simulation_parameters class.