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

✨ SiDB Operational Domain Computation #255

Merged
merged 99 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
94c481d
:sparkles: Initial algorithm for the detection of I/O BDL pairs
marcelwa Jul 21, 2023
4b28c87
:memo: Added docstrings and RST documentation
marcelwa Jul 21, 2023
84eae22
:white_check_mark: Incorporated Jan's comments
marcelwa Jul 24, 2023
90fa30d
:art: Added some more documentation and fixed some inconsistencies
marcelwa Jul 24, 2023
619268c
:art: ClangFormat changes
Jul 24, 2023
4923565
:art: Added lower bound `minimum_distance` parameter for BDL pairs to…
marcelwa Jul 24, 2023
8ee9536
:art: Rewrote detection function to detect any given kind of BDL pair
marcelwa Jul 24, 2023
23e1b23
:sparkles: Added a `bdl_input_iterator` that can iterate over all pos…
marcelwa Jul 24, 2023
365c9e7
:art: Added `operator>` and `operator>=`
marcelwa Jul 25, 2023
cc28547
:art: Made `bdl_input_iterator` into a random access iterator
marcelwa Jul 25, 2023
c532ac2
:art: ClangFormat changes
Jul 25, 2023
f0b3065
:bug: Fixed a bug resulting from the misinterpretation of the subscri…
marcelwa Jul 25, 2023
675b45c
Merge remote-tracking branch 'origin/opdomain' into opdomain
marcelwa Jul 25, 2023
caf0d8d
:bug: Fixed test case to be independent of `Lyt`'s implementation
marcelwa Jul 27, 2023
a011fda
:art: Added missing include
marcelwa Jul 27, 2023
f1d2bb3
:sparkles: Initial operational domain computation algorithm via grid …
marcelwa Jul 27, 2023
7f0ac04
:memo: Added `operational_domain` documentation
marcelwa Jul 28, 2023
92b0120
Merge branch 'main' into opdomain
marcelwa Jul 28, 2023
1e10ea9
:alien: Accommodated the removal of the units library
marcelwa Jul 28, 2023
8a7d7f2
:white_check_mark: Added a test case for a 2-input gate
marcelwa Jul 28, 2023
836cc58
:sparkles: Added random sampling operational domain computation
marcelwa Jul 31, 2023
776ef28
:art: Reduced code duplication
marcelwa Jul 31, 2023
0c40472
:art: Added missing `const`
marcelwa Aug 2, 2023
0c18ac9
:art: Revive `csv_writer`
marcelwa Aug 2, 2023
e7a4422
:sparkles: Add functionality to write an operational domain to a CSV …
marcelwa Aug 2, 2023
d7263f8
:art: Added `const`
marcelwa Aug 2, 2023
19f7dd6
:rotating_light: Fixed warning
marcelwa Aug 2, 2023
0cc545a
:bug: Removed superfluous template parameter
marcelwa Aug 2, 2023
d7378ba
:art: ClangFormat changes
Aug 2, 2023
a7efc70
:bug: Removed blank space in CSV delimiter
marcelwa Aug 2, 2023
382488c
Merge remote-tracking branch 'origin/opdomain' into opdomain
marcelwa Aug 2, 2023
2d80e78
:bug: Changed the default min values to `1.0` to prevent division by …
marcelwa Aug 2, 2023
73504de
:bug: If no physically-valid charge distributions exist, the layout i…
marcelwa Aug 2, 2023
3138abd
:art: Minor updates to documentation and code consistency
marcelwa Aug 3, 2023
7a70958
Merge branch 'main' into opdomain
marcelwa Aug 3, 2023
ae9d7d3
:twisted_rightwards_arrows: Merge `main` into this branch
marcelwa Aug 3, 2023
001352c
:art: Restructured code to avoid further code duplication
marcelwa Aug 3, 2023
9d609ef
:sparkles: Added an operational domain computation algorithm based on…
marcelwa Aug 7, 2023
7f39544
:bug: Correct boundary check in operational domain computation
marcelwa Aug 7, 2023
c3bdfb9
:bug: Fixed compiler issues by preventing the use of the C++20 extens…
marcelwa Aug 7, 2023
269570e
:art: Avoid code duplication in `read_sqd_layout`
marcelwa Aug 8, 2023
374f045
:sparkles: Add support for cell types in SQD layout files
marcelwa Aug 8, 2023
b09f5ee
:memo: Added documentation on the OpDomain flood fill algorithm
marcelwa Aug 8, 2023
76593a4
:art: Made `bdl_input_iterator` thread-safe by preventing it to work …
marcelwa Aug 8, 2023
f2afa19
:thread: Added multi-threading support to `operational_domain_grid_se…
marcelwa Aug 8, 2023
6064ca2
:pencil2: Fixed a typo
marcelwa Aug 8, 2023
0ef0df6
:art: ClangFormat changes
Aug 8, 2023
6b6e1d1
:bug: Fixed a bug in SQD parsing with SiQAD coordinates
marcelwa Aug 8, 2023
2d3e800
Merge remote-tracking branch 'origin/opdomain' into opdomain
marcelwa Aug 8, 2023
5e2dc8b
:art: Allow statistics collection via atomics instead of using a mutex
marcelwa Aug 11, 2023
0d8e4a4
:sparkles: Added an `sidb_simulation_engine` toggle to enable the use…
marcelwa Aug 11, 2023
78d0a35
:art: ClangFormat changes
Aug 11, 2023
d5c3177
:bug: Fixed potential data race bug
marcelwa Aug 11, 2023
7ee049e
:bug: Fixed QuickSim parameter passing
marcelwa Aug 11, 2023
b99847d
:sparkles: Check for the occurrence of positive charges before simula…
marcelwa Aug 14, 2023
9a1a16a
Merge remote-tracking branch 'origin/opdomain' into opdomain
marcelwa Aug 14, 2023
5145ff9
:construction: Added TODO and fixed a compiler warning
marcelwa Aug 14, 2023
c56720e
:construction: Added operational domain computation via contour tracing
marcelwa Aug 14, 2023
9cf3751
:art: Simplified code, removed duplication
marcelwa Aug 14, 2023
d1fd37a
:art: Simplified code, removed duplication, improved performance, mad…
marcelwa Aug 14, 2023
d85ab58
:thread: Made `random_sampling` multithreaded
marcelwa Aug 14, 2023
db0edf9
Merge branch 'opdomain' into opdomain-contour-tracing
marcelwa Aug 14, 2023
5e6fc1c
:alien: Updated `contour_tracing` based on the previous changes to `o…
marcelwa Aug 14, 2023
1951d21
:art: Consider the determination of positive charges a simulator call
marcelwa Aug 15, 2023
0f5ccdc
:art: Cleaned up and refactored code
marcelwa Aug 30, 2023
b0795ef
:art: Use Moore Neighborhood in `flood_fill`
marcelwa Aug 30, 2023
6978e7b
:bug: Fixed parallel random sampling
marcelwa Aug 30, 2023
5d12e8d
Merge branch 'opdomain' into opdomain-contour-tracing
marcelwa Aug 30, 2023
f835e9b
:art: Implemented `clang-tidy`'s suggestions
marcelwa Aug 30, 2023
6f8fee6
:art: Implemented `clang-tidy`'s suggestions
marcelwa Aug 30, 2023
68b07bb
Merge remote-tracking branch 'origin/opdomain' into opdomain
marcelwa Aug 30, 2023
0c5fe8b
:art: Implemented CodeQL's suggestions
marcelwa Aug 30, 2023
1fc09b9
:art: Create designated types for `step_point` and `parameter_point` …
marcelwa Aug 31, 2023
c578c80
:bug: Fixed the counter boundary finding algorithm for contour tracin…
marcelwa Aug 31, 2023
033f56f
:art: ClangFormat
marcelwa Aug 31, 2023
93154ec
:white_check_mark: Extend test cases to semi-operational areas
marcelwa Sep 4, 2023
7a3a69e
:art: Decreased code duplication
marcelwa Sep 4, 2023
4ca1822
:art: Reduced further code duplication
marcelwa Sep 4, 2023
b2dbe03
:bug: Fixed a data race bug in the logging of statistics
marcelwa Sep 4, 2023
6bf9826
Merge branch 'main' into opdomain
marcelwa Sep 4, 2023
cc7f08e
:twisted_rightwards_arrows: Merge `main` into `opdomain`
marcelwa Sep 4, 2023
ad2e829
:memo: Updated documentation on the adjusted flood fill operational d…
marcelwa Sep 4, 2023
15647db
:pencil2: Fix typos
marcelwa Sep 4, 2023
84d118e
:art: Incorporated Jan's feedback
marcelwa Sep 4, 2023
acffee3
:bug: Fixed rarely occurring bug that caught contour tracing in an en…
marcelwa Sep 5, 2023
4085da2
:art: ClangFormat changes
Sep 5, 2023
75ad346
Merge branch 'main' into opdomain
marcelwa Sep 5, 2023
552b465
Merge branch 'main' into opdomain
marcelwa Sep 12, 2023
24b59f1
:alien: Updated code due to changes introduced in the QuickExact PR
marcelwa Sep 12, 2023
f2e7eb7
:memo: Removed TODOs
marcelwa Sep 12, 2023
6c50345
:art: ClangFormat changes
Sep 12, 2023
692386b
:art: Added a check for ground-state degeneracy
marcelwa Sep 12, 2023
5572c02
Merge remote-tracking branch 'origin/opdomain' into opdomain
marcelwa Sep 12, 2023
af49cea
:memo: Added missing contour tracing operational domain algorithm to …
marcelwa Sep 12, 2023
ff6d51b
:bug: Fixed degeneracy check
marcelwa Sep 12, 2023
8b19b0b
:rotating_light: Fixed `clang-tidy` warnings
marcelwa Sep 13, 2023
cac9713
:alembic: Added the experiment code for the paper
marcelwa Sep 13, 2023
b123aa2
:rotating_light: Incorporated `clang-tidy` suggestions
marcelwa Sep 13, 2023
9a7b3b3
:rotating_light: Incorporated `clang-tidy` suggestions
marcelwa Sep 14, 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
17 changes: 16 additions & 1 deletion docs/algorithms/sidb_simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,25 @@ Temperature Behavior
.. doxygenfunction:: fiction::calculate_energy_and_state_type



