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

➖ Remove unit library due to increasing simulation runtimes. #258

Merged
merged 42 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 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
64501c1
Merge branch 'marcelwa:main' into main
Drewniok May 10, 2023
68f6885
Merge branch 'marcelwa:main' into main
Drewniok May 11, 2023
84634cd
Merge branch 'marcelwa:main' into main
Drewniok May 12, 2023
597b1a7
Merge branch 'marcelwa:main' into main
Drewniok May 12, 2023
1920794
Merge branch 'marcelwa:main' into main
Drewniok May 14, 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
cbd8345
Merge branch 'marcelwa:main' into main
Drewniok Jun 7, 2023
2903532
Merge branch 'marcelwa:main' into main
Drewniok Jun 12, 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
9c78984
Merge branch 'marcelwa:main' into main
Drewniok Jun 23, 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
1c59a58
Merge branch 'cda-tum:main' into main
Drewniok Jul 18, 2023
1f87c22
Merge branch 'cda-tum:main' into main
Drewniok Jul 20, 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
2f6990e
:heavy_minus_sign: Remove ``unit`` library due to increasing simulati…
Drewniok Jul 25, 2023
ce63b2d
:art: implement Marcel's suggestions.
Drewniok Jul 25, 2023
ab73daa
Merge branch 'main' into remove_unit_library
Drewniok Jul 25, 2023
0cb32e2
:white_check_mark: add a few more tests.
Drewniok Jul 25, 2023
9fc5819
Merge branch 'cda-tum:main' into main
Drewniok Jul 26, 2023
8d58695
Merge branch 'main' into remove_unit_library
Drewniok Jul 26, 2023
2f8650a
:white_check_mark: add a few more tests.
Drewniok Jul 26, 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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@
[submodule "libs/tinyxml2"]
path = libs/tinyxml2
url = https://github.com/leethomason/tinyxml2.git
[submodule "libs/units"]
path = libs/units
url = https://github.com/nholthaus/units.git
12 changes: 12 additions & 0 deletions docs/technology/simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ distributions of the SiDBs. Charge distribution surfaces are returned by the SiD
:members:
.. doxygenclass:: fiction::charge_distribution_surface< Lyt, false >
:members:


Physical Constants
------------------

**Header:** ``fiction/technology/physical_constants.hpp``

.. doxygenvariable:: EPSILON
.. doxygenvariable:: ELEMENTARY_CHARGE
.. doxygenvariable:: K
.. doxygenvariable:: POP_STABILITY_ERR
.. doxygenvariable:: PI
18 changes: 0 additions & 18 deletions docs/utils/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,6 @@ Array Utils
.. doxygenfunction:: fiction::convert_array
.. doxygenfunction:: fiction::convert_array_of_arrays

Unit Utils
-----------

**Header:** ``fiction/utils/unit_utils.hpp``

.. doxygentypedef:: coulomb_constant_unit
.. doxygenvariable:: POP_STABILITY_ERR

There are several suffix operators exposed in this file for convenient use of units, namely
* ``_angstrom``
* ``_e``
* ``_eV``
* ``_K``
* ``_nm``
* ``_s``
* ``_V``

This enables the use of units as follows: e.g., ``40_K``, ``40.1_nm``.

