Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions include/sqsgen/core/optimization_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,8 @@ namespace sqsgen::core {
template <class T, SublatticeMode Mode> struct optimization_config : optimization_config_data<T> {
sqsgen::core::shuffler shuffler;

static std::optional<std::uint64_t> seed_for_sublattice(
seed_t const& seed, std::size_t index) {
if (!seed.has_value()) return std::nullopt;
auto const& seeds = seed.value();
if (seeds.size() == 1)
return seeds[0].has_value()
? std::optional{seeds[0].value() + static_cast<std::uint64_t>(index)}
: std::nullopt;
static std::optional<std::uint64_t> seed_for_sublattice(seed_t const& seeds,
std::size_t index) {
if (index < seeds.size()) return seeds[index];
return std::nullopt;
}
Expand Down Expand Up @@ -98,8 +92,7 @@ namespace sqsgen::core {
std::move(config.target_objective[i]),
std::move(config.shell_radii[i]),
std::move(config.shell_weights[i]),
core::shuffler({bounds[i]},
seed_for_sublattice(config.seed, i))});
core::shuffler({bounds[i]}, seed_for_sublattice(config.seed, i))});
}
return configs;
}
Expand Down
81 changes: 47 additions & 34 deletions include/sqsgen/io/config/combined.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,34 @@
}