Time-to-Solution (TTS) Statistics
#################################

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

.. doxygenfunction:: fiction::sim_acc_tts


Utility Functions
#################


Binary-dot Logic (BDL) Pair Detection
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

.. doxygenstruct:: fiction::bdl_pair
:members:
.. doxygenstruct:: fiction::detect_bdl_pairs_params
:members:
.. doxygenfunction:: fiction::detect_io_bdl_pairs
229 changes: 229 additions & 0 deletions include/fiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
//
// Created by marcel on 21.07.23.
//

#ifndef FICTION_DETECT_BDL_PAIRS_HPP
#define FICTION_DETECT_BDL_PAIRS_HPP

#include "fiction/algorithms/path_finding/distance.hpp"
#include "fiction/technology/cell_technologies.hpp"
#include "fiction/traits.hpp"

#include <units.h>

#include <algorithm>
#include <unordered_set>
#include <vector>

namespace fiction
{

/**
* A Binary-dot Logic (BDL) pair is a pair of SiDBs that are close to each other and, thus, most likely share a charge.
*
* @tparam Lyt SiDB cell-level layout type.
*/
template <typename Lyt>
struct bdl_pair
{
/**
* The type of the SiDBs in the pair. BDL SiDBs must be of the same type. They can either be normal, input, or
* output SiDBs.
*/
const sidb_technology::cell_type type{};
/**
* The upper SiDB of the pair. Upper and lower are defined relative to each other via the `operator<` overload.
*/
const cell<Lyt> upper{};
/**
* The lower SiDB of the pair. Upper and lower are defined relative to each other via the `operator<` overload.
*/
const cell<Lyt> lower{};
/**
* Standard constructor for empty BDL pairs.
*/
bdl_pair() = default;
/**
* Constructor for BDL pairs.
*
* @param t Type of the SiDBs in the pair.
* @param u The upper SiDB of the pair.
* @param l The lower SiDB of the pair.
*/
bdl_pair(const sidb_technology::cell_type t, const cell<Lyt> u, const cell<Lyt> l) noexcept :
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
type{t},
upper{u},
lower{l}
{
static_assert(is_cell_level_layout_v<Lyt>, "Lyt is not a cell-level layout");
static_assert(has_sidb_technology_v<Lyt>, "Lyt is not an SiDB layout");
static_assert(has_siqad_coord_v<Lyt>, "Lyt is not based on SiQAD coordinates");
}
};

/**
* Parameters for the BDL pair detection algorithms.
*/
struct detect_bdl_pairs_params
{
/**
* The maximum distance between two dots to be considered a BDL pair.
*/
units::length::nanometer_t threshold{2_nm};
};

/**
* This algorithm detects input or output BDL pairs in an SiDB layout. It does so by first collecting all input and
* output dots and then uniquely pairing them up based on their distance. A threshold can be defined (default = 2 nm),
* after which SiDBs are no longer considered a pair. The distance between two dots is computed using the
* `sidb_nanometer_distance` function. The algorithm returns a vector of I/O BDL pairs.
*
* @tparam Lyt SiDB cell-level layout type.
* @param lyt The layout to detect I/O BDL pairs in.
* @param params Parameters for the BDL pair detection algorithm.
* @return A vector of I/O BDL pairs.
*/
template <typename Lyt>
std::vector<bdl_pair<Lyt>> detect_io_bdl_pairs(const Lyt& lyt, const detect_bdl_pairs_params params = {}) noexcept
{
static_assert(is_cell_level_layout_v<Lyt>, "Lyt is not a cell-level layout");
static_assert(has_sidb_technology_v<Lyt>, "Lyt is not an SiDB layout");
static_assert(has_siqad_coord_v<Lyt>, "Lyt is not based on SiQAD coordinates");

std::vector<bdl_pair<Lyt>> bdl_pairs{};
bdl_pairs.reserve(lyt.num_pis() / 2 + lyt.num_pos() / 2);

/**
* Pairs up dots based on their distance. It does so by first computing the pairwise distances between all dots and
* then sorting them. The smallest distances are then used to pair up the dots. The function takes a vector of dots
* and a cell type as input. It fills the vector of BDL pairs declared above.
*/
const auto pair_up_dots = [&lyt, &params, &bdl_pairs](const std::vector<cell<Lyt>>& io_dots,
const sidb_technology::cell_type type) noexcept -> void
{
/**
* Container for pairwise dot distances used in the pairing algorithm.
*/
struct pairwise_dot_distance
{
/**
* First dot.
*/
cell<Lyt> sidb1{};
/**
* Second dot.
*/
cell<Lyt> sidb2{};
/**
* Distance between the two dots.
*/
units::length::nanometer_t distance{};
/**
* Standard constructor for empty pairwise dot distances.
*/
pairwise_dot_distance() = default;
/**
* Constructor for pairwise dot distances.
*
* @param s1 The first dot.
* @param s2 The second dot.
* @param d The distance between the two dots.
*/
pairwise_dot_distance(const cell<Lyt> s1, const cell<Lyt> s2, const units::length::nanometer_t d) noexcept :
sidb1{s1},
sidb2{s2},
distance{d}
{}
};
/**
* Computes the pairwise distances between all dots in the input vector.
*/
const auto compute_pairwise_dot_distances =
[&lyt](const std::vector<cell<Lyt>>& dots) noexcept -> std::vector<pairwise_dot_distance>
{
std::vector<pairwise_dot_distance> pairwise_distances{};
pairwise_distances.reserve(dots.size() * (dots.size() - 1) / 2);

for (auto i = 0u; i < dots.size(); ++i)
{
for (auto j = i + 1; j < dots.size(); ++j)
{
pairwise_distances.emplace_back(dots[i], dots[j], sidb_nanometer_distance(lyt, dots[i], dots[j]));
}
}

return pairwise_distances;
};
/**
* Comparator for pairwise dot distances. Used in the sorting algorithm.
*/
const auto dot_distance_comparator = [](const auto& lhs, const auto& rhs) noexcept -> bool
{ return lhs.distance < rhs.distance; };

// compute pairwise distances
auto input_pairwise_distances = compute_pairwise_dot_distances(io_dots);
// sort pairwise distances
std::sort(input_pairwise_distances.begin(), input_pairwise_distances.end(), dot_distance_comparator);
// pair unique dots with the smallest distance
std::unordered_set<cell<Lyt>> paired_dots{};
paired_dots.reserve(io_dots.size());
/**
* Checks whether a dot has already been paired up.
*/
const auto already_paired_up = [&paired_dots](const auto& dot) noexcept -> bool
{ return paired_dots.find(dot) != paired_dots.cend(); };

for (auto& potential_bdl_pair : input_pairwise_distances)
{
// if the distance is larger than the threshold, we can break the loop because the remaining distances
// must be larger as well due to the prior sorting; this prevents unlikely pairings and helps performance
if (potential_bdl_pair.distance > params.threshold)
{
break;
}

// if either dot has already been matched, skip
if (already_paired_up(potential_bdl_pair.sidb1) || already_paired_up(potential_bdl_pair.sidb2))
{
continue;

Check warning on line 188 in include/fiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp

View check run for this annotation

Codecov / codecov/patch

include/fiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp#L188

Added line #L188 was not covered by tests
}

// a BDL pair has been detected (swap SiDBs if necessary)
if (potential_bdl_pair.sidb1 > potential_bdl_pair.sidb2)
{
bdl_pairs.emplace_back(type, potential_bdl_pair.sidb2, potential_bdl_pair.sidb1);
}
else
{
bdl_pairs.emplace_back(type, potential_bdl_pair.sidb1, potential_bdl_pair.sidb2);
}

// mark the dots as paired
paired_dots.insert(potential_bdl_pair.sidb1);
paired_dots.insert(potential_bdl_pair.sidb2);
}
};

// collect all input dots
std::vector<cell<Lyt>> input_dots{};
input_dots.reserve(lyt.num_pis());
lyt.foreach_pi([&input_dots](const auto& pi) { input_dots.push_back(pi); });

// pair up input dots
pair_up_dots(input_dots, sidb_technology::cell_type::INPUT);

// collect all output dots
std::vector<cell<Lyt>> output_dots{};
output_dots.reserve(lyt.num_pos());
lyt.foreach_po([&output_dots](const auto& po) { output_dots.push_back(po); });

// pair up output dots
pair_up_dots(output_dots, sidb_technology::cell_type::OUTPUT);

// return the detected I/O BDL pairs
return bdl_pairs;
}

}; // namespace fiction