STL Extensions
--------------
Expand Down
8 changes: 4 additions & 4 deletions include/fiction/algorithms/path_finding/distance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ template <typename Lyt, typename Dist = uint64_t>
static_cast<Dist>(std::numeric_limits<uint32_t>::max());
}
/**
* Computes the distance between two SiDB cells in nanometers.
* Computes the distance between two SiDB cells in nanometers (unit: nm).
*
* @tparam Lyt SiDB cell-level layout type.
* @tparam Dist Floating-point type for the distance.
* @param c1 The first cell.
* @param c2 The second cell.
* @return The distance between the two cells in nanometers.
* @return The distance between the two cells in nanometers (unit: nm).
*/
template <typename Lyt>
[[nodiscard]] constexpr units::length::nanometer_t
[[nodiscard]] constexpr double
sidb_nanometer_distance([[maybe_unused]] const Lyt& lyt, const coordinate<Lyt>& source, const coordinate<Lyt>& target,
const sidb_simulation_parameters& sp = sidb_simulation_parameters{}) noexcept
{
Expand All @@ -115,7 +115,7 @@ sidb_nanometer_distance([[maybe_unused]] const Lyt& lyt, const coordinate<Lyt>&
const auto x = pos_c1.first - pos_c2.first;
const auto y = pos_c1.second - pos_c2.second;

return units::math::hypot(x, y);
return std::hypot(x, y);
}

// NOLINTBEGIN(*-special-member-functions): virtual destructor is prudent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace fiction
* Data type to collect electrostatic potential energies (in eV) of charge distributions with corresponding state types
* (i.e., true = transparent, false = erroneous).
*/
using sidb_energy_and_state_type = std::vector<std::pair<units::energy::electron_volt_t, bool>>;
using sidb_energy_and_state_type = std::vector<std::pair<double, bool>>;

/**
* This function takes in an SiDB energy distribution. For each charge distribution, the state type is determined (i.e.
Expand Down
45 changes: 21 additions & 24 deletions include/fiction/algorithms/simulation/sidb/critical_temperature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
#include "fiction/utils/hash.hpp"
#include "fiction/utils/math_utils.hpp"
#include "fiction/utils/truth_table_utils.hpp"
#include "fiction/utils/units_utils.hpp"

#include <fmt/format.h>
#include <kitty/bit_operations.hpp>
#include <kitty/dynamic_truth_table.hpp>
#include <units.h>

#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -97,9 +95,9 @@ struct critical_temperature_params
*/
double confidence_level{0.99};
/**
* Simulation stops at max_temperature (~ 126 °C by default).
* Simulation stops at max_temperature (~ 126 °C by default) (unit: K).
*/
units::temperature::kelvin_t max_temperature{400_K};
double max_temperature{400};
/**
* Truth table of the given gate (if layout is simulated in `gate-based` mode).
*/
Expand All @@ -123,32 +121,31 @@ struct critical_temperature_stats
*/
std::string algorithm_name{};
/**
* Critical Temperature of the given layout.
* Critical Temperature of the given layout (unit: K).
*/
units::temperature::kelvin_t critical_temperature{0_K};
double critical_temperature{0};
/**
* Number of physically valid charge configurations.
*/
uint64_t num_valid_lyt{};
/**
* Energy difference between the ground state and the first (erroneous) excited state.
* Energy difference between the ground state and the first (erroneous) excited state (unit: eV).
*/
units::energy::electron_volt_t energy_between_ground_state_and_first_erroneous =
units::energy::electron_volt_t(std::numeric_limits<double>::infinity());
double energy_between_ground_state_and_first_erroneous = std::numeric_limits<double>::infinity();
/**
* Prints the simulation results to the given output stream.
*
* @param out Output stream.
*/
void report(std::ostream& out = std::cout) const
{
out << fmt::format("Critical Temperature = {:.2f} K\n", critical_temperature.value());
out << fmt::format("Critical Temperature = {:.2f} K\n", critical_temperature);

if (num_valid_lyt != 0)
{
out << fmt::format("'# of physically valid charge configurations': {} | Energy between ground state and "
"first erroneous: {}\n",
num_valid_lyt, energy_between_ground_state_and_first_erroneous.value());
num_valid_lyt, energy_between_ground_state_and_first_erroneous);
}
else
{
Expand Down Expand Up @@ -287,8 +284,8 @@ class critical_temperature_impl

else
{
temperature_stats.critical_temperature = 0.0_K; // If no ground state fulfills the logic, the Critical
// Temperature is zero. May be worth it to change µ_.
temperature_stats.critical_temperature = 0.0; // If no ground state fulfills the logic, the Critical
// Temperature is zero. May be worth it to change µ_.
}
}

Expand Down Expand Up @@ -329,10 +326,10 @@ class critical_temperature_impl
(first_excited_state_energy - ground_state_energy) * 1000;
}

std::vector<units::temperature::kelvin_t> temp_values{};
temp_values.reserve(static_cast<uint64_t>(parameter.max_temperature.value() * 100));
std::vector<double> temp_values{}; // unit: K
temp_values.reserve(static_cast<uint64_t>(parameter.max_temperature * 100));

for (uint64_t i = 1; i <= static_cast<uint64_t>(parameter.max_temperature.value() * 100); i++)
for (uint64_t i = 1; i <= static_cast<uint64_t>(parameter.max_temperature * 100); i++)
{
temp_values.emplace_back(static_cast<double>(i) / 100.0);
}
Expand All @@ -349,7 +346,7 @@ class critical_temperature_impl
break;
}