template <string_literal key, class Document>
parse_result<seed_t> parse_seed(Document const& document) {
parse_result<seed_t> parse_seed(Document const& document, SublatticeMode sublattice_mode,
IterationMode iteration_mode,
std::vector<sublattice> const& composition) {
using result_t = parse_result<seed_t>;
using seed_list_t = std::vector<std::optional<std::uint64_t>>;
if (auto seed = get_either_optional<key, std::uint64_t, seed_list_t>(document);
seed.has_value())
return seed.value().template collapse<seed_t>(
[](std::uint64_t&& value) -> result_t { return {seed_t{seed_list_t{value}}}; },
[](seed_list_t&& values) -> result_t { return {seed_t{std::move(values)}}; });
return {seed_t{std::nullopt}};
auto num_sublattices = sublattice_mode == SUBLATTICE_MODE_INTERACT ? 1 : composition.size();
if (auto seed = get_either_optional<key, std::uint64_t, seed_t>(document); seed.has_value()) {
if (iteration_mode == ITERATION_MODE_SYSTEMATIC)
return parse_error::from_msg<key, CODE_BAD_ARGUMENT>(
"You cannot specify a seed if you have set the iteration mode to \"systematic\". The "
"seed is only used for random iterations, but in systematic mode there is no "
"randomness involved.");
else
// here we have random mode with a value
return seed.value().template collapse<seed_t>(
[num_sublattices](std::uint64_t&& value) -> result_t {
return seed_t(num_sublattices, std::make_optional(value));
},
[num_sublattices](seed_t&& values) -> result_t {
if (values.size() != num_sublattices)
return parse_error::from_msg<key, CODE_BAD_VALUE>(format_string(
"The number of seeds provided (%u) does not match the number of sublattices "
"(%u)",
values.size(), num_sublattices));
return values;

Check failure on line 71 in include/sqsgen/io/config/combined.h

View workflow job for this annotation

GitHub Actions / build

could not convert ‘values’ from ‘sqsgen::seed_t’ {aka ‘std::vector<std::optional<long unsigned int> >’} to ‘result_t’ {aka ‘sqsgen::io::parse_result<std::vector<std::optional<long unsigned int>, std::allocator<std::optional<long unsigned int> > > >’}
});
} else
// Choose proper default values
return seed_t(num_sublattices, std::nullopt);
}

template <string_literal key, class Document, class T>
Expand Down Expand Up @@ -174,22 +193,22 @@
auto validation_result = accessor<Document>::validate_keys(doc, KNOWN_KEYS);
if (validation_result.has_value()) return {*validation_result};
return parse_iteration_mode<"iteration_mode">(doc)
.combine(parse_seed<"seed">(doc))
.combine(parse_sublattice_mode<"sublattice_mode">(doc))
.and_then([](auto&& modes)
-> parse_result<std::tuple<IterationMode, seed_t,
SublatticeMode>> {
auto [iteration_mode, seed, sublattice_mode] = modes;
if (iteration_mode == ITERATION_MODE_SYSTEMATIC
&& sublattice_mode == SUBLATTICE_MODE_SPLIT)
return {parse_error::from_msg<"iteration_mode", CODE_BAD_VALUE>(
"It is not possible to do an exhaustive search on multiple sublattices in mode "
"\"split\"")};
return modes;
})
.combine(parse_structure_config<"structure", T>(doc))
.and_then([&](auto&& sc_and_modes) {
auto [iteration_mode, seed, sublattice_mode, sc] = sc_and_modes;
.and_then(
[](auto&& modes)
-> parse_result<std::tuple<IterationMode, SublatticeMode, structure_config<T>>> {
auto [iteration_mode, sublattice_mode, _] = modes;
if (iteration_mode == ITERATION_MODE_SYSTEMATIC
&& sublattice_mode == SUBLATTICE_MODE_SPLIT)
return {parse_error::from_msg<"iteration_mode", CODE_BAD_VALUE>(
"It is not possible to do an exhaustive search on multiple sublattices in mode "
"\"split\"")};
return modes;
})

.and_then([&](auto&& modes_and_sc) {
auto [iteration_mode, sublattice_mode, sc] = modes_and_sc;
auto structure = sc.structure();
return config::parse_composition<"composition", "sites">(doc, structure.species,
sublattice_mode)
Expand All @@ -200,8 +219,9 @@
.combine(parse_iterations<"iterations">(
doc, std::forward<core::structure<T>>(structure), composition,
iteration_mode))
.and_then([&](auto&& radii_and_iterations) {
auto [radii, iterations] = radii_and_iterations;
.combine(parse_seed<"seed">(doc, sublattice_mode, iteration_mode, composition))
.and_then([&](auto&& radii_and_iterations_and_seed) {
auto [radii, iterations, seed] = radii_and_iterations_and_seed;
return config::parse_shell_weights<"shell_weights", T>(doc, sublattice_mode,
radii)
.and_then([&](auto&& weights) {
Expand All @@ -227,22 +247,15 @@
auto [prefactors, pair_weights, target_objective, chunk_size,
thread_config, to_keep, max_results_per_objective]
= arrays;
if (seed.has_value()
if (std::any_of(seed.begin(), seed.end(),
[](auto s) { return s.has_value(); })
&& std::any_of(thread_config.begin(), thread_config.end(),
[](auto t) { return t > 1; }))
return {parse_error::from_msg<"seed", CODE_BAD_VALUE>(
"A random seed is set but the thread configuration "
"specifies more than 1 thread; seeded runs require "
"(currently) "
"exactly 1 thread for reproducibility")};
if (seed.has_value()
&& seed.value().size() != 1
&& seed.value().size() != composition.size())
return {parse_error::from_msg<"seed", CODE_BAD_VALUE>(
format_string(
"The seed list has %u entries but the configuration "
"has %u sublattice(s); provide either a single seed "
"or one per sublattice",
seed.value().size(), composition.size()))};
return configuration<T>{
sublattice_mode,
iteration_mode,
Expand Down
9 changes: 1 addition & 8 deletions include/sqsgen/io/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,7 @@
static void from_json(const json& j, core::configuration<T>& c) {
j.at("sublattice_mode").get_to<SublatticeMode>(c.sublattice_mode);
j.at("iteration_mode").get_to<IterationMode>(c.iteration_mode);
if (j.contains("seed") && !j.at("seed").is_null()) {
auto const& s = j.at("seed");
if (s.is_number_unsigned())
c.seed = std::vector<std::optional<std::uint64_t>>{s.get<std::uint64_t>()};
else
c.seed = s.get<std::vector<std::optional<std::uint64_t>>>();
} else
c.seed = std::nullopt;
j.at("seed").get_to<seed_t>(c.seed);
j.at("structure").get_to<core::structure_config<T>>(c.structure);
j.at("composition").get_to<std::vector<sublattice>>(c.composition);
j.at("shell_radii").get_to<stl_matrix_t<T>>(c.shell_radii);
Expand Down Expand Up @@ -381,7 +374,7 @@
static constexpr bool available = true;
static bool is(nlohmann::json const& json) {
return json.is_array()
&& ranges::all_of(json, [](auto&& el) { return type_checker<T>::is(el); });

Check failure on line 377 in include/sqsgen/io/json.h

View workflow job for this annotation

GitHub Actions / build

no member named 'is' in 'sqsgen::io::accessor<nlohmann::basic_json<>>::type_checker<std::optional<unsigned long long>>'
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/sqsgen/sqs.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ namespace sqsgen {
};
schedule_main_loop();

// again we immdeiatly remove the signal handler after they have been used
// again we immediately remove the signal handler after they have been used
if (!mpi_mode) signal::teardown_signal_handlers();

this->barrier();
Expand Down
2 changes: 1 addition & 1 deletion include/sqsgen/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace sqsgen {

using thread_config_t = std::vector<usize_t>;

using seed_t = std::optional<std::vector<std::optional<std::uint64_t>>>;
using seed_t = std::vector<std::optional<std::uint64_t>>;

struct sublattice {
vset<usize_t> sites;
Expand Down
5 changes: 2 additions & 3 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[project]
name = "sqsgenerator"
authors = [
{ name = "Dominik Gehringer", email = "dgehringer@protonmail.com" }
{ name = "Dominik Gehringer", email = "dominik@gehringer.tech" }
]
maintainers = [
{ name = "Dominik Gehringer", email = "dgehringer@protonmail.com" },
{ name = "David Holec", email = "david.holec@unileoben.ac.at" }
{ name = "Dominik Gehringer", email = "dominik@gehringer.tech" },
]
description = "Create atomic structures for solid solutions for molecular simulations"
dependencies = ["numpy", "click"]
Expand Down
Loading