#endif // FICTION_DETECT_BDL_PAIRS_HPP
2 changes: 1 addition & 1 deletion include/fiction/technology/cell_technologies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ struct sidb_technology
static constexpr double CELL_HSPACE = 0.384;
/**
* Default average vertical spacing between two SiDBs in SiQAD.
* Depending on their lattice, they can be closer together or further apart.
* Depending on whether they are on the same or different dimer rows, SiDBs can be closer together or further apart.
*/
static constexpr double CELL_VSPACE = 0.384;
};
Expand Down
8 changes: 6 additions & 2 deletions include/fiction/technology/sidb_nm_position.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
#include "fiction/layouts/cell_level_layout.hpp"
#include "fiction/traits.hpp"

#include <units.h>

#include <utility>

namespace fiction
{

/**
* Computes the position of a cell in nanometers from the layout origin.
* Computes the position of a cell in nanometers from the layout origin in an SiDB layout.
*
* @tparam Lyt The layout type.
* @tparam Lyt SiDB cell-level layout type.
* @param sp The simulation parameters (required for the lattice constants).
* @param c The cell to compute the position for.
* @return A pair representing the `(x,y)` position of `c` in nanometers from the layout origin.
Expand All @@ -26,6 +28,8 @@ template <typename Lyt>
constexpr std::pair<units::length::nanometer_t, units::length::nanometer_t>
sidb_nm_position(const sidb_simulation_parameters& sp, const cell<Lyt>& c) noexcept
{
static_assert(is_cell_level_layout_v<Lyt>, "Lyt is not a cell-level layout");
static_assert(has_sidb_technology_v<Lyt>, "Lyt is not an SiDB layout");
static_assert(has_siqad_coord_v<Lyt>, "Lyt is not based on SiQAD coordinates");

const auto x = units::length::nanometer_t(
Expand Down
Loading
Loading