if (units::math::abs(temp - parameter.max_temperature) < 0.001_K)
if (std::abs(temp - parameter.max_temperature) < 0.001)
{
// Maximal temperature is stored as the Critical Temperature.
temperature_stats.critical_temperature = parameter.max_temperature;
Expand All @@ -366,11 +363,11 @@ class critical_temperature_impl
*
* @param energy_and_state_type All energies of all physically valid charge distributions with the corresponding
* state type (i.e. transparent, erroneous).
* @param min_energy Minimal energy of all physically valid charge distributions of a given layout.
* @param min_energy Minimal energy of all physically valid charge distributions of a given layout (unit: eV).
* @return State type (i.e. transparent, erroneous) of the ground state is returned.
*/
bool energy_between_ground_state_and_first_erroneous(const sidb_energy_and_state_type& energy_and_state_type,
const units::energy::electron_volt_t min_energy)
bool energy_between_ground_state_and_first_erroneous(const sidb_energy_and_state_type& energy_and_state_type,
const double min_energy)
{
bool ground_state_is_transparent = false;
for (const auto& [energy, state_type] : energy_and_state_type)
Expand Down Expand Up @@ -401,10 +398,10 @@ class critical_temperature_impl
void determine_critical_temperature(const sidb_energy_and_state_type& energy_state_type)
{
// Vector with temperature values from 0.01 to max_temperature * 100 K in 0.01 K steps is generated.
std::vector<units::temperature::kelvin_t> temp_values{};
temp_values.reserve(static_cast<uint64_t>(parameter.max_temperature.value() * 100));
std::vector<double> temp_values{};
temp_values.reserve(static_cast<uint64_t>(parameter.max_temperature * 100));

for (uint64_t i = 1; i <= static_cast<uint64_t>(parameter.max_temperature.value() * 100); i++)
for (uint64_t i = 1; i <= static_cast<uint64_t>(parameter.max_temperature * 100); i++)
{
temp_values.emplace_back(static_cast<double>(i) / 100.0);
}
Expand All @@ -420,7 +417,7 @@ class critical_temperature_impl
break;
}

if (units::math::abs(temp - parameter.max_temperature) < 0.001_K)
if (std::abs(temp - parameter.max_temperature) < 0.001)
{
// Maximal temperature is stored as Critical Temperature.
temperature_stats.critical_temperature = parameter.max_temperature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "fiction/technology/charge_distribution_surface.hpp"
#include "fiction/utils/math_utils.hpp"
#include "fiction/utils/units_utils.hpp"

#include <cmath>
#include <cstdint>
Expand All @@ -18,10 +17,10 @@ namespace fiction
{

/**
* Data type to collect electrostatic potential energies of charge distributions with corresponding degeneracy (i.e.
* how often a certain energy value occurs).
* Data type to collect electrostatic potential energies (unit: eV) of charge distributions with corresponding
* degeneracy (i.e. how often a certain energy value occurs).
*/
using sidb_energy_distribution = std::map<units::energy::electron_volt_t, uint64_t>;
using sidb_energy_distribution = std::map<double, uint64_t>; // unit: (eV, unitless)

/**
* This function takes in a vector of charge_distribution_surface objects and returns a map containing the system energy
Expand All @@ -39,7 +38,7 @@ energy_distribution(const std::vector<charge_distribution_surface<Lyt>>& input_v
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");

std::map<units::energy::electron_volt_t, uint64_t> distribution{};
std::map<double, uint64_t> distribution{}; // unit: (eV, unitless)

for (const auto& lyt : input_vec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "fiction/traits.hpp"
#include "fiction/utils/math_utils.hpp"

#include <units.h>

#include <cmath>

namespace fiction
Expand Down Expand Up @@ -44,7 +42,7 @@ template <typename Lyt>
const auto min_energy_exact = minimum_energy(exhaustive_results.charge_distributions);
const auto min_energy_new_ap = minimum_energy(quicksim_results.charge_distributions);

return round_to_n_decimal_places(units::math::abs(min_energy_exact - min_energy_new_ap), 6).value() == 0;
return round_to_n_decimal_places(std::abs(min_energy_exact - min_energy_new_ap), 6) == 0;
}

} // namespace fiction
Expand Down
10 changes: 4 additions & 6 deletions include/fiction/algorithms/simulation/sidb/minimum_energy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ namespace fiction
*
* @tparam Lyt Cell-level layout type.
* @param charge_lyts Vector of charge_distribution_surface objects.
* @return Value of the minimum energy found in the input vector.
* @return Value of the minimum energy found in the input vector (unit: eV).
*/
template <typename Lyt>
[[nodiscard]] units::energy::electron_volt_t
minimum_energy(const std::vector<charge_distribution_surface<Lyt>>& charge_lyts) noexcept
[[nodiscard]] double minimum_energy(const std::vector<charge_distribution_surface<Lyt>>& charge_lyts) 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");

return units::energy::electron_volt_t(
std::accumulate(charge_lyts.cbegin(), charge_lyts.cend(), std::numeric_limits<double>::max(),
[](const double a, const auto& lyt) { return std::min(a, lyt.get_system_energy().value()); }));
return std::accumulate(charge_lyts.cbegin(), charge_lyts.cend(), std::numeric_limits<double>::max(),
[](const double a, const auto& lyt) { return std::min(a, lyt.get_system_energy()); });
}

} // namespace fiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "fiction/algorithms/simulation/sidb/calculate_energy_and_state_type.hpp"
#include "fiction/utils/math_utils.hpp"
#include "fiction/utils/units_utils.hpp"

#include <algorithm>
#include <cassert>
Expand All @@ -27,20 +26,20 @@ namespace fiction
*
* @param energy_and_state_type This contains the energies of all possible charge distributions together with the
* information if the charge distribution (state) is transparent or erroneous.
* @param temperature System temperature to assume.
* @param temperature System temperature to assume (unit: K).
* @return The occupation probability of all erroneous states is returned.
*/
[[nodiscard]] inline double occupation_probability_gate_based(const sidb_energy_and_state_type& energy_and_state_type,
const units::temperature::kelvin_t& temperature) noexcept
[[nodiscard]] inline double occupation_probability_gate_based(const sidb_energy_and_state_type& energy_and_state_type,
const double temperature) noexcept
{
assert((temperature > 0.0_K) && "temperature should be slightly above 0 K");
assert((temperature > 0.0) && "temperature should be slightly above 0 K");

if (energy_and_state_type.empty())
{
return 0.0;
}

auto min_energy = units::energy::electron_volt_t(std::numeric_limits<double>::infinity());
auto min_energy = std::numeric_limits<double>::infinity(); // unit: eV

// Determine the minimal energy.
const auto [energy, state_type] = *std::min_element(energy_and_state_type.cbegin(), energy_and_state_type.cend(),
Expand All @@ -51,7 +50,7 @@ namespace fiction
const double partition_function =
std::accumulate(energy_and_state_type.cbegin(), energy_and_state_type.cend(), 0.0,
[&](const double sum, const auto& it)
{ return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature).value()); });
{ return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature)); });

