Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added function to generate random SiDB layouts and write simulation results to file. #200

Merged
merged 141 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
9622e83
:arrow_up: Bump libs/Catch2 from `6783411` to `1f881ab` (#27)
dependabot[bot] Apr 2, 2023
2da4f7e
Merge branch 'marcelwa:main' into main
Drewniok Apr 14, 2023
8f5f52f
:arrow_up: Bump libs/parallel-hashmap from `7883cb6` to `d2bed96` (#33)
dependabot[bot] Apr 14, 2023
a8cbc27
Merge branch 'marcelwa:main' into main
Drewniok Apr 18, 2023
3b11f93
Merge branch 'marcelwa:main' into main
Drewniok Apr 18, 2023
e9e2fa3
Merge branch 'marcelwa:main' into main
Drewniok Apr 18, 2023
37c881e
Merge branch 'marcelwa:main' into main
Drewniok Apr 19, 2023
4aa8489
Merge branch 'marcelwa:main' into main
Drewniok Apr 19, 2023
1587ef3
Merge branch 'marcelwa:main' into main
Drewniok Apr 20, 2023
04ed1c3
Merge branch 'marcelwa:main' into main
Drewniok Apr 21, 2023
9eaaf1f
Merge branch 'marcelwa:main' into main
Drewniok Apr 25, 2023
0dca9cf
Merge branch 'marcelwa:main' into main
Drewniok Apr 26, 2023
ce8b2e2
Merge branch 'marcelwa:main' into main
Drewniok May 1, 2023
cf70745
:sparkles: random layout generator.
Drewniok May 4, 2023
58d5f12
:sparkles: random layout generator.
Drewniok May 4, 2023
8a5efa3
:white_check_mark: add test for random layout generator.
Drewniok May 4, 2023
0109e2b
:white_check_mark: update test.
Drewniok May 4, 2023
5174cc9
:sparkles: experiment file to generate random layouts.
Drewniok May 4, 2023
6e7e8b3
:sparkles: experiment file to simulate the randomly-generated files a…
Drewniok May 4, 2023
0236e84
:memo: add RST.
Drewniok May 4, 2023
25e8b6b
:memo: small change in RST.
Drewniok May 4, 2023
6053844
:memo: remove superfluous semicolon.
Drewniok May 4, 2023
bb2d756
:memo: add missing @param.
Drewniok May 4, 2023
17377a4
:memo: add missing doxygenstruct.
Drewniok May 4, 2023
9859049
:art: add ``const`` keyword.
Drewniok May 4, 2023
f38f6bd
:art: remove ``const`` keyword.
Drewniok May 4, 2023
5bd0e28
:art: small changes.
Drewniok May 4, 2023
d70a8a6
:art: add ``const``.
Drewniok May 4, 2023
dd9ccad
:art: reformat code and clang-tidy suggestions.
Drewniok May 5, 2023
fb44a2d
:art: rename variables.
Drewniok May 8, 2023
64501c1
Merge branch 'marcelwa:main' into main
Drewniok May 10, 2023
3eac8a3
Merge branch 'main' into random_layout_generator
Drewniok May 10, 2023
a9fa94f
Merge branch 'main' into random_layout_generator
Drewniok May 11, 2023
68f6885
Merge branch 'marcelwa:main' into main
Drewniok May 11, 2023
84634cd
Merge branch 'marcelwa:main' into main
Drewniok May 12, 2023
d3f830f
Merge branch 'main' into random_layout_generator
Drewniok May 12, 2023
00d9472
Merge branch 'main' into random_layout_generator
Drewniok May 12, 2023
597b1a7
Merge branch 'marcelwa:main' into main
Drewniok May 12, 2023
9eb04bf
Merge branch 'main' into random_layout_generator
Drewniok May 12, 2023
1920794
Merge branch 'marcelwa:main' into main
Drewniok May 14, 2023
cc8ab8f
:art: change return type of simulation.
Drewniok May 15, 2023
e8c088f
:fire: remove redeclared method.
Drewniok May 15, 2023
c5cfada
Merge branch 'main' into random_layout_generator
Drewniok May 15, 2023
5d74ac6
Merge branch 'marcelwa:main' into main
Drewniok May 21, 2023
f408962
Merge branch 'marcelwa:main' into main
Drewniok May 24, 2023
b4138de
Merge branch 'marcelwa:main' into main
Drewniok May 25, 2023
930fcf2
Merge branch 'marcelwa:main' into main
Drewniok Jun 5, 2023
5916d3e
:art: implement Marcel's suggestions.
Drewniok Jun 7, 2023
cbd8345
Merge branch 'marcelwa:main' into main
Drewniok Jun 7, 2023
98f9638
:sparkles: function to generate a random cell between two given cells.
Drewniok Jun 7, 2023
866f3d5
Merge branch 'main' into random_layout_generator
Drewniok Jun 7, 2023
d99ba9d
:art: add docu.
Drewniok Jun 7, 2023
cd6d946
:fire: remove getter function.
Drewniok Jun 7, 2023
689a2a6
:sparkles: Add function to write the position of the SiDBs in nm to a…
Drewniok Jun 9, 2023
eb5acf0
:white_check_mark: Add test for write_txt_sim_result.cpp.
Drewniok Jun 9, 2023
d4577df
:art: small changes here and there.
Drewniok Jun 9, 2023
6e0909d
:art: remove type information in std::uniform_int_distribution.
Drewniok Jun 9, 2023
e181ade
:memo: Add documentation.
Drewniok Jun 9, 2023
3dc23bd
:memo: Add RST.
Drewniok Jun 9, 2023
5119304
:art: Major change of the functional structure.
Drewniok Jun 9, 2023
41a117f
:memo: change RTS-format of random_layout_generator.hpp.
Drewniok Jun 9, 2023
4ae68fe
:art: correct typo.
Drewniok Jun 9, 2023
226610a
:art: using constexpr const char*.
Drewniok Jun 9, 2023
2903532
Merge branch 'marcelwa:main' into main
Drewniok Jun 12, 2023
9b631d1
Merge branch 'main' into random_cell
Drewniok Jun 12, 2023
2ed5208
:art: implement Marcel's suggestions.
Drewniok Jun 12, 2023
89ff1ee
:art: reformat code.
Drewniok Jun 12, 2023
b39fd60
:art: implement Marcel's suggestions.
Drewniok Jun 13, 2023
a186e39
:art: remove ``const`` and pass parameters by copy.
Drewniok Jun 13, 2023
5b9da4f
:art: implement Marcel's suggestions.
Drewniok Jun 13, 2023
a93dd69
:art: implement Marcel's suggestions.
Drewniok Jun 13, 2023
4d4b946
:art: add siqad exception.
Drewniok Jun 13, 2023
5c4bd39
:art: use more elegant way.
Drewniok Jun 13, 2023
a93813d
:art: change order of if branches.
Drewniok Jun 13, 2023
ef5c52c
Merge branch 'random_cell' into random_layout_generator
Drewniok Jun 13, 2023
51efb49
:art: make use of new function to generate random coordinate.
Drewniok Jun 13, 2023
53c4872
Merge branch 'main' into random_layout_generator
Drewniok Jun 13, 2023
07c32bd
:sparkles: Layouts based on siqad and fiction coordinates can be writ…
Drewniok Jun 14, 2023
f0c133b
:sparkles: add static_assert and swap function.
Drewniok Jun 14, 2023
a37262e
:fire: remove superfluous while.
Drewniok Jun 14, 2023
ccb7bbb
:art: add const keyword.
Drewniok Jun 14, 2023
f70ceb6
Merge branch 'marcelwa:main' into main
Drewniok Jun 14, 2023
24ff3a7
Merge branch 'marcelwa:main' into main
Drewniok Jun 16, 2023
a4f3150
Merge branch 'marcelwa:main' into main
Drewniok Jun 19, 2023
de4962e
:art: add a layout as input to add random cells to this given layout.
Drewniok Jun 19, 2023
04eb35f
Merge branch 'main' into random_layout_generator
Drewniok Jun 19, 2023
6a7df5e
:art: add input layout to experiment file.
Drewniok Jun 19, 2023
9c78984
Merge branch 'marcelwa:main' into main
Drewniok Jun 23, 2023
0f54bfc
Merge branch 'main' into random_layout_generator
Drewniok Jun 26, 2023
c3f4e96
Merge branch 'marcelwa:main' into main
Drewniok Jun 28, 2023
853be74
Merge branch 'cda-tum:main' into main
Drewniok Jul 5, 2023
13eab3c
Merge branch 'cda-tum:main' into main
Drewniok Jul 10, 2023
2194c1a
Merge branch 'main' into random_layout_generator
Drewniok Jul 10, 2023
002fb41
:art: Simulation results for layouts where no physically valid charge…
Drewniok Jul 10, 2023
1c59a58
Merge branch 'cda-tum:main' into main
Drewniok Jul 18, 2023
a18d52c
Merge branch 'main' into random_layout_generator
Drewniok Jul 18, 2023
7354ef0
:art: implement Marcel's suggestions.
Drewniok Jul 18, 2023
b63a348
:white_check_mark: art more decimal places in unit test.
Drewniok Jul 19, 2023
f5eb41d
:construction: make random_layout_generator.cpp unused to find out wh…
Drewniok Jul 19, 2023
a265a7e
:construction: make random_layout_generator.cpp unused to find out wh…
Drewniok Jul 19, 2023
2cfaeb3
:construction: add only one TEST_CASE in random_layout_generator.cpp.
Drewniok Jul 19, 2023
6eea330
:construction: not using tests for ``generate_multiple_random_layouts…
Drewniok Jul 19, 2023
bfd3604
:construction: using a few tests for ``generate_multiple_random_layou…
Drewniok Jul 19, 2023
c2a973e
:construction: using a few more tests for ``generate_multiple_random_…
Drewniok Jul 19, 2023
305fbbb
:construction: using a few more tests for ``generate_multiple_random_…
Drewniok Jul 19, 2023
0b7bd9c
:construction: using a few more tests for ``generate_multiple_random_…
Drewniok Jul 19, 2023
5986de8
:construction: all test are enabled.
Drewniok Jul 19, 2023
9b6ca3f
:construction: change ``CHECK`` statement.
Drewniok Jul 20, 2023
c45c354
:construction: change ``CHECK`` statement.
Drewniok Jul 20, 2023
763a069
:art: change ``CHECK`` statement.
Drewniok Jul 20, 2023
1f87c22
Merge branch 'cda-tum:main' into main
Drewniok Jul 20, 2023
73719cd
Merge branch 'main' into random_layout_generator
Drewniok Jul 20, 2023
b638a34
:construction: not using ``uniqueness check``.
Drewniok Jul 20, 2023
977d5ff
:white_check_mark: remove last unit test.
Drewniok Jul 21, 2023
d300bc1
Merge branch 'cda-tum:main' into main
Drewniok Jul 24, 2023
2dc75ac
Merge branch 'cda-tum:main' into main
Drewniok Jul 25, 2023
9fc5819
Merge branch 'cda-tum:main' into main
Drewniok Jul 26, 2023
bd5cfc3
Merge branch 'cda-tum:main' into main
Drewniok Jul 26, 2023
51b93cb
Merge branch 'cda-tum:main' into main
Drewniok Jul 26, 2023
751369c
Merge branch 'cda-tum:main' into main
Drewniok Aug 3, 2023
311339b
Merge branch 'cda-tum:main' into main
Drewniok Aug 10, 2023
16c12e4
Merge branch 'cda-tum:main' into main
Drewniok Aug 27, 2023
9f4426b
Merge branch 'cda-tum:main' into main
Drewniok Aug 29, 2023
6eccd58
Merge branch 'cda-tum:main' into main
Drewniok Aug 30, 2023
918b755
Merge branch 'cda-tum:main' into main
Drewniok Aug 30, 2023
89bc9ae
Merge branch 'cda-tum:main' into main
Drewniok Sep 1, 2023
11b61ae
Merge branch 'main' into random_layout_generator
Drewniok Sep 4, 2023
eb84e84
:twisted_rightwards_arrows: merge ``main``.
Drewniok Sep 4, 2023
fe94fd5
:twisted_rightwards_arrows: merge ``main``.
Drewniok Sep 4, 2023
8625fc8
:art: implement review suggestions.
Drewniok Sep 4, 2023
b9c531f
:art: implement review suggestions.
Drewniok Sep 4, 2023
86dd321
:bug: wrong Header in sidb_simulation.rst.
Drewniok Sep 4, 2023
4c18389
:art: renaming for documentation.
Drewniok Sep 4, 2023
188929b
:art: renaming for documentation.
Drewniok Sep 4, 2023
3fcd565
:art: reformat code.
Drewniok Sep 4, 2023
654f049
:art: Incorporate the bots' comments.
Drewniok Sep 4, 2023
13444d6
:art: more consistency
Drewniok Sep 5, 2023
8a90cdf
:art: remove static_assert
Drewniok Sep 5, 2023
dd5da41
:art: use ``std::fabs`` to check equality.
Drewniok Sep 5, 2023
64c4862
Merge branch 'cda-tum:main' into main
Drewniok Sep 5, 2023
4746672
Merge branch 'main' into random_layout_generator
Drewniok Sep 5, 2023
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
11 changes: 11 additions & 0 deletions docs/algorithms/sidb_simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,14 @@ Time-to-Solution (TTS) Statistics
**Header:** ``fiction/algorithms/simulation/sidb/time_to_solution.hpp``

.. doxygenfunction:: fiction::sim_acc_tts


Random SiDB Layout Generator
############################

**Header:** ``fiction/algorithms/simulation/sidb/random_sidb_layout_generator.hpp``

.. doxygenenum:: fiction::positive_charges
.. doxygenstruct:: fiction::generate_random_sidb_layout_params
.. doxygenfunction:: fiction::generate_random_sidb_layout
.. doxygenfunction:: fiction::generate_multiple_random_sidb_layouts
5 changes: 5 additions & 0 deletions docs/io/physical_simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ SiQAD
.. doxygenfunction:: fiction::write_sqd_sim_result(const sidb_simulation_result<Lyt>& sim_result, std::ostream& os)
.. doxygenfunction:: fiction::write_sqd_sim_result(const sidb_simulation_result<Lyt>& sim_result, const std::string_view& filename)

**Header:** ``fiction/io/write_location_and_ground_state.hpp``

.. doxygenfunction:: fiction::write_location_and_ground_state(const sidb_simulation_result<Lyt>& sim_result, std::ostream& os)
.. doxygenfunction:: fiction::write_location_and_ground_state(const sidb_simulation_result<Lyt>& sim_result, const std::string_view& filename)

**Header:** ``fiction/io/read_sqd_layout.hpp``

.. doxygenfunction:: fiction::read_sqd_layout(std::istream& is, const std::string_view& name = "")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
//
// Created by Jan Drewniok on 04.05.23.
//

#include <fiction/algorithms/simulation/sidb/random_sidb_layout_generator.hpp>
#include <fiction/io/read_sqd_layout.hpp>
#include <fiction/types.hpp>

#include <fmt/format.h>

#include <cstdint>
#include <cstdlib>
#include <filesystem>
#include <iomanip>
#include <iostream>
#include <string>
#include <unordered_map>

using namespace fiction;

/**
* This program generates random SiDB layouts and saves them as .sqd files (provide SiQAD
* (https://github.com/siqad/siqad) compatibility) in a specified folder. It allows configuring various layout
* parameters through command-line arguments, including the folder name, layout dimensions, allowed charges (2- or
* 3-states), number of layouts for each SiDB count, and step size for SiDB count increments.
*
* @param argc The number of command-line arguments.
* @param argv An array of C-style strings containing the command-line arguments.
* @return Returns 0 on successful execution, or EXIT_FAILURE if an error occurs.
*
* Command-line Options:
* --folder_name <name> Specifies the name of the folder to store generated layouts.
* --NW_x <value> Sets the x coordinate of the north-west cell corner in SiQAD coordinates.
* --NW_y <value> Sets the y coordinate of the north-west cell corner in SiQAD coordinates.
* --SE_x <value> Sets the x coordinate of the south-east cell corner in SiQAD coordinates.
* --SE_y <value> Sets the y coordinate of the south-east cell corner in SiQAD coordinates.
* --positive_charges <type> Specifies whether positively charged SiDBs are allowed ("ALLOWED") or forbidden
* ("FORBIDDEN").
* --lower <value> Sets the number of SiDBs for the first bunch of layouts.
* --upper <value> Sets the number of SiDBs for the last bunch of layouts.
* --num_layouts <value> Sets the number of layouts to generate for each SiDB count.
* --step <value> Sets the step size for incrementing the SiDB count from lower to upper limit.
*
* Example Usage:
* To generate layouts with default options and save them in a folder named "layout_random_cli/":
* ./random_sidb_layout_generation
*
* To specify custom options:
* ./random_sidb_layout_generation --folder_name my_layouts --NW_x 0 --NW_y 0 --SE_x 20 --SE_y 20 --positive_charges
* ALLOWED --lower 5 --upper 10 --num_layouts 10 --step 1
*/
int main(int argc, const char* argv[]) // NOLINT
{
std::unordered_map<std::string, std::string> options{{"--folder_name", "random_sidb_layouts/"},
{"--NW_x", "0"},
{"--NW_y", "0"},
{"--SE_x", "20"},
{"--SE_y", "20"},
{"--positive_charges", "FORBIDDEN"},
{"--lower", "5"},
{"--upper", "10"},
{"--num_layouts", "10"},
{"--step", "1"}};

std::vector<std::string> arguments(argv + 1, argv + argc); // Convert argv to a vector of strings

// Parse command-line arguments
for (size_t i = 0; i < arguments.size(); ++i)
{
const std::string& arg = arguments[i];
if (options.count(arg) > 0)
{
if (i + 1 < arguments.size())
{
options[arg] = arguments[i + 1];
++i; // Skip the next argument
}
else
{
std::cerr << "Error: Argument " << arg << " is missing a value." << std::endl;
return EXIT_FAILURE;
}
}
}

// specifies the name of the folder to store generated layouts
const std::string folder_name = options["--folder_name"];
// sets the x coordinate of the north-west cell corner in SiQAD coordinates
const int32_t nw_x = std::stoi(options["--NW_x"]);
// sets the y-coordinate of the north-west cell corner in SiQAD coordinates
const int32_t nw_y = std::stoi(options["--NW_y"]);
// sets the x-coordinate of the south-east cell corner in SiQAD coordinates
const int32_t se_x = std::stoi(options["--SE_x"]);
// sets the y-coordinate of the south-east cell corner in SiQAD coordinates
const int32_t se_y = std::stoi(options["--SE_y"]);
// specifies whether positively charged SiDBs are allowed ("ALLOWED") or forbidden ("FORBIDDEN")
const std::string charges_str = options["--positive_charges"];
// specifies whether positively charged SiDBs are allowed ("ALLOWED") or forbidden ("FORBIDDEN")
const positive_charges charges =
(charges_str == "ALLOWED") ? positive_charges::ALLOWED : positive_charges::FORBIDDEN;
// sets the number of SiDBs for the first bunch of layouts
const uint64_t lower_limit = std::stoull(options["--lower"]);
// sets the number of SiDBs for the last bunch of layouts
const uint64_t upper_limit = std::stoull(options["--upper"]);
// sets the number of layouts to generate for each SiDB count
const uint64_t number_of_layouts = std::stoull(options["--num_layouts"]);
// sets the step size for incrementing the SiDB count from lower to upper limit
const uint64_t step = std::stoull(options["--step"]);

// print the parsed values
std::cout << "Folder name: " << folder_name << std::endl;
std::cout << fmt::format("NW: {} | {}", nw_x, nw_y) << std::endl;
std::cout << fmt::format("SE: {} | {}", se_x, se_y) << std::endl;
std::cout << fmt::format("positive_charges: {}", charges_str) << std::endl;
std::cout << "lower_limit: " << lower_limit << std::endl;
std::cout << "upper_limit: " << upper_limit << std::endl;
std::cout << "number_of_layouts: " << number_of_layouts << std::endl;
std::cout << "step: " << step << std::endl;

// generates random SiDB layouts as .sqd file
using cell_level_layout = cell_level_layout<sidb_technology, clocked_layout<cartesian_layout<siqad::coord_t>>>;

try
{
std::filesystem::path folder_path(EXPERIMENTS_PATH);

folder_path /= folder_name;

if (std::filesystem::exists(folder_path))
{
std::cout << "Folder *" << folder_path << "* exists!" << std::endl;
}
else
{
if (std::filesystem::create_directory(folder_path))
{
std::cout << fmt::format("Folder {} created successfully", folder_name) << std::endl;
}
else
{
std::cout << "Failed to create folder" << std::endl;
}
}

for (uint64_t number_of_placed_sidbs = lower_limit; number_of_placed_sidbs <= upper_limit;
number_of_placed_sidbs += step)
{
const std::filesystem::path dir_path =
folder_path.string() + "number_sidbs_" + std::to_string(number_of_placed_sidbs);
const std::filesystem::path dir_path_sqd =
folder_path.string() + "number_sidbs_" + std::to_string(number_of_placed_sidbs) + "/sqd";
const std::filesystem::path dir_path_loc =
folder_path.string() + "number_sidbs_" + std::to_string(number_of_placed_sidbs) + "/loc";
try
{
if (!std::filesystem::exists(dir_path))
{
std::filesystem::create_directory(dir_path);
std::cout << "Folder created." << std::endl;
std::filesystem::create_directory(dir_path_sqd);
std::filesystem::create_directory(dir_path_loc);
}
else
{
std::cout << "Folder already exists." << std::endl;
}

const generate_random_sidb_layout_params<cell_level_layout> params{
{{nw_x, nw_y}, {se_x, se_y}}, number_of_placed_sidbs, charges, 2,
static_cast<uint64_t>(10E6), number_of_layouts};
const auto unique_lyts =
generate_multiple_random_sidb_layouts<cell_level_layout>(cell_level_layout{}, params);
for (auto i = 0u; i < unique_lyts.size(); i++)
{
write_sqd_layout(unique_lyts[i], fmt::format("{}/layout_{}.sqd", dir_path_sqd.string(), i));
}
}
catch (const std::filesystem::filesystem_error& ex)
{
// exception is handled
std::cerr << "Filesystem error: " << ex.what() << std::endl;
}
}
}
catch (const std::filesystem::filesystem_error& ex)
{
// exception occurred, handle it here
std::cerr << "Filesystem error: " << ex.what() << std::endl;
}

return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// Created by Jan Drewniok on 04.05.23.
//

#include "fiction/algorithms/simulation/sidb/exhaustive_ground_state_simulation.hpp"
#include "fiction/io/read_sqd_layout.hpp"
#include "fiction/io/write_location_and_ground_state.hpp"
#include "fiction/technology/charge_distribution_surface.hpp"
#include "fiction/types.hpp"

#include <cstdlib>
#include <filesystem>
#include <iomanip>
#include <iostream>
#include <string>
#include <unordered_map>

using namespace fiction;

/**
* This program reads randomly generated SiDB layouts from a specified folder, simulates them, and collects the
* simulation results in text files. The simulation results include the x and y coordinates of SiDBs and their charge
* state (as an integer) in the ground state. The simulation is parameterized by the µ-value, which influences the
* charge distribution.
*
* @param argc The number of command-line arguments.
* @param argv An array of C-style strings containing the command-line arguments.
* @return Returns 0 on successful execution, or EXIT_FAILURE if an error occurs.
*
* Command-line Options:
* --folder_name <name> Specifies the name of the folder containing randomly generated layouts.
* --mu_minus <value> Sets the µ-value used for the simulation, which affects the charge distribution.
*
* Example Usage:
* To simulate layouts from the "random_sidb_layouts/" folder with a µ (mu) value of -0.32:
* ./sidb_location_and_ground_state_state_simulation --folder_name random_sidb_layouts/ --mu_minus -0.32
*/
int main(int argc, const char* argv[]) // NOLINT
{

std::unordered_map<std::string, std::string> options{{"--folder_name", "layout_random_cli/"},
{"--mu_minus", "-0.32"}};

std::vector<std::string> arguments(argv + 1, argv + argc); // Convert argv to a vector of strings

// Parse command-line arguments
for (size_t i = 0; i < arguments.size(); ++i)
{
const std::string& arg = arguments[i];
if (options.count(arg) > 0)
{
if (i + 1 < arguments.size())
{
options[arg] = arguments[i + 1];
++i; // Skip the next argument
}
else
{
std::cerr << "Error: Argument " << arg << " is missing a value." << std::endl;
return EXIT_FAILURE;
}
}
}

// Folder name where the randomly generated layouts are located.
const std::string folder_name = options["--folder_name"];
// µ-value used for the simulation.
const double mu = std::stod(options["--mu_minus"]);

// Print the parsed values
std::cout << "Folder name: " << folder_name << std::endl;
std::cout << fmt::format("µ_minus: {}", mu) << std::endl;

try
{
std::filesystem::path folder_path(EXPERIMENTS_PATH);
folder_path /= folder_name;

if (std::filesystem::exists(folder_path))
{
for (const auto& folder : std::filesystem::directory_iterator(folder_path))
{
if (std::filesystem::exists(folder_path))
{
for (const auto& file : std::filesystem::directory_iterator(folder.path().string() + "/sqd"))
{
const auto& benchmark = file.path();

// When random layouts are generated with the script random_sidb_layout_generation.cpp, they
// have the following file name format: layout_xxx (xxx is the numbering). In the following code
// lines, the file name of the current file is extracted from the file path.
const std::string path = benchmark.string();
const uint64_t start = path.rfind("layout") + 7;
const uint64_t end = path.rfind(".sqd") - 1;
const std::string name = path.substr(start, end - start + 1);

std::cout << benchmark << std::endl;

auto lyt = read_sqd_layout<sidb_cell_clk_lyt_siqad>(benchmark.string());

const sidb_simulation_parameters params{2, mu};
const auto simulation_results =
exhaustive_ground_state_simulation<sidb_cell_clk_lyt_siqad>(lyt, params);
const std::string file_path = fmt::format("{}/loc/{}_sim_µ_minus_{:.3f}.txt",
folder.path().string(), name, -params.mu_minus);

// Some SiDB layouts where positively charged SiDBs may occur cannot be simulated (i.e., no
// physically valid charge distribution is found) because the physical model currently works
// reliably only for layouts with neutrally and negatively charged SiDBs.
if (!simulation_results.charge_distributions.empty())
{
write_location_and_ground_state(simulation_results, file_path);
}
}
}
else
{
std::cout << "Folder */sqd* does not exist." << std::endl;
}
}
}
else
{
std::cout << fmt::format("Folder {} does not exist", folder_name) << std::endl;
}
}
catch (const std::filesystem::filesystem_error& ex)
{
std::cerr << "Error accessing folder: " << ex.what() << std::endl;
}

return EXIT_SUCCESS;
}
Loading
Loading