// All Boltzmann factors of the erroneous states are summed.
double p = 0;
Expand All @@ -61,7 +60,7 @@ namespace fiction
{
if (!state_transparent_erroneous)
{
p += std::exp(-((energies - min_energy) * 12'000 / temperature).value());
p += std::exp(-((energies - min_energy) * 12'000 / temperature));
}
}

Expand All @@ -72,31 +71,30 @@ namespace fiction
* This function computes the occupation probability of excited states (charge distributions with energy higher than the
* ground state) at a given temperature.
*
* @param energy_distribution This contains the energies of all possible charge distributions with the degeneracy.
* @param temperature System temperature to assume.
* @param energy_distribution This contains the energies in eV of all possible charge distributions with the degeneracy.
* @param temperature System temperature to assume (unit: K).
* @return The total occupation probability of all excited states is returned.
*/
[[nodiscard]] inline double
occupation_probability_non_gate_based(const sidb_energy_distribution& energy_distribution,
const units::temperature::kelvin_t& temperature) noexcept
[[nodiscard]] inline double occupation_probability_non_gate_based(const sidb_energy_distribution& energy_distribution,
const double temperature) noexcept
{
assert((temperature > 0.0_K) && "Temperature should be slightly above 0 K");
assert((temperature > 0.0) && "Temperature should be slightly above 0 K");

if (energy_distribution.empty())
{
return 0.0;
}

auto min_energy = units::energy::electron_volt_t(std::numeric_limits<double>::infinity());
auto min_energy = std::numeric_limits<double>::infinity();
Drewniok marked this conversation as resolved.
Show resolved Hide resolved

const auto& [energy, degeneracy] = *(energy_distribution.begin());
min_energy = energy;
min_energy = energy; // unit: eV

// The partition function is obtained by summing up all the Boltzmann factors.
const double partition_function =
std::accumulate(energy_distribution.cbegin(), energy_distribution.cend(), 0.0,
[&](const double sum, const auto& it)
{ return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature).value()); });
{ return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature)); });

// All Boltzmann factors of the excited states are summed.
const double p =
Expand All @@ -107,7 +105,7 @@ occupation_probability_non_gate_based(const sidb_energy_distribution& energy
// possible rounding errors and for comparability with the min_energy.
if (round_to_n_decimal_places(it.first, 6) != round_to_n_decimal_places(min_energy, 6))
{
return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature).value());
return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature));
}
return sum;
});
Expand Down
Loading
Loading