From c5f9e9596b3ff9d9c984b37fed525d9c1609780d Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 24 Jan 2024 03:03:35 +0100 Subject: [PATCH 001/221] :construction: WIP code. --- cli/cmd/simulation/opdom.hpp | 13 +- .../operational_domain_siqad.cpp | 6 +- .../optimization/simulated_annealing.hpp | 40 +++- .../physical_design/design_sidb_gates.hpp | 205 +++++++++++++++++- .../simulation/sidb/is_operational.hpp | 106 +++++++++ .../simulation/sidb/operational_domain.hpp | 74 +++++-- .../simulation/sidb/operational_domain.cpp | 52 ++--- 7 files changed, 416 insertions(+), 80 deletions(-) diff --git a/cli/cmd/simulation/opdom.hpp b/cli/cmd/simulation/opdom.hpp index d1e2b495a..cfe48e465 100644 --- a/cli/cmd/simulation/opdom.hpp +++ b/cli/cmd/simulation/opdom.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -40,9 +41,7 @@ class opdom_command : public command * @param e alice::environment that specifies stores etc. */ explicit opdom_command(const environment::ptr& e) : - command(e, "Opdom is a quick and exact electrostatic ground state simulation algorithm designed " - "specifically for SiDB layouts. It provides a significant performance advantage of more than " - "three orders of magnitude over ExGS from SiQAD.") + command(e, "Opdom is used to determine the operational domain of SiDB gate layouts.") { add_option("--random_sampling,-r", num_random_samples, "Use random sampling instead of grid search with this many random samples"); @@ -230,13 +229,13 @@ class opdom_command : public command } else if (is_set("flood_fill")) { - op_domain = fiction::operational_domain_flood_fill(*lyt_ptr, std::vector{*tt_ptr}, - num_random_samples, params, &stats); + op_domain = fiction::operational_domain_flood_fill( + *lyt_ptr, std::vector{*tt_ptr}, num_random_samples, params, std::nullopt, &stats); } else if (is_set("contour_tracing")) { - op_domain = fiction::operational_domain_contour_tracing(*lyt_ptr, std::vector{*tt_ptr}, - num_random_samples, params, &stats); + op_domain = fiction::operational_domain_contour_tracing( + *lyt_ptr, std::vector{*tt_ptr}, num_random_samples, params, std::nullopt, &stats); } else { diff --git a/experiments/operational_domain/operational_domain_siqad.cpp b/experiments/operational_domain/operational_domain_siqad.cpp index 17a73342b..7ca428633 100644 --- a/experiments/operational_domain/operational_domain_siqad.cpp +++ b/experiments/operational_domain/operational_domain_siqad.cpp @@ -92,13 +92,13 @@ int main() // NOLINT // compute the operational domains const auto op_domain_gs = - operational_domain_grid_search(lyt, truth_table, op_domain_params, &op_domain_stats_gs); + operational_domain_grid_search(lyt, truth_table, op_domain_params,&op_domain_stats_gs); const auto op_domain_rs = operational_domain_random_sampling(lyt, truth_table, 2500, op_domain_params, &op_domain_stats_rs); const auto op_domain_ff = - operational_domain_flood_fill(lyt, truth_table, 250, op_domain_params, &op_domain_stats_ff); + operational_domain_flood_fill(lyt, truth_table, 250, op_domain_params, std::nullopt, &op_domain_stats_ff); const auto op_domain_ct = - operational_domain_contour_tracing(lyt, truth_table, 100, op_domain_params, &op_domain_stats_ct); + operational_domain_contour_tracing(lyt, truth_table, 100, op_domain_params,std::nullopt, &op_domain_stats_ct); // write the operational domains to a CSV file write_operational_domain(op_domain_gs, diff --git a/include/fiction/algorithms/optimization/simulated_annealing.hpp b/include/fiction/algorithms/optimization/simulated_annealing.hpp index 649fe709c..612a48897 100644 --- a/include/fiction/algorithms/optimization/simulated_annealing.hpp +++ b/include/fiction/algorithms/optimization/simulated_annealing.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -38,6 +39,20 @@ constexpr auto geometric_temperature_schedule(const double t) noexcept { return t * 0.99; } +/** + * Available temperature schedule types. + */ +enum class temperature_schedule +{ + /** + * Linearly decreasing temperature schedule. + */ + LINEAR, + /** + * Logarithmically decreasing temperature schedule. + */ + GEOMETRIC +}; /** * Simulated Annealing (SA) is a probabilistic optimization algorithm that is used to find a local minimum of a given * function. SA was first proposed in \"Optimization by simulated annealing\" by S. Kirkpatrick, C. D. Gelatt Jr, and M. @@ -173,12 +188,27 @@ multi_simulated_annealing(const double init_temp, const double final_temp, const assert(std::isfinite(final_temp) && "final_temp must be a finite number"); std::vector> results(instances); - std::generate( - FICTION_EXECUTION_POLICY_PAR_UNSEQ results.begin(), results.end(), - [&init_temp, &final_temp, &cycles, &rand_state, &cost, &schedule, &next]() -> std::pair - { return simulated_annealing(rand_state(), init_temp, final_temp, cycles, cost, schedule, next); }); + std::vector threads; + + // Function to perform simulated annealing and store the result in the results vector + auto perform_simulated_annealing = + [&results, &init_temp, &final_temp, &cycles, &rand_state, &cost, &schedule, &next](std::size_t index) + { results[index] = simulated_annealing(rand_state(), init_temp, final_temp, cycles, cost, schedule, next); }; + + // Start threads + for (std::size_t i = 0; i < instances; ++i) + { + threads.emplace_back(perform_simulated_annealing, i); + } + + // Join threads (wait for all threads to finish) + for (auto& thread : threads) + { + thread.join(); + } - return *std::min_element(FICTION_EXECUTION_POLICY_PAR_UNSEQ results.cbegin(), results.cend(), + // Find the minimum result + return *std::min_element(results.cbegin(), results.cend(), [](const auto& lhs, const auto& rhs) { return lhs.second < rhs.second; }); } diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 5186fe0d0..1e36226eb 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -5,6 +5,8 @@ #ifndef FICTION_DESIGN_SIDB_GATES_HPP #define FICTION_DESIGN_SIDB_GATES_HPP +#include "fiction/algorithms/optimization/simulated_annealing.hpp" +#include "fiction/algorithms/simulation/sidb/critical_temperature.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/algorithms/simulation/sidb/operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/random_sidb_layout_generator.hpp" @@ -26,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +38,29 @@ namespace fiction { +struct design_sidb_gates_sa_params +{ + /** + * Temperature schedule type. + */ + temperature_schedule schedule{temperature_schedule::LINEAR}; + /** + * Initial temperature. + */ + double initial_temperature{10000}; + /** + * Final temperature. + */ + double final_temperature{0.1}; + /** + * Number of iterations per temperature. + */ + std::size_t number_of_cycles{100}; + /** + * Number of parallel runs to pick the overall best result from. + */ + std::size_t number_of_instances{10}; +}; /** * This struct contains parameters and settings to design SiDB gates. * @@ -56,7 +82,11 @@ struct design_sidb_gates_params /** * Gate layouts are designed randomly. */ - RANDOM + RANDOM, + /** + * Gate layouts are designed with Simulated Annealing. + */ + SIMANNEAL }; /** * All Parameters for physical SiDB simulations. @@ -78,6 +108,8 @@ struct design_sidb_gates_params * The simulation engine to be used for the operational domain computation. */ sidb_simulation_engine sim_engine{sidb_simulation_engine::QUICKEXACT}; + + design_sidb_gates_sa_params simanneal_params{}; }; namespace detail @@ -99,8 +131,12 @@ class design_sidb_gates_impl skeleton_layout{skeleton}, truth_table{tt}, params{ps}, - all_sidbs_in_canvas{all_coordinates_in_spanned_area(params.canvas.first, params.canvas.second)} - {} + all_cells_in_canvas{all_coordinates_in_spanned_area(params.canvas.first, params.canvas.second)} + { + // Use std::uniform_int_distribution to generate a random index + random_canvas_cell_functor = std::uniform_int_distribution(0, all_cells_in_canvas.size() - 1); + random_canvas_sidb_functor = std::uniform_int_distribution(0, params.number_of_sidbs - 1); + } /** * Design gates exhaustively and in parallel. * @@ -210,6 +246,95 @@ class design_sidb_gates_impl return randomly_designed_gate_layouts; } + [[nodiscard]] std::vector run_sa_design() noexcept + { + std::vector randomly_designed_gate_layouts = {}; + generate_random_sidb_layout_params parameter{ + params.canvas, params.number_of_sidbs, + generate_random_sidb_layout_params::positive_charges::FORBIDDEN}; + const is_operational_params params_is_operational{params.phys_params, params.sim_engine}; + auto initial_lyt = generate_random_sidb_layout(skeleton_layout, parameter); + + const auto temperature_schedule = params.simanneal_params.schedule == temperature_schedule::LINEAR ? + linear_temperature_schedule : + geometric_temperature_schedule; + + canvas_sidbs = determine_canvas_sidbs(initial_lyt); + + const critical_temperature_params ct_params{sidb_simulation_parameters{ + 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; + + operational_domain_params op_domain_params{sidb_simulation_parameters{ + 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; + op_domain_params.x_min = 4.0; + op_domain_params.x_max = 6; + op_domain_params.x_step = 0.2; + + op_domain_params.y_min = 4.0; + op_domain_params.y_max = 6; + op_domain_params.y_step = 0.2; + + auto [optimized_placement, optimized_net_cost] = simulated_annealing( + initial_lyt, params.simanneal_params.initial_temperature, params.simanneal_params.final_temperature, + params.simanneal_params.number_of_cycles, + [&, this](const auto& lyt) + { + const auto logic_cost = number_of_operational_input_combinations(lyt, truth_table, skeleton_layout, + params_is_operational, params.canvas) * + 10; + double temp_cost = 1; + double opo_cost = 1; + if (logic_cost != 0.0) + { + temp_cost = + (- critical_temperature_gate_based(lyt, truth_table, ct_params)) / + ct_params.max_temperature; + operational_domain_stats stats{}; + const auto op_domain = operational_domain_flood_fill( + lyt, truth_table, 1, op_domain_params, operational_domain::parameter_point{5.6, 5}, &stats); + opo_cost = - stats.percentual_operational_area; + } + + return static_cast(logic_cost + temp_cost + opo_cost); + }, + temperature_schedule, + [&](auto lyt) + { + // print_layout(lyt); + const auto lyt_swap = move_sidb(lyt); + // const auto cost_logic = + // static_cast(number_of_operational_input_combinations( + // lyt_swap, truth_table, skeleton_layout, params_is_operational, + // params.canvas)); + // std::cout << fmt::format("cost logic: {}", + // cost_logic) + // << std::endl; + // std::cout << fmt::format( + // "cost temp: {}", + // static_cast( + // (400 - critical_temperature_gate_based(lyt_swap, truth_table, + // ct_params)) / 400)) + // << std::endl; + return lyt_swap; + }); + + std::cout << fmt::format("final cost: {}", optimized_net_cost) << std::endl; + std::cout << fmt::format("cost logic: {}", static_cast(number_of_operational_input_combinations( + optimized_placement, truth_table, skeleton_layout, + params_is_operational, params.canvas))) + << std::endl; + std::cout << fmt::format("cost temp: {}", static_cast(critical_temperature_gate_based( + optimized_placement, truth_table, ct_params))) + << std::endl; + operational_domain_stats stats{}; + const auto op_domain = operational_domain_flood_fill( + optimized_placement, truth_table, 1, op_domain_params, operational_domain::parameter_point{5.6, 5}, &stats); + std::cout << fmt::format("cost opdomain: {}", stats.percentual_operational_area) + << std::endl; + + return {optimized_placement}; + } + private: /** * The skeleton layout serves as a starting layout to which SiDBs are added to create unique SiDB layouts and, if @@ -227,7 +352,59 @@ class design_sidb_gates_impl /** * All cells within the canvas. */ - const std::vector all_sidbs_in_canvas; + const std::vector all_cells_in_canvas; + /** + * All SiDBs within the canvas. + */ + std::vector canvas_sidbs; + + /** + * A random-number generator. + */ + std::mt19937_64 generator{std::random_device{}()}; + /** + * + */ + std::uniform_int_distribution random_canvas_sidb_functor; + /** + * + */ + std::uniform_int_distribution random_canvas_cell_functor; + + [[nodiscard]] std::vector determine_canvas_sidbs(const Lyt& lyt) const noexcept + { + std::vector placed_canvas_sidbs = {}; + placed_canvas_sidbs.reserve(params.number_of_sidbs); + lyt.foreach_cell( + [&](const auto& cell) + { + if (std::find(all_cells_in_canvas.begin(), all_cells_in_canvas.end(), cell) != + all_cells_in_canvas.end()) + { + placed_canvas_sidbs.emplace_back(cell); + } + }); + return placed_canvas_sidbs; + } + + [[nodiscard]] Lyt move_sidb(const Lyt& lyt) noexcept + { + auto lyt_copy = lyt.clone(); + const auto random_index = random_canvas_cell_functor(generator); + const auto random_index_replace = random_canvas_sidb_functor(generator); + const auto random_cell = all_cells_in_canvas[random_index]; + const auto replace_sidb = canvas_sidbs[random_index_replace]; + + // cell has to be empty + if (!lyt_copy.is_empty_cell(random_cell)) + { + return lyt_copy; + } + lyt_copy.assign_cell_type(replace_sidb, Lyt::technology::cell_type::EMPTY); + lyt_copy.assign_cell_type(random_cell, Lyt::technology::cell_type::NORMAL); + canvas_sidbs[random_index_replace] = random_cell; + return lyt_copy; + } /** * Calculates all possible combinations of distributing the given number of SiDBs within a canvas * based on the provided parameters. It generates combinations of SiDB indices (representing the cell position in @@ -239,9 +416,9 @@ class design_sidb_gates_impl [[nodiscard]] std::vector> determine_all_combinations_of_given_sidbs_in_canvas() noexcept { std::vector> all_combinations{}; - all_combinations.reserve(binomial_coefficient(all_sidbs_in_canvas.size(), params.number_of_sidbs)); + all_combinations.reserve(binomial_coefficient(all_cells_in_canvas.size(), params.number_of_sidbs)); - std::vector numbers(all_sidbs_in_canvas.size()); + std::vector numbers(all_cells_in_canvas.size()); std::iota(numbers.begin(), numbers.end(), 0); combinations::for_each_combination( @@ -282,8 +459,8 @@ class design_sidb_gates_impl { for (std::size_t j = i + 1; j < cell_indices.size(); j++) { - if (sidb_nanometer_distance(skeleton_layout, all_sidbs_in_canvas[cell_indices[i]], - all_sidbs_in_canvas[cell_indices[j]]) < 0.5) + if (sidb_nanometer_distance(skeleton_layout, all_cells_in_canvas[cell_indices[i]], + all_cells_in_canvas[cell_indices[j]]) < 0.5) { return true; } @@ -303,11 +480,11 @@ class design_sidb_gates_impl for (const auto i : cell_indices) { - assert(i < all_sidbs_in_canvas.size() && "cell indices are out-of-range"); + assert(i < all_cells_in_canvas.size() && "cell indices are out-of-range"); - if (lyt_copy.get_cell_type(all_sidbs_in_canvas[i]) == sidb_technology::cell_type::EMPTY) + if (lyt_copy.get_cell_type(all_cells_in_canvas[i]) == sidb_technology::cell_type::EMPTY) { - lyt_copy.assign_cell_type(all_sidbs_in_canvas[i], sidb_technology::cell_type::NORMAL); + lyt_copy.assign_cell_type(all_cells_in_canvas[i], sidb_technology::cell_type::NORMAL); } } @@ -367,8 +544,12 @@ template { return p.run_exhaustive_design(); } + else if (params.design_mode == design_sidb_gates_params::design_sidb_gates_mode::RANDOM) + { + return p.run_random_design(); + } - return p.run_random_design(); + return p.run_sa_design(); } } // namespace fiction diff --git a/include/fiction/algorithms/simulation/sidb/is_operational.hpp b/include/fiction/algorithms/simulation/sidb/is_operational.hpp index aaa7a9f5f..aa69d66b2 100644 --- a/include/fiction/algorithms/simulation/sidb/is_operational.hpp +++ b/include/fiction/algorithms/simulation/sidb/is_operational.hpp @@ -176,6 +176,89 @@ class is_operational_impl // if we made it here, the layout is operational return operational_status::OPERATIONAL; } + + [[nodiscard]] std::size_t count_number_of_non_operational_input_combinations() noexcept + { + assert(!output_bdl_pairs.empty() && "No output cell provided."); + assert((truth_table.size() == output_bdl_pairs.size()) && + "Number of truth tables and output BDL pairs does not match"); + + std::size_t operational_input_combinations = 0; + + // number of different input combinations + for (auto i = 0u; i < truth_table.front().num_bits(); ++i, ++bii) + { + ++simulator_invocations; + + // if positively charged SiDBs can occur, the SiDB layout is considered as non-operational + if (can_positive_charges_occur(*bii, parameters.simulation_parameter)) + { + continue; + } + + // performs physical simulation of a given SiDB layout at a given input combination + const auto simulation_results = physical_simulation_of_layout(bii); + + // if no physically valid charge distributions were found, the layout is non-operational + if (simulation_results.charge_distributions.empty()) + { + continue; + } + + // find the ground state, which is the charge distribution with the lowest energy + const auto ground_state = std::min_element( + simulation_results.charge_distributions.cbegin(), simulation_results.charge_distributions.cend(), + [](const auto& lhs, const auto& rhs) { return lhs.get_system_energy() < rhs.get_system_energy(); }); + + // ground state is degenerate + if ((energy_distribution(simulation_results.charge_distributions).begin()->second) > 1) + { + continue; + } + + bool correct_output = true; + // fetch the charge states of the output BDL pair + for (auto output = 0u; output < output_bdl_pairs.size(); output++) + { + auto charge_state_output_upper = ground_state->get_charge_state(output_bdl_pairs[output].upper); + auto charge_state_output_lower = ground_state->get_charge_state(output_bdl_pairs[output].lower); + + // if the output charge states are equal, the layout is not operational + if (charge_state_output_lower == charge_state_output_upper) + { + correct_output = false; + break; + } + + const auto num = truth_table.front().num_bits(); + // if the expected output is 1, the expected charge states are (upper, lower) = (0, -1) + if (kitty::get_bit(truth_table[output], i)) + { + if (charge_state_output_lower != sidb_charge_state::NEGATIVE || + charge_state_output_upper != sidb_charge_state::NEUTRAL) + { + correct_output = false; + } + } + // if the expected output is 0, the expected charge states are (upper, lower) = (-1, 0) + else + { + if (charge_state_output_lower != sidb_charge_state::NEUTRAL || + charge_state_output_upper != sidb_charge_state::NEGATIVE) + { + correct_output = false; + } + } + } + if (correct_output) + { + operational_input_combinations++; + } + } + + // if we made it here, the layout is operational + return truth_table.front().num_bits() - operational_input_combinations; + } /** * Returns the total number of simulator invocations. * @@ -287,6 +370,29 @@ is_operational(const Lyt& lyt, const std::vector& spec, const is_operational return {p.run(), p.get_number_of_simulator_invocations()}; } +template +[[nodiscard]] uint64_t +number_of_operational_input_combinations(const Lyt& lyt, const std::vector& spec, const Lyt& skeleton, + const is_operational_params& params = {}, + const std::pair& canvas = {}) noexcept +{ + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(kitty::is_truth_table::value, "TT is not a truth table"); + + assert(lyt.num_pis() > 0 && "skeleton needs input cells"); + assert(lyt.num_pos() > 0 && "skeleton needs output cells"); + + assert(!spec.empty()); + // all elements in tts must have the same number of variables + assert(std::adjacent_find(spec.begin(), spec.end(), + [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.end()); + + detail::is_operational_impl p{lyt, spec, params}; + + return p.count_number_of_non_operational_input_combinations(); +} + } // namespace fiction #endif // FICTION_IS_OPERATIONAL_HPP diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index d141e8b17..719e522a6 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -16,12 +16,12 @@ #include "fiction/algorithms/simulation/sidb/sidb_simulation_engine.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" #include "fiction/layouts/cell_level_layout.hpp" -#include "fiction/technology/cell_technologies.hpp" #include "fiction/traits.hpp" #include "fiction/utils/execution_utils.hpp" #include "fiction/utils/hash.hpp" #include "fiction/utils/phmap_utils.hpp" +#include #include #include #include @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -236,6 +235,10 @@ struct operational_domain_stats * Number of parameter combinations, for which the layout is non-operational. */ std::size_t num_non_operational_parameter_combinations{0}; + /** + * The ratio of operational parameter pairs to all possible parameter pairs. Value is between 0 and 1. + */ + double percentual_operational_area{0.0}; }; namespace detail @@ -345,13 +348,21 @@ class operational_domain_impl * border around the domain. * * @param samples Maximum number of random samples to be taken before flood fill. + * @param initial_parameter Optional initial point in the parameter space for flood fill. * @return The (partial) operational domain of the layout. */ - [[nodiscard]] operational_domain flood_fill(const std::size_t samples) noexcept + [[nodiscard]] operational_domain + flood_fill(const std::size_t samples, + const std::optional& initial_parameter) noexcept { mockturtle::stopwatch stop{stats.time_total}; - const auto step_point_samples = generate_random_step_points(samples); + auto step_point_samples = generate_random_step_points(samples); + + if (initial_parameter.has_value()) + { + step_point_samples.emplace_back(to_step_point(initial_parameter.value())); + } // for each sample point in parallel std::for_each(FICTION_EXECUTION_POLICY_PAR_UNSEQ step_point_samples.cbegin(), step_point_samples.cend(), @@ -417,15 +428,33 @@ class operational_domain_impl * a one pixel wide border around it. * * @param samples Maximum number of random samples to be taken before contour tracing. + * @param initial_parameter Optional initial point in the parameter space for contour tracing. * @return The (partial) operational domain of the layout. */ - [[nodiscard]] operational_domain contour_tracing(const std::size_t samples) noexcept + [[nodiscard]] operational_domain + contour_tracing(const std::size_t samples, + const std::optional& initial_parameter_point) noexcept { mockturtle::stopwatch stop{stats.time_total}; - // first, perform random sampling to find an operational starting point - const auto starting_point = find_operational_step_point_via_random_sampling(samples); + std::optional starting_point{}; + bool starting_point_is_non_operational = true; + if (initial_parameter_point.has_value()) + { + const auto intital_step_point = to_step_point(initial_parameter_point.value()); + const auto operational_value = is_step_point_operational(intital_step_point); + if (operational_value == operational_status::OPERATIONAL) + { + starting_point = intital_step_point; + starting_point_is_non_operational = false; + } + } + if (starting_point_is_non_operational) + { + // first, perform random sampling to find an operational starting point + starting_point = find_operational_step_point_via_random_sampling(samples); + } // if no operational point was found within the specified number of samples, return if (!starting_point.has_value()) { @@ -948,6 +977,14 @@ class operational_domain_impl ++stats.num_non_operational_parameter_combinations; } } + // calculate the total number of parameter pairs + const std::size_t total_parameter_pairs = + (static_cast((params.x_max - params.x_min) / params.x_step) * + static_cast((params.y_max - params.y_min) / params.y_step)); + + // calculate the ratio of operational parameter pairs to the total number of parameter pairs + stats.percentual_operational_area = static_cast(stats.num_operational_parameter_combinations) / + static_cast(total_parameter_pairs); } }; @@ -1063,13 +1100,16 @@ operational_domain operational_domain_random_sampling(const Lyt& lyt, const std: * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param samples Number of samples to perform. * @param params Operational domain computation parameters. + * @param initial_parameter_point Optional initial point in the parameter space for flood fill. * @param stats Operational domain computation statistics. * @return The (partial) operational domain of the layout. */ template -operational_domain operational_domain_flood_fill(const Lyt& lyt, const std::vector& spec, const std::size_t samples, - const operational_domain_params& params = {}, - operational_domain_stats* stats = nullptr) +operational_domain operational_domain_flood_fill( + const Lyt& lyt, const std::vector& spec, const std::size_t samples, + const operational_domain_params& params = {}, + const std::optional& initial_parameter_point = std::nullopt, + operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -1078,7 +1118,7 @@ operational_domain operational_domain_flood_fill(const Lyt& lyt, const std::vect operational_domain_stats st{}; detail::operational_domain_impl p{lyt, spec, params, st}; - const auto result = p.flood_fill(samples); + const auto result = p.flood_fill(samples, initial_parameter_point); if (stats) { @@ -1113,14 +1153,16 @@ operational_domain operational_domain_flood_fill(const Lyt& lyt, const std::vect * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param samples Number of samples to perform. * @param params Operational domain computation parameters. + * @param initial_parameter_point Optional initial point in the parameter space for contour tracing. * @param stats Operational domain computation statistics. * @return The (partial) operational domain of the layout. */ template -operational_domain operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, - const std::size_t samples, - const operational_domain_params& params = {}, - operational_domain_stats* stats = nullptr) +operational_domain operational_domain_contour_tracing( + const Lyt& lyt, const std::vector& spec, const std::size_t samples, + const operational_domain_params& params = {}, + const std::optional& initial_parameter_point = std::nullopt, + operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -1129,7 +1171,7 @@ operational_domain operational_domain_contour_tracing(const Lyt& lyt, const std: operational_domain_stats st{}; detail::operational_domain_impl p{lyt, spec, params, st}; - const auto result = p.contour_tracing(samples); + const auto result = p.contour_tracing(samples, initial_parameter_point); if (stats) { diff --git a/test/algorithms/simulation/sidb/operational_domain.cpp b/test/algorithms/simulation/sidb/operational_domain.cpp index 265178809..de566ff10 100644 --- a/test/algorithms/simulation/sidb/operational_domain.cpp +++ b/test/algorithms/simulation/sidb/operational_domain.cpp @@ -125,7 +125,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lyt, std::vector{create_id_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() == 100); @@ -142,7 +142,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lyt, std::vector{create_id_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 100); @@ -158,7 +158,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") } } - SECTION("operational area, different number of steps in x- and y-direction") + SECTION("operational area, different amount of steps in x and y direction") { op_domain_params.x_min = 5.1; op_domain_params.x_max = 6.1; @@ -207,7 +207,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lyt, std::vector{create_id_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() == 50); @@ -224,7 +224,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lyt, std::vector{create_id_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() <= 50); @@ -289,7 +289,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lyt, std::vector{create_id_tt()}, 25, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct maximum size CHECK(op_domain.operational_values.size() <= 100); @@ -307,7 +307,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lyt, std::vector{create_id_tt()}, 25, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct maximum size CHECK(op_domain.operational_values.size() <= 25); @@ -323,28 +323,6 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") CHECK(op_domain_stats.num_non_operational_parameter_combinations <= 25); } } - SECTION("floating-point error") - { - op_domain_params.x_min = 2.5; - op_domain_params.x_max = 4.5; - op_domain_params.x_step = 0.9; - - op_domain_params.y_min = 2.5; - op_domain_params.y_max = 2.6; - op_domain_params.y_step = 0.1; - - SECTION("flood_fill") - { - const auto op_domain = operational_domain_flood_fill(lyt, std::vector{create_id_tt()}, 10000, - op_domain_params, &op_domain_stats); - - // check if the operational domain has the correct size - CHECK(op_domain.operational_values.size() == 2); - - CHECK(op_domain_stats.num_operational_parameter_combinations == 1); - CHECK(op_domain_stats.num_non_operational_parameter_combinations == 1); - } - } SECTION("semi-operational area") { op_domain_params.x_min = 0.5; @@ -392,7 +370,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lyt, std::vector{create_id_tt()}, 50, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() >= 80); @@ -409,7 +387,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lyt, std::vector{create_id_tt()}, 50, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 100); @@ -502,8 +480,8 @@ TEST_CASE("SiQAD's AND gate operational domain computation", "[operational-domai } SECTION("flood_fill") { - const auto op_domain = - operational_domain_flood_fill(lyt, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); + const auto op_domain = operational_domain_flood_fill(lyt, std::vector{create_and_tt()}, 1, op_domain_params, + std::nullopt, &op_domain_stats); // check if the operational domain has the correct size (10 steps in each dimension) CHECK(op_domain.operational_values.size() == 100); @@ -520,7 +498,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation", "[operational-domai SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lyt, std::vector{create_and_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 100); @@ -623,8 +601,8 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat } SECTION("flood_fill") { - const auto op_domain = - operational_domain_flood_fill(lyt, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); + const auto op_domain = operational_domain_flood_fill(lyt, std::vector{create_and_tt()}, 1, op_domain_params, + std::nullopt, &op_domain_stats); // check if the operational domain has the correct size (10 steps in each dimension) CHECK(op_domain.operational_values.size() == 100); @@ -641,7 +619,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lyt, std::vector{create_and_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 100); From 7a343ffe2f1f76cf5a16477c4bcd7821761a9b11 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 31 Jan 2024 17:11:02 +0100 Subject: [PATCH 002/221] :art: add missing 2-input Boolean functions. --- include/fiction/utils/truth_table_utils.hpp | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/include/fiction/utils/truth_table_utils.hpp b/include/fiction/utils/truth_table_utils.hpp index 003e78e50..6950ec2b3 100644 --- a/include/fiction/utils/truth_table_utils.hpp +++ b/include/fiction/utils/truth_table_utils.hpp @@ -127,6 +127,62 @@ namespace fiction return table; } +/** + * Creates and returns a truth table that implements the less-than function in two variables. + * + * @return Less-than function in two variables. + */ +[[nodiscard]] inline kitty::dynamic_truth_table create_lt_tt() noexcept +{ + constexpr const uint64_t lit = 0x2; + + kitty::dynamic_truth_table table{2}; + kitty::create_from_words(table, &lit, &lit + 1); + + return table; +} +/** + * Creates and returns a truth table that implements the greater-than function in two variables. + * + * @return Greater-than function in two variables. + */ +[[nodiscard]] inline kitty::dynamic_truth_table create_gt_tt() noexcept +{ + constexpr const uint64_t lit = 0x4; + + kitty::dynamic_truth_table table{2}; + kitty::create_from_words(table, &lit, &lit + 1); + + return table; +} +/** + * Creates and returns a truth table that implements the less-than-or-equal function in two variables. + * + * @return Less-than-or-equal function in two variables. + */ +[[nodiscard]] inline kitty::dynamic_truth_table create_le_tt() noexcept +{ + constexpr const uint64_t lit = 0x11; + + kitty::dynamic_truth_table table{2}; + kitty::create_from_words(table, &lit, &lit + 1); + + return table; +} +/** + * Creates and returns a truth table that implements the greater-than-or-equal function in two variables. + * + * @return Greater-than-or-equal function in two variables. + */ +[[nodiscard]] inline kitty::dynamic_truth_table create_ge_tt() noexcept +{ + constexpr const uint64_t lit = 0x13; + + kitty::dynamic_truth_table table{2}; + kitty::create_from_words(table, &lit, &lit + 1); + + return table; +} /** * Creates and returns a truth table that implements the majority function in three variables. * From 2e05a49081aa85fd110f69cbf28a60b6c4489707 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 31 Jan 2024 17:11:58 +0100 Subject: [PATCH 003/221] :art: small fix to allow initial parameter point. --- .../algorithms/simulation/sidb/operational_domain.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index 086f6af22..4944afc03 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -357,12 +357,16 @@ class operational_domain_impl { mockturtle::stopwatch stop{stats.time_total}; - auto step_point_samples = generate_random_step_points(samples); + std::vector step_point_samples = {}; if (initial_parameter.has_value()) { step_point_samples.emplace_back(to_step_point(initial_parameter.value())); } + else + { + step_point_samples = generate_random_step_points(samples); + } // for each sample point in parallel std::for_each(FICTION_EXECUTION_POLICY_PAR_UNSEQ step_point_samples.cbegin(), step_point_samples.cend(), @@ -979,8 +983,8 @@ class operational_domain_impl } // calculate the total number of parameter pairs const std::size_t total_parameter_pairs = - (static_cast((params.x_max - params.x_min) / params.x_step) * - static_cast((params.y_max - params.y_min) / params.y_step)); + (static_cast(std::round((params.x_max - params.x_min) / params.x_step)) * + static_cast(std::round((params.y_max - params.y_min) / params.y_step))); // calculate the ratio of operational parameter pairs to the total number of parameter pairs stats.percentual_operational_area = static_cast(stats.num_operational_parameter_combinations) / From 2a39afe1234eefe2163d3de863550897156bea74 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 31 Jan 2024 17:26:41 +0100 Subject: [PATCH 004/221] :art: add runtime option for critical temperature simulation. --- .../simulation/sidb/critical_temperature.hpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp index ef2b4c65b..ed8eed7e9 100644 --- a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp +++ b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp @@ -98,6 +98,10 @@ struct critical_temperature_params template struct critical_temperature_stats { + /** + * The total runtime of the critical temperature computation. + */ + mockturtle::stopwatch<>::duration time_total{0}; /** * All parameters for physical SiDB simulations. */ @@ -275,9 +279,12 @@ class critical_temperature_impl } std::vector temp_values{}; // unit: K - temp_values.reserve(static_cast(params.max_temperature * 100)); - for (uint64_t i = 1; i <= static_cast(params.max_temperature * 100); i++) + // Calculate the number of iterations as an integer + uint64_t num_iterations = static_cast(std::round(params.max_temperature * 100)); + // Reserve space for the vector + temp_values.reserve(num_iterations); + for (uint64_t i = 1; i <= num_iterations; i++) { temp_values.emplace_back(static_cast(i) / 100.0); } @@ -461,8 +468,8 @@ double critical_temperature_gate_based(const Lyt& lyt, const std::vector& sp assert(!spec.empty()); // all elements in tts must have the same number of variables - assert(std::adjacent_find(spec.cbegin(), spec.cend(), - [](const auto& a, const auto& b) + assert(std::adjacent_find(spec.cbegin(), spec.cend(), [ + (const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.cend()); critical_temperature_stats st{}; From 036dc5799c3243815224e061baafc25e7cd7e9c8 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 31 Jan 2024 17:33:03 +0100 Subject: [PATCH 005/221] :white_check_mark: check to test the runtime. --- test/algorithms/simulation/sidb/critical_temperature.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/algorithms/simulation/sidb/critical_temperature.cpp b/test/algorithms/simulation/sidb/critical_temperature.cpp index 6ef56d35f..28e3d738d 100644 --- a/test/algorithms/simulation/sidb/critical_temperature.cpp +++ b/test/algorithms/simulation/sidb/critical_temperature.cpp @@ -5,6 +5,8 @@ #include #include +#include "mockturtle/utils/stopwatch.hpp" + #include #include #include @@ -288,7 +290,7 @@ TEMPLATE_TEST_CASE( params.alpha = 0.7; critical_temperature_gate_based(lyt, std::vector{create_fan_out_tt()}, params, &critical_stats); - + CHECK(mockturtle::to_seconds(critical_stats.time_total) > 0); CHECK_THAT(std::abs(critical_stats.energy_between_ground_state_and_first_erroneous - 0.56), Catch::Matchers::WithinAbs(0.00, 0.01)); CHECK_THAT(std::abs(critical_stats.critical_temperature - 1.46), Catch::Matchers::WithinAbs(0.00, 0.01)); @@ -446,6 +448,7 @@ TEMPLATE_TEST_CASE( params.alpha = 0.6; critical_temperature_non_gate_based(lyt, params, &critical_stats); + CHECK(mockturtle::to_seconds(critical_stats.time_total) > 0); CHECK(critical_stats.algorithm_name == "QuickSim"); From 8a633696c758c6589d57a8ce52943502a0155991 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 31 Jan 2024 17:34:05 +0100 Subject: [PATCH 006/221] :art: add runtime. --- .../algorithms/simulation/sidb/critical_temperature.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp index ed8eed7e9..5578b5d96 100644 --- a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp +++ b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp @@ -176,6 +176,7 @@ class critical_temperature_impl template void gate_based_simulation(const std::vector& spec) noexcept { + mockturtle::stopwatch stop{stats.time_total}; if (layout.is_empty()) { stats.critical_temperature = 0.0; @@ -238,6 +239,7 @@ class critical_temperature_impl */ void non_gate_based_simulation() noexcept { + mockturtle::stopwatch stop{stats.time_total}; sidb_simulation_result simulation_results{}; if (params.engine == critical_temperature_params::simulation_engine::EXACT) @@ -468,9 +470,9 @@ double critical_temperature_gate_based(const Lyt& lyt, const std::vector& sp assert(!spec.empty()); // all elements in tts must have the same number of variables - assert(std::adjacent_find(spec.cbegin(), spec.cend(), [ - (const auto& a, const auto& b) - { return a.num_vars() != b.num_vars(); }) == spec.cend()); + assert(std::adjacent_find( + spec.cbegin(), spec.cend(), (const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == + spec.cend()); critical_temperature_stats st{}; From f977884a3a9cea5cbc4d58c08fb1e3e400d83eef Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 31 Jan 2024 17:41:28 +0100 Subject: [PATCH 007/221] :art: small fixes. --- .../simulation/sidb/is_operational.hpp | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/is_operational.hpp b/include/fiction/algorithms/simulation/sidb/is_operational.hpp index aa69d66b2..72f5ccbae 100644 --- a/include/fiction/algorithms/simulation/sidb/is_operational.hpp +++ b/include/fiction/algorithms/simulation/sidb/is_operational.hpp @@ -176,7 +176,11 @@ class is_operational_impl // if we made it here, the layout is operational return operational_status::OPERATIONAL; } - + /** + * Counts the number of input combinations yielding the correct output. + * + * @return The count of operational input combinations. + */ [[nodiscard]] std::size_t count_number_of_non_operational_input_combinations() noexcept { assert(!output_bdl_pairs.empty() && "No output cell provided."); @@ -257,7 +261,7 @@ class is_operational_impl } // if we made it here, the layout is operational - return truth_table.front().num_bits() - operational_input_combinations; + return (truth_table.front().num_bits() - operational_input_combinations); } /** * Returns the total number of simulator invocations. @@ -369,12 +373,21 @@ is_operational(const Lyt& lyt, const std::vector& spec, const is_operational return {p.run(), p.get_number_of_simulator_invocations()}; } - +/** + * This function calculates the count of input combinations for which the SiDB-based logic, represented by the + * provided layout (`lyt`) and truth table specifications (`spec`), produces the correct output. + * + * @tparam Lyt Type of the cell-level layout. + * @tparam TT Type of the truth table. + * @param lyt The SiDB layout. + * @param spec Vector of truth table specifications. + * @param params Parameters to simualte if a input combination is operational. + * @return The count of operational input combinations. + * + */ template -[[nodiscard]] uint64_t -number_of_operational_input_combinations(const Lyt& lyt, const std::vector& spec, const Lyt& skeleton, - const is_operational_params& params = {}, - const std::pair& canvas = {}) noexcept +[[nodiscard]] std::size_t number_of_operational_input_combinations(const Lyt& lyt, const std::vector& spec, + const is_operational_params& params = {}) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); From d42c33d872f356f91aefd3ead951987360339b0b Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 31 Jan 2024 17:53:05 +0100 Subject: [PATCH 008/221] :art: add missing includes. --- ...defect_influence_position_and_distance.hpp | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index ab258dc39..e1bc9510c 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,17 @@ struct maximum_defect_influence_distance_params std::pair additional_scanning_area{50, 6}; }; +/** + * Statistics for the maximum defect influence simulation. + */ +struct maximum_defect_influence_distance_stats +{ + /** + * The total runtime of the maximum defect influence simulation. + */ + mockturtle::stopwatch<>::duration time_total{0}; +}; + namespace detail { /** @@ -63,15 +75,19 @@ class maximum_defect_influence_position_and_distance_impl { public: maximum_defect_influence_position_and_distance_impl(const Lyt& lyt, - const maximum_defect_influence_distance_params& sim_params) : + const maximum_defect_influence_distance_params& sim_params, + maximum_defect_influence_distance_stats& st) : layout{lyt}, - params{sim_params} + params{sim_params}, + stats{st} { collect_all_defect_cells(); } std::pair run() noexcept { + mockturtle::stopwatch stop{stats.time_total}; + const quickexact_params> params_defect{ params.physical_params, quickexact_params>::automatic_base_number_detection::OFF}; @@ -154,7 +170,21 @@ class maximum_defect_influence_position_and_distance_impl }; // Apply the process_defect function to each defect using std::for_each - std::for_each(FICTION_EXECUTION_POLICY_PAR_UNSEQ defect_cells.cbegin(), defect_cells.cend(), process_defect); + + std::vector> futures{}; + futures.reserve(defect_cells.size()); + + // Start asynchronous tasks to process combinations in parallel + for (const auto& defect_cell : defect_cells) + { + futures.emplace_back(std::async(std::launch::async, process_defect, defect_cell)); + } + + for (auto& future : futures) + { + future.wait(); + } + // std::for_each(FICTION_EXECUTION_POLICY_PAR_UNSEQ defect_cells.cbegin(), defect_cells.cend(), process_defect); return {max_defect_position, avoidance_distance}; } @@ -168,10 +198,15 @@ class maximum_defect_influence_position_and_distance_impl * Parameters used for the simulation. */ maximum_defect_influence_distance_params params{}; + /** + * The statistics of the maximum defect influence position. + */ + maximum_defect_influence_distance_stats& stats; /** * All allowed defect positions. */ std::vector defect_cells{}; + /** * Collects all possible defect cell positions within a given layout while avoiding SiDB cells. * @@ -217,16 +252,26 @@ class maximum_defect_influence_position_and_distance_impl template std::pair maximum_defect_influence_position_and_distance(const Lyt& lyt, - const maximum_defect_influence_distance_params& sim_params = {}) + const maximum_defect_influence_distance_params& sim_params = {}, + maximum_defect_influence_distance_stats* pst = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(!has_offset_ucoord_v, "Lyt cannot be based on offset coordinates"); static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); - detail::maximum_defect_influence_position_and_distance_impl p{lyt, sim_params}; + maximum_defect_influence_distance_stats st{}; + + detail::maximum_defect_influence_position_and_distance_impl p{lyt, sim_params, st}; + + const auto result = p.run(); + + if (pst) + { + *pst = st; + } - return p.run(); + return result; } } // namespace fiction From 1444722f9d1972c0341091cfc15ba5f80a1927c2 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 5 Feb 2024 13:09:05 +0100 Subject: [PATCH 009/221] :construction: WIP code. --- experiments/gate_generator_exhaustive.cpp | 174 +++++ .../optimization/simulated_annealing.hpp | 65 +- .../physical_design/design_sidb_gates.hpp | 210 +++-- .../assess_physical_population_stability.hpp | 88 ++- ...hysical_population_stability_sidb_gate.hpp | 81 ++ .../simulation/sidb/critical_temperature.hpp | 7 +- ...defect_influence_position_and_distance.hpp | 4 + ...nce_position_and_distance_of_sidb_gate.hpp | 59 ++ .../assess_physical_population_stability.cpp | 732 +++++++++--------- ...hysical_population_stability_sidb_gate.cpp | 77 ++ .../simulation/sidb/critical_temperature.cpp | 2 +- ...defect_influence_position_and_distance.cpp | 47 ++ ...nce_position_and_distance_of_sidb_gate.cpp | 73 ++ 13 files changed, 1129 insertions(+), 490 deletions(-) create mode 100644 experiments/gate_generator_exhaustive.cpp create mode 100644 include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp create mode 100644 include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp create mode 100644 test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp create mode 100644 test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp new file mode 100644 index 000000000..1611420b5 --- /dev/null +++ b/experiments/gate_generator_exhaustive.cpp @@ -0,0 +1,174 @@ +// +// Created by Jan Drewniok 01.01.23 +// + +#include "fiction/types.hpp" // pre-defined types suitable for the FCN domain + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace fiction; + +int main() // NOLINT +{ + + static const std::string folder = + fmt::format("{}skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd", EXPERIMENTS_PATH); + + static const std::string solution_folder = fmt::format("{}metric_data/", EXPERIMENTS_PATH); + + const auto skeleton = read_sqd_layout(folder); + + design_sidb_gates_params params{ + sidb_simulation_parameters{2, -0.32}, + design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, + {{17, 7, 0}, {21, 11, 0}}, + 1, + sidb_simulation_engine::QUICKEXACT}; + + params.maximal_random_solutions = 100; + + const auto truth_tables = std::vector>{ + std::vector{create_and_tt()}, std::vector{create_xor_tt()}, std::vector{create_or_tt()}, + std::vector{create_xnor_tt()}, std::vector{create_nor_tt()}, std::vector{create_nand_tt()}, + std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, + std::vector{create_ge_tt()}}; + + const critical_temperature_params ct_params{sidb_simulation_parameters{ + 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; + + operational_domain_params op_domain_params{sidb_simulation_parameters{ + 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; + op_domain_params.x_min = 4.0; + op_domain_params.x_max = 6; + op_domain_params.x_step = 0.2; + + op_domain_params.y_min = 4.0; + op_domain_params.y_max = 6; + op_domain_params.y_step = 0.2; + + const assess_physical_population_stability_params_sidb_gate assess_params{ + assess_physical_population_stability_params{sidb_simulation_parameters{ + 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}}; + + const maximum_defect_influence_position_and_distance_of_sidb_gate_params defect_avoidance_params_arsenic{ + maximum_defect_influence_position_and_distance_of_sidb_gate_params{ + {sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}, params.phys_params, {20, 3}}}}; + + const maximum_defect_influence_position_and_distance_of_sidb_gate_params defect_avoidance_params_vacancy{ + maximum_defect_influence_position_and_distance_of_sidb_gate_params{ + {sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}, params.phys_params, {20, 3}}}}; + + uint64_t truth_counter = 0; + + for (const auto& truth_table : truth_tables) + { + std::cout << fmt::format("truth counter: {}", truth_counter) << std::endl; + for (auto num_sidbs = 2u; num_sidbs < 3; num_sidbs++) + { + std::cout << fmt::format("num sidbs: {}", num_sidbs) << std::endl; + params.number_of_sidbs = num_sidbs; + + mockturtle::stopwatch<>::duration time_total{}; + + std::vector all_gate{}; + std::vector temps = {}; + std::vector op_domains = {}; + std::vector defect_influence_arsenic = {}; + std::vector defect_influence_vacancy = {}; + std::vector pop_stability_neutral_to_negative = {}; + std::vector pop_stability_negative_to_neutral = {}; + { + mockturtle::stopwatch stop{time_total}; + + design_sidb_gates_stats stats{}; + + all_gate = design_sidb_gates(skeleton, truth_table, params, &stats); + + std::cout << fmt::format("gate design finished and {} gates were found", all_gate.size()) << std::endl; + + const auto calculate_metric_values = [&](const auto& gate) noexcept + { + temps.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); + operational_domain_stats stats{}; + const auto op_domain = operational_domain_flood_fill( + gate, truth_table, 0, op_domain_params, operational_domain::parameter_point{5.6, 5}, &stats); + op_domains.push_back(stats.percentual_operational_area); + const auto maximum_defect_influence_arsenic = + maximum_defect_influence_position_and_distance_of_sidb_gate(gate, truth_table, + defect_avoidance_params_arsenic); + defect_influence_arsenic.push_back(maximum_defect_influence_arsenic.second); + const auto maximum_defect_influence_vacancy = + maximum_defect_influence_position_and_distance_of_sidb_gate(gate, truth_table, + defect_avoidance_params_vacancy); + defect_influence_vacancy.push_back(maximum_defect_influence_vacancy.second); + + pop_stability_neutral_to_negative.push_back( + assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, -1)); + pop_stability_negative_to_neutral.push_back( + assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, 1)); + }; + + // Create a vector to store std::future objects + std::vector> futures{}; + futures.reserve(all_gate.size()); + + // Start asynchronous tasks to process combinations in parallel + for (const auto& gate : all_gate) + { + futures.emplace_back(std::async(std::launch::async, calculate_metric_values, gate)); + } + + // Wait for all tasks to finish + for (auto& future : futures) + { + future.wait(); + } + + for (auto l = 0u; l < all_gate.size(); l++) + { + const auto choose_gate = all_gate[l]; + write_sqd_layout(choose_gate, + fmt::format(solution_folder + "/sqd/17_7_21_11_numdbs_{}_ttnum_{}_{}.sqd", + num_sidbs, truth_counter, l)); + } + + // Open a file for writing + std::ofstream csvFile( + fmt::format(solution_folder + "/csv/17_7_21_11_numdbs_{}_ttnum_{}.csv", num_sidbs, truth_counter)); + + // Check if the file is open + if (!csvFile.is_open()) + { + std::cerr << "Error opening output.csv\n"; + return 1; + } + + // Write headers to the CSV file + csvFile << "temp,op,popstab_neg_to_neu,popstab_neu_to_neg,defect_influence_arsenic,defect_influence_" + "vacancy\n"; + + // Write data to the CSV file + for (std::size_t k = 0; k < temps.size(); ++k) + { + csvFile << temps[k] << "," << op_domains[k] << "," << pop_stability_negative_to_neutral[k] << "," + << pop_stability_neutral_to_negative[k] << "," << defect_influence_arsenic[k] << "," + << defect_influence_vacancy[k] << "\n"; + } + + // Close the file + csvFile.close(); + } + } + truth_counter++; + } + return EXIT_SUCCESS; +} diff --git a/include/fiction/algorithms/optimization/simulated_annealing.hpp b/include/fiction/algorithms/optimization/simulated_annealing.hpp index 612a48897..35df7893a 100644 --- a/include/fiction/algorithms/optimization/simulated_annealing.hpp +++ b/include/fiction/algorithms/optimization/simulated_annealing.hpp @@ -106,45 +106,40 @@ simulated_annealing(const State& init_state, const double init_temp, const doubl State best_state = current_state; auto best_cost = current_cost; - auto temp = init_temp; - - while (temp > final_temp) - { - for (std::size_t c = 0; c < cycles; ++c) - { - State new_state = next(current_state); - auto new_cost = cost(new_state); - - if (new_cost < best_cost) - { - best_state = new_state; - best_cost = new_cost; - current_state = std::move(new_state); - current_cost = std::move(new_cost); - - continue; - } - - const auto cost_delta = static_cast(new_cost - current_cost); - - // shortcut to skip the expensive std::exp call - if (cost_delta > 10.0 * temp) - { - continue; // as std::exp(-10.0) is a very small number + auto temp = init_temp; + + while (temp > final_temp) { + for (std::size_t c = 0; c < cycles; ++c) { + State new_state = next(current_state); + auto new_cost = cost(new_state); + + if (new_cost < best_cost) { + best_state = new_state; + best_cost = new_cost; + current_state = std::move(new_state); + current_cost = std::move(new_cost); + + continue; + } + + const auto cost_delta = static_cast(new_cost - current_cost); + + // shortcut to skip the expensive std::exp call + if (cost_delta > 10.0 * temp) { + continue; // as std::exp(-10.0) is a very small number + } + + // if the new state is worse, accept it with a probability of exp(-energy_delta/temp) + if (cost_delta <= 0.0 || std::exp(-cost_delta / temp) > random_functor(generator)) { + current_state = std::move(new_state); + current_cost = std::move(new_cost); + } } - // if the new state is worse, accept it with a probability of exp(-energy_delta/temp) - if (cost_delta <= 0.0 || std::exp(-cost_delta / temp) > random_functor(generator)) - { - current_state = std::move(new_state); - current_cost = std::move(new_cost); - } + // update temperature + temp = std::clamp(schedule(temp), final_temp, init_temp); } - // update temperature - temp = std::clamp(schedule(temp), final_temp, init_temp); - } - return {best_state, best_cost}; } /** diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 1e36226eb..dc66250f7 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -20,6 +20,7 @@ #include "fiction/utils/truth_table_utils.hpp" #include +#include #include #include @@ -43,7 +44,7 @@ struct design_sidb_gates_sa_params /** * Temperature schedule type. */ - temperature_schedule schedule{temperature_schedule::LINEAR}; + temperature_schedule schedule{temperature_schedule::GEOMETRIC}; /** * Initial temperature. */ @@ -51,15 +52,19 @@ struct design_sidb_gates_sa_params /** * Final temperature. */ - double final_temperature{0.1}; + double final_temperature{0.001}; /** * Number of iterations per temperature. */ - std::size_t number_of_cycles{100}; + std::size_t number_of_cycles{10}; /** * Number of parallel runs to pick the overall best result from. */ - std::size_t number_of_instances{10}; + std::size_t number_of_instances{100}; + + critical_temperature_params ct_params{}; + + operational_domain_params op_params{}; }; /** * This struct contains parameters and settings to design SiDB gates. @@ -95,7 +100,7 @@ struct design_sidb_gates_params /** * Gate design mode. */ - design_sidb_gates_mode design_mode = design_sidb_gates_mode::EXHAUSTIVE; + design_sidb_gates_mode design_mode = design_sidb_gates_mode::SIMANNEAL; /** * Canvas spanned by the northwest and southeast cell. */ @@ -110,6 +115,20 @@ struct design_sidb_gates_params sidb_simulation_engine sim_engine{sidb_simulation_engine::QUICKEXACT}; design_sidb_gates_sa_params simanneal_params{}; + + std::size_t maximal_random_solutions{}; +}; +/** + * Statistics for the design of SiDB gates. + */ +struct design_sidb_gates_stats +{ + /** + * The total runtime of SiDb gate design process. + */ + mockturtle::stopwatch<>::duration time_total{0}; + + double cost_of_gate{}; }; namespace detail @@ -127,16 +146,19 @@ class design_sidb_gates_impl * @param tt Expected Boolean function of the layout given as a multi-output truth table. * @param ps Parameters and settings for the gate designer. */ - design_sidb_gates_impl(const Lyt& skeleton, const std::vector& tt, const design_sidb_gates_params& ps) : + design_sidb_gates_impl(const Lyt& skeleton, const std::vector& tt, const design_sidb_gates_params& ps, + design_sidb_gates_stats& st) : skeleton_layout{skeleton}, truth_table{tt}, params{ps}, + stats{st}, all_cells_in_canvas{all_coordinates_in_spanned_area(params.canvas.first, params.canvas.second)} { // Use std::uniform_int_distribution to generate a random index random_canvas_cell_functor = std::uniform_int_distribution(0, all_cells_in_canvas.size() - 1); random_canvas_sidb_functor = std::uniform_int_distribution(0, params.number_of_sidbs - 1); } + /** * Design gates exhaustively and in parallel. * @@ -147,6 +169,7 @@ class design_sidb_gates_impl */ [[nodiscard]] std::vector run_exhaustive_design() noexcept { + mockturtle::stopwatch stop{stats.time_total}; const is_operational_params params_is_operational{params.phys_params, params.sim_engine}; const auto all_combinations = determine_all_combinations_of_given_sidbs_in_canvas(); @@ -176,17 +199,22 @@ class design_sidb_gates_impl futures.reserve(all_combinations.size()); // Start asynchronous tasks to process combinations in parallel + // for (const auto& combination : all_combinations) + // { + // futures.emplace_back( + // std::async(std::launch::async, add_combination_to_layout_and_check_operation, combination)); + // } + for (const auto& combination : all_combinations) { - futures.emplace_back( - std::async(std::launch::async, add_combination_to_layout_and_check_operation, combination)); + add_combination_to_layout_and_check_operation(combination); } // Wait for all tasks to finish - for (auto& future : futures) - { - future.wait(); - } + // for (auto& future : futures) + // { + // future.wait(); + // } return designed_gate_layouts; } @@ -199,9 +227,10 @@ class design_sidb_gates_impl * * @return A vector of designed SiDB gate layouts. */ - [[nodiscard]] std::vector run_random_design() noexcept + [[nodiscard]] std::vector run_random_design(uint64_t target_num_solutions = 1u) noexcept { - std::vector randomly_designed_gate_layouts = {}; + mockturtle::stopwatch stop{stats.time_total}; + std::vector randomly_designed_gate_layouts = {}; const is_operational_params params_is_operational{params.phys_params, params.sim_engine}; @@ -212,17 +241,16 @@ class design_sidb_gates_impl const std::size_t num_threads = std::thread::hardware_concurrency(); std::vector threads{}; threads.reserve(num_threads); - std::mutex mutex_to_protect_designed_gate_layouts{}; // used to control access to shared resources - - std::atomic gate_layout_is_found(false); + std::mutex mutex_to_protect_designed_gate_layouts{}; + std::atomic num_solutions_found(0); for (uint64_t z = 0u; z < num_threads; z++) { threads.emplace_back( - [this, &gate_layout_is_found, &mutex_to_protect_designed_gate_layouts, ¶meter, - ¶ms_is_operational, &randomly_designed_gate_layouts] + [this, &num_solutions_found, &mutex_to_protect_designed_gate_layouts, ¶meter, + ¶ms_is_operational, &randomly_designed_gate_layouts, target_num_solutions] { - while (!gate_layout_is_found) + while (num_solutions_found < target_num_solutions) { const auto result_lyt = generate_random_sidb_layout(skeleton_layout, parameter); if (const auto [status, sim_calls] = @@ -231,8 +259,8 @@ class design_sidb_gates_impl { const std::lock_guard lock{mutex_to_protect_designed_gate_layouts}; randomly_designed_gate_layouts.push_back(result_lyt); - gate_layout_is_found = true; - break; + num_solutions_found++; + // break; // Break out of the loop after finding a solution } } }); @@ -246,9 +274,17 @@ class design_sidb_gates_impl return randomly_designed_gate_layouts; } + /** + * Design gates with Simulated Annealing. + * + * This function adds cells randomly to the given skeleton, and determines whether the layout is operational + * based on the specified parameters. The design process is parallelized to improve performance. + * + * @return A vector of designed SiDB gate layouts. + */ [[nodiscard]] std::vector run_sa_design() noexcept { - std::vector randomly_designed_gate_layouts = {}; + mockturtle::stopwatch stop{stats.time_total}; generate_random_sidb_layout_params parameter{ params.canvas, params.number_of_sidbs, generate_random_sidb_layout_params::positive_charges::FORBIDDEN}; @@ -261,40 +297,36 @@ class design_sidb_gates_impl canvas_sidbs = determine_canvas_sidbs(initial_lyt); - const critical_temperature_params ct_params{sidb_simulation_parameters{ - 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; - - operational_domain_params op_domain_params{sidb_simulation_parameters{ - 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; - op_domain_params.x_min = 4.0; - op_domain_params.x_max = 6; - op_domain_params.x_step = 0.2; - - op_domain_params.y_min = 4.0; - op_domain_params.y_max = 6; - op_domain_params.y_step = 0.2; - auto [optimized_placement, optimized_net_cost] = simulated_annealing( initial_lyt, params.simanneal_params.initial_temperature, params.simanneal_params.final_temperature, params.simanneal_params.number_of_cycles, [&, this](const auto& lyt) { - const auto logic_cost = number_of_operational_input_combinations(lyt, truth_table, skeleton_layout, - params_is_operational, params.canvas) * - 10; - double temp_cost = 1; - double opo_cost = 1; - if (logic_cost != 0.0) + const auto logic_cost = + (is_operational(lyt, truth_table, params_is_operational).first == operational_status::OPERATIONAL) ? + 0 : + 10; + + double temp_cost = 0; + double opo_cost = 0; + if (logic_cost == 0) { temp_cost = - (- critical_temperature_gate_based(lyt, truth_table, ct_params)) / - ct_params.max_temperature; + -((critical_temperature_gate_based(lyt, truth_table, params.simanneal_params.ct_params)) / + params.simanneal_params.ct_params.max_temperature); operational_domain_stats stats{}; const auto op_domain = operational_domain_flood_fill( - lyt, truth_table, 1, op_domain_params, operational_domain::parameter_point{5.6, 5}, &stats); - opo_cost = - stats.percentual_operational_area; + lyt, truth_table, 0, params.simanneal_params.op_params, + operational_domain::parameter_point{params.phys_params.epsilon_r, params.phys_params.lambda_tf}, + &stats); + opo_cost = -stats.percentual_operational_area; } - + // if (logic_cost + temp_cost + opo_cost < -0.5) { + // std::cout << fmt::format("cost: {}", + // static_cast(logic_cost + temp_cost + + // opo_cost)) + // << std::endl; + // } return static_cast(logic_cost + temp_cost + opo_cost); }, temperature_schedule, @@ -319,19 +351,21 @@ class design_sidb_gates_impl }); std::cout << fmt::format("final cost: {}", optimized_net_cost) << std::endl; - std::cout << fmt::format("cost logic: {}", static_cast(number_of_operational_input_combinations( - optimized_placement, truth_table, skeleton_layout, - params_is_operational, params.canvas))) - << std::endl; - std::cout << fmt::format("cost temp: {}", static_cast(critical_temperature_gate_based( - optimized_placement, truth_table, ct_params))) - << std::endl; - operational_domain_stats stats{}; - const auto op_domain = operational_domain_flood_fill( - optimized_placement, truth_table, 1, op_domain_params, operational_domain::parameter_point{5.6, 5}, &stats); - std::cout << fmt::format("cost opdomain: {}", stats.percentual_operational_area) - << std::endl; - + // std::cout << fmt::format("cost logic: {}", + // static_cast(number_of_operational_input_combinations( + // optimized_placement, truth_table, + // params_is_operational))) + // << std::endl; + // std::cout << fmt::format("cost temp: {}", static_cast(critical_temperature_gate_based( + // optimized_placement, truth_table, ct_params))) + // << std::endl; + // operational_domain_stats stats{}; + // const auto op_domain = operational_domain_flood_fill(optimized_placement, truth_table, 1, + // op_domain_params, + // operational_domain::parameter_point{5.6, 5}, + // &stats); + // std::cout << fmt::format("cost opdomain: {}", stats.percentual_operational_area) << std::endl; + stats.cost_of_gate = optimized_net_cost; return {optimized_placement}; } @@ -349,6 +383,10 @@ class design_sidb_gates_impl * Parameters for the *SiDB Gate Designer*. */ const design_sidb_gates_params& params; + /** + * The statistics of the gate design. + */ + design_sidb_gates_stats& stats; /** * All cells within the canvas. */ @@ -358,6 +396,11 @@ class design_sidb_gates_impl */ std::vector canvas_sidbs; + std::vector old_canvas_sidbs; + std::pair swaped_pair{}; + + double logical_cost{}; + /** * A random-number generator. */ @@ -387,24 +430,32 @@ class design_sidb_gates_impl return placed_canvas_sidbs; } - [[nodiscard]] Lyt move_sidb(const Lyt& lyt) noexcept + [[nodiscard]] Lyt move_sidb(Lyt& lyt) noexcept { - auto lyt_copy = lyt.clone(); const auto random_index = random_canvas_cell_functor(generator); const auto random_index_replace = random_canvas_sidb_functor(generator); const auto random_cell = all_cells_in_canvas[random_index]; const auto replace_sidb = canvas_sidbs[random_index_replace]; // cell has to be empty - if (!lyt_copy.is_empty_cell(random_cell)) + if (!lyt.is_empty_cell(random_cell)) { - return lyt_copy; + return lyt; } - lyt_copy.assign_cell_type(replace_sidb, Lyt::technology::cell_type::EMPTY); - lyt_copy.assign_cell_type(random_cell, Lyt::technology::cell_type::NORMAL); + lyt.assign_cell_type(replace_sidb, Lyt::technology::cell_type::EMPTY); + lyt.assign_cell_type(random_cell, Lyt::technology::cell_type::NORMAL); + swaped_pair = {replace_sidb, random_cell}; + old_canvas_sidbs = canvas_sidbs; canvas_sidbs[random_index_replace] = random_cell; - return lyt_copy; + return lyt; + } + + void undo_swap(const Lyt& lyt) + { + lyt.assign_cell_type(swaped_pair.firsr, Lyt::technology::cell_type::NORMAL); + lyt.assign_cell_type(swaped_pair.second, Lyt::technology::cell_type::NORMAL); } + /** * Calculates all possible combinations of distributing the given number of SiDBs within a canvas * based on the provided parameters. It generates combinations of SiDB indices (representing the cell position in @@ -442,6 +493,7 @@ class design_sidb_gates_impl return all_combinations; } + /** * Checks if any SiDBs within the specified cell indices are located too closely together, with a distance of less * than 0.5 nanometers. @@ -468,6 +520,7 @@ class design_sidb_gates_impl } return false; } + /** * This function adds SiDBs (given by indices) to the skeleton layout that is returned afterwards. * @@ -523,7 +576,8 @@ class design_sidb_gates_impl */ template [[nodiscard]] std::vector design_sidb_gates(const Lyt& skeleton, const std::vector& spec, - const design_sidb_gates_params& params = {}) noexcept + const design_sidb_gates_params& params = {}, + design_sidb_gates_stats* stats = nullptr) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -538,18 +592,28 @@ template assert(std::adjacent_find(spec.begin(), spec.end(), [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.end()); - detail::design_sidb_gates_impl p{skeleton, spec, params}; + design_sidb_gates_stats st{}; + detail::design_sidb_gates_impl p{skeleton, spec, params, st}; + + std::vector result{}; if (params.design_mode == design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE) { - return p.run_exhaustive_design(); + result = p.run_exhaustive_design(); } else if (params.design_mode == design_sidb_gates_params::design_sidb_gates_mode::RANDOM) { - return p.run_random_design(); + result = p.run_random_design(params.maximal_random_solutions); } - - return p.run_sa_design(); + else + { + result = p.run_sa_design(); + } + if (stats) + { + *stats = st; + } + return result; } } // namespace fiction diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index f844d694f..bcebb75c9 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -67,15 +67,16 @@ struct population_stability_information /** * Charge transition from the current charge state to the closest one. */ - transition_type transition_from_to{}; + std::unordered_map> + transition_from_to_with_cell_and_required_pot{}; /** * Absolute electrostatic potential (unit: V) required for the charge state transition. */ - double minimum_potential_difference_to_transition{}; + std::unordered_map minimum_potential_difference_to_transition{}; /** * Distance (unit: nm) corresponding to the minimum potential difference. */ - double distance_corresponding_to_potential{}; + std::unordered_map distance_corresponding_to_potential{}; /** * Total electrostatic energy (unit: eV) of given charge distribution. */ @@ -154,7 +155,14 @@ class assess_physical_population_stability_impl const auto& charge_lyt = *it; population_stability_information population_stability_info{}; - population_stability_info.minimum_potential_difference_to_transition = + + population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE] = + std::numeric_limits::infinity(); + population_stability_info.minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL] = + std::numeric_limits::infinity(); + population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = + std::numeric_limits::infinity(); + population_stability_info.minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = std::numeric_limits::infinity(); charge_lyt.foreach_cell( @@ -186,10 +194,21 @@ class assess_physical_population_stability_impl } } }); - population_stability_info.system_energy = charge_lyt.get_system_energy(); - population_stability_info.distance_corresponding_to_potential = convert_potential_to_distance( - population_stability_info.minimum_potential_difference_to_transition, params.physical_parameters, - params.precision_for_distance_corresponding_to_potential); + population_stability_info.system_energy = charge_lyt.get_system_energy(); + + auto minimum_potential_difference = std::numeric_limits::infinity(); + + for (const auto& transition : population_stability_info.transition_from_to_with_cell_and_required_pot) + { + population_stability_info.distance_corresponding_to_potential[transition.first] = + convert_potential_to_distance(transition.second.second, params.physical_parameters, + params.precision_for_distance_corresponding_to_potential); + if (transition.second.second < minimum_potential_difference) + { + population_stability_info.critical_cell = transition.second.first; + minimum_potential_difference = transition.second.second; + } + } popstability_information.push_back(population_stability_info); } @@ -238,12 +257,17 @@ class assess_physical_population_stability_impl auto updated_pop_stability_information = pop_stability_information; if (std::abs(-local_potential + params.physical_parameters.mu_minus) < - updated_pop_stability_information.minimum_potential_difference_to_transition) + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL]) { - updated_pop_stability_information.minimum_potential_difference_to_transition = + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL] = std::abs(-local_potential + params.physical_parameters.mu_minus); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information.transition_from_to = transition_type::NEGATIVE_TO_NEUTRAL; + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::NEGATIVE_TO_NEUTRAL] = { + c, updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL]}; } return updated_pop_stability_information; @@ -268,24 +292,33 @@ class assess_physical_population_stability_impl std::abs(-local_potential + params.physical_parameters.mu_plus())) { if (std::abs(-local_potential + params.physical_parameters.mu_minus) < - updated_pop_stability_information.minimum_potential_difference_to_transition) + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE]) { - updated_pop_stability_information.minimum_potential_difference_to_transition = + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE] = std::abs(-local_potential + params.physical_parameters.mu_minus); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information.transition_from_to = transition_type::NEUTRAL_TO_NEGATIVE; + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_NEGATIVE] = { + c, updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE]}; } } - else { if (std::abs(-local_potential + params.physical_parameters.mu_plus()) < - updated_pop_stability_information.minimum_potential_difference_to_transition) + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]) { - updated_pop_stability_information.minimum_potential_difference_to_transition = + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = std::abs(-local_potential + params.physical_parameters.mu_plus()); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information.transition_from_to = transition_type::NEUTRAL_TO_POSITIVE; + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_POSITIVE] = { + c, updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]}; } } @@ -308,12 +341,17 @@ class assess_physical_population_stability_impl { auto updated_pop_stability_information = pop_stability_information; if (std::abs(-local_potential + params.physical_parameters.mu_plus()) < - updated_pop_stability_information.minimum_potential_difference_to_transition) + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL]) { - updated_pop_stability_information.minimum_potential_difference_to_transition = + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = std::abs(-local_potential + params.physical_parameters.mu_plus()); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information.transition_from_to = transition_type::POSITIVE_TO_NEUTRAL; + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::POSITIVE_TO_NEUTRAL] = { + c, updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL]}; } return updated_pop_stability_information; diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp new file mode 100644 index 000000000..9b6709089 --- /dev/null +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp @@ -0,0 +1,81 @@ +// +// Created by Jan Drewniok on 28.01.24. +// + +#ifndef FICTION_ASSESS_PHYSICAL_POPULATION_STABILITY_SIDB_GATE_HPP +#define FICTION_ASSESS_PHYSICAL_POPULATION_STABILITY_SIDB_GATE_HPP + +#include "fiction/algorithms/iter/bdl_input_iterator.hpp" +#include "fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp" +#include "fiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" +#include "fiction/utils/layout_utils.hpp" + +namespace fiction +{ +/** + * This struct stores the parameters required to assess the population stability of an SiDB gate. + */ +struct assess_physical_population_stability_params_sidb_gate +{ + /** + * Parameter to as + */ + assess_physical_population_stability_params assess_population_stability_params{}; + detect_bdl_pairs_params detect_pair_params{}; +}; + +template +[[nodiscard]] double +assess_physical_population_stability_sidb_gate(const Lyt& lyt, const std::vector& spec, + const assess_physical_population_stability_params_sidb_gate& params = {}, + const int8_t charge_state_change = 1) noexcept +{ + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(!has_offset_ucoord_v, "Lyt should not be based on offset coordinates"); + static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); + + assert(lyt.num_pis() > 0 && "skeleton needs input cells"); + assert(lyt.num_pos() > 0 && "skeleton needs output cells"); + + assert(!spec.empty()); + // all elements in tts must have the same number of variables + assert(std::adjacent_find(spec.begin(), spec.end(), + [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.end()); + + bdl_input_iterator bii{lyt, params.detect_pair_params}; + double maximal_pop_stability_for_all_inputs = 0; + // number of different input combinations + for (auto i = 0u; i < spec.front().num_bits(); ++i, ++bii) + { + const auto pop_stability = + assess_physical_population_stability(lyt, params.assess_population_stability_params); + if (!pop_stability.empty()) + { + const auto stability_for_given_input = pop_stability.front().distance_corresponding_to_potential; + double distance_corresponding_to_potential = 0.0; + + if (charge_state_change == 1) + { + distance_corresponding_to_potential = + stability_for_given_input.at(transition_type::NEGATIVE_TO_NEUTRAL); + } + + if (charge_state_change == -1) + { + distance_corresponding_to_potential = + stability_for_given_input.at(transition_type::NEUTRAL_TO_NEGATIVE); + } + + if (distance_corresponding_to_potential > maximal_pop_stability_for_all_inputs) + { + maximal_pop_stability_for_all_inputs = distance_corresponding_to_potential; + } + } + } + return maximal_pop_stability_for_all_inputs; +} + +} // namespace fiction + +#endif // FICTION_ASSESS_PHYSICAL_POPULATION_STABILITY_SIDB_GATE_HPP diff --git a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp index 5578b5d96..4e53c8f14 100644 --- a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp +++ b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp @@ -239,7 +239,7 @@ class critical_temperature_impl */ void non_gate_based_simulation() noexcept { - mockturtle::stopwatch stop{stats.time_total}; + mockturtle::stopwatch stop{stats.time_total}; sidb_simulation_result simulation_results{}; if (params.engine == critical_temperature_params::simulation_engine::EXACT) @@ -470,9 +470,8 @@ double critical_temperature_gate_based(const Lyt& lyt, const std::vector& sp assert(!spec.empty()); // all elements in tts must have the same number of variables - assert(std::adjacent_find( - spec.cbegin(), spec.cend(), (const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == - spec.cend()); + assert(std::adjacent_find(spec.cbegin(), spec.cend(), [](const auto& a, const auto& b) + { return a.num_vars() != b.num_vars(); }) == spec.cend()); critical_temperature_stats st{}; diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index e1bc9510c..5ee6c65a1 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -15,6 +15,8 @@ #include "fiction/utils/execution_utils.hpp" #include "fiction/utils/layout_utils.hpp" +#include + #include #include #include @@ -164,6 +166,8 @@ class maximum_defect_influence_position_and_distance_impl { max_defect_position = defect; avoidance_distance = distance; +// std::cout << fmt::format("defect position x: {}, y: {}\n", max_defect_position.x, +// max_defect_position.y, distance); } } } diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp new file mode 100644 index 000000000..a722d1c45 --- /dev/null +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -0,0 +1,59 @@ +// +// Created by Jan Drewniok on 28.12.23. +// + +#ifndef FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP +#define FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP + +#include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" +#include "fiction/utils/layout_utils.hpp" + +namespace fiction +{ + +struct maximum_defect_influence_position_and_distance_of_sidb_gate_params +{ + maximum_defect_influence_distance_params defect_influence_params{}; + detect_bdl_pairs_params bdl_pairs_params{}; +}; + +template +[[nodiscard]] std::pair maximum_defect_influence_position_and_distance_of_sidb_gate( + const Lyt& lyt, const std::vector& spec, + const maximum_defect_influence_position_and_distance_of_sidb_gate_params& params = {}) noexcept +{ + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(!has_offset_ucoord_v, "Lyt should not be based on offset coordinates"); + static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); + + assert(lyt.num_pis() > 0 && "skeleton needs input cells"); + assert(lyt.num_pos() > 0 && "skeleton needs output cells"); + + assert(!spec.empty()); + // all elements in tts must have the same number of variables + assert(std::adjacent_find(spec.begin(), spec.end(), + [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.end()); + + bdl_input_iterator bii{lyt, params.bdl_pairs_params}; + double maximum_defect_influence_distance = 0.0; + cell defect_cell{}; + // number of different input combinations + for (auto i = 0u; i < spec.front().num_bits(); ++i, ++bii) + { + maximum_defect_influence_distance_stats stats_defect{}; + const auto influence_cell_distance = + maximum_defect_influence_position_and_distance(lyt, params.defect_influence_params, &stats_defect); + //std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; + if (influence_cell_distance.second > maximum_defect_influence_distance) + { + maximum_defect_influence_distance = influence_cell_distance.second; + defect_cell = influence_cell_distance.first; + } + } + return {defect_cell, maximum_defect_influence_distance}; +} + +} // namespace fiction + +#endif // FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp index 3b25b8161..8735e08c6 100644 --- a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp +++ b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp @@ -27,10 +27,17 @@ TEST_CASE("Single SiDB", "[assess-physical-population-stability]") REQUIRE(result.size() == 1); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{1, 1, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEGATIVE_TO_NEUTRAL); - CHECK(population_stability_detail.minimum_potential_difference_to_transition == 0.29); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(0.77, 1e-5)); + REQUIRE(population_stability_detail.transition_from_to_with_cell_and_required_pot.size() == 1); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEGATIVE_TO_NEUTRAL) + .first == siqad::coord_t{1, 1, 0}); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEGATIVE_TO_NEUTRAL) + .second == 0.29); + + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEGATIVE_TO_NEUTRAL), + Catch::Matchers::WithinAbs(0.77, 1e-5)); } SECTION("Precision of distance_corresponding_to_potential is three") @@ -39,11 +46,9 @@ TEST_CASE("Single SiDB", "[assess-physical-population-stability]") const auto result = assess_physical_population_stability(lyt, params); REQUIRE(result.size() == 1); const auto& population_stability_detail = result[0]; - CHECK(population_stability_detail.critical_cell == siqad::coord_t{1, 1, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEGATIVE_TO_NEUTRAL); - CHECK(population_stability_detail.minimum_potential_difference_to_transition == 0.29); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(0.762, 1e-5)); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEGATIVE_TO_NEUTRAL), + Catch::Matchers::WithinAbs(0.762, 1e-5)); } } @@ -68,348 +73,371 @@ TEST_CASE("Three SiDBs with positive charge states", "[assess-physical-populatio { const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{2, 1, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEGATIVE_TO_NEUTRAL); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.43); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(0.56, 1e-5)); - } - SECTION("1st excited state") - { - const auto& population_stability_detail = result[1]; - CHECK(population_stability_detail.critical_cell == siqad::coord_t{2, 1, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEGATIVE_TO_NEUTRAL); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.23); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(0.94, 1e-5)); - } - - SECTION("2nd excited state") - { - const auto& population_stability_detail = result[2]; - CHECK(population_stability_detail.critical_cell == siqad::coord_t{1, 1, 1}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.21); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(1.01, 1e-5)); - } -} - -TEST_CASE("Bestagon AND gate", "[assess-physical-population-stability]") -{ - layout lyt{}; - const auto params = assess_physical_population_stability_params{}; - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - - SECTION("no input specified") - { - const auto result = assess_physical_population_stability(lyt, params); - REQUIRE(result.size() == 8); - const auto& population_stability_detail = result[0]; - CHECK(population_stability_detail.critical_cell == siqad::coord_t{2, 1, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.021); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(4.79, 1e-5)); - } - - SECTION("input 00") - { - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::EMPTY); - const auto result = assess_physical_population_stability(lyt, params); - REQUIRE(result.size() == 2); - const auto& population_stability_detail = result[0]; - CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 5, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.026); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(4.32, 1e-5)); - } - - SECTION("input 01") - { - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::EMPTY); - - const auto result = assess_physical_population_stability(lyt, params); - REQUIRE(result.size() == 4); - const auto& population_stability_detail = result[0]; - CHECK(population_stability_detail.critical_cell == siqad::coord_t{32, 18, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.041); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(3.3, 1e-5)); - } - - SECTION("input 10") - { - lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::EMPTY); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::EMPTY); - - const auto result = assess_physical_population_stability(lyt, params); - REQUIRE(result.size() == 8); - const auto& population_stability_detail = result[0]; - CHECK(population_stability_detail.critical_cell == siqad::coord_t{19, 8, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.02); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(4.87, 1e-5)); - } - - SECTION("input 11") - { - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::EMPTY); - - const auto result = assess_physical_population_stability(lyt, params); - REQUIRE(result.size() == 2); - const auto& population_stability_detail = result[0]; - CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 5, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.026); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(4.32, 1e-5)); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::POSITIVE_TO_NEUTRAL) + .first == siqad::coord_t{1, 1, 0}); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEGATIVE_TO_NEUTRAL) + .first == siqad::coord_t{2, 1, 0}); + CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( + transition_type::NEGATIVE_TO_NEUTRAL) < 0.43); + CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( + transition_type::POSITIVE_TO_NEUTRAL) < 0.81); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEGATIVE_TO_NEUTRAL), + Catch::Matchers::WithinAbs(0.56, 1e-5)); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::POSITIVE_TO_NEUTRAL), + Catch::Matchers::WithinAbs(0.31, 1e-5)); } +// SECTION("1st excited state") +// { +// const auto& population_stability_detail = result[1]; +// CHECK(population_stability_detail.critical_cell == siqad::coord_t{2, 1, 0}); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == +// transition_type::NEGATIVE_TO_NEUTRAL); +// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.23); +// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, +// Catch::Matchers::WithinAbs(0.94, 1e-5)); +// } +// +// SECTION("2nd excited state") +// { +// const auto& population_stability_detail = result[2]; +// CHECK(population_stability_detail.critical_cell == siqad::coord_t{1, 1, 1}); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == +// transition_type::NEUTRAL_TO_NEGATIVE); +// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.21); +// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, +// Catch::Matchers::WithinAbs(1.01, 1e-5)); +// } } - -TEST_CASE("Bestagon CROSSING gate input 11, using siqad coordinates", "[assess-physical-population-stability]") -{ - layout lyt{}; - const auto params = assess_physical_population_stability_params{}; - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({20, 12, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 11, 1}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({14, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({12, 16, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 13, 1}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({16, 13, 1}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({20, 8, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({6, 18, 0}, sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({8, 17, 0}, sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type({2, 19, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - - CHECK(lyt.num_cells() == 27); - - const auto result = assess_physical_population_stability(lyt, params); - REQUIRE(result.size() == 20); - const auto& population_stability_detail = result[0]; - CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 9, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.01); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(6.88, 1e-5)); -} - -TEST_CASE("Bestagon CROSSING gate input 11, using cube coordinates", "[assess-physical-population-stability]") -{ - cell_level_layout>> lyt{}; - - const auto params = assess_physical_population_stability_params{}; - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 1, 0}), - sidb_technology::cell_type::INPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 1, 0}), - sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 2, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 12, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 3, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 5, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 11, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 4, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 15, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 4, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 9, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 15, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 16, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{18, 9, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 16, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 13, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 5, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 3, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{16, 13, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 2, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 8, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 17, 0}), - sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 18, 0}), - sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 18, 0}), - sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 17, 0}), - sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 19, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 19, 0}), - sidb_technology::cell_type::NORMAL); - - CHECK(lyt.num_cells() == 27); - - const auto result = assess_physical_population_stability(lyt, params); - REQUIRE(result.size() == 20); - const auto& population_stability_detail = result[0]; - CHECK(population_stability_detail.critical_cell == cube::coord_t{14, 18, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.01); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(6.88, 1e-5)); -} - -TEST_CASE("Bestagon CROSSING gate input 11, using offset coordinates", "[assess-physical-population-stability]") -{ - cell_level_layout>> lyt{}; - - const auto params = assess_physical_population_stability_params{}; - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 1, 0}), - sidb_technology::cell_type::INPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 1, 0}), - sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 2, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 12, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 3, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 5, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 11, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 4, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 15, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 4, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 9, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 15, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 16, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{18, 9, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 16, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 13, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 5, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 3, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{16, 13, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 2, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 8, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 17, 0}), - sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 18, 0}), - sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 18, 0}), - sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 17, 0}), - sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 19, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 19, 0}), - sidb_technology::cell_type::NORMAL); - - CHECK(lyt.num_cells() == 27); - - const auto result = assess_physical_population_stability(lyt, params); - REQUIRE(result.size() == 20); - const auto& population_stability_detail = result[0]; - CHECK(population_stability_detail.critical_cell == offset::ucoord_t{14, 18, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.01); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(6.88, 1e-5)); -} +// + TEST_CASE("Bestagon AND gate", "[assess-physical-population-stability]") + { + layout lyt{}; + const auto params = assess_physical_population_stability_params{}; + lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); + lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); + + lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + + SECTION("no input specified") + { + const auto result = assess_physical_population_stability(lyt, params); + REQUIRE(result.size() == 8); + const auto& population_stability_detail = result[0]; + CHECK(population_stability_detail.critical_cell == siqad::coord_t{2, 1, 0}); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == +// transition_type::NEUTRAL_TO_NEGATIVE); +// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.021); +// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, +// Catch::Matchers::WithinAbs(4.79, 1e-5)); + } + } +// +// SECTION("input 00") +// { +// lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); +// lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::EMPTY); +// const auto result = assess_physical_population_stability(lyt, params); +// REQUIRE(result.size() == 2); +// const auto& population_stability_detail = result[0]; +// CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 5, 0}); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == +// transition_type::NEUTRAL_TO_NEGATIVE); +// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.026); +// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, +// Catch::Matchers::WithinAbs(4.32, 1e-5)); +// } +// +// SECTION("input 01") +// { +// lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); +// lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::EMPTY); +// +// const auto result = assess_physical_population_stability(lyt, params); +// REQUIRE(result.size() == 4); +// const auto& population_stability_detail = result[0]; +// CHECK(population_stability_detail.critical_cell == siqad::coord_t{32, 18, 0}); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == +// transition_type::NEUTRAL_TO_NEGATIVE); +// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.041); +// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, +// Catch::Matchers::WithinAbs(3.3, 1e-5)); +// } +// +// SECTION("input 10") +// { +// lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::EMPTY); +// lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::EMPTY); +// +// const auto result = assess_physical_population_stability(lyt, params); +// REQUIRE(result.size() == 8); +// const auto& population_stability_detail = result[0]; +// CHECK(population_stability_detail.critical_cell == siqad::coord_t{19, 8, 0}); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == +// transition_type::NEUTRAL_TO_NEGATIVE); +// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.02); +// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, +// Catch::Matchers::WithinAbs(4.87, 1e-5)); +// } +// +// SECTION("input 11") +// { +// lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); +// lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::EMPTY); +// +// const auto result = assess_physical_population_stability(lyt, params); +// REQUIRE(result.size() == 2); +// const auto& population_stability_detail = result[0]; +// CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 5, 0}); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == +// transition_type::NEUTRAL_TO_NEGATIVE); +// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.026); +// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, +// Catch::Matchers::WithinAbs(4.32, 1e-5)); +// } +//} +// +// TEST_CASE("Bestagon CROSSING gate input 11, using siqad coordinates", "[assess-physical-population-stability]") +//{ +// layout lyt{}; +// const auto params = assess_physical_population_stability_params{}; +// lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); +// lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); +// +// lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({20, 12, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({14, 11, 1}, sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({14, 15, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type({14, 9, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({12, 16, 0}, sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({24, 13, 1}, sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({16, 13, 1}, sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({20, 8, 0}, sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); +// lyt.assign_cell_type({6, 18, 0}, sidb_technology::cell_type::OUTPUT); +// +// lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); +// lyt.assign_cell_type({8, 17, 0}, sidb_technology::cell_type::OUTPUT); +// +// lyt.assign_cell_type({2, 19, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); +// +// CHECK(lyt.num_cells() == 27); +// +// const auto result = assess_physical_population_stability(lyt, params); +// REQUIRE(result.size() == 20); +// const auto& population_stability_detail = result[0]; +// CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 9, 0}); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == +// transition_type::NEUTRAL_TO_NEGATIVE); +// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.01); +// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, +// Catch::Matchers::WithinAbs(6.88, 1e-5)); +//} +// +// TEST_CASE("Bestagon CROSSING gate input 11, using cube coordinates", "[assess-physical-population-stability]") +//{ +// cell_level_layout>> lyt{}; +// +// const auto params = assess_physical_population_stability_params{}; +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 1, 0}), +// sidb_technology::cell_type::INPUT); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 1, 0}), +// sidb_technology::cell_type::INPUT); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 2, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 12, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 3, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 5, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 11, 1}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 4, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 15, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 4, 0}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 9, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 15, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 16, 0}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{18, 9, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 16, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 13, 1}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 5, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 3, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{16, 13, 1}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 2, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 8, 0}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 17, 0}), +// sidb_technology::cell_type::OUTPUT); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 18, 0}), +// sidb_technology::cell_type::OUTPUT); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 18, 0}), +// sidb_technology::cell_type::OUTPUT); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 17, 0}), +// sidb_technology::cell_type::OUTPUT); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 19, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 19, 0}), +// sidb_technology::cell_type::NORMAL); +// +// CHECK(lyt.num_cells() == 27); +// +// const auto result = assess_physical_population_stability(lyt, params); +// REQUIRE(result.size() == 20); +// const auto& population_stability_detail = result[0]; +// CHECK(population_stability_detail.critical_cell == cube::coord_t{14, 18, 0}); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == +// transition_type::NEUTRAL_TO_NEGATIVE); +// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.01); +// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, +// Catch::Matchers::WithinAbs(6.88, 1e-5)); +//} +// +// TEST_CASE("Bestagon CROSSING gate input 11, using offset coordinates", "[assess-physical-population-stability]") +//{ +// cell_level_layout>> lyt{}; +// +// const auto params = assess_physical_population_stability_params{}; +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 1, 0}), +// sidb_technology::cell_type::INPUT); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 1, 0}), +// sidb_technology::cell_type::INPUT); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 2, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 12, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 3, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 5, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 11, 1}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 4, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 15, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 4, 0}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 9, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 15, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 16, 0}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{18, 9, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 16, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 13, 1}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 5, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 3, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{16, 13, 1}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 2, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 8, 0}), +// sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 17, 0}), +// sidb_technology::cell_type::OUTPUT); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 18, 0}), +// sidb_technology::cell_type::OUTPUT); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 18, 0}), +// sidb_technology::cell_type::OUTPUT); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 17, 0}), +// sidb_technology::cell_type::OUTPUT); +// +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 19, 0}), +// sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 19, 0}), +// sidb_technology::cell_type::NORMAL); +// +// CHECK(lyt.num_cells() == 27); +// +// const auto result = assess_physical_population_stability(lyt, params); +// REQUIRE(result.size() == 20); +// const auto& population_stability_detail = result[0]; +// CHECK(population_stability_detail.critical_cell == offset::ucoord_t{14, 18, 0}); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == +// transition_type::NEUTRAL_TO_NEGATIVE); +// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.01); +// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, +// Catch::Matchers::WithinAbs(6.88, 1e-5)); +//} diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp b/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp new file mode 100644 index 000000000..20df97e0f --- /dev/null +++ b/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp @@ -0,0 +1,77 @@ +// +// Created by Jan Drewniok on 04.02.24. +// + +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace fiction; + +using layout = sidb_cell_clk_lyt_siqad; + +TEST_CASE("Single SiDB", "[assess-physical-population-stability]") +{ + layout lyt{}; + lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({29, 7, 1}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({17, 8, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({17, 9, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({21, 9, 1}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); + lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); + + lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + + SECTION("Precision of distance_corresponding_to_potential is two") + { + const auto params = assess_physical_population_stability_params_sidb_gate{ + assess_physical_population_stability_params{sidb_simulation_parameters{2, -0.32}, 2}}; + const auto result = assess_physical_population_stability_sidb_gate(lyt, std::vector{create_or_tt()}, + params, -1); +// REQUIRE(result.size() == 1); +// const auto &population_stability_detail = result[0]; +// CHECK(population_stability_detail.critical_cell == siqad::coord_t{1, 1, 0}); +// REQUIRE(population_stability_detail.transition_from_to_with_cell_and_required_pot.size() == 1); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot +// .at(transition_type::NEGATIVE_TO_NEUTRAL) +// .first == siqad::coord_t{1, 1, 0}); +// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot +// .at(transition_type::NEGATIVE_TO_NEUTRAL) +// .second == 0.29); +// +// REQUIRE_THAT( +// population_stability_detail.distance_corresponding_to_potential.at( +// transition_type::NEGATIVE_TO_NEUTRAL), +// Catch::Matchers::WithinAbs(0.77, 1e-5)); + } +} \ No newline at end of file diff --git a/test/algorithms/simulation/sidb/critical_temperature.cpp b/test/algorithms/simulation/sidb/critical_temperature.cpp index 28e3d738d..d80bad857 100644 --- a/test/algorithms/simulation/sidb/critical_temperature.cpp +++ b/test/algorithms/simulation/sidb/critical_temperature.cpp @@ -352,7 +352,7 @@ TEMPLATE_TEST_CASE( CHECK_THAT(std::abs(critical_stats.critical_temperature - 0.85), Catch::Matchers::WithinAbs(0.00, 0.01)); } - SECTION("OR gate") + SECTION("SiQAD OR gate") { lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); lyt.assign_cell_type({26, 0, 0}, sidb_technology::cell_type::INPUT); diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp index e56265d3d..11653ad9a 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp @@ -5,9 +5,14 @@ #include #include +#include "mockturtle/utils/stopwatch.hpp" + #include #include +#include #include +#include +#include #include using namespace fiction; @@ -149,3 +154,45 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio CHECK_THAT(distance, Catch::Matchers::WithinAbs(2.8999201713, physical_constants::POP_STABILITY_ERR)); } } + +TEST_CASE("Test influence distance function for Gate") +{ + sidb_cell_clk_lyt_siqad lyt{}; + + lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); + lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); + + lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + + const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, 5.6, 5.0}; + const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{2, -0.32}, {20, 4}}; + + maximum_defect_influence_distance_stats stats{}; + + const auto [defect_pos, distance] = maximum_defect_influence_position_and_distance(lyt, sim_params, &stats); + CHECK(mockturtle::to_seconds(stats.time_total) > 1.0); +} diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp new file mode 100644 index 000000000..36ae9e10b --- /dev/null +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp @@ -0,0 +1,73 @@ +// +// Created by Jan Drewniok on 26.06.23. +// + +#include +#include + +#include "mockturtle/utils/stopwatch.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace fiction; + +TEST_CASE("Test influence distance function for Gate") +{ + sidb_cell_clk_lyt_siqad lyt{}; + + lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); + lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); + + lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + + const maximum_defect_influence_position_and_distance_of_sidb_gate_params defect_avoidance_params_vacancy{ + maximum_defect_influence_position_and_distance_of_sidb_gate_params{ + {sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}, sidb_simulation_parameters{2}, {10, 0}}}}; + + const maximum_defect_influence_position_and_distance_of_sidb_gate_params defect_avoidance_params_arsenic{ + maximum_defect_influence_position_and_distance_of_sidb_gate_params{ + {sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}, sidb_simulation_parameters{2}}}}; + + const auto cell_distance_vacancy = maximum_defect_influence_position_and_distance_of_sidb_gate( + lyt, std::vector{create_or_tt()}, defect_avoidance_params_vacancy); + + const auto cell_distance_arsenic = maximum_defect_influence_position_and_distance_of_sidb_gate( + lyt, std::vector{create_or_tt()}, defect_avoidance_params_arsenic); + + CHECK(cell_distance_vacancy.first == siqad::coord_t{6, 13, 1}); + CHECK(cell_distance_arsenic.first == siqad::coord_t{12, 8, 0}); + CHECK_THAT(std::abs(cell_distance_vacancy.second - 4.857), Catch::Matchers::WithinAbs(0.00, 0.01)); + CHECK_THAT(std::abs(cell_distance_arsenic.second - 2.428), Catch::Matchers::WithinAbs(0.00, 0.01)); +} From d407eed511aa1142b246021e26f4fde655e9947f Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 5 Feb 2024 13:10:05 +0100 Subject: [PATCH 010/221] :construction: WIP code. --- experiments/gate_generator_with_sa.cpp | 99 ++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 experiments/gate_generator_with_sa.cpp diff --git a/experiments/gate_generator_with_sa.cpp b/experiments/gate_generator_with_sa.cpp new file mode 100644 index 000000000..9818d0b01 --- /dev/null +++ b/experiments/gate_generator_with_sa.cpp @@ -0,0 +1,99 @@ +// +// Created by Jan Drewniok 01.01.23 +// + +#include "fiction/types.hpp" // pre-defined types suitable for the FCN domain + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace fiction; + +int main() // NOLINT +{ + const auto skeleton = + read_sqd_layout("/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/" + "skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd"); + + // toffoli + // const design_sidb_gates_params params{ + // sidb_simulation_parameters{2, -0.32}, + // design_sidb_gates_params::design_sidb_gates_mode::RANDOM, + // {{9, 0, 0}, {19, 14, 0}}, + // 6, + // sidb_simulation_engine::QUICKEXACT}; + + design_sidb_gates_params params{ + sidb_simulation_parameters{2, -0.32}, + design_sidb_gates_params::design_sidb_gates_mode::SIMANNEAL, + {{17, 7, 0}, {21, 11, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT}; + + params.maximal_random_solutions = 100; + + const auto truth_tables = std::vector>{ + std::vector{create_and_tt()}, std::vector{create_xor_tt()}, std::vector{create_or_tt()}, + std::vector{create_xnor_tt()}, std::vector{create_nor_tt()}, std::vector{create_nand_tt()}, + std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, + std::vector{create_ge_tt()}}; + + // const auto truth_tables = std::vector>{std::vector{create_nor_tt()}}; + + // const auto truth_tables + // std::vector>{std::vector{create_id_tt()}, std::vector{create_not_tt()}}; + + const critical_temperature_params ct_params{sidb_simulation_parameters{ + 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; + + operational_domain_params op_domain_params{sidb_simulation_parameters{ + 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; + op_domain_params.x_min = 4.0; + op_domain_params.x_max = 6; + op_domain_params.x_step = 0.2; + + op_domain_params.y_min = 4.0; + op_domain_params.y_max = 6; + op_domain_params.y_step = 0.2; + + params.simanneal_params.ct_params = ct_params; + params.simanneal_params.op_params = op_domain_params; + + uint64_t truth_counter = 0; + + for (const auto& truth : truth_tables) + { + std::cout << fmt::format("{} truth table", truth_counter) << std::endl; + for (auto i = 4u; i < 5; i++) + { + double total_time = 0; + double net_cost = 0; + std::cout << fmt::format("{} placed SiDBs", i) << std::endl; + for (auto t = 0u; t < 10; t++) + { + params.number_of_sidbs = i; + + design_sidb_gates_stats stats{}; + + const auto all_gate = design_sidb_gates(skeleton, truth, params, &stats); + net_cost += stats.cost_of_gate; + total_time += mockturtle::to_seconds(stats.time_total); + } + std::cout << fmt::format("average runtime: {}", total_time / 10) << std::endl; + std::cout << fmt::format("net cost: {}", net_cost / 10) << std::endl; + } + + std::cout << "-----------" << std::endl; + truth_counter++; + } + + return EXIT_SUCCESS; +} From cde94af000ec1af55ee3871ee29d737ad93d89ac Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 5 Feb 2024 13:37:01 +0100 Subject: [PATCH 011/221] :construction: WIP code. --- experiments/gate_generator_exhaustive.cpp | 75 ++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 1611420b5..e84a810be 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -156,14 +156,87 @@ int main() // NOLINT csvFile << "temp,op,popstab_neg_to_neu,popstab_neu_to_neg,defect_influence_arsenic,defect_influence_" "vacancy\n"; - // Write data to the CSV file + // Write data to the CSV file and calculate mean, max, min + double meanTemp = 0.0, maxTemp = std::numeric_limits::min(), + minTemp = std::numeric_limits::max(); + double meanOpDomains = 0.0, maxOpDomains = std::numeric_limits::min(), + minOpDomains = std::numeric_limits::max(); + double meanDefectInfluenceArsenic = 0.0, maxDefectInfluenceArsenic = std::numeric_limits::min(), + minDefectInfluenceArsenic = std::numeric_limits::max(); + double meanDefectInfluenceVacancy = 0.0, maxDefectInfluenceVacancy = std::numeric_limits::min(), + minDefectInfluenceVacancy = std::numeric_limits::max(); + double meanPopStabilityNegToNeu = 0.0, maxPopStabilityNegToNeu = std::numeric_limits::min(), + minPopStabilityNegToNeu = std::numeric_limits::max(); + double meanPopStabilityNeuToNeg = 0.0, maxPopStabilityNeuToNeg = std::numeric_limits::min(), + minPopStabilityNeuToNeg = std::numeric_limits::max(); + for (std::size_t k = 0; k < temps.size(); ++k) { csvFile << temps[k] << "," << op_domains[k] << "," << pop_stability_negative_to_neutral[k] << "," << pop_stability_neutral_to_negative[k] << "," << defect_influence_arsenic[k] << "," << defect_influence_vacancy[k] << "\n"; + + // Update mean, max, min for temps + meanTemp += temps[k]; + maxTemp = std::max(maxTemp, temps[k]); + minTemp = std::min(minTemp, temps[k]); + + // Update mean, max, min for op_domains + meanOpDomains += op_domains[k]; + maxOpDomains = std::max(maxOpDomains, op_domains[k]); + minOpDomains = std::min(minOpDomains, op_domains[k]); + + // Update mean, max, min for defect_influence_arsenic + meanDefectInfluenceArsenic += defect_influence_arsenic[k]; + maxDefectInfluenceArsenic = std::max(maxDefectInfluenceArsenic, defect_influence_arsenic[k]); + minDefectInfluenceArsenic = std::min(minDefectInfluenceArsenic, defect_influence_arsenic[k]); + + // Update mean, max, min for defect_influence_vacancy + meanDefectInfluenceVacancy += defect_influence_vacancy[k]; + maxDefectInfluenceVacancy = std::max(maxDefectInfluenceVacancy, defect_influence_vacancy[k]); + minDefectInfluenceVacancy = std::min(minDefectInfluenceVacancy, defect_influence_vacancy[k]); + + // Update mean, max, min for pop_stability_negative_to_neutral + meanPopStabilityNegToNeu += pop_stability_negative_to_neutral[k]; + maxPopStabilityNegToNeu = std::max(maxPopStabilityNegToNeu, pop_stability_negative_to_neutral[k]); + minPopStabilityNegToNeu = std::min(minPopStabilityNegToNeu, pop_stability_negative_to_neutral[k]); + + // Update mean, max, min for pop_stability_neutral_to_negative + meanPopStabilityNeuToNeg += pop_stability_neutral_to_negative[k]; + maxPopStabilityNeuToNeg = std::max(maxPopStabilityNeuToNeg, pop_stability_neutral_to_negative[k]); + minPopStabilityNeuToNeg = std::min(minPopStabilityNeuToNeg, pop_stability_neutral_to_negative[k]); } + // Calculate mean for temps, op_domains, and other metrics + meanTemp /= temps.size(); + meanOpDomains /= op_domains.size(); + meanDefectInfluenceArsenic /= defect_influence_arsenic.size(); + meanDefectInfluenceVacancy /= defect_influence_vacancy.size(); + meanPopStabilityNegToNeu /= pop_stability_negative_to_neutral.size(); + meanPopStabilityNeuToNeg /= pop_stability_neutral_to_negative.size(); + + // Output mean, max, min for temps + std::cout << "temp: " << meanTemp << ";" << maxTemp << ";" << minTemp << std::endl; + + // Output mean, max, min for op_domains + std::cout << "op: " << meanOpDomains << ";" << maxOpDomains << ";" << minOpDomains << std::endl; + + // Output mean, max, min for temps + std::cout << "ars: " << meanDefectInfluenceArsenic << ";" << maxDefectInfluenceArsenic << ";" + << minDefectInfluenceArsenic << std::endl; + + // Output mean, max, min for op_domains + std::cout << "vac: " << meanDefectInfluenceVacancy << ";" << maxDefectInfluenceVacancy << ";" + << minDefectInfluenceVacancy << std::endl; + + // Output mean, max, min for temps + std::cout << "pop_neu_to_neg: " << meanPopStabilityNeuToNeg << ";" << maxPopStabilityNeuToNeg << ";" + << minPopStabilityNeuToNeg << std::endl; + + // Output mean, max, min for op_domains + std::cout << "pop_neg_to_neu: " << meanPopStabilityNegToNeu << ";" << maxPopStabilityNegToNeu << ";" + << minPopStabilityNegToNeu << std::endl; + // Close the file csvFile.close(); } From 67cf66ac06b625811542dcc6625d8f977ef46d7d Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 5 Feb 2024 13:43:40 +0100 Subject: [PATCH 012/221] :construction: WIP code. --- experiments/gate_generator_exhaustive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index e84a810be..bf39c84cb 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -72,7 +72,7 @@ int main() // NOLINT for (const auto& truth_table : truth_tables) { std::cout << fmt::format("truth counter: {}", truth_counter) << std::endl; - for (auto num_sidbs = 2u; num_sidbs < 3; num_sidbs++) + for (auto num_sidbs = 2u; num_sidbs < 7; num_sidbs++) { std::cout << fmt::format("num sidbs: {}", num_sidbs) << std::endl; params.number_of_sidbs = num_sidbs; From d8d546fd302fe0281a1f2813226fec3114e5ec8b Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 5 Feb 2024 13:58:15 +0100 Subject: [PATCH 013/221] :construction: WIP code. --- experiments/gate_generator_exhaustive.cpp | 15 ++++++++++----- .../physical_design/design_sidb_gates.hpp | 6 +++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index bf39c84cb..2f63de174 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -122,16 +122,21 @@ int main() // NOLINT futures.reserve(all_gate.size()); // Start asynchronous tasks to process combinations in parallel +// for (const auto& gate : all_gate) +//// { +//// futures.emplace_back(std::async(std::launch::async, calculate_metric_values, gate)); +//// } + for (const auto& gate : all_gate) { - futures.emplace_back(std::async(std::launch::async, calculate_metric_values, gate)); + calculate_metric_values(gate); } // Wait for all tasks to finish - for (auto& future : futures) - { - future.wait(); - } +// for (auto& future : futures) +// { +// future.wait(); +// } for (auto l = 0u; l < all_gate.size(); l++) { diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index dc66250f7..ccf7bfd44 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -577,7 +577,7 @@ class design_sidb_gates_impl template [[nodiscard]] std::vector design_sidb_gates(const Lyt& skeleton, const std::vector& spec, const design_sidb_gates_params& params = {}, - design_sidb_gates_stats* stats = nullptr) noexcept + design_sidb_gates_stats* pst = nullptr) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -609,9 +609,9 @@ template { result = p.run_sa_design(); } - if (stats) + if (pst) { - *stats = st; + *pst = st; } return result; } From d0499445de28b047a80215068b4976ad825025c9 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 07:17:35 +0100 Subject: [PATCH 014/221] :construction: WIP code. --- experiments/gate_generator_exhaustive.cpp | 131 ++++++++++++++++------ 1 file changed, 98 insertions(+), 33 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 2f63de174..40e7ce725 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -14,6 +14,7 @@ #include #include +#include using namespace fiction; @@ -95,48 +96,112 @@ int main() // NOLINT std::cout << fmt::format("gate design finished and {} gates were found", all_gate.size()) << std::endl; - const auto calculate_metric_values = [&](const auto& gate) noexcept + // Define mutex for synchronization + std::mutex mtx; + + const auto calculate_metric_values = [&](const auto& gate_chunk) noexcept { - temps.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); - operational_domain_stats stats{}; - const auto op_domain = operational_domain_flood_fill( - gate, truth_table, 0, op_domain_params, operational_domain::parameter_point{5.6, 5}, &stats); - op_domains.push_back(stats.percentual_operational_area); - const auto maximum_defect_influence_arsenic = - maximum_defect_influence_position_and_distance_of_sidb_gate(gate, truth_table, - defect_avoidance_params_arsenic); - defect_influence_arsenic.push_back(maximum_defect_influence_arsenic.second); - const auto maximum_defect_influence_vacancy = - maximum_defect_influence_position_and_distance_of_sidb_gate(gate, truth_table, - defect_avoidance_params_vacancy); - defect_influence_vacancy.push_back(maximum_defect_influence_vacancy.second); - - pop_stability_neutral_to_negative.push_back( - assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, -1)); - pop_stability_negative_to_neutral.push_back( - assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, 1)); + // Local vectors to store calculated metrics + std::vector temps_local; + std::vector op_domains_local; + std::vector defect_influence_arsenic_local; + std::vector defect_influence_vacancy_local; + std::vector pop_stability_neutral_to_negative_local; + std::vector pop_stability_negative_to_neutral_local; + + for (const auto& gate : gate_chunk) + { + temps.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); + operational_domain_stats stats{}; + const auto op_domain = + operational_domain_flood_fill(gate, truth_table, 0, op_domain_params, + operational_domain::parameter_point{5.6, 5}, &stats); + op_domains.push_back(stats.percentual_operational_area); + const auto maximum_defect_influence_arsenic = + maximum_defect_influence_position_and_distance_of_sidb_gate( + gate, truth_table, defect_avoidance_params_arsenic); + defect_influence_arsenic.push_back(maximum_defect_influence_arsenic.second); + const auto maximum_defect_influence_vacancy = + maximum_defect_influence_position_and_distance_of_sidb_gate( + gate, truth_table, defect_avoidance_params_vacancy); + defect_influence_vacancy.push_back(maximum_defect_influence_vacancy.second); + + pop_stability_neutral_to_negative.push_back( + assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, -1)); + pop_stability_negative_to_neutral.push_back( + assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, 1)); + } + + // Acquire lock before modifying shared vectors + std::lock_guard lock(mtx); + + // Append local vectors to global vectors + temps.insert(temps.end(), temps_local.begin(), temps_local.end()); + op_domains.insert(op_domains.end(), op_domains_local.begin(), op_domains_local.end()); + defect_influence_arsenic.insert(defect_influence_arsenic.end(), + defect_influence_arsenic_local.begin(), + defect_influence_arsenic_local.end()); + defect_influence_vacancy.insert(defect_influence_vacancy.end(), + defect_influence_vacancy_local.begin(), + defect_influence_vacancy_local.end()); + pop_stability_neutral_to_negative.insert(pop_stability_neutral_to_negative.end(), + pop_stability_neutral_to_negative_local.begin(), + pop_stability_neutral_to_negative_local.end()); + pop_stability_negative_to_neutral.insert(pop_stability_negative_to_neutral.end(), + pop_stability_negative_to_neutral_local.begin(), + pop_stability_negative_to_neutral_local.end()); }; - // Create a vector to store std::future objects - std::vector> futures{}; - futures.reserve(all_gate.size()); + // Define the number of threads to use + const size_t num_threads = std::thread::hardware_concurrency(); + const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size - // Start asynchronous tasks to process combinations in parallel -// for (const auto& gate : all_gate) -//// { -//// futures.emplace_back(std::async(std::launch::async, calculate_metric_values, gate)); -//// } + // A vector to store threads + std::vector threads; + threads.reserve(num_threads); - for (const auto& gate : all_gate) + // Split the vector into chunks and process each chunk in its own thread + auto gate_it = all_gate.begin(); + for (size_t i = 0; i < num_threads; ++i) { - calculate_metric_values(gate); + auto chunk_start = gate_it; + auto chunk_end = std::min(gate_it + chunk_size, all_gate.end()); + + threads.emplace_back(calculate_metric_values, + std::vector(chunk_start, chunk_end)); + + gate_it = chunk_end; } + // Wait for all threads to finish + for (auto& thread : threads) + { + thread.join(); + } + + // Start asynchronous tasks to process combinations in parallel + // for (const auto& gate : all_gate) + // { + // futures.emplace_back(std::async(std::launch::async, calculate_metric_values, + // gate)); + // } + + // for (const auto& gate : all_gate) + // { + // calculate_metric_values(gate); + // } + + // for each y value in parallel + // std::for_each(FICTION_EXECUTION_POLICY_PAR all_gate.cbegin(), all_gate.cend(), + // [&](const sidb_cell_clk_lyt_siqad &gate) { + // calculate_metric_values(gate); + // }); + // Wait for all tasks to finish -// for (auto& future : futures) -// { -// future.wait(); -// } + // for (auto& future : futures) + // { + // future.wait(); + // } for (auto l = 0u; l < all_gate.size(); l++) { From fc61da5fd7460576d9a35d2248777fd0a7c5ce41 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 07:24:03 +0100 Subject: [PATCH 015/221] :construction: WIP code. --- experiments/gate_generator_exhaustive.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 40e7ce725..f4252b5ce 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -3,18 +3,30 @@ // #include "fiction/types.hpp" // pre-defined types suitable for the FCN domain +#include "mockturtle/utils/stopwatch.hpp" #include #include #include +#include #include +#include #include +#include #include #include +#include #include +#include #include +#include +#include +#include #include +#include +#include +#include using namespace fiction; From 75cd309e8c839e069831e70726ecb3c13298e0b7 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 07:47:38 +0100 Subject: [PATCH 016/221] :construction: WIP code. --- experiments/gate_generator_exhaustive.cpp | 36 ++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index f4252b5ce..3275f3a2c 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ #include #include #include +#include using namespace fiction; @@ -84,10 +86,10 @@ int main() // NOLINT for (const auto& truth_table : truth_tables) { - std::cout << fmt::format("truth counter: {}", truth_counter) << std::endl; + std::cout << fmt::format("truth counter: {}", truth_counter) << '\n'; for (auto num_sidbs = 2u; num_sidbs < 7; num_sidbs++) { - std::cout << fmt::format("num sidbs: {}", num_sidbs) << std::endl; + std::cout << fmt::format("num sidbs: {}", num_sidbs) << '\n'; params.number_of_sidbs = num_sidbs; mockturtle::stopwatch<>::duration time_total{}; @@ -106,12 +108,12 @@ int main() // NOLINT all_gate = design_sidb_gates(skeleton, truth_table, params, &stats); - std::cout << fmt::format("gate design finished and {} gates were found", all_gate.size()) << std::endl; + std::cout << fmt::format("gate design finished and {} gates were found", all_gate.size()) << '\n'; // Define mutex for synchronization std::mutex mtx; - const auto calculate_metric_values = [&](const auto& gate_chunk) noexcept + const auto calculate_metric_values = [&](const auto& gate_chunk) { // Local vectors to store calculated metrics std::vector temps_local; @@ -145,7 +147,7 @@ int main() // NOLINT } // Acquire lock before modifying shared vectors - std::lock_guard lock(mtx); + const std::lock_guard lock(mtx); // Append local vectors to global vectors temps.insert(temps.end(), temps_local.begin(), temps_local.end()); @@ -290,34 +292,34 @@ int main() // NOLINT } // Calculate mean for temps, op_domains, and other metrics - meanTemp /= temps.size(); - meanOpDomains /= op_domains.size(); - meanDefectInfluenceArsenic /= defect_influence_arsenic.size(); - meanDefectInfluenceVacancy /= defect_influence_vacancy.size(); - meanPopStabilityNegToNeu /= pop_stability_negative_to_neutral.size(); - meanPopStabilityNeuToNeg /= pop_stability_neutral_to_negative.size(); + meanTemp /= static_cast(temps.size()); + meanOpDomains /= static_cast(op_domains.size()); + meanDefectInfluenceArsenic /= static_cast(defect_influence_arsenic.size()); + meanDefectInfluenceVacancy /= static_cast(defect_influence_vacancy.size()); + meanPopStabilityNegToNeu /= static_cast(pop_stability_negative_to_neutral.size()); + meanPopStabilityNeuToNeg /= static_cast(pop_stability_neutral_to_negative.size()); // Output mean, max, min for temps - std::cout << "temp: " << meanTemp << ";" << maxTemp << ";" << minTemp << std::endl; + std::cout << "temp: " << meanTemp << ";" << maxTemp << ";" << minTemp << '\n'; // Output mean, max, min for op_domains - std::cout << "op: " << meanOpDomains << ";" << maxOpDomains << ";" << minOpDomains << std::endl; + std::cout << "op: " << meanOpDomains << ";" << maxOpDomains << ";" << minOpDomains << '\n'; // Output mean, max, min for temps std::cout << "ars: " << meanDefectInfluenceArsenic << ";" << maxDefectInfluenceArsenic << ";" - << minDefectInfluenceArsenic << std::endl; + << minDefectInfluenceArsenic << '\n'; // Output mean, max, min for op_domains std::cout << "vac: " << meanDefectInfluenceVacancy << ";" << maxDefectInfluenceVacancy << ";" - << minDefectInfluenceVacancy << std::endl; + << minDefectInfluenceVacancy << '\n'; // Output mean, max, min for temps std::cout << "pop_neu_to_neg: " << meanPopStabilityNeuToNeg << ";" << maxPopStabilityNeuToNeg << ";" - << minPopStabilityNeuToNeg << std::endl; + << minPopStabilityNeuToNeg << '\n'; // Output mean, max, min for op_domains std::cout << "pop_neg_to_neu: " << meanPopStabilityNegToNeu << ";" << maxPopStabilityNegToNeu << ";" - << minPopStabilityNegToNeu << std::endl; + << minPopStabilityNegToNeu << '\n'; // Close the file csvFile.close(); From 4b3217236d18ab5b7e7265e6e53ad1e79d306638 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 07:57:27 +0100 Subject: [PATCH 017/221] :art: fix variable shadowing --- experiments/gate_generator_exhaustive.cpp | 9 ++++++--- .../algorithms/physical_design/design_sidb_gates.hpp | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 3275f3a2c..b98576a29 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -2,7 +2,7 @@ // Created by Jan Drewniok 01.01.23 // -#include "fiction/types.hpp" // pre-defined types suitable for the FCN domain +// pre-defined types suitable for the FCN domain #include "mockturtle/utils/stopwatch.hpp" #include @@ -12,18 +12,21 @@ #include #include #include -#include #include +#include #include #include #include +#include #include +#include + #include -#include #include #include #include +#include #include #include #include diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index ccf7bfd44..09dbddf63 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -314,12 +314,12 @@ class design_sidb_gates_impl temp_cost = -((critical_temperature_gate_based(lyt, truth_table, params.simanneal_params.ct_params)) / params.simanneal_params.ct_params.max_temperature); - operational_domain_stats stats{}; + operational_domain_stats stats_op{}; const auto op_domain = operational_domain_flood_fill( lyt, truth_table, 0, params.simanneal_params.op_params, operational_domain::parameter_point{params.phys_params.epsilon_r, params.phys_params.lambda_tf}, - &stats); - opo_cost = -stats.percentual_operational_area; + &stats_op); + opo_cost = -stats_op.percentual_operational_area; } // if (logic_cost + temp_cost + opo_cost < -0.5) { // std::cout << fmt::format("cost: {}", From 1d9c6d60ed53102298ae3503b948532c90c723aa Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 07:59:02 +0100 Subject: [PATCH 018/221] :construction: WIP code. --- experiments/gate_generator_exhaustive.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index b98576a29..d5273777f 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,7 @@ #include #include #include +#include #include #include #include From af88a5daa3ba6c7cead6ea93886d76dfe02d2608 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 08:05:04 +0100 Subject: [PATCH 019/221] :construction: reduce the number of used threads. --- experiments/gate_generator_exhaustive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index d5273777f..97a8bcdbd 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -172,7 +172,7 @@ int main() // NOLINT }; // Define the number of threads to use - const size_t num_threads = std::thread::hardware_concurrency(); + const size_t num_threads = 5; const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size // A vector to store threads From 6ee8124fc51db2498fa931733eef57128003bb98 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 12:45:58 +0100 Subject: [PATCH 020/221] :construction: increase the number of used threads. --- experiments/gate_generator_exhaustive.cpp | 8 ++++---- .../sidb/assess_physical_population_stability.hpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 97a8bcdbd..0553399e7 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -131,11 +131,11 @@ int main() // NOLINT for (const auto& gate : gate_chunk) { temps.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); - operational_domain_stats stats{}; + operational_domain_stats op_stats{}; const auto op_domain = operational_domain_flood_fill(gate, truth_table, 0, op_domain_params, - operational_domain::parameter_point{5.6, 5}, &stats); - op_domains.push_back(stats.percentual_operational_area); + operational_domain::parameter_point{5.6, 5}, &op_stats); + op_domains.push_back(op_stats.percentual_operational_area); const auto maximum_defect_influence_arsenic = maximum_defect_influence_position_and_distance_of_sidb_gate( gate, truth_table, defect_avoidance_params_arsenic); @@ -172,7 +172,7 @@ int main() // NOLINT }; // Define the number of threads to use - const size_t num_threads = 5; + const size_t num_threads = 10; const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size // A vector to store threads diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index bcebb75c9..269791d11 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -409,7 +409,7 @@ assess_physical_population_stability(const Lyt& lyt, const assess_physical_popul detail::assess_physical_population_stability_impl p{lyt, params}; return p.run(); -}; +} } // namespace fiction From 8745b4fe84bb580d10a27b622d95f5d8559c1de1 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 14:39:41 +0100 Subject: [PATCH 021/221] :construction: plot runtime to assess how fast the compute server is. --- experiments/gate_generator_exhaustive.cpp | 2 +- ...imum_defect_influence_position_and_distance_of_sidb_gate.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 0553399e7..55ab7e475 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -172,7 +172,7 @@ int main() // NOLINT }; // Define the number of threads to use - const size_t num_threads = 10; + const size_t num_threads = 1; const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size // A vector to store threads diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index a722d1c45..5041efeb3 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -44,7 +44,7 @@ template maximum_defect_influence_distance_stats stats_defect{}; const auto influence_cell_distance = maximum_defect_influence_position_and_distance(lyt, params.defect_influence_params, &stats_defect); - //std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; + std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; if (influence_cell_distance.second > maximum_defect_influence_distance) { maximum_defect_influence_distance = influence_cell_distance.second; From ee8a86119093bfcb1be4c53685e86603361f0cc7 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 14:52:43 +0100 Subject: [PATCH 022/221] :construction: set number of threads to 32. --- experiments/gate_generator_exhaustive.cpp | 2 +- ...imum_defect_influence_position_and_distance_of_sidb_gate.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 55ab7e475..0688c93b6 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -172,7 +172,7 @@ int main() // NOLINT }; // Define the number of threads to use - const size_t num_threads = 1; + const size_t num_threads = 32; const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size // A vector to store threads diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index 5041efeb3..de9fb932e 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -44,7 +44,7 @@ template maximum_defect_influence_distance_stats stats_defect{}; const auto influence_cell_distance = maximum_defect_influence_position_and_distance(lyt, params.defect_influence_params, &stats_defect); - std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; + // std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; if (influence_cell_distance.second > maximum_defect_influence_distance) { maximum_defect_influence_distance = influence_cell_distance.second; From ec87c30a9c92c256b3aa0667630c0f0817eacbcd Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 15:01:50 +0100 Subject: [PATCH 023/221] :construction: set number of threads to 16. --- experiments/gate_generator_exhaustive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 0688c93b6..c49062ee5 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -172,7 +172,7 @@ int main() // NOLINT }; // Define the number of threads to use - const size_t num_threads = 32; + const size_t num_threads = 16; const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size // A vector to store threads From 67ce3649ff07cd0d79951f79ff8d182ca4c8eb26 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 15:06:35 +0100 Subject: [PATCH 024/221] :construction: set number of threads to 10. --- experiments/gate_generator_exhaustive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index c49062ee5..0553399e7 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -172,7 +172,7 @@ int main() // NOLINT }; // Define the number of threads to use - const size_t num_threads = 16; + const size_t num_threads = 10; const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size // A vector to store threads From e5e44da685668bd75a9e3d3897c9f565b0173192 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 16:58:56 +0100 Subject: [PATCH 025/221] :construction: set number of threads to 1. --- experiments/gate_generator_exhaustive.cpp | 2 +- ...defect_influence_position_and_distance.hpp | 134 +++++++++++------- ...nce_position_and_distance_of_sidb_gate.hpp | 2 +- 3 files changed, 86 insertions(+), 52 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 0553399e7..55ab7e475 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -172,7 +172,7 @@ int main() // NOLINT }; // Define the number of threads to use - const size_t num_threads = 10; + const size_t num_threads = 1; const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size // A vector to store threads diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 5ee6c65a1..a91e5668e 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -90,6 +90,8 @@ class maximum_defect_influence_position_and_distance_impl { mockturtle::stopwatch stop{stats.time_total}; + std::mutex mutex; + const quickexact_params> params_defect{ params.physical_params, quickexact_params>::automatic_base_number_detection::OFF}; @@ -116,78 +118,110 @@ class maximum_defect_influence_position_and_distance_impl } // simulate the impact of the defect at a given position on the ground state of the SiDB layout - const auto process_defect = [&](const auto& defect) noexcept + const auto process_defect = [&](const std::vector& defect_chunk) noexcept { - if (layout.get_cell_type(defect) == Lyt::technology::cell_type::EMPTY) + for (const auto& defect : defect_chunk) { - sidb_surface lyt_defect{}; + if (layout.get_cell_type(defect) == Lyt::technology::cell_type::EMPTY) + { + sidb_surface lyt_defect{}; - layout.foreach_cell([this, &lyt_defect](const auto& cell) - { lyt_defect.assign_cell_type(cell, layout.get_cell_type(cell)); }); + layout.foreach_cell([this, &lyt_defect](const auto& cell) + { lyt_defect.assign_cell_type(cell, layout.get_cell_type(cell)); }); - // assign defect to layout - lyt_defect.assign_sidb_defect(defect, params.defect); - // conduct simulation with defect - auto simulation_result_defect = quickexact(lyt_defect, params_defect); + // assign defect to layout + lyt_defect.assign_sidb_defect(defect, params.defect); + // conduct simulation with defect + auto simulation_result_defect = quickexact(lyt_defect, params_defect); - const auto min_energy_defect = minimum_energy(simulation_result_defect.charge_distributions.cbegin(), - simulation_result_defect.charge_distributions.cend()); + const auto min_energy_defect = + minimum_energy(simulation_result_defect.charge_distributions.cbegin(), + simulation_result_defect.charge_distributions.cend()); - uint64_t charge_index_defect_layout = 0; + uint64_t charge_index_defect_layout = 0; - // get the charge index of the ground state - for (const auto& lyt_simulation_with_defect : simulation_result_defect.charge_distributions) - { - if (std::fabs(round_to_n_decimal_places(lyt_simulation_with_defect.get_system_energy(), 6) - - round_to_n_decimal_places(min_energy_defect, 6)) < - std::numeric_limits::epsilon()) + // get the charge index of the ground state + for (const auto& lyt_simulation_with_defect : simulation_result_defect.charge_distributions) { - lyt_simulation_with_defect.charge_distribution_to_index_general(); - charge_index_defect_layout = lyt_simulation_with_defect.get_charge_index_and_base().first; + if (std::fabs(round_to_n_decimal_places(lyt_simulation_with_defect.get_system_energy(), 6) - + round_to_n_decimal_places(min_energy_defect, 6)) < + std::numeric_limits::epsilon()) + { + lyt_simulation_with_defect.charge_distribution_to_index_general(); + charge_index_defect_layout = lyt_simulation_with_defect.get_charge_index_and_base().first; + } } - } - // defect changes the ground state, i.e., the charge index is changed compared to the charge - // distribution without placed defect. - if (charge_index_defect_layout != charge_index_layout) - { - auto distance = std::numeric_limits::max(); - layout.foreach_cell( - [this, &defect, &distance](const auto& cell) - { - if (sidb_nanometer_distance(layout, cell, defect) < distance) + // defect changes the ground state, i.e., the charge index is changed compared to the charge + // distribution without placed defect. + if (charge_index_defect_layout != charge_index_layout) + { + auto distance = std::numeric_limits::max(); + layout.foreach_cell( + [this, &defect, &distance](const auto& cell) { - distance = sidb_nanometer_distance(layout, cell, defect); - } - }); + if (sidb_nanometer_distance(layout, cell, defect) < distance) + { + distance = sidb_nanometer_distance(layout, cell, defect); + } + }); - // the distance is larger than the current maximum one. - if (distance > avoidance_distance) - { - max_defect_position = defect; - avoidance_distance = distance; -// std::cout << fmt::format("defect position x: {}, y: {}\n", max_defect_position.x, -// max_defect_position.y, distance); + { + std::lock_guard lock(mutex); + // the distance is larger than the current maximum one. + if (distance > avoidance_distance) { + max_defect_position = defect; + avoidance_distance = distance; + } + } } } } }; - // Apply the process_defect function to each defect using std::for_each + const size_t num_threads = std::thread::hardware_concurrency(); // Anzahl der verfügbaren Threads - std::vector> futures{}; - futures.reserve(defect_cells.size()); + // Größe jedes Chunks berechnen + const size_t chunk_size = (defect_cells.size() + num_threads - 1) / num_threads; - // Start asynchronous tasks to process combinations in parallel - for (const auto& defect_cell : defect_cells) - { - futures.emplace_back(std::async(std::launch::async, process_defect, defect_cell)); + // Vektor für Threads + std::vector threads; + threads.reserve(num_threads); + + // Aufteilen des Vektors in Chunks und Starten von Threads für jeden Chunk + auto defect_it = defect_cells.begin(); + for (size_t i = 0; i < num_threads; ++i) { + + auto chunk_start = defect_it; + auto chunk_end = std::min(defect_it + chunk_size, defect_cells.end()); + + threads.emplace_back(process_defect, std::vector(chunk_start, chunk_end)); + + defect_it = chunk_end; + if (defect_it == defect_cells.end()) { + break; // Alle Defekte wurden aufgeteilt + } } - for (auto& future : futures) - { - future.wait(); + for (auto& thread : threads) { + thread.join(); } + + // Apply the process_defect function to each defect using std::for_each + +// std::vector> futures{}; +// futures.reserve(defect_cells.size()); +// +// // Start asynchronous tasks to process combinations in parallel +// for (const auto& defect_cell : defect_cells) +// { +// futures.emplace_back(std::async(std::launch::async, process_defect, defect_cell)); +// } +// +// for (auto& future : futures) +// { +// future.wait(); +// } // std::for_each(FICTION_EXECUTION_POLICY_PAR_UNSEQ defect_cells.cbegin(), defect_cells.cend(), process_defect); return {max_defect_position, avoidance_distance}; diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index de9fb932e..5041efeb3 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -44,7 +44,7 @@ template maximum_defect_influence_distance_stats stats_defect{}; const auto influence_cell_distance = maximum_defect_influence_position_and_distance(lyt, params.defect_influence_params, &stats_defect); - // std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; + std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; if (influence_cell_distance.second > maximum_defect_influence_distance) { maximum_defect_influence_distance = influence_cell_distance.second; From 7e8d871ed36ce55ed819206d28e9bf9a8b108f32 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 17:31:42 +0100 Subject: [PATCH 026/221] :construction: smaller defect region. --- experiments/gate_generator_exhaustive.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 55ab7e475..530753049 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -81,11 +81,11 @@ int main() // NOLINT const maximum_defect_influence_position_and_distance_of_sidb_gate_params defect_avoidance_params_arsenic{ maximum_defect_influence_position_and_distance_of_sidb_gate_params{ - {sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}, params.phys_params, {20, 3}}}}; + {sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}, params.phys_params, {10, 3}}}}; const maximum_defect_influence_position_and_distance_of_sidb_gate_params defect_avoidance_params_vacancy{ maximum_defect_influence_position_and_distance_of_sidb_gate_params{ - {sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}, params.phys_params, {20, 3}}}}; + {sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}, params.phys_params, {10, 3}}}}; uint64_t truth_counter = 0; From cf610bb23deb8c264c1f55d56333b0e1eb48d075 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 17:44:26 +0100 Subject: [PATCH 027/221] :construction: reduce canvas size --- experiments/gate_generator_exhaustive.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 530753049..606603291 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -50,7 +50,7 @@ int main() // NOLINT design_sidb_gates_params params{ sidb_simulation_parameters{2, -0.32}, design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, - {{17, 7, 0}, {21, 11, 0}}, + {{17, 7, 1}, {21, 10, 0}}, 1, sidb_simulation_engine::QUICKEXACT}; @@ -226,13 +226,13 @@ int main() // NOLINT { const auto choose_gate = all_gate[l]; write_sqd_layout(choose_gate, - fmt::format(solution_folder + "/sqd/17_7_21_11_numdbs_{}_ttnum_{}_{}.sqd", + fmt::format(solution_folder + "/sqd/17_7_21_10_numdbs_{}_ttnum_{}_{}.sqd", num_sidbs, truth_counter, l)); } // Open a file for writing std::ofstream csvFile( - fmt::format(solution_folder + "/csv/17_7_21_11_numdbs_{}_ttnum_{}.csv", num_sidbs, truth_counter)); + fmt::format(solution_folder + "/csv/17_7_21_10_numdbs_{}_ttnum_{}.csv", num_sidbs, truth_counter)); // Check if the file is open if (!csvFile.is_open()) From cbb1727eadd685dfec61b01e12ff765c9b1e2d73 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 18:20:09 +0100 Subject: [PATCH 028/221] :construction: increase the canvas. --- experiments/gate_generator_exhaustive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 606603291..fd0aa9954 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -50,7 +50,7 @@ int main() // NOLINT design_sidb_gates_params params{ sidb_simulation_parameters{2, -0.32}, design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, - {{17, 7, 1}, {21, 10, 0}}, + {{16, 7, 1}, {22, 10, 0}}, 1, sidb_simulation_engine::QUICKEXACT}; From d64b67f24604f736e2765cbb29866907ad48ab2c Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 18:55:35 +0100 Subject: [PATCH 029/221] :construction: set new file name. --- experiments/gate_generator_exhaustive.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index fd0aa9954..522ef4e9a 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -226,13 +226,13 @@ int main() // NOLINT { const auto choose_gate = all_gate[l]; write_sqd_layout(choose_gate, - fmt::format(solution_folder + "/sqd/17_7_21_10_numdbs_{}_ttnum_{}_{}.sqd", + fmt::format(solution_folder + "/sqd/16_7_1_22_10_numdbs_{}_ttnum_{}_{}.sqd", num_sidbs, truth_counter, l)); } // Open a file for writing std::ofstream csvFile( - fmt::format(solution_folder + "/csv/17_7_21_10_numdbs_{}_ttnum_{}.csv", num_sidbs, truth_counter)); + fmt::format(solution_folder + "/csv/16_7_1_22_10_numdbs_{}_ttnum_{}.csv", num_sidbs, truth_counter)); // Check if the file is open if (!csvFile.is_open()) From 639e1443e78eb5d054556ac87a18ab58196d010c Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 6 Feb 2024 18:57:04 +0100 Subject: [PATCH 030/221] :construction: without runtime. --- ...imum_defect_influence_position_and_distance_of_sidb_gate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index 5041efeb3..de9fb932e 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -44,7 +44,7 @@ template maximum_defect_influence_distance_stats stats_defect{}; const auto influence_cell_distance = maximum_defect_influence_position_and_distance(lyt, params.defect_influence_params, &stats_defect); - std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; + // std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; if (influence_cell_distance.second > maximum_defect_influence_distance) { maximum_defect_influence_distance = influence_cell_distance.second; From e1f63cba7580069c702db301ee7a651ced6b2682 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 7 Feb 2024 08:56:10 +0100 Subject: [PATCH 031/221] :art: add missing headers. --- .../simulation/sidb/is_operational.cpp | 48 +++++++++++++++---- ...defect_influence_position_and_distance.cpp | 25 ++++++++-- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/test/algorithms/simulation/sidb/is_operational.cpp b/test/algorithms/simulation/sidb/is_operational.cpp index fd78e11fc..0d869d870 100644 --- a/test/algorithms/simulation/sidb/is_operational.cpp +++ b/test/algorithms/simulation/sidb/is_operational.cpp @@ -5,8 +5,11 @@ #include #include +#include #include +#include #include +#include #include using namespace fiction; @@ -161,7 +164,7 @@ TEST_CASE("Bestagon CROSSING gate", "[is-operational]") TEST_CASE("Bestagon AND gate", "[is-operational]") { - using layout = sidb_cell_clk_lyt_siqad; + using layout = sidb_defect_cell_clk_lyt_siqad; layout lyt{}; @@ -194,16 +197,41 @@ TEST_CASE("Bestagon AND gate", "[is-operational]") lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - CHECK(lyt.num_cells() == 23); + const sidb_simulation_parameters params{2, -0.32}; - CHECK( - is_operational(lyt, std::vector{create_and_tt()}, - is_operational_params{sidb_simulation_parameters{2, -0.32}, sidb_simulation_engine::QUICKEXACT}) - .first == operational_status::OPERATIONAL); - CHECK( - is_operational(lyt, std::vector{create_and_tt()}, - is_operational_params{sidb_simulation_parameters{2, -0.30}, sidb_simulation_engine::QUICKEXACT}) - .first == operational_status::NON_OPERATIONAL); + SECTION("Without defects") + { + CHECK(lyt.num_cells() == 23); + + CHECK(is_operational( + lyt, std::vector{create_and_tt()}, + is_operational_params{sidb_simulation_parameters{2, -0.32}, sidb_simulation_engine::QUICKEXACT}) + .first == operational_status::OPERATIONAL); + CHECK(is_operational( + lyt, std::vector{create_and_tt()}, + is_operational_params{sidb_simulation_parameters{2, -0.30}, sidb_simulation_engine::QUICKEXACT}) + .first == operational_status::NON_OPERATIONAL); + } + SECTION("With defects") + { + lyt.assign_sidb_defect({3, 16, 1}, + sidb_defect{sidb_defect_type::UNKNOWN, -1, params.epsilon_r, params.lambda_tf}); + CHECK(is_operational(lyt, std::vector{create_and_tt()}, + is_operational_params{params, sidb_simulation_engine::QUICKEXACT}) + .first == operational_status::OPERATIONAL); + + // move defect one to the right + lyt.move_sidb_defect({3, 16, 1}, {4, 16, 1}); + CHECK(is_operational(lyt, std::vector{create_and_tt()}, + is_operational_params{params, sidb_simulation_engine::QUICKEXACT}) + .first == operational_status::OPERATIONAL); + + // move defect one to the right + lyt.move_sidb_defect({4, 16, 1}, {5, 16, 1}); + CHECK(is_operational(lyt, std::vector{create_and_tt()}, + is_operational_params{params, sidb_simulation_engine::QUICKEXACT}) + .first == operational_status::NON_OPERATIONAL); + } } TEST_CASE("Not working diagonal Wire", "[is-operational]") diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp index 11653ad9a..b31a238e8 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp @@ -9,7 +9,9 @@ #include #include +#include #include +#include #include #include #include @@ -155,7 +157,7 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio } } -TEST_CASE("Test influence distance function for Gate") +TEST_CASE("Bestagon AND Gate influence distance function", "[maximum-defect-influence-position-and-distance]") { sidb_cell_clk_lyt_siqad lyt{}; @@ -191,8 +193,23 @@ TEST_CASE("Test influence distance function for Gate") const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, 5.6, 5.0}; const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{2, -0.32}, {20, 4}}; - maximum_defect_influence_distance_stats stats{}; + SECTION("input 00") + { + maximum_defect_influence_distance_stats stats{}; + const auto [defect_pos, distance] = maximum_defect_influence_position_and_distance(lyt, sim_params, &stats); + std::cout << fmt::format("{} {} {} {}", defect_pos.x, defect_pos.y, defect_pos.z, distance) << std::endl; + CHECK(mockturtle::to_seconds(stats.time_total) > 1.0); + } + SECTION("input 01") + { + + } + SECTION("input 10") + { - const auto [defect_pos, distance] = maximum_defect_influence_position_and_distance(lyt, sim_params, &stats); - CHECK(mockturtle::to_seconds(stats.time_total) > 1.0); + } + SECTION("input 11") + { + + } } From a0d4b72bd4f1c45563e81e0609af9c7820a1c3fd Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 7 Feb 2024 08:57:36 +0100 Subject: [PATCH 032/221] :art: add new function to move defect. --- include/fiction/technology/sidb_surface.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/fiction/technology/sidb_surface.hpp b/include/fiction/technology/sidb_surface.hpp index f946e6790..53b5883e0 100644 --- a/include/fiction/technology/sidb_surface.hpp +++ b/include/fiction/technology/sidb_surface.hpp @@ -134,6 +134,22 @@ class sidb_surface : public Lyt strg->defective_coordinates.insert({c, d}); } } + /** + * Moves an SiDB defect from one cell to another. + * + * @param c Current Coordinate of the defect. + * @param new_c Position to move the defect to. + */ + void move_sidb_defect(const typename Lyt::coordinate& c, const typename Lyt::coordinate& new_c) noexcept + { + const auto defect = get_sidb_defect(c); + if (defect.type != sidb_defect_type::NONE) + { + strg->defective_coordinates.insert({new_c, defect}); + } + // delete defect at the old coordinate + strg->defective_coordinates.erase(c); + } /** * Returns the given coordinate's assigned defect type. If no defect type has been assigned, NONE is returned. * From acd65a84bd71711ff059d6d7e78a71b48e2f0ce4 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 7 Feb 2024 16:22:30 +0100 Subject: [PATCH 033/221] :construction: WIP code. --- experiments/gate_generator_exhaustive.cpp | 89 ++-- ...influence_of_sidb_gate_contour_tracing.hpp | 491 ++++++++++++++++++ .../sidb/max_min_avoidance_distance.hpp | 44 ++ ...defect_influence_position_and_distance.hpp | 383 ++++++-------- ...nce_position_and_distance_of_sidb_gate.hpp | 2 +- .../io/write_defect_operational_domain.hpp | 101 ++++ include/fiction/types.hpp | 3 + ...influence_of_sidb_gate_contour_tracing.cpp | 75 +++ .../simulation/sidb/is_operational.cpp | 1 + 9 files changed, 940 insertions(+), 249 deletions(-) create mode 100644 include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp create mode 100644 include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp create mode 100644 include/fiction/io/write_defect_operational_domain.hpp create mode 100644 test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 522ef4e9a..3254f8fb8 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -9,7 +9,9 @@ #include #include #include -#include +#include +#include +#include #include #include #include @@ -39,20 +41,20 @@ using namespace fiction; int main() // NOLINT { + using Lyt = sidb_cell_clk_lyt_siqad; static const std::string folder = fmt::format("{}skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd", EXPERIMENTS_PATH); static const std::string solution_folder = fmt::format("{}metric_data/", EXPERIMENTS_PATH); - const auto skeleton = read_sqd_layout(folder); + const auto skeleton = read_sqd_layout(folder); - design_sidb_gates_params params{ - sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, - {{16, 7, 1}, {22, 10, 0}}, - 1, - sidb_simulation_engine::QUICKEXACT}; + design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, + {{17, 7, 0}, {21, 11, 0}}, + 1, + sidb_simulation_engine::QUICKEXACT}; params.maximal_random_solutions = 100; @@ -79,39 +81,41 @@ int main() // NOLINT assess_physical_population_stability_params{sidb_simulation_parameters{ 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}}; - const maximum_defect_influence_position_and_distance_of_sidb_gate_params defect_avoidance_params_arsenic{ - maximum_defect_influence_position_and_distance_of_sidb_gate_params{ - {sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}, params.phys_params, {10, 3}}}}; + const maximum_defect_influence_distance_params defect_avoidance_params_arsenic{ + sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}, + params.phys_params, + {20, 20}}; - const maximum_defect_influence_position_and_distance_of_sidb_gate_params defect_avoidance_params_vacancy{ - maximum_defect_influence_position_and_distance_of_sidb_gate_params{ - {sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}, params.phys_params, {10, 3}}}}; + const maximum_defect_influence_distance_params defect_avoidance_params_vacancy{ + sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}, + params.phys_params, + {20, 20}}; uint64_t truth_counter = 0; for (const auto& truth_table : truth_tables) { std::cout << fmt::format("truth counter: {}", truth_counter) << '\n'; - for (auto num_sidbs = 2u; num_sidbs < 7; num_sidbs++) + for (auto num_sidbs = 2u; num_sidbs < 5; num_sidbs++) { std::cout << fmt::format("num sidbs: {}", num_sidbs) << '\n'; params.number_of_sidbs = num_sidbs; mockturtle::stopwatch<>::duration time_total{}; - std::vector all_gate{}; - std::vector temps = {}; - std::vector op_domains = {}; - std::vector defect_influence_arsenic = {}; - std::vector defect_influence_vacancy = {}; - std::vector pop_stability_neutral_to_negative = {}; - std::vector pop_stability_negative_to_neutral = {}; + std::vector all_gate{}; + std::vector temps = {}; + std::vector op_domains = {}; + std::vector defect_influence_arsenic = {}; + std::vector defect_influence_vacancy = {}; + std::vector pop_stability_neutral_to_negative = {}; + std::vector pop_stability_negative_to_neutral = {}; { mockturtle::stopwatch stop{time_total}; design_sidb_gates_stats stats{}; - all_gate = design_sidb_gates(skeleton, truth_table, params, &stats); + all_gate = design_sidb_gates(skeleton, truth_table, params, &stats); std::cout << fmt::format("gate design finished and {} gates were found", all_gate.size()) << '\n'; @@ -136,14 +140,30 @@ int main() // NOLINT operational_domain_flood_fill(gate, truth_table, 0, op_domain_params, operational_domain::parameter_point{5.6, 5}, &op_stats); op_domains.push_back(op_stats.percentual_operational_area); - const auto maximum_defect_influence_arsenic = - maximum_defect_influence_position_and_distance_of_sidb_gate( - gate, truth_table, defect_avoidance_params_arsenic); - defect_influence_arsenic.push_back(maximum_defect_influence_arsenic.second); - const auto maximum_defect_influence_vacancy = - maximum_defect_influence_position_and_distance_of_sidb_gate( - gate, truth_table, defect_avoidance_params_vacancy); - defect_influence_vacancy.push_back(maximum_defect_influence_vacancy.second); + + defect_influence_stats arsenic_stats{}; + const auto siqad_gate = convert_to_fiction_coordinates(gate); + const auto defect_influence_domain_arsenic = defect_influence_of_sidb_gate_contour_tracing( + siqad_gate, truth_table, 300, + defect_influence_params{ + defect_avoidance_params_arsenic, + is_operational_params{defect_avoidance_params_arsenic.physical_params}}, + &arsenic_stats); + std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) + << '\n'; + + defect_influence_arsenic.push_back( + max_min_avoidance_distance(siqad_gate, defect_influence_domain_arsenic)); + + defect_influence_stats vacancy_stats{}; + const auto defect_influence_domain_vacancy = defect_influence_of_sidb_gate_contour_tracing( + siqad_gate, truth_table, 300, + defect_influence_params{ + defect_avoidance_params_vacancy, + is_operational_params{defect_avoidance_params_arsenic.physical_params}}, + &vacancy_stats); + defect_influence_vacancy.push_back( + max_min_avoidance_distance(siqad_gate, defect_influence_domain_vacancy)); pop_stability_neutral_to_negative.push_back( assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, -1)); @@ -186,8 +206,7 @@ int main() // NOLINT auto chunk_start = gate_it; auto chunk_end = std::min(gate_it + chunk_size, all_gate.end()); - threads.emplace_back(calculate_metric_values, - std::vector(chunk_start, chunk_end)); + threads.emplace_back(calculate_metric_values, std::vector(chunk_start, chunk_end)); gate_it = chunk_end; } @@ -231,8 +250,8 @@ int main() // NOLINT } // Open a file for writing - std::ofstream csvFile( - fmt::format(solution_folder + "/csv/16_7_1_22_10_numdbs_{}_ttnum_{}.csv", num_sidbs, truth_counter)); + std::ofstream csvFile(fmt::format(solution_folder + "/csv/16_7_1_22_10_numdbs_{}_ttnum_{}.csv", + num_sidbs, truth_counter)); // Check if the file is open if (!csvFile.is_open()) diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp new file mode 100644 index 000000000..215b60abb --- /dev/null +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp @@ -0,0 +1,491 @@ +// +// Created by Jan Drewniok on 28.12.23. +// + +#ifndef FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP +#define FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP + +#include "fiction/algorithms/simulation/sidb/is_operational.hpp" +#include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" +#include "fiction/layouts/bounding_box.hpp" +#include "fiction/layouts/coordinates.hpp" +#include "fiction/technology/sidb_surface.hpp" +#include "fiction/types.hpp" +#include "fiction/utils/hash.hpp" +#include "fiction/utils/layout_utils.hpp" +#include "fiction/utils/phmap_utils.hpp" +#include "mockturtle/utils/stopwatch.hpp" + +namespace fiction +{ + +struct defect_influence_params +{ + maximum_defect_influence_distance_params defect_influence_params{}; + is_operational_params is_operational_params{}; + detect_bdl_pairs_params bdl_pairs_params{}; +}; + +template +struct defect_operational_domain +{ + locked_parallel_flat_hash_map operational_values{}; +}; + +struct defect_influence_stats +{ + /** + * The total runtime of the operational domain computation. + */ + mockturtle::stopwatch<>::duration time_total{0}; + /** + * Number of simulator invocations. + */ + std::size_t num_simulator_invocations{0}; + /** + * Number of evaluated parameter combinations. + */ + std::size_t num_evaluated_defect_positions{0}; + /** + * Number of parameter combinations, for which the layout is operational. + */ + std::size_t num_operational_defect_positions{0}; + /** + * Number of parameter combinations, for which the layout is non-operational. + */ + std::size_t num_non_operational_defect_positions{0}; +}; + +namespace detail +{ + +template +class defect_influence_impl +{ + public: + defect_influence_impl(const Lyt& lyt, const std::vector& tt, const defect_influence_params& ps, + defect_influence_stats& st) : + layout{lyt}, + truth_table{tt}, + params{ps}, + stats{st} + { + determine_edge_cells(); + } + + [[nodiscard]] defect_operational_domain contour_tracing(const std::size_t samples) noexcept + { + mockturtle::stopwatch stop{stats.time_total}; + + // first, perform random sampling to find an operational starting point + const auto non_operational_starting_point = find_non_operational_defect_position_via_random_sampling(samples); + + // if no operational point was found within the specified number of samples, return + if (!non_operational_starting_point.has_value()) + { + return defect_domain; + } + + const auto next_clockwise_point = [](std::vector& neighborhood, + const typename Lyt::cell& backtrack) noexcept -> typename Lyt::cell + { + assert(std::find(neighborhood.cbegin(), neighborhood.cend(), backtrack) != neighborhood.cend() && + "The backtrack point must be part of the neighborhood"); + + while (neighborhood.back() != backtrack) + { + std::rotate(neighborhood.begin(), neighborhood.begin() + 1, neighborhood.end()); + } + + return neighborhood.front(); + }; + + assert(layout.num_defects() == 0 && "defect is added defect"); + + // find an operational point on the contour starting from the randomly determined starting point + const auto contour_starting_point = find_non_operational_defect_position(*non_operational_starting_point); + + assert(layout.num_defects() == 0 && "more than one defect"); + + auto current_contour_point = contour_starting_point; + auto backtrack_point = current_contour_point.x == nw_cell.x ? + current_contour_point : + typename Lyt::cell{current_contour_point.x - 1, current_contour_point.y}; + + auto current_neighborhood = moore_neighborhood(current_contour_point); + auto next_point = current_contour_point == backtrack_point ? + current_neighborhood.front() : + next_clockwise_point(current_neighborhood, backtrack_point); + + while (next_point != contour_starting_point) + { + const auto operational_status = is_defect_position_operational(next_point); + + assert(layout.num_defects() == 0 && "more than one defect"); + + if (operational_status == operational_status::NON_OPERATIONAL) + { + backtrack_point = current_contour_point; + current_contour_point = next_point; + } + else + { + backtrack_point = next_point; + } + + current_neighborhood = moore_neighborhood(current_contour_point); + next_point = next_clockwise_point(current_neighborhood, backtrack_point); + } + + log_stats(); + + return defect_domain; + } + + private: + void determine_edge_cells() noexcept + { + // bounding box around the given layout to have north-west and south-east cells. + const auto siqad_layout = convert_to_siqad_coordinates(layout); + bounding_box_2d bb{siqad_layout}; + + auto nw = fiction::siqad::to_fiction_coord(bb.get_min()); // north-west cell + auto se = fiction::siqad::to_fiction_coord(bb.get_max()); // south-east cell + + // shift nw and se cell by the additional scanning area to cover an area that is larger than the gate area. + nw.x = nw.x - params.defect_influence_params.additional_scanning_area.first; + nw.y = nw.y - params.defect_influence_params.additional_scanning_area.second; + + se.x = se.x + params.defect_influence_params.additional_scanning_area.first; + se.y = se.y + params.defect_influence_params.additional_scanning_area.second; + + nw_cell = nw; + se_cell = se; + // defect_cells = all_coordinates_in_spanned_area(nw, se); + } + + [[nodiscard]] std::optional find_non_operational_defect_position_via_sidbs() noexcept + { + layout.foreach_cell( + [this](const auto& c) + { + auto c_copy = c; + c_copy.x = c.x - 1; + if (layout.is_empty_cell(c_copy)) + { + layout.assign_sidb_defect(c_copy, params.defect_influence_params.defect); + // determine the operational status + const auto operational_value = is_defect_position_operational(c_copy); + + layout.assign_sidb_defect(c_copy, sidb_defect{sidb_defect_type::NONE}); + + // if the parameter combination is operational, return its step values in x and y dimension + if (operational_value == operational_status::NON_OPERATIONAL) + { + return c_copy; + } + } + }); + return std::nullopt; + } + + [[nodiscard]] std::optional + find_non_operational_defect_position_via_random_sampling(const std::size_t samples) noexcept + { + std::set random_cells{}; + while (random_cells.size() < samples) + { + const auto random = random_coordinate(nw_cell, se_cell); + if (layout.is_empty_cell(random)) + { + random_cells.insert(random); + } + } + + for (const auto& random_cell : random_cells) + { + layout.assign_sidb_defect(random_cell, params.defect_influence_params.defect); + // determine the operational status + const auto operational_value = is_defect_position_operational(random_cell); + + layout.assign_sidb_defect(random_cell, sidb_defect{sidb_defect_type::NONE}); + + // if the parameter combination is operational, return its step values in x and y dimension + if (operational_value == operational_status::NON_OPERATIONAL) + { + return random_cell; + } + } + + return std::nullopt; + } + + operational_status is_defect_position_operational(const typename Lyt::cell& c) noexcept + { + // if the point has already been sampled, return the stored operational status + if (const auto op_value = has_already_been_sampled(c); op_value.has_value()) + { + return *op_value; + } + + const auto operational = [this, &c]() + { + defect_domain.operational_values[c] = operational_status::OPERATIONAL; + + return operational_status::OPERATIONAL; + }; + + const auto non_operational = [this, &c]() + { + defect_domain.operational_values[c] = operational_status::NON_OPERATIONAL; + + return operational_status::NON_OPERATIONAL; + }; + + // increment the number of evaluated parameter combinations + ++num_evaluated_defect_positions; + + layout.assign_sidb_defect(c, params.defect_influence_params.defect); + const auto& [status, sim_calls] = is_operational(layout, truth_table, params.is_operational_params); + layout.assign_sidb_defect(c, sidb_defect{sidb_defect_type::NONE}); + num_simulator_invocations += sim_calls; + + if (status == operational_status::NON_OPERATIONAL) + { + return non_operational(); + } + + // if we made it here, the layout is operational + return operational(); + } + + [[nodiscard]] inline std::optional + has_already_been_sampled(const typename Lyt::cell& c) const noexcept + { + if (const auto it = defect_domain.operational_values.find(c); it != defect_domain.operational_values.cend()) + { + return it->second; + } + + return std::nullopt; + } + + [[nodiscard]] typename Lyt::cell + find_non_operational_defect_position(const typename Lyt::cell& starting_defect_position) noexcept + { + auto latest_non_operational_defect_position = starting_defect_position; + // layout.assign_sidb_defect(starting_defect_position, params.defect_influence_params.defect); + previous_defect_position = starting_defect_position; + + // move towards the left border of the parameter range + for (int64_t x = starting_defect_position.x; x >= nw_cell.x; --x) + { + current_defect_position = {x, starting_defect_position.y}; + + layout.assign_sidb_defect(current_defect_position, params.defect_influence_params.defect); + + const auto operational_status = is_defect_position_operational(current_defect_position); + + layout.assign_sidb_defect(current_defect_position, sidb_defect{sidb_defect_type::NONE}); + ; + + if (operational_status == operational_status::NON_OPERATIONAL) + { + latest_non_operational_defect_position = current_defect_position; + } + else + { + return latest_non_operational_defect_position; + } + } + + // if no boundary point was found, the operational area extends outside the parameter range + // return the latest operational point + return latest_non_operational_defect_position; + } + + /** + * Helper function that writes the the statistics of the operational domain computation to the statistics object. + * Due to data races that can occur during the computation, each value is temporarily held in an atomic variable and + * written to the statistics object only after the computation has finished. + */ + void log_stats() const noexcept + { + stats.num_simulator_invocations = num_simulator_invocations; + stats.num_evaluated_defect_positions = num_evaluated_defect_positions; + + for (const auto& [param_point, status] : defect_domain.operational_values) + { + if (status == operational_status::OPERATIONAL) + { + ++stats.num_operational_defect_positions; + } + else + { + ++stats.num_non_operational_defect_positions; + } + } + } + + [[nodiscard]] std::vector moore_neighborhood(const typename Lyt::cell& c) const noexcept + { + std::vector neighbors{}; + neighbors.reserve(8); + + const auto& moore = c; + + const auto decr_x = (moore.x - 1 >= nw_cell.x) ? moore.x - 1 : moore.x; + const auto incr_x = (moore.x + 1 <= se_cell.x) ? moore.x + 1 : moore.x; + const auto decr_y = (moore.y - 1 >= nw_cell.y) ? moore.y - 1 : moore.y; + const auto incr_y = (moore.y + 1 <= se_cell.y) ? moore.y + 1 : moore.y; + + // add neighbors in clockwise direction + + // right + if (moore.x != incr_x) + { + neighbors.emplace_back(incr_x, moore.y); + } + // lower-right + if (moore.x != incr_x && moore.y != decr_y) + { + neighbors.emplace_back(incr_x, decr_y); + } + // down + if (moore.y != decr_y) + { + neighbors.emplace_back(moore.x, decr_y); + } + // lower-left + if (moore.x != decr_x && moore.y != decr_y) + { + neighbors.emplace_back(decr_x, decr_y); + } + // left + if (moore.x != decr_x) + { + neighbors.emplace_back(decr_x, moore.y); + } + // upper-left + if (moore.x != decr_x && moore.y != incr_y) + { + neighbors.emplace_back(decr_x, incr_y); + } + // up + if (moore.y != incr_y) + { + neighbors.emplace_back(moore.x, incr_y); + } + // upper-right + if (moore.x != incr_x && moore.y != incr_y) + { + neighbors.emplace_back(incr_x, incr_y); + } + + return neighbors; + }; + + /** + * The SiDB cell-level layout to investigate. + */ + sidb_surface layout{}; + /** + * The specification of the layout. + */ + const std::vector& truth_table; + /** + * The parameters for the operational domain computation. + */ + const defect_influence_params& params; + + typename Lyt::cell nw_cell{}; + + typename Lyt::cell se_cell{}; + + typename Lyt::cell current_defect_position{}; + + typename Lyt::cell previous_defect_position{}; + + /** + * The operational domain of the layout. + */ + defect_operational_domain defect_domain{}; + + /** + * The statistics of the operational domain computation. + */ + defect_influence_stats& stats; + + std::atomic num_simulator_invocations{0}; + /** + * Number of evaluated parameter combinations. + */ + std::atomic num_evaluated_defect_positions{0}; +}; +} // namespace detail + +template +defect_operational_domain +defect_influence_of_sidb_gate_contour_tracing(const Lyt& lyt, const std::vector& spec, const std::size_t samples, + const defect_influence_params& params = {}, + defect_influence_stats* stats = nullptr) +{ + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(kitty::is_truth_table::value, "TT is not a truth table"); + static_assert(has_cube_coord_v, "Lyt is not based on cube coordinates"); + + defect_influence_stats st{}; + detail::defect_influence_impl p{lyt, spec, params, st}; + + const auto result = p.contour_tracing(samples); + + if (stats) + { + *stats = st; + } + + return result; +} + +// template +//[[nodiscard]] std::pair maximum_defect_influence_position_and_distance_of_sidb_gate( +// const Lyt& lyt, const std::vector& spec, +// const maximum_defect_influence_position_and_distance_of_sidb_gate_params& params = {}) noexcept +//{ +// static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); +// static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); +// static_assert(!has_offset_ucoord_v, "Lyt should not be based on offset coordinates"); +// static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); +// +// assert(lyt.num_pis() > 0 && "skeleton needs input cells"); +// assert(lyt.num_pos() > 0 && "skeleton needs output cells"); +// +// assert(!spec.empty()); +// // all elements in tts must have the same number of variables +// assert(std::adjacent_find(spec.begin(), spec.end(), +// [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == +// spec.end()); +// +// bdl_input_iterator bii{lyt, params.bdl_pairs_params}; +// double maximum_defect_influence_distance = 0.0; +// cell defect_cell{}; +// // number of different input combinations +// for (auto i = 0u; i < spec.front().num_bits(); ++i, ++bii) +// { +// maximum_defect_influence_distance_stats stats_defect{}; +// const auto influence_cell_distance = +// maximum_defect_influence_position_and_distance(lyt, params.defect_influence_params, &stats_defect); +// std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; +// if (influence_cell_distance.second > maximum_defect_influence_distance) +// { +// maximum_defect_influence_distance = influence_cell_distance.second; +// defect_cell = influence_cell_distance.first; +// } +// } +// return {defect_cell, maximum_defect_influence_distance}; +// } + +} // namespace fiction + +#endif // FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP diff --git a/include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp b/include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp new file mode 100644 index 000000000..89f4f15f6 --- /dev/null +++ b/include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp @@ -0,0 +1,44 @@ +// +// Created by Jan Drewniok on 07.02.24. +// + +#ifndef FICTION_MINIMUM_DISTANCE_DEFECT_HPP +#define FICTION_MINIMUM_DISTANCE_DEFECT_HPP + +#include "fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp" +#include "fiction/layouts/cell_level_layout.hpp" +#include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" +#include "fiction/algorithms/simulation/sidb/operational_domain.hpp" + +namespace fiction +{ +template +[[nodiscard]] double max_min_avoidance_distance(const Lyt& lyt, + const defect_operational_domain& defect_opdomain) noexcept +{ + double max_distance = 0; + for (const auto& val : defect_opdomain.operational_values) + { + if (val.second == operational_status::OPERATIONAL) + { + continue; + } + auto min_distance = std::numeric_limits::max(); + lyt.foreach_cell( + [&val, &min_distance, &lyt](const auto& c) + { + if (sidb_nanometer_distance(lyt, c, val.first) < min_distance) + { + min_distance = sidb_nanometer_distance(lyt, c, val.first); + } + }); + if (min_distance > max_distance) + { + max_distance = min_distance; + } + } + return max_distance; +} +} // namespace fiction + +#endif // FICTION_MINIMUM_DISTANCE_DEFECT_HPP diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index a91e5668e..3d76bf9a8 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -24,43 +24,39 @@ #include #include -namespace fiction -{ +namespace fiction { /** * This struct stores the parameters for the maximum_defect_influence_position_and_distance algorithm. */ -struct maximum_defect_influence_distance_params -{ - /** - * The defect to calculate the maximum defect influence distance for. - */ - sidb_defect defect{}; - /** - * Physical simulation parameters. - */ - sidb_simulation_parameters physical_params{}; - /** - * The pair describes the width and height of the area around the gate, which is - * also used to place defects. - * - * @note If SiQAD coordinates are used, the second entry describes the number of dimer rows. - */ - std::pair additional_scanning_area{50, 6}; -}; + struct maximum_defect_influence_distance_params { + /** + * The defect to calculate the maximum defect influence distance for. + */ + sidb_defect defect{}; + /** + * Physical simulation parameters. + */ + sidb_simulation_parameters physical_params{}; + /** + * The pair describes the width and height of the area around the gate, which is + * also used to place defects. + * + * @note If SiQAD coordinates are used, the second entry describes the number of dimer rows. + */ + std::pair additional_scanning_area{50, 6}; + }; /** * Statistics for the maximum defect influence simulation. */ -struct maximum_defect_influence_distance_stats -{ - /** - * The total runtime of the maximum defect influence simulation. - */ - mockturtle::stopwatch<>::duration time_total{0}; -}; - -namespace detail -{ + struct maximum_defect_influence_distance_stats { + /** + * The total runtime of the maximum defect influence simulation. + */ + mockturtle::stopwatch<>::duration time_total{0}; + }; + + namespace detail { /** * A class for simulating the maximum influence distance of defects within an SiDB layout. * @@ -72,142 +68,131 @@ namespace detail * distance and corresponding defect position. It utilizes multithreading for efficient defect * position simulations. */ -template -class maximum_defect_influence_position_and_distance_impl -{ - public: - maximum_defect_influence_position_and_distance_impl(const Lyt& lyt, - const maximum_defect_influence_distance_params& sim_params, - maximum_defect_influence_distance_stats& st) : - layout{lyt}, - params{sim_params}, - stats{st} - { - collect_all_defect_cells(); - } - - std::pair run() noexcept - { - mockturtle::stopwatch stop{stats.time_total}; + template + class maximum_defect_influence_position_and_distance_impl { + public: + maximum_defect_influence_position_and_distance_impl(const Lyt &lyt, + const maximum_defect_influence_distance_params &sim_params, + maximum_defect_influence_distance_stats &st) : + layout{lyt}, + params{sim_params}, + stats{st} { + } - std::mutex mutex; + std::pair run() noexcept { + mockturtle::stopwatch stop{stats.time_total}; - const quickexact_params> params_defect{ - params.physical_params, quickexact_params>::automatic_base_number_detection::OFF}; + std::mutex mutex; - double avoidance_distance{0}; - coordinate max_defect_position{}; + const quickexact_params> params_defect{ + params.physical_params, + quickexact_params>::automatic_base_number_detection::OFF}; - const auto simulation_results = - quickexact(layout, quickexact_params{params.physical_params, - quickexact_params::automatic_base_number_detection::OFF}); + double avoidance_distance{0}; + coordinate max_defect_position{}; - const auto min_energy = minimum_energy(simulation_results.charge_distributions.cbegin(), - simulation_results.charge_distributions.cend()); + const auto simulation_results = + quickexact(layout, quickexact_params{params.physical_params, + quickexact_params::automatic_base_number_detection::OFF}); - uint64_t charge_index_layout = 0; + const auto min_energy = minimum_energy(simulation_results.charge_distributions.cbegin(), + simulation_results.charge_distributions.cend()); - for (auto& lyt_result : simulation_results.charge_distributions) - { - if (std::fabs(round_to_n_decimal_places(lyt_result.get_system_energy(), 6) - - round_to_n_decimal_places(min_energy, 6)) < std::numeric_limits::epsilon()) - { - lyt_result.charge_distribution_to_index_general(); - charge_index_layout = lyt_result.get_charge_index_and_base().first; - } - } + uint64_t charge_index_layout = 0; - // simulate the impact of the defect at a given position on the ground state of the SiDB layout - const auto process_defect = [&](const std::vector& defect_chunk) noexcept - { - for (const auto& defect : defect_chunk) - { - if (layout.get_cell_type(defect) == Lyt::technology::cell_type::EMPTY) - { - sidb_surface lyt_defect{}; - - layout.foreach_cell([this, &lyt_defect](const auto& cell) - { lyt_defect.assign_cell_type(cell, layout.get_cell_type(cell)); }); - - // assign defect to layout - lyt_defect.assign_sidb_defect(defect, params.defect); - // conduct simulation with defect - auto simulation_result_defect = quickexact(lyt_defect, params_defect); - - const auto min_energy_defect = - minimum_energy(simulation_result_defect.charge_distributions.cbegin(), - simulation_result_defect.charge_distributions.cend()); - - uint64_t charge_index_defect_layout = 0; - - // get the charge index of the ground state - for (const auto& lyt_simulation_with_defect : simulation_result_defect.charge_distributions) - { - if (std::fabs(round_to_n_decimal_places(lyt_simulation_with_defect.get_system_energy(), 6) - - round_to_n_decimal_places(min_energy_defect, 6)) < - std::numeric_limits::epsilon()) - { - lyt_simulation_with_defect.charge_distribution_to_index_general(); - charge_index_defect_layout = lyt_simulation_with_defect.get_charge_index_and_base().first; - } + for (auto &lyt_result: simulation_results.charge_distributions) { + if (std::fabs(round_to_n_decimal_places(lyt_result.get_system_energy(), 6) - + round_to_n_decimal_places(min_energy, 6)) < std::numeric_limits::epsilon()) { + lyt_result.charge_distribution_to_index_general(); + charge_index_layout = lyt_result.get_charge_index_and_base().first; } + } - // defect changes the ground state, i.e., the charge index is changed compared to the charge - // distribution without placed defect. - if (charge_index_defect_layout != charge_index_layout) - { - auto distance = std::numeric_limits::max(); - layout.foreach_cell( - [this, &defect, &distance](const auto& cell) - { - if (sidb_nanometer_distance(layout, cell, defect) < distance) - { - distance = sidb_nanometer_distance(layout, cell, defect); - } + // simulate the impact of the defect at a given position on the ground state of the SiDB layout + const auto process_defect = [&](const std::vector &defect_chunk) noexcept { + for (const auto &defect: defect_chunk) { + if (layout.get_cell_type(defect) == Lyt::technology::cell_type::EMPTY) { + sidb_surface lyt_defect{}; + + layout.foreach_cell([this, &lyt_defect](const auto &cell) { + lyt_defect.assign_cell_type(cell, layout.get_cell_type(cell)); }); - { - std::lock_guard lock(mutex); - // the distance is larger than the current maximum one. - if (distance > avoidance_distance) { - max_defect_position = defect; - avoidance_distance = distance; + // assign defect to layout + lyt_defect.assign_sidb_defect(defect, params.defect); + // conduct simulation with defect + auto simulation_result_defect = quickexact(lyt_defect, params_defect); + + const auto min_energy_defect = + minimum_energy(simulation_result_defect.charge_distributions.cbegin(), + simulation_result_defect.charge_distributions.cend()); + + uint64_t charge_index_defect_layout = 0; + + // get the charge index of the ground state + for (const auto &lyt_simulation_with_defect: simulation_result_defect.charge_distributions) { + if (std::fabs( + round_to_n_decimal_places(lyt_simulation_with_defect.get_system_energy(), 6) - + round_to_n_decimal_places(min_energy_defect, 6)) < + std::numeric_limits::epsilon()) { + lyt_simulation_with_defect.charge_distribution_to_index_general(); + charge_index_defect_layout = lyt_simulation_with_defect.get_charge_index_and_base().first; + } + } + + // defect changes the ground state, i.e., the charge index is changed compared to the charge + // distribution without placed defect. + if (charge_index_defect_layout != charge_index_layout) { + auto distance = std::numeric_limits::max(); + layout.foreach_cell( + [this, &defect, &distance](const auto &cell) { + if (sidb_nanometer_distance(layout, cell, defect) < distance) { + distance = sidb_nanometer_distance(layout, cell, defect); + } + }); + + { + std::lock_guard lock(mutex); + // the distance is larger than the current maximum one. + if (distance > avoidance_distance) { + max_defect_position = defect; + avoidance_distance = distance; + } + } } } } - } - } - }; + }; - const size_t num_threads = std::thread::hardware_concurrency(); // Anzahl der verfügbaren Threads + const size_t num_threads = std::thread::hardware_concurrency(); // Anzahl der verfügbaren Threads - // Größe jedes Chunks berechnen - const size_t chunk_size = (defect_cells.size() + num_threads - 1) / num_threads; + // Größe jedes Chunks berechnen + const size_t chunk_size = (defect_cells.size() + num_threads - 1) / num_threads; - // Vektor für Threads - std::vector threads; - threads.reserve(num_threads); + // Vektor für Threads + std::vector threads; + threads.reserve(num_threads); - // Aufteilen des Vektors in Chunks und Starten von Threads für jeden Chunk - auto defect_it = defect_cells.begin(); - for (size_t i = 0; i < num_threads; ++i) { + // Aufteilen des Vektors in Chunks und Starten von Threads für jeden Chunk + auto defect_it = defect_cells.begin(); + for (size_t i = 0; i < num_threads; ++i) { - auto chunk_start = defect_it; - auto chunk_end = std::min(defect_it + chunk_size, defect_cells.end()); + auto chunk_start = defect_it; + auto chunk_end = std::min(defect_it + chunk_size, defect_cells.end()); - threads.emplace_back(process_defect, std::vector(chunk_start, chunk_end)); + threads.emplace_back(process_defect, std::vector(chunk_start, chunk_end)); - defect_it = chunk_end; - if (defect_it == defect_cells.end()) { - break; // Alle Defekte wurden aufgeteilt - } - } + defect_it = chunk_end; + if (defect_it == defect_cells.end()) { + break; // Alle Defekte wurden aufgeteilt + } + } - for (auto& thread : threads) { - thread.join(); - } + for (auto &thread: threads) { + thread.join(); + } - // Apply the process_defect function to each defect using std::for_each + // Apply the process_defect function to each defect using std::for_each // std::vector> futures{}; // futures.reserve(defect_cells.size()); @@ -222,57 +207,31 @@ class maximum_defect_influence_position_and_distance_impl // { // future.wait(); // } - // std::for_each(FICTION_EXECUTION_POLICY_PAR_UNSEQ defect_cells.cbegin(), defect_cells.cend(), process_defect); + // std::for_each(FICTION_EXECUTION_POLICY_PAR_UNSEQ defect_cells.cbegin(), defect_cells.cend(), process_defect); - return {max_defect_position, avoidance_distance}; - } + return {max_defect_position, avoidance_distance}; + } - private: - /** - * SiDB cell-level layout to simulate. - */ - Lyt layout; - /** - * Parameters used for the simulation. - */ - maximum_defect_influence_distance_params params{}; - /** - * The statistics of the maximum defect influence position. - */ - maximum_defect_influence_distance_stats& stats; - /** - * All allowed defect positions. - */ - std::vector defect_cells{}; - - /** - * Collects all possible defect cell positions within a given layout while avoiding SiDB cells. - * - * This function calculates a bounding box around the provided layout, encompassing the area - * where defect cells can be placed. It then iterates through this bounding box, scanning from - * top to bottom and left to right, and identifies all valid positions for defect cells. A defect - * cell can only be placed in locations where there are no SiDB cells. - */ - void collect_all_defect_cells() noexcept - { - // bounding box around the given layout to have north-west and south-east cells. - bounding_box_2d bb{layout}; - - auto nw = bb.get_min(); // north-west cell - auto se = bb.get_max(); // south-east cell - - // shift nw and se cell by the additional scanning area to cover an area that is larger than the gate area. - nw.x = nw.x - params.additional_scanning_area.first; - nw.y = nw.y - params.additional_scanning_area.second; - - se.x = se.x + params.additional_scanning_area.first; - se.y = se.y + params.additional_scanning_area.second; - - defect_cells = all_coordinates_in_spanned_area(nw, se); - } -}; + private: + /** + * SiDB cell-level layout to simulate. + */ + Lyt layout; + /** + * Parameters used for the simulation. + */ + maximum_defect_influence_distance_params params{}; + /** + * The statistics of the maximum defect influence position. + */ + maximum_defect_influence_distance_stats &stats; + /** + * All allowed defect positions. + */ + std::vector defect_cells{}; + }; -} // namespace detail + } // namespace detail /** * Calculates the maximum distance at which a given defect can influence the layout's ground state. @@ -287,30 +246,28 @@ class maximum_defect_influence_position_and_distance_impl * can still affect the ground state of the layout. The second entry describes the distance of the defect from the * layout. */ -template -std::pair -maximum_defect_influence_position_and_distance(const Lyt& lyt, - const maximum_defect_influence_distance_params& sim_params = {}, - maximum_defect_influence_distance_stats* pst = nullptr) -{ - static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); - static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); - static_assert(!has_offset_ucoord_v, "Lyt cannot be based on offset coordinates"); - static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); - - maximum_defect_influence_distance_stats st{}; - - detail::maximum_defect_influence_position_and_distance_impl p{lyt, sim_params, st}; - - const auto result = p.run(); - - if (pst) - { - *pst = st; - } + template + std::pair + maximum_defect_influence_position_and_distance(const Lyt &lyt, + const maximum_defect_influence_distance_params &sim_params = {}, + maximum_defect_influence_distance_stats *pst = nullptr) { + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(!has_offset_ucoord_v, "Lyt cannot be based on offset coordinates"); + static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); + + maximum_defect_influence_distance_stats st{}; + + detail::maximum_defect_influence_position_and_distance_impl p{lyt, sim_params, st}; - return result; -} + const auto result = p.run(); + + if (pst) { + *pst = st; + } + + return result; + } } // namespace fiction diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index de9fb932e..5041efeb3 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -44,7 +44,7 @@ template maximum_defect_influence_distance_stats stats_defect{}; const auto influence_cell_distance = maximum_defect_influence_position_and_distance(lyt, params.defect_influence_params, &stats_defect); - // std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; + std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; if (influence_cell_distance.second > maximum_defect_influence_distance) { maximum_defect_influence_distance = influence_cell_distance.second; diff --git a/include/fiction/io/write_defect_operational_domain.hpp b/include/fiction/io/write_defect_operational_domain.hpp new file mode 100644 index 000000000..6c3f509c0 --- /dev/null +++ b/include/fiction/io/write_defect_operational_domain.hpp @@ -0,0 +1,101 @@ +// +// Created by marcel on 02.08.23. +// + +#ifndef FICTION_WRITE_OPERATIONAL_DOMAIN_HPP +#define FICTION_WRITE_OPERATIONAL_DOMAIN_HPP + +#include "fiction/algorithms/simulation/sidb/is_operational.hpp" +#include "fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp" +#include "fiction/io/csv_writer.hpp" + +#include +#include +#include +#include + +namespace fiction +{ + +/** + * Parameters for writing an operational domain to a CSV file. + */ +struct write_operational_domain_params +{ + /** + * The tag used to represent the operational value of a parameter set. + */ + std::string_view operational_tag = "operational"; + /** + * The tag used to represent the non-operational value of a parameter set. + */ + std::string_view non_operational_tag = "non-operational"; +}; + +/** + * Writes a CSV representation of an operational domain to the specified output stream. The data are written + * as rows, each corresponding to one set of simulation parameters and their corresponding operational status. + * + * The output CSV format is as follows: + * X_DIMENSION, Y_DIMENSION, OPERATIONAL STATUS + * ... subsequent rows for each set of simulation parameters. + * + * The operational status is a binary value represented by specified tags in `params` indicating whether the simulation + * parameters are within the operational domain or not. + * + * @param opdom The operational domain to be written. It contains a mapping from sets of simulation parameters + * (represented as a pair of sweep parameters for the X and Y dimensions) to their operational status. + * @param os The output stream where the CSV representation of the operational domain is written to. + * @param params The parameters used for writing, including the operational and non-operational tags. Defaults to an + * empty `write_operational_domain_params` object, which provides standard tags. + */ + template +inline void write_operational_domain(const defect_operational_domain& opdom, std::ostream& os, + const write_operational_domain_params& params = {}) +{ + csv_writer writer{os}; + + writer.write_line("x","y", "operational status"); + + for (const auto& [sim_param, op_val] : opdom.operational_values) + { + writer.write_line(sim_param.x, sim_param.y, + op_val == operational_status::OPERATIONAL ? params.operational_tag : + params.non_operational_tag); + } +} +/** + * Writes a CSV representation of an operational domain to the specified file. The data are written as rows, each + * corresponding to one set of simulation parameters and their corresponding operational status. + * + * The output CSV format is as follows: + * X_DIMENSION, Y_DIMENSION, OPERATIONAL STATUS + * ... subsequent rows for each set of simulation parameters. + * + * The operational status is a binary value represented by specified tags in `params` indicating whether the simulation + * parameters are within the operational domain or not. + * + * @param opdom The operational domain to be written. It contains a mapping from sets of simulation parameters + * (represented as a pair of sweep parameters for the X and Y dimensions) to their operational status. + * @param filename The filename where the CSV representation of the operational domain is written to. + * @param params The parameters used for writing, including the operational and non-operational tags. Defaults to an + * empty `write_operational_domain_params` object, which provides standard tags. + */ + template +inline void write_operational_domain(const defect_operational_domain& opdom, const std::string_view& filename, + const write_operational_domain_params& params = {}) +{ + std::ofstream os{filename.data(), std::ofstream::out}; + + if (!os.is_open()) + { + throw std::ofstream::failure("could not open file"); + } + + write_operational_domain(opdom, os, params); + os.close(); +} + +} // namespace fiction + +#endif // FICTION_WRITE_OPERATIONAL_DOMAIN_HPP diff --git a/include/fiction/types.hpp b/include/fiction/types.hpp index 5f5cd7966..f684c295a 100644 --- a/include/fiction/types.hpp +++ b/include/fiction/types.hpp @@ -167,6 +167,9 @@ using cds_sidb_cell_clk_lyt = charge_distribution_surface>>>; using cds_sidb_cell_clk_lyt_ptr = std::shared_ptr; +using sidb_cell_clk_lyt_cube = cell_level_layout>>; +using sidb_cell_clk_lyt_cube_ptr = std::shared_ptr; + using sidb_cell_clk_lyt_siqad = cell_level_layout>>; using sidb_cell_clk_lyt_siqad_ptr = std::shared_ptr; diff --git a/test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp b/test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp new file mode 100644 index 000000000..560da8fcc --- /dev/null +++ b/test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp @@ -0,0 +1,75 @@ +// +// Created by Jan Drewniok on 07.02.24. +// + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace fiction; + +TEST_CASE("Bestagon AND Gate influence distance function", "[defect-influence-of-sidb-gate-contour-tracing]") +{ + sidb_cell_clk_lyt_siqad lyt{}; + + lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); + lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); + + lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + + const auto cube_lyt = convert_to_fiction_coordinates(lyt); + + const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, 5.6, 5.0}; + const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{2, -0.32}, {20, 20}}; + const defect_influence_params params{sim_params, is_operational_params{sim_params.physical_params}}; + + SECTION("input 00") + { + defect_influence_stats stats{}; + const auto defect_influence_domain = + defect_influence_of_sidb_gate_contour_tracing(cube_lyt, std::vector{create_and_tt()}, 100, params, &stats); + + write_operational_domain_params write_params{}; + write_params.operational_tag = "1"; + write_params.non_operational_tag = "0"; + write_operational_domain(defect_influence_domain, + "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", + write_params); + } + SECTION("input 01") {} + SECTION("input 10") {} + SECTION("input 11") {} +} diff --git a/test/algorithms/simulation/sidb/is_operational.cpp b/test/algorithms/simulation/sidb/is_operational.cpp index 0d869d870..23c435be7 100644 --- a/test/algorithms/simulation/sidb/is_operational.cpp +++ b/test/algorithms/simulation/sidb/is_operational.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include From c932bde6b2f40e361b672963c777034c0d33be20 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 7 Feb 2024 16:26:54 +0100 Subject: [PATCH 034/221] :construction: bug fix. --- .../sidb/defect_influence_of_sidb_gate_contour_tracing.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp index 215b60abb..e75ca3140 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp @@ -22,7 +22,7 @@ namespace fiction struct defect_influence_params { maximum_defect_influence_distance_params defect_influence_params{}; - is_operational_params is_operational_params{}; + is_operational_params op_params{}; detect_bdl_pairs_params bdl_pairs_params{}; }; @@ -246,7 +246,7 @@ class defect_influence_impl ++num_evaluated_defect_positions; layout.assign_sidb_defect(c, params.defect_influence_params.defect); - const auto& [status, sim_calls] = is_operational(layout, truth_table, params.is_operational_params); + const auto& [status, sim_calls] = is_operational(layout, truth_table, params.op_params); layout.assign_sidb_defect(c, sidb_defect{sidb_defect_type::NONE}); num_simulator_invocations += sim_calls; From b858c59fbeaf5dd4c09148f8ea32fdfb236256f8 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 7 Feb 2024 17:48:18 +0100 Subject: [PATCH 035/221] :construction: increase thread size. --- experiments/gate_generator_exhaustive.cpp | 35 ++++++++++++++++--- .../physical_design/design_sidb_gates.hpp | 22 ++++++------ ...influence_of_sidb_gate_contour_tracing.hpp | 14 ++++++-- 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 3254f8fb8..4b8270e20 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -84,12 +85,12 @@ int main() // NOLINT const maximum_defect_influence_distance_params defect_avoidance_params_arsenic{ sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}, params.phys_params, - {20, 20}}; + {50, 20}}; const maximum_defect_influence_distance_params defect_avoidance_params_vacancy{ sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}, params.phys_params, - {20, 20}}; + {50, 20}}; uint64_t truth_counter = 0; @@ -110,6 +111,7 @@ int main() // NOLINT std::vector defect_influence_vacancy = {}; std::vector pop_stability_neutral_to_negative = {}; std::vector pop_stability_negative_to_neutral = {}; + std::vector runtime = {}; { mockturtle::stopwatch stop{time_total}; @@ -126,11 +128,19 @@ int main() // NOLINT { // Local vectors to store calculated metrics std::vector temps_local; + temps_local.reserve(gate_chunk.size()); std::vector op_domains_local; + op_domains_local.reserve(gate_chunk.size()); std::vector defect_influence_arsenic_local; + defect_influence_arsenic_local.reserve(gate_chunk.size()); std::vector defect_influence_vacancy_local; + defect_influence_vacancy_local.reserve(gate_chunk.size()); std::vector pop_stability_neutral_to_negative_local; + pop_stability_neutral_to_negative_local.reserve(gate_chunk.size()); std::vector pop_stability_negative_to_neutral_local; + pop_stability_negative_to_neutral_local.reserve(gate_chunk.size()); + std::vector runtime_local; + runtime.reserve(gate_chunk.size()); for (const auto& gate : gate_chunk) { @@ -151,6 +161,20 @@ int main() // NOLINT &arsenic_stats); std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) << '\n'; + runtime_local.push_back(mockturtle::to_seconds(arsenic_stats.time_total)); +// if (mockturtle::to_seconds(arsenic_stats.time_total) < 0.4) +// { +// write_operational_domain_params write_params{}; +// write_params.operational_tag = "1"; +// write_params.non_operational_tag = "0"; +// write_operational_domain( +// defect_influence_domain_arsenic, +// "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", +// write_params); +// write_sqd_layout( +// gate, +// "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.sqd"); +// } defect_influence_arsenic.push_back( max_min_avoidance_distance(siqad_gate, defect_influence_domain_arsenic)); @@ -175,6 +199,7 @@ int main() // NOLINT const std::lock_guard lock(mtx); // Append local vectors to global vectors + runtime.insert(runtime.end(), runtime_local.begin(), runtime_local.end()); temps.insert(temps.end(), temps_local.begin(), temps_local.end()); op_domains.insert(op_domains.end(), op_domains_local.begin(), op_domains_local.end()); defect_influence_arsenic.insert(defect_influence_arsenic.end(), @@ -192,7 +217,7 @@ int main() // NOLINT }; // Define the number of threads to use - const size_t num_threads = 1; + const size_t num_threads = 10; const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size // A vector to store threads @@ -262,7 +287,7 @@ int main() // NOLINT // Write headers to the CSV file csvFile << "temp,op,popstab_neg_to_neu,popstab_neu_to_neg,defect_influence_arsenic,defect_influence_" - "vacancy\n"; + "vacancy,runtime\n"; // Write data to the CSV file and calculate mean, max, min double meanTemp = 0.0, maxTemp = std::numeric_limits::min(), @@ -282,7 +307,7 @@ int main() // NOLINT { csvFile << temps[k] << "," << op_domains[k] << "," << pop_stability_negative_to_neutral[k] << "," << pop_stability_neutral_to_negative[k] << "," << defect_influence_arsenic[k] << "," - << defect_influence_vacancy[k] << "\n"; + << defect_influence_vacancy[k] << runtime[k] << "\n"; // Update mean, max, min for temps meanTemp += temps[k]; diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 09dbddf63..9ae9f69a7 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -199,23 +199,23 @@ class design_sidb_gates_impl futures.reserve(all_combinations.size()); // Start asynchronous tasks to process combinations in parallel - // for (const auto& combination : all_combinations) - // { - // futures.emplace_back( - // std::async(std::launch::async, add_combination_to_layout_and_check_operation, combination)); - // } - for (const auto& combination : all_combinations) { - add_combination_to_layout_and_check_operation(combination); + futures.emplace_back( + std::async(std::launch::async, add_combination_to_layout_and_check_operation, combination)); } - // Wait for all tasks to finish - // for (auto& future : futures) + // for (const auto& combination : all_combinations) // { - // future.wait(); + // add_combination_to_layout_and_check_operation(combination); // } + // Wait for all tasks to finish + for (auto& future : futures) + { + future.wait(); + } + return designed_gate_layouts; } @@ -577,7 +577,7 @@ class design_sidb_gates_impl template [[nodiscard]] std::vector design_sidb_gates(const Lyt& skeleton, const std::vector& spec, const design_sidb_gates_params& params = {}, - design_sidb_gates_stats* pst = nullptr) noexcept + design_sidb_gates_stats* pst = nullptr) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp index e75ca3140..4ce31d058 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp @@ -152,6 +152,9 @@ class defect_influence_impl auto nw = fiction::siqad::to_fiction_coord(bb.get_min()); // north-west cell auto se = fiction::siqad::to_fiction_coord(bb.get_max()); // south-east cell + nw_layout = nw; + se_layout = se; + // shift nw and se cell by the additional scanning area to cover an area that is larger than the gate area. nw.x = nw.x - params.defect_influence_params.additional_scanning_area.first; nw.y = nw.y - params.defect_influence_params.additional_scanning_area.second; @@ -193,9 +196,13 @@ class defect_influence_impl find_non_operational_defect_position_via_random_sampling(const std::size_t samples) noexcept { std::set random_cells{}; + auto left = nw_layout; + auto right = se_layout; + left.y = 16; + right.x = 14; while (random_cells.size() < samples) { - const auto random = random_coordinate(nw_cell, se_cell); + const auto random = random_coordinate(left, right); if (layout.is_empty_cell(random)) { random_cells.insert(random); @@ -287,7 +294,6 @@ class defect_influence_impl const auto operational_status = is_defect_position_operational(current_defect_position); layout.assign_sidb_defect(current_defect_position, sidb_defect{sidb_defect_type::NONE}); - ; if (operational_status == operational_status::NON_OPERATIONAL) { @@ -400,8 +406,12 @@ class defect_influence_impl typename Lyt::cell nw_cell{}; + typename Lyt::cell nw_layout{}; + typename Lyt::cell se_cell{}; + typename Lyt::cell se_layout{}; + typename Lyt::cell current_defect_position{}; typename Lyt::cell previous_defect_position{}; From 8e30c94450f85fe0b1bb1da113e5cb2decd4a7e3 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 7 Feb 2024 17:59:04 +0100 Subject: [PATCH 036/221] :construction: increase thread size. --- experiments/gate_generator_exhaustive.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 4b8270e20..e320abc4a 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -217,7 +217,7 @@ int main() // NOLINT }; // Define the number of threads to use - const size_t num_threads = 10; + const size_t num_threads = 5; const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size // A vector to store threads @@ -307,7 +307,7 @@ int main() // NOLINT { csvFile << temps[k] << "," << op_domains[k] << "," << pop_stability_negative_to_neutral[k] << "," << pop_stability_neutral_to_negative[k] << "," << defect_influence_arsenic[k] << "," - << defect_influence_vacancy[k] << runtime[k] << "\n"; + << defect_influence_vacancy[k] << "," << runtime[k] << "\n"; // Update mean, max, min for temps meanTemp += temps[k]; From 9bca6f8a3bee72cf4b5b8fb61b33240b48c51469 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 9 Feb 2024 08:19:20 +0100 Subject: [PATCH 037/221] :construction: WIP code. --- experiments/gate_generator_exhaustive.cpp | 72 ++++---- ...influence_of_sidb_gate_contour_tracing.hpp | 86 +++++++-- .../sidb/max_min_avoidance_distance.hpp | 1 + ...influence_of_sidb_gate_contour_tracing.cpp | 163 ++++++++++++++++-- 4 files changed, 255 insertions(+), 67 deletions(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index e320abc4a..3b4138db2 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -59,11 +59,17 @@ int main() // NOLINT params.maximal_random_solutions = 100; - const auto truth_tables = std::vector>{ - std::vector{create_and_tt()}, std::vector{create_xor_tt()}, std::vector{create_or_tt()}, - std::vector{create_xnor_tt()}, std::vector{create_nor_tt()}, std::vector{create_nand_tt()}, - std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, - std::vector{create_ge_tt()}}; + // const auto truth_tables = std::vector>{std::vector{create_or_tt()}, + // std::vector{create_xnor_tt()}, std::vector{create_nor_tt()}, std::vector{create_nand_tt()}, + // std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, + // std::vector{create_ge_tt()}}; + +// const auto truth_tables = +// std::vector>{std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, +// std::vector{create_le_tt()}, std::vector{create_ge_tt()}}; + + const auto truth_tables = + std::vector>{std::vector{create_nand_tt()}}; const critical_temperature_params ct_params{sidb_simulation_parameters{ 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; @@ -92,12 +98,12 @@ int main() // NOLINT params.phys_params, {50, 20}}; - uint64_t truth_counter = 0; + uint64_t truth_counter = 5; for (const auto& truth_table : truth_tables) { std::cout << fmt::format("truth counter: {}", truth_counter) << '\n'; - for (auto num_sidbs = 2u; num_sidbs < 5; num_sidbs++) + for (auto num_sidbs = 2u; num_sidbs < 7; num_sidbs++) { std::cout << fmt::format("num sidbs: {}", num_sidbs) << '\n'; params.number_of_sidbs = num_sidbs; @@ -111,7 +117,7 @@ int main() // NOLINT std::vector defect_influence_vacancy = {}; std::vector pop_stability_neutral_to_negative = {}; std::vector pop_stability_negative_to_neutral = {}; - std::vector runtime = {}; + std::vector runtime = {}; { mockturtle::stopwatch stop{time_total}; @@ -144,12 +150,12 @@ int main() // NOLINT for (const auto& gate : gate_chunk) { - temps.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); + temps_local.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); operational_domain_stats op_stats{}; const auto op_domain = operational_domain_flood_fill(gate, truth_table, 0, op_domain_params, operational_domain::parameter_point{5.6, 5}, &op_stats); - op_domains.push_back(op_stats.percentual_operational_area); + op_domains_local.push_back(op_stats.percentual_operational_area); defect_influence_stats arsenic_stats{}; const auto siqad_gate = convert_to_fiction_coordinates(gate); @@ -162,21 +168,21 @@ int main() // NOLINT std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) << '\n'; runtime_local.push_back(mockturtle::to_seconds(arsenic_stats.time_total)); -// if (mockturtle::to_seconds(arsenic_stats.time_total) < 0.4) -// { -// write_operational_domain_params write_params{}; -// write_params.operational_tag = "1"; -// write_params.non_operational_tag = "0"; -// write_operational_domain( -// defect_influence_domain_arsenic, -// "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", -// write_params); -// write_sqd_layout( -// gate, -// "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.sqd"); -// } - - defect_influence_arsenic.push_back( + // if (mockturtle::to_seconds(arsenic_stats.time_total) < 0.4) + // { + // write_operational_domain_params write_params{}; + // write_params.operational_tag = "1"; + // write_params.non_operational_tag = "0"; + // write_operational_domain( + // defect_influence_domain_arsenic, + // "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", + // write_params); + // write_sqd_layout( + // gate, + // "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.sqd"); + // } + + defect_influence_arsenic_local.push_back( max_min_avoidance_distance(siqad_gate, defect_influence_domain_arsenic)); defect_influence_stats vacancy_stats{}; @@ -186,12 +192,12 @@ int main() // NOLINT defect_avoidance_params_vacancy, is_operational_params{defect_avoidance_params_arsenic.physical_params}}, &vacancy_stats); - defect_influence_vacancy.push_back( + defect_influence_vacancy_local.push_back( max_min_avoidance_distance(siqad_gate, defect_influence_domain_vacancy)); - pop_stability_neutral_to_negative.push_back( + pop_stability_neutral_to_negative_local.push_back( assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, -1)); - pop_stability_negative_to_neutral.push_back( + pop_stability_negative_to_neutral_local.push_back( assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, 1)); } @@ -217,7 +223,7 @@ int main() // NOLINT }; // Define the number of threads to use - const size_t num_threads = 5; + const size_t num_threads = 10; const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size // A vector to store threads @@ -242,6 +248,8 @@ int main() // NOLINT thread.join(); } + std::cout << "determination is finished" << std::endl; + // Start asynchronous tasks to process combinations in parallel // for (const auto& gate : all_gate) // { @@ -270,13 +278,13 @@ int main() // NOLINT { const auto choose_gate = all_gate[l]; write_sqd_layout(choose_gate, - fmt::format(solution_folder + "/sqd/16_7_1_22_10_numdbs_{}_ttnum_{}_{}.sqd", + fmt::format(solution_folder + "/sqd/17_7_21_11_numdbs_{}_ttnum_{}_{}.sqd", num_sidbs, truth_counter, l)); } // Open a file for writing - std::ofstream csvFile(fmt::format(solution_folder + "/csv/16_7_1_22_10_numdbs_{}_ttnum_{}.csv", - num_sidbs, truth_counter)); + std::ofstream csvFile( + fmt::format(solution_folder + "/csv/17_7_21_11_numdbs_{}_ttnum_{}.csv", num_sidbs, truth_counter)); // Check if the file is open if (!csvFile.is_open()) diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp index 4ce31d058..a772cb214 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp @@ -78,7 +78,7 @@ class defect_influence_impl mockturtle::stopwatch stop{stats.time_total}; // first, perform random sampling to find an operational starting point - const auto non_operational_starting_point = find_non_operational_defect_position_via_random_sampling(samples); + const auto non_operational_starting_point = find_operational_defect_position_at_the_top_left_corner(); // if no operational point was found within the specified number of samples, return if (!non_operational_starting_point.has_value()) @@ -103,7 +103,7 @@ class defect_influence_impl assert(layout.num_defects() == 0 && "defect is added defect"); // find an operational point on the contour starting from the randomly determined starting point - const auto contour_starting_point = find_non_operational_defect_position(*non_operational_starting_point); + const auto contour_starting_point = find_non_operational_defect_position_moving_right(*non_operational_starting_point); assert(layout.num_defects() == 0 && "more than one defect"); @@ -192,35 +192,49 @@ class defect_influence_impl return std::nullopt; } + [[nodiscard]] std::optional find_operational_defect_position_at_the_top_left_corner() noexcept + { + auto startin_point = nw_cell; + startin_point.y = se_layout.y; + layout.assign_sidb_defect(startin_point, params.defect_influence_params.defect); + // determine the operational status + const auto operational_value = is_defect_position_operational(startin_point); + layout.assign_sidb_defect(startin_point, sidb_defect{sidb_defect_type::NONE}); + + // if the parameter combination is operational, return its step values in x and y dimension + if (operational_value == operational_status::OPERATIONAL) + { + return startin_point; + } + + return std::nullopt; + } + [[nodiscard]] std::optional find_non_operational_defect_position_via_random_sampling(const std::size_t samples) noexcept { std::set random_cells{}; - auto left = nw_layout; - auto right = se_layout; - left.y = 16; - right.x = 14; + auto left = nw_layout; + auto right = se_layout; + left.y = 11; + right.x = 14; while (random_cells.size() < samples) { const auto random = random_coordinate(left, right); if (layout.is_empty_cell(random)) { random_cells.insert(random); - } - } - - for (const auto& random_cell : random_cells) - { - layout.assign_sidb_defect(random_cell, params.defect_influence_params.defect); - // determine the operational status - const auto operational_value = is_defect_position_operational(random_cell); + layout.assign_sidb_defect(random, params.defect_influence_params.defect); + // determine the operational status + const auto operational_value = is_defect_position_operational(random); - layout.assign_sidb_defect(random_cell, sidb_defect{sidb_defect_type::NONE}); + layout.assign_sidb_defect(random, sidb_defect{sidb_defect_type::NONE}); - // if the parameter combination is operational, return its step values in x and y dimension - if (operational_value == operational_status::NON_OPERATIONAL) - { - return random_cell; + // if the parameter combination is operational, return its step values in x and y dimension + if (operational_value == operational_status::NON_OPERATIONAL) + { + return random; + } } } @@ -253,6 +267,7 @@ class defect_influence_impl ++num_evaluated_defect_positions; layout.assign_sidb_defect(c, params.defect_influence_params.defect); + const auto num_defects = layout.num_defects(); const auto& [status, sim_calls] = is_operational(layout, truth_table, params.op_params); layout.assign_sidb_defect(c, sidb_defect{sidb_defect_type::NONE}); num_simulator_invocations += sim_calls; @@ -277,6 +292,39 @@ class defect_influence_impl return std::nullopt; } + [[nodiscard]] typename Lyt::cell + find_non_operational_defect_position_moving_right(const typename Lyt::cell& starting_defect_position) noexcept + { + auto latest_non_operational_defect_position = starting_defect_position; + // layout.assign_sidb_defect(starting_defect_position, params.defect_influence_params.defect); + previous_defect_position = starting_defect_position; + + // move towards the left border of the parameter range + for (int64_t x = starting_defect_position.x; x <= se_layout.x; x++) + { + current_defect_position = {x, starting_defect_position.y}; + + layout.assign_sidb_defect(current_defect_position, params.defect_influence_params.defect); + + const auto operational_status = is_defect_position_operational(current_defect_position); + + layout.assign_sidb_defect(current_defect_position, sidb_defect{sidb_defect_type::NONE}); + + if (operational_status == operational_status::OPERATIONAL) + { + latest_non_operational_defect_position = current_defect_position; + } + else + { + return current_defect_position; + } + } + + // if no boundary point was found, the operational area extends outside the parameter range + // return the latest operational point + return latest_non_operational_defect_position; + } + [[nodiscard]] typename Lyt::cell find_non_operational_defect_position(const typename Lyt::cell& starting_defect_position) noexcept { diff --git a/include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp b/include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp index 89f4f15f6..0a3651732 100644 --- a/include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp @@ -7,6 +7,7 @@ #include "fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp" #include "fiction/layouts/cell_level_layout.hpp" +#include "fiction/algorithms/simulation/sidb/operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" #include "fiction/algorithms/simulation/sidb/operational_domain.hpp" diff --git a/test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp b/test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp index 560da8fcc..06e360c5a 100644 --- a/test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp @@ -14,37 +14,167 @@ #include #include #include +#include using namespace fiction; -TEST_CASE("Bestagon AND Gate influence distance function", "[defect-influence-of-sidb-gate-contour-tracing]") +//TEST_CASE("Bestagon AND Gate influence distance function", "[defect-influence-of-sidb-gate-contour-tracing]") +//{ +// sidb_cell_clk_lyt_siqad lyt{}; +// +// lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); +// lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); +// +// lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); +// lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); +// +// lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); +// lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); +// +// lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); +// +// const auto cube_lyt = convert_to_fiction_coordinates(lyt); +// +// const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, 5.6, 5.0}; +// const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{2, -0.32}, {20, 20}}; +// const defect_influence_params params{sim_params, is_operational_params{sim_params.physical_params}}; +// +// SECTION("input 00") +// { +// defect_influence_stats stats{}; +// const auto defect_influence_domain = +// defect_influence_of_sidb_gate_contour_tracing(cube_lyt, std::vector{create_and_tt()}, 100, params, &stats); +// +// write_operational_domain_params write_params{}; +// write_params.operational_tag = "1"; +// write_params.non_operational_tag = "0"; +// write_operational_domain(defect_influence_domain, +// "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", +// write_params); +// } +// SECTION("input 01") {} +// SECTION("input 10") {} +// SECTION("input 11") {} +//} + +//TEST_CASE("novel designed AND Gate influence distance function", "[defect-influence-of-sidb-gate-contour-tracing]") +//{ +// sidb_cell_clk_lyt_siqad lyt{}; +// +// lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); +// lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); +// +// lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); +// lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); +// +// +// lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); +// +// // canvas SiDBs +// // ------------- +// lyt.assign_cell_type({21, 7, 1}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({17, 9, 0}, sidb_technology::cell_type::NORMAL); +// +// lyt.assign_cell_type({19, 10, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({20, 11, 0}, sidb_technology::cell_type::NORMAL); +// // ------------- +// +// +// lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); +// lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); +// lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); +// +// lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); +// +// const auto cube_lyt = convert_to_fiction_coordinates(lyt); +// +// const sidb_defect sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}; +// const maximum_defect_influence_distance_params sim_params{sidb_defect, sidb_simulation_parameters{2, -0.32}, {20, 20}}; +// const defect_influence_params params{sim_params, is_operational_params{sim_params.physical_params}}; +// +// SECTION("input 00") +// { +// defect_influence_stats stats{}; +// const auto defect_influence_domain = +// defect_influence_of_sidb_gate_contour_tracing(cube_lyt, std::vector{create_and_tt()}, 1000, params, &stats); +// std::cout << max_min_avoidance_distance(cube_lyt, defect_influence_domain) << std::endl; +// +// write_operational_domain_params write_params{}; +// write_params.operational_tag = "1"; +// write_params.non_operational_tag = "0"; +// write_operational_domain(defect_influence_domain, +// "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", +// write_params); +// } +// SECTION("input 01") {} +// SECTION("input 10") {} +// SECTION("input 11") {} +//} + +TEST_CASE("novel designed AND Gate influence distance function which fails", "[defect-influence-of-sidb-gate-contour-tracing]") { sidb_cell_clk_lyt_siqad lyt{}; + lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); + // canvas SiDBs + // ------------- + lyt.assign_cell_type({19, 7, 1}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 9, 1}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 11, 0}, sidb_technology::cell_type::NORMAL); + // ------------- + + + lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); @@ -52,15 +182,16 @@ TEST_CASE("Bestagon AND Gate influence distance function", "[defect-influence-of const auto cube_lyt = convert_to_fiction_coordinates(lyt); - const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, 5.6, 5.0}; - const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{2, -0.32}, {20, 20}}; + const sidb_defect sidb_defect{sidb_defect_type::UNKNOWN, -1, 9.7, 2.1}; + const maximum_defect_influence_distance_params sim_params{sidb_defect, sidb_simulation_parameters{2, -0.32}, {50, 20}}; const defect_influence_params params{sim_params, is_operational_params{sim_params.physical_params}}; SECTION("input 00") { defect_influence_stats stats{}; const auto defect_influence_domain = - defect_influence_of_sidb_gate_contour_tracing(cube_lyt, std::vector{create_and_tt()}, 100, params, &stats); + defect_influence_of_sidb_gate_contour_tracing(cube_lyt, std::vector{create_nand_tt()}, 100, params, &stats); + std::cout << max_min_avoidance_distance(cube_lyt, defect_influence_domain) << std::endl; write_operational_domain_params write_params{}; write_params.operational_tag = "1"; From a1cc61c073f188090ac943455a12b726c140ce67 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 9 Feb 2024 08:26:43 +0100 Subject: [PATCH 038/221] :construction: use maximum number of threads. --- experiments/gate_generator_exhaustive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index 3b4138db2..e0cbcade8 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -223,7 +223,7 @@ int main() // NOLINT }; // Define the number of threads to use - const size_t num_threads = 10; + const size_t num_threads = std::thread::hardware_concurrency(); const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size // A vector to store threads From cbd65cbf4c7bdfe7d6258cfd8d36b4ce6887653d Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 26 Apr 2024 08:31:53 +0200 Subject: [PATCH 039/221] :construction: WIP code. --- docs/algorithms/sidb_simulation.rst | 8 + experiments/gate_generator_exhaustive.cpp | 65 +- experiments/gate_generator_with_sa.cpp | 68 +- .../optimization/simulated_annealing.hpp | 61 +- .../physical_design/design_sidb_gates.hpp | 33 +- ...hysical_population_stability_sidb_gate.hpp | 16 +- ...influence_of_sidb_gate_contour_tracing.hpp | 549 -------------- .../defect_influence_operational_domain.hpp | 704 ++++++++++++++++++ .../simulation/sidb/is_operational.hpp | 4 + .../sidb/max_min_avoidance_distance.hpp | 45 -- ...defect_influence_position_and_distance.hpp | 6 +- ...imum_minimum_defect_influence_distance.hpp | 56 ++ .../io/write_defect_operational_domain.hpp | 6 +- ...influence_of_sidb_gate_contour_tracing.cpp | 206 ----- .../defect_influence_operational_domain.cpp | 117 +++ ...defect_influence_position_and_distance.cpp | 17 +- 16 files changed, 1022 insertions(+), 939 deletions(-) delete mode 100644 include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp create mode 100644 include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp delete mode 100644 include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp create mode 100644 include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp delete mode 100644 test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp create mode 100644 test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 815cc40fb..29a1fe708 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -213,3 +213,11 @@ Convert Potential to Distance **Header:** ``fiction/algorithms/simulation/sidb/convert_potential_to_distance.hpp`` .. doxygenfunction:: fiction::convert_potential_to_distance + + +Maximum Minimum Defect Influence Distance +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +**Header:** ``fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp`` + +.. doxygenfunction:: fiction::maximum_minimum_defect_influence_distance diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp index e0cbcade8..01a56003e 100644 --- a/experiments/gate_generator_exhaustive.cpp +++ b/experiments/gate_generator_exhaustive.cpp @@ -9,9 +9,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include #include @@ -47,7 +47,7 @@ int main() // NOLINT static const std::string folder = fmt::format("{}skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd", EXPERIMENTS_PATH); - static const std::string solution_folder = fmt::format("{}metric_data/", EXPERIMENTS_PATH); + static const std::string solution_folder = fmt::format("{}metric_data_final/", EXPERIMENTS_PATH); const auto skeleton = read_sqd_layout(folder); @@ -59,17 +59,19 @@ int main() // NOLINT params.maximal_random_solutions = 100; - // const auto truth_tables = std::vector>{std::vector{create_or_tt()}, - // std::vector{create_xnor_tt()}, std::vector{create_nor_tt()}, std::vector{create_nand_tt()}, - // std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, - // std::vector{create_ge_tt()}}; + const auto truth_tables = std::vector>{std::vector{create_and_tt()}, + std::vector{create_xor_tt()}, std::vector{create_or_tt()}, + std::vector{create_xnor_tt()}, std::vector{create_nor_tt()}, std::vector{create_nand_tt()}, + std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, + std::vector{create_ge_tt()}}; -// const auto truth_tables = -// std::vector>{std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, -// std::vector{create_le_tt()}, std::vector{create_ge_tt()}}; + const std::vector gate_names = {"and", "xor", "or", "xnor", "nor", "nand", "lt", "gt", "le", "ge"}; - const auto truth_tables = - std::vector>{std::vector{create_nand_tt()}}; + // const auto truth_tables = + // std::vector>{std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, + // std::vector{create_le_tt()}, std::vector{create_ge_tt()}}; + + // const auto truth_tables = std::vector>{std::vector{create_nand_tt()}}; const critical_temperature_params ct_params{sidb_simulation_parameters{ 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; @@ -98,12 +100,12 @@ int main() // NOLINT params.phys_params, {50, 20}}; - uint64_t truth_counter = 5; + uint64_t truth_counter = 0; for (const auto& truth_table : truth_tables) { std::cout << fmt::format("truth counter: {}", truth_counter) << '\n'; - for (auto num_sidbs = 2u; num_sidbs < 7; num_sidbs++) + for (auto num_sidbs = 5u; num_sidbs < 7; num_sidbs++) { std::cout << fmt::format("num sidbs: {}", num_sidbs) << '\n'; params.number_of_sidbs = num_sidbs; @@ -150,6 +152,7 @@ int main() // NOLINT for (const auto& gate : gate_chunk) { + //write_sqd_layout(gate, solution_folder + "/bug/17_7_21_11_numdbs_{}.sqd"); temps_local.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); operational_domain_stats op_stats{}; const auto op_domain = @@ -159,12 +162,12 @@ int main() // NOLINT defect_influence_stats arsenic_stats{}; const auto siqad_gate = convert_to_fiction_coordinates(gate); - const auto defect_influence_domain_arsenic = defect_influence_of_sidb_gate_contour_tracing( - siqad_gate, truth_table, 300, - defect_influence_params{ - defect_avoidance_params_arsenic, - is_operational_params{defect_avoidance_params_arsenic.physical_params}}, - &arsenic_stats); + const auto defect_influence_domain_arsenic = defect_influence_operational_domain_contour_tracing( + siqad_gate, truth_table, 300, + defect_influence_params{ + defect_avoidance_params_arsenic, + is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, + &arsenic_stats); std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) << '\n'; runtime_local.push_back(mockturtle::to_seconds(arsenic_stats.time_total)); @@ -183,17 +186,17 @@ int main() // NOLINT // } defect_influence_arsenic_local.push_back( - max_min_avoidance_distance(siqad_gate, defect_influence_domain_arsenic)); + maximum_minimum_defect_influence_distance(siqad_gate, defect_influence_domain_arsenic)); defect_influence_stats vacancy_stats{}; - const auto defect_influence_domain_vacancy = defect_influence_of_sidb_gate_contour_tracing( - siqad_gate, truth_table, 300, - defect_influence_params{ - defect_avoidance_params_vacancy, - is_operational_params{defect_avoidance_params_arsenic.physical_params}}, - &vacancy_stats); + const auto defect_influence_domain_vacancy = defect_influence_operational_domain_contour_tracing( + siqad_gate, truth_table, 300, + defect_influence_params{ + defect_avoidance_params_vacancy, + is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, + &vacancy_stats); defect_influence_vacancy_local.push_back( - max_min_avoidance_distance(siqad_gate, defect_influence_domain_vacancy)); + maximum_minimum_defect_influence_distance(siqad_gate, defect_influence_domain_vacancy)); pop_stability_neutral_to_negative_local.push_back( assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, -1)); @@ -278,13 +281,13 @@ int main() // NOLINT { const auto choose_gate = all_gate[l]; write_sqd_layout(choose_gate, - fmt::format(solution_folder + "/sqd/17_7_21_11_numdbs_{}_ttnum_{}_{}.sqd", - num_sidbs, truth_counter, l)); + fmt::format(solution_folder + "/sqd/17_7_21_11_numdbs_{}_{}_{}.sqd", + num_sidbs, gate_names[truth_counter], l)); } // Open a file for writing std::ofstream csvFile( - fmt::format(solution_folder + "/csv/17_7_21_11_numdbs_{}_ttnum_{}.csv", num_sidbs, truth_counter)); + fmt::format(solution_folder + "/csv/17_7_21_11_numdbs_{}_{}.csv", num_sidbs, gate_names[truth_counter])); // Check if the file is open if (!csvFile.is_open()) diff --git a/experiments/gate_generator_with_sa.cpp b/experiments/gate_generator_with_sa.cpp index 9818d0b01..3e2de29db 100644 --- a/experiments/gate_generator_with_sa.cpp +++ b/experiments/gate_generator_with_sa.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -20,8 +21,9 @@ using namespace fiction; int main() // NOLINT { const auto skeleton = - read_sqd_layout("/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/" - "skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd"); + read_sqd_layout( + "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/" + "skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd"); // toffoli // const design_sidb_gates_params params{ @@ -32,36 +34,36 @@ int main() // NOLINT // sidb_simulation_engine::QUICKEXACT}; design_sidb_gates_params params{ - sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params::design_sidb_gates_mode::SIMANNEAL, - {{17, 7, 0}, {21, 11, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT}; + sidb_simulation_parameters{2, -0.32}, + design_sidb_gates_params::design_sidb_gates_mode::SIMANNEAL, + {{17, 7, 0}, {21, 11, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT}; params.maximal_random_solutions = 100; - const auto truth_tables = std::vector>{ - std::vector{create_and_tt()}, std::vector{create_xor_tt()}, std::vector{create_or_tt()}, - std::vector{create_xnor_tt()}, std::vector{create_nor_tt()}, std::vector{create_nand_tt()}, - std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, - std::vector{create_ge_tt()}}; + // const auto truth_tables = std::vector>{ + // std::vector{create_and_tt()}, std::vector{create_xor_tt()}, std::vector{create_or_tt()}, + // std::vector{create_xnor_tt()}, std::vector{create_nor_tt()}, std::vector{create_nand_tt()}, + // std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, + // std::vector{create_ge_tt()}}; - // const auto truth_tables = std::vector>{std::vector{create_nor_tt()}}; + const auto truth_tables = std::vector>{std::vector{create_and_tt()}}; // const auto truth_tables // std::vector>{std::vector{create_id_tt()}, std::vector{create_not_tt()}}; const critical_temperature_params ct_params{sidb_simulation_parameters{ - 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; + 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; operational_domain_params op_domain_params{sidb_simulation_parameters{ - 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; - op_domain_params.x_min = 4.0; - op_domain_params.x_max = 6; + 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; + op_domain_params.x_min = 4.0; + op_domain_params.x_max = 6; op_domain_params.x_step = 0.2; - op_domain_params.y_min = 4.0; - op_domain_params.y_max = 6; + op_domain_params.y_min = 4.0; + op_domain_params.y_max = 6; op_domain_params.y_step = 0.2; params.simanneal_params.ct_params = ct_params; @@ -69,26 +71,34 @@ int main() // NOLINT uint64_t truth_counter = 0; - for (const auto& truth : truth_tables) - { + for (const auto &truth: truth_tables) { std::cout << fmt::format("{} truth table", truth_counter) << std::endl; - for (auto i = 4u; i < 5; i++) - { + for (auto i = 4u; i < 5; i++) { double total_time = 0; - double net_cost = 0; + double net_cost = 0; std::cout << fmt::format("{} placed SiDBs", i) << std::endl; - for (auto t = 0u; t < 10; t++) - { + std::vector all_gate{}; + for (auto t = 0u; t < 1; t++) { params.number_of_sidbs = i; design_sidb_gates_stats stats{}; - const auto all_gate = design_sidb_gates(skeleton, truth, params, &stats); + all_gate = design_sidb_gates(skeleton, truth, params, &stats); net_cost += stats.cost_of_gate; total_time += mockturtle::to_seconds(stats.time_total); } - std::cout << fmt::format("average runtime: {}", total_time / 10) << std::endl; - std::cout << fmt::format("net cost: {}", net_cost / 10) << std::endl; + const is_operational_params params_is_operational{params.phys_params, params.sim_engine}; + auto result = + is_operational(all_gate[0], truth, params_is_operational).first == operational_status::OPERATIONAL ? + "operational" : + "non_operational"; + std::cout << result; + + std::cout << fmt::format("average runtime: {}", total_time / 1) << std::endl; + std::cout << fmt::format("net cost: {}", net_cost / 1) << std::endl; + write_sqd_layout( + all_gate[0], "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/gate_design_sa/" + + std::to_string(truth_counter) + ".sqd"); } std::cout << "-----------" << std::endl; diff --git a/include/fiction/algorithms/optimization/simulated_annealing.hpp b/include/fiction/algorithms/optimization/simulated_annealing.hpp index 35df7893a..38fa9e0d5 100644 --- a/include/fiction/algorithms/optimization/simulated_annealing.hpp +++ b/include/fiction/algorithms/optimization/simulated_annealing.hpp @@ -53,6 +53,7 @@ enum class temperature_schedule */ GEOMETRIC }; + /** * Simulated Annealing (SA) is a probabilistic optimization algorithm that is used to find a local minimum of a given * function. SA was first proposed in \"Optimization by simulated annealing\" by S. Kirkpatrick, C. D. Gelatt Jr, and M. @@ -106,42 +107,48 @@ simulated_annealing(const State& init_state, const double init_temp, const doubl State best_state = current_state; auto best_cost = current_cost; - auto temp = init_temp; - - while (temp > final_temp) { - for (std::size_t c = 0; c < cycles; ++c) { - State new_state = next(current_state); - auto new_cost = cost(new_state); - - if (new_cost < best_cost) { - best_state = new_state; - best_cost = new_cost; - current_state = std::move(new_state); - current_cost = std::move(new_cost); + auto temp = init_temp; - continue; - } - - const auto cost_delta = static_cast(new_cost - current_cost); + while (temp > final_temp) + { + for (std::size_t c = 0; c < cycles; ++c) + { + State new_state = next(current_state); + auto new_cost = cost(new_state); + + if (new_cost < best_cost) + { + best_state = new_state; + best_cost = new_cost; + current_state = std::move(new_state); + current_cost = std::move(new_cost); + + continue; + } - // shortcut to skip the expensive std::exp call - if (cost_delta > 10.0 * temp) { - continue; // as std::exp(-10.0) is a very small number - } + const auto cost_delta = static_cast(new_cost - current_cost); - // if the new state is worse, accept it with a probability of exp(-energy_delta/temp) - if (cost_delta <= 0.0 || std::exp(-cost_delta / temp) > random_functor(generator)) { - current_state = std::move(new_state); - current_cost = std::move(new_cost); - } + // shortcut to skip the expensive std::exp call + if (cost_delta > 10.0 * temp) + { + continue; // as std::exp(-10.0) is a very small number } - // update temperature - temp = std::clamp(schedule(temp), final_temp, init_temp); + // if the new state is worse, accept it with a probability of exp(-energy_delta/temp) + if (cost_delta <= 0.0 || std::exp(-cost_delta / temp) > random_functor(generator)) + { + current_state = std::move(new_state); + current_cost = std::move(new_cost); + } } + // update temperature + temp = std::clamp(schedule(temp), final_temp, init_temp); + } + return {best_state, best_cost}; } + /** * This variation of Simulated Annealing (SA) does not start from just one provided initial state, but generates a * number of random initial states using a provided random state generator. SA as specified above is then run on all diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index b218456cf..8852d41e9 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -112,10 +112,14 @@ struct design_sidb_gates_params * The simulation engine to be used for the operational domain computation. */ sidb_simulation_engine sim_engine{sidb_simulation_engine::QUICKEXACT}; - + /** + * The design parameters used when designing with Simulated Annealing. + */ design_sidb_gates_sa_params simanneal_params{}; - - std::size_t maximal_random_solutions{}; + /** + * The number of gate implementations found before the random design process is stopped. + */ + std::size_t maximal_random_solutions = 1; }; /** * Statistics for the design of SiDB gates. @@ -123,7 +127,7 @@ struct design_sidb_gates_params struct design_sidb_gates_stats { /** - * The total runtime of SiDb gate design process. + * The total runtime of SiDB gate design process. */ mockturtle::stopwatch<>::duration time_total{0}; @@ -172,7 +176,7 @@ class design_sidb_gates_impl const is_operational_params params_is_operational{params.phys_params, params.sim_engine}; const auto all_combinations = determine_all_combinations_of_distributing_k_entities_on_n_positions( - params.number_of_sidbs, static_cast(all_sidbs_in_canvas.size())); + params.number_of_sidbs, static_cast(all_cells_in_canvas.size())); std::vector designed_gate_layouts = {}; @@ -205,11 +209,6 @@ class design_sidb_gates_impl std::async(std::launch::async, add_combination_to_layout_and_check_operation, combination)); } - // for (const auto& combination : all_combinations) - // { - // add_combination_to_layout_and_check_operation(combination); - // } - // Wait for all tasks to finish for (auto& future : futures) { @@ -351,20 +350,6 @@ class design_sidb_gates_impl }); std::cout << fmt::format("final cost: {}", optimized_net_cost) << std::endl; - // std::cout << fmt::format("cost logic: {}", - // static_cast(number_of_operational_input_combinations( - // optimized_placement, truth_table, - // params_is_operational))) - // << std::endl; - // std::cout << fmt::format("cost temp: {}", static_cast(critical_temperature_gate_based( - // optimized_placement, truth_table, ct_params))) - // << std::endl; - // operational_domain_stats stats{}; - // const auto op_domain = operational_domain_flood_fill(optimized_placement, truth_table, 1, - // op_domain_params, - // operational_domain::parameter_point{5.6, 5}, - // &stats); - // std::cout << fmt::format("cost opdomain: {}", stats.percentual_operational_area) << std::endl; stats.cost_of_gate = optimized_net_cost; return {optimized_placement}; } diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp index 9b6709089..90479f449 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp @@ -44,7 +44,7 @@ assess_physical_population_stability_sidb_gate(const Lyt& lyt, const std::vector [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.end()); bdl_input_iterator bii{lyt, params.detect_pair_params}; - double maximal_pop_stability_for_all_inputs = 0; + double maximal_pop_stability_for_all_inputs = std::numeric_limits::infinity(); // number of different input combinations for (auto i = 0u; i < spec.front().num_bits(); ++i, ++bii) { @@ -52,24 +52,22 @@ assess_physical_population_stability_sidb_gate(const Lyt& lyt, const std::vector assess_physical_population_stability(lyt, params.assess_population_stability_params); if (!pop_stability.empty()) { - const auto stability_for_given_input = pop_stability.front().distance_corresponding_to_potential; - double distance_corresponding_to_potential = 0.0; + const auto stability_for_given_input = pop_stability.front().minimum_potential_difference_to_transition; + double potential = 0.0; if (charge_state_change == 1) { - distance_corresponding_to_potential = - stability_for_given_input.at(transition_type::NEGATIVE_TO_NEUTRAL); + potential = std::abs(stability_for_given_input.at(transition_type::NEGATIVE_TO_NEUTRAL)); } if (charge_state_change == -1) { - distance_corresponding_to_potential = - stability_for_given_input.at(transition_type::NEUTRAL_TO_NEGATIVE); + potential = std::abs(stability_for_given_input.at(transition_type::NEUTRAL_TO_NEGATIVE)); } - if (distance_corresponding_to_potential > maximal_pop_stability_for_all_inputs) + if (potential < maximal_pop_stability_for_all_inputs) { - maximal_pop_stability_for_all_inputs = distance_corresponding_to_potential; + maximal_pop_stability_for_all_inputs = potential; } } } diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp deleted file mode 100644 index a772cb214..000000000 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp +++ /dev/null @@ -1,549 +0,0 @@ -// -// Created by Jan Drewniok on 28.12.23. -// - -#ifndef FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP -#define FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP - -#include "fiction/algorithms/simulation/sidb/is_operational.hpp" -#include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" -#include "fiction/layouts/bounding_box.hpp" -#include "fiction/layouts/coordinates.hpp" -#include "fiction/technology/sidb_surface.hpp" -#include "fiction/types.hpp" -#include "fiction/utils/hash.hpp" -#include "fiction/utils/layout_utils.hpp" -#include "fiction/utils/phmap_utils.hpp" -#include "mockturtle/utils/stopwatch.hpp" - -namespace fiction -{ - -struct defect_influence_params -{ - maximum_defect_influence_distance_params defect_influence_params{}; - is_operational_params op_params{}; - detect_bdl_pairs_params bdl_pairs_params{}; -}; - -template -struct defect_operational_domain -{ - locked_parallel_flat_hash_map operational_values{}; -}; - -struct defect_influence_stats -{ - /** - * The total runtime of the operational domain computation. - */ - mockturtle::stopwatch<>::duration time_total{0}; - /** - * Number of simulator invocations. - */ - std::size_t num_simulator_invocations{0}; - /** - * Number of evaluated parameter combinations. - */ - std::size_t num_evaluated_defect_positions{0}; - /** - * Number of parameter combinations, for which the layout is operational. - */ - std::size_t num_operational_defect_positions{0}; - /** - * Number of parameter combinations, for which the layout is non-operational. - */ - std::size_t num_non_operational_defect_positions{0}; -}; - -namespace detail -{ - -template -class defect_influence_impl -{ - public: - defect_influence_impl(const Lyt& lyt, const std::vector& tt, const defect_influence_params& ps, - defect_influence_stats& st) : - layout{lyt}, - truth_table{tt}, - params{ps}, - stats{st} - { - determine_edge_cells(); - } - - [[nodiscard]] defect_operational_domain contour_tracing(const std::size_t samples) noexcept - { - mockturtle::stopwatch stop{stats.time_total}; - - // first, perform random sampling to find an operational starting point - const auto non_operational_starting_point = find_operational_defect_position_at_the_top_left_corner(); - - // if no operational point was found within the specified number of samples, return - if (!non_operational_starting_point.has_value()) - { - return defect_domain; - } - - const auto next_clockwise_point = [](std::vector& neighborhood, - const typename Lyt::cell& backtrack) noexcept -> typename Lyt::cell - { - assert(std::find(neighborhood.cbegin(), neighborhood.cend(), backtrack) != neighborhood.cend() && - "The backtrack point must be part of the neighborhood"); - - while (neighborhood.back() != backtrack) - { - std::rotate(neighborhood.begin(), neighborhood.begin() + 1, neighborhood.end()); - } - - return neighborhood.front(); - }; - - assert(layout.num_defects() == 0 && "defect is added defect"); - - // find an operational point on the contour starting from the randomly determined starting point - const auto contour_starting_point = find_non_operational_defect_position_moving_right(*non_operational_starting_point); - - assert(layout.num_defects() == 0 && "more than one defect"); - - auto current_contour_point = contour_starting_point; - auto backtrack_point = current_contour_point.x == nw_cell.x ? - current_contour_point : - typename Lyt::cell{current_contour_point.x - 1, current_contour_point.y}; - - auto current_neighborhood = moore_neighborhood(current_contour_point); - auto next_point = current_contour_point == backtrack_point ? - current_neighborhood.front() : - next_clockwise_point(current_neighborhood, backtrack_point); - - while (next_point != contour_starting_point) - { - const auto operational_status = is_defect_position_operational(next_point); - - assert(layout.num_defects() == 0 && "more than one defect"); - - if (operational_status == operational_status::NON_OPERATIONAL) - { - backtrack_point = current_contour_point; - current_contour_point = next_point; - } - else - { - backtrack_point = next_point; - } - - current_neighborhood = moore_neighborhood(current_contour_point); - next_point = next_clockwise_point(current_neighborhood, backtrack_point); - } - - log_stats(); - - return defect_domain; - } - - private: - void determine_edge_cells() noexcept - { - // bounding box around the given layout to have north-west and south-east cells. - const auto siqad_layout = convert_to_siqad_coordinates(layout); - bounding_box_2d bb{siqad_layout}; - - auto nw = fiction::siqad::to_fiction_coord(bb.get_min()); // north-west cell - auto se = fiction::siqad::to_fiction_coord(bb.get_max()); // south-east cell - - nw_layout = nw; - se_layout = se; - - // shift nw and se cell by the additional scanning area to cover an area that is larger than the gate area. - nw.x = nw.x - params.defect_influence_params.additional_scanning_area.first; - nw.y = nw.y - params.defect_influence_params.additional_scanning_area.second; - - se.x = se.x + params.defect_influence_params.additional_scanning_area.first; - se.y = se.y + params.defect_influence_params.additional_scanning_area.second; - - nw_cell = nw; - se_cell = se; - // defect_cells = all_coordinates_in_spanned_area(nw, se); - } - - [[nodiscard]] std::optional find_non_operational_defect_position_via_sidbs() noexcept - { - layout.foreach_cell( - [this](const auto& c) - { - auto c_copy = c; - c_copy.x = c.x - 1; - if (layout.is_empty_cell(c_copy)) - { - layout.assign_sidb_defect(c_copy, params.defect_influence_params.defect); - // determine the operational status - const auto operational_value = is_defect_position_operational(c_copy); - - layout.assign_sidb_defect(c_copy, sidb_defect{sidb_defect_type::NONE}); - - // if the parameter combination is operational, return its step values in x and y dimension - if (operational_value == operational_status::NON_OPERATIONAL) - { - return c_copy; - } - } - }); - return std::nullopt; - } - - [[nodiscard]] std::optional find_operational_defect_position_at_the_top_left_corner() noexcept - { - auto startin_point = nw_cell; - startin_point.y = se_layout.y; - layout.assign_sidb_defect(startin_point, params.defect_influence_params.defect); - // determine the operational status - const auto operational_value = is_defect_position_operational(startin_point); - layout.assign_sidb_defect(startin_point, sidb_defect{sidb_defect_type::NONE}); - - // if the parameter combination is operational, return its step values in x and y dimension - if (operational_value == operational_status::OPERATIONAL) - { - return startin_point; - } - - return std::nullopt; - } - - [[nodiscard]] std::optional - find_non_operational_defect_position_via_random_sampling(const std::size_t samples) noexcept - { - std::set random_cells{}; - auto left = nw_layout; - auto right = se_layout; - left.y = 11; - right.x = 14; - while (random_cells.size() < samples) - { - const auto random = random_coordinate(left, right); - if (layout.is_empty_cell(random)) - { - random_cells.insert(random); - layout.assign_sidb_defect(random, params.defect_influence_params.defect); - // determine the operational status - const auto operational_value = is_defect_position_operational(random); - - layout.assign_sidb_defect(random, sidb_defect{sidb_defect_type::NONE}); - - // if the parameter combination is operational, return its step values in x and y dimension - if (operational_value == operational_status::NON_OPERATIONAL) - { - return random; - } - } - } - - return std::nullopt; - } - - operational_status is_defect_position_operational(const typename Lyt::cell& c) noexcept - { - // if the point has already been sampled, return the stored operational status - if (const auto op_value = has_already_been_sampled(c); op_value.has_value()) - { - return *op_value; - } - - const auto operational = [this, &c]() - { - defect_domain.operational_values[c] = operational_status::OPERATIONAL; - - return operational_status::OPERATIONAL; - }; - - const auto non_operational = [this, &c]() - { - defect_domain.operational_values[c] = operational_status::NON_OPERATIONAL; - - return operational_status::NON_OPERATIONAL; - }; - - // increment the number of evaluated parameter combinations - ++num_evaluated_defect_positions; - - layout.assign_sidb_defect(c, params.defect_influence_params.defect); - const auto num_defects = layout.num_defects(); - const auto& [status, sim_calls] = is_operational(layout, truth_table, params.op_params); - layout.assign_sidb_defect(c, sidb_defect{sidb_defect_type::NONE}); - num_simulator_invocations += sim_calls; - - if (status == operational_status::NON_OPERATIONAL) - { - return non_operational(); - } - - // if we made it here, the layout is operational - return operational(); - } - - [[nodiscard]] inline std::optional - has_already_been_sampled(const typename Lyt::cell& c) const noexcept - { - if (const auto it = defect_domain.operational_values.find(c); it != defect_domain.operational_values.cend()) - { - return it->second; - } - - return std::nullopt; - } - - [[nodiscard]] typename Lyt::cell - find_non_operational_defect_position_moving_right(const typename Lyt::cell& starting_defect_position) noexcept - { - auto latest_non_operational_defect_position = starting_defect_position; - // layout.assign_sidb_defect(starting_defect_position, params.defect_influence_params.defect); - previous_defect_position = starting_defect_position; - - // move towards the left border of the parameter range - for (int64_t x = starting_defect_position.x; x <= se_layout.x; x++) - { - current_defect_position = {x, starting_defect_position.y}; - - layout.assign_sidb_defect(current_defect_position, params.defect_influence_params.defect); - - const auto operational_status = is_defect_position_operational(current_defect_position); - - layout.assign_sidb_defect(current_defect_position, sidb_defect{sidb_defect_type::NONE}); - - if (operational_status == operational_status::OPERATIONAL) - { - latest_non_operational_defect_position = current_defect_position; - } - else - { - return current_defect_position; - } - } - - // if no boundary point was found, the operational area extends outside the parameter range - // return the latest operational point - return latest_non_operational_defect_position; - } - - [[nodiscard]] typename Lyt::cell - find_non_operational_defect_position(const typename Lyt::cell& starting_defect_position) noexcept - { - auto latest_non_operational_defect_position = starting_defect_position; - // layout.assign_sidb_defect(starting_defect_position, params.defect_influence_params.defect); - previous_defect_position = starting_defect_position; - - // move towards the left border of the parameter range - for (int64_t x = starting_defect_position.x; x >= nw_cell.x; --x) - { - current_defect_position = {x, starting_defect_position.y}; - - layout.assign_sidb_defect(current_defect_position, params.defect_influence_params.defect); - - const auto operational_status = is_defect_position_operational(current_defect_position); - - layout.assign_sidb_defect(current_defect_position, sidb_defect{sidb_defect_type::NONE}); - - if (operational_status == operational_status::NON_OPERATIONAL) - { - latest_non_operational_defect_position = current_defect_position; - } - else - { - return latest_non_operational_defect_position; - } - } - - // if no boundary point was found, the operational area extends outside the parameter range - // return the latest operational point - return latest_non_operational_defect_position; - } - - /** - * Helper function that writes the the statistics of the operational domain computation to the statistics object. - * Due to data races that can occur during the computation, each value is temporarily held in an atomic variable and - * written to the statistics object only after the computation has finished. - */ - void log_stats() const noexcept - { - stats.num_simulator_invocations = num_simulator_invocations; - stats.num_evaluated_defect_positions = num_evaluated_defect_positions; - - for (const auto& [param_point, status] : defect_domain.operational_values) - { - if (status == operational_status::OPERATIONAL) - { - ++stats.num_operational_defect_positions; - } - else - { - ++stats.num_non_operational_defect_positions; - } - } - } - - [[nodiscard]] std::vector moore_neighborhood(const typename Lyt::cell& c) const noexcept - { - std::vector neighbors{}; - neighbors.reserve(8); - - const auto& moore = c; - - const auto decr_x = (moore.x - 1 >= nw_cell.x) ? moore.x - 1 : moore.x; - const auto incr_x = (moore.x + 1 <= se_cell.x) ? moore.x + 1 : moore.x; - const auto decr_y = (moore.y - 1 >= nw_cell.y) ? moore.y - 1 : moore.y; - const auto incr_y = (moore.y + 1 <= se_cell.y) ? moore.y + 1 : moore.y; - - // add neighbors in clockwise direction - - // right - if (moore.x != incr_x) - { - neighbors.emplace_back(incr_x, moore.y); - } - // lower-right - if (moore.x != incr_x && moore.y != decr_y) - { - neighbors.emplace_back(incr_x, decr_y); - } - // down - if (moore.y != decr_y) - { - neighbors.emplace_back(moore.x, decr_y); - } - // lower-left - if (moore.x != decr_x && moore.y != decr_y) - { - neighbors.emplace_back(decr_x, decr_y); - } - // left - if (moore.x != decr_x) - { - neighbors.emplace_back(decr_x, moore.y); - } - // upper-left - if (moore.x != decr_x && moore.y != incr_y) - { - neighbors.emplace_back(decr_x, incr_y); - } - // up - if (moore.y != incr_y) - { - neighbors.emplace_back(moore.x, incr_y); - } - // upper-right - if (moore.x != incr_x && moore.y != incr_y) - { - neighbors.emplace_back(incr_x, incr_y); - } - - return neighbors; - }; - - /** - * The SiDB cell-level layout to investigate. - */ - sidb_surface layout{}; - /** - * The specification of the layout. - */ - const std::vector& truth_table; - /** - * The parameters for the operational domain computation. - */ - const defect_influence_params& params; - - typename Lyt::cell nw_cell{}; - - typename Lyt::cell nw_layout{}; - - typename Lyt::cell se_cell{}; - - typename Lyt::cell se_layout{}; - - typename Lyt::cell current_defect_position{}; - - typename Lyt::cell previous_defect_position{}; - - /** - * The operational domain of the layout. - */ - defect_operational_domain defect_domain{}; - - /** - * The statistics of the operational domain computation. - */ - defect_influence_stats& stats; - - std::atomic num_simulator_invocations{0}; - /** - * Number of evaluated parameter combinations. - */ - std::atomic num_evaluated_defect_positions{0}; -}; -} // namespace detail - -template -defect_operational_domain -defect_influence_of_sidb_gate_contour_tracing(const Lyt& lyt, const std::vector& spec, const std::size_t samples, - const defect_influence_params& params = {}, - defect_influence_stats* stats = nullptr) -{ - static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); - static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); - static_assert(kitty::is_truth_table::value, "TT is not a truth table"); - static_assert(has_cube_coord_v, "Lyt is not based on cube coordinates"); - - defect_influence_stats st{}; - detail::defect_influence_impl p{lyt, spec, params, st}; - - const auto result = p.contour_tracing(samples); - - if (stats) - { - *stats = st; - } - - return result; -} - -// template -//[[nodiscard]] std::pair maximum_defect_influence_position_and_distance_of_sidb_gate( -// const Lyt& lyt, const std::vector& spec, -// const maximum_defect_influence_position_and_distance_of_sidb_gate_params& params = {}) noexcept -//{ -// static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); -// static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); -// static_assert(!has_offset_ucoord_v, "Lyt should not be based on offset coordinates"); -// static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); -// -// assert(lyt.num_pis() > 0 && "skeleton needs input cells"); -// assert(lyt.num_pos() > 0 && "skeleton needs output cells"); -// -// assert(!spec.empty()); -// // all elements in tts must have the same number of variables -// assert(std::adjacent_find(spec.begin(), spec.end(), -// [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == -// spec.end()); -// -// bdl_input_iterator bii{lyt, params.bdl_pairs_params}; -// double maximum_defect_influence_distance = 0.0; -// cell defect_cell{}; -// // number of different input combinations -// for (auto i = 0u; i < spec.front().num_bits(); ++i, ++bii) -// { -// maximum_defect_influence_distance_stats stats_defect{}; -// const auto influence_cell_distance = -// maximum_defect_influence_position_and_distance(lyt, params.defect_influence_params, &stats_defect); -// std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; -// if (influence_cell_distance.second > maximum_defect_influence_distance) -// { -// maximum_defect_influence_distance = influence_cell_distance.second; -// defect_cell = influence_cell_distance.first; -// } -// } -// return {defect_cell, maximum_defect_influence_distance}; -// } - -} // namespace fiction - -#endif // FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp new file mode 100644 index 000000000..2b9343ebb --- /dev/null +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -0,0 +1,704 @@ +// +// Created by Jan Drewniok on 28.12.23. +// + +#ifndef FICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP +#define FICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP + +#include "fiction/algorithms/simulation/sidb/is_operational.hpp" +#include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" +#include "fiction/layouts/bounding_box.hpp" +#include "fiction/layouts/coordinates.hpp" +#include "fiction/technology/sidb_surface.hpp" +#include "fiction/types.hpp" +#include "fiction/utils/hash.hpp" +#include "fiction/utils/layout_utils.hpp" +#include "fiction/utils/phmap_utils.hpp" +#include "mockturtle/utils/stopwatch.hpp" + +namespace fiction +{ + +struct defect_operational_domain_params +{ + /** + * Parameters to simulate the influence of the atomic defect. + */ + maximum_defect_influence_distance_params defect_influence_params{}; + /** + * Parameters for the `is_operational` algorithm. + */ + is_operational_params is_operational_params{}; +}; +/** + * A defect operational domain defines the positions where a specific atomic defect may exist along with corresponding + * information indicating whether the SiDB layout remains logically operational. Logically operational implies that the + * layout's ground state aligns with a designated Boolean function at the layout's outputs for all feasible input + * combinations. This implementation assumes the presence of \f$ n \f$ BDL input wires and a single BDL output wire for + * a given layout. Any algorithm for computing the operational domain iterates through all \f$ 2^n \f$ input + * combinations, evaluating the layout's output behavior based on the specified Boolean function. The layout is + * classified as operational for a particular parameter combination only if its output behavior is correct across all + * input combinations. + */ +template +struct defect_influence_operational_domain +{ + locked_parallel_flat_hash_map operational_values{}; +}; +/** + * Statistics. + */ +struct defect_influence_operational_stats +{ + /** + * The total runtime of the operational domain computation. + */ + mockturtle::stopwatch<>::duration time_total{0}; + /** + * Number of simulator invocations. + */ + std::size_t num_simulator_invocations{0}; + /** + * Number of evaluated parameter combinations. + */ + std::size_t num_evaluated_defect_positions{0}; + /** + * Number of parameter combinations, for which the layout is operational. + */ + std::size_t num_operational_defect_positions{0}; + /** + * Number of parameter combinations, for which the layout is non-operational. + */ + std::size_t num_non_operational_defect_positions{0}; +}; + +namespace detail +{ +template +class defect_influence_impl +{ + public: + defect_influence_impl(const Lyt& lyt, const std::vector& tt, const defect_operational_domain_params& ps, + defect_influence_operational_stats& st) : + layout{lyt}, + truth_table{tt}, + params{ps}, + stats{st} + { + determine_nw_se_cells(); + } + + [[nodiscard]] defect_influence_operational_domain grid_search(const std::size_t& step_size) noexcept + { + mockturtle::stopwatch stop{stats.time_total}; + const auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); + + for (std::size_t i = 0; i < all_possible_defect_positions.size(); i += step_size) + { + if (std::abs(all_possible_defect_positions[i].x) % step_size == 0 && + std::abs(all_possible_defect_positions[i].y) % step_size == 0) + { + is_defect_position_operational(all_possible_defect_positions[i]); + } + } + + log_stats(); + + return defect_operational_domain; + } + + [[nodiscard]] defect_influence_operational_domain random_sampling(std::size_t samples) noexcept + { + mockturtle::stopwatch stop{stats.time_total}; + auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); + + std::random_device rd; + std::mt19937 gen(rd()); + + // Shuffle the vector using std::shuffle + std::shuffle(all_possible_defect_positions.begin(), all_possible_defect_positions.end(), gen); + + const auto min_iterations = std::min(all_possible_defect_positions.size(), samples); + + for (auto i = 0u; i < min_iterations; ++i) + { + is_defect_position_operational(all_possible_defect_positions[i]); + } + + log_stats(); + + return defect_operational_domain; + } + + [[nodiscard]] defect_influence_operational_domain contour_tracing(std::size_t samples) noexcept + { + mockturtle::stopwatch stop{stats.time_total}; + + const auto next_clockwise_point = [](std::vector& neighborhood, + const typename Lyt::cell& backtrack) noexcept -> typename Lyt::cell + { + assert(std::find(neighborhood.cbegin(), neighborhood.cend(), backtrack) != neighborhood.cend() && + "The backtrack point must be part of the neighborhood"); + + while (neighborhood.back() != backtrack) + { + std::rotate(neighborhood.begin(), neighborhood.begin() + 1, neighborhood.end()); + } + + return neighborhood.front(); + }; + + std::size_t number_of_random_start_positions = 0; + while (number_of_random_start_positions < samples) + { + + // first, perform random sampling to find an operational starting point + const auto non_operational_starting_point = find_operational_defect_position_at_the_top_left(); + + // if no operational point was found within the specified number of samples, return + if (!non_operational_starting_point.has_value()) + { + return defect_operational_domain; + } + + assert(layout.num_defects() == 0 && "defect is added defect"); + + // find an operational point on the contour starting from the randomly determined starting point + const auto contour_starting_point = + find_last_operational_defect_position_moving_right(*non_operational_starting_point); + + assert(layout.num_defects() == 0 && "more than one defect"); + + auto current_contour_point = contour_starting_point; + auto backtrack_point = current_contour_point.x == nw_cell.x ? + current_contour_point : + typename Lyt::cell{current_contour_point.x - 1, current_contour_point.y}; + + auto current_neighborhood = moore_neighborhood(current_contour_point); + auto next_point = current_contour_point == backtrack_point ? + current_neighborhood.front() : + next_clockwise_point(current_neighborhood, backtrack_point); + + uint64_t counter = 0; + bool contour_around_gate = false; + while (next_point != contour_starting_point) + { + counter++; + const auto operational_status = is_defect_position_operational(next_point); + if (next_point.x >= se_bb_layout.x) + { + contour_around_gate = true; + } + + assert(layout.num_defects() == 0 && "more than one defect"); + + if (operational_status == operational_status::NON_OPERATIONAL || !layout.is_empty_cell(next_point)) + { + backtrack_point = current_contour_point; + current_contour_point = next_point; + } + else + { + backtrack_point = next_point; + } + + current_neighborhood = moore_neighborhood(current_contour_point); + next_point = next_clockwise_point(current_neighborhood, backtrack_point); + } + number_of_random_start_positions++; + if (!contour_around_gate) + { + continue; + } + else + { + log_stats(); + + return defect_operational_domain; + } + } + log_stats(); + + return defect_operational_domain; + } + + private: + /** + * This function determines the northwest and southeast cells based on the gate layout and the additional scan area + * specified. + */ + void determine_nw_se_cells() noexcept + { + // bounding box around the given layout to have north-west and south-east cells. + const auto siqad_layout = convert_to_siqad_coordinates(layout); + bounding_box_2d bb{siqad_layout}; + + auto nw = siqad::to_fiction_coord(bb.get_min()); // north-west cell + auto se = siqad::to_fiction_coord(bb.get_max()); // south-east cell + + nw_bb_layout = nw; + se_bb_layout = se; + + // shift nw and se cell by the additional scanning area to cover an area that is larger than the gate area. + nw.x = nw.x - params.defect_influence_params.additional_scanning_area.first; + nw.y = nw.y - params.defect_influence_params.additional_scanning_area.second; + + se.x = se.x + params.defect_influence_params.additional_scanning_area.first; + se.y = se.y + params.defect_influence_params.additional_scanning_area.second; + + nw_cell = nw; + se_cell = se; + } + + [[nodiscard]] std::optional find_non_operational_defect_position_via_sidbs() noexcept + { + layout.foreach_cell( + [this](const auto& c) + { + auto c_copy = c; + c_copy.x = c.x - 1; + if (layout.is_empty_cell(c_copy)) + { + layout.assign_sidb_defect(c_copy, params.defect_influence_params.defect); + // determine the operational status + const auto operational_value = is_defect_position_operational(c_copy); + + layout.assign_sidb_defect(c_copy, sidb_defect{sidb_defect_type::NONE}); + + // if the parameter combination is operational, return its step values in x and y dimension + if (operational_value == operational_status::NON_OPERATIONAL) + { + return c_copy; + } + } + }); + return std::nullopt; + } + + /** + * This function aims to identify an operational defect position within the layout. It does so by selecting a defect + * position with the leftmost x-coordinate and a y-coordinate aligned with the layout's bounding box. + */ + [[nodiscard]] std::optional find_operational_defect_position_at_the_top_left() noexcept + { + auto starting_point = nw_cell; + std::random_device rd; + std::mt19937 gen(rd()); + // Create a distribution for generating random numbers within the specified range + std::uniform_int_distribution dist(nw_bb_layout.y, se_bb_layout.y); + starting_point.y = dist(gen); + layout.assign_sidb_defect(starting_point, params.defect_influence_params.defect); + // determine the operational status + const auto operational_value = is_defect_position_operational(starting_point); + layout.assign_sidb_defect(starting_point, sidb_defect{sidb_defect_type::NONE}); + + // if the parameter combination is operational, return its step values in x and y dimension + if (operational_value == operational_status::OPERATIONAL) + { + return starting_point; + } + + return std::nullopt; + } + + /** + * This function evaluates the operational status of the SiDB gate when a defect is placed at position `c`. + * + * @param c Position of the defect. + */ + operational_status is_defect_position_operational(const typename Lyt::cell& c) noexcept + { + // if the point has already been sampled, return the stored operational status + if (const auto op_value = has_already_been_sampled(c); op_value.has_value()) + { + return *op_value; + } + + const auto operational = [this, &c]() + { + defect_operational_domain.operational_values[c] = operational_status::OPERATIONAL; + + return operational_status::OPERATIONAL; + }; + + const auto non_operational = [this, &c]() + { + defect_operational_domain.operational_values[c] = operational_status::NON_OPERATIONAL; + + return operational_status::NON_OPERATIONAL; + }; + + // increment the number of evaluated parameter combinations + ++num_evaluated_defect_positions; + + if (!layout.is_empty_cell(c)) + { + return non_operational(); + } + + layout.assign_sidb_defect(c, params.defect_influence_params.defect); + const auto& [status, sim_calls] = is_operational(layout, truth_table, params.is_operational_params); + layout.assign_sidb_defect(c, sidb_defect{sidb_defect_type::NONE}); + num_simulator_invocations += sim_calls; + + if (status == operational_status::NON_OPERATIONAL) + { + return non_operational(); + } + + // if we made it here, the layout is operational + return operational(); + } + + /** + * This function verifies whether the layout has already been analyzed for the specified defect position `c`. + * + * @param c Position of the defect. + */ + [[nodiscard]] inline std::optional + has_already_been_sampled(const typename Lyt::cell& c) const noexcept + { + if (const auto it = defect_operational_domain.operational_values.find(c); + it != defect_operational_domain.operational_values.cend()) + { + return it->second; + } + + return std::nullopt; + } + + /** + * This function identifies the most recent operational defect position while traversing from left to right towards + * the SiDB gate. + * + * @param starting_defect_position The starting position of the defect, from which the traversal towards the right + * is conducted while maintaining gate operability. + * @return The most recent operational defect position. + */ + [[nodiscard]] typename Lyt::cell + find_last_operational_defect_position_moving_right(const typename Lyt::cell& starting_defect_position) noexcept + { + auto latest_operational_defect_position = starting_defect_position; + // layout.assign_sidb_defect(starting_defect_position, params.defect_influence_params.defect); + previous_defect_position = starting_defect_position; + + // move towards the left border of the parameter range + for (int64_t x = starting_defect_position.x; x <= se_bb_layout.x; x++) + { + previous_defect_position = current_defect_position; + current_defect_position = {x, starting_defect_position.y}; + + layout.assign_sidb_defect(current_defect_position, params.defect_influence_params.defect); + + const auto operational_status = is_defect_position_operational(current_defect_position); + + layout.assign_sidb_defect(current_defect_position, sidb_defect{sidb_defect_type::NONE}); + + if (operational_status == operational_status::OPERATIONAL) + { + latest_operational_defect_position = current_defect_position; + } + else + { + return previous_defect_position; + } + } + + return latest_operational_defect_position; + } + + /** + * Helper function that writes the the statistics of the defect operational domain computation to the statistics + * object. + */ + void log_stats() const noexcept + { + stats.num_simulator_invocations = num_simulator_invocations; + stats.num_evaluated_defect_positions = num_evaluated_defect_positions; + + for (const auto& [param_point, status] : defect_operational_domain.operational_values) + { + if (status == operational_status::OPERATIONAL) + { + ++stats.num_operational_defect_positions; + } + else + { + ++stats.num_non_operational_defect_positions; + } + } + } + + /** + * Computes the Moore neighborhood of a given cell within the SiDB layout. + * The Moore neighborhood consists of the eight cells surrounding the central cell + * in horizontal, vertical, and diagonal directions. + * + * @param c The cell for which the Moore neighborhood is computed. + * @return A vector containing the cells in the Moore neighborhood that are empty. + * If a cell is outside the layout boundaries or occupied, it is not included in the result. + */ + [[nodiscard]] std::vector moore_neighborhood(const typename Lyt::cell& c) const noexcept + { + std::vector neighbors{}; + neighbors.reserve(8); + + const auto& moore = c; + + const auto decr_x = (moore.x - 1 >= nw_cell.x) ? moore.x - 1 : moore.x; + const auto incr_x = (moore.x + 1 <= se_cell.x) ? moore.x + 1 : moore.x; + const auto decr_y = (moore.y - 1 >= nw_cell.y) ? moore.y - 1 : moore.y; + const auto incr_y = (moore.y + 1 <= se_cell.y) ? moore.y + 1 : moore.y; + + // add neighbors in clockwise direction + + // right + if (moore.x != incr_x) + { + if (layout.is_empty_cell({incr_x, moore.y})) + { + neighbors.emplace_back(incr_x, moore.y); + } + } + // lower-right + if (moore.x != incr_x && moore.y != decr_y) + { + if (layout.is_empty_cell({incr_x, decr_y})) + { + neighbors.emplace_back(incr_x, decr_y); + } + } + // down + if (moore.y != decr_y) + { + if (layout.is_empty_cell({moore.x, decr_y})) + { + neighbors.emplace_back(moore.x, decr_y); + } + } + // lower-left + if (moore.x != decr_x && moore.y != decr_y) + { + if (layout.is_empty_cell({decr_x, decr_y})) + { + neighbors.emplace_back(decr_x, decr_y); + } + } + // left + if (moore.x != decr_x) + { + if (layout.is_empty_cell({decr_x, moore.y})) + { + neighbors.emplace_back(decr_x, moore.y); + } + } + // upper-left + if (moore.x != decr_x && moore.y != incr_y) + { + if (layout.is_empty_cell({decr_x, incr_y})) + { + neighbors.emplace_back(decr_x, incr_y); + } + } + // up + if (moore.y != incr_y) + { + if (layout.is_empty_cell({moore.x, incr_y})) + { + neighbors.emplace_back(moore.x, incr_y); + } + } + // upper-right + if (moore.x != incr_x && moore.y != incr_y) + { + if (layout.is_empty_cell({incr_x, incr_y})) + { + neighbors.emplace_back(incr_x, incr_y); + } + } + + return neighbors; + }; + + /** + * The SiDB cell-level layout to investigate. + */ + sidb_surface layout{}; + /** + * The specification of the layout. + */ + const std::vector& truth_table; + /** + * The parameters for the operational domain computation. + */ + const defect_operational_domain_params& params; + /** + * North-west cell. + */ + typename Lyt::cell nw_cell{}; + /** + * The north-west bounding box of the layout. + */ + typename Lyt::cell nw_bb_layout{}; + /** + * South-east cell. + */ + typename Lyt::cell se_cell{}; + /** + * The south-east bounding box of the layout. + */ + typename Lyt::cell se_bb_layout{}; + /** + * The current defect position. + */ + typename Lyt::cell current_defect_position{}; + /** + * The previous defect position. + */ + typename Lyt::cell previous_defect_position{}; + /** + * The operational domain of the layout. + */ + defect_influence_operational_domain defect_operational_domain{}; + /** + * The statistics of the operational domain computation. + */ + defect_influence_operational_stats& stats; + /** + * Number of simulator invocations. + */ + std::atomic num_simulator_invocations{0}; + /** + * Number of evaluated defect positions. + */ + std::atomic num_evaluated_defect_positions{0}; +}; +} // namespace detail + +/** + * Computes the defect influence operational domain of the given SiDB cell-level layout. The defect influence + * operational domain is the set of all defect positions for which the layout is logically operational. Logical + * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed + * to be in the same order as the inputs of the truth table. + * + * // TODO + * + * @tparam Lyt SiDB cell-level layout type. + * @tparam TT Truth table type. + * @param lyt Layout to compute the defect influence operational domain for. + * @param spec Expected Boolean function of the layout given as a multi-output truth table. + * @param samples Number of samples to perform. + * @param params Defect influence operational domain computation parameters. + * @param stats Operational domain computation statistics. + * @return The (partial) defect influence operational domain of the layout. + */ +template +defect_influence_operational_domain +defect_influence_operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, std::size_t samples, + const defect_operational_domain_params& params = {}, + defect_influence_operational_stats* stats = nullptr) +{ + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(kitty::is_truth_table::value, "TT is not a truth table"); + static_assert(has_cube_coord_v || has_siqad_coord_v, "Lyt is not based on cube coordinates"); + + defect_influence_operational_stats st{}; + detail::defect_influence_impl p{lyt, spec, params, st}; + + const auto result = p.contour_tracing(samples); + + if (stats) + { + *stats = st; + } + + return result; +} + +/** + * Computes the defect influence operational domain of the given SiDB cell-level layout. The defect influence + * operational domain is the set of all defect positions for which the layout is logically operational. Logical + * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed + * to be in the same order as the inputs of the truth table. + * + * This algorithm uses a grid search to determine the defect influence operational domain. The grid search is performed + * by exhaustively sweeping all possible atomic defect positions in x and y dimensions. + * + * @tparam Lyt SiDB cell-level layout type. + * @tparam TT Truth table type. + * @param lyt Layout to compute the defect influence operational domain for. + * @param spec Expected Boolean function of the layout given as a multi-output truth table. + * @param params Defect influence operational domain computation parameters. + * @param stats Operational domain computation statistics. + * @return The defect influence operational domain of the layout. + */ +template +defect_influence_operational_domain +defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vector& spec, std::size_t step_size = 1, + const defect_operational_domain_params& params = {}, + defect_influence_operational_stats* stats = nullptr) +{ + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(kitty::is_truth_table::value, "TT is not a truth table"); + static_assert(has_cube_coord_v || has_siqad_coord_v, "Lyt is not based on cube coordinates"); + + defect_influence_operational_stats st{}; + detail::defect_influence_impl p{lyt, spec, params, st}; + + const auto result = p.grid_search(step_size); + + if (stats) + { + *stats = st; + } + + return result; +} + +/** + * Computes the defect influence operational domain of the given SiDB cell-level layout. The defect influence + * operational domain is the set of all defect positions for which the layout is logically operational. Logical + * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed + * to be in the same order as the inputs of the truth table. + * + * This algorithm uses random sampling to find a part of the defect influence operational domain that might not be + * complete. It performs a total of `samples` uniformly-distributed random samples within the a specified area. + * + * @tparam Lyt SiDB cell-level layout type. + * @tparam TT Truth table type. + * @param lyt Layout to compute the defect influence operational domain for. + * @param spec Expected Boolean function of the layout given as a multi-output truth table. + * @param samples Number of samples to perform. + * @param params Defect influence operational domain computation parameters. + * @param stats Operational domain computation statistics. + * @return The (partial) defect influence operational domain of the layout. + */ +template +defect_influence_operational_domain +defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::vector& spec, std::size_t samples, + const defect_operational_domain_params& params = {}, + defect_influence_operational_stats* stats = nullptr) +{ + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(kitty::is_truth_table::value, "TT is not a truth table"); + static_assert(has_cube_coord_v, "Lyt is not based on cube coordinates"); + + defect_influence_operational_stats st{}; + detail::defect_influence_impl p{lyt, spec, params, st}; + + const auto result = p.random_sampling(samples); + + if (stats) + { + *stats = st; + } + + return result; +} + +} // namespace fiction + +#endif // FICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP diff --git a/include/fiction/algorithms/simulation/sidb/is_operational.hpp b/include/fiction/algorithms/simulation/sidb/is_operational.hpp index 72f5ccbae..3b5665bb4 100644 --- a/include/fiction/algorithms/simulation/sidb/is_operational.hpp +++ b/include/fiction/algorithms/simulation/sidb/is_operational.hpp @@ -13,6 +13,9 @@ #include "fiction/algorithms/simulation/sidb/quicksim.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_engine.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" +#include "fiction/algorithms/simulation/sidb/sidb_simulation_result.hpp" +#include "fiction/technology/cell_technologies.hpp" +#include "fiction/technology/sidb_charge_state.hpp" #include "fiction/traits.hpp" #include "fiction/types.hpp" #include "fiction/utils/truth_table_utils.hpp" @@ -299,6 +302,7 @@ class is_operational_impl * Number of simulator invocations. */ std::size_t simulator_invocations{0}; + /** * This function conducts physical simulation of the given layout (gate layout with certain input combination). The * simulation results are stored in the `sim_result` variable. diff --git a/include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp b/include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp deleted file mode 100644 index 0a3651732..000000000 --- a/include/fiction/algorithms/simulation/sidb/max_min_avoidance_distance.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// -// Created by Jan Drewniok on 07.02.24. -// - -#ifndef FICTION_MINIMUM_DISTANCE_DEFECT_HPP -#define FICTION_MINIMUM_DISTANCE_DEFECT_HPP - -#include "fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp" -#include "fiction/layouts/cell_level_layout.hpp" -#include "fiction/algorithms/simulation/sidb/operational_domain.hpp" -#include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" -#include "fiction/algorithms/simulation/sidb/operational_domain.hpp" - -namespace fiction -{ -template -[[nodiscard]] double max_min_avoidance_distance(const Lyt& lyt, - const defect_operational_domain& defect_opdomain) noexcept -{ - double max_distance = 0; - for (const auto& val : defect_opdomain.operational_values) - { - if (val.second == operational_status::OPERATIONAL) - { - continue; - } - auto min_distance = std::numeric_limits::max(); - lyt.foreach_cell( - [&val, &min_distance, &lyt](const auto& c) - { - if (sidb_nanometer_distance(lyt, c, val.first) < min_distance) - { - min_distance = sidb_nanometer_distance(lyt, c, val.first); - } - }); - if (min_distance > max_distance) - { - max_distance = min_distance; - } - } - return max_distance; -} -} // namespace fiction - -#endif // FICTION_MINIMUM_DISTANCE_DEFECT_HPP diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 3d76bf9a8..d2d179472 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -36,7 +36,7 @@ namespace fiction { /** * Physical simulation parameters. */ - sidb_simulation_parameters physical_params{}; + sidb_simulation_parameters simulation_parameters{}; /** * The pair describes the width and height of the area around the gate, which is * also used to place defects. @@ -85,14 +85,14 @@ namespace fiction { std::mutex mutex; const quickexact_params> params_defect{ - params.physical_params, + params.simulation_parameters, quickexact_params>::automatic_base_number_detection::OFF}; double avoidance_distance{0}; coordinate max_defect_position{}; const auto simulation_results = - quickexact(layout, quickexact_params{params.physical_params, + quickexact(layout, quickexact_params{params.simulation_parameters, quickexact_params::automatic_base_number_detection::OFF}); const auto min_energy = minimum_energy(simulation_results.charge_distributions.cbegin(), diff --git a/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp new file mode 100644 index 000000000..80858546b --- /dev/null +++ b/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp @@ -0,0 +1,56 @@ +// +// Created by Jan Drewniok on 07.02.24. +// + +#ifndef FICTION_MAXIMUM_MINIMUM_DEFECT_INFLUENCE_DISTANCE_HPP +#define FICTION_MAXIMUM_MINIMUM_DEFECT_INFLUENCE_DISTANCE_HPP + +#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" +#include "fiction/algorithms/simulation/sidb/operational_domain.hpp" +#include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" +#include "fiction/layouts/cell_level_layout.hpp" + +namespace fiction +{ +/** + * Calculates the maximum minimum influence distance of a given gate layout by a specified atomic defect. + * This function requires both the defect operational domain and the layout as input. For each non-operational + * defect position, it computes the minimum distance to the layout. The maximum value among these minimal distances + * is then returned. + * + * @tparam Lyt Type representing the SiDB cell-level layout. + * @param lyt The cell-level layout for which the defect operational domain was computed. + * @param defect_opdomain The defect operational domain associated with the layout. + * @return The maximum minimum defect influence distance. + */ +template +[[nodiscard]] double +maximum_minimum_defect_influence_distance(const Lyt& lyt, + const defect_influence_operational_domain& defect_opdomain) noexcept +{ + double max_distance = 0; + for (const auto& val : defect_opdomain.operational_values) + { + if (val.second == operational_status::OPERATIONAL) + { + continue; + } + auto min_distance = std::numeric_limits::infinity(); + lyt.foreach_cell( + [&val, &min_distance, &lyt](const auto& c) + { + if (sidb_nanometer_distance(lyt, c, val.first) < min_distance) + { + min_distance = sidb_nanometer_distance(lyt, c, val.first); + } + }); + if (min_distance > max_distance) + { + max_distance = min_distance; + } + } + return max_distance; +} +} // namespace fiction + +#endif // FICTION_MAXIMUM_MINIMUM_DEFECT_INFLUENCE_DISTANCE_HPP diff --git a/include/fiction/io/write_defect_operational_domain.hpp b/include/fiction/io/write_defect_operational_domain.hpp index 6c3f509c0..88d545545 100644 --- a/include/fiction/io/write_defect_operational_domain.hpp +++ b/include/fiction/io/write_defect_operational_domain.hpp @@ -6,7 +6,7 @@ #define FICTION_WRITE_OPERATIONAL_DOMAIN_HPP #include "fiction/algorithms/simulation/sidb/is_operational.hpp" -#include "fiction/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.hpp" +#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" #include "fiction/io/csv_writer.hpp" #include @@ -50,7 +50,7 @@ struct write_operational_domain_params * empty `write_operational_domain_params` object, which provides standard tags. */ template -inline void write_operational_domain(const defect_operational_domain& opdom, std::ostream& os, +inline void write_operational_domain(const defect_influence_operational_domain& opdom, std::ostream& os, const write_operational_domain_params& params = {}) { csv_writer writer{os}; @@ -82,7 +82,7 @@ inline void write_operational_domain(const defect_operational_domain& opdom * empty `write_operational_domain_params` object, which provides standard tags. */ template -inline void write_operational_domain(const defect_operational_domain& opdom, const std::string_view& filename, +inline void write_operational_domain(const defect_influence_operational_domain& opdom, const std::string_view& filename, const write_operational_domain_params& params = {}) { std::ofstream os{filename.data(), std::ofstream::out}; diff --git a/test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp b/test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp deleted file mode 100644 index 06e360c5a..000000000 --- a/test/algorithms/simulation/sidb/defect_influence_of_sidb_gate_contour_tracing.cpp +++ /dev/null @@ -1,206 +0,0 @@ -// -// Created by Jan Drewniok on 07.02.24. -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace fiction; - -//TEST_CASE("Bestagon AND Gate influence distance function", "[defect-influence-of-sidb-gate-contour-tracing]") -//{ -// sidb_cell_clk_lyt_siqad lyt{}; -// -// lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); -// lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); -// -// lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); -// lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); -// -// lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); -// -// lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); -// -// lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); -// lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); -// -// lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); -// -// const auto cube_lyt = convert_to_fiction_coordinates(lyt); -// -// const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, 5.6, 5.0}; -// const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{2, -0.32}, {20, 20}}; -// const defect_influence_params params{sim_params, is_operational_params{sim_params.physical_params}}; -// -// SECTION("input 00") -// { -// defect_influence_stats stats{}; -// const auto defect_influence_domain = -// defect_influence_of_sidb_gate_contour_tracing(cube_lyt, std::vector{create_and_tt()}, 100, params, &stats); -// -// write_operational_domain_params write_params{}; -// write_params.operational_tag = "1"; -// write_params.non_operational_tag = "0"; -// write_operational_domain(defect_influence_domain, -// "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", -// write_params); -// } -// SECTION("input 01") {} -// SECTION("input 10") {} -// SECTION("input 11") {} -//} - -//TEST_CASE("novel designed AND Gate influence distance function", "[defect-influence-of-sidb-gate-contour-tracing]") -//{ -// sidb_cell_clk_lyt_siqad lyt{}; -// -// lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); -// lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); -// -// lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); -// lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); -// -// -// lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); -// -// lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); -// -// lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); -// -// // canvas SiDBs -// // ------------- -// lyt.assign_cell_type({21, 7, 1}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({17, 9, 0}, sidb_technology::cell_type::NORMAL); -// -// lyt.assign_cell_type({19, 10, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({20, 11, 0}, sidb_technology::cell_type::NORMAL); -// // ------------- -// -// -// lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); -// lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); -// lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); -// -// lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); -// -// const auto cube_lyt = convert_to_fiction_coordinates(lyt); -// -// const sidb_defect sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}; -// const maximum_defect_influence_distance_params sim_params{sidb_defect, sidb_simulation_parameters{2, -0.32}, {20, 20}}; -// const defect_influence_params params{sim_params, is_operational_params{sim_params.physical_params}}; -// -// SECTION("input 00") -// { -// defect_influence_stats stats{}; -// const auto defect_influence_domain = -// defect_influence_of_sidb_gate_contour_tracing(cube_lyt, std::vector{create_and_tt()}, 1000, params, &stats); -// std::cout << max_min_avoidance_distance(cube_lyt, defect_influence_domain) << std::endl; -// -// write_operational_domain_params write_params{}; -// write_params.operational_tag = "1"; -// write_params.non_operational_tag = "0"; -// write_operational_domain(defect_influence_domain, -// "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", -// write_params); -// } -// SECTION("input 01") {} -// SECTION("input 10") {} -// SECTION("input 11") {} -//} - -TEST_CASE("novel designed AND Gate influence distance function which fails", "[defect-influence-of-sidb-gate-contour-tracing]") -{ - sidb_cell_clk_lyt_siqad lyt{}; - - lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - - - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - - // canvas SiDBs - // ------------- - lyt.assign_cell_type({19, 7, 1}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 9, 1}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 11, 0}, sidb_technology::cell_type::NORMAL); - // ------------- - - - lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - - const auto cube_lyt = convert_to_fiction_coordinates(lyt); - - const sidb_defect sidb_defect{sidb_defect_type::UNKNOWN, -1, 9.7, 2.1}; - const maximum_defect_influence_distance_params sim_params{sidb_defect, sidb_simulation_parameters{2, -0.32}, {50, 20}}; - const defect_influence_params params{sim_params, is_operational_params{sim_params.physical_params}}; - - SECTION("input 00") - { - defect_influence_stats stats{}; - const auto defect_influence_domain = - defect_influence_of_sidb_gate_contour_tracing(cube_lyt, std::vector{create_nand_tt()}, 100, params, &stats); - std::cout << max_min_avoidance_distance(cube_lyt, defect_influence_domain) << std::endl; - - write_operational_domain_params write_params{}; - write_params.operational_tag = "1"; - write_params.non_operational_tag = "0"; - write_operational_domain(defect_influence_domain, - "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", - write_params); - } - SECTION("input 01") {} - SECTION("input 10") {} - SECTION("input 11") {} -} diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp new file mode 100644 index 000000000..1418ddf69 --- /dev/null +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -0,0 +1,117 @@ +// +// Created by Jan Drewniok on 07.02.24. +// + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace fiction; + +TEST_CASE("novel designed AND Gate influence distance function which fails again", + "[defect-influence-of-sidb-gate-contour-tracing]") +{ + + // TODO Use SiQAD gate + sidb_cell_clk_lyt_siqad lyt{}; + + lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); + + lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); + + lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); + + // canvas SiDBs + // ------------- + lyt.assign_cell_type({17, 8, 1}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({21, 8, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({18, 11, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({20, 11, 0}, sidb_technology::cell_type::NORMAL); + // ------------- + + lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); + lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); + + lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + + const auto cube_lyt = convert_to_fiction_coordinates(lyt); + + const sidb_defect sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}; + // const sidb_defect sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}; + const maximum_defect_influence_distance_params sim_params{sidb_defect, sidb_simulation_parameters{2, -0.32}}; + defect_operational_domain_params params{sim_params, is_operational_params{sim_params.simulation_parameters}}; + + SECTION("Grid Search") + { + params.defect_influence_params.additional_scanning_area = {10, 10}; + defect_influence_operational_stats stats{}; + const auto defect_influence_domain = defect_influence_operational_domain_grid_search( + cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); + CHECK_THAT(maximum_minimum_defect_influence_distance(cube_lyt, defect_influence_domain), + Catch::Matchers::WithinAbs(11.6138152646, physical_constants::POP_STABILITY_ERR)); + + write_operational_domain_params write_params{}; + write_params.operational_tag = "1"; + write_params.non_operational_tag = "0"; + write_operational_domain(defect_influence_domain, + "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", + write_params); + } + SECTION("Random Sampling") + { + params.defect_influence_params.additional_scanning_area = {0, 0}; + defect_influence_operational_stats stats{}; + const auto defect_influence_domain = defect_influence_operational_domain_random_sampling( + cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); + CHECK(defect_influence_domain.operational_values.size() == 100); + CHECK(maximum_minimum_defect_influence_distance(cube_lyt, defect_influence_domain) < 11.61); + + write_operational_domain_params write_params{}; + write_params.operational_tag = "1"; + write_params.non_operational_tag = "0"; + write_operational_domain(defect_influence_domain, + "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", + write_params); + } + SECTION("Contour Tracing") + { + params.defect_influence_params.additional_scanning_area = {20, 20}; + defect_influence_operational_stats stats{}; + const auto defect_influence_domain = defect_influence_operational_domain_contour_tracing( + cube_lyt, std::vector{create_or_tt()}, 10, params, &stats); + CHECK(maximum_minimum_defect_influence_distance(cube_lyt, defect_influence_domain) > 11.61); + + write_operational_domain_params write_params{}; + write_params.operational_tag = "1"; + write_params.non_operational_tag = "0"; + write_operational_domain(defect_influence_domain, + "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", + write_params); + } +} diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp index b31a238e8..9814a1060 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp @@ -198,18 +198,9 @@ TEST_CASE("Bestagon AND Gate influence distance function", "[maximum-defect-infl maximum_defect_influence_distance_stats stats{}; const auto [defect_pos, distance] = maximum_defect_influence_position_and_distance(lyt, sim_params, &stats); std::cout << fmt::format("{} {} {} {}", defect_pos.x, defect_pos.y, defect_pos.z, distance) << std::endl; - CHECK(mockturtle::to_seconds(stats.time_total) > 1.0); - } - SECTION("input 01") - { - - } - SECTION("input 10") - { - - } - SECTION("input 11") - { - + CHECK(mockturtle::to_seconds(stats.time_total) > 0.0); } + SECTION("input 01") {} + SECTION("input 10") {} + SECTION("input 11") {} } From e2396ff215f4dfe014f6a7eaffe769aad9ad9270 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 26 Apr 2024 15:25:27 +0200 Subject: [PATCH 040/221] :art: All unit tests run successfully. --- experiments/gate_generator_with_sa.cpp | 73 +- .../optimization/simulated_annealing.hpp | 10 +- .../physical_design/design_sidb_gates.hpp | 232 +++--- .../assess_physical_population_stability.hpp | 681 +++++++++--------- .../defect_influence_operational_domain.hpp | 4 +- ...defect_influence_position_and_distance.hpp | 340 +++++---- ...nce_position_and_distance_of_sidb_gate.hpp | 10 +- ...imum_minimum_defect_influence_distance.hpp | 6 +- .../simulation/sidb/operational_domain.hpp | 4 +- include/fiction/utils/math_utils.hpp | 24 + .../physical_design/design_sidb_gates.cpp | 138 ++-- .../assess_physical_population_stability.cpp | 420 ++++------- ...defect_influence_position_and_distance.cpp | 50 -- .../simulation/sidb/operational_domain.cpp | 54 +- test/utils/blueprints/layout_blueprints.hpp | 49 ++ test/utils/math_utils.cpp | 22 + 16 files changed, 1046 insertions(+), 1071 deletions(-) diff --git a/experiments/gate_generator_with_sa.cpp b/experiments/gate_generator_with_sa.cpp index 3e2de29db..8c240b325 100644 --- a/experiments/gate_generator_with_sa.cpp +++ b/experiments/gate_generator_with_sa.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -20,10 +21,9 @@ using namespace fiction; int main() // NOLINT { - const auto skeleton = - read_sqd_layout( - "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/" - "skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd"); + const auto skeleton = read_sqd_layout( + "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/" + "skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd"); // toffoli // const design_sidb_gates_params params{ @@ -34,13 +34,11 @@ int main() // NOLINT // sidb_simulation_engine::QUICKEXACT}; design_sidb_gates_params params{ - sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params::design_sidb_gates_mode::SIMANNEAL, - {{17, 7, 0}, {21, 11, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT}; - - params.maximal_random_solutions = 100; + sidb_simulation_parameters{2, -0.32}, + {{17, 7, 0}, {21, 11, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT, + 100}; // const auto truth_tables = std::vector>{ // std::vector{create_and_tt()}, std::vector{create_xor_tt()}, std::vector{create_or_tt()}, @@ -53,52 +51,59 @@ int main() // NOLINT // const auto truth_tables // std::vector>{std::vector{create_id_tt()}, std::vector{create_not_tt()}}; - const critical_temperature_params ct_params{sidb_simulation_parameters{ - 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; + const critical_temperature_params ct_params{sidb_simulation_parameters{2, params.simulation_parameters.mu_minus, + params.simulation_parameters.epsilon_r, + params.simulation_parameters.lambda_tf}}; - operational_domain_params op_domain_params{sidb_simulation_parameters{ - 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; - op_domain_params.x_min = 4.0; - op_domain_params.x_max = 6; + operational_domain_params op_domain_params{sidb_simulation_parameters{2, params.simulation_parameters.mu_minus, + params.simulation_parameters.epsilon_r, + params.simulation_parameters.lambda_tf}}; + op_domain_params.x_min = 4.0; + op_domain_params.x_max = 6; op_domain_params.x_step = 0.2; - op_domain_params.y_min = 4.0; - op_domain_params.y_max = 6; + op_domain_params.y_min = 4.0; + op_domain_params.y_max = 6; op_domain_params.y_step = 0.2; - params.simanneal_params.ct_params = ct_params; - params.simanneal_params.op_params = op_domain_params; + design_sidb_gates_sa_params sa_params{}; + + sa_params.ct_params = ct_params; + sa_params.op_params = op_domain_params; uint64_t truth_counter = 0; - for (const auto &truth: truth_tables) { + for (const auto& truth : truth_tables) + { std::cout << fmt::format("{} truth table", truth_counter) << std::endl; - for (auto i = 4u; i < 5; i++) { + for (auto i = 3u; i < 4; i++) + { double total_time = 0; - double net_cost = 0; + double net_cost = 0; std::cout << fmt::format("{} placed SiDBs", i) << std::endl; - std::vector all_gate{}; - for (auto t = 0u; t < 1; t++) { + sidb_cell_clk_lyt_siqad gate{}; + for (auto t = 0u; t < 1; t++) + { params.number_of_sidbs = i; design_sidb_gates_stats stats{}; - all_gate = design_sidb_gates(skeleton, truth, params, &stats); + gate = design_sidb_gates_metric_driven_simulated_annealing( + skeleton, truth, params, sa_params, &stats); net_cost += stats.cost_of_gate; total_time += mockturtle::to_seconds(stats.time_total); } - const is_operational_params params_is_operational{params.phys_params, params.sim_engine}; - auto result = - is_operational(all_gate[0], truth, params_is_operational).first == operational_status::OPERATIONAL ? - "operational" : - "non_operational"; + const is_operational_params params_is_operational{params.simulation_parameters, params.sim_engine}; + auto result = is_operational(gate, truth, params_is_operational).first == operational_status::OPERATIONAL ? + "operational\n" : + "non_operational\n"; std::cout << result; std::cout << fmt::format("average runtime: {}", total_time / 1) << std::endl; std::cout << fmt::format("net cost: {}", net_cost / 1) << std::endl; write_sqd_layout( - all_gate[0], "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/gate_design_sa/" + - std::to_string(truth_counter) + ".sqd"); + gate, "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/gate_design_sa/" + + std::to_string(truth_counter) + ".sqd"); } std::cout << "-----------" << std::endl; diff --git a/include/fiction/algorithms/optimization/simulated_annealing.hpp b/include/fiction/algorithms/optimization/simulated_annealing.hpp index 2cf0a7251..5979f7169 100644 --- a/include/fiction/algorithms/optimization/simulated_annealing.hpp +++ b/include/fiction/algorithms/optimization/simulated_annealing.hpp @@ -5,6 +5,7 @@ #ifndef FICTION_SIMULATED_ANNEALING_HPP #define FICTION_SIMULATED_ANNEALING_HPP +#include "fiction/traits.hpp" #include "fiction/utils/execution_utils.hpp" #include @@ -118,7 +119,14 @@ simulated_annealing(const State& init_state, const double init_temp, const doubl if (new_cost < best_cost) { - best_state = new_state; + if constexpr (is_cell_level_layout_v) + { + best_state = new_state.clone(); + } + else + { + best_state = new_state; + } best_cost = new_cost; current_state = std::move(new_state); current_cost = std::move(new_cost); diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 5084c3797..22a5748fe 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -8,6 +8,7 @@ #include "fiction/algorithms/optimization/simulated_annealing.hpp" #include "fiction/algorithms/simulation/sidb/critical_temperature.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" +#include "fiction/algorithms/simulation/sidb/operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/random_sidb_layout_generator.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_engine.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" @@ -17,8 +18,8 @@ #include "fiction/utils/math_utils.hpp" #include -#include #include +#include #include #include @@ -36,32 +37,65 @@ namespace fiction { +/** + * Parameters for Simulated Annealing-based gate design. + */ struct design_sidb_gates_sa_params { /** - * Temperature schedule type. + * Type of temperature schedule used in Simulated Annealing. + * Possible values are GEOMETRIC or LINEAR. */ temperature_schedule schedule{temperature_schedule::GEOMETRIC}; /** - * Initial temperature. + * Initial temperature for Simulated Annealing. */ - double initial_temperature{10000}; + double initial_temperature{1000}; /** - * Final temperature. + * Final temperature for Simulated Annealing. */ - double final_temperature{0.001}; + double final_temperature{0.1}; /** - * Number of iterations per temperature. + * Number of iterations per temperature in Simulated Annealing. */ std::size_t number_of_cycles{10}; /** - * Number of parallel runs to pick the overall best result from. + * Parameters for simulating the critical temperature. */ - std::size_t number_of_instances{100}; - critical_temperature_params ct_params{}; - + /** + * Parameters for simulating the operational domain. + */ operational_domain_params op_params{}; + /** + * Weight assigned to the critical temperature in the overall cost function. + * A negative value indicates that this weight is not used. + */ + double weight_temperature = -1.0; + /** + * Weight assigned to the operational domain in the overall cost function. + * A negative value indicates that this weight is not used. + */ + double weight_operational_domain = -1.0; + /** + * Weight assigned to the non-operational behavior in the overall cost function. + * This weight affects the cost function when the design is non-operational. + */ + double weight_non_operational = 10; +}; +/** + * Selector for the available design approaches. + */ +enum class design_sidb_gates_mode +{ + /** + * All gate layouts are designed exhaustively. + */ + EXHAUSTIVE, + /** + * Gate layouts are designed randomly. + */ + RANDOM }; /** * This struct contains parameters and settings to design SiDB gates. @@ -72,36 +106,14 @@ struct design_sidb_gates_sa_params template struct design_sidb_gates_params { - /** - * Selector for the available design approaches. - */ - enum class design_sidb_gates_mode - { - /** - * All gate layouts are designed exhaustively. - */ - EXHAUSTIVE, - /** - * Gate layouts are designed randomly. - */ - RANDOM, - /** - * Gate layouts are designed with Simulated Annealing. - */ - SIMANNEAL - }; /** * All Parameters for physical SiDB simulations. */ sidb_simulation_parameters simulation_parameters{}; - /** - * Gate design mode. - */ - design_sidb_gates_mode design_mode = design_sidb_gates_mode::SIMANNEAL; /** * Canvas spanned by the northwest and southeast cell. */ - std::pair canvas{}; + std::pair, cell> canvas{}; /** * Number of SiDBs placed in the canvas to create a working gate. */ @@ -110,10 +122,6 @@ struct design_sidb_gates_params * The simulation engine to be used for the operational domain computation. */ sidb_simulation_engine sim_engine{sidb_simulation_engine::QUICKEXACT}; - /** - * The design parameters used when designing with Simulated Annealing. - */ - design_sidb_gates_sa_params simanneal_params{}; /** * The number of gate implementations found before the random design process is stopped. */ @@ -153,10 +161,10 @@ class design_sidb_gates_impl truth_table{tt}, params{ps}, stats{st}, - all_cells_in_canvas{all_coordinates_in_spanned_area(params.canvas.first, params.canvas.second)} + all_sidbs_in_canvas{all_coordinates_in_spanned_area(params.canvas.first, params.canvas.second)} { // Use std::uniform_int_distribution to generate a random index - random_canvas_cell_functor = std::uniform_int_distribution(0, all_cells_in_canvas.size() - 1); + random_canvas_cell_functor = std::uniform_int_distribution(0, all_sidbs_in_canvas.size() - 1); random_canvas_sidb_functor = std::uniform_int_distribution(0, params.number_of_sidbs - 1); } @@ -174,7 +182,7 @@ class design_sidb_gates_impl const is_operational_params params_is_operational{params.simulation_parameters, params.sim_engine}; const auto all_combinations = determine_all_combinations_of_distributing_k_entities_on_n_positions( - params.number_of_sidbs, static_cast(all_cells_in_canvas.size())); + params.number_of_sidbs, static_cast(all_sidbs_in_canvas.size())); std::vector designed_gate_layouts = {}; @@ -279,77 +287,63 @@ class design_sidb_gates_impl * * @return A vector of designed SiDB gate layouts. */ - [[nodiscard]] std::vector run_sa_design() noexcept + [[nodiscard]] Lyt run_sa_design(const design_sidb_gates_sa_params& sa_params) noexcept { - mockturtle::stopwatch stop{stats.time_total}; - generate_random_sidb_layout_params parameter{ + mockturtle::stopwatch stop{stats.time_total}; + generate_random_sidb_layout_params> parameter{ params.canvas, params.number_of_sidbs, - generate_random_sidb_layout_params::positive_charges::FORBIDDEN}; - const is_operational_params params_is_operational{params.phys_params, params.sim_engine}; + generate_random_sidb_layout_params>::positive_charges::FORBIDDEN}; + const is_operational_params params_is_operational{params.simulation_parameters, params.sim_engine}; auto initial_lyt = generate_random_sidb_layout(skeleton_layout, parameter); - const auto temperature_schedule = params.simanneal_params.schedule == temperature_schedule::LINEAR ? + const auto temperature_schedule = sa_params.schedule == temperature_schedule::LINEAR ? linear_temperature_schedule : geometric_temperature_schedule; canvas_sidbs = determine_canvas_sidbs(initial_lyt); - auto [optimized_placement, optimized_net_cost] = simulated_annealing( - initial_lyt, params.simanneal_params.initial_temperature, params.simanneal_params.final_temperature, - params.simanneal_params.number_of_cycles, + auto [optimized_gate_design, optimized_net_cost] = simulated_annealing( + initial_lyt, sa_params.initial_temperature, sa_params.final_temperature, sa_params.number_of_cycles, [&, this](const auto& lyt) { const auto logic_cost = (is_operational(lyt, truth_table, params_is_operational).first == operational_status::OPERATIONAL) ? 0 : - 10; + sa_params.weight_non_operational; double temp_cost = 0; double opo_cost = 0; if (logic_cost == 0) { - temp_cost = - -((critical_temperature_gate_based(lyt, truth_table, params.simanneal_params.ct_params)) / - params.simanneal_params.ct_params.max_temperature); - operational_domain_stats stats_op{}; - const auto op_domain = operational_domain_flood_fill( - lyt, truth_table, 0, params.simanneal_params.op_params, - operational_domain::parameter_point{params.phys_params.epsilon_r, params.phys_params.lambda_tf}, - &stats_op); - opo_cost = -stats_op.percentual_operational_area; + if (sa_params.weight_temperature != 0.0) + { + temp_cost = ((critical_temperature_gate_based(lyt, truth_table, sa_params.ct_params)) / + sa_params.ct_params.max_temperature); + } + if (sa_params.weight_operational_domain != 0.0) + { + operational_domain_stats stats_op{}; + const auto op_domain = operational_domain_flood_fill( + lyt, truth_table, 0, sa_params.op_params, + operational_domain::parameter_point{params.simulation_parameters.epsilon_r, + params.simulation_parameters.lambda_tf}, + &stats_op); + opo_cost = stats_op.percentual_operational_area; + } } - // if (logic_cost + temp_cost + opo_cost < -0.5) { - // std::cout << fmt::format("cost: {}", - // static_cast(logic_cost + temp_cost + - // opo_cost)) - // << std::endl; - // } - return static_cast(logic_cost + temp_cost + opo_cost); + return cost_function_chi({logic_cost, temp_cost, opo_cost}, + {sa_params.weight_non_operational, sa_params.weight_temperature, + sa_params.weight_operational_domain}); }, temperature_schedule, [&](auto lyt) { - // print_layout(lyt); const auto lyt_swap = move_sidb(lyt); - // const auto cost_logic = - // static_cast(number_of_operational_input_combinations( - // lyt_swap, truth_table, skeleton_layout, params_is_operational, - // params.canvas)); - // std::cout << fmt::format("cost logic: {}", - // cost_logic) - // << std::endl; - // std::cout << fmt::format( - // "cost temp: {}", - // static_cast( - // (400 - critical_temperature_gate_based(lyt_swap, truth_table, - // ct_params)) / 400)) - // << std::endl; return lyt_swap; }); - std::cout << fmt::format("final cost: {}", optimized_net_cost) << std::endl; stats.cost_of_gate = optimized_net_cost; - return {optimized_placement}; + return optimized_gate_design; } private: @@ -373,7 +367,7 @@ class design_sidb_gates_impl /** * All cells within the canvas. */ - const std::vector all_cells_in_canvas; + const std::vector all_sidbs_in_canvas; /** * All SiDBs within the canvas. */ @@ -404,8 +398,8 @@ class design_sidb_gates_impl lyt.foreach_cell( [&](const auto& cell) { - if (std::find(all_cells_in_canvas.begin(), all_cells_in_canvas.end(), cell) != - all_cells_in_canvas.end()) + if (std::find(all_sidbs_in_canvas.begin(), all_sidbs_in_canvas.end(), cell) != + all_sidbs_in_canvas.end()) { placed_canvas_sidbs.emplace_back(cell); } @@ -417,7 +411,7 @@ class design_sidb_gates_impl { const auto random_index = random_canvas_cell_functor(generator); const auto random_index_replace = random_canvas_sidb_functor(generator); - const auto random_cell = all_cells_in_canvas[random_index]; + const auto random_cell = all_sidbs_in_canvas[random_index]; const auto replace_sidb = canvas_sidbs[random_index_replace]; // cell has to be empty @@ -478,11 +472,11 @@ class design_sidb_gates_impl for (const auto i : cell_indices) { - assert(i < all_cells_in_canvas.size() && "cell indices are out-of-range"); + assert(i < all_sidbs_in_canvas.size() && "cell indices are out-of-range"); - if (lyt_copy.get_cell_type(all_cells_in_canvas[i]) == sidb_technology::cell_type::EMPTY) + if (lyt_copy.get_cell_type(all_sidbs_in_canvas[i]) == sidb_technology::cell_type::EMPTY) { - lyt_copy.assign_cell_type(all_cells_in_canvas[i], sidb_technology::cell_type::NORMAL); + lyt_copy.assign_cell_type(all_sidbs_in_canvas[i], sidb_technology::cell_type::NORMAL); } } @@ -520,9 +514,10 @@ class design_sidb_gates_impl * @return A vector of designed SiDB gate layouts. */ template -[[nodiscard]] std::vector design_sidb_gates(const Lyt& skeleton, const std::vector& spec, - const design_sidb_gates_params& params = {}, - design_sidb_gates_stats* pst = nullptr) noexcept +[[nodiscard]] std::vector +design_sidb_gates(const Lyt& skeleton, const std::vector& spec, const design_sidb_gates_params& params = {}, + design_sidb_gates_mode design_mode = design_sidb_gates_mode::EXHAUSTIVE, + design_sidb_gates_stats* pst = nullptr) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -542,18 +537,61 @@ template std::vector result{}; - if (params.design_mode == design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE) + if (design_mode == design_sidb_gates_mode::EXHAUSTIVE) { result = p.run_exhaustive_design(); } - else if (params.design_mode == design_sidb_gates_params::design_sidb_gates_mode::RANDOM) + else { result = p.run_random_design(params.maximal_random_solutions); } - else + if (pst) { - result = p.run_sa_design(); + *pst = st; } + return result; +} + +/** + * Designs SiDB gates using metric-driven simulated annealing. + * + * This function designs SiDB gates based on a given layout skeleton, a set of truth tables, and specified parameters + * for gate design and simulated annealing. The function employs a metric-driven approach to optimize gate placement + * and configuration, utilizing simulated annealing to explore the solution space. + * + * * @tparam Lyt SiDB cell-level layout type. + * @tparam TT The type of the truth table specifying the gate behavior. + * @param skeleton The skeleton layout used as a starting point for gate design. + * @param spec Expected Boolean function of the layout given as a multi-output truth table. + * @param params The parameters for SiDB gate design. + * @param sa_params The parameters for simulated annealing. + * @param pst Pointer to a statistics object to store the design statistics. + * @return The designed layout with SiDB gates. + */ +template +[[nodiscard]] Lyt design_sidb_gates_metric_driven_simulated_annealing(const Lyt& skeleton, const std::vector& spec, + const design_sidb_gates_params& params, + const design_sidb_gates_sa_params& sa_params, + design_sidb_gates_stats* pst = nullptr) noexcept +{ + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(kitty::is_truth_table::value, "TT is not a truth table"); + static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); + + assert(skeleton.num_pis() > 0 && "skeleton needs input cells"); + assert(skeleton.num_pos() > 0 && "skeleton needs output cells"); + + assert(!spec.empty()); + // all elements in tts must have the same number of variables + assert(std::adjacent_find(spec.begin(), spec.end(), + [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.end()); + + design_sidb_gates_stats st{}; + detail::design_sidb_gates_impl p{skeleton, spec, params, st}; + + const auto result = p.run_sa_design(sa_params); + if (pst) { *pst = st; diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 7a43c016b..4b9041aa1 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -8,46 +8,44 @@ #include "fiction/algorithms/simulation/sidb/convert_potential_to_distance.hpp" #include "fiction/algorithms/simulation/sidb/quickexact.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" -#include "fiction/algorithms/simulation/sidb/sidb_simulation_result.hpp" -#include "fiction/technology/charge_distribution_surface.hpp" -#include "fiction/technology/sidb_charge_state.hpp" +#include "fiction/layouts/cell_level_layout.hpp" #include "fiction/traits.hpp" +#include "fiction/types.hpp" #include #include -#include #include #include #include -#include +#include +#include +#include -namespace fiction -{ +namespace fiction { /** * Possible types of charge transitions that can occur in an SiDB layout. These transitions represent * changes in the charge state of SiDBs, including transitions from neutral to negative, negative to neutral, neutral to * positive, and positive to neutral. */ -enum class transition_type -{ - /** - * SiDB is neutrally charged, but is closest to being negatively charged. - */ - NEUTRAL_TO_NEGATIVE, - /** - * SiDB is negatively charged, but is closest to being neutrally charged. - */ - NEGATIVE_TO_NEUTRAL, - /** - * SiDB is neutrally charged, but is closest to being positively charged. - */ - NEUTRAL_TO_POSITIVE, - /** - * SiDB is positively charged, but is closest to being neutrally charged. - */ - POSITIVE_TO_NEUTRAL, -}; + enum class transition_type { + /** + * SiDB is neutrally charged, but is closest to being negatively charged. + */ + NEUTRAL_TO_NEGATIVE, + /** + * SiDB is negatively charged, but is closest to being neutrally charged. + */ + NEGATIVE_TO_NEUTRAL, + /** + * SiDB is neutrally charged, but is closest to being positively charged. + */ + NEUTRAL_TO_POSITIVE, + /** + * SiDB is positively charged, but is closest to being neutrally charged. + */ + POSITIVE_TO_NEUTRAL, + }; /** * This struct encapsulates information related to the population stability of a charge distribution. * It includes details about the SiDB closest to a charge transition (critical cell), the specific @@ -57,335 +55,315 @@ enum class transition_type * * @tparam Lyt SiDB cell-level layout type. */ -template -struct population_stability_information -{ - /** - * SiDB cell which is closest to a charge transition. - */ - typename Lyt::cell critical_cell{}; - /** - * Charge transition from the current charge state to the closest one. - */ - std::unordered_map> - transition_from_to_with_cell_and_required_pot{}; - /** - * Absolute electrostatic potential (unit: V) required for the charge state transition. - */ - std::unordered_map minimum_potential_difference_to_transition{}; - /** - * Distance (unit: nm) corresponding to the minimum potential difference. - */ - std::unordered_map distance_corresponding_to_potential{}; - /** - * Total electrostatic energy (unit: eV) of given charge distribution. - */ - double system_energy{}; -}; + template + struct population_stability_information { + /** + * SiDB cell which is closest to a charge transition. + */ + typename Lyt::cell critical_cell{}; + /** + * Charge transition from the current charge state to the closest one. + */ + std::unordered_map> + transition_from_to_with_cell_and_required_pot{}; + /** + * Absolute electrostatic potential (unit: V) required for the charge state transition. + */ + std::unordered_map minimum_potential_difference_to_transition{}; + /** + * Distance (unit: nm) corresponding to the minimum potential difference. + */ + std::unordered_map distance_corresponding_to_potential{}; + /** + * Total electrostatic energy (unit: eV) of given charge distribution. + */ + double system_energy{}; + }; /** * This struct stores the parameters required to assess the population stability. */ -struct assess_physical_population_stability_params -{ - /** - * Parameters for the electrostatic potential. - */ - sidb_simulation_parameters simulation_parameters{}; - /** - * The precision level for the conversion from the minimum potential difference to the corresponding - * distance. - */ - uint64_t precision_for_distance_corresponding_to_potential = 2; -}; - -namespace detail -{ - -template -class assess_physical_population_stability_impl -{ - public: - /** - * Constructor for assess_physical_population_stability_impl. - * - * @param lyt SiDB layout. - * @param parameters The simulation parameters used for the assessment. - */ - assess_physical_population_stability_impl(const Lyt& lyt, - const assess_physical_population_stability_params& parameters) : - layout{lyt}, - params{parameters} - {} - - /** - * Runs a population stability assessment for a given SiDB layout using the provided simulation parameters. - * This function determines the minimum electrostatic potential required for charge state transitions within the - * layout and identifies the corresponding critical SiDB along with the type of charge state transition. - * - * @return A vector of population stability information structures, where each element represents a charge - * distribution in ascending energy order. Each structure contains details about the critical SiDB, the type of - * charge state transition, and the minimum electrostatic potential required for the charge transition. - */ - [[nodiscard]] std::vector> run() noexcept - { - const quickexact_params> quickexact_parameters{params.simulation_parameters}; - const auto simulation_results = quickexact(layout, quickexact_parameters); - const auto energy_and_unique_charge_index = collect_energy_and_charge_index(simulation_results); - - std::vector> popstability_information{}; - popstability_information.reserve(simulation_results.charge_distributions.size()); - - // Access the unique indices - for (const auto& energy_and_index : energy_and_unique_charge_index) - { - const auto it = std::find_if( - simulation_results.charge_distributions.begin(), simulation_results.charge_distributions.end(), - [&](const charge_distribution_surface& charge_lyt) - { - // Compare with the first element of the pair returned by get_charge_index_and_base() - return charge_lyt.get_charge_index_and_base().first == energy_and_index.charge_index; - }); - - if (it == simulation_results.charge_distributions.end()) - { - continue; - } + struct assess_physical_population_stability_params { + /** + * Parameters for the electrostatic potential. + */ + sidb_simulation_parameters physical_parameters{}; + /** + * The precision level for the conversion from the minimum potential difference to the corresponding + * distance. + */ + uint64_t precision_for_distance_corresponding_to_potential = 2; + }; - const auto& charge_lyt = *it; - - population_stability_information population_stability_info{}; - - population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE] = - std::numeric_limits::infinity(); - population_stability_info.minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL] = - std::numeric_limits::infinity(); - population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = - std::numeric_limits::infinity(); - population_stability_info.minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = - std::numeric_limits::infinity(); - - charge_lyt.foreach_cell( - [this, &charge_lyt, &population_stability_info](const auto& c) - { - switch (charge_lyt.get_charge_state(c)) - { - case sidb_charge_state::NEGATIVE: - { - population_stability_info = handle_negative_charges(*charge_lyt.get_local_potential(c), c, - population_stability_info); - break; - } - case sidb_charge_state::NEUTRAL: - { - population_stability_info = handle_neutral_charges(*charge_lyt.get_local_potential(c), c, - population_stability_info); - break; - } - case sidb_charge_state::POSITIVE: - { - population_stability_info = handle_positive_charges(*charge_lyt.get_local_potential(c), c, - population_stability_info); - break; - } - case sidb_charge_state::NONE: - { - break; + namespace detail { + + template + class assess_physical_population_stability_impl { + public: + /** + * Constructor for assess_physical_population_stability_impl. + * + * @param lyt SiDB layout. + * @param parameters The simulation parameters used for the assessment. + */ + assess_physical_population_stability_impl(const Lyt &lyt, + const assess_physical_population_stability_params ¶meters) : + layout{lyt}, + params{parameters} {} + + /** + * Runs a population stability assessment for a given SiDB layout using the provided simulation parameters. + * This function determines the minimum electrostatic potential required for charge state transitions within the + * layout and identifies the corresponding critical SiDB along with the type of charge state transition. + * + * @return A vector of population stability information structures, where each element represents a charge + * distribution in ascending energy order. Each structure contains details about the critical SiDB, the type of + * charge state transition, and the minimum electrostatic potential required for the charge transition. + */ + [[nodiscard]] std::vector> run() noexcept { + const quickexact_params> quickexact_parameters{params.physical_parameters}; + const auto simulation_results = quickexact(layout, quickexact_parameters); + const auto energy_and_unique_charge_index = collect_energy_and_charge_index(simulation_results); + + std::vector> popstability_information{}; + popstability_information.reserve(simulation_results.charge_distributions.size()); + + // Access the unique indices + for (const auto &energy_and_index: energy_and_unique_charge_index) { + const auto it = std::find_if( + simulation_results.charge_distributions.begin(), + simulation_results.charge_distributions.end(), + [&](const charge_distribution_surface &charge_lyt) { + // Compare with the first element of the pair returned by get_charge_index_and_base() + return charge_lyt.get_charge_index_and_base().first == energy_and_index.charge_index; + }); + + if (it == simulation_results.charge_distributions.end()) { + continue; + } + + const auto &charge_lyt = *it; + + population_stability_information population_stability_info{}; + + population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE] = + std::numeric_limits::infinity(); + population_stability_info.minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL] = + std::numeric_limits::infinity(); + population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = + std::numeric_limits::infinity(); + population_stability_info.minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = + std::numeric_limits::infinity(); + + charge_lyt.foreach_cell( + [this, &charge_lyt, &population_stability_info](const auto &c) { + switch (charge_lyt.get_charge_state(c)) { + case sidb_charge_state::NEGATIVE: { + population_stability_info = handle_negative_charges( + *charge_lyt.get_local_potential(c), c, + population_stability_info); + break; + } + case sidb_charge_state::NEUTRAL: { + population_stability_info = handle_neutral_charges( + *charge_lyt.get_local_potential(c), c, + population_stability_info); + break; + } + case sidb_charge_state::POSITIVE: { + population_stability_info = handle_positive_charges( + *charge_lyt.get_local_potential(c), c, + population_stability_info); + break; + } + case sidb_charge_state::NONE: { + break; + } + } + }); + population_stability_info.system_energy = charge_lyt.get_system_energy(); + + auto minimum_potential_difference = std::numeric_limits::infinity(); + + for (const auto &transition: population_stability_info.transition_from_to_with_cell_and_required_pot) { + population_stability_info.distance_corresponding_to_potential[transition.first] = + convert_potential_to_distance(transition.second.second, params.physical_parameters, + params.precision_for_distance_corresponding_to_potential); + if (transition.second.second < minimum_potential_difference) { + population_stability_info.critical_cell = transition.second.first; + minimum_potential_difference = transition.second.second; } } - }); - population_stability_info.system_energy = charge_lyt.get_system_energy(); - - auto minimum_potential_difference = std::numeric_limits::infinity(); - - for (const auto& transition : population_stability_info.transition_from_to_with_cell_and_required_pot) - { - population_stability_info.distance_corresponding_to_potential[transition.first] = - convert_potential_to_distance(transition.second.second, params.physical_parameters, - params.precision_for_distance_corresponding_to_potential); - if (transition.second.second < minimum_potential_difference) - { - population_stability_info.critical_cell = transition.second.first; - minimum_potential_difference = transition.second.second; + popstability_information.push_back(population_stability_info); } + + return popstability_information; + }; + + private: + /** + * This struct represents the electrostatic energy and charge index of a charge distribution. + */ + struct energy_and_charge_index { + /** + * Electrostatic energy of the charge distribution. + */ + double energy; + /** + * Charge index of the charge distribution. + */ + uint64_t charge_index; + }; + /** + * Layout to analyze. + */ + const Lyt &layout; + /** + * Parameters required to assess the population stability. + */ + const assess_physical_population_stability_params ¶ms; + + /** + * This function checks if the absolute difference between the given local potential and + * µ- is smaller than the current minimum potential difference to transition for a negatively charged SiDB. + * If `true`, it updates the population stability information with the new minimum difference and critical cell. + * + * @param local_potential The local potential associated with the cell. + * @param c The cell for which the charge state is being considered (SiDB is negatively charged). + * @param pop_stability_information The current population stability information. + * + * @return An updated population stability information with potential transition details. + */ + [[nodiscard]] population_stability_information + handle_negative_charges(const double local_potential, const typename Lyt::cell &c, + const population_stability_information &pop_stability_information) noexcept { + auto updated_pop_stability_information = pop_stability_information; + + if (std::abs(-local_potential + params.physical_parameters.mu_minus) < + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL]) { + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL] = + std::abs(-local_potential + params.physical_parameters.mu_minus); + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::NEGATIVE_TO_NEUTRAL] = { + c, updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL]}; + } + + return updated_pop_stability_information; } - popstability_information.push_back(population_stability_info); - } - return popstability_information; - }; + /** + * This function checks if the absolute difference between the given local potential and + * µ- or µ+ is smaller than the current minimum potential difference. + * If `true`, it updates the population stability information with the new minimum difference and critical cell. + * + * @param local_potential The local potential associated with the cell. + * @param c The cell for which the charge state is being considered (SiDB is neutrally charged). + * @param pop_stability_information The current population stability information. + * + * @return An updated population stability information with potential transition details. + */ + [[nodiscard]] population_stability_information + handle_neutral_charges(const double local_potential, const typename Lyt::cell &c, + const population_stability_information &pop_stability_information) noexcept { + auto updated_pop_stability_information = pop_stability_information; + if (std::abs(-local_potential + params.physical_parameters.mu_minus) < + std::abs(-local_potential + params.physical_parameters.mu_plus())) { + if (std::abs(-local_potential + params.physical_parameters.mu_minus) < + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE]) { + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE] = + std::abs(-local_potential + params.physical_parameters.mu_minus); + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_NEGATIVE] = { + c, updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE]}; + } + } else { + if (std::abs(-local_potential + params.physical_parameters.mu_plus()) < + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]) { + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = + std::abs(-local_potential + params.physical_parameters.mu_plus()); + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_POSITIVE] = { + c, updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]}; + } + } - private: - /** - * This struct represents the electrostatic energy and charge index of a charge distribution. - */ - struct energy_and_charge_index - { - /** - * Electrostatic energy of the charge distribution. - */ - double energy; - /** - * Charge index of the charge distribution. - */ - uint64_t charge_index; - }; - /** - * Layout to analyze. - */ - const Lyt& layout; - /** - * Parameters required to assess the population stability. - */ - const assess_physical_population_stability_params& params; - - /** - * This function checks if the absolute difference between the given local potential and - * µ- is smaller than the current minimum potential difference to transition for a negatively charged SiDB. - * If `true`, it updates the population stability information with the new minimum difference and critical cell. - * - * @param local_potential The local potential associated with the cell. - * @param c The cell for which the charge state is being considered (SiDB is negatively charged). - * @param pop_stability_information The current population stability information. - * - * @return An updated population stability information with potential transition details. - */ - [[nodiscard]] population_stability_information - handle_negative_charges(const double local_potential, const typename Lyt::cell& c, - const population_stability_information& pop_stability_information) noexcept - { - auto updated_pop_stability_information = pop_stability_information; - - if (std::abs(-local_potential + params.physical_parameters.mu_minus) < - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL]) - { - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL] = - std::abs(-local_potential + params.physical_parameters.mu_minus); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information - .transition_from_to_with_cell_and_required_pot[transition_type::NEGATIVE_TO_NEUTRAL] = { - c, updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL]}; - } - - return updated_pop_stability_information; - } - /** - * This function checks if the absolute difference between the given local potential and - * µ- or µ+ is smaller than the current minimum potential difference. - * If `true`, it updates the population stability information with the new minimum difference and critical cell. - * - * @param local_potential The local potential associated with the cell. - * @param c The cell for which the charge state is being considered (SiDB is neutrally charged). - * @param pop_stability_information The current population stability information. - * - * @return An updated population stability information with potential transition details. - */ - [[nodiscard]] population_stability_information - handle_neutral_charges(const double local_potential, const typename Lyt::cell& c, - const population_stability_information& pop_stability_information) noexcept - { - auto updated_pop_stability_information = pop_stability_information; - if (std::abs(-local_potential + params.simulation_parameters.mu_minus) < - std::abs(-local_potential + params.simulation_parameters.mu_plus())) - { - if (std::abs(-local_potential + params.physical_parameters.mu_minus) < - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE]) - { - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE] = - std::abs(-local_potential + params.physical_parameters.mu_minus); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information - .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_NEGATIVE] = { - c, updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE]}; + return updated_pop_stability_information; } - } - else - { - if (std::abs(-local_potential + params.physical_parameters.mu_plus()) < - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]) - { - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = - std::abs(-local_potential + params.physical_parameters.mu_plus()); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information - .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_POSITIVE] = { - c, updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]}; + + /** + * This function checks if the absolute difference between the given local potential and µ+ is smaller than the + * current minimum potential difference. If true`, it updates the + * population stability information with the new minimum difference and critical cell. + * + * @param local_potential The local potential associated with the cell. + * @param c The cell for which the charge state is being considered (SiDB is positively charged). + * @param pop_stability_information The current population stability information. + * + * @return An updated population stability information with potential transition details. + */ + [[nodiscard]] population_stability_information + handle_positive_charges(const double local_potential, const typename Lyt::cell &c, + const population_stability_information &pop_stability_information) noexcept { + auto updated_pop_stability_information = pop_stability_information; + if (std::abs(-local_potential + params.physical_parameters.mu_plus()) < + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL]) { + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = + std::abs(-local_potential + params.physical_parameters.mu_plus()); + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::POSITIVE_TO_NEUTRAL] = { + c, updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL]}; + } + + return updated_pop_stability_information; } - } - return updated_pop_stability_information; - } - /** - * This function checks if the absolute difference between the given local potential and µ+ is smaller than the - * current minimum potential difference. If true`, it updates the - * population stability information with the new minimum difference and critical cell. - * - * @param local_potential The local potential associated with the cell. - * @param c The cell for which the charge state is being considered (SiDB is positively charged). - * @param pop_stability_information The current population stability information. - * - * @return An updated population stability information with potential transition details. - */ - [[nodiscard]] population_stability_information - handle_positive_charges(const double local_potential, const typename Lyt::cell& c, - const population_stability_information& pop_stability_information) noexcept - { - auto updated_pop_stability_information = pop_stability_information; - if (std::abs(-local_potential + params.physical_parameters.mu_plus()) < - updated_pop_stability_information.minimum_potential_difference_to_transition) - { - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = - std::abs(-local_potential + params.physical_parameters.mu_plus()); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information - .transition_from_to_with_cell_and_required_pot[transition_type::POSITIVE_TO_NEUTRAL] = { - c, updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL]}; - } - - return updated_pop_stability_information; - } - /** - * Collects the system energy with the corresponding charge index information of all physically valid - * charge distributions of a given SiDB layout. - * - * @param sim_results The simulation results, including all physically valid charge distributions. - * @return A vector of energy_and_charge_index pairs, where each pair consists of a double value representing - * the system energy and a uint64_t representing the unique charge index. The vector is sorted in ascending order - * of the energy values. - */ - [[nodiscard]] std::vector - collect_energy_and_charge_index(const sidb_simulation_result& sim_results) const noexcept - { - std::vector energy_charge_index{}; - energy_charge_index.reserve(sim_results.charge_distributions.size()); - - std::transform( - sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), - std::back_inserter(energy_charge_index), - [](const auto& ch_lyt) { - return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; - }); - - // Sort the vector in ascending order of the energy value - std::sort(energy_charge_index.begin(), energy_charge_index.end(), - [](const auto& lhs, const auto& rhs) { return lhs.energy < rhs.energy; }); - - return energy_charge_index; - } -}; + /** + * Collects the system energy with the corresponding charge index information of all physically valid + * charge distributions of a given SiDB layout. + * + * @param sim_results The simulation results, including all physically valid charge distributions. + * @return A vector of energy_and_charge_index pairs, where each pair consists of a double value representing + * the system energy and a uint64_t representing the unique charge index. The vector is sorted in ascending order + * of the energy values. + */ + [[nodiscard]] std::vector + collect_energy_and_charge_index(const sidb_simulation_result &sim_results) const noexcept { + std::vector energy_charge_index{}; + energy_charge_index.reserve(sim_results.charge_distributions.size()); + + std::transform( + sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), + std::back_inserter(energy_charge_index), + [](const auto &ch_lyt) { + return energy_and_charge_index{ch_lyt.get_system_energy(), + ch_lyt.get_charge_index_and_base().first}; + }); + + // Sort the vector in ascending order of the energy value + std::sort(energy_charge_index.begin(), energy_charge_index.end(), + [](const auto &lhs, const auto &rhs) { return lhs.energy < rhs.energy; }); + + return energy_charge_index; + } + }; -} // namespace detail + } // namespace detail /** * This function assesses the population stability of each physically valid charge distributions of a given SiDB layout. @@ -398,17 +376,18 @@ class assess_physical_population_stability_impl * @return A vector of population stability information for all physically valid charge distributions of the given SiDB * layout. */ -template -[[nodiscard]] std::vector> -assess_physical_population_stability(const Lyt& lyt, const assess_physical_population_stability_params& params) noexcept -{ - static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); - static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); - - detail::assess_physical_population_stability_impl p{lyt, params}; - return p.run(); -} + template + [[nodiscard]] std::vector> + assess_physical_population_stability(const Lyt &lyt, + const assess_physical_population_stability_params ¶ms) noexcept { + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); + + detail::assess_physical_population_stability_impl p{lyt, params}; + return p.run(); + } } // namespace fiction -#endif // FICTION_ASSESS_PHYSICAL_POPULATION_STABILITY_HPP +#endif // FICTION_ASSESS_PHYSICAL_POPULATION_STABILITY_HPP \ No newline at end of file diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 2b9343ebb..e69ebd422 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -9,7 +9,7 @@ #include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" #include "fiction/layouts/bounding_box.hpp" #include "fiction/layouts/coordinates.hpp" -#include "fiction/technology/sidb_surface.hpp" +#include "fiction/technology/sidb_defect_surface.hpp" #include "fiction/types.hpp" #include "fiction/utils/hash.hpp" #include "fiction/utils/layout_utils.hpp" @@ -523,7 +523,7 @@ class defect_influence_impl /** * The SiDB cell-level layout to investigate. */ - sidb_surface layout{}; + sidb_defect_surface layout{}; /** * The specification of the layout. */ diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 4f8f0264d..1be553e39 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -53,14 +53,16 @@ struct maximum_defect_influence_distance_params /** * Statistics for the maximum defect influence simulation. */ - struct maximum_defect_influence_distance_stats { - /** - * The total runtime of the maximum defect influence simulation. - */ - mockturtle::stopwatch<>::duration time_total{0}; - }; +struct maximum_defect_influence_distance_stats +{ + /** + * The total runtime of the maximum defect influence simulation. + */ + mockturtle::stopwatch<>::duration time_total{0}; +}; - namespace detail { +namespace detail +{ /** * A class for simulating the maximum influence distance of defects within an SiDB layout. * @@ -72,174 +74,190 @@ struct maximum_defect_influence_distance_params * distance and corresponding defect position. It utilizes multithreading for efficient defect * position simulations. */ - template - class maximum_defect_influence_position_and_distance_impl { - public: - maximum_defect_influence_position_and_distance_impl(const Lyt &lyt, - const maximum_defect_influence_distance_params &sim_params, - maximum_defect_influence_distance_stats &st) : - layout{lyt}, - params{sim_params}, - stats{st} { - } +template +class maximum_defect_influence_position_and_distance_impl +{ + public: + maximum_defect_influence_position_and_distance_impl(const Lyt& lyt, + const maximum_defect_influence_distance_params& sim_params, + maximum_defect_influence_distance_stats& st) : + layout{lyt}, + params{sim_params}, + stats{st} + { + collect_all_defect_cells(); + }; std::pair run() noexcept { const quickexact_params> params_defect{ params.simulation_parameters, quickexact_params>::automatic_base_number_detection::OFF}; - std::pair run() noexcept { - mockturtle::stopwatch stop{stats.time_total}; + mockturtle::stopwatch stop{stats.time_total}; - std::mutex mutex; + std::mutex mutex; - const quickexact_params> params_defect{ - params.simulation_parameters, - quickexact_params>::automatic_base_number_detection::OFF}; + double avoidance_distance{0}; + coordinate max_defect_position{}; - double avoidance_distance{0}; - coordinate max_defect_position{}; + const auto simulation_results = quickexact(layout, params_defect); - const auto simulation_results = - quickexact(layout, quickexact_params{params.simulation_parameters, - quickexact_params::automatic_base_number_detection::OFF}); + const auto min_energy = minimum_energy(simulation_results.charge_distributions.cbegin(), + simulation_results.charge_distributions.cend()); - const auto min_energy = minimum_energy(simulation_results.charge_distributions.cbegin(), - simulation_results.charge_distributions.cend()); + uint64_t charge_index_layout = 0; - uint64_t charge_index_layout = 0; + for (auto& lyt_result : simulation_results.charge_distributions) + { + if (std::fabs(round_to_n_decimal_places(lyt_result.get_system_energy(), 6) - + round_to_n_decimal_places(min_energy, 6)) < std::numeric_limits::epsilon()) + { + lyt_result.charge_distribution_to_index_general(); + charge_index_layout = lyt_result.get_charge_index_and_base().first; + } + } - for (auto &lyt_result: simulation_results.charge_distributions) { - if (std::fabs(round_to_n_decimal_places(lyt_result.get_system_energy(), 6) - - round_to_n_decimal_places(min_energy, 6)) < std::numeric_limits::epsilon()) { - lyt_result.charge_distribution_to_index_general(); - charge_index_layout = lyt_result.get_charge_index_and_base().first; + // simulate the impact of the defect at a given position on the ground state of the SiDB layout + const auto process_defect = [&](const std::vector& defect_chunk) noexcept + { + for (const auto& defect : defect_chunk) + { + if (layout.get_cell_type(defect) == Lyt::technology::cell_type::EMPTY) + { + sidb_defect_surface lyt_defect{}; + + layout.foreach_cell([this, &lyt_defect](const auto& cell) + { lyt_defect.assign_cell_type(cell, layout.get_cell_type(cell)); }); + + // assign defect to layout + lyt_defect.assign_sidb_defect(defect, params.defect); + // conduct simulation with defect + auto simulation_result_defect = quickexact(lyt_defect, params_defect); + + const auto min_energy_defect = + minimum_energy(simulation_result_defect.charge_distributions.cbegin(), + simulation_result_defect.charge_distributions.cend()); + + uint64_t charge_index_defect_layout = 0; + + // get the charge index of the ground state + for (const auto& lyt_simulation_with_defect : simulation_result_defect.charge_distributions) + { + if (std::fabs(round_to_n_decimal_places(lyt_simulation_with_defect.get_system_energy(), 6) - + round_to_n_decimal_places(min_energy_defect, 6)) < + std::numeric_limits::epsilon()) + { + lyt_simulation_with_defect.charge_distribution_to_index_general(); + charge_index_defect_layout = lyt_simulation_with_defect.get_charge_index_and_base().first; + } } - } - - // simulate the impact of the defect at a given position on the ground state of the SiDB layout - const auto process_defect = [&](const std::vector &defect_chunk) noexcept { - for (const auto &defect: defect_chunk) { - if (layout.get_cell_type(defect) == Lyt::technology::cell_type::EMPTY) { - sidb_surface lyt_defect{}; - - layout.foreach_cell([this, &lyt_defect](const auto &cell) { - lyt_defect.assign_cell_type(cell, layout.get_cell_type(cell)); - }); - - // assign defect to layout - lyt_defect.assign_sidb_defect(defect, params.defect); - // conduct simulation with defect - auto simulation_result_defect = quickexact(lyt_defect, params_defect); - - const auto min_energy_defect = - minimum_energy(simulation_result_defect.charge_distributions.cbegin(), - simulation_result_defect.charge_distributions.cend()); - - uint64_t charge_index_defect_layout = 0; - - // get the charge index of the ground state - for (const auto &lyt_simulation_with_defect: simulation_result_defect.charge_distributions) { - if (std::fabs( - round_to_n_decimal_places(lyt_simulation_with_defect.get_system_energy(), 6) - - round_to_n_decimal_places(min_energy_defect, 6)) < - std::numeric_limits::epsilon()) { - lyt_simulation_with_defect.charge_distribution_to_index_general(); - charge_index_defect_layout = lyt_simulation_with_defect.get_charge_index_and_base().first; - } - } - - // defect changes the ground state, i.e., the charge index is changed compared to the charge - // distribution without placed defect. - if (charge_index_defect_layout != charge_index_layout) { - auto distance = std::numeric_limits::max(); - layout.foreach_cell( - [this, &defect, &distance](const auto &cell) { - if (sidb_nanometer_distance(layout, cell, defect) < distance) { - distance = sidb_nanometer_distance(layout, cell, defect); - } - }); + // defect changes the ground state, i.e., the charge index is changed compared to the charge + // distribution without placed defect. + if (charge_index_defect_layout != charge_index_layout) + { + auto distance = std::numeric_limits::max(); + layout.foreach_cell( + [this, &defect, &distance](const auto& cell) + { + if (sidb_nm_distance(layout, cell, defect) < distance) { - std::lock_guard lock(mutex); - // the distance is larger than the current maximum one. - if (distance > avoidance_distance) { - max_defect_position = defect; - avoidance_distance = distance; - } + distance = sidb_nm_distance(layout, cell, defect); } + }); + + { + std::lock_guard lock(mutex); + // the distance is larger than the current maximum one. + if (distance > avoidance_distance) + { + max_defect_position = defect; + avoidance_distance = distance; } } } - }; + } + } + }; - const size_t num_threads = std::thread::hardware_concurrency(); // Anzahl der verfügbaren Threads + const size_t num_threads = std::thread::hardware_concurrency(); // Anzahl der verfügbaren Threads - // Größe jedes Chunks berechnen - const size_t chunk_size = (defect_cells.size() + num_threads - 1) / num_threads; + // Größe jedes Chunks berechnen + const size_t chunk_size = (defect_cells.size() + num_threads - 1) / num_threads; - // Vektor für Threads - std::vector threads; - threads.reserve(num_threads); + // Vektor für Threads + std::vector threads; + threads.reserve(num_threads); - // Aufteilen des Vektors in Chunks und Starten von Threads für jeden Chunk - auto defect_it = defect_cells.begin(); - for (size_t i = 0; i < num_threads; ++i) { + // Aufteilen des Vektors in Chunks und Starten von Threads für jeden Chunk + auto defect_it = defect_cells.begin(); + for (size_t i = 0; i < num_threads; ++i) + { - auto chunk_start = defect_it; - auto chunk_end = std::min(defect_it + chunk_size, defect_cells.end()); + auto chunk_start = defect_it; + auto chunk_end = std::min(defect_it + chunk_size, defect_cells.end()); - threads.emplace_back(process_defect, std::vector(chunk_start, chunk_end)); + threads.emplace_back(process_defect, std::vector(chunk_start, chunk_end)); - defect_it = chunk_end; - if (defect_it == defect_cells.end()) { - break; // Alle Defekte wurden aufgeteilt - } - } + defect_it = chunk_end; + if (defect_it == defect_cells.end()) + { + break; // Alle Defekte wurden aufgeteilt + } + } - for (auto &thread: threads) { - thread.join(); - } + for (auto& thread : threads) + { + thread.join(); + } - // Apply the process_defect function to each defect using std::for_each + return {max_defect_position, avoidance_distance}; + } -// std::vector> futures{}; -// futures.reserve(defect_cells.size()); -// -// // Start asynchronous tasks to process combinations in parallel -// for (const auto& defect_cell : defect_cells) -// { -// futures.emplace_back(std::async(std::launch::async, process_defect, defect_cell)); -// } -// -// for (auto& future : futures) -// { -// future.wait(); -// } - // std::for_each(FICTION_EXECUTION_POLICY_PAR_UNSEQ defect_cells.cbegin(), defect_cells.cend(), process_defect); + private: + /** + * SiDB cell-level layout to simulate. + */ + Lyt layout; + /** + * Parameters used for the simulation. + */ + maximum_defect_influence_distance_params params{}; + /** + * The statistics of the maximum defect influence position. + */ + maximum_defect_influence_distance_stats& stats; + /** + * All allowed defect positions. + */ + std::vector defect_cells{}; + /** + * Collects all possible defect cell positions within a given layout while avoiding SiDB cells. + * + * This function calculates a bounding box around the provided layout, encompassing the area + * where defect cells can be placed. It then iterates through this bounding box, scanning from + * top to bottom and left to right, and identifies all valid positions for defect cells. A defect + * cell can only be placed in locations where there are no SiDB cells. + */ + void collect_all_defect_cells() noexcept + { + // bounding box around the given layout to have north-west and south-east cells. + bounding_box_2d bb{layout}; - return {max_defect_position, avoidance_distance}; - } + auto nw = bb.get_min(); // north-west cell + auto se = bb.get_max(); // south-east cell - private: - /** - * SiDB cell-level layout to simulate. - */ - Lyt layout; - /** - * Parameters used for the simulation. - */ - maximum_defect_influence_distance_params params{}; - /** - * The statistics of the maximum defect influence position. - */ - maximum_defect_influence_distance_stats &stats; - /** - * All allowed defect positions. - */ - std::vector defect_cells{}; - }; + // shift nw and se cell by the additional scanning area to cover an area that is larger than the gate area. + nw.x = nw.x - params.additional_scanning_area.first; + nw.y = nw.y - params.additional_scanning_area.second; + + se.x = se.x + params.additional_scanning_area.first; + se.y = se.y + params.additional_scanning_area.second; + + defect_cells = all_coordinates_in_spanned_area(nw, se); + } +}; - } // namespace detail +} // namespace detail /** * Calculates the maximum distance at which a given defect can influence the layout's ground state. @@ -254,29 +272,31 @@ struct maximum_defect_influence_distance_params * can still affect the ground state of the layout. The second entry describes the distance of the defect from the * layout. */ - template - std::pair - maximum_defect_influence_position_and_distance(const Lyt &lyt, - const maximum_defect_influence_distance_params &sim_params = {}, - maximum_defect_influence_distance_stats *pst = nullptr) { - static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); - static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); - static_assert(!has_offset_ucoord_v, "Lyt cannot be based on offset coordinates"); - static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); +template +std::pair +maximum_defect_influence_position_and_distance(const Lyt& lyt, + const maximum_defect_influence_distance_params& sim_params = {}, + maximum_defect_influence_distance_stats* pst = nullptr) +{ + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(!has_offset_ucoord_v, "Lyt cannot be based on offset coordinates"); + static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); - maximum_defect_influence_distance_stats st{}; + maximum_defect_influence_distance_stats st{}; - detail::maximum_defect_influence_position_and_distance_impl p{lyt, sim_params, st}; + detail::maximum_defect_influence_position_and_distance_impl p{lyt, sim_params, st}; - const auto result = p.run(); + const auto result = p.run(); - if (pst) { - *pst = st; - } - - return result; + if (pst) + { + *pst = st; } + return result; +} + } // namespace fiction #endif // FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_HPP diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index 5041efeb3..45a21e4c1 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -5,6 +5,8 @@ #ifndef FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP #define FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP +#include "fiction/algorithms/iter/bdl_input_iterator.hpp" +#include "fiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" #include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" #include "fiction/utils/layout_utils.hpp" @@ -14,7 +16,7 @@ namespace fiction struct maximum_defect_influence_position_and_distance_of_sidb_gate_params { maximum_defect_influence_distance_params defect_influence_params{}; - detect_bdl_pairs_params bdl_pairs_params{}; + detect_bdl_pairs_params bdl_pairs_params{}; }; template @@ -37,18 +39,18 @@ template bdl_input_iterator bii{lyt, params.bdl_pairs_params}; double maximum_defect_influence_distance = 0.0; - cell defect_cell{}; + cell defect_cell{}; // number of different input combinations for (auto i = 0u; i < spec.front().num_bits(); ++i, ++bii) { maximum_defect_influence_distance_stats stats_defect{}; - const auto influence_cell_distance = + const auto influence_cell_distance = maximum_defect_influence_position_and_distance(lyt, params.defect_influence_params, &stats_defect); std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; if (influence_cell_distance.second > maximum_defect_influence_distance) { maximum_defect_influence_distance = influence_cell_distance.second; - defect_cell = influence_cell_distance.first; + defect_cell = influence_cell_distance.first; } } return {defect_cell, maximum_defect_influence_distance}; diff --git a/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp index 80858546b..5c9b7a847 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp @@ -25,7 +25,7 @@ namespace fiction */ template [[nodiscard]] double -maximum_minimum_defect_influence_distance(const Lyt& lyt, +maximum_minimum_defect_influence_distance(const Lyt& lyt, const defect_influence_operational_domain& defect_opdomain) noexcept { double max_distance = 0; @@ -39,9 +39,9 @@ maximum_minimum_defect_influence_distance(const Lyt& lyt.foreach_cell( [&val, &min_distance, &lyt](const auto& c) { - if (sidb_nanometer_distance(lyt, c, val.first) < min_distance) + if (sidb_nm_distance(lyt, c, val.first) < min_distance) { - min_distance = sidb_nanometer_distance(lyt, c, val.first); + min_distance = sidb_nm_distance(lyt, c, val.first); } }); if (min_distance > max_distance) diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index 6c625f35a..3afaf04cc 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -364,11 +364,11 @@ class operational_domain_impl { mockturtle::stopwatch stop{stats.time_total}; - std::vector step_point_samples = {}; + std::set step_point_samples = {}; if (initial_parameter.has_value()) { - step_point_samples.emplace_back(to_step_point(initial_parameter.value())); + step_point_samples.insert(to_step_point(initial_parameter.value())); } else { diff --git a/include/fiction/utils/math_utils.hpp b/include/fiction/utils/math_utils.hpp index 83ed3bd9f..66130bdc5 100644 --- a/include/fiction/utils/math_utils.hpp +++ b/include/fiction/utils/math_utils.hpp @@ -118,6 +118,30 @@ determine_all_combinations_of_distributing_k_entities_on_n_positions(const std:: return all_combinations; } +/** + * Calculates the cost function \f$ \chi \f$ by summing the product of chi values and weights. + * + * @param chis The vector containing the chi values. + * @param weights The vector containing the weights. + * @return The calculated cost function \f$ \chi(L) \f$. + * + * @throws std::invalid_argument If the sizes of chis and weights vectors are different. + */ +double cost_function_chi(const std::vector& chis, const std::vector& weights) +{ + if (chis.size() != weights.size()) + { + throw std::invalid_argument("chis and weights must have the same size."); + } + + double chi = 0.0; + for (std::size_t i = 0; i < chis.size(); ++i) + { + chi += weights.at(i) * chis.at(i); + } + return chi; +} + } // namespace fiction #endif // FICTION_MATH_UTILS_HPP diff --git a/test/algorithms/physical_design/design_sidb_gates.cpp b/test/algorithms/physical_design/design_sidb_gates.cpp index 1a4570615..9438f60bc 100644 --- a/test/algorithms/physical_design/design_sidb_gates.cpp +++ b/test/algorithms/physical_design/design_sidb_gates.cpp @@ -5,17 +5,14 @@ #include #include +#include #include #include -#include -#include -#include #include #include #include #include #include -#include #include #include #include @@ -55,12 +52,10 @@ TEST_CASE("Use SiQAD XNOR skeleton and generate SiQAD XNOR gate, exhaustive", "[ CHECK(lyt.num_cells() == 13); - const design_sidb_gates_params params{ - sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, - {{10, 4, 0}, {10, 4, 0}}, - 1, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + {{10, 4, 0}, {10, 4, 0}}, + 1, + sidb_simulation_engine::QUICKEXACT}; const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_xnor_tt()}, params); @@ -72,7 +67,6 @@ TEST_CASE("Use SiQAD XNOR skeleton and generate SiQAD XNOR gate, exhaustive", "[ const auto lyt_in_cube_coord = convert_to_fiction_coordinates(lyt); const design_sidb_gates_params params_cube{ sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, {siqad::to_fiction_coord(siqad::coord_t{10, 4, 0}), siqad::to_fiction_coord(siqad::coord_t{10, 4, 0})}, 1, @@ -90,7 +84,6 @@ TEST_CASE("Use SiQAD XNOR skeleton and generate SiQAD XNOR gate, exhaustive", "[ const auto lyt_in_offset_coord = convert_to_fiction_coordinates(lyt); const design_sidb_gates_params params_offset{ sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, {siqad::to_fiction_coord(siqad::coord_t{10, 4, 0}), siqad::to_fiction_coord(siqad::coord_t{10, 4, 0})}, 1, @@ -126,12 +119,10 @@ TEST_CASE("Use SiQAD's AND gate skeleton to generate all possible AND gates", "[ lyt.assign_cell_type({10, 9, 1}, sidb_technology::cell_type::NORMAL); - design_sidb_gates_params params{ - sidb_simulation_parameters{2, -0.28}, - design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, - {{4, 4, 0}, {14, 5, 1}}, - 1, - sidb_simulation_engine::EXGS}; + design_sidb_gates_params params{sidb_simulation_parameters{2, -0.28}, + {{4, 4, 0}, {14, 5, 1}}, + 1, + sidb_simulation_engine::EXGS}; SECTION("Exhaustive Generation") { @@ -141,8 +132,8 @@ TEST_CASE("Use SiQAD's AND gate skeleton to generate all possible AND gates", "[ SECTION("Random Generation") { - params.design_mode = design_sidb_gates_params::design_sidb_gates_mode::RANDOM; - const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_and_tt()}, params); + const auto found_gate_layouts = + design_sidb_gates(lyt, std::vector{create_and_tt()}, params, design_sidb_gates_mode::RANDOM); CHECK(!found_gate_layouts.empty()); } } @@ -183,12 +174,10 @@ TEST_CASE("Use FO2 Bestagon gate without SiDB at {17, 11, 0} and generate origin SECTION("generate original FO2") { - const design_sidb_gates_params params{ - sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, - {{17, 11, 0}, {17, 11, 0}}, - 1, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + {{17, 11, 0}, {17, 11, 0}}, + 1, + sidb_simulation_engine::QUICKEXACT}; CHECK(lyt.get_cell_type({17, 11, 0}) == sidb_100_cell_clk_lyt_siqad::technology::EMPTY); @@ -205,8 +194,6 @@ TEST_CASE("Use FO2 Bestagon gate without SiDB at {17, 11, 0} and generate origin { const design_sidb_gates_params> params{ sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params< - sidb_defect_surface>::design_sidb_gates_mode::EXHAUSTIVE, {{17, 11, 0}, {17, 11, 0}}, 1, sidb_simulation_engine::QUICKEXACT}; @@ -263,25 +250,23 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") SECTION("Random Generation") { - const design_sidb_gates_params params{ - sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params::design_sidb_gates_mode::RANDOM, - {{14, 6, 0}, {24, 12, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + {{14, 6, 0}, {24, 12, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT}; - const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_and_tt()}, params); + const auto found_gate_layouts = + design_sidb_gates(lyt, std::vector{create_and_tt()}, params, design_sidb_gates_mode::RANDOM); REQUIRE(!found_gate_layouts.empty()); CHECK(found_gate_layouts.front().num_cells() == lyt.num_cells() + 3); } - SECTION("Random Generation with defects") + SECTION("Random Generation with defects, random") { sidb_defect_surface defect_layout{lyt}; const design_sidb_gates_params> params{ sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params>::design_sidb_gates_mode::RANDOM, {{14, 6, 0}, {24, 12, 0}}, 3, sidb_simulation_engine::QUICKEXACT}; @@ -293,7 +278,8 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") sidb_defect{sidb_defect_type::DB, -1, params.simulation_parameters.epsilon_r, params.simulation_parameters.lambda_tf}); - const auto found_gate_layouts = design_sidb_gates(defect_layout, std::vector{create_and_tt()}, params); + const auto found_gate_layouts = + design_sidb_gates(defect_layout, std::vector{create_and_tt()}, params, design_sidb_gates_mode::RANDOM); REQUIRE(!found_gate_layouts.empty()); CHECK(found_gate_layouts.front().num_defects() == 2); CHECK(found_gate_layouts.front().num_cells() == lyt.num_cells() + 3); @@ -305,6 +291,54 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") CHECK(cell != siqad::coord_t{20, 12, 0}); }); } + + SECTION("Random Generation with defects, Simulated Annealing") + { + sidb_defect_surface defect_layout{lyt}; + + const design_sidb_gates_params> params{ + sidb_simulation_parameters{2, -0.32}, + {{14, 6, 0}, {24, 12, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT}; + + defect_layout.assign_sidb_defect({15, 10, 0}, + sidb_defect{sidb_defect_type::DB, -1, params.simulation_parameters.epsilon_r, + params.simulation_parameters.lambda_tf}); + defect_layout.assign_sidb_defect({20, 12, 0}, + sidb_defect{sidb_defect_type::DB, -1, params.simulation_parameters.epsilon_r, + params.simulation_parameters.lambda_tf}); + + const critical_temperature_params ct_params{params.simulation_parameters}; + const operational_domain_params op_params{params.simulation_parameters}; + design_sidb_gates_sa_params sa_params{}; + sa_params.ct_params = ct_params; + sa_params.op_params = op_params; + sa_params.weight_temperature = -1.0; + sa_params.weight_operational_domain = -1.0; + sa_params.weight_non_operational = 10; + sa_params.final_temperature = 0.1; + sa_params.initial_temperature = 500; + sa_params.number_of_cycles = 1; + sa_params.op_params.x_step = 0.2; + sa_params.op_params.y_step = 0.2; + sa_params.op_params.x_min = 3; + sa_params.op_params.y_min = 3; + sa_params.op_params.x_max = 7; + sa_params.op_params.y_max = 7; + + const auto found_gate_layout = design_sidb_gates_metric_driven_simulated_annealing( + defect_layout, std::vector{create_and_tt()}, params, sa_params); + CHECK(found_gate_layout.num_defects() == 2); + CHECK(found_gate_layout.num_cells() == lyt.num_cells() + 3); + + found_gate_layout.foreach_cell( + [](const auto& cell) + { + CHECK(cell != siqad::coord_t{15, 10, 0}); + CHECK(cell != siqad::coord_t{20, 12, 0}); + }); + } } TEST_CASE("Design AND Bestagon shaped gate on H-Si 111", "[design-sidb-gates]") @@ -339,28 +373,26 @@ TEST_CASE("Design AND Bestagon shaped gate on H-Si 111", "[design-sidb-gates]") SECTION("Random Generation") { - const design_sidb_gates_params params{ - sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params::design_sidb_gates_mode::RANDOM, - {{10, 11, 0}, {14, 17, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + {{10, 11, 0}, {14, 17, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT}; - const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_nor_tt()}, params); + const auto found_gate_layouts = + design_sidb_gates(lyt, std::vector{create_nor_tt()}, params, design_sidb_gates_mode::RANDOM); REQUIRE(!found_gate_layouts.empty()); CHECK(found_gate_layouts.front().num_cells() == lyt.num_cells() + 3); } - SECTION("Random Generation") + SECTION("Exhaustive Generation") { - const design_sidb_gates_params params{ - sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, - {{10, 11, 0}, {14, 17, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + {{10, 11, 0}, {14, 17, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT}; - const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_nor_tt()}, params); + const auto found_gate_layouts = + design_sidb_gates(lyt, std::vector{create_nor_tt()}, params, design_sidb_gates_mode::EXHAUSTIVE); REQUIRE(found_gate_layouts.size() == 206); CHECK(found_gate_layouts.front().num_cells() == lyt.num_cells() + 3); } diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp index 74e6d3521..b78c280a8 100644 --- a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp +++ b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp @@ -5,28 +5,30 @@ #include #include +#include "utils/blueprints/layout_blueprints.hpp" + #include #include -#include +#include #include -#include #include +#include using namespace fiction; +using layout = sidb_100_cell_clk_lyt_siqad; + TEST_CASE("Single SiDB", "[assess-physical-population-stability]") { - sidb_cell_clk_lyt_siqad lyt{}; + layout lyt{}; lyt.assign_cell_type({1, 1, 0}, sidb_technology::cell_type::NORMAL); - const sidb_100_cell_clk_lyt_siqad lat{lyt}; - SECTION("Precision of distance_corresponding_to_potential is two") { const auto params = assess_physical_population_stability_params{sidb_simulation_parameters{2, -0.29}, 2}; - const auto result = assess_physical_population_stability(lat, params); + const auto result = assess_physical_population_stability(lyt, params); REQUIRE(result.size() == 1); - const auto& population_stability_detail = result.front(); + const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{1, 1, 0}); REQUIRE(population_stability_detail.transition_from_to_with_cell_and_required_pot.size() == 1); CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot @@ -44,7 +46,7 @@ TEST_CASE("Single SiDB", "[assess-physical-population-stability]") SECTION("Precision of distance_corresponding_to_potential is three") { const auto params = assess_physical_population_stability_params{sidb_simulation_parameters{2, -0.29}, 3}; - const auto result = assess_physical_population_stability(lat, params); + const auto result = assess_physical_population_stability(lyt, params); REQUIRE(result.size() == 1); const auto& population_stability_detail = result[0]; REQUIRE_THAT( @@ -53,20 +55,15 @@ TEST_CASE("Single SiDB", "[assess-physical-population-stability]") } } -TEMPLATE_TEST_CASE( - "Three SiDBs with positive charge states", "[assess-physical-population-stability]", - (cell_level_layout>>), - (charge_distribution_surface>>>)) +TEST_CASE("Three SiDBs with positive charge states", "[assess-physical-population-stability]") { - sidb_cell_clk_lyt_siqad lyt{}; - const auto params = assess_physical_population_stability_params{}; + layout lyt{}; + const auto params = assess_physical_population_stability_params{}; lyt.assign_cell_type({1, 1, 0}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({1, 1, 1}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::NORMAL); - const sidb_100_cell_clk_lyt_siqad lat{lyt}; - - const auto result = assess_physical_population_stability(lat, params); + const auto result = assess_physical_population_stability(lyt, params); REQUIRE(result.size() == 3); SECTION("Check correct energy order") @@ -96,359 +93,196 @@ TEMPLATE_TEST_CASE( population_stability_detail.distance_corresponding_to_potential.at(transition_type::POSITIVE_TO_NEUTRAL), Catch::Matchers::WithinAbs(0.31, 1e-5)); } -// SECTION("1st excited state") -// { -// const auto& population_stability_detail = result[1]; -// CHECK(population_stability_detail.critical_cell == siqad::coord_t{2, 1, 0}); -// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == -// transition_type::NEGATIVE_TO_NEUTRAL); -// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.23); -// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, -// Catch::Matchers::WithinAbs(0.94, 1e-5)); -// } -// -// SECTION("2nd excited state") -// { -// const auto& population_stability_detail = result[2]; -// CHECK(population_stability_detail.critical_cell == siqad::coord_t{1, 1, 1}); -// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot == -// transition_type::NEUTRAL_TO_NEGATIVE); -// CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.21); -// REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, -// Catch::Matchers::WithinAbs(1.01, 1e-5)); -// } + SECTION("1st excited state") + { + const auto& population_stability_detail = result[1]; + CHECK(population_stability_detail.critical_cell == siqad::coord_t{2, 1, 0}); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEGATIVE_TO_NEUTRAL), + Catch::Matchers::WithinAbs(0.94, 1e-5)); + } + + SECTION("2nd excited state") + { + const auto& population_stability_detail = result[2]; + CHECK(population_stability_detail.critical_cell == siqad::coord_t{1, 1, 1}); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), + Catch::Matchers::WithinAbs(1.01, 1e-5)); + } } -TEMPLATE_TEST_CASE( - "Bestagon AND gate", "[assess-physical-population-stability]", - (cell_level_layout>>), - (charge_distribution_surface>>>)) +TEST_CASE("Bestagon AND gate", "[assess-physical-population-stability]") { - sidb_cell_clk_lyt_siqad lyt{}; - const auto params = assess_physical_population_stability_params{}; + layout lyt{}; + const auto params = assess_physical_population_stability_params{}; lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); + lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); + lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); + lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); - sidb_100_cell_clk_lyt_siqad lat{lyt}; + lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); SECTION("no input specified") { - const auto result = assess_physical_population_stability(lat, params); + const auto result = assess_physical_population_stability(lyt, params); REQUIRE(result.size() == 8); - const auto& population_stability_detail = result[0]; + const auto& population_stability_detail = result.at(0); CHECK(population_stability_detail.critical_cell == siqad::coord_t{2, 1, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.021); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(4.79, 1e-5)); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), + Catch::Matchers::WithinAbs(4.79, 1e-5)); } SECTION("input 00") { - lat.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); - lat.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::EMPTY); - const auto result = assess_physical_population_stability(lat, params); + lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); + lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::EMPTY); + const auto result = assess_physical_population_stability(lyt, params); REQUIRE(result.size() == 2); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 5, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.026); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(4.32, 1e-5)); + CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( + transition_type::NEUTRAL_TO_NEGATIVE) < 0.026); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), + Catch::Matchers::WithinAbs(4.32, 1e-5)); } SECTION("input 01") { - lat.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); - lat.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::EMPTY); + lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); + lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::EMPTY); - const auto result = assess_physical_population_stability(lat, params); + const auto result = assess_physical_population_stability(lyt, params); REQUIRE(result.size() == 4); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{32, 18, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.041); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(3.3, 1e-5)); + CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( + transition_type::NEUTRAL_TO_NEGATIVE) < 0.041); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), + Catch::Matchers::WithinAbs(3.3, 1e-5)); } SECTION("input 10") { - lat.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::EMPTY); - lat.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::EMPTY); + lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::EMPTY); + lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::EMPTY); - const auto result = assess_physical_population_stability(lat, params); + const auto result = assess_physical_population_stability(lyt, params); REQUIRE(result.size() == 8); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{19, 8, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.02); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(4.87, 1e-5)); + CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( + transition_type::NEUTRAL_TO_NEGATIVE) < 0.02); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), + Catch::Matchers::WithinAbs(4.87, 1e-5)); } SECTION("input 11") { - lat.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); - lat.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::EMPTY); + lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::EMPTY); + lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::EMPTY); - const auto result = assess_physical_population_stability(lat, params); + const auto result = assess_physical_population_stability(lyt, params); REQUIRE(result.size() == 2); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 5, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.026); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(4.32, 1e-5)); + CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( + transition_type::NEUTRAL_TO_NEGATIVE) < 0.026); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), + Catch::Matchers::WithinAbs(4.32, 1e-5)); } } -TEMPLATE_TEST_CASE( - "Bestagon CROSSING gate input 11, using siqad coordinates", "[assess-physical-population-stability]", - (cell_level_layout>>), - (charge_distribution_surface>>>)) +TEST_CASE("Bestagon CROSSING gate input 11, using siqad coordinates", "[assess-physical-population-stability]") { - sidb_cell_clk_lyt_siqad lyt{}; - const auto params = assess_physical_population_stability_params{}; - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({20, 12, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 11, 1}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({14, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({12, 16, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 13, 1}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({16, 13, 1}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({20, 8, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({6, 18, 0}, sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({8, 17, 0}, sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type({2, 19, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + const auto params = assess_physical_population_stability_params{}; + auto lyt = blueprints::bestagon_crossing_gate(); - const sidb_100_cell_clk_lyt_siqad lat{lyt}; + lyt.assign_cell_type({0, 0, 0}, layout::technology::cell_type::EMPTY); + lyt.assign_cell_type({38, 0, 0}, layout::technology::cell_type::EMPTY); CHECK(lyt.num_cells() == 27); - const auto result = assess_physical_population_stability(lat, params); + const auto result = assess_physical_population_stability(lyt, params); REQUIRE(result.size() == 20); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 9, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.01); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(6.88, 1e-5)); + CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( + transition_type::NEUTRAL_TO_NEGATIVE) < 0.01); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), + Catch::Matchers::WithinAbs(6.88, 1e-5)); } TEST_CASE("Bestagon CROSSING gate input 11, using cube coordinates", "[assess-physical-population-stability]") { - sidb_cell_clk_lyt_cube lyt{}; - const auto params = assess_physical_population_stability_params{}; - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 1, 0}), - sidb_technology::cell_type::INPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 1, 0}), - sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 2, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 12, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 3, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 5, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 11, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 4, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 15, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 4, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 9, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 15, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 16, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{18, 9, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 16, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 13, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 5, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 3, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{16, 13, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 2, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 8, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 17, 0}), - sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 18, 0}), - sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 18, 0}), - sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 17, 0}), - sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 19, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 19, 0}), - sidb_technology::cell_type::NORMAL); + auto lyt = blueprints::bestagon_crossing_gate(); - CHECK(lyt.num_cells() == 27); + lyt.assign_cell_type({0, 0, 0}, layout::technology::cell_type::EMPTY); + lyt.assign_cell_type({38, 0, 0}, layout::technology::cell_type::EMPTY); - const sidb_lattice lat{lyt}; + const auto lyt_cube = convert_to_fiction_coordinates(lyt); + + CHECK(lyt.num_cells() == 27); - const auto result = assess_physical_population_stability(lat, params); + const auto result = assess_physical_population_stability(lyt_cube, params); REQUIRE(result.size() == 20); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == cube::coord_t{14, 18, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.01); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(6.88, 1e-5)); + CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( + transition_type::NEUTRAL_TO_NEGATIVE) < 0.01); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), + Catch::Matchers::WithinAbs(6.88, 1e-5)); } TEST_CASE("Bestagon CROSSING gate input 11, using offset coordinates", "[assess-physical-population-stability]") { - sidb_100_cell_clk_lyt lyt{}; - const auto params = assess_physical_population_stability_params{}; - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 1, 0}), - sidb_technology::cell_type::INPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 1, 0}), - sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 2, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 12, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 3, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 5, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 11, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 4, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 15, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 4, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{14, 9, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 15, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{12, 16, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{18, 9, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{26, 16, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 13, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{24, 5, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 3, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{16, 13, 1}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 2, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{20, 8, 0}), - sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{30, 17, 0}), - sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{6, 18, 0}), - sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{32, 18, 0}), - sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{8, 17, 0}), - sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{2, 19, 0}), - sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{36, 19, 0}), - sidb_technology::cell_type::NORMAL); + auto lyt = blueprints::bestagon_crossing_gate(); - CHECK(lyt.num_cells() == 27); + lyt.assign_cell_type({0, 0, 0}, layout::technology::cell_type::EMPTY); + lyt.assign_cell_type({38, 0, 0}, layout::technology::cell_type::EMPTY); - const sidb_lattice lat{lyt}; + const auto lyt_offset = convert_to_fiction_coordinates(lyt); + + CHECK(lyt.num_cells() == 27); - const auto result = assess_physical_population_stability(lat, params); + const auto result = assess_physical_population_stability(lyt_offset, params); REQUIRE(result.size() == 20); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == offset::ucoord_t{14, 18, 0}); - CHECK(population_stability_detail.transition_from_to == transition_type::NEUTRAL_TO_NEGATIVE); - CHECK(population_stability_detail.minimum_potential_difference_to_transition < 0.01); - REQUIRE_THAT(population_stability_detail.distance_corresponding_to_potential, - Catch::Matchers::WithinAbs(6.88, 1e-5)); + CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( + transition_type::NEUTRAL_TO_NEGATIVE) < 0.01); + REQUIRE_THAT( + population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), + Catch::Matchers::WithinAbs(6.88, 1e-5)); } diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp index 330fcbc82..a1ed8f6f4 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp @@ -18,8 +18,6 @@ #include #include #include -#include -#include #include using namespace fiction; @@ -177,51 +175,3 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio CHECK_THAT(distance, Catch::Matchers::WithinAbs(2.8999201713, physical_constants::POP_STABILITY_ERR)); } } - -TEST_CASE("Bestagon AND Gate influence distance function", "[maximum-defect-influence-position-and-distance]") -{ - sidb_cell_clk_lyt_siqad lyt{}; - - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - - const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, 5.6, 5.0}; - const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{2, -0.32}, {20, 4}}; - - SECTION("input 00") - { - maximum_defect_influence_distance_stats stats{}; - const auto [defect_pos, distance] = maximum_defect_influence_position_and_distance(lyt, sim_params, &stats); - std::cout << fmt::format("{} {} {} {}", defect_pos.x, defect_pos.y, defect_pos.z, distance) << std::endl; - CHECK(mockturtle::to_seconds(stats.time_total) > 0.0); - } - SECTION("input 01") {} - SECTION("input 10") {} - SECTION("input 11") {} -} diff --git a/test/algorithms/simulation/sidb/operational_domain.cpp b/test/algorithms/simulation/sidb/operational_domain.cpp index aa812f874..c92e723e8 100644 --- a/test/algorithms/simulation/sidb/operational_domain.cpp +++ b/test/algorithms/simulation/sidb/operational_domain.cpp @@ -134,7 +134,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() == 1); @@ -151,7 +151,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() == 1); @@ -215,7 +215,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() == 100); @@ -232,7 +232,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() <= 100); @@ -297,7 +297,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() == 50); @@ -314,7 +314,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() <= 50); @@ -379,7 +379,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 25, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct maximum size CHECK(op_domain.operational_values.size() <= 100); @@ -397,7 +397,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 25, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct maximum size CHECK(op_domain.operational_values.size() <= 25); @@ -426,7 +426,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 10000, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() == 3); @@ -482,7 +482,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 50, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() <= 256); @@ -499,7 +499,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 50, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 256); @@ -594,8 +594,11 @@ TEST_CASE("SiQAD's AND gate operational domain computation", "[operational-domai } SECTION("flood_fill") { - const auto op_domain = - operational_domain_flood_fill(lat, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); + const auto op_domain = operational_domain_flood_fill( + lat, std::vector{create_and_tt()}, 1, op_domain_params, + operational_domain::parameter_point{op_domain_params.simulation_parameters.epsilon_r, + op_domain_params.simulation_parameters.lambda_tf}, + &op_domain_stats); // check if the operational domain has the correct size (10 steps in each dimension) CHECK(op_domain.operational_values.size() == 100); @@ -612,7 +615,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation", "[operational-domai SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_and_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 100); @@ -717,8 +720,11 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat } SECTION("flood_fill") { - const auto op_domain = - operational_domain_flood_fill(lat, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); + const auto op_domain = operational_domain_flood_fill( + lat, std::vector{create_and_tt()}, 1, op_domain_params, + operational_domain::parameter_point{op_domain_params.simulation_parameters.epsilon_r, + op_domain_params.simulation_parameters.lambda_tf}, + &op_domain_stats); // check if the operational domain has the correct size (10 steps in each dimension) CHECK(op_domain.operational_values.size() == 100); @@ -734,8 +740,11 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat } SECTION("contour_tracing") { - const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_and_tt()}, 1, - op_domain_params, &op_domain_stats); + const auto op_domain = operational_domain_contour_tracing( + lat, std::vector{create_and_tt()}, 1, op_domain_params, + operational_domain::parameter_point{op_domain_params.simulation_parameters.epsilon_r, + op_domain_params.simulation_parameters.lambda_tf}, + &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 100); @@ -809,8 +818,11 @@ TEMPLATE_TEST_CASE("AND gate on the H-Si(111)-1x1 surface", "[operational-domain } SECTION("flood_fill") { - const auto op_domain = operational_domain_flood_fill(layout, std::vector{create_and_tt()}, 1, - op_domain_params, &op_domain_stats); + const auto op_domain = operational_domain_flood_fill( + layout, std::vector{create_and_tt()}, 1, op_domain_params, + operational_domain::parameter_point{op_domain_params.simulation_parameters.epsilon_r, + op_domain_params.simulation_parameters.lambda_tf}, + &op_domain_stats); // check if the operational domain has the correct size (10 steps in each dimension) CHECK(op_domain.operational_values.size() == 4); @@ -827,7 +839,7 @@ TEMPLATE_TEST_CASE("AND gate on the H-Si(111)-1x1 surface", "[operational-domain SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(layout, std::vector{create_and_tt()}, 1, - op_domain_params, &op_domain_stats); + op_domain_params, std::nullopt, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 4); diff --git a/test/utils/blueprints/layout_blueprints.hpp b/test/utils/blueprints/layout_blueprints.hpp index 11b677c6e..8c00a0bb4 100644 --- a/test/utils/blueprints/layout_blueprints.hpp +++ b/test/utils/blueprints/layout_blueprints.hpp @@ -730,6 +730,55 @@ Lyt and_gate_111() noexcept return lyt; }; +template +Lyt bestagon_crossing_gate() noexcept +{ + static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::is_sidb_lattice_100_v, "Lyt should have 111 as lattice orientation"); + + Lyt lyt{}; + + lyt.assign_cell_type({36, 1, 0}, Lyt::cell_type::INPUT); + lyt.assign_cell_type({2, 1, 0}, Lyt::cell_type::INPUT); + + lyt.assign_cell_type({6, 2, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({20, 12, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({8, 3, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({14, 5, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({14, 11, 1}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({12, 4, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({14, 15, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({26, 4, 0}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({14, 9, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({12, 16, 0}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({18, 9, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({24, 13, 1}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({24, 5, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({30, 3, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({16, 13, 1}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({32, 2, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({20, 8, 0}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({30, 17, 0}, Lyt::cell_type::OUTPUT); + lyt.assign_cell_type({6, 18, 0}, Lyt::cell_type::OUTPUT); + + lyt.assign_cell_type({32, 18, 0}, Lyt::cell_type::OUTPUT); + lyt.assign_cell_type({8, 17, 0}, Lyt::cell_type::OUTPUT); + + lyt.assign_cell_type({2, 19, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({36, 19, 0}, Lyt::cell_type::NORMAL); + + return lyt; +}; + } // namespace blueprints #endif // FICTION_LAYOUT_BLUEPRINTS_HPP diff --git a/test/utils/math_utils.cpp b/test/utils/math_utils.cpp index b08dcf00e..deab022ee 100644 --- a/test/utils/math_utils.cpp +++ b/test/utils/math_utils.cpp @@ -3,6 +3,7 @@ // #include +#include #include @@ -112,3 +113,24 @@ TEST_CASE("Binomial Coefficient Tests") REQUIRE(result == 126410606437752); // C(50, 25) = 126,410,606,437,752 } } + +using namespace fiction; + +TEST_CASE("Cost function chi calculation", "[cost_function_chi]") +{ + SECTION("Valid input") + { + std::vector chis = {0.2, 0.3, 0.5}; + std::vector weights = {0.1, 0.5, 0.4}; + double expected_chi = 0.2 * 0.1 + 0.3 * 0.5 + 0.5 * 0.4; // Expected result: 0.39 + REQUIRE_THAT(cost_function_chi(chis, weights), Catch::Matchers::WithinAbs(expected_chi, 1e-5)); + } + + SECTION("Invalid input: Different sizes") + { + std::vector chis = {0.2, 0.3, 0.5}; + std::vector weights = {0.1, 0.5}; // Different size than chis + + REQUIRE_THROWS_AS(cost_function_chi(chis, weights), std::invalid_argument); + } +} From 9e1ab4941df18ed937975bb3aa3c90263e2c2c55 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 26 Apr 2024 15:29:25 +0200 Subject: [PATCH 041/221] :art: small changes. --- .../simulation/sidb/assess_physical_population_stability.hpp | 2 +- .../sidb/assess_physical_population_stability_sidb_gate.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 4b9041aa1..5c48632b9 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -390,4 +390,4 @@ namespace fiction { } // namespace fiction -#endif // FICTION_ASSESS_PHYSICAL_POPULATION_STABILITY_HPP \ No newline at end of file +#endif // FICTION_ASSESS_PHYSICAL_POPULATION_STABILITY_HPP diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp b/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp index 20df97e0f..fdd5cb864 100644 --- a/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp +++ b/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp @@ -74,4 +74,4 @@ TEST_CASE("Single SiDB", "[assess-physical-population-stability]") // transition_type::NEGATIVE_TO_NEUTRAL), // Catch::Matchers::WithinAbs(0.77, 1e-5)); } -} \ No newline at end of file +} From 4dbf67f495c7c33ad0e945b2c8b85028dbccf6e5 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 26 Apr 2024 16:29:19 +0200 Subject: [PATCH 042/221] :art: small changes. --- ...nce_position_and_distance_of_sidb_gate.hpp | 1 - ...nce_position_and_distance_of_sidb_gate.cpp | 41 +++---------------- test/utils/blueprints/layout_blueprints.hpp | 31 ++++++++++++++ 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index 45a21e4c1..b1e9987c2 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -46,7 +46,6 @@ template maximum_defect_influence_distance_stats stats_defect{}; const auto influence_cell_distance = maximum_defect_influence_position_and_distance(lyt, params.defect_influence_params, &stats_defect); - std::cout << mockturtle::to_seconds(stats_defect.time_total) << std::endl; if (influence_cell_distance.second > maximum_defect_influence_distance) { maximum_defect_influence_distance = influence_cell_distance.second; diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp index 36ae9e10b..fbf46fd15 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp @@ -5,7 +5,7 @@ #include #include -#include "mockturtle/utils/stopwatch.hpp" +#include "utils/blueprints/layout_blueprints.hpp" #include #include @@ -21,36 +21,7 @@ using namespace fiction; TEST_CASE("Test influence distance function for Gate") { - sidb_cell_clk_lyt_siqad lyt{}; - - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + const auto lyt = blueprints::siqad_and_gate(); const maximum_defect_influence_position_and_distance_of_sidb_gate_params defect_avoidance_params_vacancy{ maximum_defect_influence_position_and_distance_of_sidb_gate_params{ @@ -66,8 +37,8 @@ TEST_CASE("Test influence distance function for Gate") const auto cell_distance_arsenic = maximum_defect_influence_position_and_distance_of_sidb_gate( lyt, std::vector{create_or_tt()}, defect_avoidance_params_arsenic); - CHECK(cell_distance_vacancy.first == siqad::coord_t{6, 13, 1}); - CHECK(cell_distance_arsenic.first == siqad::coord_t{12, 8, 0}); - CHECK_THAT(std::abs(cell_distance_vacancy.second - 4.857), Catch::Matchers::WithinAbs(0.00, 0.01)); - CHECK_THAT(std::abs(cell_distance_arsenic.second - 2.428), Catch::Matchers::WithinAbs(0.00, 0.01)); + CHECK(cell_distance_vacancy.first == siqad::coord_t{-4, 3, 1}); + CHECK(cell_distance_arsenic.first == siqad::coord_t{3, 6, 0}); + CHECK_THAT(std::abs(cell_distance_vacancy.second - 2.769), Catch::Matchers::WithinAbs(0.00, 0.01)); + CHECK_THAT(std::abs(cell_distance_arsenic.second - 2.376), Catch::Matchers::WithinAbs(0.00, 0.01)); } diff --git a/test/utils/blueprints/layout_blueprints.hpp b/test/utils/blueprints/layout_blueprints.hpp index 8c00a0bb4..fdba2a6e5 100644 --- a/test/utils/blueprints/layout_blueprints.hpp +++ b/test/utils/blueprints/layout_blueprints.hpp @@ -680,6 +680,37 @@ CellLyt single_layer_inml_crosswire() noexcept return layout; } +/** + * This layout represents the AND Gate, as proposed in the paper + * titled \"SiQAD: A Design and Simulation Tool for Atomic Silicon Quantum Dot Circuits\". + */ +template +Lyt siqad_and_gate() noexcept +{ + static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + + Lyt lyt{}; + + lyt.assign_cell_type({0, 0, 1}, Lyt::cell_type::INPUT); + lyt.assign_cell_type({2, 1, 1}, Lyt::cell_type::INPUT); + + lyt.assign_cell_type({20, 0, 1}, Lyt::cell_type::INPUT); + lyt.assign_cell_type({18, 1, 1}, Lyt::cell_type::INPUT); + + lyt.assign_cell_type({4, 2, 1}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({6, 3, 1}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({14, 3, 1}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({16, 2, 1}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({10, 6, 0}, Lyt::cell_type::OUTPUT); + lyt.assign_cell_type({10, 7, 0}, Lyt::cell_type::OUTPUT); + + lyt.assign_cell_type({10, 9, 1}, Lyt::cell_type::NORMAL); + + return lyt; +}; /** * This layout represents the AND Gate implemented on the H-Si(111)-1x1 surface, as proposed in the paper * titled \"Unlocking Flexible Silicon Dangling Bond Logic Designs on Alternative Silicon Orientations\" authored by From 1ab11c2fb960b6290dd7761864af0967d67325f5 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 26 Apr 2024 16:41:44 +0200 Subject: [PATCH 043/221] :art: small changes. --- docs/algorithms/sidb_simulation.rst | 8 +++++++ ...nce_position_and_distance_of_sidb_gate.hpp | 23 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 9ddcb1148..daa59137d 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -378,4 +378,12 @@ Maximum Minimum Defect Influence Distance **Header:** ``fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp`` +.. doxygenstruct:: fiction::maximum_minimum_defect_influence_distance_params + :members: .. doxygenfunction:: fiction::maximum_minimum_defect_influence_distance + +**Header:** ``fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance_of_sidb_gate.hpp`` + +.. doxygenstruct:: fiction::maximum_defect_influence_position_and_distance_of_sidb_gate_params + :members: +.. doxygenfunction:: fiction::maximum_defect_influence_position_and_distance_of_sidb_gate diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index b1e9987c2..c11a44fe8 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -13,12 +13,33 @@ namespace fiction { +/** + * Parameters for the `maximum_defect_influence_position_and_distance_of_sidb_gate` algorithm. + */ struct maximum_defect_influence_position_and_distance_of_sidb_gate_params { + /** + * Parameters for the defect influence simulation. + */ maximum_defect_influence_distance_params defect_influence_params{}; - detect_bdl_pairs_params bdl_pairs_params{}; + /** + * Parameters for the detection of BDL pairs. + */ + detect_bdl_pairs_params bdl_pairs_params{}; }; +/** + * This function calculates the maximum influence position and distance of a defect on the ground state + * of an SiDB gate layout. It iterates over all input combinations and finds the defect position at maximum position + * that affects the gate's behavior. + * + * @tparam Lyt Lyt SiDB cell-level layout type. + * @tparam TT Truth table type. + * @param lyt Layout to compute the maximum defect influence position and distance for. + * @param spec Expected Boolean function of the layout given as a multi-output truth table. + * @param params Parameters for the defect influence simulation and BDL pair detection. + * @return A pair containing the maximum influence defect position and its distance from the layout/gate. + */ template [[nodiscard]] std::pair maximum_defect_influence_position_and_distance_of_sidb_gate( const Lyt& lyt, const std::vector& spec, From 9d30215d7451142c0a4d9e88a316ab7bf005826f Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 26 Apr 2024 16:52:06 +0200 Subject: [PATCH 044/221] :memo: update docu. --- docs/algorithms/sidb_simulation.rst | 15 +++++++ docs/utils/utils.rst | 1 + .../defect_influence_operational_domain.hpp | 40 +++++++++---------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index daa59137d..998084b4c 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -271,6 +271,21 @@ Operational Domain Computation .. autofunction:: mnt.pyfiction.operational_domain_contour_tracing +Defect Influence Operational Domain +################################### + +**Header:** ``fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp`` + +.. doxygenstruct:: fiction::defect_operational_domain_params + :members: +.. doxygenstruct:: fiction::defect_influence_operational_domain + :members: +.. doxygenstruct:: fiction::defect_influence_operational_stats + :members: +.. doxygenfunction:: fiction::defect_influence_operational_domain_grid_search +.. doxygenfunction:: fiction::defect_influence_operational_domain_random_sampling +.. doxygenfunction:: fiction::defect_influence_operational_domain_contour_tracing + Utility Functions ################# diff --git a/docs/utils/utils.rst b/docs/utils/utils.rst index e6813fd36..cbef91eef 100644 --- a/docs/utils/utils.rst +++ b/docs/utils/utils.rst @@ -252,6 +252,7 @@ Math Utils .. doxygenfunction:: fiction::integral_abs .. doxygenfunction:: fiction::binomial_coefficient .. doxygenfunction:: fiction::determine_all_combinations_of_distributing_k_entities_on_n_positions +.. doxygenfunction:: fiction::cost_function_chi ``phmap`` --------- diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index e69ebd422..f488df6ad 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -581,22 +581,22 @@ class defect_influence_impl * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed * to be in the same order as the inputs of the truth table. * - * // TODO + * This algorithm uses a grid search to determine the defect influence operational domain. The grid search is performed + * by exhaustively sweeping all possible atomic defect positions in x and y dimensions. * * @tparam Lyt SiDB cell-level layout type. * @tparam TT Truth table type. * @param lyt Layout to compute the defect influence operational domain for. * @param spec Expected Boolean function of the layout given as a multi-output truth table. - * @param samples Number of samples to perform. * @param params Defect influence operational domain computation parameters. * @param stats Operational domain computation statistics. - * @return The (partial) defect influence operational domain of the layout. + * @return The defect influence operational domain of the layout. */ template defect_influence_operational_domain -defect_influence_operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, std::size_t samples, - const defect_operational_domain_params& params = {}, - defect_influence_operational_stats* stats = nullptr) +defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vector& spec, std::size_t step_size = 1, + const defect_operational_domain_params& params = {}, + defect_influence_operational_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -606,7 +606,7 @@ defect_influence_operational_domain_contour_tracing(const Lyt& lyt, const std::v defect_influence_operational_stats st{}; detail::defect_influence_impl p{lyt, spec, params, st}; - const auto result = p.contour_tracing(samples); + const auto result = p.grid_search(step_size); if (stats) { @@ -622,32 +622,33 @@ defect_influence_operational_domain_contour_tracing(const Lyt& lyt, const std::v * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed * to be in the same order as the inputs of the truth table. * - * This algorithm uses a grid search to determine the defect influence operational domain. The grid search is performed - * by exhaustively sweeping all possible atomic defect positions in x and y dimensions. + * This algorithm uses random sampling to find a part of the defect influence operational domain that might not be + * complete. It performs a total of `samples` uniformly-distributed random samples within the a specified area. * * @tparam Lyt SiDB cell-level layout type. * @tparam TT Truth table type. * @param lyt Layout to compute the defect influence operational domain for. * @param spec Expected Boolean function of the layout given as a multi-output truth table. + * @param samples Number of samples to perform. * @param params Defect influence operational domain computation parameters. * @param stats Operational domain computation statistics. - * @return The defect influence operational domain of the layout. + * @return The (partial) defect influence operational domain of the layout. */ template defect_influence_operational_domain -defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vector& spec, std::size_t step_size = 1, - const defect_operational_domain_params& params = {}, - defect_influence_operational_stats* stats = nullptr) +defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::vector& spec, std::size_t samples, + const defect_operational_domain_params& params = {}, + defect_influence_operational_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); - static_assert(has_cube_coord_v || has_siqad_coord_v, "Lyt is not based on cube coordinates"); + static_assert(has_cube_coord_v, "Lyt is not based on cube coordinates"); defect_influence_operational_stats st{}; detail::defect_influence_impl p{lyt, spec, params, st}; - const auto result = p.grid_search(step_size); + const auto result = p.random_sampling(samples); if (stats) { @@ -663,8 +664,7 @@ defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vecto * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed * to be in the same order as the inputs of the truth table. * - * This algorithm uses random sampling to find a part of the defect influence operational domain that might not be - * complete. It performs a total of `samples` uniformly-distributed random samples within the a specified area. + * // TODO * * @tparam Lyt SiDB cell-level layout type. * @tparam TT Truth table type. @@ -677,19 +677,19 @@ defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vecto */ template defect_influence_operational_domain -defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::vector& spec, std::size_t samples, +defect_influence_operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, std::size_t samples, const defect_operational_domain_params& params = {}, defect_influence_operational_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); - static_assert(has_cube_coord_v, "Lyt is not based on cube coordinates"); + static_assert(has_cube_coord_v || has_siqad_coord_v, "Lyt is not based on cube coordinates"); defect_influence_operational_stats st{}; detail::defect_influence_impl p{lyt, spec, params, st}; - const auto result = p.random_sampling(samples); + const auto result = p.contour_tracing(samples); if (stats) { From 7b1e331601397ec7d2b9fed8e4520a1cc74edb38 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 26 Apr 2024 16:58:02 +0200 Subject: [PATCH 045/221] :art: small fix. --- .../fiction/algorithms/physical_design/design_sidb_gates.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 22a5748fe..85bf36e2a 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -375,9 +375,6 @@ class design_sidb_gates_impl std::vector old_canvas_sidbs; std::pair swaped_pair{}; - - double logical_cost{}; - /** * A random-number generator. */ @@ -492,7 +489,7 @@ class design_sidb_gates_impl * * The `exhaustive design` is composed of three steps: * 1. In the initial step, all possible distributions of `number_of_sidbs` SiDBs within a given canvas are - * exhaustively determined. This ensures exhaustive coverage of every potential arrangement of ``number_of_sidbs`` SiDBs + * exhaustively determined. This ensures exhaustive coverage of every potential arrangement of `number_of_sidbs` SiDBs * across the canvas. * 2. The calculated SiDB distributions are then incorporated into the skeleton, resulting in the generation of distinct * SiDB layouts. From 59c1777599fdf553184d97b98486503d20721130 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 07:23:39 +0200 Subject: [PATCH 046/221] :memo: update docu. --- ..._defect_influence_position_and_distance_of_sidb_gate.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index c11a44fe8..4218e7e97 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -31,7 +31,11 @@ struct maximum_defect_influence_position_and_distance_of_sidb_gate_params /** * This function calculates the maximum influence position and distance of a defect on the ground state * of an SiDB gate layout. It iterates over all input combinations and finds the defect position at maximum position - * that affects the gate's behavior. + * that affects the gate's ground state. + * + * @Note The defect influence distance describes the distance at which an defect influences the ground state. It does + * check when the successful operation starts to fail, since a change in the ground state can still lead to an + * operational gate. * * @tparam Lyt Lyt SiDB cell-level layout type. * @tparam TT Truth table type. From cfc687e379272269a3c28433aebb4dd9521ceab7 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 07:38:29 +0200 Subject: [PATCH 047/221] :fire: delete experiments. --- experiments/gate_generator_exhaustive.cpp | 391 ---------------------- experiments/gate_generator_with_sa.cpp | 114 ------- 2 files changed, 505 deletions(-) delete mode 100644 experiments/gate_generator_exhaustive.cpp delete mode 100644 experiments/gate_generator_with_sa.cpp diff --git a/experiments/gate_generator_exhaustive.cpp b/experiments/gate_generator_exhaustive.cpp deleted file mode 100644 index 01a56003e..000000000 --- a/experiments/gate_generator_exhaustive.cpp +++ /dev/null @@ -1,391 +0,0 @@ -// -// Created by Jan Drewniok 01.01.23 -// - -// pre-defined types suitable for the FCN domain -#include "mockturtle/utils/stopwatch.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace fiction; - -int main() // NOLINT -{ - using Lyt = sidb_cell_clk_lyt_siqad; - - static const std::string folder = - fmt::format("{}skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd", EXPERIMENTS_PATH); - - static const std::string solution_folder = fmt::format("{}metric_data_final/", EXPERIMENTS_PATH); - - const auto skeleton = read_sqd_layout(folder); - - design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, - design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, - {{17, 7, 0}, {21, 11, 0}}, - 1, - sidb_simulation_engine::QUICKEXACT}; - - params.maximal_random_solutions = 100; - - const auto truth_tables = std::vector>{std::vector{create_and_tt()}, - std::vector{create_xor_tt()}, std::vector{create_or_tt()}, - std::vector{create_xnor_tt()}, std::vector{create_nor_tt()}, std::vector{create_nand_tt()}, - std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, - std::vector{create_ge_tt()}}; - - const std::vector gate_names = {"and", "xor", "or", "xnor", "nor", "nand", "lt", "gt", "le", "ge"}; - - // const auto truth_tables = - // std::vector>{std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, - // std::vector{create_le_tt()}, std::vector{create_ge_tt()}}; - - // const auto truth_tables = std::vector>{std::vector{create_nand_tt()}}; - - const critical_temperature_params ct_params{sidb_simulation_parameters{ - 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; - - operational_domain_params op_domain_params{sidb_simulation_parameters{ - 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}; - op_domain_params.x_min = 4.0; - op_domain_params.x_max = 6; - op_domain_params.x_step = 0.2; - - op_domain_params.y_min = 4.0; - op_domain_params.y_max = 6; - op_domain_params.y_step = 0.2; - - const assess_physical_population_stability_params_sidb_gate assess_params{ - assess_physical_population_stability_params{sidb_simulation_parameters{ - 2, params.phys_params.mu_minus, params.phys_params.epsilon_r, params.phys_params.lambda_tf}}}; - - const maximum_defect_influence_distance_params defect_avoidance_params_arsenic{ - sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}, - params.phys_params, - {50, 20}}; - - const maximum_defect_influence_distance_params defect_avoidance_params_vacancy{ - sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}, - params.phys_params, - {50, 20}}; - - uint64_t truth_counter = 0; - - for (const auto& truth_table : truth_tables) - { - std::cout << fmt::format("truth counter: {}", truth_counter) << '\n'; - for (auto num_sidbs = 5u; num_sidbs < 7; num_sidbs++) - { - std::cout << fmt::format("num sidbs: {}", num_sidbs) << '\n'; - params.number_of_sidbs = num_sidbs; - - mockturtle::stopwatch<>::duration time_total{}; - - std::vector all_gate{}; - std::vector temps = {}; - std::vector op_domains = {}; - std::vector defect_influence_arsenic = {}; - std::vector defect_influence_vacancy = {}; - std::vector pop_stability_neutral_to_negative = {}; - std::vector pop_stability_negative_to_neutral = {}; - std::vector runtime = {}; - { - mockturtle::stopwatch stop{time_total}; - - design_sidb_gates_stats stats{}; - - all_gate = design_sidb_gates(skeleton, truth_table, params, &stats); - - std::cout << fmt::format("gate design finished and {} gates were found", all_gate.size()) << '\n'; - - // Define mutex for synchronization - std::mutex mtx; - - const auto calculate_metric_values = [&](const auto& gate_chunk) - { - // Local vectors to store calculated metrics - std::vector temps_local; - temps_local.reserve(gate_chunk.size()); - std::vector op_domains_local; - op_domains_local.reserve(gate_chunk.size()); - std::vector defect_influence_arsenic_local; - defect_influence_arsenic_local.reserve(gate_chunk.size()); - std::vector defect_influence_vacancy_local; - defect_influence_vacancy_local.reserve(gate_chunk.size()); - std::vector pop_stability_neutral_to_negative_local; - pop_stability_neutral_to_negative_local.reserve(gate_chunk.size()); - std::vector pop_stability_negative_to_neutral_local; - pop_stability_negative_to_neutral_local.reserve(gate_chunk.size()); - std::vector runtime_local; - runtime.reserve(gate_chunk.size()); - - for (const auto& gate : gate_chunk) - { - //write_sqd_layout(gate, solution_folder + "/bug/17_7_21_11_numdbs_{}.sqd"); - temps_local.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); - operational_domain_stats op_stats{}; - const auto op_domain = - operational_domain_flood_fill(gate, truth_table, 0, op_domain_params, - operational_domain::parameter_point{5.6, 5}, &op_stats); - op_domains_local.push_back(op_stats.percentual_operational_area); - - defect_influence_stats arsenic_stats{}; - const auto siqad_gate = convert_to_fiction_coordinates(gate); - const auto defect_influence_domain_arsenic = defect_influence_operational_domain_contour_tracing( - siqad_gate, truth_table, 300, - defect_influence_params{ - defect_avoidance_params_arsenic, - is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, - &arsenic_stats); - std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) - << '\n'; - runtime_local.push_back(mockturtle::to_seconds(arsenic_stats.time_total)); - // if (mockturtle::to_seconds(arsenic_stats.time_total) < 0.4) - // { - // write_operational_domain_params write_params{}; - // write_params.operational_tag = "1"; - // write_params.non_operational_tag = "0"; - // write_operational_domain( - // defect_influence_domain_arsenic, - // "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", - // write_params); - // write_sqd_layout( - // gate, - // "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.sqd"); - // } - - defect_influence_arsenic_local.push_back( - maximum_minimum_defect_influence_distance(siqad_gate, defect_influence_domain_arsenic)); - - defect_influence_stats vacancy_stats{}; - const auto defect_influence_domain_vacancy = defect_influence_operational_domain_contour_tracing( - siqad_gate, truth_table, 300, - defect_influence_params{ - defect_avoidance_params_vacancy, - is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, - &vacancy_stats); - defect_influence_vacancy_local.push_back( - maximum_minimum_defect_influence_distance(siqad_gate, defect_influence_domain_vacancy)); - - pop_stability_neutral_to_negative_local.push_back( - assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, -1)); - pop_stability_negative_to_neutral_local.push_back( - assess_physical_population_stability_sidb_gate(gate, truth_table, assess_params, 1)); - } - - // Acquire lock before modifying shared vectors - const std::lock_guard lock(mtx); - - // Append local vectors to global vectors - runtime.insert(runtime.end(), runtime_local.begin(), runtime_local.end()); - temps.insert(temps.end(), temps_local.begin(), temps_local.end()); - op_domains.insert(op_domains.end(), op_domains_local.begin(), op_domains_local.end()); - defect_influence_arsenic.insert(defect_influence_arsenic.end(), - defect_influence_arsenic_local.begin(), - defect_influence_arsenic_local.end()); - defect_influence_vacancy.insert(defect_influence_vacancy.end(), - defect_influence_vacancy_local.begin(), - defect_influence_vacancy_local.end()); - pop_stability_neutral_to_negative.insert(pop_stability_neutral_to_negative.end(), - pop_stability_neutral_to_negative_local.begin(), - pop_stability_neutral_to_negative_local.end()); - pop_stability_negative_to_neutral.insert(pop_stability_negative_to_neutral.end(), - pop_stability_negative_to_neutral_local.begin(), - pop_stability_negative_to_neutral_local.end()); - }; - - // Define the number of threads to use - const size_t num_threads = std::thread::hardware_concurrency(); - const size_t chunk_size = (all_gate.size() + num_threads - 1) / num_threads; // Calculate chunk size - - // A vector to store threads - std::vector threads; - threads.reserve(num_threads); - - // Split the vector into chunks and process each chunk in its own thread - auto gate_it = all_gate.begin(); - for (size_t i = 0; i < num_threads; ++i) - { - auto chunk_start = gate_it; - auto chunk_end = std::min(gate_it + chunk_size, all_gate.end()); - - threads.emplace_back(calculate_metric_values, std::vector(chunk_start, chunk_end)); - - gate_it = chunk_end; - } - - // Wait for all threads to finish - for (auto& thread : threads) - { - thread.join(); - } - - std::cout << "determination is finished" << std::endl; - - // Start asynchronous tasks to process combinations in parallel - // for (const auto& gate : all_gate) - // { - // futures.emplace_back(std::async(std::launch::async, calculate_metric_values, - // gate)); - // } - - // for (const auto& gate : all_gate) - // { - // calculate_metric_values(gate); - // } - - // for each y value in parallel - // std::for_each(FICTION_EXECUTION_POLICY_PAR all_gate.cbegin(), all_gate.cend(), - // [&](const sidb_cell_clk_lyt_siqad &gate) { - // calculate_metric_values(gate); - // }); - - // Wait for all tasks to finish - // for (auto& future : futures) - // { - // future.wait(); - // } - - for (auto l = 0u; l < all_gate.size(); l++) - { - const auto choose_gate = all_gate[l]; - write_sqd_layout(choose_gate, - fmt::format(solution_folder + "/sqd/17_7_21_11_numdbs_{}_{}_{}.sqd", - num_sidbs, gate_names[truth_counter], l)); - } - - // Open a file for writing - std::ofstream csvFile( - fmt::format(solution_folder + "/csv/17_7_21_11_numdbs_{}_{}.csv", num_sidbs, gate_names[truth_counter])); - - // Check if the file is open - if (!csvFile.is_open()) - { - std::cerr << "Error opening output.csv\n"; - return 1; - } - - // Write headers to the CSV file - csvFile << "temp,op,popstab_neg_to_neu,popstab_neu_to_neg,defect_influence_arsenic,defect_influence_" - "vacancy,runtime\n"; - - // Write data to the CSV file and calculate mean, max, min - double meanTemp = 0.0, maxTemp = std::numeric_limits::min(), - minTemp = std::numeric_limits::max(); - double meanOpDomains = 0.0, maxOpDomains = std::numeric_limits::min(), - minOpDomains = std::numeric_limits::max(); - double meanDefectInfluenceArsenic = 0.0, maxDefectInfluenceArsenic = std::numeric_limits::min(), - minDefectInfluenceArsenic = std::numeric_limits::max(); - double meanDefectInfluenceVacancy = 0.0, maxDefectInfluenceVacancy = std::numeric_limits::min(), - minDefectInfluenceVacancy = std::numeric_limits::max(); - double meanPopStabilityNegToNeu = 0.0, maxPopStabilityNegToNeu = std::numeric_limits::min(), - minPopStabilityNegToNeu = std::numeric_limits::max(); - double meanPopStabilityNeuToNeg = 0.0, maxPopStabilityNeuToNeg = std::numeric_limits::min(), - minPopStabilityNeuToNeg = std::numeric_limits::max(); - - for (std::size_t k = 0; k < temps.size(); ++k) - { - csvFile << temps[k] << "," << op_domains[k] << "," << pop_stability_negative_to_neutral[k] << "," - << pop_stability_neutral_to_negative[k] << "," << defect_influence_arsenic[k] << "," - << defect_influence_vacancy[k] << "," << runtime[k] << "\n"; - - // Update mean, max, min for temps - meanTemp += temps[k]; - maxTemp = std::max(maxTemp, temps[k]); - minTemp = std::min(minTemp, temps[k]); - - // Update mean, max, min for op_domains - meanOpDomains += op_domains[k]; - maxOpDomains = std::max(maxOpDomains, op_domains[k]); - minOpDomains = std::min(minOpDomains, op_domains[k]); - - // Update mean, max, min for defect_influence_arsenic - meanDefectInfluenceArsenic += defect_influence_arsenic[k]; - maxDefectInfluenceArsenic = std::max(maxDefectInfluenceArsenic, defect_influence_arsenic[k]); - minDefectInfluenceArsenic = std::min(minDefectInfluenceArsenic, defect_influence_arsenic[k]); - - // Update mean, max, min for defect_influence_vacancy - meanDefectInfluenceVacancy += defect_influence_vacancy[k]; - maxDefectInfluenceVacancy = std::max(maxDefectInfluenceVacancy, defect_influence_vacancy[k]); - minDefectInfluenceVacancy = std::min(minDefectInfluenceVacancy, defect_influence_vacancy[k]); - - // Update mean, max, min for pop_stability_negative_to_neutral - meanPopStabilityNegToNeu += pop_stability_negative_to_neutral[k]; - maxPopStabilityNegToNeu = std::max(maxPopStabilityNegToNeu, pop_stability_negative_to_neutral[k]); - minPopStabilityNegToNeu = std::min(minPopStabilityNegToNeu, pop_stability_negative_to_neutral[k]); - - // Update mean, max, min for pop_stability_neutral_to_negative - meanPopStabilityNeuToNeg += pop_stability_neutral_to_negative[k]; - maxPopStabilityNeuToNeg = std::max(maxPopStabilityNeuToNeg, pop_stability_neutral_to_negative[k]); - minPopStabilityNeuToNeg = std::min(minPopStabilityNeuToNeg, pop_stability_neutral_to_negative[k]); - } - - // Calculate mean for temps, op_domains, and other metrics - meanTemp /= static_cast(temps.size()); - meanOpDomains /= static_cast(op_domains.size()); - meanDefectInfluenceArsenic /= static_cast(defect_influence_arsenic.size()); - meanDefectInfluenceVacancy /= static_cast(defect_influence_vacancy.size()); - meanPopStabilityNegToNeu /= static_cast(pop_stability_negative_to_neutral.size()); - meanPopStabilityNeuToNeg /= static_cast(pop_stability_neutral_to_negative.size()); - - // Output mean, max, min for temps - std::cout << "temp: " << meanTemp << ";" << maxTemp << ";" << minTemp << '\n'; - - // Output mean, max, min for op_domains - std::cout << "op: " << meanOpDomains << ";" << maxOpDomains << ";" << minOpDomains << '\n'; - - // Output mean, max, min for temps - std::cout << "ars: " << meanDefectInfluenceArsenic << ";" << maxDefectInfluenceArsenic << ";" - << minDefectInfluenceArsenic << '\n'; - - // Output mean, max, min for op_domains - std::cout << "vac: " << meanDefectInfluenceVacancy << ";" << maxDefectInfluenceVacancy << ";" - << minDefectInfluenceVacancy << '\n'; - - // Output mean, max, min for temps - std::cout << "pop_neu_to_neg: " << meanPopStabilityNeuToNeg << ";" << maxPopStabilityNeuToNeg << ";" - << minPopStabilityNeuToNeg << '\n'; - - // Output mean, max, min for op_domains - std::cout << "pop_neg_to_neu: " << meanPopStabilityNegToNeu << ";" << maxPopStabilityNegToNeu << ";" - << minPopStabilityNegToNeu << '\n'; - - // Close the file - csvFile.close(); - } - } - truth_counter++; - } - return EXIT_SUCCESS; -} diff --git a/experiments/gate_generator_with_sa.cpp b/experiments/gate_generator_with_sa.cpp deleted file mode 100644 index 8c240b325..000000000 --- a/experiments/gate_generator_with_sa.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// -// Created by Jan Drewniok 01.01.23 -// - -#include "fiction/types.hpp" // pre-defined types suitable for the FCN domain - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace fiction; - -int main() // NOLINT -{ - const auto skeleton = read_sqd_layout( - "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/" - "skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd"); - - // toffoli - // const design_sidb_gates_params params{ - // sidb_simulation_parameters{2, -0.32}, - // design_sidb_gates_params::design_sidb_gates_mode::RANDOM, - // {{9, 0, 0}, {19, 14, 0}}, - // 6, - // sidb_simulation_engine::QUICKEXACT}; - - design_sidb_gates_params params{ - sidb_simulation_parameters{2, -0.32}, - {{17, 7, 0}, {21, 11, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT, - 100}; - - // const auto truth_tables = std::vector>{ - // std::vector{create_and_tt()}, std::vector{create_xor_tt()}, std::vector{create_or_tt()}, - // std::vector{create_xnor_tt()}, std::vector{create_nor_tt()}, std::vector{create_nand_tt()}, - // std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, - // std::vector{create_ge_tt()}}; - - const auto truth_tables = std::vector>{std::vector{create_and_tt()}}; - - // const auto truth_tables - // std::vector>{std::vector{create_id_tt()}, std::vector{create_not_tt()}}; - - const critical_temperature_params ct_params{sidb_simulation_parameters{2, params.simulation_parameters.mu_minus, - params.simulation_parameters.epsilon_r, - params.simulation_parameters.lambda_tf}}; - - operational_domain_params op_domain_params{sidb_simulation_parameters{2, params.simulation_parameters.mu_minus, - params.simulation_parameters.epsilon_r, - params.simulation_parameters.lambda_tf}}; - op_domain_params.x_min = 4.0; - op_domain_params.x_max = 6; - op_domain_params.x_step = 0.2; - - op_domain_params.y_min = 4.0; - op_domain_params.y_max = 6; - op_domain_params.y_step = 0.2; - - design_sidb_gates_sa_params sa_params{}; - - sa_params.ct_params = ct_params; - sa_params.op_params = op_domain_params; - - uint64_t truth_counter = 0; - - for (const auto& truth : truth_tables) - { - std::cout << fmt::format("{} truth table", truth_counter) << std::endl; - for (auto i = 3u; i < 4; i++) - { - double total_time = 0; - double net_cost = 0; - std::cout << fmt::format("{} placed SiDBs", i) << std::endl; - sidb_cell_clk_lyt_siqad gate{}; - for (auto t = 0u; t < 1; t++) - { - params.number_of_sidbs = i; - - design_sidb_gates_stats stats{}; - - gate = design_sidb_gates_metric_driven_simulated_annealing( - skeleton, truth, params, sa_params, &stats); - net_cost += stats.cost_of_gate; - total_time += mockturtle::to_seconds(stats.time_total); - } - const is_operational_params params_is_operational{params.simulation_parameters, params.sim_engine}; - auto result = is_operational(gate, truth, params_is_operational).first == operational_status::OPERATIONAL ? - "operational\n" : - "non_operational\n"; - std::cout << result; - - std::cout << fmt::format("average runtime: {}", total_time / 1) << std::endl; - std::cout << fmt::format("net cost: {}", net_cost / 1) << std::endl; - write_sqd_layout( - gate, "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/gate_design_sa/" + - std::to_string(truth_counter) + ".sqd"); - } - - std::cout << "-----------" << std::endl; - truth_counter++; - } - - return EXIT_SUCCESS; -} From c592a24b58fa274fece6bd34215fe37decbf23dc Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 07:54:47 +0200 Subject: [PATCH 048/221] :fire: small fix. --- .../optimization/simulated_annealing.hpp | 3 ++- .../physical_design/design_sidb_gates.hpp | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/fiction/algorithms/optimization/simulated_annealing.hpp b/include/fiction/algorithms/optimization/simulated_annealing.hpp index 5979f7169..491ee421b 100644 --- a/include/fiction/algorithms/optimization/simulated_annealing.hpp +++ b/include/fiction/algorithms/optimization/simulated_annealing.hpp @@ -199,6 +199,7 @@ multi_simulated_annealing(const double init_temp, const double final_temp, const std::vector> results(instances); std::vector threads; + threads.reserve(instances); // Function to perform simulated annealing and store the result in the results vector auto perform_simulated_annealing = @@ -218,7 +219,7 @@ multi_simulated_annealing(const double init_temp, const double final_temp, const } // Find the minimum result - return *std::min_element(results.cbegin(), results.cend(), + return *std::min_element(FICTION_EXECUTION_POLICY_PAR_UNSEQ results.cbegin(), results.cend(), [](const auto& lhs, const auto& rhs) { return lhs.second < rhs.second; }); } diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 85bf36e2a..6dbe18f09 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -44,7 +44,6 @@ struct design_sidb_gates_sa_params { /** * Type of temperature schedule used in Simulated Annealing. - * Possible values are GEOMETRIC or LINEAR. */ temperature_schedule schedule{temperature_schedule::GEOMETRIC}; /** @@ -69,7 +68,7 @@ struct design_sidb_gates_sa_params operational_domain_params op_params{}; /** * Weight assigned to the critical temperature in the overall cost function. - * A negative value indicates that this weight is not used. + * A negative value indicates that a high critical temperature is preferred. */ double weight_temperature = -1.0; /** @@ -136,8 +135,10 @@ struct design_sidb_gates_stats * The total runtime of SiDB gate design process. */ mockturtle::stopwatch<>::duration time_total{0}; - - double cost_of_gate{}; + /** + * The cost value of the final gate designed with Simulated Annealing. + */ + double gate_cost{}; }; namespace detail @@ -154,6 +155,7 @@ class design_sidb_gates_impl * @param skeleton The skeleton layout used as a basis for gate design. * @param tt Expected Boolean function of the layout given as a multi-output truth table. * @param ps Parameters and settings for the gate designer. + * @param st Statistics for the gate designer. */ design_sidb_gates_impl(const Lyt& skeleton, const std::vector& tt, const design_sidb_gates_params& ps, design_sidb_gates_stats& st) : @@ -282,10 +284,10 @@ class design_sidb_gates_impl /** * Design gates with Simulated Annealing. * - * This function adds cells randomly to the given skeleton, and determines whether the layout is operational - * based on the specified parameters. The design process is parallelized to improve performance. + * This function designs gates with Simulated Annealing. The cost function involves the critical temperature and the + * operational domain. The importance of the individual figures of merit can be adjusted by the weights. * - * @return A vector of designed SiDB gate layouts. + * @return Designed SiDB gate with minimal cost. */ [[nodiscard]] Lyt run_sa_design(const design_sidb_gates_sa_params& sa_params) noexcept { @@ -342,7 +344,7 @@ class design_sidb_gates_impl return lyt_swap; }); std::cout << fmt::format("final cost: {}", optimized_net_cost) << std::endl; - stats.cost_of_gate = optimized_net_cost; + stats.gate_cost = optimized_net_cost; return optimized_gate_design; } From e4b685534fc4e93c8353593aef04f34ffb0810e0 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 08:23:35 +0200 Subject: [PATCH 049/221] :art: small fix. --- .../physical_design/design_sidb_gates.hpp | 78 +++++++++++-------- .../physical_design/design_sidb_gates.cpp | 6 +- 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 6dbe18f09..5e57cbbfa 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -40,7 +40,7 @@ namespace fiction /** * Parameters for Simulated Annealing-based gate design. */ -struct design_sidb_gates_sa_params +struct design_sidb_gates_metric_driven_simulated_annealing_params { /** * Type of temperature schedule used in Simulated Annealing. @@ -287,9 +287,11 @@ class design_sidb_gates_impl * This function designs gates with Simulated Annealing. The cost function involves the critical temperature and the * operational domain. The importance of the individual figures of merit can be adjusted by the weights. * + * @param sa_params Simulated Annealing parameters. * @return Designed SiDB gate with minimal cost. */ - [[nodiscard]] Lyt run_sa_design(const design_sidb_gates_sa_params& sa_params) noexcept + [[nodiscard]] Lyt run_metric_driven_design_process( + const design_sidb_gates_metric_driven_simulated_annealing_params& sa_params) noexcept { mockturtle::stopwatch stop{stats.time_total}; generate_random_sidb_layout_params> parameter{ @@ -374,9 +376,14 @@ class design_sidb_gates_impl * All SiDBs within the canvas. */ std::vector canvas_sidbs; - - std::vector old_canvas_sidbs; - std::pair swaped_pair{}; + /** + * Canvas SiDBs before move. + */ + std::vector canvas_sidbs_before_move; + /** + * Canvas SiDB was moved from one cell (first cell) to another cell (second cell). + */ + std::pair sidb_moved_from_to{}; /** * A random-number generator. */ @@ -389,7 +396,14 @@ class design_sidb_gates_impl * */ std::uniform_int_distribution random_canvas_cell_functor; - + /** + * This function iterates over each cell in the provided layout `lyt` and checks if the cell + * corresponds to a canvas SiDB. Canvas SiDBs are defined as SiDBs that are part of the canvas + * region. It populates a vector with the canvas SiDBs found in the layout and returns it. + * + * @param lyt The layout from which canvas SiDBs are to be determined. + * @return A vector containing the canvas SiDBs found in the layout. + */ [[nodiscard]] std::vector determine_canvas_sidbs(const Lyt& lyt) const noexcept { std::vector placed_canvas_sidbs = {}; @@ -405,7 +419,16 @@ class design_sidb_gates_impl }); return placed_canvas_sidbs; } - + /** + * This function randomly selects a canvas cell from the layout `lyt` and a canvas SiDB + * to replace it with. It then moves the selected canvas SiDB to the randomly chosen + * canvas cell, updating the layout accordingly. If the randomly chosen canvas cell is not + * empty, the layout remains unchanged. + * + * @param lyt The layout from which a canvas SiDB is to be moved. + * @return The layout after the canvas SiDB has been moved, or the original layout if the + * randomly chosen canvas cell was not empty. + */ [[nodiscard]] Lyt move_sidb(Lyt& lyt) noexcept { const auto random_index = random_canvas_cell_functor(generator); @@ -420,18 +443,11 @@ class design_sidb_gates_impl } lyt.assign_cell_type(replace_sidb, Lyt::technology::cell_type::EMPTY); lyt.assign_cell_type(random_cell, Lyt::technology::cell_type::NORMAL); - swaped_pair = {replace_sidb, random_cell}; - old_canvas_sidbs = canvas_sidbs; + sidb_moved_from_to = {replace_sidb, random_cell}; + canvas_sidbs_before_move = canvas_sidbs; canvas_sidbs[random_index_replace] = random_cell; return lyt; } - - void undo_swap(const Lyt& lyt) - { - lyt.assign_cell_type(swaped_pair.firsr, Lyt::technology::cell_type::NORMAL); - lyt.assign_cell_type(swaped_pair.second, Lyt::technology::cell_type::NORMAL); - } - /** * Checks if any SiDBs within the specified cell indices are located too closely together, with a distance of less * than 0.5 nanometers. @@ -552,26 +568,22 @@ design_sidb_gates(const Lyt& skeleton, const std::vector& spec, const design } /** - * Designs SiDB gates using metric-driven simulated annealing. - * - * This function designs SiDB gates based on a given layout skeleton, a set of truth tables, and specified parameters - * for gate design and simulated annealing. The function employs a metric-driven approach to optimize gate placement - * and configuration, utilizing simulated annealing to explore the solution space. + * This function designs SiDB gates to minimize the cost function \f$\chi\f$, considering a layout skeleton, a set of + * truth tables, and specified parameters for gate design and simulated annealing. Currently, only the critical + * temperature and the operational domain are incorporated into the cost function. * - * * @tparam Lyt SiDB cell-level layout type. - * @tparam TT The type of the truth table specifying the gate behavior. - * @param skeleton The skeleton layout used as a starting point for gate design. + * @param skeleton The layout skeleton used as the basis for gate design. * @param spec Expected Boolean function of the layout given as a multi-output truth table. - * @param params The parameters for SiDB gate design. - * @param sa_params The parameters for simulated annealing. - * @param pst Pointer to a statistics object to store the design statistics. - * @return The designed layout with SiDB gates. + * @param params The parameters for gate design. + * @param sa_params Parameters for simulated annealing. + * @param pst Statistics for gate design. + * @return A layout with SiDB gates designed to minimize the cost function. */ template -[[nodiscard]] Lyt design_sidb_gates_metric_driven_simulated_annealing(const Lyt& skeleton, const std::vector& spec, - const design_sidb_gates_params& params, - const design_sidb_gates_sa_params& sa_params, - design_sidb_gates_stats* pst = nullptr) noexcept +[[nodiscard]] Lyt design_sidb_gates_metric_driven_simulated_annealing( + const Lyt& skeleton, const std::vector& spec, const design_sidb_gates_params& params, + const design_sidb_gates_metric_driven_simulated_annealing_params& sa_params, + design_sidb_gates_stats* pst = nullptr) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -589,7 +601,7 @@ template design_sidb_gates_stats st{}; detail::design_sidb_gates_impl p{skeleton, spec, params, st}; - const auto result = p.run_sa_design(sa_params); + const auto result = p.run_metric_driven_design_process(sa_params); if (pst) { diff --git a/test/algorithms/physical_design/design_sidb_gates.cpp b/test/algorithms/physical_design/design_sidb_gates.cpp index 9438f60bc..257802346 100644 --- a/test/algorithms/physical_design/design_sidb_gates.cpp +++ b/test/algorithms/physical_design/design_sidb_gates.cpp @@ -309,9 +309,9 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") sidb_defect{sidb_defect_type::DB, -1, params.simulation_parameters.epsilon_r, params.simulation_parameters.lambda_tf}); - const critical_temperature_params ct_params{params.simulation_parameters}; - const operational_domain_params op_params{params.simulation_parameters}; - design_sidb_gates_sa_params sa_params{}; + const critical_temperature_params ct_params{params.simulation_parameters}; + const operational_domain_params op_params{params.simulation_parameters}; + design_sidb_gates_metric_driven_simulated_annealing_params sa_params{}; sa_params.ct_params = ct_params; sa_params.op_params = op_params; sa_params.weight_temperature = -1.0; From 89e75c3b8928df61b5d2350bcdeacf99d315d9be Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 09:08:47 +0200 Subject: [PATCH 050/221] :art: small fix. --- ...defect_influence_position_and_distance.hpp | 5 +++-- ...e_defect_influence_operational_domain.hpp} | 20 +++++++++-------- .../defect_influence_operational_domain.cpp | 22 +++++++++---------- 3 files changed, 24 insertions(+), 23 deletions(-) rename include/fiction/io/{write_defect_operational_domain.hpp => write_defect_influence_operational_domain.hpp} (81%) diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 1be553e39..745b7cc4d 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -86,7 +86,7 @@ class maximum_defect_influence_position_and_distance_impl stats{st} { collect_all_defect_cells(); - }; + } std::pair run() noexcept { @@ -267,7 +267,8 @@ class maximum_defect_influence_position_and_distance_impl * defect can still affect the layout's ground state, potentially altering its behavior, such as gate functionality. * * @param lyt The SiDB cell-level layout for which the influence distance is being determined. - * @param params Parameters used to calculate the defect's maximum influence distance. + * @param sim_params Parameters used to calculate the defect's maximum influence distance. + * @param pst Statistics of the maximum defect influence distance. * @return Pair with the first element describing the position with maximum distance to the layout where a placed defect * can still affect the ground state of the layout. The second entry describes the distance of the defect from the * layout. diff --git a/include/fiction/io/write_defect_operational_domain.hpp b/include/fiction/io/write_defect_influence_operational_domain.hpp similarity index 81% rename from include/fiction/io/write_defect_operational_domain.hpp rename to include/fiction/io/write_defect_influence_operational_domain.hpp index 88d545545..be80fce5c 100644 --- a/include/fiction/io/write_defect_operational_domain.hpp +++ b/include/fiction/io/write_defect_influence_operational_domain.hpp @@ -5,8 +5,8 @@ #ifndef FICTION_WRITE_OPERATIONAL_DOMAIN_HPP #define FICTION_WRITE_OPERATIONAL_DOMAIN_HPP -#include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" +#include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/io/csv_writer.hpp" #include @@ -49,13 +49,14 @@ struct write_operational_domain_params * @param params The parameters used for writing, including the operational and non-operational tags. Defaults to an * empty `write_operational_domain_params` object, which provides standard tags. */ - template -inline void write_operational_domain(const defect_influence_operational_domain& opdom, std::ostream& os, - const write_operational_domain_params& params = {}) +template +inline void write_defect_influence_operational_domain(const defect_influence_operational_domain& opdom, + std::ostream& os, + const write_operational_domain_params& params = {}) { csv_writer writer{os}; - writer.write_line("x","y", "operational status"); + writer.write_line("x", "y", "operational status"); for (const auto& [sim_param, op_val] : opdom.operational_values) { @@ -81,9 +82,10 @@ inline void write_operational_domain(const defect_influence_operational_domain -inline void write_operational_domain(const defect_influence_operational_domain& opdom, const std::string_view& filename, - const write_operational_domain_params& params = {}) +template +inline void write_defect_influence_operational_domain(const defect_influence_operational_domain& opdom, + const std::string_view& filename, + const write_operational_domain_params& params = {}) { std::ofstream os{filename.data(), std::ofstream::out}; @@ -92,7 +94,7 @@ inline void write_operational_domain(const defect_influence_operational_domain #include #include -#include +#include #include #include #include @@ -22,8 +22,6 @@ using namespace fiction; TEST_CASE("novel designed AND Gate influence distance function which fails again", "[defect-influence-of-sidb-gate-contour-tracing]") { - - // TODO Use SiQAD gate sidb_cell_clk_lyt_siqad lyt{}; lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); @@ -79,9 +77,9 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again write_operational_domain_params write_params{}; write_params.operational_tag = "1"; write_params.non_operational_tag = "0"; - write_operational_domain(defect_influence_domain, - "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", - write_params); + write_defect_influence_operational_domain( + defect_influence_domain, + "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", write_params); } SECTION("Random Sampling") { @@ -95,9 +93,9 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again write_operational_domain_params write_params{}; write_params.operational_tag = "1"; write_params.non_operational_tag = "0"; - write_operational_domain(defect_influence_domain, - "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", - write_params); + write_defect_influence_operational_domain( + defect_influence_domain, + "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", write_params); } SECTION("Contour Tracing") { @@ -110,8 +108,8 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again write_operational_domain_params write_params{}; write_params.operational_tag = "1"; write_params.non_operational_tag = "0"; - write_operational_domain(defect_influence_domain, - "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", - write_params); + write_defect_influence_operational_domain( + defect_influence_domain, + "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", write_params); } } From 263480a7bf4af83e3381ad3a3b14d3fe80e63c90 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 11:00:44 +0200 Subject: [PATCH 051/221] :art: small fix. --- .../assess_physical_population_stability.hpp | 680 +++++++++--------- ...hysical_population_stability_sidb_gate.hpp | 60 +- .../assess_physical_population_stability.cpp | 2 +- ...hysical_population_stability_sidb_gate.cpp | 74 +- test/utils/blueprints/layout_blueprints.hpp | 53 ++ 5 files changed, 469 insertions(+), 400 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 5c48632b9..184b2ac6c 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -8,44 +8,48 @@ #include "fiction/algorithms/simulation/sidb/convert_potential_to_distance.hpp" #include "fiction/algorithms/simulation/sidb/quickexact.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" -#include "fiction/layouts/cell_level_layout.hpp" +#include "fiction/algorithms/simulation/sidb/sidb_simulation_result.hpp" +#include "fiction/technology/charge_distribution_surface.hpp" +#include "fiction/technology/sidb_charge_state.hpp" #include "fiction/traits.hpp" -#include "fiction/types.hpp" #include #include +#include #include #include #include -#include #include #include +#include -namespace fiction { +namespace fiction +{ /** * Possible types of charge transitions that can occur in an SiDB layout. These transitions represent * changes in the charge state of SiDBs, including transitions from neutral to negative, negative to neutral, neutral to * positive, and positive to neutral. */ - enum class transition_type { - /** - * SiDB is neutrally charged, but is closest to being negatively charged. - */ - NEUTRAL_TO_NEGATIVE, - /** - * SiDB is negatively charged, but is closest to being neutrally charged. - */ - NEGATIVE_TO_NEUTRAL, - /** - * SiDB is neutrally charged, but is closest to being positively charged. - */ - NEUTRAL_TO_POSITIVE, - /** - * SiDB is positively charged, but is closest to being neutrally charged. - */ - POSITIVE_TO_NEUTRAL, - }; +enum class transition_type +{ + /** + * SiDB is neutrally charged, but is closest to being negatively charged. + */ + NEUTRAL_TO_NEGATIVE, + /** + * SiDB is negatively charged, but is closest to being neutrally charged. + */ + NEGATIVE_TO_NEUTRAL, + /** + * SiDB is neutrally charged, but is closest to being positively charged. + */ + NEUTRAL_TO_POSITIVE, + /** + * SiDB is positively charged, but is closest to being neutrally charged. + */ + POSITIVE_TO_NEUTRAL, +}; /** * This struct encapsulates information related to the population stability of a charge distribution. * It includes details about the SiDB closest to a charge transition (critical cell), the specific @@ -55,315 +59,339 @@ namespace fiction { * * @tparam Lyt SiDB cell-level layout type. */ - template - struct population_stability_information { - /** - * SiDB cell which is closest to a charge transition. - */ - typename Lyt::cell critical_cell{}; - /** - * Charge transition from the current charge state to the closest one. - */ - std::unordered_map> - transition_from_to_with_cell_and_required_pot{}; - /** - * Absolute electrostatic potential (unit: V) required for the charge state transition. - */ - std::unordered_map minimum_potential_difference_to_transition{}; - /** - * Distance (unit: nm) corresponding to the minimum potential difference. - */ - std::unordered_map distance_corresponding_to_potential{}; - /** - * Total electrostatic energy (unit: eV) of given charge distribution. - */ - double system_energy{}; - }; +template +struct population_stability_information +{ + /** + * SiDB cell which is closest to a charge transition. + */ + typename Lyt::cell critical_cell{}; + /** + * Charge transition from the current charge state to the closest one. + */ + std::unordered_map> + transition_from_to_with_cell_and_required_pot{}; + /** + * Absolute electrostatic potential (unit: V) required for the charge state transition. + */ + std::unordered_map minimum_potential_difference_to_transition{}; + /** + * Distance (unit: nm) corresponding to the minimum potential difference. + */ + std::unordered_map distance_corresponding_to_potential{}; + /** + * Total electrostatic energy (unit: eV) of given charge distribution. + */ + double system_energy{}; +}; /** * This struct stores the parameters required to assess the population stability. */ - struct assess_physical_population_stability_params { - /** - * Parameters for the electrostatic potential. - */ - sidb_simulation_parameters physical_parameters{}; - /** - * The precision level for the conversion from the minimum potential difference to the corresponding - * distance. - */ - uint64_t precision_for_distance_corresponding_to_potential = 2; - }; - - namespace detail { - - template - class assess_physical_population_stability_impl { - public: - /** - * Constructor for assess_physical_population_stability_impl. - * - * @param lyt SiDB layout. - * @param parameters The simulation parameters used for the assessment. - */ - assess_physical_population_stability_impl(const Lyt &lyt, - const assess_physical_population_stability_params ¶meters) : - layout{lyt}, - params{parameters} {} - - /** - * Runs a population stability assessment for a given SiDB layout using the provided simulation parameters. - * This function determines the minimum electrostatic potential required for charge state transitions within the - * layout and identifies the corresponding critical SiDB along with the type of charge state transition. - * - * @return A vector of population stability information structures, where each element represents a charge - * distribution in ascending energy order. Each structure contains details about the critical SiDB, the type of - * charge state transition, and the minimum electrostatic potential required for the charge transition. - */ - [[nodiscard]] std::vector> run() noexcept { - const quickexact_params> quickexact_parameters{params.physical_parameters}; - const auto simulation_results = quickexact(layout, quickexact_parameters); - const auto energy_and_unique_charge_index = collect_energy_and_charge_index(simulation_results); - - std::vector> popstability_information{}; - popstability_information.reserve(simulation_results.charge_distributions.size()); - - // Access the unique indices - for (const auto &energy_and_index: energy_and_unique_charge_index) { - const auto it = std::find_if( - simulation_results.charge_distributions.begin(), - simulation_results.charge_distributions.end(), - [&](const charge_distribution_surface &charge_lyt) { - // Compare with the first element of the pair returned by get_charge_index_and_base() - return charge_lyt.get_charge_index_and_base().first == energy_and_index.charge_index; - }); - - if (it == simulation_results.charge_distributions.end()) { - continue; - } +struct assess_physical_population_stability_params +{ + /** + * Parameters for the electrostatic potential. + */ + sidb_simulation_parameters simulation_parameters{}; + /** + * The precision level for the conversion from the minimum potential difference to the corresponding + * distance. + */ + uint64_t precision_for_distance_corresponding_to_potential = 2; +}; + +namespace detail +{ + +template +class assess_physical_population_stability_impl +{ + public: + /** + * Constructor for assess_physical_population_stability_impl. + * + * @param lyt SiDB layout. + * @param parameters The simulation parameters used for the assessment. + */ + assess_physical_population_stability_impl(const Lyt& lyt, + const assess_physical_population_stability_params& parameters) : + layout{lyt}, + params{parameters} + {} + + /** + * Runs a population stability assessment for a given SiDB layout using the provided simulation parameters. + * This function determines the minimum electrostatic potential required for charge state transitions within the + * layout and identifies the corresponding critical SiDB along with the type of charge state transition. + * + * @return A vector of population stability information structures, where each element represents a charge + * distribution in ascending energy order. Each structure contains details about the critical SiDB, the type of + * charge state transition, and the minimum electrostatic potential required for the charge transition. + */ + [[nodiscard]] std::vector> run() noexcept + { + const quickexact_params> quickexact_parameters{params.simulation_parameters}; + const auto simulation_results = quickexact(layout, quickexact_parameters); + const auto energy_and_unique_charge_index = collect_energy_and_charge_index(simulation_results); + + std::vector> popstability_information{}; + popstability_information.reserve(simulation_results.charge_distributions.size()); + + // Access the unique indices + for (const auto& energy_and_index : energy_and_unique_charge_index) + { + const auto it = std::find_if( + simulation_results.charge_distributions.begin(), simulation_results.charge_distributions.end(), + [&](const charge_distribution_surface& charge_lyt) + { + // Compare with the first element of the pair returned by get_charge_index_and_base() + return charge_lyt.get_charge_index_and_base().first == energy_and_index.charge_index; + }); + + if (it == simulation_results.charge_distributions.end()) + { + continue; + } - const auto &charge_lyt = *it; - - population_stability_information population_stability_info{}; - - population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE] = - std::numeric_limits::infinity(); - population_stability_info.minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL] = - std::numeric_limits::infinity(); - population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = - std::numeric_limits::infinity(); - population_stability_info.minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = - std::numeric_limits::infinity(); - - charge_lyt.foreach_cell( - [this, &charge_lyt, &population_stability_info](const auto &c) { - switch (charge_lyt.get_charge_state(c)) { - case sidb_charge_state::NEGATIVE: { - population_stability_info = handle_negative_charges( - *charge_lyt.get_local_potential(c), c, - population_stability_info); - break; - } - case sidb_charge_state::NEUTRAL: { - population_stability_info = handle_neutral_charges( - *charge_lyt.get_local_potential(c), c, - population_stability_info); - break; - } - case sidb_charge_state::POSITIVE: { - population_stability_info = handle_positive_charges( - *charge_lyt.get_local_potential(c), c, - population_stability_info); - break; - } - case sidb_charge_state::NONE: { - break; - } - } - }); - population_stability_info.system_energy = charge_lyt.get_system_energy(); - - auto minimum_potential_difference = std::numeric_limits::infinity(); - - for (const auto &transition: population_stability_info.transition_from_to_with_cell_and_required_pot) { - population_stability_info.distance_corresponding_to_potential[transition.first] = - convert_potential_to_distance(transition.second.second, params.physical_parameters, - params.precision_for_distance_corresponding_to_potential); - if (transition.second.second < minimum_potential_difference) { - population_stability_info.critical_cell = transition.second.first; - minimum_potential_difference = transition.second.second; + const auto& charge_lyt = *it; + + population_stability_information population_stability_info{}; + + population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE] = + std::numeric_limits::infinity(); + population_stability_info.minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL] = + std::numeric_limits::infinity(); + population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = + std::numeric_limits::infinity(); + population_stability_info.minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = + std::numeric_limits::infinity(); + + charge_lyt.foreach_cell( + [this, &charge_lyt, &population_stability_info](const auto& c) + { + switch (charge_lyt.get_charge_state(c)) + { + case sidb_charge_state::NEGATIVE: + { + population_stability_info = handle_negative_charges(*charge_lyt.get_local_potential(c), c, + population_stability_info); + break; + } + case sidb_charge_state::NEUTRAL: + { + population_stability_info = handle_neutral_charges(*charge_lyt.get_local_potential(c), c, + population_stability_info); + break; + } + case sidb_charge_state::POSITIVE: + { + population_stability_info = handle_positive_charges(*charge_lyt.get_local_potential(c), c, + population_stability_info); + break; + } + case sidb_charge_state::NONE: + { + break; } } - popstability_information.push_back(population_stability_info); + }); + population_stability_info.system_energy = charge_lyt.get_system_energy(); + + auto minimum_potential_difference = std::numeric_limits::infinity(); + + for (const auto& transition : population_stability_info.transition_from_to_with_cell_and_required_pot) + { + population_stability_info.distance_corresponding_to_potential[transition.first] = + convert_potential_to_distance(transition.second.second, params.simulation_parameters, + params.precision_for_distance_corresponding_to_potential); + if (transition.second.second < minimum_potential_difference) + { + population_stability_info.critical_cell = transition.second.first; + minimum_potential_difference = transition.second.second; } - - return popstability_information; - }; - - private: - /** - * This struct represents the electrostatic energy and charge index of a charge distribution. - */ - struct energy_and_charge_index { - /** - * Electrostatic energy of the charge distribution. - */ - double energy; - /** - * Charge index of the charge distribution. - */ - uint64_t charge_index; - }; - /** - * Layout to analyze. - */ - const Lyt &layout; - /** - * Parameters required to assess the population stability. - */ - const assess_physical_population_stability_params ¶ms; - - /** - * This function checks if the absolute difference between the given local potential and - * µ- is smaller than the current minimum potential difference to transition for a negatively charged SiDB. - * If `true`, it updates the population stability information with the new minimum difference and critical cell. - * - * @param local_potential The local potential associated with the cell. - * @param c The cell for which the charge state is being considered (SiDB is negatively charged). - * @param pop_stability_information The current population stability information. - * - * @return An updated population stability information with potential transition details. - */ - [[nodiscard]] population_stability_information - handle_negative_charges(const double local_potential, const typename Lyt::cell &c, - const population_stability_information &pop_stability_information) noexcept { - auto updated_pop_stability_information = pop_stability_information; - - if (std::abs(-local_potential + params.physical_parameters.mu_minus) < - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL]) { - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL] = - std::abs(-local_potential + params.physical_parameters.mu_minus); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information - .transition_from_to_with_cell_and_required_pot[transition_type::NEGATIVE_TO_NEUTRAL] = { - c, updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL]}; - } - - return updated_pop_stability_information; } + popstability_information.push_back(population_stability_info); + } - /** - * This function checks if the absolute difference between the given local potential and - * µ- or µ+ is smaller than the current minimum potential difference. - * If `true`, it updates the population stability information with the new minimum difference and critical cell. - * - * @param local_potential The local potential associated with the cell. - * @param c The cell for which the charge state is being considered (SiDB is neutrally charged). - * @param pop_stability_information The current population stability information. - * - * @return An updated population stability information with potential transition details. - */ - [[nodiscard]] population_stability_information - handle_neutral_charges(const double local_potential, const typename Lyt::cell &c, - const population_stability_information &pop_stability_information) noexcept { - auto updated_pop_stability_information = pop_stability_information; - if (std::abs(-local_potential + params.physical_parameters.mu_minus) < - std::abs(-local_potential + params.physical_parameters.mu_plus())) { - if (std::abs(-local_potential + params.physical_parameters.mu_minus) < - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE]) { - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE] = - std::abs(-local_potential + params.physical_parameters.mu_minus); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information - .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_NEGATIVE] = { - c, updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE]}; - } - } else { - if (std::abs(-local_potential + params.physical_parameters.mu_plus()) < - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]) { - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = - std::abs(-local_potential + params.physical_parameters.mu_plus()); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information - .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_POSITIVE] = { - c, updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]}; - } - } + return popstability_information; + }; + + private: + /** + * This struct represents the electrostatic energy and charge index of a charge distribution. + */ + struct energy_and_charge_index + { + /** + * Electrostatic energy of the charge distribution. + */ + double energy; + /** + * Charge index of the charge distribution. + */ + uint64_t charge_index; + }; + /** + * Layout to analyze. + */ + const Lyt& layout; + /** + * Parameters required to assess the population stability. + */ + const assess_physical_population_stability_params& params; + + /** + * This function checks if the absolute difference between the given local potential and + * µ- is smaller than the current minimum potential difference to transition for a negatively charged SiDB. + * If `true`, it updates the population stability information with the new minimum difference and critical cell. + * + * @param local_potential The local potential associated with the cell. + * @param c The cell for which the charge state is being considered (SiDB is negatively charged). + * @param pop_stability_information The current population stability information. + * + * @return An updated population stability information with potential transition details. + */ + [[nodiscard]] population_stability_information + handle_negative_charges(const double local_potential, const typename Lyt::cell& c, + const population_stability_information& pop_stability_information) noexcept + { + auto updated_pop_stability_information = pop_stability_information; + + if (std::abs(-local_potential + params.simulation_parameters.mu_minus) < + updated_pop_stability_information.minimum_potential_difference_to_transition.at( + transition_type::NEGATIVE_TO_NEUTRAL)) + { + updated_pop_stability_information.minimum_potential_difference_to_transition.at( + transition_type::NEGATIVE_TO_NEUTRAL) = + std::abs(-local_potential + params.simulation_parameters.mu_minus); + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::NEGATIVE_TO_NEUTRAL] = { + c, updated_pop_stability_information.minimum_potential_difference_to_transition.at( + transition_type::NEGATIVE_TO_NEUTRAL)}; + } + + return updated_pop_stability_information; + } - return updated_pop_stability_information; + /** + * This function checks if the absolute difference between the given local potential and + * µ- or µ+ is smaller than the current minimum potential difference. + * If `true`, it updates the population stability information with the new minimum difference and critical cell. + * + * @param local_potential The local potential associated with the cell. + * @param c The cell for which the charge state is being considered (SiDB is neutrally charged). + * @param pop_stability_information The current population stability information. + * + * @return An updated population stability information with potential transition details. + */ + [[nodiscard]] population_stability_information + handle_neutral_charges(const double local_potential, const typename Lyt::cell& c, + const population_stability_information& pop_stability_information) noexcept + { + auto updated_pop_stability_information = pop_stability_information; + if (std::abs(-local_potential + params.simulation_parameters.mu_minus) < + std::abs(-local_potential + params.simulation_parameters.mu_plus())) + { + if (std::abs(-local_potential + params.simulation_parameters.mu_minus) < + updated_pop_stability_information.minimum_potential_difference_to_transition.at( + transition_type::NEUTRAL_TO_NEGATIVE)) + { + updated_pop_stability_information.minimum_potential_difference_to_transition.at( + transition_type::NEUTRAL_TO_NEGATIVE) = + std::abs(-local_potential + params.simulation_parameters.mu_minus); + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_NEGATIVE] = { + c, updated_pop_stability_information.minimum_potential_difference_to_transition.at( + transition_type::NEUTRAL_TO_NEGATIVE)}; + } + } + else + { + if (std::abs(-local_potential + params.simulation_parameters.mu_plus()) < + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]) + { + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = + std::abs(-local_potential + params.simulation_parameters.mu_plus()); + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_POSITIVE] = { + c, updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]}; } + } - /** - * This function checks if the absolute difference between the given local potential and µ+ is smaller than the - * current minimum potential difference. If true`, it updates the - * population stability information with the new minimum difference and critical cell. - * - * @param local_potential The local potential associated with the cell. - * @param c The cell for which the charge state is being considered (SiDB is positively charged). - * @param pop_stability_information The current population stability information. - * - * @return An updated population stability information with potential transition details. - */ - [[nodiscard]] population_stability_information - handle_positive_charges(const double local_potential, const typename Lyt::cell &c, - const population_stability_information &pop_stability_information) noexcept { - auto updated_pop_stability_information = pop_stability_information; - if (std::abs(-local_potential + params.physical_parameters.mu_plus()) < - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL]) { - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = - std::abs(-local_potential + params.physical_parameters.mu_plus()); - updated_pop_stability_information.critical_cell = c; - updated_pop_stability_information - .transition_from_to_with_cell_and_required_pot[transition_type::POSITIVE_TO_NEUTRAL] = { - c, updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL]}; - } + return updated_pop_stability_information; + } - return updated_pop_stability_information; - } + /** + * This function checks if the absolute difference between the given local potential and µ+ is smaller than the + * current minimum potential difference. If true`, it updates the + * population stability information with the new minimum difference and critical cell. + * + * @param local_potential The local potential associated with the cell. + * @param c The cell for which the charge state is being considered (SiDB is positively charged). + * @param pop_stability_information The current population stability information. + * + * @return An updated population stability information with potential transition details. + */ + [[nodiscard]] population_stability_information + handle_positive_charges(const double local_potential, const typename Lyt::cell& c, + const population_stability_information& pop_stability_information) noexcept + { + auto updated_pop_stability_information = pop_stability_information; + if (std::abs(-local_potential + params.simulation_parameters.mu_plus()) < + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL]) + { + updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = + std::abs(-local_potential + params.simulation_parameters.mu_plus()); + updated_pop_stability_information.critical_cell = c; + updated_pop_stability_information + .transition_from_to_with_cell_and_required_pot[transition_type::POSITIVE_TO_NEUTRAL] = { + c, updated_pop_stability_information + .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL]}; + } + + return updated_pop_stability_information; + } - /** - * Collects the system energy with the corresponding charge index information of all physically valid - * charge distributions of a given SiDB layout. - * - * @param sim_results The simulation results, including all physically valid charge distributions. - * @return A vector of energy_and_charge_index pairs, where each pair consists of a double value representing - * the system energy and a uint64_t representing the unique charge index. The vector is sorted in ascending order - * of the energy values. - */ - [[nodiscard]] std::vector - collect_energy_and_charge_index(const sidb_simulation_result &sim_results) const noexcept { - std::vector energy_charge_index{}; - energy_charge_index.reserve(sim_results.charge_distributions.size()); - - std::transform( - sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), - std::back_inserter(energy_charge_index), - [](const auto &ch_lyt) { - return energy_and_charge_index{ch_lyt.get_system_energy(), - ch_lyt.get_charge_index_and_base().first}; - }); - - // Sort the vector in ascending order of the energy value - std::sort(energy_charge_index.begin(), energy_charge_index.end(), - [](const auto &lhs, const auto &rhs) { return lhs.energy < rhs.energy; }); - - return energy_charge_index; - } - }; + /** + * Collects the system energy with the corresponding charge index information of all physically valid + * charge distributions of a given SiDB layout. + * + * @param sim_results The simulation results, including all physically valid charge distributions. + * @return A vector of energy_and_charge_index pairs, where each pair consists of a double value representing + * the system energy and a uint64_t representing the unique charge index. The vector is sorted in ascending order + * of the energy values. + */ + [[nodiscard]] std::vector + collect_energy_and_charge_index(const sidb_simulation_result& sim_results) const noexcept + { + std::vector energy_charge_index{}; + energy_charge_index.reserve(sim_results.charge_distributions.size()); + + std::transform( + sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), + std::back_inserter(energy_charge_index), + [](const auto& ch_lyt) { + return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; + }); + + // Sort the vector in ascending order of the energy value + std::sort(energy_charge_index.begin(), energy_charge_index.end(), + [](const auto& lhs, const auto& rhs) { return lhs.energy < rhs.energy; }); + + return energy_charge_index; + } +}; - } // namespace detail +} // namespace detail /** * This function assesses the population stability of each physically valid charge distributions of a given SiDB layout. @@ -376,17 +404,17 @@ namespace fiction { * @return A vector of population stability information for all physically valid charge distributions of the given SiDB * layout. */ - template - [[nodiscard]] std::vector> - assess_physical_population_stability(const Lyt &lyt, - const assess_physical_population_stability_params ¶ms) noexcept { - static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); - static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); - static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); - - detail::assess_physical_population_stability_impl p{lyt, params}; - return p.run(); - } +template +[[nodiscard]] std::vector> +assess_physical_population_stability(const Lyt& lyt, const assess_physical_population_stability_params& params) noexcept +{ + static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); + + detail::assess_physical_population_stability_impl p{lyt, params}; + return p.run(); +} } // namespace fiction diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp index 90479f449..f2b5ae3bd 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp @@ -7,8 +7,14 @@ #include "fiction/algorithms/iter/bdl_input_iterator.hpp" #include "fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp" +#include "fiction/algorithms/simulation/sidb/can_positive_charges_occur.hpp" #include "fiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" -#include "fiction/utils/layout_utils.hpp" + +#include +#include +#include +#include +#include namespace fiction { @@ -25,16 +31,21 @@ struct assess_physical_population_stability_params_sidb_gate }; template -[[nodiscard]] double -assess_physical_population_stability_sidb_gate(const Lyt& lyt, const std::vector& spec, - const assess_physical_population_stability_params_sidb_gate& params = {}, - const int8_t charge_state_change = 1) noexcept +[[nodiscard]] double calculate_min_potential_for_charge_change_for_all_input_combinations( + const Lyt& lyt, const std::vector& spec, + const assess_physical_population_stability_params_sidb_gate& params = {}, + const std::optional charge_state_change = 1) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(!has_offset_ucoord_v, "Lyt should not be based on offset coordinates"); static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); + if (can_positive_charges_occur(lyt, params.assess_population_stability_params.simulation_parameters)) + { + return 0.0; + } + assert(lyt.num_pis() > 0 && "skeleton needs input cells"); assert(lyt.num_pos() > 0 && "skeleton needs output cells"); @@ -44,7 +55,11 @@ assess_physical_population_stability_sidb_gate(const Lyt& lyt, const std::vector [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.end()); bdl_input_iterator bii{lyt, params.detect_pair_params}; - double maximal_pop_stability_for_all_inputs = std::numeric_limits::infinity(); + + assert(bii.get_number_of_inputs() == spec.front().num_bits() / 2 && + "Number of truth table dimensions and input BDL pairs does not match"); + + double minimal_pop_stability_for_all_inputs = std::numeric_limits::infinity(); // number of different input combinations for (auto i = 0u; i < spec.front().num_bits(); ++i, ++bii) { @@ -53,25 +68,32 @@ assess_physical_population_stability_sidb_gate(const Lyt& lyt, const std::vector if (!pop_stability.empty()) { const auto stability_for_given_input = pop_stability.front().minimum_potential_difference_to_transition; - double potential = 0.0; - if (charge_state_change == 1) + if (charge_state_change.has_value()) { - potential = std::abs(stability_for_given_input.at(transition_type::NEGATIVE_TO_NEUTRAL)); - } + if (charge_state_change.value() == 1) + { + const auto potential_negative_to_neutral = + stability_for_given_input.at(transition_type::NEGATIVE_TO_NEUTRAL); + if (potential_negative_to_neutral < minimal_pop_stability_for_all_inputs) + { + minimal_pop_stability_for_all_inputs = potential_negative_to_neutral; + } + } - if (charge_state_change == -1) - { - potential = std::abs(stability_for_given_input.at(transition_type::NEUTRAL_TO_NEGATIVE)); - } - - if (potential < maximal_pop_stability_for_all_inputs) - { - maximal_pop_stability_for_all_inputs = potential; + if (charge_state_change.value() == -1) + { + const auto potential_neutral_to_negative = + stability_for_given_input.at(transition_type::NEUTRAL_TO_NEGATIVE); + if (potential_neutral_to_negative < minimal_pop_stability_for_all_inputs) + { + minimal_pop_stability_for_all_inputs = potential_neutral_to_negative; + } + } } } } - return maximal_pop_stability_for_all_inputs; + return minimal_pop_stability_for_all_inputs; } } // namespace fiction diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp index b78c280a8..57294e518 100644 --- a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp +++ b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp @@ -2,7 +2,7 @@ // Created by Jan Drewniok on 02.11.23. // -#include +#include #include #include "utils/blueprints/layout_blueprints.hpp" diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp b/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp index fdd5cb864..d28b958ab 100644 --- a/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp +++ b/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp @@ -5,73 +5,39 @@ #include #include +#include "utils/blueprints/layout_blueprints.hpp" + #include #include -#include -#include -#include #include +#include + +#include using namespace fiction; using layout = sidb_cell_clk_lyt_siqad; -TEST_CASE("Single SiDB", "[assess-physical-population-stability]") +TEST_CASE("Single SiDB", "[assess-physical-population-stability-sidb-gate]") { - layout lyt{}; - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); + const auto lyt = blueprints::bestagon_and_gate(); - lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); + const auto params = assess_physical_population_stability_params_sidb_gate{ + assess_physical_population_stability_params{sidb_simulation_parameters{2, -0.32}, 2}}; - lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({29, 7, 1}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({17, 8, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({17, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({21, 9, 1}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); + SECTION("Minimal potential required to conduct a charge change from neutral to negative") + { + const auto min_potential = calculate_min_potential_for_charge_change_for_all_input_combinations( + lyt, std::vector{create_and_tt()}, params, -1); - lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + CHECK_THAT(min_potential, Catch::Matchers::WithinAbs(0.020652, physical_constants::POP_STABILITY_ERR)); + } - SECTION("Precision of distance_corresponding_to_potential is two") + SECTION("Minimal potential required to conduct a charge change from negative to neutral") { - const auto params = assess_physical_population_stability_params_sidb_gate{ - assess_physical_population_stability_params{sidb_simulation_parameters{2, -0.32}, 2}}; - const auto result = assess_physical_population_stability_sidb_gate(lyt, std::vector{create_or_tt()}, - params, -1); -// REQUIRE(result.size() == 1); -// const auto &population_stability_detail = result[0]; -// CHECK(population_stability_detail.critical_cell == siqad::coord_t{1, 1, 0}); -// REQUIRE(population_stability_detail.transition_from_to_with_cell_and_required_pot.size() == 1); -// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot -// .at(transition_type::NEGATIVE_TO_NEUTRAL) -// .first == siqad::coord_t{1, 1, 0}); -// CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot -// .at(transition_type::NEGATIVE_TO_NEUTRAL) -// .second == 0.29); -// -// REQUIRE_THAT( -// population_stability_detail.distance_corresponding_to_potential.at( -// transition_type::NEGATIVE_TO_NEUTRAL), -// Catch::Matchers::WithinAbs(0.77, 1e-5)); + const auto min_potential = calculate_min_potential_for_charge_change_for_all_input_combinations( + lyt, std::vector{create_and_tt()}, params, 1); + + CHECK_THAT(min_potential, Catch::Matchers::WithinAbs(0.087417, physical_constants::POP_STABILITY_ERR)); } } diff --git a/test/utils/blueprints/layout_blueprints.hpp b/test/utils/blueprints/layout_blueprints.hpp index fdba2a6e5..d0c8883ed 100644 --- a/test/utils/blueprints/layout_blueprints.hpp +++ b/test/utils/blueprints/layout_blueprints.hpp @@ -760,7 +760,60 @@ Lyt and_gate_111() noexcept return lyt; }; +/** + * This layout represents the AND Gate, as proposed in the paper + * titled \"Hexagons are the Bestagons: Design Automation for Silicon Dangling Bond Logic\" authored by + * Marcel Walter, Samuel Sze Hang Ng, Konrad Walus, and Robert Wille. + * + * (https://github.com/cda-tum/mnt-bestagon-library/blob/main/bestagon-gates/2i1o_and/21_hex_inputsdbp_and_v19.sqd) + */ +template +Lyt bestagon_and_gate() noexcept +{ + static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); + + Lyt lyt{}; + + lyt.assign_cell_type({36, 1, 0}, Lyt::cell_type::INPUT); + lyt.assign_cell_type({2, 1, 0}, Lyt::cell_type::INPUT); + + lyt.assign_cell_type({38, 0, 0}, Lyt::cell_type::INPUT); + lyt.assign_cell_type({0, 0, 0}, Lyt::cell_type::INPUT); + + lyt.assign_cell_type({23, 9, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({18, 11, 1}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({18, 9, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({19, 8, 0}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({20, 14, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({19, 13, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({32, 2, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({30, 3, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({26, 4, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({24, 5, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({12, 4, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({14, 5, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({6, 2, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({8, 3, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({32, 18, 0}, Lyt::cell_type::OUTPUT); + lyt.assign_cell_type({30, 17, 0}, Lyt::cell_type::OUTPUT); + + lyt.assign_cell_type({36, 19, 0}, Lyt::cell_type::NORMAL); + + return lyt; +}; +/** + * This layout represents the Crossing, as proposed in the paper + * titled \"Hexagons are the Bestagons: Design Automation for Silicon Dangling Bond Logic\" authored by + * Marcel Walter, Samuel Sze Hang Ng, Konrad Walus, and Robert Wille. + * + * (https://github.com/cda-tum/mnt-bestagon-library/blob/main/bestagon-gates/2i2o_cx/22_hex_inputsdbp_cx_try2_v0.sqd) + */ template Lyt bestagon_crossing_gate() noexcept { From cb2edd089873a9cefc4464256bfd2b4e97038038 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 12:40:33 +0200 Subject: [PATCH 052/221] :art: small fix. --- docs/algorithms/sidb_simulation.rst | 7 ++++++ ...rge_change_for_all_input_combinations.hpp} | 24 +++++++++++++------ ...rge_change_for_all_input_combinations.cpp} | 8 ++++--- 3 files changed, 29 insertions(+), 10 deletions(-) rename include/fiction/algorithms/simulation/sidb/{assess_physical_population_stability_sidb_gate.hpp => calculate_min_potential_for_charge_change_for_all_input_combinations.hpp} (76%) rename test/algorithms/simulation/sidb/{assess_physical_population_stability_sidb_gate.cpp => calculate_min_potential_for_charge_change_for_all_input_combinations.cpp} (81%) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 998084b4c..ffe21b690 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -366,6 +366,13 @@ Assess Population Stability :members: .. doxygenfunction:: fiction::assess_physical_population_stability + **Header:** ``fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp`` + + .. doxygenstruct:: fiction::calculate_min_potential_for_charge_change_for_all_input_combinations_params + :members: + .. doxygenfunction:: fiction::calculate_min_potential_for_charge_change_for_all_input_combinations + + .. tab:: Python .. autoclass:: mnt.pyfiction.transition_type :members: diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp similarity index 76% rename from include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp rename to include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp index f2b5ae3bd..acd294ee7 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp @@ -2,8 +2,8 @@ // Created by Jan Drewniok on 28.01.24. // -#ifndef FICTION_ASSESS_PHYSICAL_POPULATION_STABILITY_SIDB_GATE_HPP -#define FICTION_ASSESS_PHYSICAL_POPULATION_STABILITY_SIDB_GATE_HPP +#ifndef FICTION_CALCULATE_MIN_POTENTIAL_FOR_CHARGE_CHANGE_FOR_ALL_INPUT_COMBINATIONS_HPP +#define FICTION_CALCULATE_MIN_POTENTIAL_FOR_CHARGE_CHANGE_FOR_ALL_INPUT_COMBINATIONS_HPP #include "fiction/algorithms/iter/bdl_input_iterator.hpp" #include "fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp" @@ -21,7 +21,7 @@ namespace fiction /** * This struct stores the parameters required to assess the population stability of an SiDB gate. */ -struct assess_physical_population_stability_params_sidb_gate +struct calculate_min_potential_for_charge_change_for_all_input_combinations_params { /** * Parameter to as @@ -29,12 +29,22 @@ struct assess_physical_population_stability_params_sidb_gate assess_physical_population_stability_params assess_population_stability_params{}; detect_bdl_pairs_params detect_pair_params{}; }; - +/** + * Calculates the minimum potential required to induce charge changes in an SiDB layout for all input combinations. + * + * @tparam Lyt Type representing the SiDB cell-level layout. + * @tparam TT Type representing the truth table. + * @param lyt The SiDB layout object. + * @param spec Expected Boolean function of the layout, provided as a multi-output truth table. + * @param params Parameters for assessing physical population stability. + * @param charge_state_change Optional parameter indicating the direction of charge state change (default is 1). + * @return The minimum potential required for charge change across all input combinations. + */ template [[nodiscard]] double calculate_min_potential_for_charge_change_for_all_input_combinations( const Lyt& lyt, const std::vector& spec, - const assess_physical_population_stability_params_sidb_gate& params = {}, - const std::optional charge_state_change = 1) noexcept + const calculate_min_potential_for_charge_change_for_all_input_combinations_params& params = {}, + const std::optional charge_state_change = 1) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -98,4 +108,4 @@ template } // namespace fiction -#endif // FICTION_ASSESS_PHYSICAL_POPULATION_STABILITY_SIDB_GATE_HPP +#endif // FICTION_CALCULATE_MIN_POTENTIAL_FOR_CHARGE_CHANGE_FOR_ALL_INPUT_COMBINATIONS_HPP diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp b/test/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.cpp similarity index 81% rename from test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp rename to test/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.cpp index d28b958ab..58edefe91 100644 --- a/test/algorithms/simulation/sidb/assess_physical_population_stability_sidb_gate.cpp +++ b/test/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.cpp @@ -2,13 +2,15 @@ // Created by Jan Drewniok on 04.02.24. // -#include +#include #include #include "utils/blueprints/layout_blueprints.hpp" -#include +#include +#include #include +#include #include #include @@ -22,7 +24,7 @@ TEST_CASE("Single SiDB", "[assess-physical-population-stability-sidb-gate]") { const auto lyt = blueprints::bestagon_and_gate(); - const auto params = assess_physical_population_stability_params_sidb_gate{ + const auto params = calculate_min_potential_for_charge_change_for_all_input_combinations_params{ assess_physical_population_stability_params{sidb_simulation_parameters{2, -0.32}, 2}}; SECTION("Minimal potential required to conduct a charge change from neutral to negative") From 1191d51f8df2ba728c754beefcf0850d37f8a93a Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 12:51:07 +0200 Subject: [PATCH 053/221] :art: fix inconsistencies. --- docs/algorithms/sidb_simulation.rst | 2 +- .../defect_influence_operational_domain.hpp | 77 ++++++++----------- .../defect_influence_operational_domain.cpp | 6 +- 3 files changed, 34 insertions(+), 51 deletions(-) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index ffe21b690..3bb4d123e 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -276,7 +276,7 @@ Defect Influence Operational Domain **Header:** ``fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp`` -.. doxygenstruct:: fiction::defect_operational_domain_params +.. doxygenstruct:: fiction::defect_influence_operational_domain_params :members: .. doxygenstruct:: fiction::defect_influence_operational_domain :members: diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index f488df6ad..6576fb2ca 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -10,16 +10,25 @@ #include "fiction/layouts/bounding_box.hpp" #include "fiction/layouts/coordinates.hpp" #include "fiction/technology/sidb_defect_surface.hpp" -#include "fiction/types.hpp" -#include "fiction/utils/hash.hpp" +#include "fiction/technology/sidb_defects.hpp" #include "fiction/utils/layout_utils.hpp" #include "fiction/utils/phmap_utils.hpp" -#include "mockturtle/utils/stopwatch.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include namespace fiction { -struct defect_operational_domain_params +struct defect_influence_operational_domain_params { /** * Parameters to simulate the influence of the atomic defect. @@ -75,11 +84,12 @@ struct defect_influence_operational_stats namespace detail { template -class defect_influence_impl +class defect_influence_operational_domain_impl { public: - defect_influence_impl(const Lyt& lyt, const std::vector& tt, const defect_operational_domain_params& ps, - defect_influence_operational_stats& st) : + defect_influence_operational_domain_impl(const Lyt& lyt, const std::vector& tt, + const defect_influence_operational_domain_params& ps, + defect_influence_operational_stats& st) : layout{lyt}, truth_table{tt}, params{ps}, @@ -249,32 +259,6 @@ class defect_influence_impl nw_cell = nw; se_cell = se; } - - [[nodiscard]] std::optional find_non_operational_defect_position_via_sidbs() noexcept - { - layout.foreach_cell( - [this](const auto& c) - { - auto c_copy = c; - c_copy.x = c.x - 1; - if (layout.is_empty_cell(c_copy)) - { - layout.assign_sidb_defect(c_copy, params.defect_influence_params.defect); - // determine the operational status - const auto operational_value = is_defect_position_operational(c_copy); - - layout.assign_sidb_defect(c_copy, sidb_defect{sidb_defect_type::NONE}); - - // if the parameter combination is operational, return its step values in x and y dimension - if (operational_value == operational_status::NON_OPERATIONAL) - { - return c_copy; - } - } - }); - return std::nullopt; - } - /** * This function aims to identify an operational defect position within the layout. It does so by selecting a defect * position with the leftmost x-coordinate and a y-coordinate aligned with the layout's bounding box. @@ -531,7 +515,7 @@ class defect_influence_impl /** * The parameters for the operational domain computation. */ - const defect_operational_domain_params& params; + const defect_influence_operational_domain_params& params; /** * North-west cell. */ @@ -595,16 +579,16 @@ class defect_influence_impl template defect_influence_operational_domain defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vector& spec, std::size_t step_size = 1, - const defect_operational_domain_params& params = {}, - defect_influence_operational_stats* stats = nullptr) + const defect_influence_operational_domain_params& params = {}, + defect_influence_operational_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); static_assert(has_cube_coord_v || has_siqad_coord_v, "Lyt is not based on cube coordinates"); - defect_influence_operational_stats st{}; - detail::defect_influence_impl p{lyt, spec, params, st}; + defect_influence_operational_stats st{}; + detail::defect_influence_operational_domain_impl p{lyt, spec, params, st}; const auto result = p.grid_search(step_size); @@ -615,7 +599,6 @@ defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vecto return result; } - /** * Computes the defect influence operational domain of the given SiDB cell-level layout. The defect influence * operational domain is the set of all defect positions for which the layout is logically operational. Logical @@ -637,16 +620,16 @@ defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vecto template defect_influence_operational_domain defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::vector& spec, std::size_t samples, - const defect_operational_domain_params& params = {}, - defect_influence_operational_stats* stats = nullptr) + const defect_influence_operational_domain_params& params = {}, + defect_influence_operational_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); static_assert(has_cube_coord_v, "Lyt is not based on cube coordinates"); - defect_influence_operational_stats st{}; - detail::defect_influence_impl p{lyt, spec, params, st}; + defect_influence_operational_stats st{}; + detail::defect_influence_operational_domain_impl p{lyt, spec, params, st}; const auto result = p.random_sampling(samples); @@ -678,16 +661,16 @@ defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::v template defect_influence_operational_domain defect_influence_operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, std::size_t samples, - const defect_operational_domain_params& params = {}, - defect_influence_operational_stats* stats = nullptr) + const defect_influence_operational_domain_params& params = {}, + defect_influence_operational_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); static_assert(has_cube_coord_v || has_siqad_coord_v, "Lyt is not based on cube coordinates"); - defect_influence_operational_stats st{}; - detail::defect_influence_impl p{lyt, spec, params, st}; + defect_influence_operational_stats st{}; + detail::defect_influence_operational_domain_impl p{lyt, spec, params, st}; const auto result = p.contour_tracing(samples); diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index caea20966..60fd1d8f7 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -60,10 +60,10 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again const auto cube_lyt = convert_to_fiction_coordinates(lyt); - const sidb_defect sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}; - // const sidb_defect sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}; + const sidb_defect sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}; const maximum_defect_influence_distance_params sim_params{sidb_defect, sidb_simulation_parameters{2, -0.32}}; - defect_operational_domain_params params{sim_params, is_operational_params{sim_params.simulation_parameters}}; + defect_influence_operational_domain_params params{sim_params, + is_operational_params{sim_params.simulation_parameters}}; SECTION("Grid Search") { From 3682bc419fde0b7079edb2b6e2aebcbcb723e478 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 11:06:05 +0000 Subject: [PATCH 054/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operational_domain/operational_domain_siqad.cpp | 10 +++++----- ...al_for_charge_change_for_all_input_combinations.hpp | 2 +- .../simulation/sidb/critical_temperature.hpp | 3 ++- .../algorithms/simulation/sidb/operational_domain.hpp | 2 +- test/algorithms/simulation/sidb/is_operational.cpp | 4 +--- .../maximum_defect_influence_position_and_distance.cpp | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/experiments/operational_domain/operational_domain_siqad.cpp b/experiments/operational_domain/operational_domain_siqad.cpp index d75a5da07..7843fedf4 100644 --- a/experiments/operational_domain/operational_domain_siqad.cpp +++ b/experiments/operational_domain/operational_domain_siqad.cpp @@ -98,13 +98,13 @@ int main() // NOLINT // compute the operational domains const auto op_domain_gs = - operational_domain_grid_search(lyt, truth_table, op_domain_params,&op_domain_stats_gs); + operational_domain_grid_search(lyt, truth_table, op_domain_params, &op_domain_stats_gs); const auto op_domain_rs = operational_domain_random_sampling(lyt, truth_table, 2500, op_domain_params, &op_domain_stats_rs); - const auto op_domain_ff = - operational_domain_flood_fill(lyt, truth_table, 250, op_domain_params, std::nullopt, &op_domain_stats_ff); - const auto op_domain_ct = - operational_domain_contour_tracing(lyt, truth_table, 100, op_domain_params,std::nullopt, &op_domain_stats_ct); + const auto op_domain_ff = operational_domain_flood_fill(lyt, truth_table, 250, op_domain_params, + std::nullopt, &op_domain_stats_ff); + const auto op_domain_ct = operational_domain_contour_tracing(lyt, truth_table, 100, op_domain_params, + std::nullopt, &op_domain_stats_ct); // write the operational domains to a CSV file write_operational_domain(op_domain_gs, diff --git a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp index acd294ee7..67e812ced 100644 --- a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp +++ b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp @@ -44,7 +44,7 @@ template [[nodiscard]] double calculate_min_potential_for_charge_change_for_all_input_combinations( const Lyt& lyt, const std::vector& spec, const calculate_min_potential_for_charge_change_for_all_input_combinations_params& params = {}, - const std::optional charge_state_change = 1) + const std::optional charge_state_change = 1) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); diff --git a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp index 1b3e7b047..6b0bcc680 100644 --- a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp +++ b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp @@ -467,7 +467,8 @@ double critical_temperature_gate_based(const Lyt& lyt, const std::vector& sp assert(!spec.empty()); // all elements in tts must have the same number of variables - assert(std::adjacent_find(spec.cbegin(), spec.cend(), [](const auto& a, const auto& b) + assert(std::adjacent_find(spec.cbegin(), spec.cend(), + [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.cend()); critical_temperature_stats st{}; diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index 3afaf04cc..0b8f7ad0d 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -9,9 +9,9 @@ #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_engine.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" +#include "fiction/layouts/cell_level_layout.hpp" #include "fiction/technology/cell_technologies.hpp" #include "fiction/technology/physical_constants.hpp" -#include "fiction/layouts/cell_level_layout.hpp" #include "fiction/traits.hpp" #include "fiction/utils/execution_utils.hpp" #include "fiction/utils/hash.hpp" diff --git a/test/algorithms/simulation/sidb/is_operational.cpp b/test/algorithms/simulation/sidb/is_operational.cpp index b27f45bf8..5996a5bee 100644 --- a/test/algorithms/simulation/sidb/is_operational.cpp +++ b/test/algorithms/simulation/sidb/is_operational.cpp @@ -8,15 +8,13 @@ #include "utils/blueprints/layout_blueprints.hpp" #include +#include #include #include #include #include #include #include -#include -#include -#include #include #include diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp index a1ed8f6f4..7b9b0823a 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp @@ -9,9 +9,9 @@ #include #include -#include #include #include +#include #include #include #include From f24b41de3dfd94ed4b8eb948a118c941bf969348 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 13:23:37 +0200 Subject: [PATCH 055/221] :memo: fix bug in docu. --- docs/algorithms/sidb_simulation.rst | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 3bb4d123e..ff07d98fd 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -175,6 +175,13 @@ Maximum Defect Influence Distance .. doxygenfunction:: fiction::maximum_defect_influence_position_and_distance +**Header:** ``fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp`` + +.. doxygenstruct:: fiction::maximum_defect_influence_position_and_distance_of_sidb_gate_params + :members: +.. doxygenfunction:: fiction::maximum_defect_influence_position_and_distance_of_sidb_gate + + Time-to-Solution (TTS) Statistics ################################# @@ -400,12 +407,4 @@ Maximum Minimum Defect Influence Distance **Header:** ``fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp`` -.. doxygenstruct:: fiction::maximum_minimum_defect_influence_distance_params - :members: .. doxygenfunction:: fiction::maximum_minimum_defect_influence_distance - -**Header:** ``fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance_of_sidb_gate.hpp`` - -.. doxygenstruct:: fiction::maximum_defect_influence_position_and_distance_of_sidb_gate_params - :members: -.. doxygenfunction:: fiction::maximum_defect_influence_position_and_distance_of_sidb_gate From 5512dcef51550fb758f97c5c6381ead2285cc1d2 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 14:22:17 +0200 Subject: [PATCH 056/221] :art: add docu and small fixes. --- docs/algorithms/sidb_simulation.rst | 6 ++- .../defect_influence_operational_domain.hpp | 28 ++++++------ ...defect_influence_position_and_distance.hpp | 32 ++++++------- ...nce_position_and_distance_of_sidb_gate.hpp | 12 +++-- ...imum_minimum_defect_influence_distance.hpp | 6 +-- include/fiction/utils/layout_utils.hpp | 2 +- include/fiction/utils/math_utils.hpp | 3 +- .../defect_influence_operational_domain.cpp | 45 ++++++------------- ...defect_influence_position_and_distance.cpp | 34 +++++++------- .../sidb/random_sidb_layout_generator.cpp | 2 +- 10 files changed, 78 insertions(+), 92 deletions(-) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index ff07d98fd..e77d9e40a 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -170,7 +170,9 @@ Maximum Defect Influence Distance **Header:** ``fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp`` -.. doxygenstruct:: fiction::maximum_defect_influence_distance_params +.. doxygenstruct:: fiction::maximum_defect_influence_position_and_distance_params + :members: +.. doxygenstruct:: fiction::maximum_defect_influence_position_and_distance_stats :members: .. doxygenfunction:: fiction::maximum_defect_influence_position_and_distance @@ -287,7 +289,7 @@ Defect Influence Operational Domain :members: .. doxygenstruct:: fiction::defect_influence_operational_domain :members: -.. doxygenstruct:: fiction::defect_influence_operational_stats +.. doxygenstruct:: fiction::defect_influence_operational_domain_stats :members: .. doxygenfunction:: fiction::defect_influence_operational_domain_grid_search .. doxygenfunction:: fiction::defect_influence_operational_domain_random_sampling diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 6576fb2ca..d2dfd28c2 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -27,13 +27,15 @@ namespace fiction { - +/** + * Parameters to determine the defect influence operational domain. + */ struct defect_influence_operational_domain_params { /** * Parameters to simulate the influence of the atomic defect. */ - maximum_defect_influence_distance_params defect_influence_params{}; + maximum_defect_influence_position_and_distance_params defect_influence_params{}; /** * Parameters for the `is_operational` algorithm. */ @@ -57,7 +59,7 @@ struct defect_influence_operational_domain /** * Statistics. */ -struct defect_influence_operational_stats +struct defect_influence_operational_domain_stats { /** * The total runtime of the operational domain computation. @@ -89,7 +91,7 @@ class defect_influence_operational_domain_impl public: defect_influence_operational_domain_impl(const Lyt& lyt, const std::vector& tt, const defect_influence_operational_domain_params& ps, - defect_influence_operational_stats& st) : + defect_influence_operational_domain_stats& st) : layout{lyt}, truth_table{tt}, params{ps}, @@ -189,11 +191,9 @@ class defect_influence_operational_domain_impl current_neighborhood.front() : next_clockwise_point(current_neighborhood, backtrack_point); - uint64_t counter = 0; - bool contour_around_gate = false; + bool contour_around_gate = false; while (next_point != contour_starting_point) { - counter++; const auto operational_status = is_defect_position_operational(next_point); if (next_point.x >= se_bb_layout.x) { @@ -547,7 +547,7 @@ class defect_influence_operational_domain_impl /** * The statistics of the operational domain computation. */ - defect_influence_operational_stats& stats; + defect_influence_operational_domain_stats& stats; /** * Number of simulator invocations. */ @@ -580,14 +580,14 @@ template defect_influence_operational_domain defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vector& spec, std::size_t step_size = 1, const defect_influence_operational_domain_params& params = {}, - defect_influence_operational_stats* stats = nullptr) + defect_influence_operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); static_assert(has_cube_coord_v || has_siqad_coord_v, "Lyt is not based on cube coordinates"); - defect_influence_operational_stats st{}; + defect_influence_operational_domain_stats st{}; detail::defect_influence_operational_domain_impl p{lyt, spec, params, st}; const auto result = p.grid_search(step_size); @@ -621,14 +621,14 @@ template defect_influence_operational_domain defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::vector& spec, std::size_t samples, const defect_influence_operational_domain_params& params = {}, - defect_influence_operational_stats* stats = nullptr) + defect_influence_operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); static_assert(has_cube_coord_v, "Lyt is not based on cube coordinates"); - defect_influence_operational_stats st{}; + defect_influence_operational_domain_stats st{}; detail::defect_influence_operational_domain_impl p{lyt, spec, params, st}; const auto result = p.random_sampling(samples); @@ -662,14 +662,14 @@ template defect_influence_operational_domain defect_influence_operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, std::size_t samples, const defect_influence_operational_domain_params& params = {}, - defect_influence_operational_stats* stats = nullptr) + defect_influence_operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); static_assert(has_cube_coord_v || has_siqad_coord_v, "Lyt is not based on cube coordinates"); - defect_influence_operational_stats st{}; + defect_influence_operational_domain_stats st{}; detail::defect_influence_operational_domain_impl p{lyt, spec, params, st}; const auto result = p.contour_tracing(samples); diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 745b7cc4d..87e07600b 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -11,7 +11,7 @@ #include "fiction/layouts/bounding_box.hpp" #include "fiction/technology/sidb_defect_surface.hpp" #include "fiction/technology/sidb_defects.hpp" -#include "fiction/types.hpp" +#include "fiction/traits.hpp" #include "fiction/utils/execution_utils.hpp" #include "fiction/utils/layout_utils.hpp" @@ -31,7 +31,7 @@ namespace fiction /** * This struct stores the parameters for the maximum_defect_influence_position_and_distance algorithm. */ -struct maximum_defect_influence_distance_params +struct maximum_defect_influence_position_and_distance_params { /** * The defect to calculate the maximum defect influence distance for. @@ -53,7 +53,7 @@ struct maximum_defect_influence_distance_params /** * Statistics for the maximum defect influence simulation. */ -struct maximum_defect_influence_distance_stats +struct maximum_defect_influence_position_and_distance_stats { /** * The total runtime of the maximum defect influence simulation. @@ -78,9 +78,9 @@ template class maximum_defect_influence_position_and_distance_impl { public: - maximum_defect_influence_position_and_distance_impl(const Lyt& lyt, - const maximum_defect_influence_distance_params& sim_params, - maximum_defect_influence_distance_stats& st) : + maximum_defect_influence_position_and_distance_impl( + const Lyt& lyt, const maximum_defect_influence_position_and_distance_params& sim_params, + maximum_defect_influence_position_and_distance_stats& st) : layout{lyt}, params{sim_params}, stats{st} @@ -179,16 +179,13 @@ class maximum_defect_influence_position_and_distance_impl } }; - const size_t num_threads = std::thread::hardware_concurrency(); // Anzahl der verfügbaren Threads + const size_t num_threads = std::thread::hardware_concurrency(); - // Größe jedes Chunks berechnen const size_t chunk_size = (defect_cells.size() + num_threads - 1) / num_threads; - // Vektor für Threads std::vector threads; threads.reserve(num_threads); - // Aufteilen des Vektors in Chunks und Starten von Threads für jeden Chunk auto defect_it = defect_cells.begin(); for (size_t i = 0; i < num_threads; ++i) { @@ -201,7 +198,7 @@ class maximum_defect_influence_position_and_distance_impl defect_it = chunk_end; if (defect_it == defect_cells.end()) { - break; // Alle Defekte wurden aufgeteilt + break; } } @@ -221,11 +218,11 @@ class maximum_defect_influence_position_and_distance_impl /** * Parameters used for the simulation. */ - maximum_defect_influence_distance_params params{}; + maximum_defect_influence_position_and_distance_params params{}; /** * The statistics of the maximum defect influence position. */ - maximum_defect_influence_distance_stats& stats; + maximum_defect_influence_position_and_distance_stats& stats; /** * All allowed defect positions. */ @@ -274,17 +271,16 @@ class maximum_defect_influence_position_and_distance_impl * layout. */ template -std::pair -maximum_defect_influence_position_and_distance(const Lyt& lyt, - const maximum_defect_influence_distance_params& sim_params = {}, - maximum_defect_influence_distance_stats* pst = nullptr) +std::pair maximum_defect_influence_position_and_distance( + const Lyt& lyt, const maximum_defect_influence_position_and_distance_params& sim_params = {}, + maximum_defect_influence_position_and_distance_stats* pst = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(!has_offset_ucoord_v, "Lyt cannot be based on offset coordinates"); static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); - maximum_defect_influence_distance_stats st{}; + maximum_defect_influence_position_and_distance_stats st{}; detail::maximum_defect_influence_position_and_distance_impl p{lyt, sim_params, st}; diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index 4218e7e97..fb99d068a 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -8,7 +8,11 @@ #include "fiction/algorithms/iter/bdl_input_iterator.hpp" #include "fiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" #include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" -#include "fiction/utils/layout_utils.hpp" +#include "fiction/traits.hpp" + +#include +#include +#include namespace fiction { @@ -21,7 +25,7 @@ struct maximum_defect_influence_position_and_distance_of_sidb_gate_params /** * Parameters for the defect influence simulation. */ - maximum_defect_influence_distance_params defect_influence_params{}; + maximum_defect_influence_position_and_distance_params defect_influence_params{}; /** * Parameters for the detection of BDL pairs. */ @@ -68,8 +72,8 @@ template // number of different input combinations for (auto i = 0u; i < spec.front().num_bits(); ++i, ++bii) { - maximum_defect_influence_distance_stats stats_defect{}; - const auto influence_cell_distance = + maximum_defect_influence_position_and_distance_stats stats_defect{}; + const auto influence_cell_distance = maximum_defect_influence_position_and_distance(lyt, params.defect_influence_params, &stats_defect); if (influence_cell_distance.second > maximum_defect_influence_distance) { diff --git a/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp index 5c9b7a847..1a810df13 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp @@ -6,9 +6,9 @@ #define FICTION_MAXIMUM_MINIMUM_DEFECT_INFLUENCE_DISTANCE_HPP #include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" -#include "fiction/algorithms/simulation/sidb/operational_domain.hpp" -#include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" -#include "fiction/layouts/cell_level_layout.hpp" +#include "fiction/algorithms/simulation/sidb/is_operational.hpp" + +#include namespace fiction { diff --git a/include/fiction/utils/layout_utils.hpp b/include/fiction/utils/layout_utils.hpp index 79e66b47d..f6b22cabd 100644 --- a/include/fiction/utils/layout_utils.hpp +++ b/include/fiction/utils/layout_utils.hpp @@ -418,7 +418,7 @@ LytDest convert_to_fiction_coordinates(const LytSrc& lyt) noexcept return convert_to_fiction_coordinates(normalize_layout_coordinates(lyt)); } - auto process_layout = [&lyt](auto lyt_new) + auto process_layout = [&](auto lyt_new) { if constexpr (is_sidb_lattice_v) { diff --git a/include/fiction/utils/math_utils.hpp b/include/fiction/utils/math_utils.hpp index 66130bdc5..947c7e0a2 100644 --- a/include/fiction/utils/math_utils.hpp +++ b/include/fiction/utils/math_utils.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -127,7 +128,7 @@ determine_all_combinations_of_distributing_k_entities_on_n_positions(const std:: * * @throws std::invalid_argument If the sizes of chis and weights vectors are different. */ -double cost_function_chi(const std::vector& chis, const std::vector& weights) +[[nodiscard]] inline double cost_function_chi(const std::vector& chis, const std::vector& weights) { if (chis.size() != weights.size()) { diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 60fd1d8f7..909d9f751 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -2,21 +2,24 @@ // Created by Jan Drewniok on 07.02.24. // -#include +#include #include #include #include +#include #include #include -#include #include #include +#include #include -#include #include +#include #include +#include + using namespace fiction; TEST_CASE("novel designed AND Gate influence distance function which fails again", @@ -60,56 +63,36 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again const auto cube_lyt = convert_to_fiction_coordinates(lyt); - const sidb_defect sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}; - const maximum_defect_influence_distance_params sim_params{sidb_defect, sidb_simulation_parameters{2, -0.32}}; - defect_influence_operational_domain_params params{sim_params, + const sidb_defect sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}; + const maximum_defect_influence_position_and_distance_params sim_params{sidb_defect, + sidb_simulation_parameters{2, -0.32}}; + defect_influence_operational_domain_params params{sim_params, is_operational_params{sim_params.simulation_parameters}}; SECTION("Grid Search") { params.defect_influence_params.additional_scanning_area = {10, 10}; - defect_influence_operational_stats stats{}; - const auto defect_influence_domain = defect_influence_operational_domain_grid_search( + defect_influence_operational_domain_stats stats{}; + const auto defect_influence_domain = defect_influence_operational_domain_grid_search( cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); CHECK_THAT(maximum_minimum_defect_influence_distance(cube_lyt, defect_influence_domain), Catch::Matchers::WithinAbs(11.6138152646, physical_constants::POP_STABILITY_ERR)); - - write_operational_domain_params write_params{}; - write_params.operational_tag = "1"; - write_params.non_operational_tag = "0"; - write_defect_influence_operational_domain( - defect_influence_domain, - "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", write_params); } SECTION("Random Sampling") { params.defect_influence_params.additional_scanning_area = {0, 0}; - defect_influence_operational_stats stats{}; + defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_random_sampling( cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); CHECK(maximum_minimum_defect_influence_distance(cube_lyt, defect_influence_domain) < 11.61); - - write_operational_domain_params write_params{}; - write_params.operational_tag = "1"; - write_params.non_operational_tag = "0"; - write_defect_influence_operational_domain( - defect_influence_domain, - "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", write_params); } SECTION("Contour Tracing") { params.defect_influence_params.additional_scanning_area = {20, 20}; - defect_influence_operational_stats stats{}; + defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_contour_tracing( cube_lyt, std::vector{create_or_tt()}, 10, params, &stats); CHECK(maximum_minimum_defect_influence_distance(cube_lyt, defect_influence_domain) > 11.61); - - write_operational_domain_params write_params{}; - write_params.operational_tag = "1"; - write_params.non_operational_tag = "0"; - write_defect_influence_operational_domain( - defect_influence_domain, - "/Users/jandrewniok/CLionProjects/fiction_copy/fiction/experiments/test_defect_op.csv", write_params); } } diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp index 7b9b0823a..861256405 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp @@ -5,14 +5,12 @@ #include #include -#include "mockturtle/utils/stopwatch.hpp" - -#include #include #include #include #include #include +#include #include #include #include @@ -26,9 +24,9 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio { SECTION("empty layout") { - const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, 10.6, 5.9}; - const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{}}; - const sidb_cell_clk_lyt_siqad lyt{}; + const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, 10.6, 5.9}; + const maximum_defect_influence_position_and_distance_params sim_params{defect, sidb_simulation_parameters{}}; + const sidb_cell_clk_lyt_siqad lyt{}; const sidb_100_cell_clk_lyt_siqad lat{lyt}; @@ -41,7 +39,9 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio { const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, sidb_simulation_parameters{}.lambda_tf}; - const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{}, {2, 2}}; + const maximum_defect_influence_position_and_distance_params sim_params{defect, + sidb_simulation_parameters{}, + {2, 2}}; sidb_cell_clk_lyt_siqad lyt{}; lyt.assign_cell_type({0, 0, 0}, sidb_cell_clk_lyt_siqad::cell_type::NORMAL); @@ -58,8 +58,8 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio SECTION("layout with one SiDB, negative defect, smaller lambda_tf") { const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, 1}; - const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{}}; - sidb_cell_clk_lyt_siqad lyt{}; + const maximum_defect_influence_position_and_distance_params sim_params{defect, sidb_simulation_parameters{}}; + sidb_cell_clk_lyt_siqad lyt{}; lyt.assign_cell_type({0, 0, 0}, sidb_cell_clk_lyt_siqad::cell_type::NORMAL); const sidb_100_cell_clk_lyt_siqad lat{lyt}; @@ -73,7 +73,7 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio SECTION("layout with one SiDB, negative defect, large lambda_tf") { const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, 20}; - const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{}, {2, 2}}; + const maximum_defect_influence_position_and_distance_params sim_params{defect, sidb_simulation_parameters{}, {2, 2}}; sidb_cell_clk_lyt_siqad lyt{}; lyt.assign_cell_type({0, 0, 0}, sidb_cell_clk_lyt_siqad::cell_type::NORMAL); @@ -89,8 +89,8 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio { const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, sidb_simulation_parameters{}.lambda_tf}; - const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{}}; - sidb_cell_clk_lyt_siqad lyt{}; + const maximum_defect_influence_position_and_distance_params sim_params{defect, sidb_simulation_parameters{}}; + sidb_cell_clk_lyt_siqad lyt{}; lyt.assign_cell_type({0, 0, 0}, sidb_cell_clk_lyt_siqad::cell_type::NORMAL); lyt.assign_cell_type({4, 0, 0}, sidb_cell_clk_lyt_siqad::cell_type::NORMAL); lyt.assign_cell_type({6, 0, 0}, sidb_cell_clk_lyt_siqad::cell_type::NORMAL); @@ -107,8 +107,8 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio { const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, sidb_simulation_parameters{}.lambda_tf}; - const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{}}; - sidb_cell_clk_lyt_siqad lyt{}; + const maximum_defect_influence_position_and_distance_params sim_params{defect, sidb_simulation_parameters{}}; + sidb_cell_clk_lyt_siqad lyt{}; lyt.assign_cell_type({10, 0, 0}, sidb_cell_clk_lyt_siqad::cell_type::NORMAL); lyt.assign_cell_type({0, 1, 0}, sidb_cell_clk_lyt_siqad::cell_type::NORMAL); @@ -131,7 +131,7 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio // number of threads given by the hardware const sidb_defect high_screening{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, 1}; - const maximum_defect_influence_distance_params sim_params_high_screening{high_screening, + const maximum_defect_influence_position_and_distance_params sim_params_high_screening{high_screening, sidb_simulation_parameters{}}; const auto [defect_pos_high_screening, distance_high_screening] = @@ -144,8 +144,8 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio { const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, sidb_simulation_parameters{}.lambda_tf}; - const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{}}; - sidb_cell_clk_lyt_cube lyt{{30, 30}}; + const maximum_defect_influence_position_and_distance_params sim_params{defect, sidb_simulation_parameters{}}; + sidb_cell_clk_lyt_cube lyt{{30, 30}}; lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{10, 0, 0}), sidb_cell_clk_lyt_siqad::cell_type::NORMAL); diff --git a/test/algorithms/simulation/sidb/random_sidb_layout_generator.cpp b/test/algorithms/simulation/sidb/random_sidb_layout_generator.cpp index fa4aa2303..5d18218ff 100644 --- a/test/algorithms/simulation/sidb/random_sidb_layout_generator.cpp +++ b/test/algorithms/simulation/sidb/random_sidb_layout_generator.cpp @@ -8,9 +8,9 @@ #include #include #include -#include #include #include +#include #include #include From 6daa45e06f0008c841583e565d205e2de588c78d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 12:22:37 +0000 Subject: [PATCH 057/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...aximum_defect_influence_position_and_distance.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp index 861256405..63042fe46 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp @@ -10,11 +10,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include @@ -73,8 +73,10 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio SECTION("layout with one SiDB, negative defect, large lambda_tf") { const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, 20}; - const maximum_defect_influence_position_and_distance_params sim_params{defect, sidb_simulation_parameters{}, {2, 2}}; - sidb_cell_clk_lyt_siqad lyt{}; + const maximum_defect_influence_position_and_distance_params sim_params{defect, + sidb_simulation_parameters{}, + {2, 2}}; + sidb_cell_clk_lyt_siqad lyt{}; lyt.assign_cell_type({0, 0, 0}, sidb_cell_clk_lyt_siqad::cell_type::NORMAL); const sidb_100_cell_clk_lyt_siqad lat{lyt}; @@ -131,8 +133,8 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio // number of threads given by the hardware const sidb_defect high_screening{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, 1}; - const maximum_defect_influence_position_and_distance_params sim_params_high_screening{high_screening, - sidb_simulation_parameters{}}; + const maximum_defect_influence_position_and_distance_params sim_params_high_screening{ + high_screening, sidb_simulation_parameters{}}; const auto [defect_pos_high_screening, distance_high_screening] = maximum_defect_influence_position_and_distance(lat, sim_params_high_screening); From a44aa99361a92fa5b5541d78145d9e9f4e79529a Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 17:15:52 +0200 Subject: [PATCH 058/221] :art: renaming. --- .../simulation/sidb/defect_influence_operational_domain.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index d2dfd28c2..6708ee122 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -39,7 +39,7 @@ struct defect_influence_operational_domain_params /** * Parameters for the `is_operational` algorithm. */ - is_operational_params is_operational_params{}; + is_operational_params operational_params{}; }; /** * A defect operational domain defines the positions where a specific atomic defect may exist along with corresponding @@ -321,7 +321,7 @@ class defect_influence_operational_domain_impl } layout.assign_sidb_defect(c, params.defect_influence_params.defect); - const auto& [status, sim_calls] = is_operational(layout, truth_table, params.is_operational_params); + const auto& [status, sim_calls] = is_operational(layout, truth_table, params.operational_params); layout.assign_sidb_defect(c, sidb_defect{sidb_defect_type::NONE}); num_simulator_invocations += sim_calls; From ab4d01c787c1ca45290f125ed3a69c9893a8a7a4 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 29 Apr 2024 17:50:35 +0200 Subject: [PATCH 059/221] :snake: update bindings. --- .../physical_design/design_sidb_gates.hpp | 14 +++++++------- .../sidb/assess_physical_population_stability.hpp | 3 ++- .../simulation/sidb/operational_domain.hpp | 8 ++++---- ...or_charge_change_for_all_input_combinations.hpp | 2 +- ...imum_defect_influence_position_and_distance.cpp | 1 - 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp index ef6ba7ac6..5f07512a0 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp @@ -6,6 +6,7 @@ #define PYFICTION_DESIGN_SIDB_GATES_HPP #include "pyfiction/documentation.hpp" +#include "pyfiction/types.hpp" #include #include @@ -27,11 +28,11 @@ void design_sidb_gates(pybind11::module& m) /** * Design approach selector type. */ - pybind11::enum_::design_sidb_gates_mode>( - m, "design_sidb_gates_mode", DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode)) - .value("EXHAUSTIVE", fiction::design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, + pybind11::enum_(m, "design_sidb_gates_mode", + DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode)) + .value("EXHAUSTIVE", fiction::design_sidb_gates_mode::EXHAUSTIVE, DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE)) - .value("RANDOM", fiction::design_sidb_gates_params::design_sidb_gates_mode::RANDOM, + .value("RANDOM", fiction::design_sidb_gates_mode::RANDOM, DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM)); /** @@ -42,8 +43,6 @@ void design_sidb_gates(pybind11::module& m) .def(py::init<>()) .def_readwrite("simulation_parameters", &fiction::design_sidb_gates_params::simulation_parameters, DOC(fiction_design_sidb_gates_params)) - .def_readwrite("design_mode", &fiction::design_sidb_gates_params::design_mode, - DOC(fiction_design_sidb_gates_params_design_mode)) .def_readwrite("canvas", &fiction::design_sidb_gates_params::canvas, DOC(fiction_design_sidb_gates_params_canvas)) .def_readwrite("number_of_sidbs", &fiction::design_sidb_gates_params::number_of_sidbs, @@ -52,7 +51,8 @@ void design_sidb_gates(pybind11::module& m) DOC(fiction_design_sidb_gates_params_sim_engine)); m.def("design_sidb_gates", &fiction::design_sidb_gates, "skeleton"_a, "spec"_a, - "params"_a = fiction::design_sidb_gates_params{}, DOC(fiction_design_sidb_gates)); + "params"_a = fiction::design_sidb_gates_params{}, "design_mode"_a, "pstats"_a = nullptr, + DOC(fiction_design_sidb_gates)); } } // namespace detail diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 4c0df375b..f74573ea2 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -31,7 +31,8 @@ void assess_physical_population_stability(pybind11::module& m, const std::string .def(py::init<>()) .def_readwrite("critical_cell", &fiction::population_stability_information::critical_cell, DOC(fiction_population_stability_information_critical_cell)) - .def_readwrite("transition_from_to", &fiction::population_stability_information::transition_from_to, + .def_readwrite("transition_from_to_with_cell_and_required_pot", + &fiction::population_stability_information::transition_from_to_with_cell_and_required_pot, DOC(fiction_population_stability_information_transition_from_to)) .def_readwrite("minimum_potential_difference_to_transition", &fiction::population_stability_information::minimum_potential_difference_to_transition, diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp index 6fa706c59..182c203c2 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp @@ -36,12 +36,12 @@ void operational_domain(pybind11::module& m) DOC(fiction_operational_domain_random_sampling)); m.def("operational_domain_flood_fill", &fiction::operational_domain_flood_fill, "lyt"_a, "spec"_a, - "samples"_a, "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr, - DOC(fiction_operational_domain_flood_fill)); + "initial_parameter_point"_a, "samples"_a, "params"_a = fiction::operational_domain_params{}, + "stats"_a = nullptr, DOC(fiction_operational_domain_flood_fill)); m.def("operational_domain_contour_tracing", &fiction::operational_domain_contour_tracing, "lyt"_a, - "spec"_a, "samples"_a, "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr, - DOC(fiction_operational_domain_contour_tracing)); + "initial_parameter_point"_a, "spec"_a, "samples"_a, "params"_a = fiction::operational_domain_params{}, + "stats"_a = nullptr, DOC(fiction_operational_domain_contour_tracing)); } } // namespace detail diff --git a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp index 67e812ced..71a1e9f1f 100644 --- a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp +++ b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp @@ -24,7 +24,7 @@ namespace fiction struct calculate_min_potential_for_charge_change_for_all_input_combinations_params { /** - * Parameter to as + * TODO */ assess_physical_population_stability_params assess_population_stability_params{}; detect_bdl_pairs_params detect_pair_params{}; diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp index 63042fe46..d5ef5a4d4 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include From b37fb411f68222f59e81489d83f7c8609567df0d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Apr 2024 09:02:30 +0000 Subject: [PATCH 060/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../algorithms/simulation/sidb/critical_temperature.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp index 6b0bcc680..1b3e7b047 100644 --- a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp +++ b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp @@ -467,8 +467,7 @@ double critical_temperature_gate_based(const Lyt& lyt, const std::vector& sp assert(!spec.empty()); // all elements in tts must have the same number of variables - assert(std::adjacent_find(spec.cbegin(), spec.cend(), - [](const auto& a, const auto& b) + assert(std::adjacent_find(spec.cbegin(), spec.cend(), [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.cend()); critical_temperature_stats st{}; From f245d30b030d7aa0ff536970ae6179a124072301 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 30 Apr 2024 12:28:49 +0200 Subject: [PATCH 061/221] :art: add missing includes. --- ...mum_defect_influence_position_and_distance.hpp | 15 ++++++++------- .../maximum_minimum_defect_influence_distance.hpp | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 87e07600b..7b358e35f 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -12,7 +12,6 @@ #include "fiction/technology/sidb_defect_surface.hpp" #include "fiction/technology/sidb_defects.hpp" #include "fiction/traits.hpp" -#include "fiction/utils/execution_utils.hpp" #include "fiction/utils/layout_utils.hpp" #include @@ -20,8 +19,10 @@ #include #include #include -#include +#include #include +#include +#include #include #include @@ -79,10 +80,10 @@ class maximum_defect_influence_position_and_distance_impl { public: maximum_defect_influence_position_and_distance_impl( - const Lyt& lyt, const maximum_defect_influence_position_and_distance_params& sim_params, + const Lyt& lyt, maximum_defect_influence_position_and_distance_params sim_params, maximum_defect_influence_position_and_distance_stats& st) : layout{lyt}, - params{sim_params}, + params{std::move(sim_params)}, stats{st} { collect_all_defect_cells(); @@ -179,15 +180,15 @@ class maximum_defect_influence_position_and_distance_impl } }; - const size_t num_threads = std::thread::hardware_concurrency(); + const std::size_t num_threads = std::thread::hardware_concurrency(); - const size_t chunk_size = (defect_cells.size() + num_threads - 1) / num_threads; + const std::size_t chunk_size = (defect_cells.size() + num_threads - 1) / num_threads; std::vector threads; threads.reserve(num_threads); auto defect_it = defect_cells.begin(); - for (size_t i = 0; i < num_threads; ++i) + for (std::size_t i = 0; i < num_threads; ++i) { auto chunk_start = defect_it; diff --git a/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp index 1a810df13..3e2e65602 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp @@ -51,6 +51,7 @@ maximum_minimum_defect_influence_distance(const Lyt& } return max_distance; } + } // namespace fiction #endif // FICTION_MAXIMUM_MINIMUM_DEFECT_INFLUENCE_DISTANCE_HPP From 652c8e9f0f153107b159031133fce799c9cf8db6 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 30 Apr 2024 13:58:59 +0200 Subject: [PATCH 062/221] :art: restructure multithreading due to windows issue. --- ...imum_defect_influence_position_and_distance.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 7b358e35f..ecf3803cf 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -182,7 +182,7 @@ class maximum_defect_influence_position_and_distance_impl const std::size_t num_threads = std::thread::hardware_concurrency(); - const std::size_t chunk_size = (defect_cells.size() + num_threads - 1) / num_threads; + const std::size_t chunk_size = defect_cells.size() / num_threads; std::vector threads; threads.reserve(num_threads); @@ -190,19 +190,21 @@ class maximum_defect_influence_position_and_distance_impl auto defect_it = defect_cells.begin(); for (std::size_t i = 0; i < num_threads; ++i) { - auto chunk_start = defect_it; auto chunk_end = std::min(defect_it + chunk_size, defect_cells.end()); threads.emplace_back(process_defect, std::vector(chunk_start, chunk_end)); defect_it = chunk_end; - if (defect_it == defect_cells.end()) - { - break; - } } + auto chunk_start = defect_it; + auto chunk_end = defect_cells.end(); + + const auto chunk_vector = std::vector(chunk_start, chunk_end); + + threads.emplace_back(process_defect, chunk_vector); + for (auto& thread : threads) { thread.join(); From a3face704251b41b22e09ebf7c209c0cd3ebeebf Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 1 May 2024 18:12:49 +0200 Subject: [PATCH 063/221] :snake: fix bindings after changes. --- .../physical_design/design_sidb_gates.hpp | 27 +++++++++++-------- .../simulation/sidb/operational_domain.hpp | 6 ++--- .../physical_design/test_design_sidb_gates.py | 3 +-- .../sidb/test_operational_domain.py | 8 +++--- .../physical_design/design_sidb_gates.hpp | 18 +++++++------ 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp index 5f07512a0..38653159b 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp @@ -25,16 +25,6 @@ void design_sidb_gates(pybind11::module& m) namespace py = pybind11; using namespace py::literals; - /** - * Design approach selector type. - */ - pybind11::enum_(m, "design_sidb_gates_mode", - DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode)) - .value("EXHAUSTIVE", fiction::design_sidb_gates_mode::EXHAUSTIVE, - DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE)) - .value("RANDOM", fiction::design_sidb_gates_mode::RANDOM, - DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM)); - /** * Parameters. */ @@ -50,8 +40,12 @@ void design_sidb_gates(pybind11::module& m) .def_readwrite("sim_engine", &fiction::design_sidb_gates_params::sim_engine, DOC(fiction_design_sidb_gates_params_sim_engine)); + py::class_(m, "exact_stats", DOC(fiction_exact_physical_design_stats)) + .def(py::init<>()); + m.def("design_sidb_gates", &fiction::design_sidb_gates, "skeleton"_a, "spec"_a, - "params"_a = fiction::design_sidb_gates_params{}, "design_mode"_a, "pstats"_a = nullptr, + "params"_a = fiction::design_sidb_gates_params{}, + "design_mode"_a = fiction::design_sidb_gates_mode::EXHAUSTIVE, "stats"_a = nullptr, DOC(fiction_design_sidb_gates)); } @@ -59,6 +53,17 @@ void design_sidb_gates(pybind11::module& m) inline void design_sidb_gates(pybind11::module& m) { + namespace py = pybind11; + /** + * Design approach selector type. + */ + py::enum_(m, "design_sidb_gates_mode", + DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode)) + .value("EXHAUSTIVE", fiction::design_sidb_gates_mode::EXHAUSTIVE, + DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE)) + .value("RANDOM", fiction::design_sidb_gates_mode::RANDOM, + DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM)); + detail::design_sidb_gates(m); } diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp index 182c203c2..978a3ed4f 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp @@ -36,12 +36,12 @@ void operational_domain(pybind11::module& m) DOC(fiction_operational_domain_random_sampling)); m.def("operational_domain_flood_fill", &fiction::operational_domain_flood_fill, "lyt"_a, "spec"_a, - "initial_parameter_point"_a, "samples"_a, "params"_a = fiction::operational_domain_params{}, + "samples"_a, "params"_a = fiction::operational_domain_params{}, "initial_parameter_point"_a = nullptr, "stats"_a = nullptr, DOC(fiction_operational_domain_flood_fill)); m.def("operational_domain_contour_tracing", &fiction::operational_domain_contour_tracing, "lyt"_a, - "initial_parameter_point"_a, "spec"_a, "samples"_a, "params"_a = fiction::operational_domain_params{}, - "stats"_a = nullptr, DOC(fiction_operational_domain_contour_tracing)); + "spec"_a, "samples"_a, "params"_a = fiction::operational_domain_params{}, + "initial_parameter_point"_a = nullptr, "stats"_a = nullptr, DOC(fiction_operational_domain_contour_tracing)); } } // namespace detail diff --git a/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py b/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py index ee055c817..2bd0af6de 100644 --- a/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py +++ b/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py @@ -26,7 +26,6 @@ def test_siqad_and_gate_skeleton(self): params = design_sidb_gates_params() params.simulation_parameters.base = 2 params.simulation_parameters.mu_minus = -0.28 - params.design_mode = design_sidb_gates_mode.EXHAUSTIVE params.canvas = [(4, 8), (14, 11)] params.number_of_sidbs = 1 params.sim_engine = sidb_simulation_engine.QUICKEXACT @@ -36,7 +35,7 @@ def test_siqad_and_gate_skeleton(self): self.assertEqual(params.canvas[0], (4, 8, 0)) self.assertEqual(params.canvas[1], (14, 11)) - designed_gates = design_sidb_gates(layout, [create_and_tt()], params) + designed_gates = design_sidb_gates(layout, [create_and_tt()], params, design_sidb_gates_mode.EXHAUSTIVE) self.assertEqual(len(designed_gates), 23) diff --git a/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py b/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py index d9a35d9e8..0bf4d25e8 100644 --- a/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py +++ b/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py @@ -27,7 +27,7 @@ def test_xor_gate_100_lattice(self): self.assertGreater(stats_grid.num_operational_parameter_combinations, 0) stats_flood_fill = operational_domain_stats() - opdomain = operational_domain_flood_fill(lyt, [create_xor_tt()], 100, params, stats_flood_fill) + opdomain = operational_domain_flood_fill(lyt, [create_xor_tt()], 100, params, None, stats_flood_fill) self.assertGreater(stats_flood_fill.num_operational_parameter_combinations, 0) stats_random_sampling = operational_domain_stats() @@ -35,7 +35,7 @@ def test_xor_gate_100_lattice(self): self.assertGreater(stats_random_sampling.num_operational_parameter_combinations, 0) stats_contour_tracing = operational_domain_stats() - opdomain = operational_domain_contour_tracing(lyt, [create_xor_tt()], 100, params, stats_contour_tracing) + opdomain = operational_domain_contour_tracing(lyt, [create_xor_tt()], 100, params, None, stats_contour_tracing) self.assertGreater(stats_contour_tracing.num_operational_parameter_combinations, 0) def test_and_gate_111_lattice(self): @@ -59,7 +59,7 @@ def test_and_gate_111_lattice(self): self.assertGreater(stats_grid.num_operational_parameter_combinations, 0) stats_flood_fill = operational_domain_stats() - opdomain = operational_domain_flood_fill(lyt, [create_and_tt()], 100, params, stats_flood_fill) + opdomain = operational_domain_flood_fill(lyt, [create_and_tt()], 100, params, None,stats_flood_fill) self.assertGreater(stats_flood_fill.num_operational_parameter_combinations, 0) stats_random_sampling = operational_domain_stats() @@ -67,7 +67,7 @@ def test_and_gate_111_lattice(self): self.assertGreater(stats_random_sampling.num_operational_parameter_combinations, 0) stats_contour_tracing = operational_domain_stats() - opdomain = operational_domain_contour_tracing(lyt, [create_and_tt()], 100, params, stats_contour_tracing) + opdomain = operational_domain_contour_tracing(lyt, [create_and_tt()], 100, params, None, stats_contour_tracing) self.assertGreater(stats_contour_tracing.num_operational_parameter_combinations, 0) diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 5e57cbbfa..a000b7ed8 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -526,13 +526,15 @@ class design_sidb_gates_impl * @param skeleton The skeleton layout used as a starting point for gate design. * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param params Parameters for the *SiDB Gate Designer*. + * @param design_mode The design mode to use. + * @param stats The design statistics. * @return A vector of designed SiDB gate layouts. */ template [[nodiscard]] std::vector design_sidb_gates(const Lyt& skeleton, const std::vector& spec, const design_sidb_gates_params& params = {}, - design_sidb_gates_mode design_mode = design_sidb_gates_mode::EXHAUSTIVE, - design_sidb_gates_stats* pst = nullptr) noexcept + const design_sidb_gates_mode design_mode = design_sidb_gates_mode::EXHAUSTIVE, + design_sidb_gates_stats* stats = nullptr) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -560,9 +562,9 @@ design_sidb_gates(const Lyt& skeleton, const std::vector& spec, const design { result = p.run_random_design(params.maximal_random_solutions); } - if (pst) + if (stats) { - *pst = st; + *stats = st; } return result; } @@ -576,14 +578,14 @@ design_sidb_gates(const Lyt& skeleton, const std::vector& spec, const design * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param params The parameters for gate design. * @param sa_params Parameters for simulated annealing. - * @param pst Statistics for gate design. + * @param stats Statistics for gate design. * @return A layout with SiDB gates designed to minimize the cost function. */ template [[nodiscard]] Lyt design_sidb_gates_metric_driven_simulated_annealing( const Lyt& skeleton, const std::vector& spec, const design_sidb_gates_params& params, const design_sidb_gates_metric_driven_simulated_annealing_params& sa_params, - design_sidb_gates_stats* pst = nullptr) noexcept + design_sidb_gates_stats* stats = nullptr) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -603,9 +605,9 @@ template const auto result = p.run_metric_driven_design_process(sa_params); - if (pst) + if (stats) { - *pst = st; + *stats = st; } return result; } From c6f51f10f97dd582405c72ff50a63b71b3a954a2 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 2 May 2024 08:33:44 +0200 Subject: [PATCH 064/221] :snake: fix bindings after changes. --- .../physical_design/design_sidb_gates.hpp | 2 +- .../include/pyfiction/inout/read_sqd_layout.hpp | 13 ++++++++----- .../sidb/random_sidb_layout_generator.hpp | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp index 38653159b..21166e08e 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp @@ -40,7 +40,7 @@ void design_sidb_gates(pybind11::module& m) .def_readwrite("sim_engine", &fiction::design_sidb_gates_params::sim_engine, DOC(fiction_design_sidb_gates_params_sim_engine)); - py::class_(m, "exact_stats", DOC(fiction_exact_physical_design_stats)) + py::class_(m, "design_sidb_gates_stats", DOC(fiction_exact_physical_design_stats)) .def(py::init<>()); m.def("design_sidb_gates", &fiction::design_sidb_gates, "skeleton"_a, "spec"_a, diff --git a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp index 9da344f9d..fc55ed4cc 100644 --- a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp @@ -28,17 +28,20 @@ void read_sqd_layout(pybind11::module& m) py::register_exception(m, "sqd_parsing_error", PyExc_RuntimeError); - Lyt (*read_sqd_layout_function_pointer)(const std::string_view&, const std::string_view&) = - &fiction::read_sqd_layout; - if constexpr (fiction::is_sidb_lattice_100_v) { - m.def("read_sqd_layout_100", read_sqd_layout_function_pointer, "filename"_a, "layout_name"_a = "", + Lyt (*read_sqd_layout_function_pointer)(const std::string_view&, const std::string_view&) = + &fiction::read_sqd_layout; + + m.def("read_sqd_layout_100", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", DOC(fiction_read_sqd_layout_3)); } else { - m.def("read_sqd_layout_111", read_sqd_layout_function_pointer, "filename"_a, "layout_name"_a = "", + Lyt (*read_sqd_layout_function_pointer)(const std::string_view&, const std::string_view&) = + &fiction::read_sqd_layout; + + m.def("read_sqd_layout_111", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", DOC(fiction_read_sqd_layout_3)); } } diff --git a/include/fiction/algorithms/simulation/sidb/random_sidb_layout_generator.hpp b/include/fiction/algorithms/simulation/sidb/random_sidb_layout_generator.hpp index 7bc042533..e5fd66e34 100644 --- a/include/fiction/algorithms/simulation/sidb/random_sidb_layout_generator.hpp +++ b/include/fiction/algorithms/simulation/sidb/random_sidb_layout_generator.hpp @@ -63,7 +63,7 @@ struct generate_random_sidb_layout_params * is small and many SiDBs are to be placed, several tries are required to generate a layout with no positively * charged SiDBs. */ - uint64_t maximal_attempts = 10E6; + uint64_t maximal_attempts = static_cast(10E6); /** * The desired number of unique layouts to be generated. */ From be14bcd930630444fb4bca60c2cee1affbcd0d0a Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 2 May 2024 08:57:01 +0200 Subject: [PATCH 065/221] :snake: implement CodeQL comments. --- .../algorithms/simulation/sidb/test_operational_domain.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py b/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py index 0bf4d25e8..17614233f 100644 --- a/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py +++ b/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py @@ -55,19 +55,19 @@ def test_and_gate_111_lattice(self): params.y_step = 0.01 stats_grid = operational_domain_stats() - opdomain = operational_domain_grid_search(lyt, [create_and_tt()], params, stats_grid) + operational_domain_grid_search(lyt, [create_and_tt()], params, stats_grid) self.assertGreater(stats_grid.num_operational_parameter_combinations, 0) stats_flood_fill = operational_domain_stats() - opdomain = operational_domain_flood_fill(lyt, [create_and_tt()], 100, params, None,stats_flood_fill) + operational_domain_flood_fill(lyt, [create_and_tt()], 100, params, None,stats_flood_fill) self.assertGreater(stats_flood_fill.num_operational_parameter_combinations, 0) stats_random_sampling = operational_domain_stats() - opdomain = operational_domain_random_sampling(lyt, [create_and_tt()], 100, params, stats_random_sampling) + operational_domain_random_sampling(lyt, [create_and_tt()], 100, params, stats_random_sampling) self.assertGreater(stats_random_sampling.num_operational_parameter_combinations, 0) stats_contour_tracing = operational_domain_stats() - opdomain = operational_domain_contour_tracing(lyt, [create_and_tt()], 100, params, None, stats_contour_tracing) + operational_domain_contour_tracing(lyt, [create_and_tt()], 100, params, None, stats_contour_tracing) self.assertGreater(stats_contour_tracing.num_operational_parameter_combinations, 0) From 1d626be75ecfcbb04cd6aa848d4fe82aefc885fc Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 2 May 2024 14:55:27 +0200 Subject: [PATCH 066/221] :snake: small updates. --- .../physical_design/design_sidb_gates.hpp | 44 +++++----- .../physical_design/test_design_sidb_gates.py | 2 +- .../physical_design/design_sidb_gates.hpp | 20 ++--- ...defect_influence_position_and_distance.hpp | 2 +- .../physical_design/design_sidb_gates.cpp | 81 +++++++++---------- 5 files changed, 75 insertions(+), 74 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp index 21166e08e..bc8cee2ae 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp @@ -25,26 +25,8 @@ void design_sidb_gates(pybind11::module& m) namespace py = pybind11; using namespace py::literals; - /** - * Parameters. - */ - py::class_>(m, "design_sidb_gates_params", - DOC(fiction_design_sidb_gates_params)) - .def(py::init<>()) - .def_readwrite("simulation_parameters", &fiction::design_sidb_gates_params::simulation_parameters, - DOC(fiction_design_sidb_gates_params)) - .def_readwrite("canvas", &fiction::design_sidb_gates_params::canvas, - DOC(fiction_design_sidb_gates_params_canvas)) - .def_readwrite("number_of_sidbs", &fiction::design_sidb_gates_params::number_of_sidbs, - DOC(fiction_design_sidb_gates_params_number_of_sidbs)) - .def_readwrite("sim_engine", &fiction::design_sidb_gates_params::sim_engine, - DOC(fiction_design_sidb_gates_params_sim_engine)); - - py::class_(m, "design_sidb_gates_stats", DOC(fiction_exact_physical_design_stats)) - .def(py::init<>()); - m.def("design_sidb_gates", &fiction::design_sidb_gates, "skeleton"_a, "spec"_a, - "params"_a = fiction::design_sidb_gates_params{}, + "params"_a = fiction::design_sidb_gates_params{}, "design_mode"_a = fiction::design_sidb_gates_mode::EXHAUSTIVE, "stats"_a = nullptr, DOC(fiction_design_sidb_gates)); } @@ -54,6 +36,11 @@ void design_sidb_gates(pybind11::module& m) inline void design_sidb_gates(pybind11::module& m) { namespace py = pybind11; + /** + * Stats object + */ + py::class_(m, "design_sidb_gates_stats", DOC(fiction_exact_physical_design_stats)) + .def(py::init<>()); /** * Design approach selector type. */ @@ -63,8 +50,25 @@ inline void design_sidb_gates(pybind11::module& m) DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE)) .value("RANDOM", fiction::design_sidb_gates_mode::RANDOM, DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM)); + /** + * Parameters. + */ + py::class_>(m, "design_sidb_gates_params", + DOC(fiction_design_sidb_gates_params)) + .def(py::init<>()) + .def_readwrite("simulation_parameters", + &fiction::design_sidb_gates_params::simulation_parameters, + DOC(fiction_design_sidb_gates_params)) + .def_readwrite("canvas", &fiction::design_sidb_gates_params::canvas, + DOC(fiction_design_sidb_gates_params_canvas)) + .def_readwrite("number_of_sidbs", + &fiction::design_sidb_gates_params::number_of_sidbs, + DOC(fiction_design_sidb_gates_params_number_of_sidbs)) + .def_readwrite("sim_engine", &fiction::design_sidb_gates_params::sim_engine, + DOC(fiction_design_sidb_gates_params_sim_engine)); - detail::design_sidb_gates(m); + detail::design_sidb_gates(m); + detail::design_sidb_gates(m); } } // namespace pyfiction diff --git a/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py b/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py index 2bd0af6de..f4ece5400 100644 --- a/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py +++ b/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py @@ -4,7 +4,7 @@ class TestDesignSiDBGates(unittest.TestCase): def test_siqad_and_gate_skeleton(self): - layout = sidb_layout((20, 20)) + layout = sidb_lattice_100((20, 20)) layout.assign_cell_type((0, 1), sidb_technology.cell_type.INPUT) layout.assign_cell_type((2, 3), sidb_technology.cell_type.INPUT) diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index a000b7ed8..0a84e5a10 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -102,7 +102,7 @@ enum class design_sidb_gates_mode * @tparam Cell-level layout type. * */ -template +template struct design_sidb_gates_params { /** @@ -112,7 +112,7 @@ struct design_sidb_gates_params /** * Canvas spanned by the northwest and southeast cell. */ - std::pair, cell> canvas{}; + std::pair canvas{}; /** * Number of SiDBs placed in the canvas to create a working gate. */ @@ -157,8 +157,8 @@ class design_sidb_gates_impl * @param ps Parameters and settings for the gate designer. * @param st Statistics for the gate designer. */ - design_sidb_gates_impl(const Lyt& skeleton, const std::vector& tt, const design_sidb_gates_params& ps, - design_sidb_gates_stats& st) : + design_sidb_gates_impl(const Lyt& skeleton, const std::vector& tt, + const design_sidb_gates_params>& ps, design_sidb_gates_stats& st) : skeleton_layout{skeleton}, truth_table{tt}, params{ps}, @@ -345,7 +345,6 @@ class design_sidb_gates_impl const auto lyt_swap = move_sidb(lyt); return lyt_swap; }); - std::cout << fmt::format("final cost: {}", optimized_net_cost) << std::endl; stats.gate_cost = optimized_net_cost; return optimized_gate_design; } @@ -363,7 +362,7 @@ class design_sidb_gates_impl /** * Parameters for the *SiDB Gate Designer*. */ - const design_sidb_gates_params& params; + const design_sidb_gates_params>& params; /** * The statistics of the gate design. */ @@ -532,9 +531,10 @@ class design_sidb_gates_impl */ template [[nodiscard]] std::vector -design_sidb_gates(const Lyt& skeleton, const std::vector& spec, const design_sidb_gates_params& params = {}, - const design_sidb_gates_mode design_mode = design_sidb_gates_mode::EXHAUSTIVE, - design_sidb_gates_stats* stats = nullptr) noexcept +design_sidb_gates(const Lyt& skeleton, const std::vector& spec, + const design_sidb_gates_params>& params = {}, + const design_sidb_gates_mode design_mode = design_sidb_gates_mode::EXHAUSTIVE, + design_sidb_gates_stats* stats = nullptr) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -583,7 +583,7 @@ design_sidb_gates(const Lyt& skeleton, const std::vector& spec, const design */ template [[nodiscard]] Lyt design_sidb_gates_metric_driven_simulated_annealing( - const Lyt& skeleton, const std::vector& spec, const design_sidb_gates_params& params, + const Lyt& skeleton, const std::vector& spec, const design_sidb_gates_params>& params, const design_sidb_gates_metric_driven_simulated_annealing_params& sa_params, design_sidb_gates_stats* stats = nullptr) noexcept { diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index ecf3803cf..1c5af885b 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -167,7 +167,7 @@ class maximum_defect_influence_position_and_distance_impl }); { - std::lock_guard lock(mutex); + const std::lock_guard lock(mutex); // the distance is larger than the current maximum one. if (distance > avoidance_distance) { diff --git a/test/algorithms/physical_design/design_sidb_gates.cpp b/test/algorithms/physical_design/design_sidb_gates.cpp index 257802346..6f693f92b 100644 --- a/test/algorithms/physical_design/design_sidb_gates.cpp +++ b/test/algorithms/physical_design/design_sidb_gates.cpp @@ -52,10 +52,10 @@ TEST_CASE("Use SiQAD XNOR skeleton and generate SiQAD XNOR gate, exhaustive", "[ CHECK(lyt.num_cells() == 13); - const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, - {{10, 4, 0}, {10, 4, 0}}, - 1, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params> params{sidb_simulation_parameters{2, -0.32}, + {{10, 4, 0}, {10, 4, 0}}, + 1, + sidb_simulation_engine::QUICKEXACT}; const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_xnor_tt()}, params); @@ -64,8 +64,8 @@ TEST_CASE("Use SiQAD XNOR skeleton and generate SiQAD XNOR gate, exhaustive", "[ CHECK(found_gate_layouts[0].get_cell_type({10, 4, 0}) == siqad_layout::technology::NORMAL); // using cube coordinates - const auto lyt_in_cube_coord = convert_to_fiction_coordinates(lyt); - const design_sidb_gates_params params_cube{ + const auto lyt_in_cube_coord = convert_to_fiction_coordinates(lyt); + const design_sidb_gates_params> params_cube{ sidb_simulation_parameters{2, -0.32}, {siqad::to_fiction_coord(siqad::coord_t{10, 4, 0}), siqad::to_fiction_coord(siqad::coord_t{10, 4, 0})}, @@ -82,7 +82,7 @@ TEST_CASE("Use SiQAD XNOR skeleton and generate SiQAD XNOR gate, exhaustive", "[ // using offset coordinates const auto lyt_in_offset_coord = convert_to_fiction_coordinates(lyt); - const design_sidb_gates_params params_offset{ + const design_sidb_gates_params> params_offset{ sidb_simulation_parameters{2, -0.32}, {siqad::to_fiction_coord(siqad::coord_t{10, 4, 0}), siqad::to_fiction_coord(siqad::coord_t{10, 4, 0})}, @@ -119,10 +119,10 @@ TEST_CASE("Use SiQAD's AND gate skeleton to generate all possible AND gates", "[ lyt.assign_cell_type({10, 9, 1}, sidb_technology::cell_type::NORMAL); - design_sidb_gates_params params{sidb_simulation_parameters{2, -0.28}, - {{4, 4, 0}, {14, 5, 1}}, - 1, - sidb_simulation_engine::EXGS}; + design_sidb_gates_params> params{sidb_simulation_parameters{2, -0.28}, + {{4, 4, 0}, {14, 5, 1}}, + 1, + sidb_simulation_engine::EXGS}; SECTION("Exhaustive Generation") { @@ -174,10 +174,10 @@ TEST_CASE("Use FO2 Bestagon gate without SiDB at {17, 11, 0} and generate origin SECTION("generate original FO2") { - const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, - {{17, 11, 0}, {17, 11, 0}}, - 1, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params> params{sidb_simulation_parameters{2, -0.32}, + {{17, 11, 0}, {17, 11, 0}}, + 1, + sidb_simulation_engine::QUICKEXACT}; CHECK(lyt.get_cell_type({17, 11, 0}) == sidb_100_cell_clk_lyt_siqad::technology::EMPTY); @@ -192,11 +192,10 @@ TEST_CASE("Use FO2 Bestagon gate without SiDB at {17, 11, 0} and generate origin SECTION("replace the output perturbers by equivalent negatively charged defects") { - const design_sidb_gates_params> params{ - sidb_simulation_parameters{2, -0.32}, - {{17, 11, 0}, {17, 11, 0}}, - 1, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + {{17, 11, 0}, {17, 11, 0}}, + 1, + sidb_simulation_engine::QUICKEXACT}; sidb_defect_surface defect_layout{lyt}; defect_layout.assign_cell_type({36, 19, 0}, sidb_100_cell_clk_lyt_siqad::cell_type::EMPTY); @@ -250,10 +249,10 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") SECTION("Random Generation") { - const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, - {{14, 6, 0}, {24, 12, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + {{14, 6, 0}, {24, 12, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT}; const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_and_tt()}, params, design_sidb_gates_mode::RANDOM); @@ -265,11 +264,10 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") { sidb_defect_surface defect_layout{lyt}; - const design_sidb_gates_params> params{ - sidb_simulation_parameters{2, -0.32}, - {{14, 6, 0}, {24, 12, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + {{14, 6, 0}, {24, 12, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT}; defect_layout.assign_sidb_defect({15, 10, 0}, sidb_defect{sidb_defect_type::DB, -1, params.simulation_parameters.epsilon_r, @@ -296,11 +294,10 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") { sidb_defect_surface defect_layout{lyt}; - const design_sidb_gates_params> params{ - sidb_simulation_parameters{2, -0.32}, - {{14, 6, 0}, {24, 12, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + {{14, 6, 0}, {24, 12, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT}; defect_layout.assign_sidb_defect({15, 10, 0}, sidb_defect{sidb_defect_type::DB, -1, params.simulation_parameters.epsilon_r, @@ -373,10 +370,10 @@ TEST_CASE("Design AND Bestagon shaped gate on H-Si 111", "[design-sidb-gates]") SECTION("Random Generation") { - const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, - {{10, 11, 0}, {14, 17, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + {{10, 11, 0}, {14, 17, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT}; const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_nor_tt()}, params, design_sidb_gates_mode::RANDOM); @@ -386,10 +383,10 @@ TEST_CASE("Design AND Bestagon shaped gate on H-Si 111", "[design-sidb-gates]") SECTION("Exhaustive Generation") { - const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, - {{10, 11, 0}, {14, 17, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, + {{10, 11, 0}, {14, 17, 0}}, + 3, + sidb_simulation_engine::QUICKEXACT}; const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_nor_tt()}, params, design_sidb_gates_mode::EXHAUSTIVE); From 5871a79883b56186cdccbad74ee93b0fb59034f5 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 2 May 2024 15:47:41 +0200 Subject: [PATCH 067/221] :memo: update docu. --- .../pyfiction/include/pyfiction/layouts/sidb_lattice.hpp | 3 +++ docs/algorithms/design_sidb_gates.rst | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/bindings/pyfiction/include/pyfiction/layouts/sidb_lattice.hpp b/bindings/pyfiction/include/pyfiction/layouts/sidb_lattice.hpp index 5454e0baf..c9b690625 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/sidb_lattice.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/sidb_lattice.hpp @@ -10,11 +10,14 @@ #include #include +#include #include #include +#include #include +#include #include namespace pyfiction diff --git a/docs/algorithms/design_sidb_gates.rst b/docs/algorithms/design_sidb_gates.rst index b65c3577e..7037cf5e0 100644 --- a/docs/algorithms/design_sidb_gates.rst +++ b/docs/algorithms/design_sidb_gates.rst @@ -7,11 +7,20 @@ SiDB Gate Designer .. tab:: C++ **Header:** ``fiction/algorithms/physical_design/design_sidb_gates.hpp`` + .. doxygenstruct:: fiction::design_sidb_gates_metric_driven_simulated_annealing_params + :members: + .. doxygenstruct:: fiction::design_sidb_gates_mode + :members: .. doxygenstruct:: fiction::design_sidb_gates_params :members: + .. doxygenstruct:: fiction::design_sidb_gates_stats + :members: .. doxygenfunction:: fiction::design_sidb_gates + .. doxygenfunction:: fiction::design_sidb_gates_metric_driven_simulated_annealing .. tab:: Python + .. autoclass:: mnt.pyfiction.design_sidb_gates_mode + :members: .. autoclass:: mnt.pyfiction.design_sidb_gates_params :members: .. autofunction:: mnt.pyfiction.design_sidb_gates From 87499c4868af7bc4b397940d77a5d95336b93e8a Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 2 May 2024 15:49:05 +0200 Subject: [PATCH 068/221] :art: include missing headers. --- .../pyfiction/include/pyfiction/layouts/sidb_lattice.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/layouts/sidb_lattice.hpp b/bindings/pyfiction/include/pyfiction/layouts/sidb_lattice.hpp index c9b690625..c10ca137a 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/sidb_lattice.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/sidb_lattice.hpp @@ -8,17 +8,14 @@ #include "pyfiction/documentation.hpp" #include "pyfiction/types.hpp" -#include -#include +#include #include #include #include #include -#include #include -#include namespace pyfiction { From 9bced8ee7e23178d4e14296ea9f04cfef3ac368d Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 2 May 2024 16:06:09 +0200 Subject: [PATCH 069/221] :memo: small fix. --- docs/algorithms/design_sidb_gates.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/algorithms/design_sidb_gates.rst b/docs/algorithms/design_sidb_gates.rst index 7037cf5e0..0a792161d 100644 --- a/docs/algorithms/design_sidb_gates.rst +++ b/docs/algorithms/design_sidb_gates.rst @@ -9,7 +9,7 @@ SiDB Gate Designer .. doxygenstruct:: fiction::design_sidb_gates_metric_driven_simulated_annealing_params :members: - .. doxygenstruct:: fiction::design_sidb_gates_mode + .. doxygenenum:: fiction::design_sidb_gates_mode :members: .. doxygenstruct:: fiction::design_sidb_gates_params :members: From a54d3b73969d217921203d7ad941cce92bdaa338 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 3 May 2024 10:10:23 +0200 Subject: [PATCH 070/221] :art: small fixes. --- .../sidb/test_operational_domain.py | 8 +- .../physical_design/design_sidb_gates.hpp | 2 +- .../defect_influence_operational_domain.hpp | 95 +++++++++++-------- 3 files changed, 59 insertions(+), 46 deletions(-) diff --git a/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py b/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py index 17614233f..e86fd1d22 100644 --- a/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py +++ b/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py @@ -23,19 +23,19 @@ def test_xor_gate_100_lattice(self): params.y_step = 0.01 stats_grid = operational_domain_stats() - opdomain = operational_domain_grid_search(lyt, [create_xor_tt()], params, stats_grid) + operational_domain_grid_search(lyt, [create_xor_tt()], params, stats_grid) self.assertGreater(stats_grid.num_operational_parameter_combinations, 0) stats_flood_fill = operational_domain_stats() - opdomain = operational_domain_flood_fill(lyt, [create_xor_tt()], 100, params, None, stats_flood_fill) + operational_domain_flood_fill(lyt, [create_xor_tt()], 100, params, None, stats_flood_fill) self.assertGreater(stats_flood_fill.num_operational_parameter_combinations, 0) stats_random_sampling = operational_domain_stats() - opdomain = operational_domain_random_sampling(lyt, [create_xor_tt()], 100, params, stats_random_sampling) + operational_domain_random_sampling(lyt, [create_xor_tt()], 100, params, stats_random_sampling) self.assertGreater(stats_random_sampling.num_operational_parameter_combinations, 0) stats_contour_tracing = operational_domain_stats() - opdomain = operational_domain_contour_tracing(lyt, [create_xor_tt()], 100, params, None, stats_contour_tracing) + operational_domain_contour_tracing(lyt, [create_xor_tt()], 100, params, None, stats_contour_tracing) self.assertGreater(stats_contour_tracing.num_operational_parameter_combinations, 0) def test_and_gate_111_lattice(self): diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 0a84e5a10..18762d23a 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -502,7 +502,7 @@ class design_sidb_gates_impl /** * The *SiDB Gate Designer* designs SiDB gate implementations based on a specified Boolean function, a * skeleton layout (can hold defects), canvas size, and a predetermined number of canvas SiDBs. Two different design - * modes are implemented: `exhaustive` and `random design`. + * modes are implemented: `exhaustive` and `random`. * * The `exhaustive design` is composed of three steps: * 1. In the initial step, all possible distributions of `number_of_sidbs` SiDBs within a given canvas are diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 6708ee122..4b982cd1d 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -46,9 +46,9 @@ struct defect_influence_operational_domain_params * information indicating whether the SiDB layout remains logically operational. Logically operational implies that the * layout's ground state aligns with a designated Boolean function at the layout's outputs for all feasible input * combinations. This implementation assumes the presence of \f$ n \f$ BDL input wires and a single BDL output wire for - * a given layout. Any algorithm for computing the operational domain iterates through all \f$ 2^n \f$ input - * combinations, evaluating the layout's output behavior based on the specified Boolean function. The layout is - * classified as operational for a particular parameter combination only if its output behavior is correct across all + * a given layout. Any algorithm for computing the defect influence operational domain iterates through all \f$ 2^n \f$ + * input combinations, evaluating the layout's output behavior based on the specified Boolean function. The layout is + * classified as operational for a particular defect position only if its output behavior is correct across all * input combinations. */ template @@ -105,10 +105,12 @@ class defect_influence_operational_domain_impl mockturtle::stopwatch stop{stats.time_total}; const auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); + // Iterate through all possible defect positions, but make sure that the position is distributed on a grid + // defined by `step_size'. for (std::size_t i = 0; i < all_possible_defect_positions.size(); i += step_size) { - if (std::abs(all_possible_defect_positions[i].x) % step_size == 0 && - std::abs(all_possible_defect_positions[i].y) % step_size == 0) + if (static_cast(std::abs(all_possible_defect_positions[i].x)) % step_size == 0 && + static_cast(std::abs(all_possible_defect_positions[i].y)) % step_size == 0) { is_defect_position_operational(all_possible_defect_positions[i]); } @@ -119,7 +121,7 @@ class defect_influence_operational_domain_impl return defect_operational_domain; } - [[nodiscard]] defect_influence_operational_domain random_sampling(std::size_t samples) noexcept + [[nodiscard]] defect_influence_operational_domain random_sampling(const std::size_t samples) noexcept { mockturtle::stopwatch stop{stats.time_total}; auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); @@ -142,7 +144,7 @@ class defect_influence_operational_domain_impl return defect_operational_domain; } - [[nodiscard]] defect_influence_operational_domain contour_tracing(std::size_t samples) noexcept + [[nodiscard]] defect_influence_operational_domain contour_tracing(const std::size_t samples) noexcept { mockturtle::stopwatch stop{stats.time_total}; @@ -163,23 +165,26 @@ class defect_influence_operational_domain_impl std::size_t number_of_random_start_positions = 0; while (number_of_random_start_positions < samples) { - // first, perform random sampling to find an operational starting point - const auto non_operational_starting_point = find_operational_defect_position_at_the_top_left(); + const auto operational_starting_point = find_operational_defect_position_at_left_side(); // if no operational point was found within the specified number of samples, return - if (!non_operational_starting_point.has_value()) + if (!operational_starting_point.has_value()) { return defect_operational_domain; } - assert(layout.num_defects() == 0 && "defect is added defect"); + // the layout hs to be defect-free. + assert(layout.num_defects() == 0 && "An atomic defect is added"); + + number_of_random_start_positions++; // find an operational point on the contour starting from the randomly determined starting point const auto contour_starting_point = - find_last_operational_defect_position_moving_right(*non_operational_starting_point); + find_last_operational_defect_position_moving_right(*operational_starting_point); - assert(layout.num_defects() == 0 && "more than one defect"); + // the layout hs to be defect-free. + assert(layout.num_defects() == 0 && "An atomic defect is added"); auto current_contour_point = contour_starting_point; auto backtrack_point = current_contour_point.x == nw_cell.x ? @@ -191,13 +196,14 @@ class defect_influence_operational_domain_impl current_neighborhood.front() : next_clockwise_point(current_neighborhood, backtrack_point); - bool contour_around_gate = false; + bool contour_goes_around_layout = false; while (next_point != contour_starting_point) { const auto operational_status = is_defect_position_operational(next_point); + // check if the contour goes around the layout. if (next_point.x >= se_bb_layout.x) { - contour_around_gate = true; + contour_goes_around_layout = true; } assert(layout.num_defects() == 0 && "more than one defect"); @@ -216,16 +222,12 @@ class defect_influence_operational_domain_impl next_point = next_clockwise_point(current_neighborhood, backtrack_point); } number_of_random_start_positions++; - if (!contour_around_gate) + if (!contour_goes_around_layout) { continue; } - else - { - log_stats(); - - return defect_operational_domain; - } + log_stats(); + return defect_operational_domain; } log_stats(); @@ -261,9 +263,9 @@ class defect_influence_operational_domain_impl } /** * This function aims to identify an operational defect position within the layout. It does so by selecting a defect - * position with the leftmost x-coordinate and a y-coordinate aligned with the layout's bounding box. + * position with the leftmost x-coordinate and a randomly selected y-coordinate limited the layout's bounding box. */ - [[nodiscard]] std::optional find_operational_defect_position_at_the_top_left() noexcept + [[nodiscard]] std::optional find_operational_defect_position_at_left_side() noexcept { auto starting_point = nw_cell; std::random_device rd; @@ -357,7 +359,7 @@ class defect_influence_operational_domain_impl * * @param starting_defect_position The starting position of the defect, from which the traversal towards the right * is conducted while maintaining gate operability. - * @return The most recent operational defect position. + * @return The last operational defect position. */ [[nodiscard]] typename Lyt::cell find_last_operational_defect_position_moving_right(const typename Lyt::cell& starting_defect_position) noexcept @@ -367,7 +369,7 @@ class defect_influence_operational_domain_impl previous_defect_position = starting_defect_position; // move towards the left border of the parameter range - for (int64_t x = starting_defect_position.x; x <= se_bb_layout.x; x++) + for (auto x = starting_defect_position.x; x <= se_bb_layout.x; x++) { previous_defect_position = current_defect_position; current_defect_position = {x, starting_defect_position.y}; @@ -390,7 +392,6 @@ class defect_influence_operational_domain_impl return latest_operational_defect_position; } - /** * Helper function that writes the the statistics of the defect operational domain computation to the statistics * object. @@ -412,7 +413,6 @@ class defect_influence_operational_domain_impl } } } - /** * Computes the Moore neighborhood of a given cell within the SiDB layout. * The Moore neighborhood consists of the eight cells surrounding the central cell @@ -560,10 +560,9 @@ class defect_influence_operational_domain_impl } // namespace detail /** - * Computes the defect influence operational domain of the given SiDB cell-level layout. The defect influence + * Computes the defect influence operational domain of the given SiDB layout. The defect influence * operational domain is the set of all defect positions for which the layout is logically operational. Logical - * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed - * to be in the same order as the inputs of the truth table. + * operation is defined as the layout implementing the given truth table. * * This algorithm uses a grid search to determine the defect influence operational domain. The grid search is performed * by exhaustively sweeping all possible atomic defect positions in x and y dimensions. @@ -572,15 +571,17 @@ class defect_influence_operational_domain_impl * @tparam TT Truth table type. * @param lyt Layout to compute the defect influence operational domain for. * @param spec Expected Boolean function of the layout given as a multi-output truth table. + * @param step_size The parameter specifying the interval between consecutive defect positions to be evaluated. * @param params Defect influence operational domain computation parameters. - * @param stats Operational domain computation statistics. + * @param stats Statistics. * @return The defect influence operational domain of the layout. */ template defect_influence_operational_domain -defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vector& spec, std::size_t step_size = 1, - const defect_influence_operational_domain_params& params = {}, - defect_influence_operational_domain_stats* stats = nullptr) +defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vector& spec, + const std::size_t step_size = 1, + const defect_influence_operational_domain_params& params = {}, + defect_influence_operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -600,21 +601,21 @@ defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vecto return result; } /** - * Computes the defect influence operational domain of the given SiDB cell-level layout. The defect influence + * Computes the `defect influence operational domain` of the given SiDB cell-level layout. The defect influence * operational domain is the set of all defect positions for which the layout is logically operational. Logical * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed * to be in the same order as the inputs of the truth table. * * This algorithm uses random sampling to find a part of the defect influence operational domain that might not be - * complete. It performs a total of `samples` uniformly-distributed random samples within the a specified area. + * complete. It performs a total of `samples` uniformly-distributed random samples within the specified area. * * @tparam Lyt SiDB cell-level layout type. * @tparam TT Truth table type. * @param lyt Layout to compute the defect influence operational domain for. * @param spec Expected Boolean function of the layout given as a multi-output truth table. - * @param samples Number of samples to perform. + * @param samples Number of random samples to perform. * @param params Defect influence operational domain computation parameters. - * @param stats Operational domain computation statistics. + * @param stats Statistics. * @return The (partial) defect influence operational domain of the layout. */ template @@ -647,7 +648,18 @@ defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::v * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed * to be in the same order as the inputs of the truth table. * - * // TODO + * This algorithm uses contour tracing to identify operational defect locations within the SiDB gate layout. + * It starts by searching for defect locations on the left side of the bounding box, with an additional distance + * of the SiDB gate where the SiDB gate remains operational. The y-coordinate for these positions is chosen + * randomly. The number of samples is determined by the `samples` parameter. + * + * Then the algorithm moves each defect position to the right, searching for the last operational defect position. This + * position is selected as the starting point for the contour trace. The contour tracing process checks whether the + * contour includes the SiDB layout. If it does not, the next random sample point is is selected as the starting point + * and the process is repeated. + * + * @Note This algorithm is an approximation to determine the defect influence operational domain. Therefore, it + * is recommended to analyze the result afterwards to assess whether the contour reflects the desired contour. * * @tparam Lyt SiDB cell-level layout type. * @tparam TT Truth table type. @@ -660,7 +672,8 @@ defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::v */ template defect_influence_operational_domain -defect_influence_operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, std::size_t samples, +defect_influence_operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, + const std::size_t samples, const defect_influence_operational_domain_params& params = {}, defect_influence_operational_domain_stats* stats = nullptr) { From 5a48af63faafb5e742fd4fd46413be3c147e8474 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 3 May 2024 10:36:07 +0200 Subject: [PATCH 071/221] :art: Rename function to better represent functionality. --- docs/algorithms/sidb_simulation.rst | 4 ++-- .../physical_design/design_sidb_gates.hpp | 6 +++--- ...harge_change_for_all_input_combinations.hpp | 7 +++++-- ...tance.hpp => defect_avoidance_distance.hpp} | 18 ++++++++---------- .../defect_influence_operational_domain.cpp | 8 ++++---- 5 files changed, 22 insertions(+), 21 deletions(-) rename include/fiction/algorithms/simulation/sidb/{maximum_minimum_defect_influence_distance.hpp => defect_avoidance_distance.hpp} (62%) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index e77d9e40a..c7fd0734d 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -407,6 +407,6 @@ Convert Potential to Distance Maximum Minimum Defect Influence Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -**Header:** ``fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp`` +**Header:** ``fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp`` -.. doxygenfunction:: fiction::maximum_minimum_defect_influence_distance +.. doxygenfunction:: fiction::defect_avoidance_distance diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 18762d23a..98a2f4527 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -99,7 +98,7 @@ enum class design_sidb_gates_mode /** * This struct contains parameters and settings to design SiDB gates. * - * @tparam Cell-level layout type. + * @tparam CellType Cell type. * */ template @@ -267,7 +266,6 @@ class design_sidb_gates_impl const std::lock_guard lock{mutex_to_protect_designed_gate_layouts}; randomly_designed_gate_layouts.push_back(result_lyt); num_solutions_found++; - // break; // Break out of the loop after finding a solution } } }); @@ -574,6 +572,8 @@ design_sidb_gates(const Lyt& skeleton, const std::vector& spec, * truth tables, and specified parameters for gate design and simulated annealing. Currently, only the critical * temperature and the operational domain are incorporated into the cost function. * + * @tparam Lyt SiDB cell-level layout type. + * @tparam TT The type of the truth table specifying the gate behavior. * @param skeleton The layout skeleton used as the basis for gate design. * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param params The parameters for gate design. diff --git a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp index 71a1e9f1f..ce1009990 100644 --- a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp +++ b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp @@ -24,10 +24,13 @@ namespace fiction struct calculate_min_potential_for_charge_change_for_all_input_combinations_params { /** - * TODO + * Parameters for the `assessing physical population stability` simulation */ assess_physical_population_stability_params assess_population_stability_params{}; - detect_bdl_pairs_params detect_pair_params{}; + /** + * Parameters to identify the output pairs used to read the output. + */ + detect_bdl_pairs_params detect_pair_params{}; }; /** * Calculates the minimum potential required to induce charge changes in an SiDB layout for all input combinations. diff --git a/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp similarity index 62% rename from include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp rename to include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp index 3e2e65602..42afade43 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_minimum_defect_influence_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp @@ -2,8 +2,8 @@ // Created by Jan Drewniok on 07.02.24. // -#ifndef FICTION_MAXIMUM_MINIMUM_DEFECT_INFLUENCE_DISTANCE_HPP -#define FICTION_MAXIMUM_MINIMUM_DEFECT_INFLUENCE_DISTANCE_HPP +#ifndef FICTION_DEFECT_AVOIDANCE_DISTANCE_HPP +#define FICTION_DEFECT_AVOIDANCE_DISTANCE_HPP #include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" @@ -13,10 +13,9 @@ namespace fiction { /** - * Calculates the maximum minimum influence distance of a given gate layout by a specified atomic defect. - * This function requires both the defect operational domain and the layout as input. For each non-operational - * defect position, it computes the minimum distance to the layout. The maximum value among these minimal distances - * is then returned. + * Calculates the defect avoidance distance of a given gate layout by a given atomic defect. This means that a defect + * must be further away than this distance for the SiDB gate to be operational. This function requires both the defect + * operational domain and the layout as input. * * @tparam Lyt Type representing the SiDB cell-level layout. * @param lyt The cell-level layout for which the defect operational domain was computed. @@ -24,9 +23,8 @@ namespace fiction * @return The maximum minimum defect influence distance. */ template -[[nodiscard]] double -maximum_minimum_defect_influence_distance(const Lyt& lyt, - const defect_influence_operational_domain& defect_opdomain) noexcept +[[nodiscard]] double defect_avoidance_distance(const Lyt& lyt, + const defect_influence_operational_domain& defect_opdomain) noexcept { double max_distance = 0; for (const auto& val : defect_opdomain.operational_values) @@ -54,4 +52,4 @@ maximum_minimum_defect_influence_distance(const Lyt& } // namespace fiction -#endif // FICTION_MAXIMUM_MINIMUM_DEFECT_INFLUENCE_DISTANCE_HPP +#endif // FICTION_DEFECT_AVOIDANCE_DISTANCE_HPP diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 909d9f751..41ea48038 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -5,10 +5,10 @@ #include #include +#include #include #include #include -#include #include #include #include @@ -75,7 +75,7 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_grid_search( cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); - CHECK_THAT(maximum_minimum_defect_influence_distance(cube_lyt, defect_influence_domain), + CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain), Catch::Matchers::WithinAbs(11.6138152646, physical_constants::POP_STABILITY_ERR)); } SECTION("Random Sampling") @@ -85,7 +85,7 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again const auto defect_influence_domain = defect_influence_operational_domain_random_sampling( cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); - CHECK(maximum_minimum_defect_influence_distance(cube_lyt, defect_influence_domain) < 11.61); + CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain) < 11.61); } SECTION("Contour Tracing") { @@ -93,6 +93,6 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_contour_tracing( cube_lyt, std::vector{create_or_tt()}, 10, params, &stats); - CHECK(maximum_minimum_defect_influence_distance(cube_lyt, defect_influence_domain) > 11.61); + CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain) > 11.61); } } From 47dfa968c9572baaa3eb268d01dae99f63d64e46 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 3 May 2024 12:11:40 +0200 Subject: [PATCH 072/221] :art: small fixes. --- ...for_charge_change_for_all_input_combinations.hpp | 3 ++- .../sidb/defect_influence_operational_domain.hpp | 2 +- ...ximum_defect_influence_position_and_distance.hpp | 1 - ...influence_position_and_distance_of_sidb_gate.hpp | 4 ++-- .../physical_design/design_sidb_gates.cpp | 13 ++++++------- test/utils/blueprints/layout_blueprints.hpp | 10 ++++++++-- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp index ce1009990..a9c560bc4 100644 --- a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp +++ b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp @@ -40,7 +40,8 @@ struct calculate_min_potential_for_charge_change_for_all_input_combinations_para * @param lyt The SiDB layout object. * @param spec Expected Boolean function of the layout, provided as a multi-output truth table. * @param params Parameters for assessing physical population stability. - * @param charge_state_change Optional parameter indicating the direction of charge state change (default is 1). + * @param charge_state_change Optional parameter indicating the direction of the considered charge state change (default + * is 1). * @return The minimum potential required for charge change across all input combinations. */ template diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 4b982cd1d..9e4581e36 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -503,7 +503,6 @@ class defect_influence_operational_domain_impl return neighbors; }; - /** * The SiDB cell-level layout to investigate. */ @@ -557,6 +556,7 @@ class defect_influence_operational_domain_impl */ std::atomic num_evaluated_defect_positions{0}; }; + } // namespace detail /** diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 1c5af885b..5813c4bb6 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -28,7 +28,6 @@ namespace fiction { - /** * This struct stores the parameters for the maximum_defect_influence_position_and_distance algorithm. */ diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index fb99d068a..62b004211 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -37,8 +37,8 @@ struct maximum_defect_influence_position_and_distance_of_sidb_gate_params * of an SiDB gate layout. It iterates over all input combinations and finds the defect position at maximum position * that affects the gate's ground state. * - * @Note The defect influence distance describes the distance at which an defect influences the ground state. It does - * check when the successful operation starts to fail, since a change in the ground state can still lead to an + * @Note The `defect influence distance` describes the distance at which an defect influences the ground state. It does + * not check when the successful operation starts to fail, since a change in the ground state can still lead to an * operational gate. * * @tparam Lyt Lyt SiDB cell-level layout type. diff --git a/test/algorithms/physical_design/design_sidb_gates.cpp b/test/algorithms/physical_design/design_sidb_gates.cpp index 6f693f92b..d75364ea3 100644 --- a/test/algorithms/physical_design/design_sidb_gates.cpp +++ b/test/algorithms/physical_design/design_sidb_gates.cpp @@ -2,17 +2,16 @@ // Created by Jan Drewniok on 12.09.23. // -#include +#include #include #include +#include #include #include #include #include -#include #include -#include #include #include #include @@ -119,10 +118,10 @@ TEST_CASE("Use SiQAD's AND gate skeleton to generate all possible AND gates", "[ lyt.assign_cell_type({10, 9, 1}, sidb_technology::cell_type::NORMAL); - design_sidb_gates_params> params{sidb_simulation_parameters{2, -0.28}, - {{4, 4, 0}, {14, 5, 1}}, - 1, - sidb_simulation_engine::EXGS}; + const design_sidb_gates_params> params{sidb_simulation_parameters{2, -0.28}, + {{4, 4, 0}, {14, 5, 1}}, + 1, + sidb_simulation_engine::EXGS}; SECTION("Exhaustive Generation") { diff --git a/test/utils/blueprints/layout_blueprints.hpp b/test/utils/blueprints/layout_blueprints.hpp index d0c8883ed..f25221344 100644 --- a/test/utils/blueprints/layout_blueprints.hpp +++ b/test/utils/blueprints/layout_blueprints.hpp @@ -717,6 +717,8 @@ Lyt siqad_and_gate() noexcept * Samuel Sze Hang Ng, Jan Drewniok, Marcel Walter, Jacob Retallick, Robert Wille, and Konrad Walus. * * (https://github.com/samuelngsh/si-111-paper-supplementary/blob/main/bestagon-111-gates/gates/AND_mu_032_0.sqd) + * + * @tparam Lyt SiDB cell-level layout type based on SiQAD-coordinates. */ template Lyt and_gate_111() noexcept @@ -766,13 +768,15 @@ Lyt and_gate_111() noexcept * Marcel Walter, Samuel Sze Hang Ng, Konrad Walus, and Robert Wille. * * (https://github.com/cda-tum/mnt-bestagon-library/blob/main/bestagon-gates/2i1o_and/21_hex_inputsdbp_and_v19.sqd) + * + * @tparam Lyt SiDB cell-level layout type based on SiQAD-coordinates. */ template Lyt bestagon_and_gate() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); - static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not based on SiQAD-coordinates"); Lyt lyt{}; @@ -813,13 +817,15 @@ Lyt bestagon_and_gate() noexcept * Marcel Walter, Samuel Sze Hang Ng, Konrad Walus, and Robert Wille. * * (https://github.com/cda-tum/mnt-bestagon-library/blob/main/bestagon-gates/2i2o_cx/22_hex_inputsdbp_cx_try2_v0.sqd) + * + * @tparam Lyt SiDB cell-level layout type based on SiQAD-coordinates. */ template Lyt bestagon_crossing_gate() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); - static_assert(fiction::is_sidb_lattice_100_v, "Lyt should have 111 as lattice orientation"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not based on SiQAD-coordinates"); Lyt lyt{}; From fa75945ab9d84db1e86cb03e23521e1e579dc5ba Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 6 May 2024 11:01:06 +0200 Subject: [PATCH 073/221] :art: small fixes. --- .../assess_physical_population_stability.hpp | 3 - .../physical_design/design_sidb_gates.hpp | 4 +- .../assess_physical_population_stability.hpp | 95 +++++++++---------- ...arge_change_for_all_input_combinations.hpp | 11 ++- include/fiction/utils/math_utils.hpp | 3 +- .../assess_physical_population_stability.cpp | 55 +++++++---- 6 files changed, 92 insertions(+), 79 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index f74573ea2..fa4841ba2 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -34,9 +34,6 @@ void assess_physical_population_stability(pybind11::module& m, const std::string .def_readwrite("transition_from_to_with_cell_and_required_pot", &fiction::population_stability_information::transition_from_to_with_cell_and_required_pot, DOC(fiction_population_stability_information_transition_from_to)) - .def_readwrite("minimum_potential_difference_to_transition", - &fiction::population_stability_information::minimum_potential_difference_to_transition, - DOC(fiction_population_stability_information_minimum_potential_difference_to_transition)) .def_readwrite("distance_corresponding_to_potential", &fiction::population_stability_information::distance_corresponding_to_potential, DOC(fiction_population_stability_information_distance_corresponding_to_potential)) diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 98a2f4527..af1839168 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -58,11 +58,11 @@ struct design_sidb_gates_metric_driven_simulated_annealing_params */ std::size_t number_of_cycles{10}; /** - * Parameters for simulating the critical temperature. + * Parameters for simulating the Critical Temperature. */ critical_temperature_params ct_params{}; /** - * Parameters for simulating the operational domain. + * Parameters for simulating the Operational Domain. */ operational_domain_params op_params{}; /** diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 736b23c27..a52d8268d 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -67,16 +67,15 @@ struct population_stability_information */ typename Lyt::cell critical_cell{}; /** - * Charge transition from the current charge state to the closest one. + * This map collects all charge transition types, the corresponding critical cells and the required + * electrostatic potential required to conduct the transition. */ std::unordered_map> transition_from_to_with_cell_and_required_pot{}; /** - * Absolute electrostatic potential (unit: V) required for the charge state transition. - */ - std::unordered_map minimum_potential_difference_to_transition{}; - /** - * Distance (unit: nm) corresponding to the minimum potential difference. + * This map collects for all charge transition types, the electrostatic potential difference which is + * required to conduct a charge change as a distance in nanometer. This is possible since the electrostatic + * potential is connected to the distance. */ std::unordered_map distance_corresponding_to_potential{}; /** @@ -158,14 +157,14 @@ class assess_physical_population_stability_impl population_stability_information population_stability_info{}; - population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_NEGATIVE] = - std::numeric_limits::infinity(); - population_stability_info.minimum_potential_difference_to_transition[transition_type::NEGATIVE_TO_NEUTRAL] = - std::numeric_limits::infinity(); - population_stability_info.minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = - std::numeric_limits::infinity(); - population_stability_info.minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = - std::numeric_limits::infinity(); + population_stability_info.transition_from_to_with_cell_and_required_pot.insert( + {transition_type::NEUTRAL_TO_NEGATIVE, {cell{}, std::numeric_limits::infinity()}}); + population_stability_info.transition_from_to_with_cell_and_required_pot.insert( + {transition_type::NEGATIVE_TO_NEUTRAL, {cell{}, std::numeric_limits::infinity()}}); + population_stability_info.transition_from_to_with_cell_and_required_pot.insert( + {transition_type::NEUTRAL_TO_POSITIVE, {cell{}, std::numeric_limits::infinity()}}); + population_stability_info.transition_from_to_with_cell_and_required_pot.insert( + {transition_type::POSITIVE_TO_NEUTRAL, {cell{}, std::numeric_limits::infinity()}}); charge_lyt.foreach_cell( [this, &charge_lyt, &population_stability_info](const auto& c) @@ -258,18 +257,17 @@ class assess_physical_population_stability_impl { auto updated_pop_stability_information = pop_stability_information; - if (std::abs(-local_potential + params.simulation_parameters.mu_minus) < - updated_pop_stability_information.minimum_potential_difference_to_transition.at( - transition_type::NEGATIVE_TO_NEUTRAL)) + const auto required_potential_to_conduct_transition_negative_to_neutral = + std::abs(-local_potential + params.simulation_parameters.mu_minus); + + if (required_potential_to_conduct_transition_negative_to_neutral < + updated_pop_stability_information.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEGATIVE_TO_NEUTRAL) + .second) { - updated_pop_stability_information.minimum_potential_difference_to_transition.at( - transition_type::NEGATIVE_TO_NEUTRAL) = - std::abs(-local_potential + params.simulation_parameters.mu_minus); - updated_pop_stability_information.critical_cell = c; updated_pop_stability_information .transition_from_to_with_cell_and_required_pot[transition_type::NEGATIVE_TO_NEUTRAL] = { - c, updated_pop_stability_information.minimum_potential_difference_to_transition.at( - transition_type::NEGATIVE_TO_NEUTRAL)}; + c, required_potential_to_conduct_transition_negative_to_neutral}; } return updated_pop_stability_information; @@ -291,37 +289,34 @@ class assess_physical_population_stability_impl const population_stability_information& pop_stability_information) noexcept { auto updated_pop_stability_information = pop_stability_information; - if (std::abs(-local_potential + params.simulation_parameters.mu_minus) < + + const auto required_potential_to_conduct_transition_neutral_to_negative = + std::abs(-local_potential + params.simulation_parameters.mu_minus); + if (required_potential_to_conduct_transition_neutral_to_negative < std::abs(-local_potential + params.simulation_parameters.mu_plus())) { if (std::abs(-local_potential + params.simulation_parameters.mu_minus) < - updated_pop_stability_information.minimum_potential_difference_to_transition.at( - transition_type::NEUTRAL_TO_NEGATIVE)) + updated_pop_stability_information.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEUTRAL_TO_NEGATIVE) + .second) { - updated_pop_stability_information.minimum_potential_difference_to_transition.at( - transition_type::NEUTRAL_TO_NEGATIVE) = - std::abs(-local_potential + params.simulation_parameters.mu_minus); - updated_pop_stability_information.critical_cell = c; updated_pop_stability_information .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_NEGATIVE] = { - c, updated_pop_stability_information.minimum_potential_difference_to_transition.at( - transition_type::NEUTRAL_TO_NEGATIVE)}; + c, required_potential_to_conduct_transition_neutral_to_negative}; } } else { + const auto required_potential_to_conduct_transition_neutral_to_positive = + -local_potential + params.simulation_parameters.mu_plus(); if (std::abs(-local_potential + params.simulation_parameters.mu_plus()) < - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]) + updated_pop_stability_information.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEUTRAL_TO_POSITIVE) + .second) { - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE] = - std::abs(-local_potential + params.simulation_parameters.mu_plus()); - updated_pop_stability_information.critical_cell = c; updated_pop_stability_information .transition_from_to_with_cell_and_required_pot[transition_type::NEUTRAL_TO_POSITIVE] = { - c, updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::NEUTRAL_TO_POSITIVE]}; + c, required_potential_to_conduct_transition_neutral_to_positive}; } } @@ -344,18 +339,16 @@ class assess_physical_population_stability_impl const population_stability_information& pop_stability_information) noexcept { auto updated_pop_stability_information = pop_stability_information; + + const auto required_potential_to_conduct_transition_from_positive_to_neutral = + std::abs(-local_potential + params.simulation_parameters.mu_plus()); + if (std::abs(-local_potential + params.simulation_parameters.mu_plus()) < - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL]) + required_potential_to_conduct_transition_from_positive_to_neutral) { - updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL] = - std::abs(-local_potential + params.simulation_parameters.mu_plus()); - updated_pop_stability_information.critical_cell = c; updated_pop_stability_information .transition_from_to_with_cell_and_required_pot[transition_type::POSITIVE_TO_NEUTRAL] = { - c, updated_pop_stability_information - .minimum_potential_difference_to_transition[transition_type::POSITIVE_TO_NEUTRAL]}; + c, required_potential_to_conduct_transition_from_positive_to_neutral}; } return updated_pop_stability_information; @@ -378,8 +371,10 @@ class assess_physical_population_stability_impl std::transform( sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), - std::back_inserter(energy_charge_index), [](const auto& ch_lyt) - { return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; }); + std::back_inserter(energy_charge_index), + [](const auto& ch_lyt) { + return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; + }); // Sort the vector in ascending order of the energy value std::sort(energy_charge_index.begin(), energy_charge_index.end(), diff --git a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp index a9c560bc4..3d0407c88 100644 --- a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp +++ b/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp @@ -81,24 +81,27 @@ template assess_physical_population_stability(lyt, params.assess_population_stability_params); if (!pop_stability.empty()) { - const auto stability_for_given_input = pop_stability.front().minimum_potential_difference_to_transition; + const auto ground_state_stability_for_given_input = pop_stability.front(); if (charge_state_change.has_value()) { if (charge_state_change.value() == 1) { const auto potential_negative_to_neutral = - stability_for_given_input.at(transition_type::NEGATIVE_TO_NEUTRAL); + ground_state_stability_for_given_input.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEGATIVE_TO_NEUTRAL) + .second; if (potential_negative_to_neutral < minimal_pop_stability_for_all_inputs) { minimal_pop_stability_for_all_inputs = potential_negative_to_neutral; } } - if (charge_state_change.value() == -1) { const auto potential_neutral_to_negative = - stability_for_given_input.at(transition_type::NEUTRAL_TO_NEGATIVE); + ground_state_stability_for_given_input.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEUTRAL_TO_NEGATIVE) + .second; if (potential_neutral_to_negative < minimal_pop_stability_for_all_inputs) { minimal_pop_stability_for_all_inputs = potential_neutral_to_negative; diff --git a/include/fiction/utils/math_utils.hpp b/include/fiction/utils/math_utils.hpp index 947c7e0a2..b9eff7080 100644 --- a/include/fiction/utils/math_utils.hpp +++ b/include/fiction/utils/math_utils.hpp @@ -120,7 +120,8 @@ determine_all_combinations_of_distributing_k_entities_on_n_positions(const std:: } /** - * Calculates the cost function \f$ \chi \f$ by summing the product of chi values and weights. + * Calculates the cost function \f$ \chi = \sum_{i=1} w_{i} \cdot \chi_{i} \f$ by summing the product of normalized chi + * values \f$ \chi_{i} \f$ and weights \f$ w_{i} \f$. * * @param chis The vector containing the chi values. * @param weights The vector containing the weights. diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp index 57294e518..aabfba806 100644 --- a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp +++ b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp @@ -14,6 +14,8 @@ #include #include +#include + using namespace fiction; using layout = sidb_100_cell_clk_lyt_siqad; @@ -30,13 +32,19 @@ TEST_CASE("Single SiDB", "[assess-physical-population-stability]") REQUIRE(result.size() == 1); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{1, 1, 0}); - REQUIRE(population_stability_detail.transition_from_to_with_cell_and_required_pot.size() == 1); + REQUIRE(population_stability_detail.transition_from_to_with_cell_and_required_pot.size() == 4); CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot .at(transition_type::NEGATIVE_TO_NEUTRAL) .first == siqad::coord_t{1, 1, 0}); CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot .at(transition_type::NEGATIVE_TO_NEUTRAL) .second == 0.29); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEUTRAL_TO_POSITIVE) + .second == std::numeric_limits::infinity()); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::POSITIVE_TO_NEUTRAL) + .second == std::numeric_limits::infinity()); REQUIRE_THAT( population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEGATIVE_TO_NEUTRAL), @@ -82,10 +90,12 @@ TEST_CASE("Three SiDBs with positive charge states", "[assess-physical-populatio CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot .at(transition_type::NEGATIVE_TO_NEUTRAL) .first == siqad::coord_t{2, 1, 0}); - CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( - transition_type::NEGATIVE_TO_NEUTRAL) < 0.43); - CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( - transition_type::POSITIVE_TO_NEUTRAL) < 0.81); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEGATIVE_TO_NEUTRAL) + .second < 0.43); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::POSITIVE_TO_NEUTRAL) + .second < 0.81); REQUIRE_THAT( population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEGATIVE_TO_NEUTRAL), Catch::Matchers::WithinAbs(0.56, 1e-5)); @@ -164,8 +174,9 @@ TEST_CASE("Bestagon AND gate", "[assess-physical-population-stability]") REQUIRE(result.size() == 2); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 5, 0}); - CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( - transition_type::NEUTRAL_TO_NEGATIVE) < 0.026); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEUTRAL_TO_NEGATIVE) + .second < 0.026); REQUIRE_THAT( population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), Catch::Matchers::WithinAbs(4.32, 1e-5)); @@ -180,8 +191,9 @@ TEST_CASE("Bestagon AND gate", "[assess-physical-population-stability]") REQUIRE(result.size() == 4); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{32, 18, 0}); - CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( - transition_type::NEUTRAL_TO_NEGATIVE) < 0.041); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEUTRAL_TO_NEGATIVE) + .second < 0.041); REQUIRE_THAT( population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), Catch::Matchers::WithinAbs(3.3, 1e-5)); @@ -196,8 +208,9 @@ TEST_CASE("Bestagon AND gate", "[assess-physical-population-stability]") REQUIRE(result.size() == 8); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{19, 8, 0}); - CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( - transition_type::NEUTRAL_TO_NEGATIVE) < 0.02); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEUTRAL_TO_NEGATIVE) + .second < 0.02); REQUIRE_THAT( population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), Catch::Matchers::WithinAbs(4.87, 1e-5)); @@ -212,8 +225,9 @@ TEST_CASE("Bestagon AND gate", "[assess-physical-population-stability]") REQUIRE(result.size() == 2); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 5, 0}); - CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( - transition_type::NEUTRAL_TO_NEGATIVE) < 0.026); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEUTRAL_TO_NEGATIVE) + .second < 0.026); REQUIRE_THAT( population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), Catch::Matchers::WithinAbs(4.32, 1e-5)); @@ -234,8 +248,9 @@ TEST_CASE("Bestagon CROSSING gate input 11, using siqad coordinates", "[assess-p REQUIRE(result.size() == 20); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == siqad::coord_t{14, 9, 0}); - CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( - transition_type::NEUTRAL_TO_NEGATIVE) < 0.01); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEUTRAL_TO_NEGATIVE) + .second < 0.01); REQUIRE_THAT( population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), Catch::Matchers::WithinAbs(6.88, 1e-5)); @@ -257,8 +272,9 @@ TEST_CASE("Bestagon CROSSING gate input 11, using cube coordinates", "[assess-ph REQUIRE(result.size() == 20); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == cube::coord_t{14, 18, 0}); - CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( - transition_type::NEUTRAL_TO_NEGATIVE) < 0.01); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEUTRAL_TO_NEGATIVE) + .second < 0.01); REQUIRE_THAT( population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), Catch::Matchers::WithinAbs(6.88, 1e-5)); @@ -280,8 +296,9 @@ TEST_CASE("Bestagon CROSSING gate input 11, using offset coordinates", "[assess- REQUIRE(result.size() == 20); const auto& population_stability_detail = result[0]; CHECK(population_stability_detail.critical_cell == offset::ucoord_t{14, 18, 0}); - CHECK(population_stability_detail.minimum_potential_difference_to_transition.at( - transition_type::NEUTRAL_TO_NEGATIVE) < 0.01); + CHECK(population_stability_detail.transition_from_to_with_cell_and_required_pot + .at(transition_type::NEUTRAL_TO_NEGATIVE) + .second < 0.01); REQUIRE_THAT( population_stability_detail.distance_corresponding_to_potential.at(transition_type::NEUTRAL_TO_NEGATIVE), Catch::Matchers::WithinAbs(6.88, 1e-5)); From 4a44c277a63f021b93ae72b1b36ab0dfcab69300 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 09:01:49 +0000 Subject: [PATCH 074/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sidb/assess_physical_population_stability.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index a52d8268d..829f63834 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -371,10 +371,8 @@ class assess_physical_population_stability_impl std::transform( sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), - std::back_inserter(energy_charge_index), - [](const auto& ch_lyt) { - return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; - }); + std::back_inserter(energy_charge_index), [](const auto& ch_lyt) + { return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; }); // Sort the vector in ascending order of the energy value std::sort(energy_charge_index.begin(), energy_charge_index.end(), From 10944913339f03a6dc43c6d878a71abf5cd8df35 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 7 May 2024 07:09:05 +0200 Subject: [PATCH 075/221] :bug: small bug fix. --- .../assess_physical_population_stability.hpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 829f63834..a6a743ee3 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -308,8 +308,8 @@ class assess_physical_population_stability_impl else { const auto required_potential_to_conduct_transition_neutral_to_positive = - -local_potential + params.simulation_parameters.mu_plus(); - if (std::abs(-local_potential + params.simulation_parameters.mu_plus()) < + std::abs(-local_potential + params.simulation_parameters.mu_plus()); + if (required_potential_to_conduct_transition_neutral_to_positive < updated_pop_stability_information.transition_from_to_with_cell_and_required_pot .at(transition_type::NEUTRAL_TO_POSITIVE) .second) @@ -343,8 +343,10 @@ class assess_physical_population_stability_impl const auto required_potential_to_conduct_transition_from_positive_to_neutral = std::abs(-local_potential + params.simulation_parameters.mu_plus()); - if (std::abs(-local_potential + params.simulation_parameters.mu_plus()) < - required_potential_to_conduct_transition_from_positive_to_neutral) + if (required_potential_to_conduct_transition_from_positive_to_neutral < + updated_pop_stability_information.transition_from_to_with_cell_and_required_pot + .at(transition_type::POSITIVE_TO_NEUTRAL) + .second) { updated_pop_stability_information .transition_from_to_with_cell_and_required_pot[transition_type::POSITIVE_TO_NEUTRAL] = { @@ -371,8 +373,10 @@ class assess_physical_population_stability_impl std::transform( sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), - std::back_inserter(energy_charge_index), [](const auto& ch_lyt) - { return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; }); + std::back_inserter(energy_charge_index), + [](const auto& ch_lyt) { + return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; + }); // Sort the vector in ascending order of the energy value std::sort(energy_charge_index.begin(), energy_charge_index.end(), From 3c5848743c7f10c74e35cbfca0062c886bf836be Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 05:10:22 +0000 Subject: [PATCH 076/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sidb/assess_physical_population_stability.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index a6a743ee3..26be6f3ce 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -373,10 +373,8 @@ class assess_physical_population_stability_impl std::transform( sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), - std::back_inserter(energy_charge_index), - [](const auto& ch_lyt) { - return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; - }); + std::back_inserter(energy_charge_index), [](const auto& ch_lyt) + { return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; }); // Sort the vector in ascending order of the energy value std::sort(energy_charge_index.begin(), energy_charge_index.end(), From 1cbbc7d4b57e0b8045793445370e00672f8d1786 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 7 May 2024 07:27:33 +0200 Subject: [PATCH 077/221] :art: small renaming due to previous merge. --- .../test/algorithms/physical_design/test_design_sidb_gates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py b/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py index f4ece5400..5a7c0e16b 100644 --- a/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py +++ b/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py @@ -4,7 +4,7 @@ class TestDesignSiDBGates(unittest.TestCase): def test_siqad_and_gate_skeleton(self): - layout = sidb_lattice_100((20, 20)) + layout = sidb_100_lattice((20, 20)) layout.assign_cell_type((0, 1), sidb_technology.cell_type.INPUT) layout.assign_cell_type((2, 3), sidb_technology.cell_type.INPUT) From 1f6420ccb3ad3d9985a18d4da6c389002c3184fa Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 31 May 2024 16:38:43 +0200 Subject: [PATCH 078/221] :art: increase the sample size. --- .../simulation/sidb/defect_influence_operational_domain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 41ea48038..331a2ae18 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -92,7 +92,7 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again params.defect_influence_params.additional_scanning_area = {20, 20}; defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_contour_tracing( - cube_lyt, std::vector{create_or_tt()}, 10, params, &stats); + cube_lyt, std::vector{create_or_tt()}, 30, params, &stats); CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain) > 11.61); } } From 1e805eacfd4925aa4853c9b7c5e8dc074be15b05 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 31 May 2024 14:39:20 +0000 Subject: [PATCH 079/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/algorithms/physical_design/design_sidb_gates.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/algorithms/physical_design/design_sidb_gates.cpp b/test/algorithms/physical_design/design_sidb_gates.cpp index 0b803b00d..d75364ea3 100644 --- a/test/algorithms/physical_design/design_sidb_gates.cpp +++ b/test/algorithms/physical_design/design_sidb_gates.cpp @@ -51,11 +51,10 @@ TEST_CASE("Use SiQAD XNOR skeleton and generate SiQAD XNOR gate, exhaustive", "[ CHECK(lyt.num_cells() == 13); - const design_sidb_gates_params> params{ - sidb_simulation_parameters{2, -0.32}, - {{10, 4, 0}, {10, 4, 0}}, - 1, - sidb_simulation_engine::QUICKEXACT}; + const design_sidb_gates_params> params{sidb_simulation_parameters{2, -0.32}, + {{10, 4, 0}, {10, 4, 0}}, + 1, + sidb_simulation_engine::QUICKEXACT}; const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_xnor_tt()}, params); From 15c4aa2645f5d93e333ff9d1e2a4e02e494403a5 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 31 May 2024 16:51:31 +0200 Subject: [PATCH 080/221] :bug: small error in unit test. --- .../test/algorithms/physical_design/test_design_sidb_gates.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py b/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py index c35df530e..45b1d0ae6 100644 --- a/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py +++ b/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py @@ -73,7 +73,6 @@ def test_nor_gate_111(self): params = design_sidb_gates_params() params.simulation_parameters.base = 2 params.simulation_parameters.mu_minus = -0.32 - params.design_mode = design_sidb_gates_mode.EXHAUSTIVE params.canvas = [(10, 22), (14, 34)] params.number_of_sidbs = 3 params.sim_engine = sidb_simulation_engine.QUICKEXACT From bfc703a0fb19d14b732cae38d92e9d564c3af1ac Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 3 Jun 2024 10:22:49 +0200 Subject: [PATCH 081/221] :art: minor changes. --- .../figure_of_merit_analysis/fom_analysis.cpp | 203 ++++++++++++++++++ .../defect_influence_operational_domain.hpp | 18 +- 2 files changed, 214 insertions(+), 7 deletions(-) create mode 100644 experiments/figure_of_merit_analysis/fom_analysis.cpp diff --git a/experiments/figure_of_merit_analysis/fom_analysis.cpp b/experiments/figure_of_merit_analysis/fom_analysis.cpp new file mode 100644 index 000000000..a54a1185e --- /dev/null +++ b/experiments/figure_of_merit_analysis/fom_analysis.cpp @@ -0,0 +1,203 @@ +// +// Created by Jan Drewniok 01.01.23 +// + +// pre-defined types suitable for the FCN domain +#include "fiction_experiments.hpp" +#include "mockturtle/utils/stopwatch.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace fiction; + +int main() // NOLINT +{ + using Lyt = sidb_100_cell_clk_lyt_cube; + + static const std::string folder = + fmt::format("{}skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd", EXPERIMENTS_PATH); + + experiments::experiment fom_exp{ + "FOM", "benchmark", "CT max", "OPD max", "MDC_ars_min", "MDC_vac_max", "BBR"}; + + const auto skeleton = read_sqd_layout(folder); + + design_sidb_gates_params> params{sidb_simulation_parameters{2, -0.32}, + {{17, 14, 0}, {21, 22, 0}}, + 2, + sidb_simulation_engine::QUICKEXACT}; + + params.maximal_random_solutions = 100; + + const auto truth_tables = std::vector>{ + std::vector{create_and_tt()}, std::vector{create_nand_tt()}, std::vector{create_or_tt()}, + std::vector{create_nor_tt()}, std::vector{create_xor_tt()}, std::vector{create_xnor_tt()}, + std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, + std::vector{create_ge_tt()}}; + + const auto gate_names = std::vector{"and", "nand", "or", "nor", "xor", "xnor", "lt", "gt", "le", "ge"}; + + const critical_temperature_params ct_params{sidb_simulation_parameters{2, params.simulation_parameters.mu_minus, + params.simulation_parameters.epsilon_r, + params.simulation_parameters.lambda_tf}}; + + // defining the operational domain parameters + operational_domain_params op_domain_params{sidb_simulation_parameters{2, params.simulation_parameters.mu_minus, + params.simulation_parameters.epsilon_r, + params.simulation_parameters.lambda_tf}}; + + // setting the operational domain range + op_domain_params.x_min = 4.0; + op_domain_params.x_max = 6; + op_domain_params.x_step = 0.2; + + op_domain_params.y_min = 4.0; + op_domain_params.y_max = 6; + op_domain_params.y_step = 0.2; + + const calculate_min_potential_for_charge_change_for_all_input_combinations_params assess_params{ + assess_physical_population_stability_params{ + sidb_simulation_parameters{2, params.simulation_parameters.mu_minus, params.simulation_parameters.epsilon_r, + params.simulation_parameters.lambda_tf}}}; + + const maximum_defect_influence_position_and_distance_params defect_avoidance_params_arsenic{ + sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}, + params.simulation_parameters, + {30, 20}}; + + const maximum_defect_influence_position_and_distance_params defect_avoidance_params_vacancy{ + sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}, + params.simulation_parameters, + {30, 20}}; + + uint64_t counter = 0; + for (const auto& truth_table : truth_tables) + { + for (auto num_sidbs = 2u; num_sidbs < 6; num_sidbs++) + { + std::cout << fmt::format("num sidbs: {}", num_sidbs) << '\n'; + params.number_of_sidbs = num_sidbs; + + mockturtle::stopwatch<>::duration time_total{}; + + std::vector temps = {}; + std::vector op_domains = {}; + std::vector defect_influence_arsenic = {}; + std::vector defect_influence_vacancy = {}; + std::vector pop_stability_neutral_to_negative = {}; + std::vector pop_stability_negative_to_neutral = {}; + std::vector runtime = {}; + { + mockturtle::stopwatch stop{time_total}; + + const auto all_gate = design_sidb_gates(skeleton, truth_table, params); + + std::cout << fmt::format("Number of gates: {}", all_gate.size()) << '\n'; + + for (const auto& gate : all_gate) + { + temps.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); + operational_domain_stats op_stats{}; + const auto op_domain = operational_domain_flood_fill( + gate, truth_table, 0, op_domain_params, operational_domain::parameter_point{5.6, 5}, &op_stats); + op_domains.push_back(op_stats.percentual_operational_area); + + defect_influence_operational_domain_stats arsenic_stats{}; +// const auto defect_influence_domain_arsenic = defect_influence_operational_domain_grid_search( +// gate, truth_table, 2, +// defect_influence_operational_domain_params{ +// defect_avoidance_params_arsenic, +// is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, +// &arsenic_stats); + std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) << '\n'; + runtime.push_back(mockturtle::to_seconds(arsenic_stats.time_total)); + +// defect_influence_arsenic.push_back( +// defect_avoidance_distance(gate, defect_influence_domain_arsenic)); + + defect_influence_operational_domain_stats vacancy_stats{}; +// const auto defect_influence_domain_vacancy = defect_influence_operational_domain_grid_search( +// gate, truth_table, 2, +// defect_influence_operational_domain_params{ +// defect_avoidance_params_vacancy, +// is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, +// &vacancy_stats); + std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) << '\n'; + +// defect_influence_vacancy.push_back( +// defect_avoidance_distance(gate, defect_influence_domain_vacancy)); + + pop_stability_neutral_to_negative.push_back( + calculate_min_potential_for_charge_change_for_all_input_combinations( + gate, truth_table, + calculate_min_potential_for_charge_change_for_all_input_combinations_params{assess_params}, + -1) * + 1000); + pop_stability_negative_to_neutral.push_back( + calculate_min_potential_for_charge_change_for_all_input_combinations( + gate, truth_table, + calculate_min_potential_for_charge_change_for_all_input_combinations_params{assess_params}, + 1) * + 1000); + } + + if (temps.size() != 0) + { + const auto max_temp = *std::max_element(temps.begin(), temps.end()); + const auto max_op_domain = *std::max_element(op_domains.begin(), op_domains.end()); +// const auto max_defect_influence_arsenic = +// *std::min_element(defect_influence_arsenic.begin(), defect_influence_arsenic.end()); +// const auto max_defect_influence_vacancy = +// *std::min_element(defect_influence_vacancy.begin(), defect_influence_vacancy.end()); + const auto max_pop_stability_neutral_to_negative = *std::max_element( + pop_stability_neutral_to_negative.begin(), pop_stability_neutral_to_negative.end()); + const auto max_pop_stability_negative_to_neutral = *std::max_element( + pop_stability_negative_to_neutral.begin(), pop_stability_negative_to_neutral.end()); + + const auto bbr = + std::max(max_pop_stability_neutral_to_negative, max_pop_stability_negative_to_neutral); + + // log results + fom_exp(gate_names[counter], max_temp, max_op_domain, 0, + 0, bbr); + + fom_exp.save(); + fom_exp.table(); + } + } + } + counter++; + } + return EXIT_SUCCESS; +} diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 9e4581e36..588522a70 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -197,11 +197,13 @@ class defect_influence_operational_domain_impl next_clockwise_point(current_neighborhood, backtrack_point); bool contour_goes_around_layout = false; - while (next_point != contour_starting_point) + + uint64_t counter = 0; + while (next_point != contour_starting_point && counter < 100000) { const auto operational_status = is_defect_position_operational(next_point); // check if the contour goes around the layout. - if (next_point.x >= se_bb_layout.x) + if (next_point.x >= se_bb_layout.x && next_point.y >= se_bb_layout.y) { contour_goes_around_layout = true; } @@ -220,6 +222,7 @@ class defect_influence_operational_domain_impl current_neighborhood = moore_neighborhood(current_contour_point); next_point = next_clockwise_point(current_neighborhood, backtrack_point); + counter++; } number_of_random_start_positions++; if (!contour_goes_around_layout) @@ -294,6 +297,7 @@ class defect_influence_operational_domain_impl */ operational_status is_defect_position_operational(const typename Lyt::cell& c) noexcept { + auto lyt_copy = layout.clone(); // if the point has already been sampled, return the stored operational status if (const auto op_value = has_already_been_sampled(c); op_value.has_value()) { @@ -317,14 +321,14 @@ class defect_influence_operational_domain_impl // increment the number of evaluated parameter combinations ++num_evaluated_defect_positions; - if (!layout.is_empty_cell(c)) + if (!lyt_copy.is_empty_cell(c)) { return non_operational(); } - layout.assign_sidb_defect(c, params.defect_influence_params.defect); - const auto& [status, sim_calls] = is_operational(layout, truth_table, params.operational_params); - layout.assign_sidb_defect(c, sidb_defect{sidb_defect_type::NONE}); + lyt_copy.assign_sidb_defect(c, params.defect_influence_params.defect); + const auto& [status, sim_calls] = is_operational(lyt_copy, truth_table, params.operational_params); + lyt_copy.assign_sidb_defect(c, sidb_defect{sidb_defect_type::NONE}); num_simulator_invocations += sim_calls; if (status == operational_status::NON_OPERATIONAL) @@ -680,7 +684,7 @@ defect_influence_operational_domain_contour_tracing(const Lyt& lyt, const std::v static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); - static_assert(has_cube_coord_v || has_siqad_coord_v, "Lyt is not based on cube coordinates"); + static_assert(has_cube_coord_v, "Lyt is not based on cube coordinates"); defect_influence_operational_domain_stats st{}; detail::defect_influence_operational_domain_impl p{lyt, spec, params, st}; From 69336642cebaad3e53c3c95d585921c9ac0abd08 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 4 Jun 2024 14:14:13 +0200 Subject: [PATCH 082/221] :construction: testing. --- .../figure_of_merit_analysis/fom_analysis.cpp | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/experiments/figure_of_merit_analysis/fom_analysis.cpp b/experiments/figure_of_merit_analysis/fom_analysis.cpp index a54a1185e..cd8b4b4a3 100644 --- a/experiments/figure_of_merit_analysis/fom_analysis.cpp +++ b/experiments/figure_of_merit_analysis/fom_analysis.cpp @@ -134,29 +134,30 @@ int main() // NOLINT op_domains.push_back(op_stats.percentual_operational_area); defect_influence_operational_domain_stats arsenic_stats{}; -// const auto defect_influence_domain_arsenic = defect_influence_operational_domain_grid_search( -// gate, truth_table, 2, -// defect_influence_operational_domain_params{ -// defect_avoidance_params_arsenic, -// is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, -// &arsenic_stats); + // const auto defect_influence_domain_arsenic = + // defect_influence_operational_domain_grid_search( + // gate, truth_table, 2, + // defect_influence_operational_domain_params{ + // defect_avoidance_params_arsenic, + // is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, + // &arsenic_stats); std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) << '\n'; runtime.push_back(mockturtle::to_seconds(arsenic_stats.time_total)); -// defect_influence_arsenic.push_back( -// defect_avoidance_distance(gate, defect_influence_domain_arsenic)); + defect_influence_arsenic.push_back( + defect_avoidance_distance(gate, defect_influence_domain_arsenic)); defect_influence_operational_domain_stats vacancy_stats{}; -// const auto defect_influence_domain_vacancy = defect_influence_operational_domain_grid_search( -// gate, truth_table, 2, -// defect_influence_operational_domain_params{ -// defect_avoidance_params_vacancy, -// is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, -// &vacancy_stats); + const auto defect_influence_domain_vacancy = defect_influence_operational_domain_grid_search( + gate, truth_table, 2, + defect_influence_operational_domain_params{ + defect_avoidance_params_vacancy, + is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, + &vacancy_stats); std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) << '\n'; -// defect_influence_vacancy.push_back( -// defect_avoidance_distance(gate, defect_influence_domain_vacancy)); + defect_influence_vacancy.push_back( + defect_avoidance_distance(gate, defect_influence_domain_vacancy)); pop_stability_neutral_to_negative.push_back( calculate_min_potential_for_charge_change_for_all_input_combinations( @@ -176,10 +177,10 @@ int main() // NOLINT { const auto max_temp = *std::max_element(temps.begin(), temps.end()); const auto max_op_domain = *std::max_element(op_domains.begin(), op_domains.end()); -// const auto max_defect_influence_arsenic = -// *std::min_element(defect_influence_arsenic.begin(), defect_influence_arsenic.end()); -// const auto max_defect_influence_vacancy = -// *std::min_element(defect_influence_vacancy.begin(), defect_influence_vacancy.end()); + const auto max_defect_influence_arsenic = + *std::min_element(defect_influence_arsenic.begin(), defect_influence_arsenic.end()); + const auto max_defect_influence_vacancy = + *std::min_element(defect_influence_vacancy.begin(), defect_influence_vacancy.end()); const auto max_pop_stability_neutral_to_negative = *std::max_element( pop_stability_neutral_to_negative.begin(), pop_stability_neutral_to_negative.end()); const auto max_pop_stability_negative_to_neutral = *std::max_element( @@ -189,11 +190,16 @@ int main() // NOLINT std::max(max_pop_stability_neutral_to_negative, max_pop_stability_negative_to_neutral); // log results - fom_exp(gate_names[counter], max_temp, max_op_domain, 0, - 0, bbr); + fom_exp(gate_names[counter], max_temp, max_op_domain, 0, 0, bbr); fom_exp.save(); fom_exp.table(); + for (auto i = 0; i < temps.size(); i++) + { + cost_function_chi(temps[i] / max_temp, op_domains[i] / max_op_domain, + defect_influence_arsenic[i] / max_defect_influence_arsenic, + defect_influence_vacancy[i]/max_defect_influence_vacancy, bbr[i], bbr, -1,-1,1,1,-1); + } } } } From 009fe964ec585cd5afbecd15ca053031500ac9d0 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 4 Jun 2024 14:29:00 +0200 Subject: [PATCH 083/221] :construction: small fixes. --- .../figure_of_merit_analysis/fom_analysis.cpp | 66 +++++++++++-------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/experiments/figure_of_merit_analysis/fom_analysis.cpp b/experiments/figure_of_merit_analysis/fom_analysis.cpp index cd8b4b4a3..fb1821c12 100644 --- a/experiments/figure_of_merit_analysis/fom_analysis.cpp +++ b/experiments/figure_of_merit_analysis/fom_analysis.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -53,12 +54,9 @@ int main() // NOLINT const auto skeleton = read_sqd_layout(folder); - design_sidb_gates_params> params{sidb_simulation_parameters{2, -0.32}, - {{17, 14, 0}, {21, 22, 0}}, - 2, - sidb_simulation_engine::QUICKEXACT}; + const auto sim_params = sidb_simulation_parameters{2, -0.32}; - params.maximal_random_solutions = 100; + design_sidb_gates_params> params{sim_params, {{17, 14, 0}, {21, 22, 0}}, 2}; const auto truth_tables = std::vector>{ std::vector{create_and_tt()}, std::vector{create_nand_tt()}, std::vector{create_or_tt()}, @@ -68,14 +66,10 @@ int main() // NOLINT const auto gate_names = std::vector{"and", "nand", "or", "nor", "xor", "xnor", "lt", "gt", "le", "ge"}; - const critical_temperature_params ct_params{sidb_simulation_parameters{2, params.simulation_parameters.mu_minus, - params.simulation_parameters.epsilon_r, - params.simulation_parameters.lambda_tf}}; + const critical_temperature_params ct_params{sim_params}; // defining the operational domain parameters - operational_domain_params op_domain_params{sidb_simulation_parameters{2, params.simulation_parameters.mu_minus, - params.simulation_parameters.epsilon_r, - params.simulation_parameters.lambda_tf}}; + operational_domain_params op_domain_params{sim_params}; // setting the operational domain range op_domain_params.x_min = 4.0; @@ -87,18 +81,16 @@ int main() // NOLINT op_domain_params.y_step = 0.2; const calculate_min_potential_for_charge_change_for_all_input_combinations_params assess_params{ - assess_physical_population_stability_params{ - sidb_simulation_parameters{2, params.simulation_parameters.mu_minus, params.simulation_parameters.epsilon_r, - params.simulation_parameters.lambda_tf}}}; + assess_physical_population_stability_params{sim_params}}; const maximum_defect_influence_position_and_distance_params defect_avoidance_params_arsenic{ sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}, - params.simulation_parameters, + sim_params, {30, 20}}; const maximum_defect_influence_position_and_distance_params defect_avoidance_params_vacancy{ sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}, - params.simulation_parameters, + sim_params, {30, 20}}; uint64_t counter = 0; @@ -117,6 +109,7 @@ int main() // NOLINT std::vector defect_influence_vacancy = {}; std::vector pop_stability_neutral_to_negative = {}; std::vector pop_stability_negative_to_neutral = {}; + std::vector bbr_all = {}; std::vector runtime = {}; { mockturtle::stopwatch stop{time_total}; @@ -134,13 +127,12 @@ int main() // NOLINT op_domains.push_back(op_stats.percentual_operational_area); defect_influence_operational_domain_stats arsenic_stats{}; - // const auto defect_influence_domain_arsenic = - // defect_influence_operational_domain_grid_search( - // gate, truth_table, 2, - // defect_influence_operational_domain_params{ - // defect_avoidance_params_arsenic, - // is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, - // &arsenic_stats); + const auto defect_influence_domain_arsenic = defect_influence_operational_domain_grid_search( + gate, truth_table, 2, + defect_influence_operational_domain_params{ + defect_avoidance_params_arsenic, + is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, + &arsenic_stats); std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) << '\n'; runtime.push_back(mockturtle::to_seconds(arsenic_stats.time_total)); @@ -165,12 +157,28 @@ int main() // NOLINT calculate_min_potential_for_charge_change_for_all_input_combinations_params{assess_params}, -1) * 1000); + + const auto bbr_neu_to_neg = + calculate_min_potential_for_charge_change_for_all_input_combinations( + gate, truth_table, + calculate_min_potential_for_charge_change_for_all_input_combinations_params{assess_params}, + 1) * + 1000; + pop_stability_negative_to_neutral.push_back( calculate_min_potential_for_charge_change_for_all_input_combinations( gate, truth_table, calculate_min_potential_for_charge_change_for_all_input_combinations_params{assess_params}, 1) * 1000); + const auto bbr_neg_to_neu = + calculate_min_potential_for_charge_change_for_all_input_combinations( + gate, truth_table, + calculate_min_potential_for_charge_change_for_all_input_combinations_params{assess_params}, + 1) * + 1000; + + bbr_all.push_back(std::min(bbr_neu_to_neg, bbr_neg_to_neu)); } if (temps.size() != 0) @@ -186,19 +194,21 @@ int main() // NOLINT const auto max_pop_stability_negative_to_neutral = *std::max_element( pop_stability_negative_to_neutral.begin(), pop_stability_negative_to_neutral.end()); - const auto bbr = + const auto bbr_max = std::max(max_pop_stability_neutral_to_negative, max_pop_stability_negative_to_neutral); // log results - fom_exp(gate_names[counter], max_temp, max_op_domain, 0, 0, bbr); + fom_exp(gate_names[counter], max_temp, max_op_domain, 0, 0, bbr_max); fom_exp.save(); fom_exp.table(); for (auto i = 0; i < temps.size(); i++) { - cost_function_chi(temps[i] / max_temp, op_domains[i] / max_op_domain, - defect_influence_arsenic[i] / max_defect_influence_arsenic, - defect_influence_vacancy[i]/max_defect_influence_vacancy, bbr[i], bbr, -1,-1,1,1,-1); + cost_function_chi({temps[i] / max_temp, op_domains[i] / max_op_domain, + defect_influence_arsenic[i] / max_defect_influence_arsenic, + defect_influence_vacancy[i] / max_defect_influence_vacancy, + bbr_all[i] / bbr_max}, + {-1, -1, 1, 1, -1}); } } } From a1ed9eb6a171ee8fa208a3df9bead085d6587ec3 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 1 Jul 2024 13:24:33 +0200 Subject: [PATCH 084/221] :art: small fixes. --- docs/algorithms/sidb_simulation.rst | 2 ++ .../figure_of_merit_analysis/fom_analysis.cpp | 6 ++-- .../sidb/defect_avoidance_distance.hpp | 36 ++++++++++++++----- ...te_defect_influence_operational_domain.hpp | 16 ++++----- .../defect_influence_operational_domain.cpp | 8 ++--- 5 files changed, 45 insertions(+), 23 deletions(-) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 4206ca6eb..10bd74db0 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -406,4 +406,6 @@ Maximum Minimum Defect Influence Distance **Header:** ``fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp`` +.. doxygenstruct:: fiction::defect_avoidance_distance_result + :members: .. doxygenfunction:: fiction::defect_avoidance_distance diff --git a/experiments/figure_of_merit_analysis/fom_analysis.cpp b/experiments/figure_of_merit_analysis/fom_analysis.cpp index fb1821c12..09e7eca81 100644 --- a/experiments/figure_of_merit_analysis/fom_analysis.cpp +++ b/experiments/figure_of_merit_analysis/fom_analysis.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -20,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -137,7 +137,7 @@ int main() // NOLINT runtime.push_back(mockturtle::to_seconds(arsenic_stats.time_total)); defect_influence_arsenic.push_back( - defect_avoidance_distance(gate, defect_influence_domain_arsenic)); + defect_avoidance_distance(gate, defect_influence_domain_arsenic).max_min_distance); defect_influence_operational_domain_stats vacancy_stats{}; const auto defect_influence_domain_vacancy = defect_influence_operational_domain_grid_search( @@ -149,7 +149,7 @@ int main() // NOLINT std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) << '\n'; defect_influence_vacancy.push_back( - defect_avoidance_distance(gate, defect_influence_domain_vacancy)); + defect_avoidance_distance(gate, defect_influence_domain_vacancy).max_min_distance); pop_stability_neutral_to_negative.push_back( calculate_min_potential_for_charge_change_for_all_input_combinations( diff --git a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp index 42afade43..9414fe94a 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp @@ -12,6 +12,21 @@ namespace fiction { +/** + * Results of the defect avoidance distance calculation. + */ +template +struct defect_avoidance_distance_result +{ + /** + * Maximum position at which the placement of a SiDB defect still causes the gate to fail. + */ + CellType max_distance_postion_of_non_operational_defect{}; + /** + * Minimum distance between a SiDB of the gate and the defect at the maximum distance that causes the gate to fail. + */ + double max_min_distance{}; +}; /** * Calculates the defect avoidance distance of a given gate layout by a given atomic defect. This means that a defect * must be further away than this distance for the SiDB gate to be operational. This function requires both the defect @@ -23,31 +38,36 @@ namespace fiction * @return The maximum minimum defect influence distance. */ template -[[nodiscard]] double defect_avoidance_distance(const Lyt& lyt, - const defect_influence_operational_domain& defect_opdomain) noexcept +[[nodiscard]] defect_avoidance_distance_result> +defect_avoidance_distance(const Lyt& lyt, const defect_influence_operational_domain& defect_opdomain) noexcept { - double max_distance = 0; + double max_distance = 0; + cell max_distance_postion = {}; + for (const auto& val : defect_opdomain.operational_values) { if (val.second == operational_status::OPERATIONAL) { continue; } - auto min_distance = std::numeric_limits::infinity(); + auto min_distance = std::numeric_limits::infinity(); + cell min_distance_position = {}; lyt.foreach_cell( - [&val, &min_distance, &lyt](const auto& c) + [&val, &min_distance, &min_distance_position, &lyt](const auto& c) { if (sidb_nm_distance(lyt, c, val.first) < min_distance) { - min_distance = sidb_nm_distance(lyt, c, val.first); + min_distance = sidb_nm_distance(lyt, c, val.first); + min_distance_position = val.first; } }); if (min_distance > max_distance) { - max_distance = min_distance; + max_distance = min_distance; + max_distance_postion = min_distance_position; } } - return max_distance; + return defect_avoidance_distance_result>{max_distance_postion, max_distance}; } } // namespace fiction diff --git a/include/fiction/io/write_defect_influence_operational_domain.hpp b/include/fiction/io/write_defect_influence_operational_domain.hpp index be80fce5c..7a978985f 100644 --- a/include/fiction/io/write_defect_influence_operational_domain.hpp +++ b/include/fiction/io/write_defect_influence_operational_domain.hpp @@ -2,8 +2,8 @@ // Created by marcel on 02.08.23. // -#ifndef FICTION_WRITE_OPERATIONAL_DOMAIN_HPP -#define FICTION_WRITE_OPERATIONAL_DOMAIN_HPP +#ifndef FICTION_WRITE_DEFECT_OPERATIONAL_DOMAIN_HPP +#define FICTION_WRITE_DEFECT_OPERATIONAL_DOMAIN_HPP #include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" @@ -20,7 +20,7 @@ namespace fiction /** * Parameters for writing an operational domain to a CSV file. */ -struct write_operational_domain_params +struct write_defect_operational_domain_params { /** * The tag used to represent the operational value of a parameter set. @@ -47,12 +47,12 @@ struct write_operational_domain_params * (represented as a pair of sweep parameters for the X and Y dimensions) to their operational status. * @param os The output stream where the CSV representation of the operational domain is written to. * @param params The parameters used for writing, including the operational and non-operational tags. Defaults to an - * empty `write_operational_domain_params` object, which provides standard tags. + * empty `write_defect_operational_domain_params` object, which provides standard tags. */ template inline void write_defect_influence_operational_domain(const defect_influence_operational_domain& opdom, std::ostream& os, - const write_operational_domain_params& params = {}) + const write_defect_operational_domain_params& params = {}) { csv_writer writer{os}; @@ -80,12 +80,12 @@ inline void write_defect_influence_operational_domain(const defect_influence_ope * (represented as a pair of sweep parameters for the X and Y dimensions) to their operational status. * @param filename The filename where the CSV representation of the operational domain is written to. * @param params The parameters used for writing, including the operational and non-operational tags. Defaults to an - * empty `write_operational_domain_params` object, which provides standard tags. + * empty `write_defect_operational_domain_params` object, which provides standard tags. */ template inline void write_defect_influence_operational_domain(const defect_influence_operational_domain& opdom, const std::string_view& filename, - const write_operational_domain_params& params = {}) + const write_defect_operational_domain_params& params = {}) { std::ofstream os{filename.data(), std::ofstream::out}; @@ -100,4 +100,4 @@ inline void write_defect_influence_operational_domain(const defect_influence_ope } // namespace fiction -#endif // FICTION_WRITE_OPERATIONAL_DOMAIN_HPP +#endif // FICTION_WRITE_DEFECT_OPERATIONAL_DOMAIN_HPP diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 331a2ae18..742ad60aa 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -23,7 +23,7 @@ using namespace fiction; TEST_CASE("novel designed AND Gate influence distance function which fails again", - "[defect-influence-of-sidb-gate-contour-tracing]") + "[defect-influence-operational-domain]") { sidb_cell_clk_lyt_siqad lyt{}; @@ -75,7 +75,7 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_grid_search( cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); - CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain), + CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance, Catch::Matchers::WithinAbs(11.6138152646, physical_constants::POP_STABILITY_ERR)); } SECTION("Random Sampling") @@ -85,7 +85,7 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again const auto defect_influence_domain = defect_influence_operational_domain_random_sampling( cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); - CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain) < 11.61); + CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance < 11.61); } SECTION("Contour Tracing") { @@ -93,6 +93,6 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_contour_tracing( cube_lyt, std::vector{create_or_tt()}, 30, params, &stats); - CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain) > 11.61); + CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance > 11.61); } } From 2f9ff4f4c322c79f28fbe19dfe62553eb5f0c7df Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 1 Jul 2024 14:25:33 +0200 Subject: [PATCH 085/221] :green_heart: changes to fix code ql error. --- .github/workflows/codeql-analysis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index a46f059b0..8975955fd 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -133,10 +133,10 @@ jobs: -DFICTION_WARNINGS_AS_ERRORS=OFF -DMOCKTURTLE_EXAMPLES=OFF - - if: matrix.language == 'cpp' - name: Build fiction - working-directory: ${{github.workspace}}/build - run: cmake --build . --config ${{matrix.build_type}} -j4 + - name: Build fiction + if: ${{ matrix.language == 'cpp' }} + working-directory: ${{ github.workspace }}/build + run: cmake --build . --config ${{ matrix.build_type }} -j4 - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 From 9bce4934a296df2188c10b7802ccf4aa3ac4d936 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 1 Jul 2024 15:16:44 +0200 Subject: [PATCH 086/221] :green_heart: changes to fix code ql error. --- .github/workflows/codeql-analysis.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 8975955fd..f2b0d8c75 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -136,7 +136,20 @@ jobs: - name: Build fiction if: ${{ matrix.language == 'cpp' }} working-directory: ${{ github.workspace }}/build - run: cmake --build . --config ${{ matrix.build_type }} -j4 + run: > + cmake ${{github.workspace}} + -DCMAKE_CXX_COMPILER=${{matrix.compiler}} + -DCMAKE_BUILD_TYPE=Debug + -DFICTION_ENABLE_UNITY_BUILD=ON + -DFICTION_ENABLE_PCH=ON + -DFICTION_CLI=ON + -DFICTION_TEST=ON + -DFICTION_BENCHMARK=OFF + -DFICTION_EXPERIMENTS=ON + -DFICTION_Z3=ON + -DFICTION_PROGRESS_BARS=OFF + -DFICTION_WARNINGS_AS_ERRORS=OFF + -DMOCKTURTLE_EXAMPLES=OFF - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 From 23db22aec039f0d1ce4d7bc43a72922bf910c829 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 1 Jul 2024 18:05:34 +0200 Subject: [PATCH 087/221] :green_heart: changes to fix code ql error. --- .github/workflows/codeql-analysis.yml | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index f2b0d8c75..e14fff801 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -136,20 +136,8 @@ jobs: - name: Build fiction if: ${{ matrix.language == 'cpp' }} working-directory: ${{ github.workspace }}/build - run: > - cmake ${{github.workspace}} - -DCMAKE_CXX_COMPILER=${{matrix.compiler}} - -DCMAKE_BUILD_TYPE=Debug - -DFICTION_ENABLE_UNITY_BUILD=ON - -DFICTION_ENABLE_PCH=ON - -DFICTION_CLI=ON - -DFICTION_TEST=ON - -DFICTION_BENCHMARK=OFF - -DFICTION_EXPERIMENTS=ON - -DFICTION_Z3=ON - -DFICTION_PROGRESS_BARS=OFF - -DFICTION_WARNINGS_AS_ERRORS=OFF - -DMOCKTURTLE_EXAMPLES=OFF + run: cmake --build . --config ${{matrix.build_type}} -j4 + - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 From c5bb04f4f3809442ab6e0a666233d579ddad2e0c Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 1 Jul 2024 18:33:47 +0200 Subject: [PATCH 088/221] :green_heart: disable mugen. --- .github/workflows/codeql-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index e14fff801..26a0fe634 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -128,7 +128,7 @@ jobs: -DFICTION_BENCHMARK=OFF -DFICTION_EXPERIMENTS=ON -DFICTION_Z3=ON - -DFICTION_ENABLE_MUGEN=ON + -DFICTION_ENABLE_MUGEN=OFF -DFICTION_PROGRESS_BARS=OFF -DFICTION_WARNINGS_AS_ERRORS=OFF -DMOCKTURTLE_EXAMPLES=OFF From 088b0dcba54f7b27b9fcee5e8d7a20550af662ba Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 2 Jul 2024 07:20:11 +0200 Subject: [PATCH 089/221] :art: update docstring. --- .../algorithms/simulation/sidb/defect_avoidance_distance.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp index 9414fe94a..3c488555e 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp @@ -14,6 +14,8 @@ namespace fiction { /** * Results of the defect avoidance distance calculation. + * + * @tparam CellType */ template struct defect_avoidance_distance_result From 2478303afc854294184550333f5f28e915f599a5 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 2 Jul 2024 09:07:10 +0200 Subject: [PATCH 090/221] :green_heart: small changes to test. --- .github/workflows/codeql-analysis.yml | 46 +++++++++++++-------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 26a0fe634..a5914ce3f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -110,31 +110,31 @@ jobs: languages: ${{ matrix.language }} config-file: .github/codeql-config.yml - - if: matrix.language == 'cpp' - name: Create Build Environment - run: cmake -E make_directory ${{github.workspace}}/build - - - if: matrix.language == 'cpp' - name: Configure CMake - working-directory: ${{github.workspace}}/build - run: > - cmake ${{github.workspace}} - -DCMAKE_CXX_COMPILER=${{matrix.compiler}} - -DCMAKE_BUILD_TYPE=${{matrix.build_type}} - -DFICTION_ENABLE_UNITY_BUILD=ON - -DFICTION_ENABLE_PCH=ON - -DFICTION_CLI=ON - -DFICTION_TEST=ON - -DFICTION_BENCHMARK=OFF - -DFICTION_EXPERIMENTS=ON - -DFICTION_Z3=ON - -DFICTION_ENABLE_MUGEN=OFF - -DFICTION_PROGRESS_BARS=OFF - -DFICTION_WARNINGS_AS_ERRORS=OFF - -DMOCKTURTLE_EXAMPLES=OFF + - name: Create Build Environment + if: matrix.language == 'cpp' + run: cmake -E make_directory ${{ github.workspace }}/build + + - name: Configure CMake + if: matrix.language == 'cpp' + working-directory: ${{ github.workspace }}/build + run: | + cmake ${{ github.workspace }} \ + -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} \ + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + -DFICTION_ENABLE_UNITY_BUILD=ON \ + -DFICTION_ENABLE_PCH=ON \ + -DFICTION_CLI=ON \ + -DFICTION_TEST=ON \ + -DFICTION_BENCHMARK=OFF \ + -DFICTION_EXPERIMENTS=ON \ + -DFICTION_Z3=ON \ + -DFICTION_ENABLE_MUGEN=OFF \ + -DFICTION_PROGRESS_BARS=OFF \ + -DFICTION_WARNINGS_AS_ERRORS=OFF \ + -DMOCKTURTLE_EXAMPLES=OFF - name: Build fiction - if: ${{ matrix.language == 'cpp' }} + if: matrix.language == 'cpp' working-directory: ${{ github.workspace }}/build run: cmake --build . --config ${{matrix.build_type}} -j4 From 55f9ab83da922afd70712c6af87652fad6ebe313 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 2 Jul 2024 11:00:03 +0200 Subject: [PATCH 091/221] :green_heart: small changes to test. --- .github/workflows/codeql-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index a5914ce3f..328ed9d2e 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -37,7 +37,7 @@ env: jobs: analyze: name: Analyze ${{ matrix.language }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 permissions: actions: read contents: read From 4ffefe14ac21404e8b260256be51eb3c290133f3 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 2 Jul 2024 12:11:41 +0200 Subject: [PATCH 092/221] :green_heart: small changes to test. --- .github/workflows/codeql-analysis.yml | 40 +++++++++++++++------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 328ed9d2e..68935e47a 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -31,6 +31,10 @@ concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true +defaults: + run: + shell: bash + env: Z3_VERSION: 4.10.0 @@ -85,14 +89,14 @@ jobs: python-version: '3.10.x' cache: 'pip' - - name: Setup mold - uses: rui314/setup-mold@v1 - - name: Install pip packages uses: BSFishy/pip-action@v1 with: requirements: ${{github.workspace}}/libs/mugen/requirements.txt + - name: Setup mold + uses: rui314/setup-mold@v1 + - name: Setup Z3 Solver id: z3 uses: cda-tum/setup-z3@v1 @@ -117,21 +121,21 @@ jobs: - name: Configure CMake if: matrix.language == 'cpp' working-directory: ${{ github.workspace }}/build - run: | - cmake ${{ github.workspace }} \ - -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} \ - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ - -DFICTION_ENABLE_UNITY_BUILD=ON \ - -DFICTION_ENABLE_PCH=ON \ - -DFICTION_CLI=ON \ - -DFICTION_TEST=ON \ - -DFICTION_BENCHMARK=OFF \ - -DFICTION_EXPERIMENTS=ON \ - -DFICTION_Z3=ON \ - -DFICTION_ENABLE_MUGEN=OFF \ - -DFICTION_PROGRESS_BARS=OFF \ - -DFICTION_WARNINGS_AS_ERRORS=OFF \ - -DMOCKTURTLE_EXAMPLES=OFF + run: > + cmake ${{github.workspace}} ${{matrix.cppstandard}} + -DCMAKE_CXX_COMPILER=${{matrix.compiler}} + -DCMAKE_BUILD_TYPE=Debug + -DFICTION_ENABLE_UNITY_BUILD=ON + -DFICTION_ENABLE_PCH=ON + -DFICTION_CLI=ON + -DFICTION_TEST=ON + -DFICTION_BENCHMARK=OFF + -DFICTION_EXPERIMENTS=ON + -DFICTION_Z3=ON + -DFICTION_ENABLE_MUGEN=ON + -DFICTION_PROGRESS_BARS=OFF + -DFICTION_WARNINGS_AS_ERRORS=OFF + -DMOCKTURTLE_EXAMPLES=OFF - name: Build fiction if: matrix.language == 'cpp' From 63f35f59b0f5c6c56d13008062ea60f16877cbcb Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 3 Jul 2024 08:40:22 +0200 Subject: [PATCH 093/221] :art: rename function. --- docs/algorithms/sidb_simulation.rst | 6 ++-- .../figure_of_merit_analysis/fom_analysis.cpp | 28 +++++++------------ ...p => calculate_min_bbr_for_all_inputs.hpp} | 12 ++++---- ...arge_change_for_all_input_combinations.cpp | 10 +++---- 4 files changed, 23 insertions(+), 33 deletions(-) rename include/fiction/algorithms/simulation/sidb/{calculate_min_potential_for_charge_change_for_all_input_combinations.hpp => calculate_min_bbr_for_all_inputs.hpp} (89%) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 10bd74db0..cfd435c88 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -372,11 +372,11 @@ Assess Population Stability :members: .. doxygenfunction:: fiction::assess_physical_population_stability - **Header:** ``fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp`` + **Header:** ``fiction/algorithms/simulation/sidb/calculate_min_bbr.hpp`` - .. doxygenstruct:: fiction::calculate_min_potential_for_charge_change_for_all_input_combinations_params + .. doxygenstruct:: fiction::calculate_min_bbr_for_all_inputs_params :members: - .. doxygenfunction:: fiction::calculate_min_potential_for_charge_change_for_all_input_combinations + .. doxygenfunction:: fiction::calculate_min_bbr_for_all_inputs .. tab:: Python diff --git a/experiments/figure_of_merit_analysis/fom_analysis.cpp b/experiments/figure_of_merit_analysis/fom_analysis.cpp index 09e7eca81..de7821780 100644 --- a/experiments/figure_of_merit_analysis/fom_analysis.cpp +++ b/experiments/figure_of_merit_analysis/fom_analysis.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include @@ -80,7 +80,7 @@ int main() // NOLINT op_domain_params.y_max = 6; op_domain_params.y_step = 0.2; - const calculate_min_potential_for_charge_change_for_all_input_combinations_params assess_params{ + const calculate_min_bbr_for_all_inputs_params assess_params{ assess_physical_population_stability_params{sim_params}}; const maximum_defect_influence_position_and_distance_params defect_avoidance_params_arsenic{ @@ -152,30 +152,22 @@ int main() // NOLINT defect_avoidance_distance(gate, defect_influence_domain_vacancy).max_min_distance); pop_stability_neutral_to_negative.push_back( - calculate_min_potential_for_charge_change_for_all_input_combinations( - gate, truth_table, - calculate_min_potential_for_charge_change_for_all_input_combinations_params{assess_params}, - -1) * + calculate_min_bbr(gate, truth_table, calculate_min_bbr_for_all_inputs_params{assess_params}, + -1) * 1000); const auto bbr_neu_to_neg = - calculate_min_potential_for_charge_change_for_all_input_combinations( - gate, truth_table, - calculate_min_potential_for_charge_change_for_all_input_combinations_params{assess_params}, - 1) * + calculate_min_bbr(gate, truth_table, calculate_min_bbr_for_all_inputs_params{assess_params}, + 1) * 1000; pop_stability_negative_to_neutral.push_back( - calculate_min_potential_for_charge_change_for_all_input_combinations( - gate, truth_table, - calculate_min_potential_for_charge_change_for_all_input_combinations_params{assess_params}, - 1) * + calculate_min_bbr(gate, truth_table, calculate_min_bbr_for_all_inputs_params{assess_params}, + 1) * 1000); const auto bbr_neg_to_neu = - calculate_min_potential_for_charge_change_for_all_input_combinations( - gate, truth_table, - calculate_min_potential_for_charge_change_for_all_input_combinations_params{assess_params}, - 1) * + calculate_min_bbr(gate, truth_table, calculate_min_bbr_for_all_inputs_params{assess_params}, + 1) * 1000; bbr_all.push_back(std::min(bbr_neu_to_neg, bbr_neg_to_neu)); diff --git a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp b/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp similarity index 89% rename from include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp rename to include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp index 3d0407c88..fc40538e5 100644 --- a/include/fiction/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.hpp +++ b/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp @@ -2,8 +2,8 @@ // Created by Jan Drewniok on 28.01.24. // -#ifndef FICTION_CALCULATE_MIN_POTENTIAL_FOR_CHARGE_CHANGE_FOR_ALL_INPUT_COMBINATIONS_HPP -#define FICTION_CALCULATE_MIN_POTENTIAL_FOR_CHARGE_CHANGE_FOR_ALL_INPUT_COMBINATIONS_HPP +#ifndef FICTION_CALCULATE_MIN_BBR_FOR_ALL_INPUTS_HPP +#define FICTION_CALCULATE_MIN_BBR_FOR_ALL_INPUTS_HPP #include "fiction/algorithms/iter/bdl_input_iterator.hpp" #include "fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp" @@ -21,7 +21,7 @@ namespace fiction /** * This struct stores the parameters required to assess the population stability of an SiDB gate. */ -struct calculate_min_potential_for_charge_change_for_all_input_combinations_params +struct calculate_min_bbr_for_all_inputs_params { /** * Parameters for the `assessing physical population stability` simulation @@ -45,9 +45,9 @@ struct calculate_min_potential_for_charge_change_for_all_input_combinations_para * @return The minimum potential required for charge change across all input combinations. */ template -[[nodiscard]] double calculate_min_potential_for_charge_change_for_all_input_combinations( +[[nodiscard]] double calculate_min_bbr_for_all_inputs( const Lyt& lyt, const std::vector& spec, - const calculate_min_potential_for_charge_change_for_all_input_combinations_params& params = {}, + const calculate_min_bbr_for_all_inputs_params& params = {}, const std::optional charge_state_change = 1) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); @@ -115,4 +115,4 @@ template } // namespace fiction -#endif // FICTION_CALCULATE_MIN_POTENTIAL_FOR_CHARGE_CHANGE_FOR_ALL_INPUT_COMBINATIONS_HPP +#endif // FICTION_CALCULATE_MIN_BBR_FOR_ALL_INPUTS_HPP diff --git a/test/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.cpp b/test/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.cpp index 58edefe91..eccd267ac 100644 --- a/test/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.cpp +++ b/test/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.cpp @@ -8,7 +8,7 @@ #include "utils/blueprints/layout_blueprints.hpp" #include -#include +#include #include #include #include @@ -24,21 +24,19 @@ TEST_CASE("Single SiDB", "[assess-physical-population-stability-sidb-gate]") { const auto lyt = blueprints::bestagon_and_gate(); - const auto params = calculate_min_potential_for_charge_change_for_all_input_combinations_params{ + const auto params = calculate_min_bbr_for_all_inputs_params{ assess_physical_population_stability_params{sidb_simulation_parameters{2, -0.32}, 2}}; SECTION("Minimal potential required to conduct a charge change from neutral to negative") { - const auto min_potential = calculate_min_potential_for_charge_change_for_all_input_combinations( - lyt, std::vector{create_and_tt()}, params, -1); + const auto min_potential = calculate_min_bbr_for_all_inputs(lyt, std::vector{create_and_tt()}, params, -1); CHECK_THAT(min_potential, Catch::Matchers::WithinAbs(0.020652, physical_constants::POP_STABILITY_ERR)); } SECTION("Minimal potential required to conduct a charge change from negative to neutral") { - const auto min_potential = calculate_min_potential_for_charge_change_for_all_input_combinations( - lyt, std::vector{create_and_tt()}, params, 1); + const auto min_potential = calculate_min_bbr_for_all_inputs(lyt, std::vector{create_and_tt()}, params, 1); CHECK_THAT(min_potential, Catch::Matchers::WithinAbs(0.087417, physical_constants::POP_STABILITY_ERR)); } From 95cf2634ba01c9ee86ef946164ee947d9d435580 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 3 Jul 2024 06:40:39 +0000 Subject: [PATCH 094/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulation/sidb/calculate_min_bbr_for_all_inputs.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp b/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp index fc40538e5..bf2ab21cb 100644 --- a/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp +++ b/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp @@ -45,10 +45,9 @@ struct calculate_min_bbr_for_all_inputs_params * @return The minimum potential required for charge change across all input combinations. */ template -[[nodiscard]] double calculate_min_bbr_for_all_inputs( - const Lyt& lyt, const std::vector& spec, - const calculate_min_bbr_for_all_inputs_params& params = {}, - const std::optional charge_state_change = 1) +[[nodiscard]] double calculate_min_bbr_for_all_inputs(const Lyt& lyt, const std::vector& spec, + const calculate_min_bbr_for_all_inputs_params& params = {}, + const std::optional charge_state_change = 1) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); From d97820ea2aac1e7a716831956924051fce794529 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 3 Jul 2024 09:05:27 +0200 Subject: [PATCH 095/221] :art: missing renaming in experiment. --- .../figure_of_merit_analysis/fom_analysis.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/experiments/figure_of_merit_analysis/fom_analysis.cpp b/experiments/figure_of_merit_analysis/fom_analysis.cpp index de7821780..81c525313 100644 --- a/experiments/figure_of_merit_analysis/fom_analysis.cpp +++ b/experiments/figure_of_merit_analysis/fom_analysis.cpp @@ -2,7 +2,6 @@ // Created by Jan Drewniok 01.01.23 // -// pre-defined types suitable for the FCN domain #include "fiction_experiments.hpp" #include "mockturtle/utils/stopwatch.hpp" @@ -152,22 +151,22 @@ int main() // NOLINT defect_avoidance_distance(gate, defect_influence_domain_vacancy).max_min_distance); pop_stability_neutral_to_negative.push_back( - calculate_min_bbr(gate, truth_table, calculate_min_bbr_for_all_inputs_params{assess_params}, - -1) * + calculate_min_bbr_for_all_inputs(gate, truth_table, + calculate_min_bbr_for_all_inputs_params{assess_params}, -1) * 1000); const auto bbr_neu_to_neg = - calculate_min_bbr(gate, truth_table, calculate_min_bbr_for_all_inputs_params{assess_params}, - 1) * + calculate_min_bbr_for_all_inputs(gate, truth_table, + calculate_min_bbr_for_all_inputs_params{assess_params}, 1) * 1000; pop_stability_negative_to_neutral.push_back( - calculate_min_bbr(gate, truth_table, calculate_min_bbr_for_all_inputs_params{assess_params}, - 1) * + calculate_min_bbr_for_all_inputs(gate, truth_table, + calculate_min_bbr_for_all_inputs_params{assess_params}, 1) * 1000); const auto bbr_neg_to_neu = - calculate_min_bbr(gate, truth_table, calculate_min_bbr_for_all_inputs_params{assess_params}, - 1) * + calculate_min_bbr_for_all_inputs(gate, truth_table, + calculate_min_bbr_for_all_inputs_params{assess_params}, 1) * 1000; bbr_all.push_back(std::min(bbr_neu_to_neg, bbr_neg_to_neu)); From d61690da10f44b7cc03c51935568d8158045f0dd Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 3 Jul 2024 13:04:19 +0200 Subject: [PATCH 096/221] :green_heart: fix windows build issue. --- .../simulation/sidb/defect_influence_operational_domain.hpp | 5 +++-- ...combinations.cpp => calculate_min_bbr_for_all_inputs.cpp} | 0 2 files changed, 3 insertions(+), 2 deletions(-) rename test/algorithms/simulation/sidb/{calculate_min_potential_for_charge_change_for_all_input_combinations.cpp => calculate_min_bbr_for_all_inputs.cpp} (100%) diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 588522a70..771ccd133 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -85,6 +85,7 @@ struct defect_influence_operational_domain_stats namespace detail { + template class defect_influence_operational_domain_impl { @@ -248,8 +249,8 @@ class defect_influence_operational_domain_impl const auto siqad_layout = convert_to_siqad_coordinates(layout); bounding_box_2d bb{siqad_layout}; - auto nw = siqad::to_fiction_coord(bb.get_min()); // north-west cell - auto se = siqad::to_fiction_coord(bb.get_max()); // south-east cell + auto nw = fiction::siqad::to_fiction_coord(bb.get_min()); // north-west cell + auto se = fiction::siqad::to_fiction_coord(bb.get_max()); // south-east cell nw_bb_layout = nw; se_bb_layout = se; diff --git a/test/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.cpp b/test/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.cpp similarity index 100% rename from test/algorithms/simulation/sidb/calculate_min_potential_for_charge_change_for_all_input_combinations.cpp rename to test/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.cpp From b1aa210184e600a1998417f871166a0ffcec6992 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 19 Jul 2024 14:27:46 +0000 Subject: [PATCH 097/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/pybind11_mkdoc_docstrings.hpp | 705 +++++++++++++++++- 1 file changed, 673 insertions(+), 32 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index cd09c116b..a589fd317 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -813,6 +813,44 @@ Parameter ``input_index``: Electrostatic potential energy of all charge distributions with state type.)doc"; +static const char *__doc_fiction_calculate_min_bbr_for_all_inputs = +R"doc(Calculates the minimum potential required to induce charge changes in +an SiDB layout for all input combinations. + +Template parameter ``Lyt``: + Type representing the SiDB cell-level layout. + +Template parameter ``TT``: + Type representing the truth table. + +Parameter ``lyt``: + The SiDB layout object. + +Parameter ``spec``: + Expected Boolean function of the layout, provided as a multi- + output truth table. + +Parameter ``params``: + Parameters for assessing physical population stability. + +Parameter ``charge_state_change``: + Optional parameter indicating the direction of the considered + charge state change (default is 1). + +Returns: + The minimum potential required for charge change across all input + combinations.)doc"; + +static const char *__doc_fiction_calculate_min_bbr_for_all_inputs_params = +R"doc(This struct stores the parameters required to assess the population +stability of an SiDB gate.)doc"; + +static const char *__doc_fiction_calculate_min_bbr_for_all_inputs_params_assess_population_stability_params = +R"doc(Parameters for the `assessing physical population stability` +simulation)doc"; + +static const char *__doc_fiction_calculate_min_bbr_for_all_inputs_params_detect_pair_params = R"doc(Parameters to identify the output pairs used to read the output.)doc"; + static const char *__doc_fiction_can_positive_charges_occur = R"doc(This algorithm determines if positively charged SiDBs can occur in a given SiDB cell-level layout due to strong electrostatic interaction. @@ -2515,6 +2553,24 @@ static const char *__doc_fiction_coord_iterator_operator_mul = R"doc()doc"; static const char *__doc_fiction_coord_iterator_operator_ne = R"doc()doc"; +static const char *__doc_fiction_cost_function_chi = +R"doc(Calculates the cost function :math:` \chi = \sum_{i=1} w_{i} \cdot +\chi_{i} ` by summing the product of normalized chi values :math:` +\chi_{i} ` and weights :math:` w_{i} `. + +Parameter ``chis``: + The vector containing the chi values. + +Parameter ``weights``: + The vector containing the weights. + +Returns: + The calculated cost function :math:` \chi(L) `. + +Throws: + std::invalid_argument If the sizes of chis and weights vectors are + different.)doc"; + static const char *__doc_fiction_cost_functor = R"doc(A functor that computes costs between coordinates and can be passed as an object to, e.g., path finding algorithms with a standardized @@ -2978,6 +3034,8 @@ distributions.)doc"; static const char *__doc_fiction_critical_temperature_stats_critical_temperature = R"doc(*Critical Temperature* of the given layout (unit: K).)doc"; +static const char *__doc_fiction_critical_temperature_stats_duration = R"doc(The total runtime of the critical temperature computation.)doc"; + static const char *__doc_fiction_critical_temperature_stats_energy_between_ground_state_and_first_erroneous = R"doc(Energy difference between the ground state and the first (erroneous) excited state (unit: meV).)doc"; @@ -3232,6 +3290,38 @@ static const char *__doc_fiction_debug_write_dot_layout = R"doc()doc"; static const char *__doc_fiction_debug_write_dot_network = R"doc()doc"; +static const char *__doc_fiction_defect_avoidance_distance = +R"doc(Calculates the defect avoidance distance of a given gate layout by a +given atomic defect. This means that a defect must be further away +than this distance for the SiDB gate to be operational. This function +requires both the defect operational domain and the layout as input. + +Template parameter ``Lyt``: + Type representing the SiDB cell-level layout. + +Parameter ``lyt``: + The cell-level layout for which the defect operational domain was + computed. + +Parameter ``defect_opdomain``: + The defect operational domain associated with the layout. + +Returns: + The maximum minimum defect influence distance.)doc"; + +static const char *__doc_fiction_defect_avoidance_distance_result = +R"doc(Results of the defect avoidance distance calculation. + +Template parameter ``CellType``:)doc"; + +static const char *__doc_fiction_defect_avoidance_distance_result_max_distance_postion_of_non_operational_defect = +R"doc(Maximum position at which the placement of a SiDB defect still causes +the gate to fail.)doc"; + +static const char *__doc_fiction_defect_avoidance_distance_result_max_min_distance = +R"doc(Minimum distance between a SiDB of the gate and the defect at the +maximum distance that causes the gate to fail.)doc"; + static const char *__doc_fiction_defect_extent = R"doc(Returns the extent of a defect as a pair of SiDB distances in horizontal and vertical direction. If `defect` has the `NONE` defect @@ -3244,6 +3334,170 @@ Parameter ``defect``: Number of horizontal and vertical SiDBs that are affected by the given defect.)doc"; +static const char *__doc_fiction_defect_influence_operational_domain = +R"doc(A defect operational domain defines the positions where a specific +atomic defect may exist along with corresponding information +indicating whether the SiDB layout remains logically operational. +Logically operational implies that the layout's ground state aligns +with a designated Boolean function at the layout's outputs for all +feasible input combinations. This implementation assumes the presence +of :math:` n ` BDL input wires and a single BDL output wire for a +given layout. Any algorithm for computing the defect influence +operational domain iterates through all :math:` 2^n ` input +combinations, evaluating the layout's output behavior based on the +specified Boolean function. The layout is classified as operational +for a particular defect position only if its output behavior is +correct across all input combinations.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_contour_tracing = +R"doc(Computes the defect influence operational domain of the given SiDB +cell-level layout. The defect influence operational domain is the set +of all defect positions for which the layout is logically operational. +Logical operation is defined as the layout implementing the given +truth table. The input BDL pairs of the layout are assumed to be in +the same order as the inputs of the truth table. + +This algorithm uses contour tracing to identify operational defect +locations within the SiDB gate layout. It starts by searching for +defect locations on the left side of the bounding box, with an +additional distance of the SiDB gate where the SiDB gate remains +operational. The y-coordinate for these positions is chosen randomly. +The number of samples is determined by the `samples` parameter. + +Then the algorithm moves each defect position to the right, searching +for the last operational defect position. This position is selected as +the starting point for the contour trace. The contour tracing process +checks whether the contour includes the SiDB layout. If it does not, +the next random sample point is is selected as the starting point and +the process is repeated. + +@Note This algorithm is an approximation to determine the defect +influence operational domain. Therefore, it is recommended to analyze +the result afterwards to assess whether the contour reflects the +desired contour. + +Template parameter ``Lyt``: + SiDB cell-level layout type. + +Template parameter ``TT``: + Truth table type. + +Parameter ``lyt``: + Layout to compute the defect influence operational domain for. + +Parameter ``spec``: + Expected Boolean function of the layout given as a multi-output + truth table. + +Parameter ``samples``: + Number of samples to perform. + +Parameter ``params``: + Defect influence operational domain computation parameters. + +Parameter ``stats``: + Operational domain computation statistics. + +Returns: + The (partial) defect influence operational domain of the layout.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_grid_search = +R"doc(Computes the defect influence operational domain of the given SiDB +layout. The defect influence operational domain is the set of all +defect positions for which the layout is logically operational. +Logical operation is defined as the layout implementing the given +truth table. + +This algorithm uses a grid search to determine the defect influence +operational domain. The grid search is performed by exhaustively +sweeping all possible atomic defect positions in x and y dimensions. + +Template parameter ``Lyt``: + SiDB cell-level layout type. + +Template parameter ``TT``: + Truth table type. + +Parameter ``lyt``: + Layout to compute the defect influence operational domain for. + +Parameter ``spec``: + Expected Boolean function of the layout given as a multi-output + truth table. + +Parameter ``step_size``: + The parameter specifying the interval between consecutive defect + positions to be evaluated. + +Parameter ``params``: + Defect influence operational domain computation parameters. + +Parameter ``stats``: + Statistics. + +Returns: + The defect influence operational domain of the layout.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_operational_values = R"doc()doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_params = R"doc(Parameters to determine the defect influence operational domain.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_params_defect_influence_params = R"doc(Parameters to simulate the influence of the atomic defect.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_params_operational_params = R"doc(Parameters for the `is_operational` algorithm.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_random_sampling = +R"doc(Computes the `defect influence operational domain` of the given SiDB +cell-level layout. The defect influence operational domain is the set +of all defect positions for which the layout is logically operational. +Logical operation is defined as the layout implementing the given +truth table. The input BDL pairs of the layout are assumed to be in +the same order as the inputs of the truth table. + +This algorithm uses random sampling to find a part of the defect +influence operational domain that might not be complete. It performs a +total of `samples` uniformly-distributed random samples within the +specified area. + +Template parameter ``Lyt``: + SiDB cell-level layout type. + +Template parameter ``TT``: + Truth table type. + +Parameter ``lyt``: + Layout to compute the defect influence operational domain for. + +Parameter ``spec``: + Expected Boolean function of the layout given as a multi-output + truth table. + +Parameter ``samples``: + Number of random samples to perform. + +Parameter ``params``: + Defect influence operational domain computation parameters. + +Parameter ``stats``: + Statistics. + +Returns: + The (partial) defect influence operational domain of the layout.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_stats = R"doc(Statistics.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_stats_duration = R"doc(The total runtime of the operational domain computation.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_stats_num_evaluated_defect_positions = R"doc(Number of evaluated parameter combinations.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_stats_num_non_operational_defect_positions = +R"doc(Number of parameter combinations, for which the layout is non- +operational.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_stats_num_operational_defect_positions = R"doc(Number of parameter combinations, for which the layout is operational.)doc"; + +static const char *__doc_fiction_defect_influence_operational_domain_stats_num_simulator_invocations = R"doc(Number of simulator invocations.)doc"; + static const char *__doc_fiction_dependent_cell_mode = R"doc(An enumeration of modes for the dependent cell.)doc"; static const char *__doc_fiction_dependent_cell_mode_FIXED = @@ -3258,12 +3512,12 @@ static const char *__doc_fiction_design_sidb_gates = R"doc(The *SiDB Gate Designer* designs SiDB gate implementations based on a specified Boolean function, a skeleton layout (can hold defects), canvas size, and a predetermined number of canvas SiDBs. Two different -design modes are implemented: `exhaustive` and `random design`. +design modes are implemented: `exhaustive` and `random`. The `exhaustive design` is composed of three steps: 1. In the initial step, all possible distributions of `number_of_sidbs` SiDBs within a given canvas are exhaustively determined. This ensures exhaustive -coverage of every potential arrangement of ``number_of_sidbs`` SiDBs +coverage of every potential arrangement of `number_of_sidbs` SiDBs across the canvas. 2. The calculated SiDB distributions are then incorporated into the skeleton, resulting in the generation of distinct SiDB layouts. 3. The generated SiDB layouts then undergo an @@ -3294,9 +3548,81 @@ Parameter ``spec``: Parameter ``params``: Parameters for the *SiDB Gate Designer*. +Parameter ``design_mode``: + The design mode to use. + +Parameter ``stats``: + The design statistics. + Returns: A vector of designed SiDB gate layouts.)doc"; +static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing = +R"doc(This function designs SiDB gates to minimize the cost function +:math:`\chi`, considering a layout skeleton, a set of truth tables, +and specified parameters for gate design and simulated annealing. +Currently, only the critical temperature and the operational domain +are incorporated into the cost function. + +Template parameter ``Lyt``: + SiDB cell-level layout type. + +Template parameter ``TT``: + The type of the truth table specifying the gate behavior. + +Parameter ``skeleton``: + The layout skeleton used as the basis for gate design. + +Parameter ``spec``: + Expected Boolean function of the layout given as a multi-output + truth table. + +Parameter ``params``: + The parameters for gate design. + +Parameter ``sa_params``: + Parameters for simulated annealing. + +Parameter ``stats``: + Statistics for gate design. + +Returns: + A layout with SiDB gates designed to minimize the cost function.)doc"; + +static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params = R"doc(Parameters for Simulated Annealing-based gate design.)doc"; + +static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_ct_params = R"doc(Parameters for simulating the Critical Temperature.)doc"; + +static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_final_temperature = R"doc(Final temperature for Simulated Annealing.)doc"; + +static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_initial_temperature = R"doc(Initial temperature for Simulated Annealing.)doc"; + +static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_number_of_cycles = R"doc(Number of iterations per temperature in Simulated Annealing.)doc"; + +static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_op_params = R"doc(Parameters for simulating the Operational Domain.)doc"; + +static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_schedule = R"doc(Type of temperature schedule used in Simulated Annealing.)doc"; + +static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_weight_non_operational = +R"doc(Weight assigned to the non-operational behavior in the overall cost +function. This weight affects the cost function when the design is +non-operational.)doc"; + +static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_weight_operational_domain = +R"doc(Weight assigned to the operational domain in the overall cost +function. A negative value indicates that this weight is not used.)doc"; + +static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_weight_temperature = +R"doc(Weight assigned to the critical temperature in the overall cost +function. A negative value indicates that a high critical temperature +is preferred.)doc"; + +static const char *__doc_fiction_design_sidb_gates_mode = R"doc(Selector for the available design approaches.)doc"; + +static const char *__doc_fiction_design_sidb_gates_mode_EXHAUSTIVE = R"doc(All gate layouts are designed exhaustively.)doc"; + +static const char *__doc_fiction_design_sidb_gates_mode_RANDOM = R"doc(Gate layouts are designed randomly.)doc"; + static const char *__doc_fiction_design_sidb_gates_params = R"doc(This struct contains parameters and settings to design SiDB gates. @@ -3305,13 +3631,9 @@ Template parameter ``CellType``: static const char *__doc_fiction_design_sidb_gates_params_canvas = R"doc(Canvas spanned by the northwest and southeast cell.)doc"; -static const char *__doc_fiction_design_sidb_gates_params_design_mode = R"doc(Gate design mode.)doc"; - -static const char *__doc_fiction_design_sidb_gates_params_design_sidb_gates_mode = R"doc(Selector for the available design approaches.)doc"; - -static const char *__doc_fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE = R"doc(All gate layouts are designed exhaustively.)doc"; - -static const char *__doc_fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM = R"doc(Gate layouts are designed randomly.)doc"; +static const char *__doc_fiction_design_sidb_gates_params_maximal_random_solutions = +R"doc(The number of gate implementations found before the random design +process is stopped.)doc"; static const char *__doc_fiction_design_sidb_gates_params_number_of_sidbs = R"doc(Number of SiDBs placed in the canvas to create a working gate.)doc"; @@ -3321,6 +3643,12 @@ computation.)doc"; static const char *__doc_fiction_design_sidb_gates_params_simulation_parameters = R"doc(All Parameters for physical SiDB simulations.)doc"; +static const char *__doc_fiction_design_sidb_gates_stats = R"doc(Statistics for the design of SiDB gates.)doc"; + +static const char *__doc_fiction_design_sidb_gates_stats_duration = R"doc(The total runtime of SiDB gate design process.)doc"; + +static const char *__doc_fiction_design_sidb_gates_stats_gate_cost = R"doc(The cost value of the final gate designed with Simulated Annealing.)doc"; + static const char *__doc_fiction_detail_a_star_impl = R"doc()doc"; static const char *__doc_fiction_detail_a_star_impl_a_star_impl = R"doc()doc"; @@ -3974,6 +4302,94 @@ Parameter ``bdl_iterator``: static const char *__doc_fiction_detail_critical_temperature_impl_stats = R"doc(Statistics.)doc"; +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl = R"doc()doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_contour_tracing = R"doc()doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_current_defect_position = R"doc(The current defect position.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_defect_influence_operational_domain_impl = R"doc()doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_defect_operational_domain = R"doc(The operational domain of the layout.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_determine_nw_se_cells = +R"doc(This function determines the northwest and southeast cells based on +the gate layout and the additional scan area specified.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_find_last_operational_defect_position_moving_right = +R"doc(This function identifies the most recent operational defect position +while traversing from left to right towards the SiDB gate. + +Parameter ``starting_defect_position``: + The starting position of the defect, from which the traversal + towards the right is conducted while maintaining gate operability. + +Returns: + The last operational defect position.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_find_operational_defect_position_at_left_side = +R"doc(This function aims to identify an operational defect position within +the layout. It does so by selecting a defect position with the +leftmost x-coordinate and a randomly selected y-coordinate limited the +layout's bounding box.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_grid_search = R"doc()doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_has_already_been_sampled = +R"doc(This function verifies whether the layout has already been analyzed +for the specified defect position `c`. + +Parameter ``c``: + Position of the defect.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_is_defect_position_operational = +R"doc(This function evaluates the operational status of the SiDB gate when a +defect is placed at position `c`. + +Parameter ``c``: + Position of the defect.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_layout = R"doc(The SiDB cell-level layout to investigate.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_log_stats = +R"doc(Helper function that writes the the statistics of the defect +operational domain computation to the statistics object.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_moore_neighborhood = +R"doc(Computes the Moore neighborhood of a given cell within the SiDB +layout. The Moore neighborhood consists of the eight cells surrounding +the central cell in horizontal, vertical, and diagonal directions. + +Parameter ``c``: + The cell for which the Moore neighborhood is computed. + +Returns: + A vector containing the cells in the Moore neighborhood that are + empty. If a cell is outside the layout boundaries or occupied, it + is not included in the result.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_num_evaluated_defect_positions = R"doc(Number of evaluated defect positions.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_num_simulator_invocations = R"doc(Number of simulator invocations.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_nw_bb_layout = R"doc(The north-west bounding box of the layout.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_nw_cell = R"doc(North-west cell.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_params = R"doc(The parameters for the operational domain computation.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_previous_defect_position = R"doc(The previous defect position.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_random_sampling = R"doc()doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_se_bb_layout = R"doc(The south-east bounding box of the layout.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_se_cell = R"doc(South-east cell.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_stats = R"doc(The statistics of the operational domain computation.)doc"; + +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_truth_table = R"doc(The specification of the layout.)doc"; + static const char *__doc_fiction_detail_delete_wires = R"doc(This function deletes wires from the provided `wiring_reduction_layout` based on the specified coordinates and @@ -4016,6 +4432,10 @@ Parameter ``cell_indices``: Returns: `true` if any SiDBs are too close; otherwise, `false`.)doc"; +static const char *__doc_fiction_detail_design_sidb_gates_impl_canvas_sidbs = R"doc(All SiDBs within the canvas.)doc"; + +static const char *__doc_fiction_detail_design_sidb_gates_impl_canvas_sidbs_before_move = R"doc(Canvas SiDBs before move.)doc"; + static const char *__doc_fiction_detail_design_sidb_gates_impl_design_sidb_gates_impl = R"doc(This constructor initializes an instance of the *SiDB Gate Designer* implementation with the provided skeleton layout and configuration @@ -4029,10 +4449,45 @@ Parameter ``tt``: truth table. Parameter ``ps``: - Parameters and settings for the gate designer.)doc"; + Parameters and settings for the gate designer. + +Parameter ``st``: + Statistics for the gate designer.)doc"; + +static const char *__doc_fiction_detail_design_sidb_gates_impl_determine_canvas_sidbs = +R"doc(This function iterates over each cell in the provided layout `lyt` and +checks if the cell corresponds to a canvas SiDB. Canvas SiDBs are +defined as SiDBs that are part of the canvas region. It populates a +vector with the canvas SiDBs found in the layout and returns it. + +Parameter ``lyt``: + The layout from which canvas SiDBs are to be determined. + +Returns: + A vector containing the canvas SiDBs found in the layout.)doc"; + +static const char *__doc_fiction_detail_design_sidb_gates_impl_generator = R"doc(A random-number generator.)doc"; + +static const char *__doc_fiction_detail_design_sidb_gates_impl_move_sidb = +R"doc(This function randomly selects a canvas cell from the layout `lyt` and +a canvas SiDB to replace it with. It then moves the selected canvas +SiDB to the randomly chosen canvas cell, updating the layout +accordingly. If the randomly chosen canvas cell is not empty, the +layout remains unchanged. + +Parameter ``lyt``: + The layout from which a canvas SiDB is to be moved. + +Returns: + The layout after the canvas SiDB has been moved, or the original + layout if the randomly chosen canvas cell was not empty.)doc"; static const char *__doc_fiction_detail_design_sidb_gates_impl_params = R"doc(Parameters for the *SiDB Gate Designer*.)doc"; +static const char *__doc_fiction_detail_design_sidb_gates_impl_random_canvas_cell_functor = R"doc()doc"; + +static const char *__doc_fiction_detail_design_sidb_gates_impl_random_canvas_sidb_functor = R"doc()doc"; + static const char *__doc_fiction_detail_design_sidb_gates_impl_run_exhaustive_design = R"doc(Design gates exhaustively and in parallel. @@ -4043,6 +4498,20 @@ parameters. The design process is parallelized to improve performance. Returns: A vector of designed SiDB gate layouts.)doc"; +static const char *__doc_fiction_detail_design_sidb_gates_impl_run_metric_driven_design_process = +R"doc(Design gates with Simulated Annealing. + +This function designs gates with Simulated Annealing. The cost +function involves the critical temperature and the operational domain. +The importance of the individual figures of merit can be adjusted by +the weights. + +Parameter ``sa_params``: + Simulated Annealing parameters. + +Returns: + Designed SiDB gate with minimal cost.)doc"; + static const char *__doc_fiction_detail_design_sidb_gates_impl_run_random_design = R"doc(Design gates randomly and in parallel. @@ -4053,6 +4522,10 @@ parameters. The design process is parallelized to improve performance. Returns: A vector of designed SiDB gate layouts.)doc"; +static const char *__doc_fiction_detail_design_sidb_gates_impl_sidb_moved_from_to = +R"doc(Canvas SiDB was moved from one cell (first cell) to another cell +(second cell).)doc"; + static const char *__doc_fiction_detail_design_sidb_gates_impl_skeleton_layout = R"doc(The skeleton layout serves as a starting layout to which SiDBs are added to create unique SiDB layouts and, if possible, working gates. @@ -4069,6 +4542,8 @@ Parameter ``cell_indices``: A copy of the original layout (`skeleton_layout`) with SiDB cells added at specified indices.)doc"; +static const char *__doc_fiction_detail_design_sidb_gates_impl_stats = R"doc(The statistics of the gate design.)doc"; + static const char *__doc_fiction_detail_design_sidb_gates_impl_truth_table = R"doc(Truth table of the given gate.)doc"; static const char *__doc_fiction_detail_determine_clocking_impl = R"doc()doc"; @@ -5691,6 +6166,8 @@ static const char *__doc_fiction_detail_maximum_defect_influence_position_and_di static const char *__doc_fiction_detail_maximum_defect_influence_position_and_distance_impl_run = R"doc()doc"; +static const char *__doc_fiction_detail_maximum_defect_influence_position_and_distance_impl_stats = R"doc(The statistics of the maximum defect influence position.)doc"; + static const char *__doc_fiction_detail_network_balancing_impl = R"doc()doc"; static const char *__doc_fiction_detail_network_balancing_impl_network_balancing_impl = R"doc()doc"; @@ -5722,6 +6199,9 @@ Parameter ``samples``: Maximum number of random samples to be taken before contour tracing. +Parameter ``initial_parameter``: + Optional initial point in the parameter space for contour tracing. + Returns: The (partial) operational domain of the layout.)doc"; @@ -5771,6 +6251,9 @@ one pixel wide border around the domain. Parameter ``samples``: Maximum number of random samples to be taken before flood fill. +Parameter ``initial_parameter``: + Optional initial point in the parameter space for flood fill. + Returns: The (partial) operational domain of the layout.)doc"; @@ -11439,21 +11922,6 @@ Template parameter ``Dist``: static const char *__doc_fiction_manhattan_distance_functor_manhattan_distance_functor = R"doc()doc"; -static const char *__doc_fiction_maximum_defect_influence_distance_params = -R"doc(This struct stores the parameters for the -maximum_defect_influence_position_and_distance algorithm.)doc"; - -static const char *__doc_fiction_maximum_defect_influence_distance_params_additional_scanning_area = -R"doc(The pair describes the width and height of the area around the gate, -which is also used to place defects. - -@note If SiQAD coordinates are used, the second entry describes the -number of dimer rows.)doc"; - -static const char *__doc_fiction_maximum_defect_influence_distance_params_defect = R"doc(The defect to calculate the maximum defect influence distance for.)doc"; - -static const char *__doc_fiction_maximum_defect_influence_distance_params_simulation_parameters = R"doc(Physical simulation parameters.)doc"; - static const char *__doc_fiction_maximum_defect_influence_position_and_distance = R"doc(Calculates the maximum distance at which a given defect can influence the layout's ground state. @@ -11468,16 +11936,80 @@ Parameter ``lyt``: The SiDB cell-level layout for which the influence distance is being determined. -Parameter ``params``: +Parameter ``sim_params``: Parameters used to calculate the defect's maximum influence distance. +Parameter ``pst``: + Statistics of the maximum defect influence distance. + Returns: Pair with the first element describing the position with maximum distance to the layout where a placed defect can still affect the ground state of the layout. The second entry describes the distance of the defect from the layout.)doc"; +static const char *__doc_fiction_maximum_defect_influence_position_and_distance_of_sidb_gate = +R"doc(This function calculates the maximum influence position and distance +of a defect on the ground state of an SiDB gate layout. It iterates +over all input combinations and finds the defect position at maximum +position that affects the gate's ground state. + +@Note The `defect influence distance` describes the distance at which +an defect influences the ground state. It does not check when the +successful operation starts to fail, since a change in the ground +state can still lead to an operational gate. + +Template parameter ``Lyt``: + Lyt SiDB cell-level layout type. + +Template parameter ``TT``: + Truth table type. + +Parameter ``lyt``: + Layout to compute the maximum defect influence position and + distance for. + +Parameter ``spec``: + Expected Boolean function of the layout given as a multi-output + truth table. + +Parameter ``params``: + Parameters for the defect influence simulation and BDL pair + detection. + +Returns: + A pair containing the maximum influence defect position and its + distance from the layout/gate.)doc"; + +static const char *__doc_fiction_maximum_defect_influence_position_and_distance_of_sidb_gate_params = +R"doc(Parameters for the +`maximum_defect_influence_position_and_distance_of_sidb_gate` +algorithm.)doc"; + +static const char *__doc_fiction_maximum_defect_influence_position_and_distance_of_sidb_gate_params_bdl_pairs_params = R"doc(Parameters for the detection of BDL pairs.)doc"; + +static const char *__doc_fiction_maximum_defect_influence_position_and_distance_of_sidb_gate_params_defect_influence_params = R"doc(Parameters for the defect influence simulation.)doc"; + +static const char *__doc_fiction_maximum_defect_influence_position_and_distance_params = +R"doc(This struct stores the parameters for the +maximum_defect_influence_position_and_distance algorithm.)doc"; + +static const char *__doc_fiction_maximum_defect_influence_position_and_distance_params_additional_scanning_area = +R"doc(The pair describes the width and height of the area around the gate, +which is also used to place defects. + +@note If SiQAD coordinates are used, the second entry describes the +number of dimer rows.)doc"; + +static const char *__doc_fiction_maximum_defect_influence_position_and_distance_params_defect = R"doc(The defect to calculate the maximum defect influence distance for.)doc"; + +static const char *__doc_fiction_maximum_defect_influence_position_and_distance_params_simulation_parameters = R"doc(Physical simulation parameters.)doc"; + +static const char *__doc_fiction_maximum_defect_influence_position_and_distance_stats = R"doc(Statistics for the maximum defect influence simulation.)doc"; + +static const char *__doc_fiction_maximum_defect_influence_position_and_distance_stats_duration = R"doc(The total runtime of the maximum defect influence simulation.)doc"; + static const char *__doc_fiction_minimum_energy = R"doc(Computes the minimum energy of a range of `charge_distribution_surface` objects. If the range is empty, infinity @@ -11660,6 +12192,29 @@ Parameter ``n``: Returns: Number of constant fanins to `n` in `ntk`.)doc"; +static const char *__doc_fiction_number_of_operational_input_combinations = +R"doc(This function calculates the count of input combinations for which the +SiDB-based logic, represented by the provided layout (`lyt`) and truth +table specifications (`spec`), produces the correct output. + +Template parameter ``Lyt``: + Type of the cell-level layout. + +Template parameter ``TT``: + Type of the truth table. + +Parameter ``lyt``: + The SiDB layout. + +Parameter ``spec``: + Vector of truth table specifications. + +Parameter ``params``: + Parameters to simualte if a input combination is operational. + +Returns: + The count of operational input combinations.)doc"; + static const char *__doc_fiction_obstruction_layout = R"doc()doc"; static const char *__doc_fiction_obstruction_layout_2 = R"doc()doc"; @@ -11972,6 +12527,9 @@ Parameter ``samples``: Parameter ``params``: Operational domain computation parameters. +Parameter ``initial_parameter_point``: + Optional initial point in the parameter space for contour tracing. + Parameter ``stats``: Operational domain computation statistics. @@ -12029,6 +12587,9 @@ Parameter ``samples``: Parameter ``params``: Operational domain computation parameters. +Parameter ``initial_parameter_point``: + Optional initial point in the parameter space for flood fill. + Parameter ``stats``: Operational domain computation statistics. @@ -12222,6 +12783,10 @@ static const char *__doc_fiction_operational_domain_stats_num_operational_parame static const char *__doc_fiction_operational_domain_stats_num_simulator_invocations = R"doc(Number of simulator invocations.)doc"; +static const char *__doc_fiction_operational_domain_stats_percentual_operational_area = +R"doc(The ratio of operational parameter pairs to all possible parameter +pairs. Value is between 0 and 1.)doc"; + static const char *__doc_fiction_operational_domain_sweep_parameter = R"doc(Possible sweep parameters for the operational domain computation.)doc"; static const char *__doc_fiction_operational_domain_sweep_parameter_EPSILON_R = R"doc(The relative permittivity of the dielectric material.)doc"; @@ -12494,15 +13059,18 @@ Template parameter ``Lyt``: static const char *__doc_fiction_population_stability_information_critical_cell = R"doc(SiDB cell which is closest to a charge transition.)doc"; -static const char *__doc_fiction_population_stability_information_distance_corresponding_to_potential = R"doc(Distance (unit: nm) corresponding to the minimum potential difference.)doc"; - -static const char *__doc_fiction_population_stability_information_minimum_potential_difference_to_transition = -R"doc(Absolute electrostatic potential (unit: V) required for the charge -state transition.)doc"; +static const char *__doc_fiction_population_stability_information_distance_corresponding_to_potential = +R"doc(This map collects for all charge transition types, the electrostatic +potential difference which is required to conduct a charge change as a +distance in nanometer. This is possible since the electrostatic +potential is connected to the distance.)doc"; static const char *__doc_fiction_population_stability_information_system_energy = R"doc(Total electrostatic energy (unit: eV) of given charge distribution.)doc"; -static const char *__doc_fiction_population_stability_information_transition_from_to = R"doc(Charge transition from the current charge state to the closest one.)doc"; +static const char *__doc_fiction_population_stability_information_transition_from_to_with_cell_and_required_pot = +R"doc(This map collects all charge transition types, the corresponding +critical cells and the required electrostatic potential required to +conduct the transition.)doc"; static const char *__doc_fiction_port_direction = R"doc(A port direction is a relative (cardinal) direction of a port within a @@ -14945,6 +15513,12 @@ static const char *__doc_fiction_technology_network_technology_network = R"doc() static const char *__doc_fiction_technology_network_technology_network_2 = R"doc()doc"; +static const char *__doc_fiction_temperature_schedule = R"doc(Available temperature schedule types.)doc"; + +static const char *__doc_fiction_temperature_schedule_GEOMETRIC = R"doc(Logarithmically decreasing temperature schedule.)doc"; + +static const char *__doc_fiction_temperature_schedule_LINEAR = R"doc(Linearly decreasing temperature schedule.)doc"; + static const char *__doc_fiction_tile_based_layout = R"doc(This class provides a tile-based naming scheme for coordinate-based functions. It does not add any functionality, but it might be useful @@ -15373,6 +15947,73 @@ static const char *__doc_fiction_wiring_reduction_stats_y_size_after = R"doc(Lay static const char *__doc_fiction_wiring_reduction_stats_y_size_before = R"doc(Layout height before the wiring reduction process.)doc"; +static const char *__doc_fiction_write_defect_influence_operational_domain = +R"doc(Writes a CSV representation of an operational domain to the specified +output stream. The data are written as rows, each corresponding to one +set of simulation parameters and their corresponding operational +status. + +The output CSV format is as follows: X_DIMENSION, Y_DIMENSION, +OPERATIONAL STATUS ... subsequent rows for each set of simulation +parameters. + +The operational status is a binary value represented by specified tags +in `params` indicating whether the simulation parameters are within +the operational domain or not. + +Parameter ``opdom``: + The operational domain to be written. It contains a mapping from + sets of simulation parameters (represented as a pair of sweep + parameters for the X and Y dimensions) to their operational + status. + +Parameter ``os``: + The output stream where the CSV representation of the operational + domain is written to. + +Parameter ``params``: + The parameters used for writing, including the operational and + non-operational tags. Defaults to an empty + `write_defect_operational_domain_params` object, which provides + standard tags.)doc"; + +static const char *__doc_fiction_write_defect_influence_operational_domain_2 = +R"doc(Writes a CSV representation of an operational domain to the specified +file. The data are written as rows, each corresponding to one set of +simulation parameters and their corresponding operational status. + +The output CSV format is as follows: X_DIMENSION, Y_DIMENSION, +OPERATIONAL STATUS ... subsequent rows for each set of simulation +parameters. + +The operational status is a binary value represented by specified tags +in `params` indicating whether the simulation parameters are within +the operational domain or not. + +Parameter ``opdom``: + The operational domain to be written. It contains a mapping from + sets of simulation parameters (represented as a pair of sweep + parameters for the X and Y dimensions) to their operational + status. + +Parameter ``filename``: + The filename where the CSV representation of the operational + domain is written to. + +Parameter ``params``: + The parameters used for writing, including the operational and + non-operational tags. Defaults to an empty + `write_defect_operational_domain_params` object, which provides + standard tags.)doc"; + +static const char *__doc_fiction_write_defect_operational_domain_params = R"doc(Parameters for writing an operational domain to a CSV file.)doc"; + +static const char *__doc_fiction_write_defect_operational_domain_params_non_operational_tag = +R"doc(The tag used to represent the non-operational value of a parameter +set.)doc"; + +static const char *__doc_fiction_write_defect_operational_domain_params_operational_tag = R"doc(The tag used to represent the operational value of a parameter set.)doc"; + static const char *__doc_fiction_write_dot_layout = R"doc(! Writes layout in DOT format into output stream From 4ea9a6922a888d577744aa7031fb8260dec7db5b Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 22 Jul 2024 16:29:51 +0200 Subject: [PATCH 098/221] :memo: fix docu issue. --- .../algorithms/physical_design/design_sidb_gates.hpp | 6 +++--- .../sidb/assess_physical_population_stability.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp index bc8cee2ae..91d3f0315 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp @@ -45,11 +45,11 @@ inline void design_sidb_gates(pybind11::module& m) * Design approach selector type. */ py::enum_(m, "design_sidb_gates_mode", - DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode)) + DOC(fiction_design_sidb_gates_mode)) .value("EXHAUSTIVE", fiction::design_sidb_gates_mode::EXHAUSTIVE, - DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE)) + DOC(fiction_design_sidb_gates_mode_EXHAUSTIVE)) .value("RANDOM", fiction::design_sidb_gates_mode::RANDOM, - DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM)); + DOC(fiction_design_sidb_gates_mode_RANDOM)); /** * Parameters. */ diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index fa4841ba2..3a031ffbf 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -33,7 +33,7 @@ void assess_physical_population_stability(pybind11::module& m, const std::string DOC(fiction_population_stability_information_critical_cell)) .def_readwrite("transition_from_to_with_cell_and_required_pot", &fiction::population_stability_information::transition_from_to_with_cell_and_required_pot, - DOC(fiction_population_stability_information_transition_from_to)) + DOC(fiction_population_stability_information_transition_from_to_with_cell_and_required_pot)) .def_readwrite("distance_corresponding_to_potential", &fiction::population_stability_information::distance_corresponding_to_potential, DOC(fiction_population_stability_information_distance_corresponding_to_potential)) From bc9bec69884bf326d7ad1b4a37269d86c783d2e5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:30:11 +0000 Subject: [PATCH 099/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../algorithms/physical_design/design_sidb_gates.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp index 91d3f0315..576daf639 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp @@ -44,12 +44,10 @@ inline void design_sidb_gates(pybind11::module& m) /** * Design approach selector type. */ - py::enum_(m, "design_sidb_gates_mode", - DOC(fiction_design_sidb_gates_mode)) + py::enum_(m, "design_sidb_gates_mode", DOC(fiction_design_sidb_gates_mode)) .value("EXHAUSTIVE", fiction::design_sidb_gates_mode::EXHAUSTIVE, DOC(fiction_design_sidb_gates_mode_EXHAUSTIVE)) - .value("RANDOM", fiction::design_sidb_gates_mode::RANDOM, - DOC(fiction_design_sidb_gates_mode_RANDOM)); + .value("RANDOM", fiction::design_sidb_gates_mode::RANDOM, DOC(fiction_design_sidb_gates_mode_RANDOM)); /** * Parameters. */ From f3745d9049c69bf87a818861a2da089936db75b0 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 25 Jul 2024 14:35:22 +0200 Subject: [PATCH 100/221] :art: update code after merge. --- .../assess_physical_population_stability.hpp | 27 ++----------- ...ne_groundstate_from_simulation_results.hpp | 3 +- ...cupation_probability_of_excited_states.hpp | 4 +- ...st_assess_physical_population_stability.py | 15 ++++---- .../physical_design/design_sidb_gates.hpp | 10 ++--- .../assess_physical_population_stability.hpp | 30 ++++++++------- .../simulation/sidb/operational_domain.hpp | 38 ++++++++++--------- .../simulation/sidb/operational_domain.cpp | 8 ++-- 8 files changed, 60 insertions(+), 75 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index d029c98e2..3a031ffbf 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -20,7 +20,7 @@ namespace detail { template -void assess_physical_population_stability(pybind11::module& m) +void assess_physical_population_stability(pybind11::module& m, const std::string& lattice = "") { namespace py = pybind11; using namespace pybind11::literals; @@ -62,27 +62,6 @@ inline void assess_physical_population_stability(pybind11::module& m) .value("POSITIVE_TO_NEUTRAL", fiction::transition_type::POSITIVE_TO_NEUTRAL, DOC(fiction_transition_type_POSITIVE_TO_NEUTRAL)); - py::class_>( - m, "population_stability_information", DOC(fiction_population_stability_information)) - .def(py::init<>()) - .def_readwrite("critical_cell", - &fiction::population_stability_information::critical_cell, - DOC(fiction_population_stability_information_critical_cell)) - .def_readwrite("transition_from_to", - &fiction::population_stability_information::transition_from_to, - DOC(fiction_population_stability_information_transition_from_to)) - .def_readwrite("minimum_potential_difference_to_transition", - &fiction::population_stability_information< - fiction::offset::ucoord_t>::minimum_potential_difference_to_transition, - DOC(fiction_population_stability_information_minimum_potential_difference_to_transition)) - .def_readwrite( - "distance_corresponding_to_potential", - &fiction::population_stability_information::distance_corresponding_to_potential, - DOC(fiction_population_stability_information_distance_corresponding_to_potential)) - .def_readwrite("system_energy", - &fiction::population_stability_information::system_energy, - DOC(fiction_population_stability_information_system_energy)); - /** * Parameters. */ @@ -99,8 +78,8 @@ inline void assess_physical_population_stability(pybind11::module& m) // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! - detail::assess_physical_population_stability(m); - detail::assess_physical_population_stability(m); + detail::assess_physical_population_stability(m, "_100"); + detail::assess_physical_population_stability(m, "_111"); } } // namespace pyfiction diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp index 45c407312..ec36e06db 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp @@ -24,8 +24,9 @@ void determine_groundstate_from_simulation_results(pybind11::module& m) { using namespace pybind11::literals; + // TODO add Docu m.def("determine_groundstate_from_simulation_results", &fiction::determine_groundstate_from_simulation_results, - "simulation_results"_a, DOC(fiction_determine_groundstate_from_simulation_results)); + "simulation_results"_a); } } // namespace detail diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp index adbbe2b8f..605a237ed 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp @@ -27,8 +27,8 @@ void occupation_probability_of_excited_states(pybind11::module& m) "temperature"_a, DOC(fiction_occupation_probability_gate_based)); m.def("occupation_probability_non_gate_based", &fiction::occupation_probability_non_gate_based, - "energy_distribution"_a, - "temperature"_a); // TODO DOC(fiction_occupation_probability_non_gate_based) + "energy_distribution"_a, "temperature"_a); + // TODO DOC(fiction_occupation_probability_non_gate_based) } } // namespace detail diff --git a/bindings/pyfiction/test/algorithms/simulation/sidb/test_assess_physical_population_stability.py b/bindings/pyfiction/test/algorithms/simulation/sidb/test_assess_physical_population_stability.py index eb5d9d6be..f83bfa9a8 100644 --- a/bindings/pyfiction/test/algorithms/simulation/sidb/test_assess_physical_population_stability.py +++ b/bindings/pyfiction/test/algorithms/simulation/sidb/test_assess_physical_population_stability.py @@ -1,6 +1,6 @@ -import unittest - from mnt.pyfiction import * +import unittest +import os class TestAssessPhysicalPopulationStability(unittest.TestCase): @@ -12,13 +12,14 @@ def test_three_DBs_100_lattice(self): layout.assign_cell_type((1, 1), sidb_technology.cell_type.NORMAL) params = assess_physical_population_stability_params() params.simulation_parameters.mu_minus = -0.25 - result = assess_physical_population_stability(layout, params) + cds = charge_distribution_surface_100(layout) + result = assess_physical_population_stability_100(layout, params) self.assertEqual(len(result), 5) self.assertLessEqual(result[0].system_energy, result[1].system_energy) self.assertLessEqual(result[1].system_energy, result[2].system_energy) params.simulation_parameters.mu_minus = -0.32 - result = assess_physical_population_stability(layout, params) + result = assess_physical_population_stability_100(cds, params) self.assertEqual(len(result), 1) def test_three_DBs_111_lattice(self): @@ -28,15 +29,15 @@ def test_three_DBs_111_lattice(self): layout.assign_cell_type((1, 1), sidb_technology.cell_type.NORMAL) params = assess_physical_population_stability_params() params.simulation_parameters.mu_minus = -0.25 - result = assess_physical_population_stability(layout, params) + cds = charge_distribution_surface_111(layout) + result = assess_physical_population_stability_111(layout, params) self.assertEqual(len(result), 5) self.assertLessEqual(result[0].system_energy, result[1].system_energy) self.assertLessEqual(result[1].system_energy, result[2].system_energy) params.simulation_parameters.mu_minus = -0.32 - result = assess_physical_population_stability(layout, params) + result = assess_physical_population_stability_111(cds, params) self.assertEqual(len(result), 2) - if __name__ == '__main__': unittest.main() diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index af1839168..a3d3cbcfb 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -325,11 +325,11 @@ class design_sidb_gates_impl if (sa_params.weight_operational_domain != 0.0) { operational_domain_stats stats_op{}; - const auto op_domain = operational_domain_flood_fill( - lyt, truth_table, 0, sa_params.op_params, - operational_domain::parameter_point{params.simulation_parameters.epsilon_r, - params.simulation_parameters.lambda_tf}, - &stats_op); + const auto op_domain = + operational_domain_flood_fill(lyt, truth_table, 0, sa_params.op_params, + parameter_point{params.simulation_parameters.epsilon_r, + params.simulation_parameters.lambda_tf}, + &stats_op); opo_cost = stats_op.percentual_operational_area; } } diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index c9bfe7e32..7f97dfa49 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -57,15 +57,15 @@ enum class transition_type * transition, the corresponding distance, and the total electrostatic energy of the * given charge distribution. * - * @tparam CellType Type of the used cells. + * @tparam Lyt SiDB cell-level layout type. */ -template +template struct population_stability_information { /** * SiDB cell which is closest to a charge transition. */ - CellType critical_cell{}; + typename Lyt::cell critical_cell{}; /** * This map collects all charge transition types, the corresponding critical cells and the required * electrostatic potential required to conduct the transition. @@ -128,13 +128,13 @@ class assess_physical_population_stability_impl * distribution in ascending energy order. Each structure contains details about the critical SiDB, the type of * charge state transition, and the minimum electrostatic potential required for the charge transition. */ - [[nodiscard]] std::vector>> run() noexcept + [[nodiscard]] std::vector> run() noexcept { const quickexact_params> quickexact_parameters{params.simulation_parameters}; const auto simulation_results = quickexact(layout, quickexact_parameters); const auto energy_and_unique_charge_index = collect_energy_and_charge_index(simulation_results); - std::vector>> popstability_information{}; + std::vector> popstability_information{}; popstability_information.reserve(simulation_results.charge_distributions.size()); // Access the unique indices @@ -251,9 +251,9 @@ class assess_physical_population_stability_impl * * @return An updated population stability information with potential transition details. */ - [[nodiscard]] population_stability_information> + [[nodiscard]] population_stability_information handle_negative_charges(const double local_potential, const typename Lyt::cell& c, - const population_stability_information>& pop_stability_information) noexcept + const population_stability_information& pop_stability_information) noexcept { auto updated_pop_stability_information = pop_stability_information; @@ -284,9 +284,9 @@ class assess_physical_population_stability_impl * * @return An updated population stability information with potential transition details. */ - [[nodiscard]] population_stability_information> + [[nodiscard]] population_stability_information handle_neutral_charges(const double local_potential, const typename Lyt::cell& c, - const population_stability_information>& pop_stability_information) noexcept + const population_stability_information& pop_stability_information) noexcept { auto updated_pop_stability_information = pop_stability_information; @@ -334,9 +334,9 @@ class assess_physical_population_stability_impl * * @return An updated population stability information with potential transition details. */ - [[nodiscard]] population_stability_information> + [[nodiscard]] population_stability_information handle_positive_charges(const double local_potential, const typename Lyt::cell& c, - const population_stability_information>& pop_stability_information) noexcept + const population_stability_information& pop_stability_information) noexcept { auto updated_pop_stability_information = pop_stability_information; @@ -373,8 +373,10 @@ class assess_physical_population_stability_impl std::transform( sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), - std::back_inserter(energy_charge_index), [](const auto& ch_lyt) - { return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; }); + std::back_inserter(energy_charge_index), []( + onst auto& ch_lyt) + t + rn energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; }); // Sort the vector in ascending order of the energy value std::sort(energy_charge_index.begin(), energy_charge_index.end(), @@ -398,7 +400,7 @@ class assess_physical_population_stability_impl * layout. */ template -[[nodiscard]] std::vector>> +[[nodiscard]] std::vector> assess_physical_population_stability(const Lyt& lyt, const assess_physical_population_stability_params& params) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index 76442a63f..07a24003a 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -434,7 +434,9 @@ class operational_domain_impl { // for each y value in parallel std::for_each(FICTION_EXECUTION_POLICY_PAR_UNSEQ y_indices.cbegin(), y_indices.cend(), - [this, x](const auto y) { is_step_point_operational({x, y}); }); + [this, x](const auto y) { + is_step_point_operational({x, y}); + }); }); log_stats(); @@ -474,9 +476,8 @@ class operational_domain_impl * @param initial_parameter Optional initial point in the parameter space for flood fill. * @return The (partial) operational domain of the layout. */ - [[nodiscard]] operational_domain - flood_fill(const std::size_t samples, - const std::optional& initial_parameter) noexcept + [[nodiscard]] operational_domain + flood_fill(const std::size_t samples, const std::optional& initial_parameter) noexcept { mockturtle::stopwatch stop{stats.time_total}; @@ -558,9 +559,8 @@ class operational_domain_impl * @param initial_parameter Optional initial point in the parameter space for contour tracing. * @return The (partial) operational domain of the layout. */ - [[nodiscard]] operational_domain - contour_tracing(const std::size_t samples, - const std::optional& initial_parameter_point) noexcept + [[nodiscard]] operational_domain + contour_tracing(const std::size_t samples, const std::optional& initial_parameter_point) noexcept { mockturtle::stopwatch stop{stats.time_total}; @@ -664,7 +664,9 @@ class operational_domain_impl [this, &lyt](const auto x) { std::for_each(y_indices.cbegin(), y_indices.cend(), - [this, &lyt, x](const auto y) { is_step_point_suitable(lyt, {x, y}); }); + [this, &lyt, x](const auto y) { + is_step_point_suitable(lyt, {x, y}); + }); }); sidb_simulation_parameters simulation_parameters = params.simulation_parameters; @@ -1383,11 +1385,11 @@ operational_domain_random_sampling(const Lyt& lyt, const std::vector& spec, * @return The (partial) operational domain of the layout. */ template -operational_domain operational_domain_flood_fill( - const Lyt& lyt, const std::vector& spec, const std::size_t samples, - const operational_domain_params& params = {}, - const std::optional& initial_parameter_point = std::nullopt, - operational_domain_stats* stats = nullptr) +operational_domain +operational_domain_flood_fill(const Lyt& lyt, const std::vector& spec, const std::size_t samples, + const operational_domain_params& params = {}, + const std::optional& initial_parameter_point = std::nullopt, + operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -1441,11 +1443,11 @@ operational_domain operational_domain_flood_fill( * @return The (partial) operational domain of the layout. */ template -operational_domain operational_domain_contour_tracing( - const Lyt& lyt, const std::vector& spec, const std::size_t samples, - const operational_domain_params& params = {}, - const std::optional& initial_parameter_point = std::nullopt, - operational_domain_stats* stats = nullptr) +operational_domain +operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, const std::size_t samples, + const operational_domain_params& params = {}, + const std::optional& initial_parameter_point = std::nullopt, + operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); diff --git a/test/algorithms/simulation/sidb/operational_domain.cpp b/test/algorithms/simulation/sidb/operational_domain.cpp index 9969b0d51..c1397441b 100644 --- a/test/algorithms/simulation/sidb/operational_domain.cpp +++ b/test/algorithms/simulation/sidb/operational_domain.cpp @@ -603,7 +603,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation", "[operational-domai { const auto op_domain = operational_domain_flood_fill( lat, std::vector{create_and_tt()}, 1, op_domain_params, - operational_domain::parameter_point{op_domain_params.simulation_parameters.epsilon_r, + parameter_point{op_domain_params.simulation_parameters.epsilon_r, op_domain_params.simulation_parameters.lambda_tf}, &op_domain_stats); @@ -729,7 +729,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat { const auto op_domain = operational_domain_flood_fill( lat, std::vector{create_and_tt()}, 1, op_domain_params, - operational_domain::parameter_point{op_domain_params.simulation_parameters.epsilon_r, + parameter_point{op_domain_params.simulation_parameters.epsilon_r, op_domain_params.simulation_parameters.lambda_tf}, &op_domain_stats); @@ -749,7 +749,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat { const auto op_domain = operational_domain_contour_tracing( lat, std::vector{create_and_tt()}, 1, op_domain_params, - operational_domain::parameter_point{op_domain_params.simulation_parameters.epsilon_r, + parameter_point{op_domain_params.simulation_parameters.epsilon_r, op_domain_params.simulation_parameters.lambda_tf}, &op_domain_stats); @@ -827,7 +827,7 @@ TEMPLATE_TEST_CASE("AND gate on the H-Si(111)-1x1 surface", "[operational-domain { const auto op_domain = operational_domain_flood_fill( layout, std::vector{create_and_tt()}, 1, op_domain_params, - operational_domain::parameter_point{op_domain_params.simulation_parameters.epsilon_r, + parameter_point{op_domain_params.simulation_parameters.epsilon_r, op_domain_params.simulation_parameters.lambda_tf}, &op_domain_stats); From f24b9606cee29adf82768b432317b6786853e258 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:35:42 +0000 Subject: [PATCH 101/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assess_physical_population_stability.hpp | 14 ++++--- .../simulation/sidb/operational_domain.hpp | 8 +--- .../simulation/sidb/operational_domain.cpp | 40 +++++++++---------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 7f97dfa49..4a35a0367 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -376,14 +376,16 @@ class assess_physical_population_stability_impl std::back_inserter(energy_charge_index), []( onst auto& ch_lyt) t - rn energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; }); + rn energy_and_charge_index{ + ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; + }); - // Sort the vector in ascending order of the energy value - std::sort(energy_charge_index.begin(), energy_charge_index.end(), - [](const auto& lhs, const auto& rhs) { return lhs.energy < rhs.energy; }); + // Sort the vector in ascending order of the energy value + std::sort(energy_charge_index.begin(), energy_charge_index.end(), + [](const auto& lhs, const auto& rhs) { return lhs.energy < rhs.energy; }); - return energy_charge_index; - } + return energy_charge_index; +} }; } // namespace detail diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index 07a24003a..21dab4db8 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -434,9 +434,7 @@ class operational_domain_impl { // for each y value in parallel std::for_each(FICTION_EXECUTION_POLICY_PAR_UNSEQ y_indices.cbegin(), y_indices.cend(), - [this, x](const auto y) { - is_step_point_operational({x, y}); - }); + [this, x](const auto y) { is_step_point_operational({x, y}); }); }); log_stats(); @@ -664,9 +662,7 @@ class operational_domain_impl [this, &lyt](const auto x) { std::for_each(y_indices.cbegin(), y_indices.cend(), - [this, &lyt, x](const auto y) { - is_step_point_suitable(lyt, {x, y}); - }); + [this, &lyt, x](const auto y) { is_step_point_suitable(lyt, {x, y}); }); }); sidb_simulation_parameters simulation_parameters = params.simulation_parameters; diff --git a/test/algorithms/simulation/sidb/operational_domain.cpp b/test/algorithms/simulation/sidb/operational_domain.cpp index c1397441b..a40470320 100644 --- a/test/algorithms/simulation/sidb/operational_domain.cpp +++ b/test/algorithms/simulation/sidb/operational_domain.cpp @@ -601,11 +601,11 @@ TEST_CASE("SiQAD's AND gate operational domain computation", "[operational-domai } SECTION("flood_fill") { - const auto op_domain = operational_domain_flood_fill( - lat, std::vector{create_and_tt()}, 1, op_domain_params, - parameter_point{op_domain_params.simulation_parameters.epsilon_r, - op_domain_params.simulation_parameters.lambda_tf}, - &op_domain_stats); + const auto op_domain = + operational_domain_flood_fill(lat, std::vector{create_and_tt()}, 1, op_domain_params, + parameter_point{op_domain_params.simulation_parameters.epsilon_r, + op_domain_params.simulation_parameters.lambda_tf}, + &op_domain_stats); // check if the operational domain has the correct size (10 steps in each dimension) CHECK(op_domain.operational_values.size() == 100); @@ -727,11 +727,11 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat } SECTION("flood_fill") { - const auto op_domain = operational_domain_flood_fill( - lat, std::vector{create_and_tt()}, 1, op_domain_params, - parameter_point{op_domain_params.simulation_parameters.epsilon_r, - op_domain_params.simulation_parameters.lambda_tf}, - &op_domain_stats); + const auto op_domain = + operational_domain_flood_fill(lat, std::vector{create_and_tt()}, 1, op_domain_params, + parameter_point{op_domain_params.simulation_parameters.epsilon_r, + op_domain_params.simulation_parameters.lambda_tf}, + &op_domain_stats); // check if the operational domain has the correct size (10 steps in each dimension) CHECK(op_domain.operational_values.size() == 100); @@ -747,11 +747,11 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat } SECTION("contour_tracing") { - const auto op_domain = operational_domain_contour_tracing( - lat, std::vector{create_and_tt()}, 1, op_domain_params, - parameter_point{op_domain_params.simulation_parameters.epsilon_r, - op_domain_params.simulation_parameters.lambda_tf}, - &op_domain_stats); + const auto op_domain = + operational_domain_contour_tracing(lat, std::vector{create_and_tt()}, 1, op_domain_params, + parameter_point{op_domain_params.simulation_parameters.epsilon_r, + op_domain_params.simulation_parameters.lambda_tf}, + &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 100); @@ -825,11 +825,11 @@ TEMPLATE_TEST_CASE("AND gate on the H-Si(111)-1x1 surface", "[operational-domain } SECTION("flood_fill") { - const auto op_domain = operational_domain_flood_fill( - layout, std::vector{create_and_tt()}, 1, op_domain_params, - parameter_point{op_domain_params.simulation_parameters.epsilon_r, - op_domain_params.simulation_parameters.lambda_tf}, - &op_domain_stats); + const auto op_domain = + operational_domain_flood_fill(layout, std::vector{create_and_tt()}, 1, op_domain_params, + parameter_point{op_domain_params.simulation_parameters.epsilon_r, + op_domain_params.simulation_parameters.lambda_tf}, + &op_domain_stats); // check if the operational domain has the correct size (10 steps in each dimension) CHECK(op_domain.operational_values.size() == 4); From f16c4dc359e0fa8021f09f5f77da8460c9f93519 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 25 Jul 2024 12:36:46 +0000 Subject: [PATCH 102/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/pybind11_mkdoc_docstrings.hpp | 54 ++++++++----------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index 717aa423d..b28ce397a 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -23,6 +23,27 @@ #endif +static const char *__doc_assess_physical_population_stability = +R"doc(This function assesses the population stability of each physically +valid charge distributions of a given SiDB layout. It determines the +minimum absolute electrostatic potential required to induce a charge +distribution transition. The function also identifies the SiDB for +which this is the case (critical SiDB) and the corresponding charge +state transition (i.e., the change from one charge state to another). + +Template parameter ``Lyt``: + SiDB cell-level layout type. + +Parameter ``lyt``: + The layout for which the population stability is assessed. + +Parameter ``params``: + Parameters used to assess the population stability. + +Returns: + A vector of population stability information for all physically + valid charge distributions of the given SiDB layout.)doc"; + static const char *__doc_fiction_a_star = R"doc(The A* path finding algorithm for shortest loop-less paths between a given source and target coordinate in a layout. This function @@ -409,27 +430,6 @@ static const char *__doc_fiction_aspect_ratio_iterator_operator_ne = R"doc()doc" static const char *__doc_fiction_aspect_ratio_iterator_operator_ne_2 = R"doc()doc"; -static const char *__doc_fiction_assess_physical_population_stability = -R"doc(This function assesses the population stability of each physically -valid charge distributions of a given SiDB layout. It determines the -minimum absolute electrostatic potential required to induce a charge -distribution transition. The function also identifies the SiDB for -which this is the case (critical SiDB) and the corresponding charge -state transition (i.e., the change from one charge state to another). - -Template parameter ``Lyt``: - SiDB cell-level layout type. - -Parameter ``lyt``: - The layout for which the population stability is assessed. - -Parameter ``params``: - Parameters used to assess the population stability. - -Returns: - A vector of population stability information for all physically - valid charge distributions of the given SiDB layout.)doc"; - static const char *__doc_fiction_assess_physical_population_stability_params = R"doc(This struct stores the parameters required to assess the population stability.)doc"; @@ -12882,14 +12882,6 @@ static const char *__doc_fiction_operational_domain_stats_percentual_operational R"doc(The ratio of operational parameter pairs to all possible parameter pairs. Value is between 0 and 1.)doc"; -static const char *__doc_fiction_operational_domain_sweep_parameter = R"doc(Possible sweep parameters for the operational domain computation.)doc"; - -static const char *__doc_fiction_operational_domain_sweep_parameter_EPSILON_R = R"doc(The relative permittivity of the dielectric material.)doc"; - -static const char *__doc_fiction_operational_domain_sweep_parameter_LAMBDA_TF = R"doc(The Thomas-Fermi screening length.)doc"; - -static const char *__doc_fiction_operational_domain_sweep_parameter_MU_MINUS = R"doc(The energy transition level.)doc"; - static const char *__doc_fiction_operational_domain_x_dimension = R"doc(X dimension sweep parameter.)doc"; static const char *__doc_fiction_operational_domain_y_dimension = R"doc(Y dimension sweep parameter.)doc"; @@ -13197,8 +13189,8 @@ state transition, the electrostatic potential difference required for the transition, the corresponding distance, and the total electrostatic energy of the given charge distribution. -Template parameter ``CellType``: - Type of the used cells.)doc"; +Template parameter ``Lyt``: + SiDB cell-level layout type.)doc"; static const char *__doc_fiction_population_stability_information_critical_cell = R"doc(SiDB cell which is closest to a charge transition.)doc"; From beca579bfb2061e4088ac0766ffcdfb2ff1861ac Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 25 Jul 2024 14:47:42 +0200 Subject: [PATCH 103/221] :art: update code after merge. --- .../assess_physical_population_stability.hpp | 4 ++-- ...ne_groundstate_from_simulation_results.hpp | 3 +-- ...cupation_probability_of_excited_states.hpp | 1 - docs/algorithms/sidb_simulation.rst | 14 ++++++----- .../assess_physical_population_stability.hpp | 24 +++++++++---------- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 3a031ffbf..740cd9f67 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -40,10 +40,10 @@ void assess_physical_population_stability(pybind11::module& m, const std::string .def_readwrite("system_energy", &fiction::population_stability_information::system_energy, DOC(fiction_population_stability_information_system_energy)); + // TODO add docu. m.def(fmt::format("assess_physical_population_stability{}", lattice).c_str(), &fiction::assess_physical_population_stability, "lyt"_a, - "params"_a = fiction::assess_physical_population_stability_params{}, - DOC(fiction_assess_physical_population_stability)); + "params"_a = fiction::assess_physical_population_stability_params{}); } } // namespace detail diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp index ec36e06db..45c407312 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp @@ -24,9 +24,8 @@ void determine_groundstate_from_simulation_results(pybind11::module& m) { using namespace pybind11::literals; - // TODO add Docu m.def("determine_groundstate_from_simulation_results", &fiction::determine_groundstate_from_simulation_results, - "simulation_results"_a); + "simulation_results"_a, DOC(fiction_determine_groundstate_from_simulation_results)); } } // namespace detail diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp index 605a237ed..5420282d9 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp @@ -28,7 +28,6 @@ void occupation_probability_of_excited_states(pybind11::module& m) m.def("occupation_probability_non_gate_based", &fiction::occupation_probability_non_gate_based, "energy_distribution"_a, "temperature"_a); - // TODO DOC(fiction_occupation_probability_non_gate_based) } } // namespace detail diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 92211ad10..36a27fc17 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -388,12 +388,6 @@ Assess Population Stability :members: .. doxygenfunction:: fiction::assess_physical_population_stability - **Header:** ``fiction/algorithms/simulation/sidb/calculate_min_bbr.hpp`` - - .. doxygenstruct:: fiction::calculate_min_bbr_for_all_inputs_params - :members: - .. doxygenfunction:: fiction::calculate_min_bbr_for_all_inputs - .. tab:: Python .. autoclass:: mnt.pyfiction.transition_type @@ -404,6 +398,14 @@ Assess Population Stability :members: .. autofunction:: mnt.pyfiction.assess_physical_population_stability + + **Header:** ``fiction/algorithms/simulation/sidb/calculate_min_bbr.hpp`` + + .. doxygenstruct:: fiction::calculate_min_bbr_for_all_inputs_params + :members: + .. doxygenfunction:: fiction::calculate_min_bbr_for_all_inputs + + Convert Potential to Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 4a35a0367..a6a743ee3 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -373,19 +373,17 @@ class assess_physical_population_stability_impl std::transform( sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), - std::back_inserter(energy_charge_index), []( - onst auto& ch_lyt) - t - rn energy_and_charge_index{ - ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; - }); - - // Sort the vector in ascending order of the energy value - std::sort(energy_charge_index.begin(), energy_charge_index.end(), - [](const auto& lhs, const auto& rhs) { return lhs.energy < rhs.energy; }); - - return energy_charge_index; -} + std::back_inserter(energy_charge_index), + [](const auto& ch_lyt) { + return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; + }); + + // Sort the vector in ascending order of the energy value + std::sort(energy_charge_index.begin(), energy_charge_index.end(), + [](const auto& lhs, const auto& rhs) { return lhs.energy < rhs.energy; }); + + return energy_charge_index; + } }; } // namespace detail From 80b498c0879b505cc71204dfe15bcf5431e99ddd Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 25 Jul 2024 12:48:47 +0000 Subject: [PATCH 104/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/pybind11_mkdoc_docstrings.hpp | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index b28ce397a..f7706b3f9 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -23,27 +23,6 @@ #endif -static const char *__doc_assess_physical_population_stability = -R"doc(This function assesses the population stability of each physically -valid charge distributions of a given SiDB layout. It determines the -minimum absolute electrostatic potential required to induce a charge -distribution transition. The function also identifies the SiDB for -which this is the case (critical SiDB) and the corresponding charge -state transition (i.e., the change from one charge state to another). - -Template parameter ``Lyt``: - SiDB cell-level layout type. - -Parameter ``lyt``: - The layout for which the population stability is assessed. - -Parameter ``params``: - Parameters used to assess the population stability. - -Returns: - A vector of population stability information for all physically - valid charge distributions of the given SiDB layout.)doc"; - static const char *__doc_fiction_a_star = R"doc(The A* path finding algorithm for shortest loop-less paths between a given source and target coordinate in a layout. This function @@ -430,6 +409,27 @@ static const char *__doc_fiction_aspect_ratio_iterator_operator_ne = R"doc()doc" static const char *__doc_fiction_aspect_ratio_iterator_operator_ne_2 = R"doc()doc"; +static const char *__doc_fiction_assess_physical_population_stability = +R"doc(This function assesses the population stability of each physically +valid charge distributions of a given SiDB layout. It determines the +minimum absolute electrostatic potential required to induce a charge +distribution transition. The function also identifies the SiDB for +which this is the case (critical SiDB) and the corresponding charge +state transition (i.e., the change from one charge state to another). + +Template parameter ``Lyt``: + SiDB cell-level layout type. + +Parameter ``lyt``: + The layout for which the population stability is assessed. + +Parameter ``params``: + Parameters used to assess the population stability. + +Returns: + A vector of population stability information for all physically + valid charge distributions of the given SiDB layout.)doc"; + static const char *__doc_fiction_assess_physical_population_stability_params = R"doc(This struct stores the parameters required to assess the population stability.)doc"; From d4675836eee3dd10195df14cbd020ef4984287e1 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 25 Jul 2024 14:55:12 +0200 Subject: [PATCH 105/221] :memo: fix docu. --- .../simulation/sidb/assess_physical_population_stability.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 740cd9f67..6bce1f2c2 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -43,7 +43,8 @@ void assess_physical_population_stability(pybind11::module& m, const std::string // TODO add docu. m.def(fmt::format("assess_physical_population_stability{}", lattice).c_str(), &fiction::assess_physical_population_stability, "lyt"_a, - "params"_a = fiction::assess_physical_population_stability_params{}); + "params"_a = fiction::assess_physical_population_stability_params{}, + DOC(fiction_assess_physical_population_stability)); } } // namespace detail From cdbb8d0cd3ff02a27da79f93d47864185f70d592 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:55:31 +0000 Subject: [PATCH 106/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sidb/assess_physical_population_stability.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index a6a743ee3..26be6f3ce 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -373,10 +373,8 @@ class assess_physical_population_stability_impl std::transform( sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), - std::back_inserter(energy_charge_index), - [](const auto& ch_lyt) { - return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; - }); + std::back_inserter(energy_charge_index), [](const auto& ch_lyt) + { return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; }); // Sort the vector in ascending order of the energy value std::sort(energy_charge_index.begin(), energy_charge_index.end(), From 351e3dbbceee494f9952d58a6623bf29e2158f8d Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 25 Jul 2024 15:03:23 +0200 Subject: [PATCH 107/221] :art: update the experiment script. --- experiments/figure_of_merit_analysis/fom_analysis.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/figure_of_merit_analysis/fom_analysis.cpp b/experiments/figure_of_merit_analysis/fom_analysis.cpp index 81c525313..60244c53c 100644 --- a/experiments/figure_of_merit_analysis/fom_analysis.cpp +++ b/experiments/figure_of_merit_analysis/fom_analysis.cpp @@ -122,7 +122,7 @@ int main() // NOLINT temps.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); operational_domain_stats op_stats{}; const auto op_domain = operational_domain_flood_fill( - gate, truth_table, 0, op_domain_params, operational_domain::parameter_point{5.6, 5}, &op_stats); + gate, truth_table, 0, op_domain_params, parameter_point{5.6, 5}, &op_stats); op_domains.push_back(op_stats.percentual_operational_area); defect_influence_operational_domain_stats arsenic_stats{}; From 4cb70cae9e9908c5f1f4ed7d069fca032ddb039e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:04:00 +0000 Subject: [PATCH 108/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- experiments/figure_of_merit_analysis/fom_analysis.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experiments/figure_of_merit_analysis/fom_analysis.cpp b/experiments/figure_of_merit_analysis/fom_analysis.cpp index 60244c53c..943322b50 100644 --- a/experiments/figure_of_merit_analysis/fom_analysis.cpp +++ b/experiments/figure_of_merit_analysis/fom_analysis.cpp @@ -121,8 +121,8 @@ int main() // NOLINT { temps.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); operational_domain_stats op_stats{}; - const auto op_domain = operational_domain_flood_fill( - gate, truth_table, 0, op_domain_params, parameter_point{5.6, 5}, &op_stats); + const auto op_domain = operational_domain_flood_fill(gate, truth_table, 0, op_domain_params, + parameter_point{5.6, 5}, &op_stats); op_domains.push_back(op_stats.percentual_operational_area); defect_influence_operational_domain_stats arsenic_stats{}; From 96053d9bcdebfb4b44e237be0540083e9a616a32 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 25 Jul 2024 16:21:27 +0200 Subject: [PATCH 109/221] :art: small fix. --- .../figure_of_merit_analysis/fom_analysis.cpp | 19 +++++-------------- .../assess_physical_population_stability.hpp | 10 ++++++---- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/experiments/figure_of_merit_analysis/fom_analysis.cpp b/experiments/figure_of_merit_analysis/fom_analysis.cpp index 943322b50..ab2e2486c 100644 --- a/experiments/figure_of_merit_analysis/fom_analysis.cpp +++ b/experiments/figure_of_merit_analysis/fom_analysis.cpp @@ -12,31 +12,22 @@ #include #include #include -#include -#include #include -#include +#include #include -#include -#include -#include #include #include +#include #include #include #include #include -#include #include #include -#include #include -#include -#include #include -#include #include using namespace fiction; @@ -49,7 +40,7 @@ int main() // NOLINT fmt::format("{}skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd", EXPERIMENTS_PATH); experiments::experiment fom_exp{ - "FOM", "benchmark", "CT max", "OPD max", "MDC_ars_min", "MDC_vac_max", "BBR"}; + "FOM", "benchmark", "CT max (K)", "OPD max", "MDC_ars_min (nm)", "MDC_vac_max (nm)", "BBR"}; const auto skeleton = read_sqd_layout(folder); @@ -172,7 +163,7 @@ int main() // NOLINT bbr_all.push_back(std::min(bbr_neu_to_neg, bbr_neg_to_neu)); } - if (temps.size() != 0) + if (!temps.empty()) { const auto max_temp = *std::max_element(temps.begin(), temps.end()); const auto max_op_domain = *std::max_element(op_domains.begin(), op_domains.end()); @@ -193,7 +184,7 @@ int main() // NOLINT fom_exp.save(); fom_exp.table(); - for (auto i = 0; i < temps.size(); i++) + for (std::size_t i = 0; i < temps.size(); i++) { cost_function_chi({temps[i] / max_temp, op_domains[i] / max_op_domain, defect_influence_arsenic[i] / max_defect_influence_arsenic, diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 26be6f3ce..01ea786d0 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -68,7 +68,7 @@ struct population_stability_information typename Lyt::cell critical_cell{}; /** * This map collects all charge transition types, the corresponding critical cells and the required - * electrostatic potential required to conduct the transition. + * electrostatic potential (unit: V) required to conduct the transition. */ std::unordered_map> transition_from_to_with_cell_and_required_pot{}; @@ -223,7 +223,7 @@ class assess_physical_population_stability_impl struct energy_and_charge_index { /** - * Electrostatic energy of the charge distribution. + * Electrostatic energy of the charge distribution (unit: eV). */ double energy; /** @@ -373,8 +373,10 @@ class assess_physical_population_stability_impl std::transform( sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), - std::back_inserter(energy_charge_index), [](const auto& ch_lyt) - { return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; }); + std::back_inserter(energy_charge_index), + [](const auto& ch_lyt) { + return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; + }); // Sort the vector in ascending order of the energy value std::sort(energy_charge_index.begin(), energy_charge_index.end(), From 2d7bb81991dedef226016c9d1f8e1e7e9589f818 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 25 Jul 2024 14:22:21 +0000 Subject: [PATCH 110/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../include/pyfiction/pybind11_mkdoc_docstrings.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index f7706b3f9..4dc7bca17 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -3993,7 +3993,7 @@ charge distribution.)doc"; static const char *__doc_fiction_detail_assess_physical_population_stability_impl_energy_and_charge_index_charge_index = R"doc(Charge index of the charge distribution.)doc"; -static const char *__doc_fiction_detail_assess_physical_population_stability_impl_energy_and_charge_index_energy = R"doc(Electrostatic energy of the charge distribution.)doc"; +static const char *__doc_fiction_detail_assess_physical_population_stability_impl_energy_and_charge_index_energy = R"doc(Electrostatic energy of the charge distribution (unit: eV).)doc"; static const char *__doc_fiction_detail_assess_physical_population_stability_impl_handle_negative_charges = R"doc(This function checks if the absolute difference between the given @@ -13204,8 +13204,8 @@ static const char *__doc_fiction_population_stability_information_system_energy static const char *__doc_fiction_population_stability_information_transition_from_to_with_cell_and_required_pot = R"doc(This map collects all charge transition types, the corresponding -critical cells and the required electrostatic potential required to -conduct the transition.)doc"; +critical cells and the required electrostatic potential (unit: V) +required to conduct the transition.)doc"; static const char *__doc_fiction_port_direction = R"doc(A port direction is a relative (cardinal) direction of a port within a From 5c260d9cce408cc6db17378869c834fda4200569 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 25 Jul 2024 16:40:02 +0200 Subject: [PATCH 111/221] :art: small fix. --- .../sidb/assess_physical_population_stability.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 01ea786d0..1dd0fd4e6 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -102,7 +102,13 @@ struct assess_physical_population_stability_params namespace detail { - +/** + * This class implements the population stability assessment for a given SiDB layout. + * It determines the minimum electrostatic potential required for charge state transitions within the layout and + * identifies the corresponding critical SiDB along with the type of charge state transition. + * + * @tparam Lyt SiDB cell-level layout type. + */ template class assess_physical_population_stability_impl { From 4043ded63eb860749fc0fd32e0e9d45e84bb778d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:40:42 +0000 Subject: [PATCH 112/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- experiments/figure_of_merit_analysis/fom_analysis.cpp | 4 ++-- .../sidb/assess_physical_population_stability.hpp | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/experiments/figure_of_merit_analysis/fom_analysis.cpp b/experiments/figure_of_merit_analysis/fom_analysis.cpp index ab2e2486c..c067849d5 100644 --- a/experiments/figure_of_merit_analysis/fom_analysis.cpp +++ b/experiments/figure_of_merit_analysis/fom_analysis.cpp @@ -11,13 +11,13 @@ #include #include #include +#include #include #include -#include #include #include -#include #include +#include #include #include diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 1dd0fd4e6..c05563efe 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -379,10 +379,8 @@ class assess_physical_population_stability_impl std::transform( sim_results.charge_distributions.cbegin(), sim_results.charge_distributions.cend(), - std::back_inserter(energy_charge_index), - [](const auto& ch_lyt) { - return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; - }); + std::back_inserter(energy_charge_index), [](const auto& ch_lyt) + { return energy_and_charge_index{ch_lyt.get_system_energy(), ch_lyt.get_charge_index_and_base().first}; }); // Sort the vector in ascending order of the energy value std::sort(energy_charge_index.begin(), energy_charge_index.end(), From 2bb165c7b16f95cca741614fda961a9cec4086f8 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 25 Jul 2024 14:41:22 +0000 Subject: [PATCH 113/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../include/pyfiction/pybind11_mkdoc_docstrings.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index 4dc7bca17..a284a2fc4 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -3961,7 +3961,15 @@ static const char *__doc_fiction_detail_apply_gate_library_impl_gate_lyt = R"doc static const char *__doc_fiction_detail_apply_gate_library_impl_run = R"doc()doc"; -static const char *__doc_fiction_detail_assess_physical_population_stability_impl = R"doc()doc"; +static const char *__doc_fiction_detail_assess_physical_population_stability_impl = +R"doc(This class implements the population stability assessment for a given +SiDB layout. It determines the minimum electrostatic potential +required for charge state transitions within the layout and identifies +the corresponding critical SiDB along with the type of charge state +transition. + +Template parameter ``Lyt``: + SiDB cell-level layout type.)doc"; static const char *__doc_fiction_detail_assess_physical_population_stability_impl_assess_physical_population_stability_impl = R"doc(Constructor for assess_physical_population_stability_impl. From 75c7fe484f876c0658d35c47771bf98edffcef4f Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 1 Aug 2024 11:14:27 +0200 Subject: [PATCH 114/221] :twisted_rightwards_arrows: merge. --- .../assess_physical_population_stability.hpp | 1 - .../sidb/defect_avoidance_distance.hpp | 6 + ...defect_influence_position_and_distance.hpp | 125 +++++++++--------- .../physical_design/design_sidb_gates.cpp | 13 +- .../assess_physical_population_stability.cpp | 4 +- ...defect_influence_position_and_distance.cpp | 2 +- 6 files changed, 81 insertions(+), 70 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index c05563efe..3438ca1bb 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -409,7 +409,6 @@ assess_physical_population_stability(const Lyt& lyt, const assess_physical_popul { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); - static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); detail::assess_physical_population_stability_impl p{lyt, params}; return p.run(); diff --git a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp index 3c488555e..3692b30dc 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp @@ -7,6 +7,8 @@ #include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" +#include "fiction/technology/sidb_nm_distance.hpp" +#include "fiction/traits.hpp" #include @@ -52,8 +54,10 @@ defect_avoidance_distance(const Lyt& lyt, const defect_influence_operational_dom { continue; } + auto min_distance = std::numeric_limits::infinity(); cell min_distance_position = {}; + lyt.foreach_cell( [&val, &min_distance, &min_distance_position, &lyt](const auto& c) { @@ -63,12 +67,14 @@ defect_avoidance_distance(const Lyt& lyt, const defect_influence_operational_dom min_distance_position = val.first; } }); + if (min_distance > max_distance) { max_distance = min_distance; max_distance_postion = min_distance_position; } } + return defect_avoidance_distance_result>{max_distance_postion, max_distance}; } diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 5813c4bb6..d9465d5a7 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -117,96 +117,101 @@ class maximum_defect_influence_position_and_distance_impl } // simulate the impact of the defect at a given position on the ground state of the SiDB layout - const auto process_defect = [&](const std::vector& defect_chunk) noexcept + const auto process_defect = [&](const cell& defect_pos) noexcept { - for (const auto& defect : defect_chunk) + if (layout.get_cell_type(defect_pos) == Lyt::technology::cell_type::EMPTY) { - if (layout.get_cell_type(defect) == Lyt::technology::cell_type::EMPTY) - { - sidb_defect_surface lyt_defect{}; + sidb_defect_surface lyt_defect{}; - layout.foreach_cell([this, &lyt_defect](const auto& cell) - { lyt_defect.assign_cell_type(cell, layout.get_cell_type(cell)); }); + layout.foreach_cell([this, &lyt_defect](const auto& cell) + { lyt_defect.assign_cell_type(cell, layout.get_cell_type(cell)); }); - // assign defect to layout - lyt_defect.assign_sidb_defect(defect, params.defect); - // conduct simulation with defect - auto simulation_result_defect = quickexact(lyt_defect, params_defect); + // assign defect to layout + lyt_defect.assign_sidb_defect(defect_pos, params.defect); + // conduct simulation with defect + auto simulation_result_defect = quickexact(lyt_defect, params_defect); - const auto min_energy_defect = - minimum_energy(simulation_result_defect.charge_distributions.cbegin(), - simulation_result_defect.charge_distributions.cend()); + const auto min_energy_defect = minimum_energy(simulation_result_defect.charge_distributions.cbegin(), + simulation_result_defect.charge_distributions.cend()); - uint64_t charge_index_defect_layout = 0; + uint64_t charge_index_defect_layout = 0; - // get the charge index of the ground state - for (const auto& lyt_simulation_with_defect : simulation_result_defect.charge_distributions) + // get the charge index of the ground state + for (const auto& lyt_simulation_with_defect : simulation_result_defect.charge_distributions) + { + if (std::fabs(round_to_n_decimal_places(lyt_simulation_with_defect.get_system_energy(), 6) - + round_to_n_decimal_places(min_energy_defect, 6)) < + std::numeric_limits::epsilon()) { - if (std::fabs(round_to_n_decimal_places(lyt_simulation_with_defect.get_system_energy(), 6) - - round_to_n_decimal_places(min_energy_defect, 6)) < - std::numeric_limits::epsilon()) - { - lyt_simulation_with_defect.charge_distribution_to_index_general(); - charge_index_defect_layout = lyt_simulation_with_defect.get_charge_index_and_base().first; - } + lyt_simulation_with_defect.charge_distribution_to_index_general(); + charge_index_defect_layout = lyt_simulation_with_defect.get_charge_index_and_base().first; } + } - // defect changes the ground state, i.e., the charge index is changed compared to the charge - // distribution without placed defect. - if (charge_index_defect_layout != charge_index_layout) - { - auto distance = std::numeric_limits::max(); - layout.foreach_cell( - [this, &defect, &distance](const auto& cell) - { - if (sidb_nm_distance(layout, cell, defect) < distance) - { - distance = sidb_nm_distance(layout, cell, defect); - } - }); - + // defect changes the ground state, i.e., the charge index is changed compared to the charge + // distribution without placed defect. + if (charge_index_defect_layout != charge_index_layout) + { + auto distance = std::numeric_limits::max(); + layout.foreach_cell( + [this, &defect_pos, &distance](const auto& cell) { - const std::lock_guard lock(mutex); - // the distance is larger than the current maximum one. - if (distance > avoidance_distance) + if (sidb_nm_distance(layout, cell, defect_pos) < distance) { - max_defect_position = defect; - avoidance_distance = distance; + distance = sidb_nm_distance(layout, cell, defect_pos); } + }); + + { + const std::lock_guard lock(mutex); + // the distance is larger than the current maximum one. + if (distance > avoidance_distance) + { + max_defect_position = defect_pos; + avoidance_distance = distance; } } } } }; - const std::size_t num_threads = std::thread::hardware_concurrency(); + static const std::size_t num_threads = std::thread::hardware_concurrency(); - const std::size_t chunk_size = defect_cells.size() / num_threads; + // calculate the size of each slice + const auto slice_size = (defect_cells.size() + -1) / num_threads; - std::vector threads; + std::vector threads{}; threads.reserve(num_threads); - auto defect_it = defect_cells.begin(); - for (std::size_t i = 0; i < num_threads; ++i) + // launch threads, each with its own slice of random step points + for (auto i = 0ul; i < num_threads; ++i) { - auto chunk_start = defect_it; - auto chunk_end = std::min(defect_it + chunk_size, defect_cells.end()); + const auto start = i * slice_size; + const auto end = std::min(start + slice_size, defect_cells.size()); - threads.emplace_back(process_defect, std::vector(chunk_start, chunk_end)); + if (start >= end) + { + break; // no more work to distribute + } - defect_it = chunk_end; + threads.emplace_back( + [this, start, end, &process_defect] + { + for (auto it = defect_cells.cbegin() + static_cast(start); + it != defect_cells.cbegin() + static_cast(end); ++it) + { + process_defect(*it); + } + }); } - auto chunk_start = defect_it; - auto chunk_end = defect_cells.end(); - - const auto chunk_vector = std::vector(chunk_start, chunk_end); - - threads.emplace_back(process_defect, chunk_vector); - + // wait for all threads to complete for (auto& thread : threads) { - thread.join(); + if (thread.joinable()) + { + thread.join(); + } } return {max_defect_position, avoidance_distance}; diff --git a/test/algorithms/physical_design/design_sidb_gates.cpp b/test/algorithms/physical_design/design_sidb_gates.cpp index 59bc89c4b..99451380b 100644 --- a/test/algorithms/physical_design/design_sidb_gates.cpp +++ b/test/algorithms/physical_design/design_sidb_gates.cpp @@ -307,7 +307,9 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") const critical_temperature_params ct_params{params.simulation_parameters}; const operational_domain_params op_params{params.simulation_parameters}; + design_sidb_gates_metric_driven_simulated_annealing_params sa_params{}; + sa_params.ct_params = ct_params; sa_params.op_params = op_params; sa_params.weight_temperature = -1.0; @@ -325,15 +327,12 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") const auto found_gate_layout = design_sidb_gates_metric_driven_simulated_annealing( defect_layout, std::vector{create_and_tt()}, params, sa_params); + CHECK(found_gate_layout.num_defects() == 2); CHECK(found_gate_layout.num_cells() == lyt.num_cells() + 3); - found_gate_layout.foreach_cell( - [](const auto& cell) - { - CHECK(cell != siqad::coord_t{15, 10, 0}); - CHECK(cell != siqad::coord_t{20, 12, 0}); - }); + found_gate_layout.is_empty_cell(siqad::coord_t{15, 10, 0}); + found_gate_layout.is_empty_cell(siqad::coord_t{20, 12, 0}); } } @@ -383,7 +382,7 @@ TEST_CASE("Design AND Bestagon shaped gate on H-Si 111", "[design-sidb-gates]") SECTION("Exhaustive Generation") { const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, - {{10, 11, 0}, {14, 16, 0}}, + {{11, 11, 0}, {14, 16, 0}}, 3, sidb_simulation_engine::QUICKEXACT}; diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp index 923c22a22..de6b3bfce 100644 --- a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp +++ b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp @@ -2,6 +2,7 @@ // Created by Jan Drewniok on 02.11.23. // +#include #include #include @@ -66,7 +67,8 @@ TEST_CASE("Single SiDB", "[assess-physical-population-stability]") TEMPLATE_TEST_CASE("Three SiDBs with positive charge states", "[assess-physical-population-stability]", sidb_cell_clk_lyt_siqad, cds_sidb_cell_clk_lyt_siqad) { - layout lyt{}; + TestType lyt{}; + const auto params = assess_physical_population_stability_params{}; lyt.assign_cell_type({1, 1, 0}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({1, 1, 1}, sidb_technology::cell_type::NORMAL); diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp index f78eb5fed..ef1192812 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp @@ -145,7 +145,7 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio { const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, sidb_simulation_parameters{}.lambda_tf}; - const maximum_defect_influence_distance_params sim_params{defect, sidb_simulation_parameters{2}}; + const maximum_defect_influence_position_and_distance_params sim_params{defect, sidb_simulation_parameters{2}}; sidb_cell_clk_lyt_cube lyt{{30, 30}}; lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{10, 0, 0}), From 53325f3caa9dcd1ac08965a99d03afb1b6e6ce9b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:14:46 +0000 Subject: [PATCH 115/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/algorithms/physical_design/design_sidb_gates.cpp | 4 ++-- .../maximum_defect_influence_position_and_distance.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/algorithms/physical_design/design_sidb_gates.cpp b/test/algorithms/physical_design/design_sidb_gates.cpp index 99451380b..0afbf7dea 100644 --- a/test/algorithms/physical_design/design_sidb_gates.cpp +++ b/test/algorithms/physical_design/design_sidb_gates.cpp @@ -305,8 +305,8 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") sidb_defect{sidb_defect_type::DB, -1, params.simulation_parameters.epsilon_r, params.simulation_parameters.lambda_tf}); - const critical_temperature_params ct_params{params.simulation_parameters}; - const operational_domain_params op_params{params.simulation_parameters}; + const critical_temperature_params ct_params{params.simulation_parameters}; + const operational_domain_params op_params{params.simulation_parameters}; design_sidb_gates_metric_driven_simulated_annealing_params sa_params{}; diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp index ef1192812..5f993265d 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.cpp @@ -109,7 +109,7 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, sidb_simulation_parameters{}.lambda_tf}; const maximum_defect_influence_position_and_distance_params sim_params{defect, sidb_simulation_parameters{2}}; - sidb_cell_clk_lyt_siqad lyt{}; + sidb_cell_clk_lyt_siqad lyt{}; lyt.assign_cell_type({10, 0, 0}, sidb_cell_clk_lyt_siqad::cell_type::NORMAL); lyt.assign_cell_type({0, 1, 0}, sidb_cell_clk_lyt_siqad::cell_type::NORMAL); @@ -132,8 +132,8 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio // number of threads given by the hardware const sidb_defect high_screening{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, 1}; - const maximum_defect_influence_position_and_distance_params sim_params_high_screening{high_screening, - sidb_simulation_parameters{2}}; + const maximum_defect_influence_position_and_distance_params sim_params_high_screening{ + high_screening, sidb_simulation_parameters{2}}; const auto [defect_pos_high_screening, distance_high_screening] = maximum_defect_influence_position_and_distance(lat, sim_params_high_screening); @@ -146,7 +146,7 @@ TEST_CASE("Test influence distance function", "[maximum-defect-influence-positio const sidb_defect defect{sidb_defect_type::UNKNOWN, -1, sidb_simulation_parameters{}.epsilon_r, sidb_simulation_parameters{}.lambda_tf}; const maximum_defect_influence_position_and_distance_params sim_params{defect, sidb_simulation_parameters{2}}; - sidb_cell_clk_lyt_cube lyt{{30, 30}}; + sidb_cell_clk_lyt_cube lyt{{30, 30}}; lyt.assign_cell_type(siqad::to_fiction_coord(siqad::coord_t{10, 0, 0}), sidb_cell_clk_lyt_siqad::cell_type::NORMAL); From 15dd8549f8cd3b727bc048c993709b26fdaac6cc Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 1 Aug 2024 11:17:28 +0200 Subject: [PATCH 116/221] :twisted_rightwards_arrows: merge. --- .../sidb/test_assess_physical_population_stability.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindings/pyfiction/test/algorithms/simulation/sidb/test_assess_physical_population_stability.py b/bindings/pyfiction/test/algorithms/simulation/sidb/test_assess_physical_population_stability.py index f83bfa9a8..bf6f2bca4 100644 --- a/bindings/pyfiction/test/algorithms/simulation/sidb/test_assess_physical_population_stability.py +++ b/bindings/pyfiction/test/algorithms/simulation/sidb/test_assess_physical_population_stability.py @@ -1,7 +1,5 @@ from mnt.pyfiction import * import unittest -import os - class TestAssessPhysicalPopulationStability(unittest.TestCase): From 1a1f204bdc293a7c50159e0cab22b4354c5247c5 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 20 Sep 2024 16:01:09 +0200 Subject: [PATCH 117/221] :see_no_evil: update gitignore file. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 44ab497fb..a0efd2d19 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,6 @@ venv/ *.tar.* *.7z *.rar + +# Jupyter notebook +*.ipynb From 8f10c7eabd8218bc5d0117e546ded38e722313ca Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 20 Sep 2024 16:03:54 +0200 Subject: [PATCH 118/221] :children_crossing: add experiment to compare different methods to determine the defect avoidance distance. --- .../defect_avoidance_distance.cpp | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 experiments/defect_avoidance_distance/defect_avoidance_distance.cpp diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp new file mode 100644 index 000000000..fa12cd373 --- /dev/null +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp @@ -0,0 +1,107 @@ +#include "fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp" +#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" +#include "fiction/algorithms/simulation/sidb/is_operational.hpp" +#include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" +#include "fiction/io/read_sqd_layout.hpp" +#include "fiction/io/write_defect_influence_operational_domain.hpp" +#include "fiction/io/write_sqd_layout.hpp" +#include "fiction/types.hpp" +#include "fiction/utils/truth_table_utils.hpp" +#include "fiction_experiments.hpp" + +#include + +#include +#include +#include +#include +#include +#include + +using namespace fiction; + +int main() { + experiments::experiment simulation_exp{ + "Benchmark", "Gate Name", "distance_grid_search", "#samples", + "distance_random", "#samples", "distance_contour", "#samples", + }; + + static const std::string folder = fmt::format("{}bestagon_gates_type_tags/", EXPERIMENTS_PATH); + static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); + + static const std::array>, 9> gates = {{ + {"and", {create_and_tt()}}, + {"xor", {create_xor_tt()}}, + {"or", {create_or_tt()}}, + {"xnor", {create_xnor_tt()}}, + {"fo2", {create_fan_out_tt()}}, + {"nor", {create_nor_tt()}}, + {"nand", {create_nand_tt()}}, + {"inv", {create_not_tt()}}, + {"wire", {create_id_tt()}}, + }}; + + const auto sidb_sim = sidb_simulation_parameters{2, -0.32, 5.6, 5.0}; + const is_operational_params is_op_params{sidb_sim}; + + maximum_defect_influence_position_and_distance_params max_defect_params{}; + max_defect_params.defect = sidb_defect{ + fiction::sidb_defect_type::UNKNOWN, -1, is_op_params.simulation_parameters.epsilon_r, + is_op_params.simulation_parameters.lambda_tf + }; + max_defect_params.additional_scanning_area = {50, 50}; + + defect_influence_operational_domain_params defect_params{}; + defect_params.defect_influence_params = max_defect_params; + defect_params.operational_params = is_op_params; + + for (const auto& [gate, truth_table] : gates) { + // Create gate directory for plots + std::string gate_folder = fmt::format("{}{}/", output_folder, gate); + std::filesystem::create_directories(gate_folder); + + for (const auto& file : std::filesystem::directory_iterator(fmt::format("{}{}", folder, gate))) { + const auto layout = read_sqd_layout(file.path().string()); + + defect_influence_operational_domain_stats grid_stats{}; + const auto op_defect_grid_search = defect_influence_operational_domain_grid_search( + layout, truth_table, 1, defect_params, &grid_stats); + + // Define file paths for the CSV and SQD + const auto csv_path = fmt::format("{}{}_grid_search.csv", gate_folder, gate); + const auto sqd_path = fmt::format("{}/{}.sqd", gate_folder, gate); + + // Write the CSV file + write_defect_influence_operational_domain(op_defect_grid_search, csv_path); + + // Write the SQD layout + write_sqd_layout(layout, sqd_path); + + const auto avoidance_grid = defect_avoidance_distance(layout, op_defect_grid_search); + + defect_influence_operational_domain_stats random_stats{}; + const auto op_defect_random_search = defect_influence_operational_domain_random_sampling( + layout, truth_table, 100, defect_params, &random_stats); + const auto avoidance_random = defect_avoidance_distance(layout, op_defect_random_search); + + const auto csv_path_random = fmt::format("{}{}_random.csv", gate_folder, gate); + write_defect_influence_operational_domain(op_defect_random_search, csv_path_random); + + defect_influence_operational_domain_stats contour_stats{}; + const auto op_defect_contour_search = defect_influence_operational_domain_contour_tracing( + layout, truth_table, 1, defect_params, &contour_stats); + const auto avoidance_contour = defect_avoidance_distance(layout, op_defect_contour_search); + + const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); + write_defect_influence_operational_domain(op_defect_contour_search, csv_path_contour); + + // Log the simulation results + simulation_exp(gate, avoidance_grid.max_min_distance, grid_stats.num_evaluated_defect_positions, + avoidance_random.max_min_distance, random_stats.num_evaluated_defect_positions, + avoidance_contour.max_min_distance, contour_stats.num_evaluated_defect_positions); + simulation_exp.save(); + simulation_exp.table(); + } + } + return EXIT_SUCCESS; +} From 37f4219a4734bcb5bd3d2686016ce520e15480a5 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 20 Sep 2024 16:04:25 +0200 Subject: [PATCH 119/221] :art: update code. --- .../algorithms/iter/bdl_input_iterator.hpp | 1 - .../physical_design/design_sidb_gates.hpp | 13 +- .../assess_physical_population_stability.hpp | 1 + .../sidb/displacement_robustness_domain.hpp | 1 + ...defect_influence_position_and_distance.hpp | 14 +- .../simulation/sidb/operational_domain.hpp | 5 +- .../physical_design/test_design_sidb_gates.py | 4 +- .../sidb/test_operational_domain.py | 10 +- docs/io/physical_simulation.rst | 13 + .../algorithms/iter/bdl_input_iterator.hpp | 2 +- .../physical_design/design_sidb_gates.hpp | 251 ++---------------- .../sidb/calculate_min_bbr_for_all_inputs.hpp | 8 +- .../defect_influence_operational_domain.hpp | 4 +- ...nce_position_and_distance_of_sidb_gate.hpp | 6 +- .../simulation/sidb/operational_domain.hpp | 48 +--- ...te_defect_influence_operational_domain.hpp | 20 +- .../physical_design/design_sidb_gates.cpp | 68 +---- .../defect_influence_operational_domain.cpp | 2 +- .../simulation/sidb/operational_domain.cpp | 52 ++-- 19 files changed, 117 insertions(+), 406 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/iter/bdl_input_iterator.hpp b/bindings/pyfiction/include/pyfiction/algorithms/iter/bdl_input_iterator.hpp index 8a0ab7bdf..6431d36ac 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/iter/bdl_input_iterator.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/iter/bdl_input_iterator.hpp @@ -9,7 +9,6 @@ #include "pyfiction/types.hpp" #include -#include #include #include diff --git a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp index e8c1e823d..0502865a5 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp @@ -6,7 +6,6 @@ #define PYFICTION_DESIGN_SIDB_GATES_HPP #include "pyfiction/documentation.hpp" -#include "pyfiction/types.hpp" #include #include @@ -37,13 +36,12 @@ inline void design_sidb_gates(pybind11::module& m) /** * Design approach selector type. */ + // todo update docstrings pybind11::enum_::design_sidb_gates_mode>( - m, "design_sidb_gates_mode", DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode)) + m, "design_sidb_gates_mode") .value("EXHAUSTIVE", - fiction::design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, - DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE)) - .value("RANDOM", fiction::design_sidb_gates_params::design_sidb_gates_mode::RANDOM, - DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM)); + fiction::design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE) + .value("RANDOM", fiction::design_sidb_gates_params::design_sidb_gates_mode::RANDOM); /** * Parameters. @@ -54,8 +52,7 @@ inline void design_sidb_gates(pybind11::module& m) .def_readwrite("operational_params", &fiction::design_sidb_gates_params::operational_params, DOC(fiction_design_sidb_gates_params_operational_params)) - .def_readwrite("design_mode", &fiction::design_sidb_gates_params::design_mode, - DOC(fiction_design_sidb_gates_params_design_mode)) + .def_readwrite("design_mode", &fiction::design_sidb_gates_params::design_mode) .def_readwrite("canvas", &fiction::design_sidb_gates_params::canvas, DOC(fiction_design_sidb_gates_params_canvas)) .def_readwrite("number_of_sidbs", diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 6bce1f2c2..e6c36e7a9 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -12,6 +12,7 @@ #include #include +#include namespace pyfiction { diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp index 3d37b2862..24e6250f1 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace pyfiction { diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 5d195d64c..ef0cb85b2 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -26,7 +26,7 @@ void maximum_defect_influence_distance(pybind11::module& m) m.def("maximum_defect_influence_position_and_distance", &fiction::maximum_defect_influence_position_and_distance, "lyt"_a, - "params"_a = fiction::maximum_defect_influence_distance_params{}, + "params"_a = fiction::maximum_defect_influence_position_and_distance_params{}, DOC(fiction_maximum_defect_influence_position_and_distance)); } @@ -36,16 +36,12 @@ inline void maximum_defect_influence_distance(pybind11::module& m) { namespace py = pybind11; - py::class_(m, "maximum_defect_influence_distance_params", - DOC(fiction_maximum_defect_influence_distance_params)) + py::class_(m, "maximum_defect_influence_distance_params") .def(py::init<>()) - .def_readwrite("defect", &fiction::maximum_defect_influence_distance_params::defect, - DOC(fiction_maximum_defect_influence_distance_params_defect)) - .def_readwrite("sim_params", &fiction::maximum_defect_influence_distance_params::simulation_parameters, - DOC(fiction_maximum_defect_influence_distance_params_sim_params)) + .def_readwrite("defect", &fiction::maximum_defect_influence_distance_params::defect) + .def_readwrite("sim_params", &fiction::maximum_defect_influence_distance_params::simulation_parameters) .def_readwrite("additional_scanning_area", - &fiction::maximum_defect_influence_distance_params::additional_scanning_area, - DOC(fiction_maximum_defect_influence_distance_params_additional_scanning_area)) + &fiction::maximum_defect_influence_distance_params::additional_scanning_area) ; diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp index 404087352..e3fde5711 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp @@ -37,12 +37,11 @@ void operational_domain(pybind11::module& m) DOC(fiction_operational_domain_random_sampling)); m.def("operational_domain_flood_fill", &fiction::operational_domain_flood_fill, "lyt"_a, "spec"_a, - "samples"_a, "params"_a = fiction::operational_domain_params{}, "initial_parameter_point"_a = nullptr, + "samples"_a, "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_operational_domain_flood_fill)); m.def("operational_domain_contour_tracing", &fiction::operational_domain_contour_tracing, "lyt"_a, - "spec"_a, "samples"_a, "params"_a = fiction::operational_domain_params{}, - "initial_parameter_point"_a = nullptr, "stats"_a = nullptr, DOC(fiction_operational_domain_contour_tracing)); + "spec"_a, "samples"_a, "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_operational_domain_contour_tracing)); } } // namespace detail diff --git a/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py b/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py index 7aa163610..9a0292bf8 100644 --- a/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py +++ b/bindings/pyfiction/test/algorithms/physical_design/test_design_sidb_gates.py @@ -5,7 +5,7 @@ class TestDesignSiDBGates(unittest.TestCase): - def test_siqad_and_gate_skeleton(self): + def test_siqad_and_gate_skeleton_100(self): layout = sidb_100_lattice((20, 20)) layout.assign_cell_type((0, 1), sidb_technology.cell_type.INPUT) @@ -38,7 +38,7 @@ def test_siqad_and_gate_skeleton(self): self.assertEqual(params.canvas[0], (4, 8, 0)) self.assertEqual(params.canvas[1], (14, 11)) - designed_gates = design_sidb_gates(layout, [create_and_tt()], params, design_sidb_gates_mode.EXHAUSTIVE) + designed_gates = design_sidb_gates(layout, [create_and_tt()], params) self.assertEqual(len(designed_gates), 23) diff --git a/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py b/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py index 10f709020..0da147359 100644 --- a/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py +++ b/bindings/pyfiction/test/algorithms/simulation/sidb/test_operational_domain.py @@ -22,7 +22,7 @@ def test_xor_gate_100_lattice(self): self.assertGreater(stats_grid.num_operational_parameter_combinations, 0) stats_flood_fill = operational_domain_stats() - operational_domain_flood_fill(lyt, [create_xor_tt()], 100, params, None, stats_flood_fill) + operational_domain_flood_fill(lyt, [create_xor_tt()], 100, params, stats_flood_fill) self.assertGreater(stats_flood_fill.num_operational_parameter_combinations, 0) stats_random_sampling = operational_domain_stats() @@ -30,7 +30,7 @@ def test_xor_gate_100_lattice(self): self.assertGreater(stats_random_sampling.num_operational_parameter_combinations, 0) stats_contour_tracing = operational_domain_stats() - operational_domain_contour_tracing(lyt, [create_xor_tt()], 100, params, None, stats_contour_tracing) + operational_domain_contour_tracing(lyt, [create_xor_tt()], 100, params, stats_contour_tracing) self.assertGreater(stats_contour_tracing.num_operational_parameter_combinations, 0) def test_and_gate_111_lattice(self): @@ -42,14 +42,14 @@ def test_and_gate_111_lattice(self): params.simulation_parameters.base = 2 params.sweep_dimensions = [operational_domain_value_range(sweep_parameter.EPSILON_R, 5.60, 5.64, 0.01), - operational_domain_value_range(sweep_parameter.LAMBDA_TF, 5.00, 5.01, 0.01)]; + operational_domain_value_range(sweep_parameter.LAMBDA_TF, 5.00, 5.01, 0.01)] stats_grid = operational_domain_stats() operational_domain_grid_search(lyt, [create_and_tt()], params, stats_grid) self.assertGreater(stats_grid.num_operational_parameter_combinations, 0) stats_flood_fill = operational_domain_stats() - operational_domain_flood_fill(lyt, [create_and_tt()], 100, params, None,stats_flood_fill) + operational_domain_flood_fill(lyt, [create_and_tt()], 100, params,stats_flood_fill) self.assertGreater(stats_flood_fill.num_operational_parameter_combinations, 0) stats_random_sampling = operational_domain_stats() @@ -57,7 +57,7 @@ def test_and_gate_111_lattice(self): self.assertGreater(stats_random_sampling.num_operational_parameter_combinations, 0) stats_contour_tracing = operational_domain_stats() - operational_domain_contour_tracing(lyt, [create_and_tt()], 100, params, None, stats_contour_tracing) + operational_domain_contour_tracing(lyt, [create_and_tt()], 100, params, stats_contour_tracing) self.assertGreater(stats_contour_tracing.num_operational_parameter_combinations, 0) diff --git a/docs/io/physical_simulation.rst b/docs/io/physical_simulation.rst index fca08d027..2aa9a2841 100644 --- a/docs/io/physical_simulation.rst +++ b/docs/io/physical_simulation.rst @@ -158,6 +158,19 @@ SiDB Operational Domain .. autofunction:: mnt.pyfiction.write_operational_domain +SiDB Defect Influence Operational Domain +######################################## + +.. tabs:: + .. tab:: C++ + **Header:** ``fiction/io/write_defect_influence_operational_domain.hpp`` + + .. doxygenstruct:: fiction::write_defect_influence_operational_domain_params + :members: + .. doxygenfunction:: fiction::write_defect_influence_operational_domain(const operational_domain& opdom, std::ostream& os, const write_defect_influence_operational_domain_params& params = {}) + .. doxygenfunction:: fiction::write_defect_influence_operational_domain(const operational_domain& opdom, const std::string_view& filename, const write_defect_influence_operational_domain_params& params = {}) + + Technology-independent Gate-level Layouts ######################################### diff --git a/include/fiction/algorithms/iter/bdl_input_iterator.hpp b/include/fiction/algorithms/iter/bdl_input_iterator.hpp index 79e5ee454..9f4668ff6 100644 --- a/include/fiction/algorithms/iter/bdl_input_iterator.hpp +++ b/include/fiction/algorithms/iter/bdl_input_iterator.hpp @@ -341,7 +341,7 @@ class bdl_input_iterator */ void set_all_inputs() noexcept { - for (uint64_t i = 0; i < input_pairs.size(); ++i) + for (uint64_t i = input_pairs.size(); i-- > 0;) { const auto& input_i = input_pairs[i]; diff --git a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp index 821967511..cb8364092 100644 --- a/include/fiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/include/fiction/algorithms/physical_design/design_sidb_gates.hpp @@ -5,13 +5,8 @@ #ifndef FICTION_DESIGN_SIDB_GATES_HPP #define FICTION_DESIGN_SIDB_GATES_HPP -#include "fiction/algorithms/optimization/simulated_annealing.hpp" -#include "fiction/algorithms/simulation/sidb/critical_temperature.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" -#include "fiction/algorithms/simulation/sidb/operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/random_sidb_layout_generator.hpp" -#include "fiction/algorithms/simulation/sidb/sidb_simulation_engine.hpp" -#include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" #include "fiction/technology/cell_technologies.hpp" #include "fiction/technology/sidb_defects.hpp" #include "fiction/technology/sidb_nm_distance.hpp" @@ -21,7 +16,6 @@ #include #include -#include #include #include @@ -39,9 +33,13 @@ namespace fiction { /** - * Parameters for Simulated Annealing-based gate design. + * This struct contains parameters and settings to design SiDB gates. + * + * @tparam CellType Cell type. + * */ -struct design_sidb_gates_metric_driven_simulated_annealing_params +template +struct design_sidb_gates_params { /** * Selector for the different termination conditions for the SiDB gate design process. @@ -75,6 +73,10 @@ struct design_sidb_gates_metric_driven_simulated_annealing_params * Parameters for the `is_operational` function. */ is_operational_params operational_params{}; + /** + * Gate design mode. + */ + design_sidb_gates_mode design_mode = design_sidb_gates_mode::EXHAUSTIVE; /** * Canvas spanned by the northwest and southeast cell. */ @@ -105,21 +107,14 @@ class design_sidb_gates_impl * @param skeleton The skeleton layout used as a basis for gate design. * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param ps Parameters and settings for the gate designer. - * @param st Statistics for the gate designer. */ design_sidb_gates_impl(const Lyt& skeleton, const std::vector& spec, const design_sidb_gates_params>& ps) : skeleton_layout{skeleton}, truth_table{spec}, params{ps}, - stats{st}, all_sidbs_in_canvas{all_coordinates_in_spanned_area(params.canvas.first, params.canvas.second)} - { - // Use std::uniform_int_distribution to generate a random index - random_canvas_cell_functor = std::uniform_int_distribution(0, all_sidbs_in_canvas.size() - 1); - random_canvas_sidb_functor = std::uniform_int_distribution(0, params.number_of_sidbs - 1); - } - + {} /** * Design gates exhaustively and in parallel. * @@ -219,10 +214,9 @@ class design_sidb_gates_impl * * @return A vector of designed SiDB gate layouts. */ - [[nodiscard]] std::vector run_random_design(uint64_t target_num_solutions = 1u) noexcept + [[nodiscard]] std::vector run_random_design() noexcept { - mockturtle::stopwatch stop{stats.time_total}; - std::vector randomly_designed_gate_layouts = {}; + std::vector randomly_designed_gate_layouts = {}; const generate_random_sidb_layout_params> parameter_random_layout{ params.canvas, params.number_of_sidbs, @@ -241,7 +235,7 @@ class design_sidb_gates_impl [this, &gate_layout_is_found, &mutex_to_protect_designed_gate_layouts, ¶meter_random_layout, &randomly_designed_gate_layouts] { - while (num_solutions_found < target_num_solutions) + while (!gate_layout_is_found) { auto result_lyt = generate_random_sidb_layout(skeleton_layout, parameter_random_layout); if constexpr (has_get_sidb_defect_v) @@ -272,7 +266,8 @@ class design_sidb_gates_impl }); } randomly_designed_gate_layouts.push_back(result_lyt); - num_solutions_found++; + gate_layout_is_found = true; + break; } } }); @@ -289,74 +284,6 @@ class design_sidb_gates_impl return randomly_designed_gate_layouts; } - /** - * Design gates with Simulated Annealing. - * - * This function designs gates with Simulated Annealing. The cost function involves the critical temperature and the - * operational domain. The importance of the individual figures of merit can be adjusted by the weights. - * - * @param sa_params Simulated Annealing parameters. - * @return Designed SiDB gate with minimal cost. - */ - [[nodiscard]] Lyt run_metric_driven_design_process( - const design_sidb_gates_metric_driven_simulated_annealing_params& sa_params) noexcept - { - mockturtle::stopwatch stop{stats.time_total}; - generate_random_sidb_layout_params> parameter{ - params.canvas, params.number_of_sidbs, - generate_random_sidb_layout_params>::positive_charges::FORBIDDEN}; - const is_operational_params params_is_operational{params.simulation_parameters, params.sim_engine}; - auto initial_lyt = generate_random_sidb_layout(skeleton_layout, parameter); - - const auto temperature_schedule = sa_params.schedule == temperature_schedule::LINEAR ? - linear_temperature_schedule : - geometric_temperature_schedule; - - canvas_sidbs = determine_canvas_sidbs(initial_lyt); - - auto [optimized_gate_design, optimized_net_cost] = simulated_annealing( - initial_lyt, sa_params.initial_temperature, sa_params.final_temperature, sa_params.number_of_cycles, - [&, this](const auto& lyt) - { - const auto logic_cost = - (is_operational(lyt, truth_table, params_is_operational).first == operational_status::OPERATIONAL) ? - 0 : - sa_params.weight_non_operational; - - double temp_cost = 0; - double opo_cost = 0; - if (logic_cost == 0) - { - if (sa_params.weight_temperature != 0.0) - { - temp_cost = ((critical_temperature_gate_based(lyt, truth_table, sa_params.ct_params)) / - sa_params.ct_params.max_temperature); - } - if (sa_params.weight_operational_domain != 0.0) - { - operational_domain_stats stats_op{}; - const auto op_domain = - operational_domain_flood_fill(lyt, truth_table, 0, sa_params.op_params, - parameter_point{params.simulation_parameters.epsilon_r, - params.simulation_parameters.lambda_tf}, - &stats_op); - opo_cost = stats_op.percentual_operational_area; - } - } - return cost_function_chi({logic_cost, temp_cost, opo_cost}, - {sa_params.weight_non_operational, sa_params.weight_temperature, - sa_params.weight_operational_domain}); - }, - temperature_schedule, - [&](auto lyt) - { - const auto lyt_swap = move_sidb(lyt); - return lyt_swap; - }); - stats.gate_cost = optimized_net_cost; - return optimized_gate_design; - } - private: /** * The skeleton layout serves as a starting layout to which SiDBs are added to create unique SiDB layouts and, if @@ -371,10 +298,6 @@ class design_sidb_gates_impl * Parameters for the *SiDB Gate Designer*. */ const design_sidb_gates_params>& params; - /** - * The statistics of the gate design. - */ - design_sidb_gates_stats& stats; /** * All cells within the canvas. */ @@ -383,82 +306,6 @@ class design_sidb_gates_impl * Number of threads to be used for parallel execution. */ const std::size_t num_threads{std::thread::hardware_concurrency()}; - /** - * All SiDBs within the canvas. - */ - std::vector canvas_sidbs; - /** - * Canvas SiDBs before move. - */ - std::vector canvas_sidbs_before_move; - /** - * Canvas SiDB was moved from one cell (first cell) to another cell (second cell). - */ - std::pair sidb_moved_from_to{}; - /** - * A random-number generator. - */ - std::mt19937_64 generator{std::random_device{}()}; - /** - * - */ - std::uniform_int_distribution random_canvas_sidb_functor; - /** - * - */ - std::uniform_int_distribution random_canvas_cell_functor; - /** - * This function iterates over each cell in the provided layout `lyt` and checks if the cell - * corresponds to a canvas SiDB. Canvas SiDBs are defined as SiDBs that are part of the canvas - * region. It populates a vector with the canvas SiDBs found in the layout and returns it. - * - * @param lyt The layout from which canvas SiDBs are to be determined. - * @return A vector containing the canvas SiDBs found in the layout. - */ - [[nodiscard]] std::vector determine_canvas_sidbs(const Lyt& lyt) const noexcept - { - std::vector placed_canvas_sidbs = {}; - placed_canvas_sidbs.reserve(params.number_of_sidbs); - lyt.foreach_cell( - [&](const auto& cell) - { - if (std::find(all_sidbs_in_canvas.begin(), all_sidbs_in_canvas.end(), cell) != - all_sidbs_in_canvas.end()) - { - placed_canvas_sidbs.emplace_back(cell); - } - }); - return placed_canvas_sidbs; - } - /** - * This function randomly selects a canvas cell from the layout `lyt` and a canvas SiDB - * to replace it with. It then moves the selected canvas SiDB to the randomly chosen - * canvas cell, updating the layout accordingly. If the randomly chosen canvas cell is not - * empty, the layout remains unchanged. - * - * @param lyt The layout from which a canvas SiDB is to be moved. - * @return The layout after the canvas SiDB has been moved, or the original layout if the - * randomly chosen canvas cell was not empty. - */ - [[nodiscard]] Lyt move_sidb(Lyt& lyt) noexcept - { - const auto random_index = random_canvas_cell_functor(generator); - const auto random_index_replace = random_canvas_sidb_functor(generator); - const auto random_cell = all_sidbs_in_canvas[random_index]; - const auto replace_sidb = canvas_sidbs[random_index_replace]; - - // cell has to be empty - if (!lyt.is_empty_cell(random_cell)) - { - return lyt; - } - lyt.assign_cell_type(replace_sidb, Lyt::technology::cell_type::EMPTY); - lyt.assign_cell_type(random_cell, Lyt::technology::cell_type::NORMAL); - sidb_moved_from_to = {replace_sidb, random_cell}; - canvas_sidbs_before_move = canvas_sidbs; - canvas_sidbs[random_index_replace] = random_cell; - return lyt; - } /** * Checks if any SiDBs within the specified cell indices are located too closely together, with a distance of less * than 0.5 nanometers. @@ -498,7 +345,6 @@ class design_sidb_gates_impl } return false; } - /** * This function adds SiDBs (given by indices) to the skeleton layout that is returned afterwards. * @@ -546,11 +392,11 @@ class design_sidb_gates_impl /** * The *SiDB Gate Designer* designs SiDB gate implementations based on a specified Boolean function, a * skeleton layout (can hold defects), canvas size, and a predetermined number of canvas SiDBs. Two different design - * modes are implemented: `exhaustive` and `random`. + * modes are implemented: `exhaustive` and `random design`. * * The `exhaustive design` is composed of three steps: * 1. In the initial step, all possible distributions of `number_of_sidbs` SiDBs within a given canvas are - * exhaustively determined. This ensures exhaustive coverage of every potential arrangement of `number_of_sidbs` SiDBs + * exhaustively determined. This ensures exhaustive coverage of every potential arrangement of ``number_of_sidbs`` SiDBs * across the canvas. * 2. The calculated SiDB distributions are then incorporated into the skeleton, resulting in the generation of distinct * SiDB layouts. @@ -569,16 +415,11 @@ class design_sidb_gates_impl * @param skeleton The skeleton layout used as a starting point for gate design. * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param params Parameters for the *SiDB Gate Designer*. - * @param design_mode The design mode to use. - * @param stats The design statistics. * @return A vector of designed SiDB gate layouts. */ template -[[nodiscard]] std::vector -design_sidb_gates(const Lyt& skeleton, const std::vector& spec, - const design_sidb_gates_params>& params = {}, - const design_sidb_gates_mode design_mode = design_sidb_gates_mode::EXHAUSTIVE, - design_sidb_gates_stats* stats = nullptr) noexcept +[[nodiscard]] std::vector design_sidb_gates(const Lyt& skeleton, const std::vector& spec, + const design_sidb_gates_params>& params = {}) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -593,58 +434,12 @@ design_sidb_gates(const Lyt& skeleton, const std::vector& spec, assert(std::adjacent_find(spec.begin(), spec.end(), [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.end()); - design_sidb_gates_stats st{}; - detail::design_sidb_gates_impl p{skeleton, spec, params, st}; - - std::vector result{}; + detail::design_sidb_gates_impl p{skeleton, spec, params}; - if (design_mode == design_sidb_gates_mode::EXHAUSTIVE) + if (params.design_mode == design_sidb_gates_params>::design_sidb_gates_mode::EXHAUSTIVE) { - result = p.run_exhaustive_design(); + return p.run_exhaustive_design(); } - else - { - result = p.run_random_design(params.maximal_random_solutions); - } - if (stats) - { - *stats = st; - } - return result; -} - -/** - * This function designs SiDB gates to minimize the cost function \f$\chi\f$, considering a layout skeleton, a set of - * truth tables, and specified parameters for gate design and simulated annealing. Currently, only the critical - * temperature and the operational domain are incorporated into the cost function. - * - * @tparam Lyt SiDB cell-level layout type. - * @tparam TT The type of the truth table specifying the gate behavior. - * @param skeleton The layout skeleton used as the basis for gate design. - * @param spec Expected Boolean function of the layout given as a multi-output truth table. - * @param params The parameters for gate design. - * @param sa_params Parameters for simulated annealing. - * @param stats Statistics for gate design. - * @return A layout with SiDB gates designed to minimize the cost function. - */ -template -[[nodiscard]] Lyt design_sidb_gates_metric_driven_simulated_annealing( - const Lyt& skeleton, const std::vector& spec, const design_sidb_gates_params>& params, - const design_sidb_gates_metric_driven_simulated_annealing_params& sa_params, - design_sidb_gates_stats* stats = nullptr) noexcept -{ - static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); - static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); - static_assert(kitty::is_truth_table::value, "TT is not a truth table"); - static_assert(!is_charge_distribution_surface_v, "Lyt cannot be a charge distribution surface"); - - assert(skeleton.num_pis() > 0 && "skeleton needs input cells"); - assert(skeleton.num_pos() > 0 && "skeleton needs output cells"); - - assert(!spec.empty()); - // all elements in tts must have the same number of variables - assert(std::adjacent_find(spec.begin(), spec.end(), - [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.end()); detail::design_sidb_gates_impl p_random{skeleton, spec, params}; return p.run_random_design(); diff --git a/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp b/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp index bf2ab21cb..db6dbf810 100644 --- a/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp +++ b/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp @@ -28,9 +28,9 @@ struct calculate_min_bbr_for_all_inputs_params */ assess_physical_population_stability_params assess_population_stability_params{}; /** - * Parameters to identify the output pairs used to read the output. + * Parameters for the input BDL iterator. */ - detect_bdl_pairs_params detect_pair_params{}; + bdl_input_iterator_params bdl_iterator_params{}; }; /** * Calculates the minimum potential required to induce charge changes in an SiDB layout for all input combinations. @@ -67,9 +67,9 @@ template assert(std::adjacent_find(spec.begin(), spec.end(), [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.end()); - bdl_input_iterator bii{lyt, params.detect_pair_params}; + bdl_input_iterator bii{lyt, params.bdl_iterator_params}; - assert(bii.get_number_of_inputs() == spec.front().num_bits() / 2 && + assert(bii.num_input_pairs() == spec.front().num_bits() / 2 && "Number of truth table dimensions and input BDL pairs does not match"); double minimal_pop_stability_for_all_inputs = std::numeric_limits::infinity(); diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 771ccd133..5bcc14294 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -246,7 +246,7 @@ class defect_influence_operational_domain_impl void determine_nw_se_cells() noexcept { // bounding box around the given layout to have north-west and south-east cells. - const auto siqad_layout = convert_to_siqad_coordinates(layout); + const auto siqad_layout = convert_layout_to_siqad_coordinates(layout); bounding_box_2d bb{siqad_layout}; auto nw = fiction::siqad::to_fiction_coord(bb.get_min()); // north-west cell @@ -591,7 +591,7 @@ defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vecto static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); - static_assert(has_cube_coord_v || has_siqad_coord_v, "Lyt is not based on cube coordinates"); + static_assert(has_cube_coord_v); defect_influence_operational_domain_stats st{}; detail::defect_influence_operational_domain_impl p{lyt, spec, params, st}; diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index 62b004211..92c319c39 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -27,9 +27,9 @@ struct maximum_defect_influence_position_and_distance_of_sidb_gate_params */ maximum_defect_influence_position_and_distance_params defect_influence_params{}; /** - * Parameters for the detection of BDL pairs. + * Parameters for the input bDL iterator. */ - detect_bdl_pairs_params bdl_pairs_params{}; + bdl_input_iterator_params bdl_iterator_params{}; }; /** @@ -66,7 +66,7 @@ template assert(std::adjacent_find(spec.begin(), spec.end(), [](const auto& a, const auto& b) { return a.num_vars() != b.num_vars(); }) == spec.end()); - bdl_input_iterator bii{lyt, params.bdl_pairs_params}; + bdl_input_iterator bii{lyt, params.bdl_iterator_params}; double maximum_defect_influence_distance = 0.0; cell defect_cell{}; // number of different input combinations diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index d870bc4ec..c85a90e39 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -12,7 +12,6 @@ #include "fiction/algorithms/simulation/sidb/sidb_simulation_engine.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_result.hpp" -#include "fiction/layouts/cell_level_layout.hpp" #include "fiction/technology/cell_technologies.hpp" #include "fiction/technology/physical_constants.hpp" #include "fiction/traits.hpp" @@ -22,7 +21,6 @@ #include #include -#include #include #include #include @@ -34,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -285,10 +284,6 @@ struct operational_domain_stats * Number of parameter combinations, for which the layout is non-operational. */ std::size_t num_non_operational_parameter_combinations{0}; - /** - * The ratio of operational parameter pairs to all possible parameter pairs. Value is between 0 and 1. - */ - double percentual_operational_area{0.0}; }; namespace detail @@ -528,27 +523,16 @@ class operational_domain_impl * border around the domain. * * @param samples Maximum number of random samples to be taken before flood fill. - * @param initial_parameter Optional initial point in the parameter space for flood fill. * @return The (partial) operational domain of the layout. */ - [[nodiscard]] operational_domain - flood_fill(const std::size_t samples, const std::optional& initial_parameter) noexcept + [[nodiscard]] operational_domain flood_fill(const std::size_t samples) noexcept { assert((num_dimensions == 2 || num_dimensions == 3) && "Flood fill is only supported for two and three dimensions"); mockturtle::stopwatch stop{stats.time_total}; - std::set step_point_samples = {}; - - if (initial_parameter.has_value()) - { - step_point_samples.insert(to_step_point(initial_parameter.value())); - } - else - { - step_point_samples = generate_random_step_points(samples); - } + const auto step_point_samples = generate_random_step_points(samples); simulate_operational_status_in_parallel(step_point_samples); @@ -625,11 +609,10 @@ class operational_domain_impl * a one pixel wide border around it. * * @param samples Maximum number of random samples to be taken before contour tracing. - * @param initial_parameter Optional initial point in the parameter space for contour tracing. * @return The (partial) operational domain of the layout. */ [[nodiscard]] operational_domain - contour_tracing(const std::size_t samples, const std::optional& initial_parameter_point) noexcept + contour_tracing(const std::size_t samples) noexcept { assert(num_dimensions == 2 && "Contour tracing is only supported for two dimensions"); @@ -1566,14 +1549,6 @@ class operational_domain_impl ++stats.num_non_operational_parameter_combinations; } } - // calculate the total number of parameter pairs - const std::size_t total_parameter_pairs = - (static_cast(std::round((params.x_max - params.x_min) / params.x_step)) * - static_cast(std::round((params.y_max - params.y_min) / params.y_step))); - - // calculate the ratio of operational parameter pairs to the total number of parameter pairs - stats.percentual_operational_area = static_cast(stats.num_operational_parameter_combinations) / - static_cast(total_parameter_pairs); } }; @@ -1707,16 +1682,13 @@ operational_domain_random_sampling(const Lyt& lyt, const std::vector& spec, * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param samples Number of samples to perform. * @param params Operational domain computation parameters. - * @param initial_parameter_point Optional initial point in the parameter space for flood fill. * @param stats Operational domain computation statistics. * @return The (partial) operational domain of the layout. */ template operational_domain operational_domain_flood_fill(const Lyt& lyt, const std::vector& spec, const std::size_t samples, - const operational_domain_params& params = {}, - const std::optional& initial_parameter_point = std::nullopt, - operational_domain_stats* stats = nullptr) + const operational_domain_params& params = {}, operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -1734,7 +1706,7 @@ operational_domain_flood_fill(const Lyt& lyt, const std::vector& spec, const detail::operational_domain_impl> p{lyt, spec, params, st}; - const auto result = p.flood_fill(samples, initial_parameter_point); + const auto result = p.flood_fill(samples); if (stats) { @@ -1776,16 +1748,14 @@ operational_domain_flood_fill(const Lyt& lyt, const std::vector& spec, const * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param samples Number of samples to perform. * @param params Operational domain computation parameters. - * @param initial_parameter_point Optional initial point in the parameter space for contour tracing. * @param stats Operational domain computation statistics. * @return The (partial) operational domain of the layout. */ template operational_domain operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, const std::size_t samples, - const operational_domain_params& params = {}, - const std::optional& initial_parameter_point = std::nullopt, - operational_domain_stats* stats = nullptr) + const operational_domain_params& params = {}, + operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -1803,7 +1773,7 @@ operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, detail::operational_domain_impl> p{lyt, spec, params, st}; - const auto result = p.contour_tracing(samples, initial_parameter_point); + const auto result = p.contour_tracing(samples); if (stats) { diff --git a/include/fiction/io/write_defect_influence_operational_domain.hpp b/include/fiction/io/write_defect_influence_operational_domain.hpp index 7a978985f..ccab7bf87 100644 --- a/include/fiction/io/write_defect_influence_operational_domain.hpp +++ b/include/fiction/io/write_defect_influence_operational_domain.hpp @@ -1,5 +1,5 @@ // -// Created by marcel on 02.08.23. +// Created by Jan Drewniok on 05.03.2024. // #ifndef FICTION_WRITE_DEFECT_OPERATIONAL_DOMAIN_HPP @@ -18,16 +18,16 @@ namespace fiction { /** - * Parameters for writing an operational domain to a CSV file. + * Parameters for writing a defect influence operational domain to a CSV file. */ struct write_defect_operational_domain_params { /** - * The tag used to represent the operational value of a parameter set. + * The tag used to represent the operational value of a defect position. */ std::string_view operational_tag = "operational"; /** - * The tag used to represent the non-operational value of a parameter set. + * The tag used to represent the non-operational value of a defect position. */ std::string_view non_operational_tag = "non-operational"; }; @@ -43,14 +43,14 @@ struct write_defect_operational_domain_params * The operational status is a binary value represented by specified tags in `params` indicating whether the simulation * parameters are within the operational domain or not. * - * @param opdom The operational domain to be written. It contains a mapping from sets of simulation parameters + * @param defect_opdom The operational domain to be written. It contains a mapping from sets of simulation parameters * (represented as a pair of sweep parameters for the X and Y dimensions) to their operational status. * @param os The output stream where the CSV representation of the operational domain is written to. * @param params The parameters used for writing, including the operational and non-operational tags. Defaults to an * empty `write_defect_operational_domain_params` object, which provides standard tags. */ template -inline void write_defect_influence_operational_domain(const defect_influence_operational_domain& opdom, +inline void write_defect_influence_operational_domain(const defect_influence_operational_domain& defect_opdom, std::ostream& os, const write_defect_operational_domain_params& params = {}) { @@ -58,7 +58,7 @@ inline void write_defect_influence_operational_domain(const defect_influence_ope writer.write_line("x", "y", "operational status"); - for (const auto& [sim_param, op_val] : opdom.operational_values) + for (const auto& [sim_param, op_val] : defect_opdom.operational_values) { writer.write_line(sim_param.x, sim_param.y, op_val == operational_status::OPERATIONAL ? params.operational_tag : @@ -76,14 +76,14 @@ inline void write_defect_influence_operational_domain(const defect_influence_ope * The operational status is a binary value represented by specified tags in `params` indicating whether the simulation * parameters are within the operational domain or not. * - * @param opdom The operational domain to be written. It contains a mapping from sets of simulation parameters + * @param defect_opdom The operational domain to be written. It contains a mapping from sets of simulation parameters * (represented as a pair of sweep parameters for the X and Y dimensions) to their operational status. * @param filename The filename where the CSV representation of the operational domain is written to. * @param params The parameters used for writing, including the operational and non-operational tags. Defaults to an * empty `write_defect_operational_domain_params` object, which provides standard tags. */ template -inline void write_defect_influence_operational_domain(const defect_influence_operational_domain& opdom, +inline void write_defect_influence_operational_domain(const defect_influence_operational_domain& defect_opdom, const std::string_view& filename, const write_defect_operational_domain_params& params = {}) { @@ -94,7 +94,7 @@ inline void write_defect_influence_operational_domain(const defect_influence_ope throw std::ofstream::failure("could not open file"); } - write_defect_influence_operational_domain(opdom, os, params); + write_defect_influence_operational_domain(defect_opdom, os, params); os.close(); } diff --git a/test/algorithms/physical_design/design_sidb_gates.cpp b/test/algorithms/physical_design/design_sidb_gates.cpp index 10a818cd8..f55c02827 100644 --- a/test/algorithms/physical_design/design_sidb_gates.cpp +++ b/test/algorithms/physical_design/design_sidb_gates.cpp @@ -2,7 +2,7 @@ // Created by Jan Drewniok on 12.09.23. // -#include +#include #include #include @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -162,8 +163,9 @@ TEST_CASE("Use SiQAD's AND gate skeleton to generate all possible AND gates", "[ SECTION("Random Generation") { - const auto found_gate_layouts = - design_sidb_gates(lyt, std::vector{create_and_tt()}, params, design_sidb_gates_mode::RANDOM); + params.design_mode = + design_sidb_gates_params>::design_sidb_gates_mode::RANDOM; + const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_and_tt()}, params); CHECK(!found_gate_layouts.empty()); } } @@ -288,13 +290,12 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") {{14, 6, 0}, {24, 12, 0}}, 3}; - const auto found_gate_layouts = - design_sidb_gates(lyt, std::vector{create_and_tt()}, params, design_sidb_gates_mode::RANDOM); + const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_and_tt()}, params); REQUIRE(!found_gate_layouts.empty()); CHECK(found_gate_layouts.front().num_cells() == lyt.num_cells() + 3); } - SECTION("Random Generation with defects, random") + SECTION("Random Generation with defects") { sidb_defect_surface defect_layout{lyt}; @@ -314,8 +315,7 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") params.operational_params.simulation_parameters.lambda_tf}); defect_layout.assign_sidb_defect({23, 12, 0}, sidb_defect{sidb_defect_type::GUNK}); - const auto found_gate_layouts = - design_sidb_gates(defect_layout, std::vector{create_and_tt()}, params, design_sidb_gates_mode::RANDOM); + const auto found_gate_layouts = design_sidb_gates(defect_layout, std::vector{create_and_tt()}, params); REQUIRE(!found_gate_layouts.empty()); CHECK(found_gate_layouts.front().num_defects() == 3); CHECK(found_gate_layouts.front().num_cells() == lyt.num_cells() + 3); @@ -327,52 +327,6 @@ TEST_CASE("Design AND Bestagon shaped gate", "[design-sidb-gates]") CHECK(cell != siqad::coord_t{20, 12, 0}); }); } - - SECTION("Random Generation with defects, Simulated Annealing") - { - sidb_defect_surface defect_layout{lyt}; - - const design_sidb_gates_params params{sidb_simulation_parameters{2, -0.32}, - {{14, 6, 0}, {24, 12, 0}}, - 3, - sidb_simulation_engine::QUICKEXACT}; - - defect_layout.assign_sidb_defect({15, 10, 0}, - sidb_defect{sidb_defect_type::DB, -1, params.simulation_parameters.epsilon_r, - params.simulation_parameters.lambda_tf}); - defect_layout.assign_sidb_defect({20, 12, 0}, - sidb_defect{sidb_defect_type::DB, -1, params.simulation_parameters.epsilon_r, - params.simulation_parameters.lambda_tf}); - - const critical_temperature_params ct_params{params.simulation_parameters}; - const operational_domain_params op_params{params.simulation_parameters}; - - design_sidb_gates_metric_driven_simulated_annealing_params sa_params{}; - - sa_params.ct_params = ct_params; - sa_params.op_params = op_params; - sa_params.weight_temperature = -1.0; - sa_params.weight_operational_domain = -1.0; - sa_params.weight_non_operational = 10; - sa_params.final_temperature = 0.1; - sa_params.initial_temperature = 500; - sa_params.number_of_cycles = 1; - sa_params.op_params.x_step = 0.2; - sa_params.op_params.y_step = 0.2; - sa_params.op_params.x_min = 3; - sa_params.op_params.y_min = 3; - sa_params.op_params.x_max = 7; - sa_params.op_params.y_max = 7; - - const auto found_gate_layout = design_sidb_gates_metric_driven_simulated_annealing( - defect_layout, std::vector{create_and_tt()}, params, sa_params); - - CHECK(found_gate_layout.num_defects() == 2); - CHECK(found_gate_layout.num_cells() == lyt.num_cells() + 3); - - found_gate_layout.is_empty_cell(siqad::coord_t{15, 10, 0}); - found_gate_layout.is_empty_cell(siqad::coord_t{20, 12, 0}); - } } TEST_CASE("Design AND Bestagon shaped gate on H-Si 111", "[design-sidb-gates]") @@ -413,8 +367,7 @@ TEST_CASE("Design AND Bestagon shaped gate on H-Si 111", "[design-sidb-gates]") {{10, 11, 0}, {14, 15, 0}}, 3}; - const auto found_gate_layouts = - design_sidb_gates(lyt, std::vector{create_nor_tt()}, params, design_sidb_gates_mode::RANDOM); + const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_nor_tt()}, params); REQUIRE(!found_gate_layouts.empty()); CHECK(found_gate_layouts.front().num_cells() == lyt.num_cells() + 3); } @@ -427,8 +380,7 @@ TEST_CASE("Design AND Bestagon shaped gate on H-Si 111", "[design-sidb-gates]") {{11, 11, 0}, {14, 16, 0}}, 3}; - const auto found_gate_layouts = - design_sidb_gates(lyt, std::vector{create_nor_tt()}, params, design_sidb_gates_mode::EXHAUSTIVE); + const auto found_gate_layouts = design_sidb_gates(lyt, std::vector{create_nor_tt()}, params); REQUIRE(found_gate_layouts.size() == 52); CHECK(found_gate_layouts.front().num_cells() == lyt.num_cells() + 3); } diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 742ad60aa..1cb63aa13 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -61,7 +61,7 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - const auto cube_lyt = convert_to_fiction_coordinates(lyt); + const auto cube_lyt = convert_layout_to_fiction_coordinates(lyt); const sidb_defect sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}; const maximum_defect_influence_position_and_distance_params sim_params{sidb_defect, diff --git a/test/algorithms/simulation/sidb/operational_domain.cpp b/test/algorithms/simulation/sidb/operational_domain.cpp index 1f697ad24..f1bd44ade 100644 --- a/test/algorithms/simulation/sidb/operational_domain.cpp +++ b/test/algorithms/simulation/sidb/operational_domain.cpp @@ -381,7 +381,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 1, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() == 1); @@ -421,7 +421,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() == 1); @@ -487,7 +487,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 1, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() == 100); @@ -504,7 +504,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() <= 100); @@ -520,7 +520,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") } } - SECTION("operational area, different amount of steps in x and y direction") + SECTION("operational area, different number of steps in x- and y-direction") { // set x-dimension op_domain_params.sweep_dimensions[0].min = 5.1; @@ -617,7 +617,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 1, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() == 50); @@ -657,7 +657,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() <= 50); @@ -770,7 +770,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 25, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct maximum size CHECK(op_domain.operational_values.size() <= 100); @@ -811,7 +811,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 25, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct maximum size CHECK(op_domain.operational_values.size() <= 25); @@ -842,7 +842,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 10000, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() == 3); @@ -900,7 +900,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("flood_fill") { const auto op_domain = operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 50, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size CHECK(op_domain.operational_values.size() <= 256); @@ -917,7 +917,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 50, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 256); @@ -1007,10 +1007,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation", "[operational-domai SECTION("flood_fill") { const auto op_domain = - operational_domain_flood_fill(lat, std::vector{create_and_tt()}, 1, op_domain_params, - parameter_point{op_domain_params.simulation_parameters.epsilon_r, - op_domain_params.simulation_parameters.lambda_tf}, - &op_domain_stats); + operational_domain_flood_fill(lat, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); // check if the operational domain has the correct size (10 steps in each dimension) CHECK(op_domain.operational_values.size() == 100); @@ -1027,7 +1024,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation", "[operational-domai SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_and_tt()}, 1, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 100); @@ -1127,10 +1124,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat SECTION("flood_fill") { const auto op_domain = - operational_domain_flood_fill(lat, std::vector{create_and_tt()}, 1, op_domain_params, - parameter_point{op_domain_params.simulation_parameters.epsilon_r, - op_domain_params.simulation_parameters.lambda_tf}, - &op_domain_stats); + operational_domain_flood_fill(lat, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); // check if the operational domain has the correct size (10 steps in each dimension) CHECK(op_domain.operational_values.size() == 100); @@ -1146,11 +1140,8 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat } SECTION("contour_tracing") { - const auto op_domain = - operational_domain_contour_tracing(lat, std::vector{create_and_tt()}, 1, op_domain_params, - parameter_point{op_domain_params.simulation_parameters.epsilon_r, - op_domain_params.simulation_parameters.lambda_tf}, - &op_domain_stats); + const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_and_tt()}, 1, + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 100); @@ -1218,11 +1209,8 @@ TEMPLATE_TEST_CASE("AND gate on the H-Si(111)-1x1 surface", "[operational-domain } SECTION("flood_fill") { - const auto op_domain = - operational_domain_flood_fill(layout, std::vector{create_and_tt()}, 1, op_domain_params, - parameter_point{op_domain_params.simulation_parameters.epsilon_r, - op_domain_params.simulation_parameters.lambda_tf}, - &op_domain_stats); + const auto op_domain = operational_domain_flood_fill(layout, std::vector{create_and_tt()}, 1, + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size (10 steps in each dimension) CHECK(op_domain.operational_values.size() == 4); @@ -1239,7 +1227,7 @@ TEMPLATE_TEST_CASE("AND gate on the H-Si(111)-1x1 surface", "[operational-domain SECTION("contour_tracing") { const auto op_domain = operational_domain_contour_tracing(layout, std::vector{create_and_tt()}, 1, - op_domain_params, std::nullopt, &op_domain_stats); + op_domain_params, &op_domain_stats); // check if the operational domain has the correct size (max 10 steps in each dimension) CHECK(op_domain.operational_values.size() <= 4); From ae3727f78836f9d5e89f738d4e1aa7aef4ec7aba Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 20 Sep 2024 14:06:52 +0000 Subject: [PATCH 120/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/pybind11_mkdoc_docstrings.hpp | 207 +++--------------- 1 file changed, 27 insertions(+), 180 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index f63a5d148..e4cf56d83 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -952,7 +952,7 @@ static const char *__doc_fiction_calculate_min_bbr_for_all_inputs_params_assess_ R"doc(Parameters for the `assessing physical population stability` simulation)doc"; -static const char *__doc_fiction_calculate_min_bbr_for_all_inputs_params_detect_pair_params = R"doc(Parameters to identify the output pairs used to read the output.)doc"; +static const char *__doc_fiction_calculate_min_bbr_for_all_inputs_params_bdl_iterator_params = R"doc(Parameters for the input BDL iterator.)doc"; static const char *__doc_fiction_can_positive_charges_occur = R"doc(This algorithm determines if positively charged SiDBs can occur in a @@ -3269,8 +3269,6 @@ static const char *__doc_fiction_critical_temperature_stats_algorithm_name = R"doc(Name of the algorithm used to compute the physically valid charge distributions.)doc"; -static const char *__doc_fiction_critical_temperature_stats_critical_temperature = R"doc(*Critical Temperature* of the given layout (unit: K).)doc"; - static const char *__doc_fiction_critical_temperature_stats_duration = R"doc(The total runtime of the critical temperature computation.)doc"; static const char *__doc_fiction_critical_temperature_stats_energy_between_ground_state_and_first_erroneous = @@ -3759,12 +3757,12 @@ static const char *__doc_fiction_design_sidb_gates = R"doc(The *SiDB Gate Designer* designs SiDB gate implementations based on a specified Boolean function, a skeleton layout (can hold defects), canvas size, and a predetermined number of canvas SiDBs. Two different -design modes are implemented: `exhaustive` and `random`. +design modes are implemented: `exhaustive` and `random design`. The `exhaustive design` is composed of three steps: 1. In the initial step, all possible distributions of `number_of_sidbs` SiDBs within a given canvas are exhaustively determined. This ensures exhaustive -coverage of every potential arrangement of `number_of_sidbs` SiDBs +coverage of every potential arrangement of ``number_of_sidbs`` SiDBs across the canvas. 2. The calculated SiDB distributions are then incorporated into the skeleton, resulting in the generation of distinct SiDB layouts. 3. The generated SiDB layouts then undergo an @@ -3795,81 +3793,9 @@ Parameter ``spec``: Parameter ``params``: Parameters for the *SiDB Gate Designer*. -Parameter ``design_mode``: - The design mode to use. - -Parameter ``stats``: - The design statistics. - Returns: A vector of designed SiDB gate layouts.)doc"; -static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing = -R"doc(This function designs SiDB gates to minimize the cost function -:math:`\chi`, considering a layout skeleton, a set of truth tables, -and specified parameters for gate design and simulated annealing. -Currently, only the critical temperature and the operational domain -are incorporated into the cost function. - -Template parameter ``Lyt``: - SiDB cell-level layout type. - -Template parameter ``TT``: - The type of the truth table specifying the gate behavior. - -Parameter ``skeleton``: - The layout skeleton used as the basis for gate design. - -Parameter ``spec``: - Expected Boolean function of the layout given as a multi-output - truth table. - -Parameter ``params``: - The parameters for gate design. - -Parameter ``sa_params``: - Parameters for simulated annealing. - -Parameter ``stats``: - Statistics for gate design. - -Returns: - A layout with SiDB gates designed to minimize the cost function.)doc"; - -static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params = R"doc(Parameters for Simulated Annealing-based gate design.)doc"; - -static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_ct_params = R"doc(Parameters for simulating the Critical Temperature.)doc"; - -static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_final_temperature = R"doc(Final temperature for Simulated Annealing.)doc"; - -static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_initial_temperature = R"doc(Initial temperature for Simulated Annealing.)doc"; - -static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_number_of_cycles = R"doc(Number of iterations per temperature in Simulated Annealing.)doc"; - -static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_op_params = R"doc(Parameters for simulating the Operational Domain.)doc"; - -static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_schedule = R"doc(Type of temperature schedule used in Simulated Annealing.)doc"; - -static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_weight_non_operational = -R"doc(Weight assigned to the non-operational behavior in the overall cost -function. This weight affects the cost function when the design is -non-operational.)doc"; - -static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_weight_operational_domain = -R"doc(Weight assigned to the operational domain in the overall cost -function. A negative value indicates that this weight is not used.)doc"; - -static const char *__doc_fiction_design_sidb_gates_metric_driven_simulated_annealing_params_weight_temperature = -R"doc(Weight assigned to the critical temperature in the overall cost -function. A negative value indicates that a high critical temperature -is preferred.)doc"; - -static const char *__doc_fiction_design_sidb_gates_mode = R"doc(Selector for the available design approaches.)doc"; - -static const char *__doc_fiction_design_sidb_gates_mode_EXHAUSTIVE = R"doc(All gate layouts are designed exhaustively.)doc"; - -static const char *__doc_fiction_design_sidb_gates_mode_RANDOM = R"doc(Gate layouts are designed randomly.)doc"; - static const char *__doc_fiction_design_sidb_gates_params = R"doc(This struct contains parameters and settings to design SiDB gates. @@ -3878,9 +3804,13 @@ Template parameter ``CellType``: static const char *__doc_fiction_design_sidb_gates_params_canvas = R"doc(Canvas spanned by the northwest and southeast cell.)doc"; -static const char *__doc_fiction_design_sidb_gates_params_maximal_random_solutions = -R"doc(The number of gate implementations found before the random design -process is stopped.)doc"; +static const char *__doc_fiction_design_sidb_gates_params_design_mode = R"doc(Gate design mode.)doc"; + +static const char *__doc_fiction_design_sidb_gates_params_design_sidb_gates_mode = R"doc(Selector for the available design approaches.)doc"; + +static const char *__doc_fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE = R"doc(All gate layouts are designed exhaustively.)doc"; + +static const char *__doc_fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM = R"doc(Gate layouts are designed randomly.)doc"; static const char *__doc_fiction_design_sidb_gates_params_number_of_sidbs = R"doc(Number of SiDBs placed in the canvas to create a working gate.)doc"; @@ -3905,12 +3835,6 @@ static const char *__doc_fiction_design_sidb_gates_params_termination_condition_ R"doc(The design process ends after all possible combinations of SiDBs within the canvas are enumerated.)doc"; -static const char *__doc_fiction_design_sidb_gates_stats = R"doc(Statistics for the design of SiDB gates.)doc"; - -static const char *__doc_fiction_design_sidb_gates_stats_duration = R"doc(The total runtime of SiDB gate design process.)doc"; - -static const char *__doc_fiction_design_sidb_gates_stats_gate_cost = R"doc(The cost value of the final gate designed with Simulated Annealing.)doc"; - static const char *__doc_fiction_detail_a_star_impl = R"doc()doc"; static const char *__doc_fiction_detail_a_star_impl_a_star_impl = R"doc()doc"; @@ -4806,10 +4730,6 @@ Parameter ``cell_indices``: Returns: A vector of cells corresponding to the given indices.)doc"; -static const char *__doc_fiction_detail_design_sidb_gates_impl_canvas_sidbs = R"doc(All SiDBs within the canvas.)doc"; - -static const char *__doc_fiction_detail_design_sidb_gates_impl_canvas_sidbs_before_move = R"doc(Canvas SiDBs before move.)doc"; - static const char *__doc_fiction_detail_design_sidb_gates_impl_design_sidb_gates_impl = R"doc(This constructor initializes an instance of the *SiDB Gate Designer* implementation with the provided skeleton layout and configuration @@ -4823,47 +4743,12 @@ Parameter ``spec``: truth table. Parameter ``ps``: - Parameters and settings for the gate designer. - -Parameter ``st``: - Statistics for the gate designer.)doc"; - -static const char *__doc_fiction_detail_design_sidb_gates_impl_determine_canvas_sidbs = -R"doc(This function iterates over each cell in the provided layout `lyt` and -checks if the cell corresponds to a canvas SiDB. Canvas SiDBs are -defined as SiDBs that are part of the canvas region. It populates a -vector with the canvas SiDBs found in the layout and returns it. - -Parameter ``lyt``: - The layout from which canvas SiDBs are to be determined. - -Returns: - A vector containing the canvas SiDBs found in the layout.)doc"; - -static const char *__doc_fiction_detail_design_sidb_gates_impl_generator = R"doc(A random-number generator.)doc"; - -static const char *__doc_fiction_detail_design_sidb_gates_impl_move_sidb = -R"doc(This function randomly selects a canvas cell from the layout `lyt` and -a canvas SiDB to replace it with. It then moves the selected canvas -SiDB to the randomly chosen canvas cell, updating the layout -accordingly. If the randomly chosen canvas cell is not empty, the -layout remains unchanged. - -Parameter ``lyt``: - The layout from which a canvas SiDB is to be moved. - -Returns: - The layout after the canvas SiDB has been moved, or the original - layout if the randomly chosen canvas cell was not empty.)doc"; + Parameters and settings for the gate designer.)doc"; static const char *__doc_fiction_detail_design_sidb_gates_impl_num_threads = R"doc(Number of threads to be used for parallel execution.)doc"; static const char *__doc_fiction_detail_design_sidb_gates_impl_params = R"doc(Parameters for the *SiDB Gate Designer*.)doc"; -static const char *__doc_fiction_detail_design_sidb_gates_impl_random_canvas_cell_functor = R"doc()doc"; - -static const char *__doc_fiction_detail_design_sidb_gates_impl_random_canvas_sidb_functor = R"doc()doc"; - static const char *__doc_fiction_detail_design_sidb_gates_impl_run_exhaustive_design = R"doc(Design gates exhaustively and in parallel. @@ -4874,20 +4759,6 @@ parameters. The design process is parallelized to improve performance. Returns: A vector of designed SiDB gate layouts.)doc"; -static const char *__doc_fiction_detail_design_sidb_gates_impl_run_metric_driven_design_process = -R"doc(Design gates with Simulated Annealing. - -This function designs gates with Simulated Annealing. The cost -function involves the critical temperature and the operational domain. -The importance of the individual figures of merit can be adjusted by -the weights. - -Parameter ``sa_params``: - Simulated Annealing parameters. - -Returns: - Designed SiDB gate with minimal cost.)doc"; - static const char *__doc_fiction_detail_design_sidb_gates_impl_run_random_design = R"doc(Design gates randomly and in parallel. @@ -4898,28 +4769,11 @@ parameters. The design process is parallelized to improve performance. Returns: A vector of designed SiDB gate layouts.)doc"; -static const char *__doc_fiction_detail_design_sidb_gates_impl_sidb_moved_from_to = -R"doc(Canvas SiDB was moved from one cell (first cell) to another cell -(second cell).)doc"; - static const char *__doc_fiction_detail_design_sidb_gates_impl_skeleton_layout = R"doc(The skeleton layout serves as a starting layout to which SiDBs are added to create unique SiDB layouts and, if possible, working gates. It defines input and output wires.)doc"; -static const char *__doc_fiction_detail_design_sidb_gates_impl_skeleton_layout_with_canvas_sidbs = -R"doc(This function adds SiDBs (given by indices) to the skeleton layout -that is returned afterwards. - -Parameter ``cell_indices``: - A vector of indices of cells to be added to the skeleton layout. - -Returns: - A copy of the original layout (`skeleton_layout`) with SiDB cells - added at specified indices.)doc"; - -static const char *__doc_fiction_detail_design_sidb_gates_impl_stats = R"doc(The statistics of the gate design.)doc"; - static const char *__doc_fiction_detail_design_sidb_gates_impl_truth_table = R"doc(Truth table of the given gate.)doc"; static const char *__doc_fiction_detail_determine_clocking_impl = R"doc()doc"; @@ -7056,6 +6910,8 @@ static const char *__doc_fiction_detail_maximum_defect_influence_position_and_di static const char *__doc_fiction_detail_maximum_defect_influence_position_and_distance_impl_run = R"doc()doc"; +static const char *__doc_fiction_detail_maximum_defect_influence_position_and_distance_impl_stats = R"doc(The statistics of the maximum defect influence position.)doc"; + static const char *__doc_fiction_detail_nested_vector_hash = R"doc(This struct defines a hash function for a nested vector of layout tiles. It calculates a combined hash value for a vector of tiles based @@ -7073,8 +6929,6 @@ Parameter ``vec``: Returns: A combined hash value for the vector of tiles.)doc"; -static const char *__doc_fiction_detail_maximum_defect_influence_position_and_distance_impl_stats = R"doc(The statistics of the maximum defect influence position.)doc"; - static const char *__doc_fiction_detail_network_balancing_impl = R"doc()doc"; static const char *__doc_fiction_detail_network_balancing_impl_network_balancing_impl = R"doc()doc"; @@ -7131,9 +6985,6 @@ Parameter ``samples``: Maximum number of random samples to be taken before contour tracing. -Parameter ``initial_parameter``: - Optional initial point in the parameter space for contour tracing. - Returns: The (partial) operational domain of the layout.)doc"; @@ -7183,6 +7034,11 @@ one pixel wide border around the domain. Parameter ``samples``: Maximum number of random samples to be taken before flood fill. +Parameter ``given_parameter_point``: + Optional parameter point in the parameter space. If it lies within + the operational region, it is used as a starting point for flood + fill. + Returns: The (partial) operational domain of the layout.)doc"; @@ -13576,7 +13432,7 @@ R"doc(Parameters for the `maximum_defect_influence_position_and_distance_of_sidb_gate` algorithm.)doc"; -static const char *__doc_fiction_maximum_defect_influence_position_and_distance_of_sidb_gate_params_bdl_pairs_params = R"doc(Parameters for the detection of BDL pairs.)doc"; +static const char *__doc_fiction_maximum_defect_influence_position_and_distance_of_sidb_gate_params_bdl_iterator_params = R"doc(Parameters for the input bDL iterator.)doc"; static const char *__doc_fiction_maximum_defect_influence_position_and_distance_of_sidb_gate_params_defect_influence_params = R"doc(Parameters for the defect influence simulation.)doc"; @@ -14209,9 +14065,6 @@ Parameter ``samples``: Parameter ``params``: Operational domain computation parameters. -Parameter ``initial_parameter_point``: - Optional initial point in the parameter space for contour tracing. - Parameter ``stats``: Operational domain computation statistics. @@ -14276,9 +14129,6 @@ Parameter ``samples``: Parameter ``params``: Operational domain computation parameters. -Parameter ``initial_parameter_point``: - Optional initial point in the parameter space for flood fill. - Parameter ``stats``: Operational domain computation statistics. @@ -14440,11 +14290,6 @@ R"doc(A range of values for a dimension sweep. The range is defined by a minimum value, a maximum value and a step size.)doc"; static const char *__doc_fiction_operational_domain_value_range_dimension = R"doc(The sweep parameter of the dimension.)doc"; -static const char *__doc_fiction_operational_domain_stats_percentual_operational_area = -R"doc(The ratio of operational parameter pairs to all possible parameter -pairs. Value is between 0 and 1.)doc"; - -static const char *__doc_fiction_operational_domain_x_dimension = R"doc(X dimension sweep parameter.)doc"; static const char *__doc_fiction_operational_domain_value_range_max = R"doc(The maximum value of the dimension sweep.)doc"; @@ -18014,7 +17859,7 @@ The operational status is a binary value represented by specified tags in `params` indicating whether the simulation parameters are within the operational domain or not. -Parameter ``opdom``: +Parameter ``defect_opdom``: The operational domain to be written. It contains a mapping from sets of simulation parameters (represented as a pair of sweep parameters for the X and Y dimensions) to their operational @@ -18043,7 +17888,7 @@ The operational status is a binary value represented by specified tags in `params` indicating whether the simulation parameters are within the operational domain or not. -Parameter ``opdom``: +Parameter ``defect_opdom``: The operational domain to be written. It contains a mapping from sets of simulation parameters (represented as a pair of sweep parameters for the X and Y dimensions) to their operational @@ -18059,13 +17904,15 @@ Parameter ``params``: `write_defect_operational_domain_params` object, which provides standard tags.)doc"; -static const char *__doc_fiction_write_defect_operational_domain_params = R"doc(Parameters for writing an operational domain to a CSV file.)doc"; +static const char *__doc_fiction_write_defect_operational_domain_params = +R"doc(Parameters for writing a defect influence operational domain to a CSV +file.)doc"; static const char *__doc_fiction_write_defect_operational_domain_params_non_operational_tag = -R"doc(The tag used to represent the non-operational value of a parameter -set.)doc"; +R"doc(The tag used to represent the non-operational value of a defect +position.)doc"; -static const char *__doc_fiction_write_defect_operational_domain_params_operational_tag = R"doc(The tag used to represent the operational value of a parameter set.)doc"; +static const char *__doc_fiction_write_defect_operational_domain_params_operational_tag = R"doc(The tag used to represent the operational value of a defect position.)doc"; static const char *__doc_fiction_write_dot_layout = R"doc(! Writes layout in DOT format into output stream From abf84cd9c428408b3c97fc5576b2e6082b8a8229 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 20 Sep 2024 16:18:37 +0200 Subject: [PATCH 121/221] :art: add comments. --- .../algorithms/physical_design/design_sidb_gates.hpp | 7 +++---- .../sidb/assess_physical_population_stability.hpp | 1 - .../sidb/determine_physically_valid_parameters.hpp | 3 +-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp index 0502865a5..ca9f50353 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp @@ -36,12 +36,11 @@ inline void design_sidb_gates(pybind11::module& m) /** * Design approach selector type. */ - // todo update docstrings pybind11::enum_::design_sidb_gates_mode>( - m, "design_sidb_gates_mode") + m, "design_sidb_gates_mode", DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode)) .value("EXHAUSTIVE", - fiction::design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE) - .value("RANDOM", fiction::design_sidb_gates_params::design_sidb_gates_mode::RANDOM); + fiction::design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE)) + .value("RANDOM", fiction::design_sidb_gates_params::design_sidb_gates_mode::RANDOM, DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM)); /** * Parameters. diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index e6c36e7a9..3b74f16b1 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -41,7 +41,6 @@ void assess_physical_population_stability(pybind11::module& m, const std::string .def_readwrite("system_energy", &fiction::population_stability_information::system_energy, DOC(fiction_population_stability_information_system_energy)); - // TODO add docu. m.def(fmt::format("assess_physical_population_stability{}", lattice).c_str(), &fiction::assess_physical_population_stability, "lyt"_a, "params"_a = fiction::assess_physical_population_stability_params{}, diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp index 0cff96e1c..021d44674 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp @@ -26,7 +26,7 @@ void determine_physically_valid_parameters(pybind11::module& m) using namespace pybind11::literals; m.def("determine_physically_valid_parameters", &fiction::determine_physically_valid_parameters, "cds"_a, - "params"_a = fiction::operational_domain_params{}); + "params"_a = fiction::operational_domain_params{}, DOC(fiction_determine_physically_valid_parameters)); } } // namespace detail @@ -38,7 +38,6 @@ inline void determine_physically_valid_parameters(pybind11::module& m) py::class_>(m, "physically_valid_parameters_domain", DOC(fiction_operational_domain)) - // todo add docu .def(py::init<>()) .def_readwrite("dimensions", &fiction::operational_domain::dimensions) From 7739a161678bba31a3181251b13a51ad98958ccd Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 20 Sep 2024 16:34:48 +0200 Subject: [PATCH 122/221] :art: small fix. --- .../simulation/sidb/critical_temperature.cpp | 4 +-- test/utils/blueprints/layout_blueprints.hpp | 31 ------------------- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/test/algorithms/simulation/sidb/critical_temperature.cpp b/test/algorithms/simulation/sidb/critical_temperature.cpp index f1226c1ab..2a6daf728 100644 --- a/test/algorithms/simulation/sidb/critical_temperature.cpp +++ b/test/algorithms/simulation/sidb/critical_temperature.cpp @@ -360,11 +360,11 @@ TEMPLATE_TEST_CASE("Test critical_temperature function", "[critical-temperature] params.iteration_steps = 80; params.alpha = 0.7; - critical_temperature_gate_based(lyt, std::vector{create_crossing_wire_tt()}, params, &critical_stats); + const auto ct = critical_temperature_gate_based(lyt, std::vector{create_crossing_wire_tt()}, params, &critical_stats); CHECK_THAT(std::fabs(critical_stats.energy_between_ground_state_and_first_erroneous - 0.32), Catch::Matchers::WithinAbs(0.00, 0.01)); - CHECK_THAT(std::abs(critical_stats.critical_temperature - 0.85), Catch::Matchers::WithinAbs(0.00, 0.01)); + CHECK_THAT(std::abs(ct - 0.85), Catch::Matchers::WithinAbs(0.00, 0.01)); } SECTION("SiQAD OR gate") diff --git a/test/utils/blueprints/layout_blueprints.hpp b/test/utils/blueprints/layout_blueprints.hpp index 52739df80..4b30fc59f 100644 --- a/test/utils/blueprints/layout_blueprints.hpp +++ b/test/utils/blueprints/layout_blueprints.hpp @@ -721,37 +721,6 @@ CellLyt single_layer_inml_crosswire() noexcept return layout; } -/** - * This layout represents the AND Gate, as proposed in the paper - * titled \"SiQAD: A Design and Simulation Tool for Atomic Silicon Quantum Dot Circuits\". - */ -template -Lyt siqad_and_gate() noexcept -{ - static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); - static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); - - Lyt lyt{}; - - lyt.assign_cell_type({0, 0, 1}, Lyt::cell_type::INPUT); - lyt.assign_cell_type({2, 1, 1}, Lyt::cell_type::INPUT); - - lyt.assign_cell_type({20, 0, 1}, Lyt::cell_type::INPUT); - lyt.assign_cell_type({18, 1, 1}, Lyt::cell_type::INPUT); - - lyt.assign_cell_type({4, 2, 1}, Lyt::cell_type::NORMAL); - lyt.assign_cell_type({6, 3, 1}, Lyt::cell_type::NORMAL); - - lyt.assign_cell_type({14, 3, 1}, Lyt::cell_type::NORMAL); - lyt.assign_cell_type({16, 2, 1}, Lyt::cell_type::NORMAL); - - lyt.assign_cell_type({10, 6, 0}, Lyt::cell_type::OUTPUT); - lyt.assign_cell_type({10, 7, 0}, Lyt::cell_type::OUTPUT); - - lyt.assign_cell_type({10, 9, 1}, Lyt::cell_type::NORMAL); - - return lyt; -}; /** * This layout represents a BDL wire comprising of 3 BDL pairs and an output perturber SiDB. * From 728f892942317744b95a258578833b6e3170e6a0 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 20 Sep 2024 16:36:36 +0200 Subject: [PATCH 123/221] :art: delete superfluous header file --- test/algorithms/simulation/sidb/critical_temperature.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/algorithms/simulation/sidb/critical_temperature.cpp b/test/algorithms/simulation/sidb/critical_temperature.cpp index 2a6daf728..2f4246435 100644 --- a/test/algorithms/simulation/sidb/critical_temperature.cpp +++ b/test/algorithms/simulation/sidb/critical_temperature.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include From ee6c60fec17ecb8afa77619d428cdbaed51af867 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 2 Oct 2024 15:02:00 +0200 Subject: [PATCH 124/221] :art: small changes --- .../and/21_hex_inputsdbp_and_v19.sqd | 218 ++++++++++++++++++ .../defect_avoidance_distance.cpp | 91 ++++---- ...avoidance_distance_checking_robustness.cpp | 120 ++++++++++ ...g_robustness_with_newly_designed_gates.cpp | 126 ++++++++++ .../defect_influence_operational_domain.hpp | 74 ++++-- 5 files changed, 570 insertions(+), 59 deletions(-) create mode 100644 experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd create mode 100644 experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp create mode 100644 experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp diff --git a/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd b/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd new file mode 100644 index 000000000..73c247a41 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd @@ -0,0 +1,218 @@ + + + + + save + 0.3.3 + 2023-08-08 17:47:07 + + + + 0.0518456 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp index fa12cd373..f7d7faef1 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp @@ -1,4 +1,5 @@ #include "fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp" + #include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" @@ -20,83 +21,93 @@ using namespace fiction; -int main() { - experiments::experiment simulation_exp{ - "Benchmark", "Gate Name", "distance_grid_search", "#samples", - "distance_random", "#samples", "distance_contour", "#samples", - }; - - static const std::string folder = fmt::format("{}bestagon_gates_type_tags/", EXPERIMENTS_PATH); +int main() +{ + experiments::experiment + simulation_exp{ + "Benchmark", "Gate Name", "Num SiDBs", + "x_coord", "y_coord", "distance_grid_search", + "#samples_grid", "distance_random", "#samples_random", + "distance_contour", "#samples_contour", + }; + + static const std::string folder = fmt::format("{}bestagon_gates_type_tags/", EXPERIMENTS_PATH); static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); - static const std::array>, 9> gates = {{ - {"and", {create_and_tt()}}, - {"xor", {create_xor_tt()}}, - {"or", {create_or_tt()}}, - {"xnor", {create_xnor_tt()}}, - {"fo2", {create_fan_out_tt()}}, - {"nor", {create_nor_tt()}}, - {"nand", {create_nand_tt()}}, - {"inv", {create_not_tt()}}, - {"wire", {create_id_tt()}}, - }}; - - const auto sidb_sim = sidb_simulation_parameters{2, -0.32, 5.6, 5.0}; + static const std::array>, 10> gates = { + std::make_pair("and", std::vector{create_and_tt()}), + std::make_pair("nand", std::vector{create_nand_tt()}), + std::make_pair("nor", std::vector{create_nor_tt()}), + std::make_pair("xnor", std::vector{create_xnor_tt()}), + std::make_pair("xor", std::vector{create_xor_tt()}), + std::make_pair("or", std::vector{create_or_tt()}), + std::make_pair("wire", std::vector{create_id_tt()}), + std::make_pair("wire_diag", std::vector{create_id_tt()}), + std::make_pair("inv", std::vector{create_not_tt()}), + std::make_pair("inv_diag", std::vector{create_not_tt()})}; + + const auto sidb_sim = sidb_simulation_parameters{2, -0.32, 5.6, 5.0}; const is_operational_params is_op_params{sidb_sim}; maximum_defect_influence_position_and_distance_params max_defect_params{}; - max_defect_params.defect = sidb_defect{ - fiction::sidb_defect_type::UNKNOWN, -1, is_op_params.simulation_parameters.epsilon_r, - is_op_params.simulation_parameters.lambda_tf - }; + max_defect_params.defect = + sidb_defect{fiction::sidb_defect_type::UNKNOWN, -1, is_op_params.simulation_parameters.epsilon_r, + is_op_params.simulation_parameters.lambda_tf}; max_defect_params.additional_scanning_area = {50, 50}; defect_influence_operational_domain_params defect_params{}; defect_params.defect_influence_params = max_defect_params; - defect_params.operational_params = is_op_params; + defect_params.operational_params = is_op_params; + + std::size_t total_number_samples = 0; - for (const auto& [gate, truth_table] : gates) { + for (const auto& [gate, truth_table] : gates) + { // Create gate directory for plots std::string gate_folder = fmt::format("{}{}/", output_folder, gate); std::filesystem::create_directories(gate_folder); - for (const auto& file : std::filesystem::directory_iterator(fmt::format("{}{}", folder, gate))) { + for (const auto& file : std::filesystem::directory_iterator(fmt::format("{}{}", folder, gate))) + { const auto layout = read_sqd_layout(file.path().string()); defect_influence_operational_domain_stats grid_stats{}; - const auto op_defect_grid_search = defect_influence_operational_domain_grid_search( - layout, truth_table, 1, defect_params, &grid_stats); + const auto op_defect_grid = + defect_influence_operational_domain_grid_search(layout, truth_table, 1, defect_params, &grid_stats); // Define file paths for the CSV and SQD - const auto csv_path = fmt::format("{}{}_grid_search.csv", gate_folder, gate); + const auto csv_path = fmt::format("{}{}_grid.csv", gate_folder, gate); const auto sqd_path = fmt::format("{}/{}.sqd", gate_folder, gate); // Write the CSV file - write_defect_influence_operational_domain(op_defect_grid_search, csv_path); + write_defect_influence_operational_domain(op_defect_grid, csv_path); // Write the SQD layout write_sqd_layout(layout, sqd_path); - const auto avoidance_grid = defect_avoidance_distance(layout, op_defect_grid_search); + const auto avoidance_grid = defect_avoidance_distance(layout, op_defect_grid); defect_influence_operational_domain_stats random_stats{}; - const auto op_defect_random_search = defect_influence_operational_domain_random_sampling( + const auto op_defect_random = defect_influence_operational_domain_random_sampling( layout, truth_table, 100, defect_params, &random_stats); - const auto avoidance_random = defect_avoidance_distance(layout, op_defect_random_search); + const auto avoidance_random = defect_avoidance_distance(layout, op_defect_random); const auto csv_path_random = fmt::format("{}{}_random.csv", gate_folder, gate); - write_defect_influence_operational_domain(op_defect_random_search, csv_path_random); + write_defect_influence_operational_domain(op_defect_random, csv_path_random); defect_influence_operational_domain_stats contour_stats{}; - const auto op_defect_contour_search = defect_influence_operational_domain_contour_tracing( - layout, truth_table, 1, defect_params, &contour_stats); - const auto avoidance_contour = defect_avoidance_distance(layout, op_defect_contour_search); + const auto op_defect_contour = defect_influence_operational_domain_contour_tracing( + layout, truth_table, 100, defect_params, &contour_stats); + const auto avoidance_contour = defect_avoidance_distance(layout, op_defect_contour); const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); - write_defect_influence_operational_domain(op_defect_contour_search, csv_path_contour); + write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); // Log the simulation results - simulation_exp(gate, avoidance_grid.max_min_distance, grid_stats.num_evaluated_defect_positions, + simulation_exp(gate, layout.num_cells(), avoidance_grid.max_distance_postion_of_non_operational_defect.x, + avoidance_grid.max_distance_postion_of_non_operational_defect.y, + avoidance_grid.max_min_distance, grid_stats.num_evaluated_defect_positions, avoidance_random.max_min_distance, random_stats.num_evaluated_defect_positions, avoidance_contour.max_min_distance, contour_stats.num_evaluated_defect_positions); simulation_exp.save(); diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp new file mode 100644 index 000000000..9bdbc2e60 --- /dev/null +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp @@ -0,0 +1,120 @@ +#include "fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp" + +#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" +#include "fiction/algorithms/simulation/sidb/is_operational.hpp" +#include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" +#include "fiction/io/read_sqd_layout.hpp" +#include "fiction/io/write_defect_influence_operational_domain.hpp" +#include "fiction/io/write_sqd_layout.hpp" +#include "fiction/types.hpp" +#include "fiction/utils/truth_table_utils.hpp" +#include "fiction_experiments.hpp" + +#include + +#include +#include +#include +#include +#include +#include + +using namespace fiction; + +int main() +{ + experiments::experiment + simulation_exp{ + "Benchmark", "Gate Name", "instance count", "#samples_grid", "#sample_contour", "#unequal" + }; + + static const std::string folder = fmt::format("{}defect_avoidance_distance/fom_data/sqd/", EXPERIMENTS_PATH); + static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); + + static const std::array>, 10> gates = { + std::make_pair("and", std::vector{create_and_tt()}), + std::make_pair("nand", std::vector{create_nand_tt()}), + std::make_pair("nor", std::vector{create_nor_tt()}), + std::make_pair("xnor", std::vector{create_xnor_tt()}), + std::make_pair("xor", std::vector{create_xor_tt()}), + std::make_pair("or", std::vector{create_or_tt()}), + std::make_pair("ge", std::vector{create_ge_tt()}), + std::make_pair("gt", std::vector{create_gt_tt()}), + std::make_pair("le", std::vector{create_le_tt()}), + std::make_pair("lt", std::vector{create_lt_tt()})}; + + const auto sidb_sim = sidb_simulation_parameters{2, -0.32, 5.6, 5.0}; + const is_operational_params is_op_params{sidb_sim}; + + maximum_defect_influence_position_and_distance_params max_defect_params{}; + max_defect_params.defect = + sidb_defect{fiction::sidb_defect_type::UNKNOWN, -1, is_op_params.simulation_parameters.epsilon_r, + is_op_params.simulation_parameters.lambda_tf}; + max_defect_params.additional_scanning_area = {50, 50}; + + defect_influence_operational_domain_params defect_params{}; + defect_params.defect_influence_params = max_defect_params; + defect_params.operational_params = is_op_params; + + for (const auto& [gate, truth_table] : gates) + { + // Create gate directory for plots + std::string gate_folder = fmt::format("{}{}/", output_folder, gate); + std::filesystem::create_directories(gate_folder); + + std::size_t gate_counter = 0; + std::size_t unequal_counter = 0; + std::size_t sample_grid_counter = 0; + std::size_t sample_contour_counter = 0; + + for (const auto& file : std::filesystem::directory_iterator(fmt::format("{}{}", folder, gate))) + { + gate_counter++; + const auto layout = read_sqd_layout(file.path().string()); + + defect_influence_operational_domain_stats grid_stats{}; + const auto op_defect_grid = + defect_influence_operational_domain_grid_search(layout, truth_table, 1, defect_params, &grid_stats); + + // Define file paths for the CSV and SQD + const auto csv_path = fmt::format("{}{}_grid.csv", gate_folder, gate); + const auto sqd_path = fmt::format("{}/{}.sqd", gate_folder, gate); + + // Write the CSV file + write_defect_influence_operational_domain(op_defect_grid, csv_path); + + // Write the SQD layout + write_sqd_layout(layout, sqd_path); + + const auto avoidance_grid = defect_avoidance_distance(layout, op_defect_grid); + + defect_influence_operational_domain_stats random_stats{}; + const auto op_defect_random = defect_influence_operational_domain_random_sampling( + layout, truth_table, 100, defect_params, &random_stats); + const auto avoidance_random = defect_avoidance_distance(layout, op_defect_random); + + const auto csv_path_random = fmt::format("{}{}_random.csv", gate_folder, gate); + write_defect_influence_operational_domain(op_defect_random, csv_path_random); + + defect_influence_operational_domain_stats contour_stats{}; + const auto op_defect_contour = defect_influence_operational_domain_contour_tracing( + layout, truth_table, 100, defect_params, &contour_stats); + const auto avoidance_contour = defect_avoidance_distance(layout, op_defect_contour); + + const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); + write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); + + sample_grid_counter += grid_stats.num_evaluated_defect_positions; + sample_contour_counter += contour_stats.num_evaluated_defect_positions; + + if (std::abs(avoidance_grid.max_min_distance - avoidance_contour.max_min_distance) > 0.1) + { // Log the simulation results + unequal_counter++; + } + } + simulation_exp(gate, gate_counter, sample_grid_counter, sample_contour_counter, unequal_counter); + simulation_exp.save(); + simulation_exp.table(); + } + return EXIT_SUCCESS; +} diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp new file mode 100644 index 000000000..cd2ca1c21 --- /dev/null +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp @@ -0,0 +1,126 @@ +#include "fiction/algorithms/physical_design/design_sidb_gates.hpp" +#include "fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp" +#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" +#include "fiction/algorithms/simulation/sidb/is_operational.hpp" +#include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" +#include "fiction/io/read_sqd_layout.hpp" +#include "fiction/io/write_defect_influence_operational_domain.hpp" +#include "fiction/io/write_sqd_layout.hpp" +#include "fiction/types.hpp" +#include "fiction/traits.hpp" +#include "fiction/utils/truth_table_utils.hpp" +#include "fiction_experiments.hpp" + +#include + +#include +#include +#include +#include +#include +#include + +using namespace fiction; + +int main() +{ + experiments::experiment simulation_exp{ + "Benchmark", "Gate Name", "distance_grid_search", "#samples_grid", + "distance_random", "#samples_random", "distance_contour", "#samples_contour", + }; + + static const std::string folder = fmt::format("{}bestagon_gates_type_tags/", EXPERIMENTS_PATH); + static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); + + static const std::array>, 1> gates = {{{"and", {create_and_tt()}}}}; + + auto lyt = + read_sqd_layout("/Users/jandrewniok/CLionProjects/fiction_fork/experiments/" + "skeleton_efficient_gate_designer/skeleton_hex_inputsdbp_2i1o.sqd"); + + const design_sidb_gates_params> params_2_in_1_out{ + is_operational_params{sidb_simulation_parameters{2, -0.32}}, + design_sidb_gates_params>::design_sidb_gates_mode::EXHAUSTIVE, + {{14, 12, 0}, {24, 23, 0}}, + 3}; + + const auto sidb_sim = sidb_simulation_parameters{2, -0.32, 5.6, 5.0}; + const is_operational_params is_op_params{sidb_sim}; + + maximum_defect_influence_position_and_distance_params max_defect_params{}; + max_defect_params.defect = + sidb_defect{fiction::sidb_defect_type::UNKNOWN, -1, is_op_params.simulation_parameters.epsilon_r, + is_op_params.simulation_parameters.lambda_tf}; + max_defect_params.additional_scanning_area = {50, 50}; + + defect_influence_operational_domain_params defect_params{}; + defect_params.defect_influence_params = max_defect_params; + defect_params.operational_params = is_op_params; + + for (const auto& [gate, truth_table] : gates) + { + const auto exhaustive_design = design_sidb_gates(lyt, truth_table, params_2_in_1_out); + std::cout << exhaustive_design.size() << std::endl; + // Create gate directory for plots + std::string gate_folder = fmt::format("{}{}/", output_folder, gate); + std::filesystem::create_directories(gate_folder); + + uint64_t counter = 0; + for (const auto& gate_lyt : exhaustive_design) + { + defect_influence_operational_domain_stats grid_stats{}; + const auto op_defect_grid = + defect_influence_operational_domain_grid_search(gate_lyt, truth_table, 1, defect_params, &grid_stats); + + // Define file paths for the CSV and SQD + const auto csv_path = fmt::format("{}{}_grid.csv", gate_folder, gate); + const auto sqd_path = fmt::format("{}/{}.sqd", gate_folder, gate); + + // Write the CSV file + write_defect_influence_operational_domain(op_defect_grid, csv_path); + + // Write the SQD layout + // write_sqd_layout(layout, sqd_path); + + const auto avoidance_grid = defect_avoidance_distance(gate_lyt, op_defect_grid); + + defect_influence_operational_domain_stats random_stats{}; + const auto op_defect_random = defect_influence_operational_domain_random_sampling( + gate_lyt, truth_table, 100, defect_params, &random_stats); + const auto avoidance_random = defect_avoidance_distance(gate_lyt, op_defect_random); + + const auto csv_path_random = fmt::format("{}{}_random.csv", gate_folder, gate); + write_defect_influence_operational_domain(op_defect_random, csv_path_random); + + defect_influence_operational_domain_stats contour_stats{}; + const auto op_defect_contour = defect_influence_operational_domain_contour_tracing( + gate_lyt, truth_table, 1, defect_params, &contour_stats); + const auto avoidance_contour = defect_avoidance_distance(gate_lyt, op_defect_contour); + + const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); + write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); + // + // simulation_exp(gate, avoidance_grid.max_min_distance, + // grid_stats.num_evaluated_defect_positions, + // avoidance_random.max_min_distance, random_stats.num_evaluated_defect_positions, + // avoidance_contour.max_min_distance, + // contour_stats.num_evaluated_defect_positions); + // simulation_exp.save(); + // simulation_exp.table(); + + if (std::abs(avoidance_grid.max_min_distance - avoidance_contour.max_min_distance) > 0.1) + { // Log the simulation results + write_sqd_layout(gate_lyt, sqd_path); + write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); + simulation_exp(gate, avoidance_grid.max_min_distance, grid_stats.num_evaluated_defect_positions, + avoidance_random.max_min_distance, random_stats.num_evaluated_defect_positions, + avoidance_contour.max_min_distance, contour_stats.num_evaluated_defect_positions); + simulation_exp.save(); + simulation_exp.table(); + } + counter++; + std::cout << counter << std::endl; + } + } + return EXIT_SUCCESS; +} diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 5bcc14294..aa42c5c6b 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace fiction { @@ -104,17 +105,38 @@ class defect_influence_operational_domain_impl [[nodiscard]] defect_influence_operational_domain grid_search(const std::size_t& step_size) noexcept { mockturtle::stopwatch stop{stats.time_total}; - const auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); + const auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); + const std::size_t num_positions = all_possible_defect_positions.size(); - // Iterate through all possible defect positions, but make sure that the position is distributed on a grid - // defined by `step_size'. - for (std::size_t i = 0; i < all_possible_defect_positions.size(); i += step_size) - { - if (static_cast(std::abs(all_possible_defect_positions[i].x)) % step_size == 0 && - static_cast(std::abs(all_possible_defect_positions[i].y)) % step_size == 0) + const auto num_threads = std::thread::hardware_concurrency(); // Get the number of hardware threads + + // Determine the chunk size (each thread will process a chunk of positions) + std::size_t chunk_size = (num_positions + num_threads - 1) / num_threads; // Distribute positions evenly + + // Define a lambda function that processes a chunk of defect positions + auto process_chunk = [&](std::size_t start, std::size_t end) { + for (std::size_t i = start; i < end; i += step_size) { - is_defect_position_operational(all_possible_defect_positions[i]); + if (static_cast(std::abs(all_possible_defect_positions[i].x)) % step_size == 0 && + static_cast(std::abs(all_possible_defect_positions[i].y)) % step_size == 0) + { + is_defect_position_operational(all_possible_defect_positions[i]); + } } + }; + + // Launch multiple threads to process the chunks + std::vector> futures; + for (std::size_t start = 0; start < num_positions; start += chunk_size) + { + std::size_t end = std::min(start + chunk_size, num_positions); // Make sure the end doesn't exceed the array size + futures.emplace_back(std::async(std::launch::async, process_chunk, start, end)); + } + + // Wait for all threads to complete + for (auto& future : futures) + { + future.get(); // Ensure each thread finishes } log_stats(); @@ -197,7 +219,9 @@ class defect_influence_operational_domain_impl current_neighborhood.front() : next_clockwise_point(current_neighborhood, backtrack_point); - bool contour_goes_around_layout = false; + bool contour_goes_around_se_layout_corner = true; + bool contour_goes_around_ne_layout_corner = true; + bool contour_goes_around_nw_layout_corner = true; uint64_t counter = 0; while (next_point != contour_starting_point && counter < 100000) @@ -206,7 +230,17 @@ class defect_influence_operational_domain_impl // check if the contour goes around the layout. if (next_point.x >= se_bb_layout.x && next_point.y >= se_bb_layout.y) { - contour_goes_around_layout = true; + contour_goes_around_se_layout_corner = true; + } + + if (next_point.x >= se_bb_layout.x && next_point.y <= nw_bb_layout.y) + { + contour_goes_around_ne_layout_corner = true; + } + + if (next_point.x <= nw_bb_layout.x && next_point.y <= nw_bb_layout.y) + { + contour_goes_around_nw_layout_corner = true; } assert(layout.num_defects() == 0 && "more than one defect"); @@ -226,15 +260,17 @@ class defect_influence_operational_domain_impl counter++; } number_of_random_start_positions++; - if (!contour_goes_around_layout) - { - continue; - } - log_stats(); - return defect_operational_domain; +// if (!contour_goes_around_se_layout_corner || !contour_goes_around_ne_layout_corner || !contour_goes_around_nw_layout_corner) +// { +// if (number_of_random_start_positions == samples) +// { +// stats = defect_influence_operational_domain_stats{}; +// defect_operational_domain = defect_influence_operational_domain{}; // return an empty domain +// } +// continue; +// } } log_stats(); - return defect_operational_domain; } @@ -275,7 +311,7 @@ class defect_influence_operational_domain_impl std::random_device rd; std::mt19937 gen(rd()); // Create a distribution for generating random numbers within the specified range - std::uniform_int_distribution dist(nw_bb_layout.y, se_bb_layout.y); + std::uniform_int_distribution dist(nw_cell.y, se_cell.y); starting_point.y = dist(gen); layout.assign_sidb_defect(starting_point, params.defect_influence_params.defect); // determine the operational status @@ -374,7 +410,7 @@ class defect_influence_operational_domain_impl previous_defect_position = starting_defect_position; // move towards the left border of the parameter range - for (auto x = starting_defect_position.x; x <= se_bb_layout.x; x++) + for (auto x = starting_defect_position.x; x <= se_cell.x; x++) { previous_defect_position = current_defect_position; current_defect_position = {x, starting_defect_position.y}; From 08b82cbf48824681185abbd08cbf1e086935ede8 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 2 Oct 2024 18:24:13 +0200 Subject: [PATCH 125/221] :art: small changes. --- .../defect_avoidance_distance_checking_robustness.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp index 9bdbc2e60..dab8062ea 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp @@ -50,7 +50,7 @@ int main() max_defect_params.defect = sidb_defect{fiction::sidb_defect_type::UNKNOWN, -1, is_op_params.simulation_parameters.epsilon_r, is_op_params.simulation_parameters.lambda_tf}; - max_defect_params.additional_scanning_area = {50, 50}; + max_defect_params.additional_scanning_area = {100, 100}; defect_influence_operational_domain_params defect_params{}; defect_params.defect_influence_params = max_defect_params; From 2bce91c6986605e942de25b57956ae4d25639e11 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 14 Oct 2024 07:17:12 +0200 Subject: [PATCH 126/221] :art: experiments. --- .../defect_avoidance_distance.cpp | 13 ++------- ...avoidance_distance_checking_robustness.cpp | 29 ++++++++++++------- ...g_robustness_with_newly_designed_gates.cpp | 4 +-- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp index f7d7faef1..6d8c6fd93 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp @@ -36,16 +36,7 @@ int main() static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); static const std::array>, 10> gates = { - std::make_pair("and", std::vector{create_and_tt()}), - std::make_pair("nand", std::vector{create_nand_tt()}), - std::make_pair("nor", std::vector{create_nor_tt()}), - std::make_pair("xnor", std::vector{create_xnor_tt()}), - std::make_pair("xor", std::vector{create_xor_tt()}), - std::make_pair("or", std::vector{create_or_tt()}), - std::make_pair("wire", std::vector{create_id_tt()}), - std::make_pair("wire_diag", std::vector{create_id_tt()}), - std::make_pair("inv", std::vector{create_not_tt()}), - std::make_pair("inv_diag", std::vector{create_not_tt()})}; + std::make_pair("nor", std::vector{create_nor_tt()})}; const auto sidb_sim = sidb_simulation_parameters{2, -0.32, 5.6, 5.0}; const is_operational_params is_op_params{sidb_sim}; @@ -98,7 +89,7 @@ int main() defect_influence_operational_domain_stats contour_stats{}; const auto op_defect_contour = defect_influence_operational_domain_contour_tracing( - layout, truth_table, 100, defect_params, &contour_stats); + layout, truth_table, 5, defect_params, &contour_stats); const auto avoidance_contour = defect_avoidance_distance(layout, op_defect_contour); const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp index dab8062ea..22c9b196e 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp @@ -32,8 +32,6 @@ int main() static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); static const std::array>, 10> gates = { - std::make_pair("and", std::vector{create_and_tt()}), - std::make_pair("nand", std::vector{create_nand_tt()}), std::make_pair("nor", std::vector{create_nor_tt()}), std::make_pair("xnor", std::vector{create_xnor_tt()}), std::make_pair("xor", std::vector{create_xor_tt()}), @@ -67,11 +65,24 @@ int main() std::size_t sample_grid_counter = 0; std::size_t sample_contour_counter = 0; + bool start_with_new_boolean_function = false; + for (const auto& file : std::filesystem::directory_iterator(fmt::format("{}{}", folder, gate))) { - gate_counter++; + if (gate_counter == 100) + { + start_with_new_boolean_function = true; + break; + } const auto layout = read_sqd_layout(file.path().string()); + if (layout.num_cells() != 22) + { + continue; + } + gate_counter++; + std::cout << gate_counter << std::endl; + defect_influence_operational_domain_stats grid_stats{}; const auto op_defect_grid = defect_influence_operational_domain_grid_search(layout, truth_table, 1, defect_params, &grid_stats); @@ -88,13 +99,6 @@ int main() const auto avoidance_grid = defect_avoidance_distance(layout, op_defect_grid); - defect_influence_operational_domain_stats random_stats{}; - const auto op_defect_random = defect_influence_operational_domain_random_sampling( - layout, truth_table, 100, defect_params, &random_stats); - const auto avoidance_random = defect_avoidance_distance(layout, op_defect_random); - - const auto csv_path_random = fmt::format("{}{}_random.csv", gate_folder, gate); - write_defect_influence_operational_domain(op_defect_random, csv_path_random); defect_influence_operational_domain_stats contour_stats{}; const auto op_defect_contour = defect_influence_operational_domain_contour_tracing( @@ -110,11 +114,16 @@ int main() if (std::abs(avoidance_grid.max_min_distance - avoidance_contour.max_min_distance) > 0.1) { // Log the simulation results unequal_counter++; + std::cout << file.path().string() << std::endl; } } simulation_exp(gate, gate_counter, sample_grid_counter, sample_contour_counter, unequal_counter); simulation_exp.save(); simulation_exp.table(); + if (start_with_new_boolean_function) + { + continue; + } } return EXIT_SUCCESS; } diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp index cd2ca1c21..1d25a2819 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp @@ -51,7 +51,7 @@ int main() max_defect_params.defect = sidb_defect{fiction::sidb_defect_type::UNKNOWN, -1, is_op_params.simulation_parameters.epsilon_r, is_op_params.simulation_parameters.lambda_tf}; - max_defect_params.additional_scanning_area = {50, 50}; + max_defect_params.additional_scanning_area = {100, 100}; defect_influence_operational_domain_params defect_params{}; defect_params.defect_influence_params = max_defect_params; @@ -94,7 +94,7 @@ int main() defect_influence_operational_domain_stats contour_stats{}; const auto op_defect_contour = defect_influence_operational_domain_contour_tracing( - gate_lyt, truth_table, 1, defect_params, &contour_stats); + gate_lyt, truth_table, 100, defect_params, &contour_stats); const auto avoidance_contour = defect_avoidance_distance(gate_lyt, op_defect_contour); const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); From 1ea65b5f7e8797e5f333fbb3714b673d80f31edf Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 18 Oct 2024 15:52:04 +0200 Subject: [PATCH 127/221] :art: several changes. --- .../physical_design/apply_gate_library.hpp | 3 +- .../defect_influence_operational_domain.hpp | 88 ++++++++++++ .../determine_physically_valid_parameters.hpp | 2 +- ...defect_influence_position_and_distance.hpp | 13 +- .../pyfiction/inout/read_sqd_layout.hpp | 34 +++-- .../pyfiction/layouts/cell_level_layout.hpp | 4 +- .../pyfiction/technology/sidb_lattice.hpp | 80 +++++++++-- .../pyfiction/include/pyfiction/types.hpp | 51 +++++-- bindings/pyfiction/pyfiction.cpp | 13 +- .../sidb/test_defect_operational_domain.py | 30 ++++ .../defect_avoidance_distance.cpp | 17 ++- ...avoidance_distance_checking_robustness.cpp | 15 +- .../defect_influence_operational_domain.hpp | 136 +++++++++++------- ...defect_influence_position_and_distance.hpp | 6 +- .../simulation/sidb/operational_domain.hpp | 55 +++---- .../defect_influence_operational_domain.cpp | 22 ++- .../determine_physically_valid_parameters.cpp | 60 ++++---- 17 files changed, 439 insertions(+), 190 deletions(-) create mode 100644 bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp create mode 100644 bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py diff --git a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/apply_gate_library.hpp b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/apply_gate_library.hpp index 4d666bf9a..26850cabf 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/apply_gate_library.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/apply_gate_library.hpp @@ -32,7 +32,8 @@ void apply_fcn_gate_library(pybind11::module& m, const std::string& lib_name) { using namespace pybind11::literals; - using py_cartesian_technology_cell_layout = py_cartesian_cell_layout>; + using py_cartesian_technology_cell_layout = + py_cartesian_cell_layout, py_cartesian_clocked_layout>; m.def(fmt::format("apply_{}_library", lib_name).c_str(), &fiction::apply_gate_library, "layout"_a, diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp new file mode 100644 index 000000000..8c217c4db --- /dev/null +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -0,0 +1,88 @@ +// +// Created by Jan Drewniok 18.10.2024 +// + +#ifndef PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP +#define PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP + +#include "pyfiction/documentation.hpp" +#include "pyfiction/types.hpp" + +#include + +#include +#include +#include + +#include + +namespace pyfiction +{ + +namespace detail +{ + +// todo add docu + +template +void defect_influence_operational_domain_detail(pybind11::module& m) +{ + using namespace pybind11::literals; + + m.def("defect_influence_operational_domain_grid_search", + &fiction::defect_influence_operational_domain_grid_search, "lyt"_a, "spec"_a, "step_size"_a, + "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr); + + m.def("defect_influence_operational_domain_random_sampling", + &fiction::defect_influence_operational_domain_random_sampling, "lyt"_a, "spec"_a, "samples"_a, + "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr); + + m.def("defect_influence_operational_contour_tracing", + &fiction::defect_influence_operational_domain_contour_tracing, "lyt"_a, "spec"_a, "samples"_a, + "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr); +} + +} // namespace detail + +inline void defect_influence_operational_domain(pybind11::module& m) +{ + namespace py = pybind11; + using namespace pybind11::literals; + + py::class_>( + m, "defect_influence_operational_domain_100") + .def(py::init<>()); + + py::class_>( + m, "defect_influence_operational_domain_111") + .def(py::init<>()); + + py::class_(m, "defect_influence_operational_domain_params") + .def(py::init<>()) + .def_readwrite("defect_influence_params", + &fiction::defect_influence_operational_domain_params::defect_influence_params) + .def_readwrite("operational_params", &fiction::defect_influence_operational_domain_params::operational_params); + + py::class_(m, "defect_influence_operational_domain_stats") + .def(py::init<>()) + .def_readonly("time_total", &fiction::defect_influence_operational_domain_stats::time_total) + .def_readonly("num_simulator_invocations", + &fiction::defect_influence_operational_domain_stats::num_simulator_invocations) + .def_readonly("num_evaluated_parameter_combinations", + &fiction::defect_influence_operational_domain_stats::num_evaluated_defect_positions) + .def_readonly("num_operational_defect_positions", + &fiction::defect_influence_operational_domain_stats::num_operational_defect_positions) + .def_readonly("num_operational_defect_positions", + &fiction::defect_influence_operational_domain_stats::num_operational_defect_positions) + .def_readonly("num_non_operational_defect_positions", + &fiction::defect_influence_operational_domain_stats::num_operational_defect_positions); + + // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! + + detail::defect_influence_operational_domain_detail(m); + detail::defect_influence_operational_domain_detail(m); +} + +} // namespace pyfiction + +#endif // PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp index 021d44674..7419aaedf 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp @@ -48,7 +48,7 @@ inline void determine_physically_valid_parameters(pybind11::module& m) { try { - return domain.get_value(pp); + return domain.get_value(pp).value(); } catch (const std::out_of_range& e) { diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index ef0cb85b2..3c4736e54 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -26,7 +26,7 @@ void maximum_defect_influence_distance(pybind11::module& m) m.def("maximum_defect_influence_position_and_distance", &fiction::maximum_defect_influence_position_and_distance, "lyt"_a, - "params"_a = fiction::maximum_defect_influence_position_and_distance_params{}, + "params"_a = fiction::maximum_defect_influence_position_and_distance_params{}, "stats"_a = nullptr, DOC(fiction_maximum_defect_influence_position_and_distance)); } @@ -36,18 +36,19 @@ inline void maximum_defect_influence_distance(pybind11::module& m) { namespace py = pybind11; - py::class_(m, "maximum_defect_influence_distance_params") + py::class_(m, "maximum_defect_influence_distance_params") .def(py::init<>()) - .def_readwrite("defect", &fiction::maximum_defect_influence_distance_params::defect) - .def_readwrite("sim_params", &fiction::maximum_defect_influence_distance_params::simulation_parameters) + .def_readwrite("defect", &fiction::maximum_defect_influence_position_and_distance_params::defect) + .def_readwrite("sim_params", &fiction::maximum_defect_influence_position_and_distance_params::simulation_parameters) .def_readwrite("additional_scanning_area", - &fiction::maximum_defect_influence_distance_params::additional_scanning_area) + &fiction::maximum_defect_influence_position_and_distance_params::additional_scanning_area) ; // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! - detail::maximum_defect_influence_distance(m); + detail::maximum_defect_influence_distance(m); + detail::maximum_defect_influence_distance(m); } } // namespace pyfiction diff --git a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp index fc55ed4cc..6add9b6f6 100644 --- a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp @@ -28,19 +28,27 @@ void read_sqd_layout(pybind11::module& m) py::register_exception(m, "sqd_parsing_error", PyExc_RuntimeError); - if constexpr (fiction::is_sidb_lattice_100_v) - { - Lyt (*read_sqd_layout_function_pointer)(const std::string_view&, const std::string_view&) = - &fiction::read_sqd_layout; + // Common function pointer for all cases + Lyt (*read_sqd_layout_function_pointer)(const std::string_view&, const std::string_view&) = + &fiction::read_sqd_layout; + if constexpr (fiction::is_sidb_lattice_100_v && fiction::has_cube_coord_v) + { + m.def("read_sqd_layout_100_cube", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", + DOC(fiction_read_sqd_layout_3)); + } + else if constexpr (fiction::is_sidb_lattice_100_v && !fiction::has_cube_coord_v) + { m.def("read_sqd_layout_100", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", DOC(fiction_read_sqd_layout_3)); } - else + else if constexpr (fiction::is_sidb_lattice_111_v && fiction::has_cube_coord_v) + { + m.def("read_sqd_layout_111_cube", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", + DOC(fiction_read_sqd_layout_3)); + } + else if constexpr (fiction::is_sidb_lattice_111_v && !fiction::has_cube_coord_v) { - Lyt (*read_sqd_layout_function_pointer)(const std::string_view&, const std::string_view&) = - &fiction::read_sqd_layout; - m.def("read_sqd_layout_111", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", DOC(fiction_read_sqd_layout_3)); } @@ -58,6 +66,16 @@ inline void read_sqd_layout_111(pybind11::module& m) detail::read_sqd_layout(m); } +inline void read_sqd_layout_100_cube(pybind11::module& m) +{ + detail::read_sqd_layout(m); +} + +inline void read_sqd_layout_111_cube(pybind11::module& m) +{ + detail::read_sqd_layout(m); +} + } // namespace pyfiction #endif // PYFICTION_READ_SQD_LAYOUT_HPP diff --git a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp index 2f7b006b1..9510caf87 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp @@ -74,14 +74,14 @@ void fcn_technology_cell_level_layout(pybind11::module& m) } // NOTE: more technologies go here - using py_cartesian_technology_cell_layout = py_cartesian_cell_layout; + using py_cartesian_technology_cell_layout = py_cartesian_cell_layout; /** * Cell-level clocked Cartesian layout. */ py::class_< py_cartesian_technology_cell_layout, - fiction::clocked_layout>>>( + py_cartesian_clocked_layout>( m, fmt::format("{}_layout", tech_name).c_str(), DOC(fiction_cell_level_layout)) .def(py::init<>()) .def(py::init&>(), "dimension"_a, diff --git a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp index 40acb09e4..eff9655c3 100644 --- a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp +++ b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp @@ -23,36 +23,90 @@ namespace pyfiction namespace detail { -template +/** + * Template function to bind SiDB lattices (regular and cube-coordinate) to Python. + * + * @tparam LatticeOrientation The lattice orientation (e.g., fiction::sidb_100_lattice, fiction::sidb_111_lattice). + * @tparam LayoutType The layout type (e.g., py_sidb_layout for regular layouts, py_sidb_layout_cube for cube layouts). + */ +template void sidb_lattice_cell_level_layout(pybind11::module& m) { namespace py = pybind11; - using namespace pybind11::literals; + using namespace py::literals; - // fetch technology name + // Fetch the lattice orientation name and convert to lowercase auto orientation = std::string{fiction::sidb_lattice_name}; std::transform(orientation.begin(), orientation.end(), orientation.begin(), ::tolower); - using py_sidb_lattice = py_sidb_lattice; + // Define the type alias for the specific SiDB lattice layout being bound + using py_sidb_lattice = fiction::sidb_lattice; /** * SiDB lattice. */ - py::class_(m, fmt::format("sidb_{}_lattice", orientation).c_str(), + if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) + { + py::class_(m, "sidb_100_lattice_cube", DOC(fiction_cell_level_layout), py::module_local()) - .def(py::init<>()) - .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", - DOC(fiction_sidb_lattice)) - - ; + .def(py::init<>()) // Default constructor + .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", + DOC(fiction_sidb_lattice)) // Constructor with aspect ratio and name + ; + } + if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) + { + py::class_(m, "sidb_111_lattice_cube", + DOC(fiction_cell_level_layout), py::module_local()) + .def(py::init<>()) // Default constructor + .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", + DOC(fiction_sidb_lattice)) // Constructor with aspect ratio and name + ; + } + if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) + { + py::class_(m, "sidb_100_lattice", + DOC(fiction_cell_level_layout), py::module_local()) + .def(py::init<>()) // Default constructor + .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", + DOC(fiction_sidb_lattice)); + } + if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) + { + py::class_(m, "sidb_111_lattice", + DOC(fiction_cell_level_layout), py::module_local()) + .def(py::init<>()) // Default constructor + .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", + DOC(fiction_sidb_lattice)); + } } } // namespace detail -inline void sidb_lattices(pybind11::module& m) + +inline void sidb_lattices_100_cube(pybind11::module& m) +{ + // Bind the cube-coordinate 100 and 111 SiDB lattices + detail::sidb_lattice_cell_level_layout(m); +} + +inline void sidb_lattices_111(pybind11::module& m) +{ + + detail::sidb_lattice_cell_level_layout(m); +} + +inline void sidb_lattices_100(pybind11::module& m) +{ + // Bind the regular 100 and 111 SiDB lattices + detail::sidb_lattice_cell_level_layout(m); +} + + +inline void sidb_lattices_111_cube(pybind11::module& m) { - detail::sidb_lattice_cell_level_layout(m); - detail::sidb_lattice_cell_level_layout(m); + // Bind the regular 100 and 111 SiDB lattices + detail::sidb_lattice_cell_level_layout(m); } } // namespace pyfiction diff --git a/bindings/pyfiction/include/pyfiction/types.hpp b/bindings/pyfiction/include/pyfiction/types.hpp index 14b914fda..7ffccac8d 100644 --- a/bindings/pyfiction/include/pyfiction/types.hpp +++ b/bindings/pyfiction/include/pyfiction/types.hpp @@ -44,6 +44,10 @@ using py_siqad_coordinate = fiction::siqad::coord_t; * Cartesian layout. */ using py_cartesian_layout = fiction::cartesian_layout; +/** + * Cartesian layout based on cube coordinates. + */ +using py_cartesian_layout_cube = fiction::cartesian_layout; /** * Shifted Cartesian layout. */ @@ -57,6 +61,10 @@ using py_hexagonal_layout = fiction::hexagonal_layout>; +/** + * Cartesian clocked layout based on cube coordinate. + */ +using py_cartesian_clocked_layout_cube = fiction::clocked_layout>; /** * Shifted Cartesian clocked layout. */ @@ -93,34 +101,47 @@ using py_hexagonal_obstruction_layout = fiction::obstruction_layout -using py_cartesian_cell_layout = fiction::cell_level_layout; +template +using py_cartesian_cell_layout = fiction::cell_level_layout; /** * QCA cell layout. */ -using py_qca_layout = py_cartesian_cell_layout; +using py_qca_layout = py_cartesian_cell_layout; /** * iNML cell layout. */ -using py_inml_layout = py_cartesian_cell_layout; +using py_inml_layout = py_cartesian_cell_layout; /** * SiDB cell layout. */ -using py_sidb_layout = py_cartesian_cell_layout; +using py_sidb_layout = py_cartesian_cell_layout; +/** + * SiDB cell layout. + */ +using py_sidb_layout_cube = py_cartesian_cell_layout; /** * SiDB lattice layout. */ -template -using py_sidb_lattice = fiction::sidb_lattice; +template +using py_sidb_lattice = fiction::sidb_lattice; /** * SiDB cell layout (with specified H-Si(100)-2x1 lattice orientation). */ -using py_sidb_100_lattice = py_sidb_lattice; +using py_sidb_100_lattice = py_sidb_lattice; /** * SiDB cell layout (with specified H-Si(111)-1x1 lattice orientation). */ -using py_sidb_111_lattice = py_sidb_lattice; +using py_sidb_111_lattice = py_sidb_lattice; + +/** + * SiDB cell layout (with specified H-Si(100)-2x1 lattice orientation). + */ +using py_sidb_100_lattice_cube = py_sidb_lattice; +/** + * SiDB cell layout (with specified H-Si(111)-1x1 lattice orientation). + */ +using py_sidb_111_lattice_cube = py_sidb_lattice; /** * Charge distribution surface. This is a special SiDB cell-level layout that is used for the SiDB simulation @@ -132,6 +153,9 @@ using py_charge_distribution_surface_layout = fiction::charge_distribution_surfa using py_charge_distribution_surface = fiction::charge_distribution_surface; + +using py_charge_distribution_surface_cube = fiction::charge_distribution_surface; + /** * Charge distribution surface with underlying H-Si(100)-2x1 lattice. */ @@ -141,6 +165,15 @@ using py_charge_distribution_surface_100 = py_charge_distribution_surface_layout */ using py_charge_distribution_surface_111 = py_charge_distribution_surface_layout; +/** + * Charge distribution surface with underlying H-Si(100)-2x1 lattice based on cube coordinates. + */ +using py_charge_distribution_surface_100_cube = py_charge_distribution_surface_layout; +/** + * Charge distribution surface with underlying H-Si(111)-1x1 lattice based on cube coordinates. + */ +using py_charge_distribution_surface_111_cube = py_charge_distribution_surface_layout; + } // namespace pyfiction #endif // PYFICTION_TYPES_HPP diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index c89094ff6..cbe929aaa 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -36,7 +36,7 @@ #include "pyfiction/algorithms/simulation/sidb/exhaustive_ground_state_simulation.hpp" #include "pyfiction/algorithms/simulation/sidb/is_ground_state.hpp" #include "pyfiction/algorithms/simulation/sidb/is_operational.hpp" -// #include "pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" +#include "pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" #include "pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp" #include "pyfiction/algorithms/simulation/sidb/check_simulation_results_for_equivalence.hpp" #include "pyfiction/algorithms/simulation/sidb/convert_potential_to_distance.hpp" @@ -134,7 +134,8 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::detect_bdl_pairs(m); pyfiction::is_operational(m); pyfiction::operational_domain(m); - // pyfiction::maximum_defect_influence_distance(m); + // pyfiction::defect_influence_operational_domain(m); + // pyfiction::maximum_defect_influence_distance(m); pyfiction::exhaustive_ground_state_simulation(m); pyfiction::quicksim(m); pyfiction::quickexact(m); @@ -197,7 +198,10 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::sidb_charge_state(m); pyfiction::sidb_nm_position(m); pyfiction::sidb_nm_distance(m); - pyfiction::sidb_lattices(m); + pyfiction::sidb_lattices_100(m); + //pyfiction::sidb_lattices_100_cube(m); + pyfiction::sidb_lattices_111(m); + //pyfiction::sidb_lattices_111_cube(m); pyfiction::charge_distribution_surfaces(m); /** * Input/Output @@ -217,6 +221,9 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::read_fqca_layout(m); pyfiction::read_sqd_layout_100(m); pyfiction::read_sqd_layout_111(m); + pyfiction::read_sqd_layout_100_cube(m); + pyfiction::read_sqd_layout_111_cube(m); + /** * Utils */ diff --git a/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py b/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py new file mode 100644 index 000000000..c579de6e4 --- /dev/null +++ b/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py @@ -0,0 +1,30 @@ +import os +import unittest + +from mnt.pyfiction import * + +dir_path = os.path.dirname(os.path.realpath(__file__)) + + +class TestOperationalDomain(unittest.TestCase): + + def test_xor_gate_100_lattice(self): + lyt = read_sqd_layout_100_cube(dir_path + "/../../../resources/hex_21_inputsdbp_xor_v1.sqd") + + params = defect_influence_operational_domain_params() + params.defect_influence_params.additional_scanning_area = (20, 20) + + stats_grid = defect_influence_operational_domain_stats() + _ = defect_influence_operational_domain_grid_search(lyt, [create_xor_tt()], params, 3, stats_grid) + self.assertGreater(stats_grid.num_operational_parameter_combinations, 0) + + stats_random = defect_influence_operational_domain_stats() + _ = defect_influence_operational_domain_grid_search(lyt, [create_xor_tt()], params, 100, stats_random) + self.assertGreater(stats_random.num_operational_parameter_combinations, 0) + + stats_contour_tracing = defect_influence_operational_domain_stats() + _ = defect_influence_operational_domain_contour_tracing(lyt, [create_xor_tt()], params, 20, stats_contour_tracing) + self.assertGreater(stats_contour_tracing.num_operational_parameter_combinations, 0) + +if __name__ == '__main__': + unittest.main() diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp index 6d8c6fd93..dac1c4365 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp @@ -18,6 +18,7 @@ #include #include #include +#include using namespace fiction; @@ -35,8 +36,16 @@ int main() static const std::string folder = fmt::format("{}bestagon_gates_type_tags/", EXPERIMENTS_PATH); static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); - static const std::array>, 10> gates = { - std::make_pair("nor", std::vector{create_nor_tt()})}; + static const std::array>, 9> gates = { + std::make_pair("and", std::vector{create_and_tt()}), + std::make_pair("xor", std::vector{create_xor_tt()}), + std::make_pair("or", std::vector{create_or_tt()}), + std::make_pair("xnor", std::vector{create_xnor_tt()}), + std::make_pair("fo2", std::vector{create_fan_out_tt()}), + std::make_pair("nor", std::vector{create_nor_tt()}), + std::make_pair("nand", std::vector{create_nand_tt()}), + std::make_pair("inv", std::vector{create_not_tt()}), + std::make_pair("wire", std::vector{create_id_tt()})}; const auto sidb_sim = sidb_simulation_parameters{2, -0.32, 5.6, 5.0}; const is_operational_params is_op_params{sidb_sim}; @@ -51,8 +60,6 @@ int main() defect_params.defect_influence_params = max_defect_params; defect_params.operational_params = is_op_params; - std::size_t total_number_samples = 0; - for (const auto& [gate, truth_table] : gates) { // Create gate directory for plots @@ -89,7 +96,7 @@ int main() defect_influence_operational_domain_stats contour_stats{}; const auto op_defect_contour = defect_influence_operational_domain_contour_tracing( - layout, truth_table, 5, defect_params, &contour_stats); + layout, truth_table, 20, defect_params, &contour_stats); const auto avoidance_contour = defect_avoidance_distance(layout, op_defect_contour); const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp index 22c9b196e..23e72140f 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp @@ -31,15 +31,16 @@ int main() static const std::string folder = fmt::format("{}defect_avoidance_distance/fom_data/sqd/", EXPERIMENTS_PATH); static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); - static const std::array>, 10> gates = { - std::make_pair("nor", std::vector{create_nor_tt()}), - std::make_pair("xnor", std::vector{create_xnor_tt()}), + static const std::array>, 9> gates = { + std::make_pair("and", std::vector{create_and_tt()}), std::make_pair("xor", std::vector{create_xor_tt()}), std::make_pair("or", std::vector{create_or_tt()}), - std::make_pair("ge", std::vector{create_ge_tt()}), - std::make_pair("gt", std::vector{create_gt_tt()}), - std::make_pair("le", std::vector{create_le_tt()}), - std::make_pair("lt", std::vector{create_lt_tt()})}; + std::make_pair("xnor", std::vector{create_xnor_tt()}), + std::make_pair("fo2", std::vector{create_fan_out_tt()}), + std::make_pair("nor", std::vector{create_nor_tt()}), + std::make_pair("nand", std::vector{create_nand_tt()}), + std::make_pair("inv", std::vector{create_not_tt()}), + std::make_pair("wire", std::vector{create_id_tt()})}; const auto sidb_sim = sidb_simulation_parameters{2, -0.32, 5.6, 5.0}; const is_operational_params is_op_params{sidb_sim}; diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index aa42c5c6b..f4593f1a7 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -17,14 +17,17 @@ #include #include +#include #include #include #include #include +#include #include #include +#include +#include #include -#include namespace fiction { @@ -102,19 +105,29 @@ class defect_influence_operational_domain_impl determine_nw_se_cells(); } + /** + * This function divides the search space (defined by `nw_cell` and `se_cell`) into chunks, each processed by a + * different thread. The search checks if defect positions in the grid are operational based on a given step size. + * Each thread processes a chunk of positions in parallel to improve performance. + * + * @param step_size The step size used to sample defect positions in the grid. Only positions with x and y + * coordinates divisible by `step_size` will be checked for being operational. + * @return A `defect_influence_operational_domain` object representing the operational domain of the defects. + */ [[nodiscard]] defect_influence_operational_domain grid_search(const std::size_t& step_size) noexcept { mockturtle::stopwatch stop{stats.time_total}; - const auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); - const std::size_t num_positions = all_possible_defect_positions.size(); + const auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); + const std::size_t num_positions = all_possible_defect_positions.size(); - const auto num_threads = std::thread::hardware_concurrency(); // Get the number of hardware threads + const auto num_threads = std::thread::hardware_concurrency(); // Get the number of hardware threads // Determine the chunk size (each thread will process a chunk of positions) - std::size_t chunk_size = (num_positions + num_threads - 1) / num_threads; // Distribute positions evenly + std::size_t chunk_size = (num_positions + num_threads - 1) / num_threads; // Distribute positions evenly // Define a lambda function that processes a chunk of defect positions - auto process_chunk = [&](std::size_t start, std::size_t end) { + auto process_chunk = [&](std::size_t start, std::size_t end) + { for (std::size_t i = start; i < end; i += step_size) { if (static_cast(std::abs(all_possible_defect_positions[i].x)) % step_size == 0 && @@ -126,17 +139,18 @@ class defect_influence_operational_domain_impl }; // Launch multiple threads to process the chunks - std::vector> futures; + std::vector> futures{}; + for (std::size_t start = 0; start < num_positions; start += chunk_size) { - std::size_t end = std::min(start + chunk_size, num_positions); // Make sure the end doesn't exceed the array size + std::size_t end = std::min(start + chunk_size, num_positions); futures.emplace_back(std::async(std::launch::async, process_chunk, start, end)); } // Wait for all threads to complete for (auto& future : futures) { - future.get(); // Ensure each thread finishes + future.get(); // Ensure each thread finishes } log_stats(); @@ -144,26 +158,67 @@ class defect_influence_operational_domain_impl return defect_operational_domain; } + /** + * This function performs random sampling of defect positions from a grid area (spanned by `nw_cell` and `se_cell`). + * The positions are shuffled and divided into chunks, which are processed by different threads to check if each + * defect position is operational. Each thread handles a subset of the defect positions to improve performance. + * + * @param samples The number of positions to sample. The actual number of iterations will be the smaller of + * the total number of positions or the `samples` value. + * @return A `defect_influence_operational_domain` object representing the operational domain of the defects. + * The return value is marked [[nodiscard]], meaning it must be used by the caller. + */ [[nodiscard]] defect_influence_operational_domain random_sampling(const std::size_t samples) noexcept { - mockturtle::stopwatch stop{stats.time_total}; - auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); + mockturtle::stopwatch stop{stats.time_total}; // Start the stopwatch for performance measurement + // Get all possible defect positions within the grid spanned by nw_cell and se_cell + auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); + + // Initialize random number generator std::random_device rd; std::mt19937 gen(rd()); // Shuffle the vector using std::shuffle std::shuffle(all_possible_defect_positions.begin(), all_possible_defect_positions.end(), gen); + // Determine how many positions to sample (use the smaller of samples or the total number of positions) const auto min_iterations = std::min(all_possible_defect_positions.size(), samples); - for (auto i = 0u; i < min_iterations; ++i) + // Get the number of hardware threads available + const auto num_threads = std::thread::hardware_concurrency(); + + // Calculate the chunk size for each thread to process + std::size_t chunk_size = (min_iterations + num_threads - 1) / num_threads; + + // Define the lambda function that processes a chunk of sampled defect positions + auto process_chunk = [&](std::size_t start, std::size_t end) + { + for (std::size_t i = start; i < end; ++i) + { + is_defect_position_operational(all_possible_defect_positions[i]); + } + }; + + // Create a vector to hold futures for the threads + std::vector> futures{}; + + // Launch threads to process chunks of defect positions in parallel + for (std::size_t start = 0; start < min_iterations; start += chunk_size) + { + std::size_t end = std::min(start + chunk_size, min_iterations); + futures.emplace_back(std::async(std::launch::async, process_chunk, start, end)); + } + + // Wait for all threads to complete their execution + for (auto& future : futures) { - is_defect_position_operational(all_possible_defect_positions[i]); + future.get(); // Block until the thread completes } - log_stats(); + log_stats(); // Log the statistics after processing + // Return the computed operational domain return defect_operational_domain; } @@ -185,8 +240,9 @@ class defect_influence_operational_domain_impl return neighborhood.front(); }; - std::size_t number_of_random_start_positions = 0; - while (number_of_random_start_positions < samples) + std::unordered_set> starting_points{}; + + while (starting_points.size() < samples) { // first, perform random sampling to find an operational starting point const auto operational_starting_point = find_operational_defect_position_at_left_side(); @@ -197,11 +253,18 @@ class defect_influence_operational_domain_impl return defect_operational_domain; } + // check if the starting point has already been sampled + if (starting_points.find(*operational_starting_point) != starting_points.cend()) + { + continue; + } + + // add operatioal starting point to the set of starting points + starting_points.insert(*operational_starting_point); + // the layout hs to be defect-free. assert(layout.num_defects() == 0 && "An atomic defect is added"); - number_of_random_start_positions++; - // find an operational point on the contour starting from the randomly determined starting point const auto contour_starting_point = find_last_operational_defect_position_moving_right(*operational_starting_point); @@ -219,29 +282,10 @@ class defect_influence_operational_domain_impl current_neighborhood.front() : next_clockwise_point(current_neighborhood, backtrack_point); - bool contour_goes_around_se_layout_corner = true; - bool contour_goes_around_ne_layout_corner = true; - bool contour_goes_around_nw_layout_corner = true; - uint64_t counter = 0; while (next_point != contour_starting_point && counter < 100000) { const auto operational_status = is_defect_position_operational(next_point); - // check if the contour goes around the layout. - if (next_point.x >= se_bb_layout.x && next_point.y >= se_bb_layout.y) - { - contour_goes_around_se_layout_corner = true; - } - - if (next_point.x >= se_bb_layout.x && next_point.y <= nw_bb_layout.y) - { - contour_goes_around_ne_layout_corner = true; - } - - if (next_point.x <= nw_bb_layout.x && next_point.y <= nw_bb_layout.y) - { - contour_goes_around_nw_layout_corner = true; - } assert(layout.num_defects() == 0 && "more than one defect"); @@ -259,18 +303,9 @@ class defect_influence_operational_domain_impl next_point = next_clockwise_point(current_neighborhood, backtrack_point); counter++; } - number_of_random_start_positions++; -// if (!contour_goes_around_se_layout_corner || !contour_goes_around_ne_layout_corner || !contour_goes_around_nw_layout_corner) -// { -// if (number_of_random_start_positions == samples) -// { -// stats = defect_influence_operational_domain_stats{}; -// defect_operational_domain = defect_influence_operational_domain{}; // return an empty domain -// } -// continue; -// } } log_stats(); + return defect_operational_domain; } @@ -690,13 +725,12 @@ defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::v * to be in the same order as the inputs of the truth table. * * This algorithm uses contour tracing to identify operational defect locations within the SiDB gate layout. - * It starts by searching for defect locations on the left side of the bounding box, with an additional distance - * of the SiDB gate where the SiDB gate remains operational. The y-coordinate for these positions is chosen - * randomly. The number of samples is determined by the `samples` parameter. + * It starts by searching for defect locations on the left side (bounding_box + additional scanning area). The + * y-coordinate for these positions is chosen randomly. The number of samples is determined by the `samples` parameter. * * Then the algorithm moves each defect position to the right, searching for the last operational defect position. This * position is selected as the starting point for the contour trace. The contour tracing process checks whether the - * contour includes the SiDB layout. If it does not, the next random sample point is is selected as the starting point + * contour includes the SiDB layout. If it does not, the next random sample point is selected as the starting point * and the process is repeated. * * @Note This algorithm is an approximation to determine the defect influence operational domain. Therefore, it diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 8dc18868e..5837b34e2 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -273,7 +273,7 @@ class maximum_defect_influence_position_and_distance_impl * defect can still affect the layout's ground state, potentially altering its behavior, such as gate functionality. * * @param lyt The SiDB cell-level layout for which the influence distance is being determined. - * @param sim_params Parameters used to calculate the defect's maximum influence distance. + * @param params Parameters used to calculate the defect's maximum influence distance. * @param pst Statistics of the maximum defect influence distance. * @return Pair with the first element describing the position with maximum distance to the layout where a placed defect * can still affect the ground state of the layout. The second entry describes the distance of the defect from the @@ -281,7 +281,7 @@ class maximum_defect_influence_position_and_distance_impl */ template std::pair maximum_defect_influence_position_and_distance( - const Lyt& lyt, const maximum_defect_influence_position_and_distance_params& sim_params = {}, + const Lyt& lyt, const maximum_defect_influence_position_and_distance_params& params = {}, maximum_defect_influence_position_and_distance_stats* pst = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); @@ -291,7 +291,7 @@ std::pair maximum_defect_influence_position_and_dist maximum_defect_influence_position_and_distance_stats st{}; - detail::maximum_defect_influence_position_and_distance_impl p{lyt, sim_params, st}; + detail::maximum_defect_influence_position_and_distance_impl p{lyt, params, st}; const auto result = p.run(); diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index 0bab18760..af7d17b5a 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -145,8 +145,8 @@ namespace detail * Forward-declaration for `operational_domain`. */ template -std::optional contains_parameter_point(const MapType& map, - const typename MapType::key_type& key); +std::optional contains_key(const MapType& map, const typename MapType::key_type& key); + } // namespace detail /** * An operational domain is a set of simulation parameter values for which a given SiDB layout is logically operational. @@ -177,35 +177,16 @@ struct operational_domain */ locked_parallel_flat_hash_map operational_values{}; /** - * This function retrieves the value associated with the provided parameter point from the operational domain. If - * the parameter point is found in the domain, its corresponding value is returned. Otherwise, `std::out_of_range` - * is thrown. + * This function retrieves the value associated with the provided key from the operational domain. If + * the key is found in the domain, its corresponding value is returned. Otherwise, `std::nullopt` + * is returned. * - * @param pp The parameter point to look up. + * @param key The key to look up. * @return The value associated with the parameter point. */ - [[nodiscard]] Value get_value(const parameter_point& pp) const + [[nodiscard]] std::optional get_value(const Key& key) const { - if (const auto v = detail::contains_parameter_point(operational_values, pp); v.has_value()) - { - return v.value().second; - } - - // Create a string stream to hold the string representation - std::stringstream ss; - - // Iterate over the vector and add elements to the string stream - for (std::size_t i = 0; i < pp.parameters.size(); ++i) - { - ss << pp.parameters[i]; - - if (i != pp.parameters.size() - 1) - { - ss << ", "; - } - } - - throw std::out_of_range(fmt::format("{} not found in the operational domain", ss.str()).c_str()); + return detail::contains_key(operational_values, key); } }; /** @@ -331,16 +312,14 @@ void validate_sweep_parameters(const operational_domain_params& params) * @return The associated `MapType::value_type` of `key` in `map`, or `std::nullopt` if `key` is not contained in `map`. */ template -std::optional contains_parameter_point(const MapType& map, - const typename MapType::key_type& key) +std::optional contains_key(const MapType& map, const typename MapType::key_type& key) { - static_assert(std::is_same_v, "Map key type must be parameter_point"); - - std::optional result = std::nullopt; - - map.if_contains(key, [&result](const typename MapType::value_type& v) { result.emplace(v); }); - - return result; + auto it = map.find(key); + if (it != map.end()) + { + return it->second; + } + return std::nullopt; // If key not found, return std::nullopt } /** * This function searches for a floating-point value specified by the `key` in the provided map `map`, applying a @@ -1039,10 +1018,10 @@ class operational_domain_impl */ [[nodiscard]] inline std::optional has_already_been_sampled(const step_point& sp) const noexcept { - if (const auto v = contains_parameter_point(op_domain.operational_values, to_parameter_point(sp)); + if (const auto v = contains_key(op_domain.operational_values, to_parameter_point(sp)); v.has_value()) { - return v.value().second; + return v.value(); } return std::nullopt; diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 1cb63aa13..d3836500f 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include @@ -61,6 +63,8 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + write_sqd_layout(lyt, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/defect_avoidance_distance/plots/and/and.sqd"); + const auto cube_lyt = convert_layout_to_fiction_coordinates(lyt); const sidb_defect sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}; @@ -71,28 +75,32 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again SECTION("Grid Search") { - params.defect_influence_params.additional_scanning_area = {10, 10}; + params.defect_influence_params.additional_scanning_area = {20, 20}; defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_grid_search( - cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); + cube_lyt, std::vector{create_or_tt()}, 1, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance, - Catch::Matchers::WithinAbs(11.6138152646, physical_constants::POP_STABILITY_ERR)); + Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); + write_defect_influence_operational_domain(defect_influence_domain, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/defect_avoidance_distance/plots/and/and_grid.csv"); } SECTION("Random Sampling") { - params.defect_influence_params.additional_scanning_area = {0, 0}; + params.defect_influence_params.additional_scanning_area = {20, 20}; defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_random_sampling( cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); - CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance < 11.61); + CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance >= 12.579477930); + write_defect_influence_operational_domain(defect_influence_domain, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/defect_avoidance_distance/plots/and/and_random.csv"); } SECTION("Contour Tracing") { params.defect_influence_params.additional_scanning_area = {20, 20}; defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_contour_tracing( - cube_lyt, std::vector{create_or_tt()}, 30, params, &stats); - CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance > 11.61); + cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); + CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance, + Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); + write_defect_influence_operational_domain(defect_influence_domain, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/defect_avoidance_distance/plots/and/and_contour.csv"); } } diff --git a/test/algorithms/simulation/sidb/determine_physically_valid_parameters.cpp b/test/algorithms/simulation/sidb/determine_physically_valid_parameters.cpp index 78663567f..10e4f050d 100644 --- a/test/algorithms/simulation/sidb/determine_physically_valid_parameters.cpp +++ b/test/algorithms/simulation/sidb/determine_physically_valid_parameters.cpp @@ -86,25 +86,21 @@ TEST_CASE("Determine physical parameters for CDS of SiQAD Y-shaped AND gate, 10 const auto valid_parameters = determine_physically_valid_parameters(cds, op_domain_params); CHECK(valid_parameters.operational_values.size() == 98); - const auto p1 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{5.9, 5.5}}); + const auto p1 = detail::contains_key(valid_parameters.operational_values, parameter_point{{5.9, 5.5}}); REQUIRE(p1.has_value()); - CHECK(p1->second == 1); + CHECK(p1 == 1); - const auto p2 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{5.8, 4.4}}); + const auto p2 = detail::contains_key(valid_parameters.operational_values, parameter_point{{5.8, 4.4}}); REQUIRE(p2.has_value()); - CHECK(p2->second == 0); + CHECK(p2 == 0); - const auto p3 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{5.8, 4.4}}); + const auto p3 = detail::contains_key(valid_parameters.operational_values, parameter_point{{5.8, 4.4}}); REQUIRE(p3.has_value()); - CHECK(p3->second == 0); + CHECK(p3 == 0); - const auto p4 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{6.0, 6.0}}); + const auto p4 = detail::contains_key(valid_parameters.operational_values, parameter_point{{6.0, 6.0}}); REQUIRE(p4.has_value()); - CHECK(p4->second == 1); + CHECK(p4 == 1); } } @@ -164,25 +160,21 @@ TEST_CASE( const auto valid_parameters = determine_physically_valid_parameters(cds, op_domain_params); REQUIRE(valid_parameters.operational_values.size() == 100); - const auto p1 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{5.6, 5.0}}); + const auto p1 = detail::contains_key(valid_parameters.operational_values, parameter_point{{5.6, 5.0}}); REQUIRE(p1.has_value()); - CHECK(p1->second == 0); + CHECK(p1 == 0); - const auto p2 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{5.0, 5.9}}); + const auto p2 = detail::contains_key(valid_parameters.operational_values, parameter_point{{5.0, 5.9}}); REQUIRE(p2.has_value()); - CHECK(p2->second == 2); + CHECK(p2 == 2); - const auto p3 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{5.4, 5.3}}); + const auto p3 = detail::contains_key(valid_parameters.operational_values, parameter_point{{5.4, 5.3}}); REQUIRE(p3.has_value()); - CHECK(p3->second == 1); + CHECK(p3 == 1); - const auto p4 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{5.8, 5.3}}); + const auto p4 = detail::contains_key(valid_parameters.operational_values, parameter_point{{5.8, 5.3}}); REQUIRE(p4.has_value()); - CHECK(p4->second == 0); + CHECK(p4 == 0); } SECTION("Using the ground state of default physical parameters as given CDS, three dimensional sweep") @@ -225,24 +217,20 @@ TEST_CASE( const auto valid_parameters = determine_physically_valid_parameters(cds, op_domain_params); REQUIRE(valid_parameters.operational_values.size() == 27); - const auto p1 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{5.6, 5.0, -0.32}}); + const auto p1 = detail::contains_key(valid_parameters.operational_values, parameter_point{{5.6, 5.0, -0.32}}); REQUIRE(p1.has_value()); - CHECK(p1->second == 0); + CHECK(p1 == 0); - const auto p2 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{5.6, 5.0, -0.33}}); + const auto p2 = detail::contains_key(valid_parameters.operational_values, parameter_point{{5.6, 5.0, -0.33}}); REQUIRE(p2.has_value()); - CHECK(p2->second == 0); + CHECK(p2 == 0); - const auto p3 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{5.6, 5.0, -0.31}}); + const auto p3 = detail::contains_key(valid_parameters.operational_values, parameter_point{{5.6, 5.0, -0.31}}); REQUIRE(p3.has_value()); - CHECK(p3->second == 1); + CHECK(p3 == 1); - const auto p4 = - detail::contains_parameter_point(valid_parameters.operational_values, parameter_point{{5.7, 5.2, -0.33}}); + const auto p4 = detail::contains_key(valid_parameters.operational_values, parameter_point{{5.7, 5.2, -0.33}}); REQUIRE(p4.has_value()); - CHECK(p4->second == 0); + CHECK(p4 == 0); } } From c6ebcbbbc59ea515b06ad20100fd06162edfb6bf Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 18 Oct 2024 13:53:10 +0000 Subject: [PATCH 128/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/pybind11_mkdoc_docstrings.hpp | 62 ++++++++++++++----- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index d0bbafa42..ecd286676 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -3604,17 +3604,16 @@ the same order as the inputs of the truth table. This algorithm uses contour tracing to identify operational defect locations within the SiDB gate layout. It starts by searching for -defect locations on the left side of the bounding box, with an -additional distance of the SiDB gate where the SiDB gate remains -operational. The y-coordinate for these positions is chosen randomly. -The number of samples is determined by the `samples` parameter. +defect locations on the left side (bounding_box + additional scanning +area). The y-coordinate for these positions is chosen randomly. The +number of samples is determined by the `samples` parameter. Then the algorithm moves each defect position to the right, searching for the last operational defect position. This position is selected as the starting point for the contour trace. The contour tracing process checks whether the contour includes the SiDB layout. If it does not, -the next random sample point is is selected as the starting point and -the process is repeated. +the next random sample point is selected as the starting point and the +process is repeated. @Note This algorithm is an approximation to determine the defect influence operational domain. Therefore, it is recommended to analyze @@ -4396,9 +4395,9 @@ static const char *__doc_fiction_detail_connect_and_place = R"doc()doc"; static const char *__doc_fiction_detail_connect_and_place_2 = R"doc()doc"; -static const char *__doc_fiction_detail_contains_parameter_point = R"doc(Forward-declaration for `operational_domain`.)doc"; +static const char *__doc_fiction_detail_contains_key = R"doc(Forward-declaration for `operational_domain`.)doc"; -static const char *__doc_fiction_detail_contains_parameter_point_2 = +static const char *__doc_fiction_detail_contains_key_2 = R"doc(This function checks for the containment of a parameter point, specified by `key`, in the provided map `map`. If the parameter point is found in the map, the associated `MapType::value_type` is returned. @@ -4607,7 +4606,21 @@ the layout. It does so by selecting a defect position with the leftmost x-coordinate and a randomly selected y-coordinate limited the layout's bounding box.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_grid_search = R"doc()doc"; +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_grid_search = +R"doc(This function divides the search space (defined by `nw_cell` and +`se_cell`) into chunks, each processed by a different thread. The +search checks if defect positions in the grid are operational based on +a given step size. Each thread processes a chunk of positions in +parallel to improve performance. + +Parameter ``step_size``: + The step size used to sample defect positions in the grid. Only + positions with x and y coordinates divisible by `step_size` will + be checked for being operational. + +Returns: + A `defect_influence_operational_domain` object representing + the operational domain of the defects.)doc"; static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_has_already_been_sampled = R"doc(This function verifies whether the layout has already been analyzed @@ -4654,7 +4667,22 @@ static const char *__doc_fiction_detail_defect_influence_operational_domain_impl static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_previous_defect_position = R"doc(The previous defect position.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_random_sampling = R"doc()doc"; +static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_random_sampling = +R"doc(This function performs random sampling of defect positions from a grid +area (spanned by `nw_cell` and `se_cell`). The positions are shuffled +and divided into chunks, which are processed by different threads to +check if each defect position is operational. Each thread handles a +subset of the defect positions to improve performance. + +Parameter ``samples``: + The number of positions to sample. The actual number of iterations + will be the smaller of the total number of positions or the + `samples` value. + +Returns: + A `defect_influence_operational_domain` object representing + the operational domain of the defects. The return value is marked + [[nodiscard]], meaning it must be used by the caller.)doc"; static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_se_bb_layout = R"doc(The south-east bounding box of the layout.)doc"; @@ -13409,7 +13437,7 @@ Parameter ``lyt``: The SiDB cell-level layout for which the influence distance is being determined. -Parameter ``sim_params``: +Parameter ``params``: Parameters used to calculate the defect's maximum influence distance. @@ -14164,13 +14192,13 @@ Parameter ``stats``: The (partial) operational domain of the layout.)doc"; static const char *__doc_fiction_operational_domain_get_value = -R"doc(This function retrieves the value associated with the provided -parameter point from the operational domain. If the parameter point is -found in the domain, its corresponding value is returned. Otherwise, -`std::out_of_range` is thrown. +R"doc(This function retrieves the value associated with the provided key +from the operational domain. If the key is found in the domain, its +corresponding value is returned. Otherwise, `std::nullopt` is +returned. -Parameter ``pp``: - The parameter point to look up. +Parameter ``key``: + The key to look up. Returns: The value associated with the parameter point.)doc"; From 0fa4620b15ae5343b20eed26f24fbe3fe7f66d16 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 18 Oct 2024 16:19:10 +0200 Subject: [PATCH 129/221] :art: small changes. --- .../sidb/defect_influence_operational_domain.hpp | 11 ++++------- .../include/pyfiction/technology/sidb_lattice.hpp | 15 +++++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 8c217c4db..6e26d205c 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -22,8 +22,6 @@ namespace pyfiction namespace detail { -// todo add docu - template void defect_influence_operational_domain_detail(pybind11::module& m) { @@ -31,15 +29,15 @@ void defect_influence_operational_domain_detail(pybind11::module& m) m.def("defect_influence_operational_domain_grid_search", &fiction::defect_influence_operational_domain_grid_search, "lyt"_a, "spec"_a, "step_size"_a, - "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr); + "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_defect_influence_operational_domain_grid_search)); m.def("defect_influence_operational_domain_random_sampling", &fiction::defect_influence_operational_domain_random_sampling, "lyt"_a, "spec"_a, "samples"_a, - "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr); + "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_defect_influence_operational_domain_random_sampling)); m.def("defect_influence_operational_contour_tracing", &fiction::defect_influence_operational_domain_contour_tracing, "lyt"_a, "spec"_a, "samples"_a, - "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr); + "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_defect_influence_operational_domain_contour_tracing)); } } // namespace detail @@ -78,9 +76,8 @@ inline void defect_influence_operational_domain(pybind11::module& m) &fiction::defect_influence_operational_domain_stats::num_operational_defect_positions); // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! - - detail::defect_influence_operational_domain_detail(m); detail::defect_influence_operational_domain_detail(m); + detail::defect_influence_operational_domain_detail(m); } } // namespace pyfiction diff --git a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp index eff9655c3..123d5625f 100644 --- a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp +++ b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp @@ -45,25 +45,23 @@ void sidb_lattice_cell_level_layout(pybind11::module& m) /** * SiDB lattice. */ - if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) + if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) { py::class_(m, "sidb_100_lattice_cube", DOC(fiction_cell_level_layout), py::module_local()) .def(py::init<>()) // Default constructor .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", - DOC(fiction_sidb_lattice)) // Constructor with aspect ratio and name - ; + DOC(fiction_sidb_lattice)); } - if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) + else if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) { py::class_(m, "sidb_111_lattice_cube", DOC(fiction_cell_level_layout), py::module_local()) .def(py::init<>()) // Default constructor .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", - DOC(fiction_sidb_lattice)) // Constructor with aspect ratio and name - ; + DOC(fiction_sidb_lattice)); } - if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) + else if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) { py::class_(m, "sidb_100_lattice", DOC(fiction_cell_level_layout), py::module_local()) @@ -71,7 +69,7 @@ void sidb_lattice_cell_level_layout(pybind11::module& m) .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", DOC(fiction_sidb_lattice)); } - if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) + else if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) { py::class_(m, "sidb_111_lattice", DOC(fiction_cell_level_layout), py::module_local()) @@ -81,6 +79,7 @@ void sidb_lattice_cell_level_layout(pybind11::module& m) } } + } // namespace detail From 9b5ee7fa1abb6f69427515dc598b9d12175d9683 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 18 Oct 2024 16:25:00 +0200 Subject: [PATCH 130/221] :art: revert changes. --- .github/workflows/codeql-analysis.yml | 33 ++++++++++++--------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index adf52fa93..af85201be 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -31,10 +31,6 @@ concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true -defaults: - run: - shell: bash - env: Z3_VERSION: 4.13.0 @@ -89,14 +85,14 @@ jobs: python-version: '3.10.x' cache: 'pip' + - name: Setup mold + uses: rui314/setup-mold@v1 + - name: Install pip packages uses: BSFishy/pip-action@v1 with: requirements: ${{github.workspace}}/libs/mugen/requirements.txt - - name: Setup mold - uses: rui314/setup-mold@v1 - - name: Setup Z3 Solver id: z3 uses: cda-tum/setup-z3@v1 @@ -114,17 +110,17 @@ jobs: languages: ${{ matrix.language }} config-file: .github/codeql-config.yml - - name: Create Build Environment - if: matrix.language == 'cpp' - run: cmake -E make_directory ${{ github.workspace }}/build + - if: matrix.language == 'cpp' + name: Create Build Environment + run: cmake -E make_directory ${{github.workspace}}/build - - name: Configure CMake - if: matrix.language == 'cpp' - working-directory: ${{ github.workspace }}/build + - if: matrix.language == 'cpp' + name: Configure CMake + working-directory: ${{github.workspace}}/build run: > - cmake ${{github.workspace}} ${{matrix.cppstandard}} + cmake ${{github.workspace}} -DCMAKE_CXX_COMPILER=${{matrix.compiler}} - -DCMAKE_BUILD_TYPE=Debug + -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DFICTION_ENABLE_UNITY_BUILD=ON -DFICTION_ENABLE_PCH=ON -DFICTION_CLI=OFF @@ -137,12 +133,11 @@ jobs: -DFICTION_WARNINGS_AS_ERRORS=OFF -DMOCKTURTLE_EXAMPLES=OFF - - name: Build fiction - if: matrix.language == 'cpp' - working-directory: ${{ github.workspace }}/build + - if: matrix.language == 'cpp' + name: Build fiction + working-directory: ${{github.workspace}}/build run: cmake --build . --config ${{matrix.build_type}} -j4 - - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 with: From bdde82feeb152ccc213b281e306eb42e16a0cf80 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:02:58 +0000 Subject: [PATCH 131/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physical_design/design_sidb_gates.hpp | 6 ++++-- .../assess_physical_population_stability.hpp | 1 + .../defect_influence_operational_domain.hpp | 9 ++++++--- .../sidb/displacement_robustness_domain.hpp | 1 + ...defect_influence_position_and_distance.hpp | 6 ++++-- .../simulation/sidb/operational_domain.hpp | 7 ++++--- .../pyfiction/layouts/cell_level_layout.hpp | 4 +--- .../pyfiction/technology/sidb_lattice.hpp | 19 ++++++++----------- .../pyfiction/include/pyfiction/types.hpp | 1 - bindings/pyfiction/pyfiction.cpp | 14 +++++++------- cli/cmd/simulation/opdom.hpp | 1 - .../and/21_hex_inputsdbp_and_v19.sqd | 2 +- .../defect_avoidance_distance.cpp | 6 +++--- ...avoidance_distance_checking_robustness.cpp | 18 +++++++----------- ...g_robustness_with_newly_designed_gates.cpp | 2 +- ...defect_influence_position_and_distance.hpp | 8 ++++---- .../simulation/sidb/operational_domain.hpp | 3 +-- .../simulation/sidb/critical_temperature.cpp | 3 ++- .../defect_influence_operational_domain.cpp | 19 +++++++++++++------ 19 files changed, 68 insertions(+), 62 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp index ca9f50353..028ec3aad 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/physical_design/design_sidb_gates.hpp @@ -39,8 +39,10 @@ inline void design_sidb_gates(pybind11::module& m) pybind11::enum_::design_sidb_gates_mode>( m, "design_sidb_gates_mode", DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode)) .value("EXHAUSTIVE", - fiction::design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE)) - .value("RANDOM", fiction::design_sidb_gates_params::design_sidb_gates_mode::RANDOM, DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM)); + fiction::design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE, + DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE)) + .value("RANDOM", fiction::design_sidb_gates_params::design_sidb_gates_mode::RANDOM, + DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM)); /** * Parameters. diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 3b74f16b1..17ff6747d 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -12,6 +12,7 @@ #include #include + #include namespace pyfiction diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 6e26d205c..5def11f58 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -29,15 +29,18 @@ void defect_influence_operational_domain_detail(pybind11::module& m) m.def("defect_influence_operational_domain_grid_search", &fiction::defect_influence_operational_domain_grid_search, "lyt"_a, "spec"_a, "step_size"_a, - "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_defect_influence_operational_domain_grid_search)); + "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, + DOC(fiction_defect_influence_operational_domain_grid_search)); m.def("defect_influence_operational_domain_random_sampling", &fiction::defect_influence_operational_domain_random_sampling, "lyt"_a, "spec"_a, "samples"_a, - "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_defect_influence_operational_domain_random_sampling)); + "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, + DOC(fiction_defect_influence_operational_domain_random_sampling)); m.def("defect_influence_operational_contour_tracing", &fiction::defect_influence_operational_domain_contour_tracing, "lyt"_a, "spec"_a, "samples"_a, - "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_defect_influence_operational_domain_contour_tracing)); + "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, + DOC(fiction_defect_influence_operational_domain_contour_tracing)); } } // namespace detail diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp index 24e6250f1..02ad1a6a4 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp @@ -13,6 +13,7 @@ #include #include #include + #include namespace pyfiction diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 3c4736e54..18701c247 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -36,10 +36,12 @@ inline void maximum_defect_influence_distance(pybind11::module& m) { namespace py = pybind11; - py::class_(m, "maximum_defect_influence_distance_params") + py::class_( + m, "maximum_defect_influence_distance_params") .def(py::init<>()) .def_readwrite("defect", &fiction::maximum_defect_influence_position_and_distance_params::defect) - .def_readwrite("sim_params", &fiction::maximum_defect_influence_position_and_distance_params::simulation_parameters) + .def_readwrite("sim_params", + &fiction::maximum_defect_influence_position_and_distance_params::simulation_parameters) .def_readwrite("additional_scanning_area", &fiction::maximum_defect_influence_position_and_distance_params::additional_scanning_area) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp index facdf49db..4a80969e3 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/operational_domain.hpp @@ -37,11 +37,12 @@ void operational_domain(pybind11::module& m) DOC(fiction_operational_domain_random_sampling)); m.def("operational_domain_flood_fill", &fiction::operational_domain_flood_fill, "lyt"_a, "spec"_a, - "samples"_a, "params"_a = fiction::operational_domain_params{}, - "stats"_a = nullptr, DOC(fiction_operational_domain_flood_fill)); + "samples"_a, "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr, + DOC(fiction_operational_domain_flood_fill)); m.def("operational_domain_contour_tracing", &fiction::operational_domain_contour_tracing, "lyt"_a, - "spec"_a, "samples"_a, "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_operational_domain_contour_tracing)); + "spec"_a, "samples"_a, "params"_a = fiction::operational_domain_params{}, "stats"_a = nullptr, + DOC(fiction_operational_domain_contour_tracing)); } } // namespace detail diff --git a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp index 9510caf87..7c76f6227 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp @@ -79,9 +79,7 @@ void fcn_technology_cell_level_layout(pybind11::module& m) /** * Cell-level clocked Cartesian layout. */ - py::class_< - py_cartesian_technology_cell_layout, - py_cartesian_clocked_layout>( + py::class_( m, fmt::format("{}_layout", tech_name).c_str(), DOC(fiction_cell_level_layout)) .def(py::init<>()) .def(py::init&>(), "dimension"_a, diff --git a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp index 123d5625f..8d6ad88e0 100644 --- a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp +++ b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp @@ -47,42 +47,40 @@ void sidb_lattice_cell_level_layout(pybind11::module& m) */ if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) { - py::class_(m, "sidb_100_lattice_cube", - DOC(fiction_cell_level_layout), py::module_local()) + py::class_(m, "sidb_100_lattice_cube", DOC(fiction_cell_level_layout), + py::module_local()) .def(py::init<>()) // Default constructor .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", DOC(fiction_sidb_lattice)); } else if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) { - py::class_(m, "sidb_111_lattice_cube", - DOC(fiction_cell_level_layout), py::module_local()) + py::class_(m, "sidb_111_lattice_cube", DOC(fiction_cell_level_layout), + py::module_local()) .def(py::init<>()) // Default constructor .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", DOC(fiction_sidb_lattice)); } else if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) { - py::class_(m, "sidb_100_lattice", - DOC(fiction_cell_level_layout), py::module_local()) + py::class_(m, "sidb_100_lattice", DOC(fiction_cell_level_layout), + py::module_local()) .def(py::init<>()) // Default constructor .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", DOC(fiction_sidb_lattice)); } else if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) { - py::class_(m, "sidb_111_lattice", - DOC(fiction_cell_level_layout), py::module_local()) + py::class_(m, "sidb_111_lattice", DOC(fiction_cell_level_layout), + py::module_local()) .def(py::init<>()) // Default constructor .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", DOC(fiction_sidb_lattice)); } } - } // namespace detail - inline void sidb_lattices_100_cube(pybind11::module& m) { // Bind the cube-coordinate 100 and 111 SiDB lattices @@ -101,7 +99,6 @@ inline void sidb_lattices_100(pybind11::module& m) detail::sidb_lattice_cell_level_layout(m); } - inline void sidb_lattices_111_cube(pybind11::module& m) { // Bind the regular 100 and 111 SiDB lattices diff --git a/bindings/pyfiction/include/pyfiction/types.hpp b/bindings/pyfiction/include/pyfiction/types.hpp index 7ffccac8d..2078a3757 100644 --- a/bindings/pyfiction/include/pyfiction/types.hpp +++ b/bindings/pyfiction/include/pyfiction/types.hpp @@ -153,7 +153,6 @@ using py_charge_distribution_surface_layout = fiction::charge_distribution_surfa using py_charge_distribution_surface = fiction::charge_distribution_surface; - using py_charge_distribution_surface_cube = fiction::charge_distribution_surface; /** diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index cbe929aaa..bf833e5bb 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -26,22 +26,22 @@ #include "pyfiction/algorithms/physical_design/wiring_reduction.hpp" #include "pyfiction/algorithms/properties/critical_path_length_and_throughput.hpp" #include "pyfiction/algorithms/simulation/logic_simulation.hpp" +#include "pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp" #include "pyfiction/algorithms/simulation/sidb/calculate_energy_and_state_type.hpp" #include "pyfiction/algorithms/simulation/sidb/can_positive_charges_occur.hpp" +#include "pyfiction/algorithms/simulation/sidb/check_simulation_results_for_equivalence.hpp" #include "pyfiction/algorithms/simulation/sidb/compute_operational_ratio.hpp" +#include "pyfiction/algorithms/simulation/sidb/convert_potential_to_distance.hpp" #include "pyfiction/algorithms/simulation/sidb/critical_temperature.hpp" #include "pyfiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" +#include "pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp" #include "pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp" +#include "pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp" #include "pyfiction/algorithms/simulation/sidb/energy_distribution.hpp" #include "pyfiction/algorithms/simulation/sidb/exhaustive_ground_state_simulation.hpp" #include "pyfiction/algorithms/simulation/sidb/is_ground_state.hpp" #include "pyfiction/algorithms/simulation/sidb/is_operational.hpp" #include "pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" -#include "pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp" -#include "pyfiction/algorithms/simulation/sidb/check_simulation_results_for_equivalence.hpp" -#include "pyfiction/algorithms/simulation/sidb/convert_potential_to_distance.hpp" -#include "pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp" -#include "pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp" #include "pyfiction/algorithms/simulation/sidb/minimum_energy.hpp" #include "pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp" #include "pyfiction/algorithms/simulation/sidb/operational_domain.hpp" @@ -199,9 +199,9 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::sidb_nm_position(m); pyfiction::sidb_nm_distance(m); pyfiction::sidb_lattices_100(m); - //pyfiction::sidb_lattices_100_cube(m); + // pyfiction::sidb_lattices_100_cube(m); pyfiction::sidb_lattices_111(m); - //pyfiction::sidb_lattices_111_cube(m); + // pyfiction::sidb_lattices_111_cube(m); pyfiction::charge_distribution_surfaces(m); /** * Input/Output diff --git a/cli/cmd/simulation/opdom.hpp b/cli/cmd/simulation/opdom.hpp index 3c98810df..61b5e5e00 100644 --- a/cli/cmd/simulation/opdom.hpp +++ b/cli/cmd/simulation/opdom.hpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd b/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd index 73c247a41..c3752f800 100644 --- a/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd +++ b/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd @@ -215,4 +215,4 @@ - \ No newline at end of file + diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp index dac1c4365..4675dcadd 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp @@ -13,19 +13,19 @@ #include #include +#include #include #include #include #include #include -#include using namespace fiction; int main() { - experiments::experiment + experiments::experiment simulation_exp{ "Benchmark", "Gate Name", "Num SiDBs", "x_coord", "y_coord", "distance_grid_search", diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp index 23e72140f..b6187236c 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp @@ -1,5 +1,4 @@ #include "fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp" - #include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" @@ -23,10 +22,8 @@ using namespace fiction; int main() { - experiments::experiment - simulation_exp{ - "Benchmark", "Gate Name", "instance count", "#samples_grid", "#sample_contour", "#unequal" - }; + experiments::experiment simulation_exp{ + "Benchmark", "Gate Name", "instance count", "#samples_grid", "#sample_contour", "#unequal"}; static const std::string folder = fmt::format("{}defect_avoidance_distance/fom_data/sqd/", EXPERIMENTS_PATH); static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); @@ -61,9 +58,9 @@ int main() std::string gate_folder = fmt::format("{}{}/", output_folder, gate); std::filesystem::create_directories(gate_folder); - std::size_t gate_counter = 0; - std::size_t unequal_counter = 0; - std::size_t sample_grid_counter = 0; + std::size_t gate_counter = 0; + std::size_t unequal_counter = 0; + std::size_t sample_grid_counter = 0; std::size_t sample_contour_counter = 0; bool start_with_new_boolean_function = false; @@ -100,7 +97,6 @@ int main() const auto avoidance_grid = defect_avoidance_distance(layout, op_defect_grid); - defect_influence_operational_domain_stats contour_stats{}; const auto op_defect_contour = defect_influence_operational_domain_contour_tracing( layout, truth_table, 100, defect_params, &contour_stats); @@ -114,8 +110,8 @@ int main() if (std::abs(avoidance_grid.max_min_distance - avoidance_contour.max_min_distance) > 0.1) { // Log the simulation results - unequal_counter++; - std::cout << file.path().string() << std::endl; + unequal_counter++; + std::cout << file.path().string() << std::endl; } } simulation_exp(gate, gate_counter, sample_grid_counter, sample_contour_counter, unequal_counter); diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp index 1d25a2819..dc503d9ea 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp @@ -6,8 +6,8 @@ #include "fiction/io/read_sqd_layout.hpp" #include "fiction/io/write_defect_influence_operational_domain.hpp" #include "fiction/io/write_sqd_layout.hpp" -#include "fiction/types.hpp" #include "fiction/traits.hpp" +#include "fiction/types.hpp" #include "fiction/utils/truth_table_utils.hpp" #include "fiction_experiments.hpp" diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 5837b34e2..b40885a92 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -13,7 +13,6 @@ #include "fiction/technology/sidb_defects.hpp" #include "fiction/traits.hpp" #include "fiction/utils/execution_utils.hpp" -#include "fiction/traits.hpp" #include "fiction/utils/layout_utils.hpp" #include @@ -280,9 +279,10 @@ class maximum_defect_influence_position_and_distance_impl * layout. */ template -std::pair maximum_defect_influence_position_and_distance( - const Lyt& lyt, const maximum_defect_influence_position_and_distance_params& params = {}, - maximum_defect_influence_position_and_distance_stats* pst = nullptr) +std::pair +maximum_defect_influence_position_and_distance(const Lyt& lyt, + const maximum_defect_influence_position_and_distance_params& params = {}, + maximum_defect_influence_position_and_distance_stats* pst = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index af7d17b5a..ee4911895 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -1018,8 +1018,7 @@ class operational_domain_impl */ [[nodiscard]] inline std::optional has_already_been_sampled(const step_point& sp) const noexcept { - if (const auto v = contains_key(op_domain.operational_values, to_parameter_point(sp)); - v.has_value()) + if (const auto v = contains_key(op_domain.operational_values, to_parameter_point(sp)); v.has_value()) { return v.value(); } diff --git a/test/algorithms/simulation/sidb/critical_temperature.cpp b/test/algorithms/simulation/sidb/critical_temperature.cpp index 2f4246435..bd7c0d2ca 100644 --- a/test/algorithms/simulation/sidb/critical_temperature.cpp +++ b/test/algorithms/simulation/sidb/critical_temperature.cpp @@ -359,7 +359,8 @@ TEMPLATE_TEST_CASE("Test critical_temperature function", "[critical-temperature] params.iteration_steps = 80; params.alpha = 0.7; - const auto ct = critical_temperature_gate_based(lyt, std::vector{create_crossing_wire_tt()}, params, &critical_stats); + const auto ct = + critical_temperature_gate_based(lyt, std::vector{create_crossing_wire_tt()}, params, &critical_stats); CHECK_THAT(std::fabs(critical_stats.energy_between_ground_state_and_first_erroneous - 0.32), Catch::Matchers::WithinAbs(0.00, 0.01)); diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index d3836500f..7b14bd75e 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -17,8 +19,6 @@ #include #include #include -#include -#include #include @@ -63,7 +63,8 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - write_sqd_layout(lyt, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/defect_avoidance_distance/plots/and/and.sqd"); + write_sqd_layout( + lyt, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/defect_avoidance_distance/plots/and/and.sqd"); const auto cube_lyt = convert_layout_to_fiction_coordinates(lyt); @@ -81,7 +82,9 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again cube_lyt, std::vector{create_or_tt()}, 1, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance, Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); - write_defect_influence_operational_domain(defect_influence_domain, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/defect_avoidance_distance/plots/and/and_grid.csv"); + write_defect_influence_operational_domain(defect_influence_domain, + "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/" + "defect_avoidance_distance/plots/and/and_grid.csv"); } SECTION("Random Sampling") { @@ -91,7 +94,9 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance >= 12.579477930); - write_defect_influence_operational_domain(defect_influence_domain, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/defect_avoidance_distance/plots/and/and_random.csv"); + write_defect_influence_operational_domain(defect_influence_domain, + "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/" + "defect_avoidance_distance/plots/and/and_random.csv"); } SECTION("Contour Tracing") { @@ -101,6 +106,8 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance, Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); - write_defect_influence_operational_domain(defect_influence_domain, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/defect_avoidance_distance/plots/and/and_contour.csv"); + write_defect_influence_operational_domain(defect_influence_domain, + "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/" + "defect_avoidance_distance/plots/and/and_contour.csv"); } } From 036945515a28a080eb1d7083806d1fe3397717a5 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 18 Oct 2024 17:16:01 +0200 Subject: [PATCH 132/221] :fire: delete files. --- .../and/21_hex_inputsdbp_and_v19.sqd | 218 ------------------ .../figure_of_merit_analysis/fom_analysis.cpp | 201 ---------------- 2 files changed, 419 deletions(-) delete mode 100644 experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd delete mode 100644 experiments/figure_of_merit_analysis/fom_analysis.cpp diff --git a/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd b/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd deleted file mode 100644 index 73c247a41..000000000 --- a/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd +++ /dev/null @@ -1,218 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:47:07 - - - - 0.0518456 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/figure_of_merit_analysis/fom_analysis.cpp b/experiments/figure_of_merit_analysis/fom_analysis.cpp deleted file mode 100644 index c067849d5..000000000 --- a/experiments/figure_of_merit_analysis/fom_analysis.cpp +++ /dev/null @@ -1,201 +0,0 @@ -// -// Created by Jan Drewniok 01.01.23 -// - -#include "fiction_experiments.hpp" -#include "mockturtle/utils/stopwatch.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -using namespace fiction; - -int main() // NOLINT -{ - using Lyt = sidb_100_cell_clk_lyt_cube; - - static const std::string folder = - fmt::format("{}skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd", EXPERIMENTS_PATH); - - experiments::experiment fom_exp{ - "FOM", "benchmark", "CT max (K)", "OPD max", "MDC_ars_min (nm)", "MDC_vac_max (nm)", "BBR"}; - - const auto skeleton = read_sqd_layout(folder); - - const auto sim_params = sidb_simulation_parameters{2, -0.32}; - - design_sidb_gates_params> params{sim_params, {{17, 14, 0}, {21, 22, 0}}, 2}; - - const auto truth_tables = std::vector>{ - std::vector{create_and_tt()}, std::vector{create_nand_tt()}, std::vector{create_or_tt()}, - std::vector{create_nor_tt()}, std::vector{create_xor_tt()}, std::vector{create_xnor_tt()}, - std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, - std::vector{create_ge_tt()}}; - - const auto gate_names = std::vector{"and", "nand", "or", "nor", "xor", "xnor", "lt", "gt", "le", "ge"}; - - const critical_temperature_params ct_params{sim_params}; - - // defining the operational domain parameters - operational_domain_params op_domain_params{sim_params}; - - // setting the operational domain range - op_domain_params.x_min = 4.0; - op_domain_params.x_max = 6; - op_domain_params.x_step = 0.2; - - op_domain_params.y_min = 4.0; - op_domain_params.y_max = 6; - op_domain_params.y_step = 0.2; - - const calculate_min_bbr_for_all_inputs_params assess_params{ - assess_physical_population_stability_params{sim_params}}; - - const maximum_defect_influence_position_and_distance_params defect_avoidance_params_arsenic{ - sidb_defect{sidb_defect_type::UNKNOWN, 1, 9.7, 2.1}, - sim_params, - {30, 20}}; - - const maximum_defect_influence_position_and_distance_params defect_avoidance_params_vacancy{ - sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}, - sim_params, - {30, 20}}; - - uint64_t counter = 0; - for (const auto& truth_table : truth_tables) - { - for (auto num_sidbs = 2u; num_sidbs < 6; num_sidbs++) - { - std::cout << fmt::format("num sidbs: {}", num_sidbs) << '\n'; - params.number_of_sidbs = num_sidbs; - - mockturtle::stopwatch<>::duration time_total{}; - - std::vector temps = {}; - std::vector op_domains = {}; - std::vector defect_influence_arsenic = {}; - std::vector defect_influence_vacancy = {}; - std::vector pop_stability_neutral_to_negative = {}; - std::vector pop_stability_negative_to_neutral = {}; - std::vector bbr_all = {}; - std::vector runtime = {}; - { - mockturtle::stopwatch stop{time_total}; - - const auto all_gate = design_sidb_gates(skeleton, truth_table, params); - - std::cout << fmt::format("Number of gates: {}", all_gate.size()) << '\n'; - - for (const auto& gate : all_gate) - { - temps.push_back(critical_temperature_gate_based(gate, truth_table, ct_params)); - operational_domain_stats op_stats{}; - const auto op_domain = operational_domain_flood_fill(gate, truth_table, 0, op_domain_params, - parameter_point{5.6, 5}, &op_stats); - op_domains.push_back(op_stats.percentual_operational_area); - - defect_influence_operational_domain_stats arsenic_stats{}; - const auto defect_influence_domain_arsenic = defect_influence_operational_domain_grid_search( - gate, truth_table, 2, - defect_influence_operational_domain_params{ - defect_avoidance_params_arsenic, - is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, - &arsenic_stats); - std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) << '\n'; - runtime.push_back(mockturtle::to_seconds(arsenic_stats.time_total)); - - defect_influence_arsenic.push_back( - defect_avoidance_distance(gate, defect_influence_domain_arsenic).max_min_distance); - - defect_influence_operational_domain_stats vacancy_stats{}; - const auto defect_influence_domain_vacancy = defect_influence_operational_domain_grid_search( - gate, truth_table, 2, - defect_influence_operational_domain_params{ - defect_avoidance_params_vacancy, - is_operational_params{defect_avoidance_params_arsenic.simulation_parameters}}, - &vacancy_stats); - std::cout << fmt::format("runtime: {}", mockturtle::to_seconds(arsenic_stats.time_total)) << '\n'; - - defect_influence_vacancy.push_back( - defect_avoidance_distance(gate, defect_influence_domain_vacancy).max_min_distance); - - pop_stability_neutral_to_negative.push_back( - calculate_min_bbr_for_all_inputs(gate, truth_table, - calculate_min_bbr_for_all_inputs_params{assess_params}, -1) * - 1000); - - const auto bbr_neu_to_neg = - calculate_min_bbr_for_all_inputs(gate, truth_table, - calculate_min_bbr_for_all_inputs_params{assess_params}, 1) * - 1000; - - pop_stability_negative_to_neutral.push_back( - calculate_min_bbr_for_all_inputs(gate, truth_table, - calculate_min_bbr_for_all_inputs_params{assess_params}, 1) * - 1000); - const auto bbr_neg_to_neu = - calculate_min_bbr_for_all_inputs(gate, truth_table, - calculate_min_bbr_for_all_inputs_params{assess_params}, 1) * - 1000; - - bbr_all.push_back(std::min(bbr_neu_to_neg, bbr_neg_to_neu)); - } - - if (!temps.empty()) - { - const auto max_temp = *std::max_element(temps.begin(), temps.end()); - const auto max_op_domain = *std::max_element(op_domains.begin(), op_domains.end()); - const auto max_defect_influence_arsenic = - *std::min_element(defect_influence_arsenic.begin(), defect_influence_arsenic.end()); - const auto max_defect_influence_vacancy = - *std::min_element(defect_influence_vacancy.begin(), defect_influence_vacancy.end()); - const auto max_pop_stability_neutral_to_negative = *std::max_element( - pop_stability_neutral_to_negative.begin(), pop_stability_neutral_to_negative.end()); - const auto max_pop_stability_negative_to_neutral = *std::max_element( - pop_stability_negative_to_neutral.begin(), pop_stability_negative_to_neutral.end()); - - const auto bbr_max = - std::max(max_pop_stability_neutral_to_negative, max_pop_stability_negative_to_neutral); - - // log results - fom_exp(gate_names[counter], max_temp, max_op_domain, 0, 0, bbr_max); - - fom_exp.save(); - fom_exp.table(); - for (std::size_t i = 0; i < temps.size(); i++) - { - cost_function_chi({temps[i] / max_temp, op_domains[i] / max_op_domain, - defect_influence_arsenic[i] / max_defect_influence_arsenic, - defect_influence_vacancy[i] / max_defect_influence_vacancy, - bbr_all[i] / bbr_max}, - {-1, -1, 1, 1, -1}); - } - } - } - } - counter++; - } - return EXIT_SUCCESS; -} From bc9b1139c407d98edde76555c33615d55db88803 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 30 Oct 2024 08:23:23 +0100 Subject: [PATCH 133/221] :art: Make sure the contour does not get stuck if you have only one contour. --- .../defect_avoidance_distance.cpp | 6 +++--- ...t_avoidance_distance_checking_robustness.cpp | 2 +- ...ing_robustness_with_newly_designed_gates.cpp | 14 +++++++------- .../sidb/defect_avoidance_distance.hpp | 6 +++--- .../defect_influence_operational_domain.hpp | 11 +++++++---- .../defect_influence_operational_domain.cpp | 17 +++++------------ 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp index 4675dcadd..12a4e869a 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp @@ -105,9 +105,9 @@ int main() // Log the simulation results simulation_exp(gate, layout.num_cells(), avoidance_grid.max_distance_postion_of_non_operational_defect.x, avoidance_grid.max_distance_postion_of_non_operational_defect.y, - avoidance_grid.max_min_distance, grid_stats.num_evaluated_defect_positions, - avoidance_random.max_min_distance, random_stats.num_evaluated_defect_positions, - avoidance_contour.max_min_distance, contour_stats.num_evaluated_defect_positions); + avoidance_grid.minimum_defect_clearance, grid_stats.num_evaluated_defect_positions, + avoidance_random.minimum_defect_clearance, random_stats.num_evaluated_defect_positions, + avoidance_contour.minimum_defect_clearance, contour_stats.num_evaluated_defect_positions); simulation_exp.save(); simulation_exp.table(); } diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp index b6187236c..7400558cf 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp @@ -108,7 +108,7 @@ int main() sample_grid_counter += grid_stats.num_evaluated_defect_positions; sample_contour_counter += contour_stats.num_evaluated_defect_positions; - if (std::abs(avoidance_grid.max_min_distance - avoidance_contour.max_min_distance) > 0.1) + if (std::abs(avoidance_grid.minimum_defect_clearance - avoidance_contour.minimum_defect_clearance) > 0.1) { // Log the simulation results unequal_counter++; std::cout << file.path().string() << std::endl; diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp index dc503d9ea..d52611b12 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp @@ -100,21 +100,21 @@ int main() const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); // - // simulation_exp(gate, avoidance_grid.max_min_distance, + // simulation_exp(gate, avoidance_grid.minimum_defect_clearance, // grid_stats.num_evaluated_defect_positions, - // avoidance_random.max_min_distance, random_stats.num_evaluated_defect_positions, - // avoidance_contour.max_min_distance, + // avoidance_random.minimum_defect_clearance, random_stats.num_evaluated_defect_positions, + // avoidance_contour.minimum_defect_clearance, // contour_stats.num_evaluated_defect_positions); // simulation_exp.save(); // simulation_exp.table(); - if (std::abs(avoidance_grid.max_min_distance - avoidance_contour.max_min_distance) > 0.1) + if (std::abs(avoidance_grid.minimum_defect_clearance - avoidance_contour.minimum_defect_clearance) > 0.1) { // Log the simulation results write_sqd_layout(gate_lyt, sqd_path); write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); - simulation_exp(gate, avoidance_grid.max_min_distance, grid_stats.num_evaluated_defect_positions, - avoidance_random.max_min_distance, random_stats.num_evaluated_defect_positions, - avoidance_contour.max_min_distance, contour_stats.num_evaluated_defect_positions); + simulation_exp(gate, avoidance_grid.minimum_defect_clearance, grid_stats.num_evaluated_defect_positions, + avoidance_random.minimum_defect_clearance, random_stats.num_evaluated_defect_positions, + avoidance_contour.minimum_defect_clearance, contour_stats.num_evaluated_defect_positions); simulation_exp.save(); simulation_exp.table(); } diff --git a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp index 3692b30dc..43540fc5d 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp @@ -23,13 +23,13 @@ template struct defect_avoidance_distance_result { /** - * Maximum position at which the placement of a SiDB defect still causes the gate to fail. + * position with maximum distance to the SiDB layout at which the placement of an SiDB defect still causes the gate to fail. */ CellType max_distance_postion_of_non_operational_defect{}; /** - * Minimum distance between a SiDB of the gate and the defect at the maximum distance that causes the gate to fail. + * Minimum distance between an SiDB of the gate and the defect at the maximum distance that causes the gate to fail. */ - double max_min_distance{}; + double minimum_defect_clearance{}; }; /** * Calculates the defect avoidance distance of a given gate layout by a given atomic defect. This means that a defect diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index f4593f1a7..a4632114a 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -11,6 +11,7 @@ #include "fiction/layouts/coordinates.hpp" #include "fiction/technology/sidb_defect_surface.hpp" #include "fiction/technology/sidb_defects.hpp" +#include "fiction/traits.hpp" #include "fiction/utils/layout_utils.hpp" #include "fiction/utils/phmap_utils.hpp" @@ -242,8 +243,12 @@ class defect_influence_operational_domain_impl std::unordered_set> starting_points{}; - while (starting_points.size() < samples) + std::size_t sample_counter = 0; + + while (sample_counter < samples) { + sample_counter++; + // first, perform random sampling to find an operational starting point const auto operational_starting_point = find_operational_defect_position_at_left_side(); @@ -282,8 +287,7 @@ class defect_influence_operational_domain_impl current_neighborhood.front() : next_clockwise_point(current_neighborhood, backtrack_point); - uint64_t counter = 0; - while (next_point != contour_starting_point && counter < 100000) + while (next_point != contour_starting_point) { const auto operational_status = is_defect_position_operational(next_point); @@ -301,7 +305,6 @@ class defect_influence_operational_domain_impl current_neighborhood = moore_neighborhood(current_contour_point); next_point = next_clockwise_point(current_neighborhood, backtrack_point); - counter++; } } log_stats(); diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 7b14bd75e..34413176d 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -80,12 +80,10 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_grid_search( cube_lyt, std::vector{create_or_tt()}, 1, params, &stats); - CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance, + CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); - write_defect_influence_operational_domain(defect_influence_domain, - "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/" - "defect_avoidance_distance/plots/and/and_grid.csv"); } + SECTION("Random Sampling") { params.defect_influence_params.additional_scanning_area = {20, 20}; @@ -93,21 +91,16 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again const auto defect_influence_domain = defect_influence_operational_domain_random_sampling( cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); - CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance >= 12.579477930); - write_defect_influence_operational_domain(defect_influence_domain, - "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/" - "defect_avoidance_distance/plots/and/and_random.csv"); + CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= 12.579477930); } + SECTION("Contour Tracing") { params.defect_influence_params.additional_scanning_area = {20, 20}; defect_influence_operational_domain_stats stats{}; const auto defect_influence_domain = defect_influence_operational_domain_contour_tracing( cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); - CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).max_min_distance, + CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); - write_defect_influence_operational_domain(defect_influence_domain, - "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/" - "defect_avoidance_distance/plots/and/and_contour.csv"); } } From c655a2434cdf5d798cc446b720b1eb4f8485ae06 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2024 07:25:35 +0000 Subject: [PATCH 134/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...stance_checking_robustness_with_newly_designed_gates.cpp | 6 ++++-- .../simulation/sidb/defect_avoidance_distance.hpp | 3 ++- test/algorithms/simulation/sidb/is_operational.cpp | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp index d52611b12..e2210c282 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp +++ b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp @@ -102,7 +102,8 @@ int main() // // simulation_exp(gate, avoidance_grid.minimum_defect_clearance, // grid_stats.num_evaluated_defect_positions, - // avoidance_random.minimum_defect_clearance, random_stats.num_evaluated_defect_positions, + // avoidance_random.minimum_defect_clearance, + // random_stats.num_evaluated_defect_positions, // avoidance_contour.minimum_defect_clearance, // contour_stats.num_evaluated_defect_positions); // simulation_exp.save(); @@ -114,7 +115,8 @@ int main() write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); simulation_exp(gate, avoidance_grid.minimum_defect_clearance, grid_stats.num_evaluated_defect_positions, avoidance_random.minimum_defect_clearance, random_stats.num_evaluated_defect_positions, - avoidance_contour.minimum_defect_clearance, contour_stats.num_evaluated_defect_positions); + avoidance_contour.minimum_defect_clearance, + contour_stats.num_evaluated_defect_positions); simulation_exp.save(); simulation_exp.table(); } diff --git a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp index 43540fc5d..0ef035787 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp @@ -23,7 +23,8 @@ template struct defect_avoidance_distance_result { /** - * position with maximum distance to the SiDB layout at which the placement of an SiDB defect still causes the gate to fail. + * position with maximum distance to the SiDB layout at which the placement of an SiDB defect still causes the gate + * to fail. */ CellType max_distance_postion_of_non_operational_defect{}; /** diff --git a/test/algorithms/simulation/sidb/is_operational.cpp b/test/algorithms/simulation/sidb/is_operational.cpp index 105960437..0e38b2498 100644 --- a/test/algorithms/simulation/sidb/is_operational.cpp +++ b/test/algorithms/simulation/sidb/is_operational.cpp @@ -133,7 +133,7 @@ TEST_CASE("Bestagon CROSSING gate", "[is-operational]") TEST_CASE("Bestagon AND gate", "[is-operational]") { const auto lyt = blueprints::bestagon_and(); - using layout = sidb_defect_cell_clk_lyt_siqad; + using layout = sidb_defect_cell_clk_lyt_siqad; layout lyt{}; From dee21949000f0a8efeef38bc63f6ffd84a2a3a23 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 30 Oct 2024 07:26:37 +0000 Subject: [PATCH 135/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../include/pyfiction/pybind11_mkdoc_docstrings.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index 8250647c2..e5f96793f 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -3799,11 +3799,11 @@ R"doc(Results of the defect avoidance distance calculation. Template parameter ``CellType``:)doc"; static const char *__doc_fiction_defect_avoidance_distance_result_max_distance_postion_of_non_operational_defect = -R"doc(Maximum position at which the placement of a SiDB defect still causes -the gate to fail.)doc"; +R"doc(position with maximum distance to the SiDB layout at which the +placement of an SiDB defect still causes the gate to fail.)doc"; -static const char *__doc_fiction_defect_avoidance_distance_result_max_min_distance = -R"doc(Minimum distance between a SiDB of the gate and the defect at the +static const char *__doc_fiction_defect_avoidance_distance_result_minimum_defect_clearance = +R"doc(Minimum distance between an SiDB of the gate and the defect at the maximum distance that causes the gate to fail.)doc"; static const char *__doc_fiction_defect_extent = From c0a82e28e4710bd6717d620b76ab5b824c5ef95e Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 30 Oct 2024 09:38:08 +0100 Subject: [PATCH 136/221] :art: small fixes. --- docs/algorithms/sidb_simulation.rst | 6 +- .../and/21_hex_inputsdbp_and_v19.sqd | 0 ...avoidance_distance_checking_robustness.cpp | 126 ----------------- ...g_robustness_with_newly_designed_gates.cpp | 128 ------------------ ...cal_design_with_on_the_fly_gate_design.cpp | 1 + .../quickrace_vs_grid_search_new_gates.cpp | 108 +++++++++++++++ .../quicktrace_vs_grid_search_bestagon.cpp} | 28 ++-- .../optimization/simulated_annealing.hpp | 6 +- .../sidb/calculate_min_bbr_for_all_inputs.hpp | 1 - .../sidb/defect_avoidance_distance.hpp | 2 +- .../defect_influence_operational_domain.hpp | 102 +++++++------- ...te_defect_influence_operational_domain.hpp | 4 +- .../defect_influence_operational_domain.cpp | 18 +-- .../simulation/sidb/is_operational.cpp | 34 +---- 14 files changed, 193 insertions(+), 371 deletions(-) delete mode 100644 experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd delete mode 100644 experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp delete mode 100644 experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp create mode 100644 experiments/quicktrace/quickrace_vs_grid_search_new_gates.cpp rename experiments/{defect_avoidance_distance/defect_avoidance_distance.cpp => quicktrace/quicktrace_vs_grid_search_bestagon.cpp} (82%) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 1e3c2f00e..5b911fc96 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -307,15 +307,15 @@ Defect Influence Operational Domain **Header:** ``fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp`` -.. doxygenstruct:: fiction::defect_influence_operational_domain_params +.. doxygenstruct:: fiction::defect_operational_domain_params :members: .. doxygenstruct:: fiction::defect_influence_operational_domain :members: -.. doxygenstruct:: fiction::defect_influence_operational_domain_stats +.. doxygenstruct:: fiction::defect_operational_domain_stats :members: .. doxygenfunction:: fiction::defect_influence_operational_domain_grid_search .. doxygenfunction:: fiction::defect_influence_operational_domain_random_sampling -.. doxygenfunction:: fiction::defect_influence_operational_domain_contour_tracing +.. doxygenfunction:: fiction::defect_operational_domain_quicktrace Determine Physically Valid Parameters ##################################### diff --git a/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd b/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd deleted file mode 100644 index e69de29bb..000000000 diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp deleted file mode 100644 index 7400558cf..000000000 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include "fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp" -#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" -#include "fiction/algorithms/simulation/sidb/is_operational.hpp" -#include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" -#include "fiction/io/read_sqd_layout.hpp" -#include "fiction/io/write_defect_influence_operational_domain.hpp" -#include "fiction/io/write_sqd_layout.hpp" -#include "fiction/types.hpp" -#include "fiction/utils/truth_table_utils.hpp" -#include "fiction_experiments.hpp" - -#include - -#include -#include -#include -#include -#include -#include - -using namespace fiction; - -int main() -{ - experiments::experiment simulation_exp{ - "Benchmark", "Gate Name", "instance count", "#samples_grid", "#sample_contour", "#unequal"}; - - static const std::string folder = fmt::format("{}defect_avoidance_distance/fom_data/sqd/", EXPERIMENTS_PATH); - static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); - - static const std::array>, 9> gates = { - std::make_pair("and", std::vector{create_and_tt()}), - std::make_pair("xor", std::vector{create_xor_tt()}), - std::make_pair("or", std::vector{create_or_tt()}), - std::make_pair("xnor", std::vector{create_xnor_tt()}), - std::make_pair("fo2", std::vector{create_fan_out_tt()}), - std::make_pair("nor", std::vector{create_nor_tt()}), - std::make_pair("nand", std::vector{create_nand_tt()}), - std::make_pair("inv", std::vector{create_not_tt()}), - std::make_pair("wire", std::vector{create_id_tt()})}; - - const auto sidb_sim = sidb_simulation_parameters{2, -0.32, 5.6, 5.0}; - const is_operational_params is_op_params{sidb_sim}; - - maximum_defect_influence_position_and_distance_params max_defect_params{}; - max_defect_params.defect = - sidb_defect{fiction::sidb_defect_type::UNKNOWN, -1, is_op_params.simulation_parameters.epsilon_r, - is_op_params.simulation_parameters.lambda_tf}; - max_defect_params.additional_scanning_area = {100, 100}; - - defect_influence_operational_domain_params defect_params{}; - defect_params.defect_influence_params = max_defect_params; - defect_params.operational_params = is_op_params; - - for (const auto& [gate, truth_table] : gates) - { - // Create gate directory for plots - std::string gate_folder = fmt::format("{}{}/", output_folder, gate); - std::filesystem::create_directories(gate_folder); - - std::size_t gate_counter = 0; - std::size_t unequal_counter = 0; - std::size_t sample_grid_counter = 0; - std::size_t sample_contour_counter = 0; - - bool start_with_new_boolean_function = false; - - for (const auto& file : std::filesystem::directory_iterator(fmt::format("{}{}", folder, gate))) - { - if (gate_counter == 100) - { - start_with_new_boolean_function = true; - break; - } - const auto layout = read_sqd_layout(file.path().string()); - - if (layout.num_cells() != 22) - { - continue; - } - gate_counter++; - std::cout << gate_counter << std::endl; - - defect_influence_operational_domain_stats grid_stats{}; - const auto op_defect_grid = - defect_influence_operational_domain_grid_search(layout, truth_table, 1, defect_params, &grid_stats); - - // Define file paths for the CSV and SQD - const auto csv_path = fmt::format("{}{}_grid.csv", gate_folder, gate); - const auto sqd_path = fmt::format("{}/{}.sqd", gate_folder, gate); - - // Write the CSV file - write_defect_influence_operational_domain(op_defect_grid, csv_path); - - // Write the SQD layout - write_sqd_layout(layout, sqd_path); - - const auto avoidance_grid = defect_avoidance_distance(layout, op_defect_grid); - - defect_influence_operational_domain_stats contour_stats{}; - const auto op_defect_contour = defect_influence_operational_domain_contour_tracing( - layout, truth_table, 100, defect_params, &contour_stats); - const auto avoidance_contour = defect_avoidance_distance(layout, op_defect_contour); - - const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); - write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); - - sample_grid_counter += grid_stats.num_evaluated_defect_positions; - sample_contour_counter += contour_stats.num_evaluated_defect_positions; - - if (std::abs(avoidance_grid.minimum_defect_clearance - avoidance_contour.minimum_defect_clearance) > 0.1) - { // Log the simulation results - unequal_counter++; - std::cout << file.path().string() << std::endl; - } - } - simulation_exp(gate, gate_counter, sample_grid_counter, sample_contour_counter, unequal_counter); - simulation_exp.save(); - simulation_exp.table(); - if (start_with_new_boolean_function) - { - continue; - } - } - return EXIT_SUCCESS; -} diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp b/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp deleted file mode 100644 index e2210c282..000000000 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance_checking_robustness_with_newly_designed_gates.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "fiction/algorithms/physical_design/design_sidb_gates.hpp" -#include "fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp" -#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" -#include "fiction/algorithms/simulation/sidb/is_operational.hpp" -#include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" -#include "fiction/io/read_sqd_layout.hpp" -#include "fiction/io/write_defect_influence_operational_domain.hpp" -#include "fiction/io/write_sqd_layout.hpp" -#include "fiction/traits.hpp" -#include "fiction/types.hpp" -#include "fiction/utils/truth_table_utils.hpp" -#include "fiction_experiments.hpp" - -#include - -#include -#include -#include -#include -#include -#include - -using namespace fiction; - -int main() -{ - experiments::experiment simulation_exp{ - "Benchmark", "Gate Name", "distance_grid_search", "#samples_grid", - "distance_random", "#samples_random", "distance_contour", "#samples_contour", - }; - - static const std::string folder = fmt::format("{}bestagon_gates_type_tags/", EXPERIMENTS_PATH); - static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); - - static const std::array>, 1> gates = {{{"and", {create_and_tt()}}}}; - - auto lyt = - read_sqd_layout("/Users/jandrewniok/CLionProjects/fiction_fork/experiments/" - "skeleton_efficient_gate_designer/skeleton_hex_inputsdbp_2i1o.sqd"); - - const design_sidb_gates_params> params_2_in_1_out{ - is_operational_params{sidb_simulation_parameters{2, -0.32}}, - design_sidb_gates_params>::design_sidb_gates_mode::EXHAUSTIVE, - {{14, 12, 0}, {24, 23, 0}}, - 3}; - - const auto sidb_sim = sidb_simulation_parameters{2, -0.32, 5.6, 5.0}; - const is_operational_params is_op_params{sidb_sim}; - - maximum_defect_influence_position_and_distance_params max_defect_params{}; - max_defect_params.defect = - sidb_defect{fiction::sidb_defect_type::UNKNOWN, -1, is_op_params.simulation_parameters.epsilon_r, - is_op_params.simulation_parameters.lambda_tf}; - max_defect_params.additional_scanning_area = {100, 100}; - - defect_influence_operational_domain_params defect_params{}; - defect_params.defect_influence_params = max_defect_params; - defect_params.operational_params = is_op_params; - - for (const auto& [gate, truth_table] : gates) - { - const auto exhaustive_design = design_sidb_gates(lyt, truth_table, params_2_in_1_out); - std::cout << exhaustive_design.size() << std::endl; - // Create gate directory for plots - std::string gate_folder = fmt::format("{}{}/", output_folder, gate); - std::filesystem::create_directories(gate_folder); - - uint64_t counter = 0; - for (const auto& gate_lyt : exhaustive_design) - { - defect_influence_operational_domain_stats grid_stats{}; - const auto op_defect_grid = - defect_influence_operational_domain_grid_search(gate_lyt, truth_table, 1, defect_params, &grid_stats); - - // Define file paths for the CSV and SQD - const auto csv_path = fmt::format("{}{}_grid.csv", gate_folder, gate); - const auto sqd_path = fmt::format("{}/{}.sqd", gate_folder, gate); - - // Write the CSV file - write_defect_influence_operational_domain(op_defect_grid, csv_path); - - // Write the SQD layout - // write_sqd_layout(layout, sqd_path); - - const auto avoidance_grid = defect_avoidance_distance(gate_lyt, op_defect_grid); - - defect_influence_operational_domain_stats random_stats{}; - const auto op_defect_random = defect_influence_operational_domain_random_sampling( - gate_lyt, truth_table, 100, defect_params, &random_stats); - const auto avoidance_random = defect_avoidance_distance(gate_lyt, op_defect_random); - - const auto csv_path_random = fmt::format("{}{}_random.csv", gate_folder, gate); - write_defect_influence_operational_domain(op_defect_random, csv_path_random); - - defect_influence_operational_domain_stats contour_stats{}; - const auto op_defect_contour = defect_influence_operational_domain_contour_tracing( - gate_lyt, truth_table, 100, defect_params, &contour_stats); - const auto avoidance_contour = defect_avoidance_distance(gate_lyt, op_defect_contour); - - const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); - write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); - // - // simulation_exp(gate, avoidance_grid.minimum_defect_clearance, - // grid_stats.num_evaluated_defect_positions, - // avoidance_random.minimum_defect_clearance, - // random_stats.num_evaluated_defect_positions, - // avoidance_contour.minimum_defect_clearance, - // contour_stats.num_evaluated_defect_positions); - // simulation_exp.save(); - // simulation_exp.table(); - - if (std::abs(avoidance_grid.minimum_defect_clearance - avoidance_contour.minimum_defect_clearance) > 0.1) - { // Log the simulation results - write_sqd_layout(gate_lyt, sqd_path); - write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); - simulation_exp(gate, avoidance_grid.minimum_defect_clearance, grid_stats.num_evaluated_defect_positions, - avoidance_random.minimum_defect_clearance, random_stats.num_evaluated_defect_positions, - avoidance_contour.minimum_defect_clearance, - contour_stats.num_evaluated_defect_positions); - simulation_exp.save(); - simulation_exp.table(); - } - counter++; - std::cout << counter << std::endl; - } - } - return EXIT_SUCCESS; -} diff --git a/experiments/physical_design_with_on_the_fly_gate_design/physical_design_with_on_the_fly_gate_design.cpp b/experiments/physical_design_with_on_the_fly_gate_design/physical_design_with_on_the_fly_gate_design.cpp index d72e8b854..4e25a5e77 100644 --- a/experiments/physical_design_with_on_the_fly_gate_design/physical_design_with_on_the_fly_gate_design.cpp +++ b/experiments/physical_design_with_on_the_fly_gate_design/physical_design_with_on_the_fly_gate_design.cpp @@ -34,6 +34,7 @@ #include #include #include +#include // This script conducts defect-aware placement and routing with defect-aware on-the-fly SiDB gate design. Thereby, SiDB // circuits can be designed in the presence of atomic defects. diff --git a/experiments/quicktrace/quickrace_vs_grid_search_new_gates.cpp b/experiments/quicktrace/quickrace_vs_grid_search_new_gates.cpp new file mode 100644 index 000000000..6d3c39690 --- /dev/null +++ b/experiments/quicktrace/quickrace_vs_grid_search_new_gates.cpp @@ -0,0 +1,108 @@ +#include "fiction/algorithms/physical_design/design_sidb_gates.hpp" +#include "fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp" +#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" +#include "fiction/algorithms/simulation/sidb/is_operational.hpp" +#include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" +#include "fiction/io/read_sqd_layout.hpp" +#include "fiction/io/write_defect_influence_operational_domain.hpp" +#include "fiction/io/write_sqd_layout.hpp" +#include "fiction/traits.hpp" +#include "fiction/types.hpp" +#include "fiction/utils/truth_table_utils.hpp" +#include "fiction_experiments.hpp" + +#include + +#include +#include +#include +#include +#include +#include + +using namespace fiction; + +int main() +{ + experiments::experiment simulation_exp{"Benchmark", "Gate Name", "samples", + "wrong output quicktrace"}; + + static const std::string folder = fmt::format("{}bestagon_gates_type_tags/", EXPERIMENTS_PATH); + static const std::string output_folder = fmt::format("{}quicktrace/plots/", EXPERIMENTS_PATH); + + static const std::array>, 9> gates = { + std::make_pair("and", std::vector{create_and_tt()}), + std::make_pair("xor", std::vector{create_xor_tt()}), + std::make_pair("or", std::vector{create_or_tt()}), + std::make_pair("xnor", std::vector{create_xnor_tt()}), + std::make_pair("fo2", std::vector{create_fan_out_tt()}), + std::make_pair("nor", std::vector{create_nor_tt()}), + std::make_pair("nand", std::vector{create_nand_tt()}), + std::make_pair("inv", std::vector{create_not_tt()}), + std::make_pair("wire", std::vector{create_id_tt()})}; + + auto lyt = read_sqd_layout( + fmt::format("{}/gate_skeletons/skeleton_bestagons_with_tags/skeleton_hex_inputsdbp_2i1o.sqd", folder)); + + const design_sidb_gates_params> params_2_in_1_out{ + is_operational_params{sidb_simulation_parameters{2, -0.32}}, + design_sidb_gates_params< + cell>::design_sidb_gates_mode::AUTOMATIC_EXHAUSTIVE_GATE_DESIGNER, + {{14, 12, 0}, {24, 23, 0}}, + 3}; + + const auto sidb_sim = sidb_simulation_parameters{2, -0.32, 5.6, 5.0}; + const is_operational_params is_op_params{sidb_sim}; + + maximum_defect_influence_position_and_distance_params max_defect_params{}; + + // for this experiment we use a stray SiDB defect + const auto stray_db = fiction::sidb_defect{fiction::sidb_defect_type::DB, -1, 4.1, 1.8}; + // const auto si_vacancy = fiction::sidb_defect{fiction::sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}; + + max_defect_params.defect = stray_db; + + max_defect_params.additional_scanning_area = {100, 100}; + + defect_operational_domain_params defect_params{}; + defect_params.defect_influence_params = max_defect_params; + defect_params.operational_params = is_op_params; + + for (const auto& [gate, truth_table] : gates) + { + const auto exhaustive_design = design_sidb_gates(lyt, truth_table, params_2_in_1_out); + + // Create gate directory for plots + std::string gate_folder = fmt::format("{}{}/", output_folder, gate); + std::filesystem::create_directories(gate_folder); + + std::size_t counter_for_wrong_output_of_quicktrace = 0; + + for (const auto& gate_lyt : exhaustive_design) + { + // using grid search to find the minimum defect clearance + defect_operational_domain_stats grid_stats{}; + const auto op_defect_grid = + defect_influence_operational_domain_grid_search(gate_lyt, truth_table, 1, defect_params, &grid_stats); + const auto avoidance_grid = defect_avoidance_distance(gate_lyt, op_defect_grid); + + // using QuickTrace to find the minimum clearance + defect_operational_domain_stats contour_stats{}; + const auto op_defect_contour = + defect_operational_domain_quicktrace(gate_lyt, truth_table, 100, defect_params, &contour_stats); + const auto avoidance_contour = defect_avoidance_distance(gate_lyt, op_defect_contour); + + // check if QuickTrace and grid search give the same result + if (std::abs(avoidance_grid.minimum_defect_clearance - avoidance_contour.minimum_defect_clearance) > + 10E-6 && + avoidance_grid.max_distance_postion_of_non_operational_defect != + avoidance_contour.max_distance_postion_of_non_operational_defect) + { + counter_for_wrong_output_of_quicktrace++; + } + } + + simulation_exp(gate, exhaustive_design.size(), counter_for_wrong_output_of_quicktrace); + } + return EXIT_SUCCESS; +} diff --git a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp b/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp similarity index 82% rename from experiments/defect_avoidance_distance/defect_avoidance_distance.cpp rename to experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp index 12a4e869a..6d58ceecd 100644 --- a/experiments/defect_avoidance_distance/defect_avoidance_distance.cpp +++ b/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp @@ -9,6 +9,7 @@ #include "fiction/types.hpp" #include "fiction/utils/truth_table_utils.hpp" #include "fiction_experiments.hpp" +#include "fiction/technology/sidb_defects.hpp" #include @@ -34,7 +35,7 @@ int main() }; static const std::string folder = fmt::format("{}bestagon_gates_type_tags/", EXPERIMENTS_PATH); - static const std::string output_folder = fmt::format("{}defect_avoidance_distance/plots/", EXPERIMENTS_PATH); + static const std::string output_folder = fmt::format("{}quicktrace/plots/", EXPERIMENTS_PATH); static const std::array>, 9> gates = { std::make_pair("and", std::vector{create_and_tt()}), @@ -51,12 +52,15 @@ int main() const is_operational_params is_op_params{sidb_sim}; maximum_defect_influence_position_and_distance_params max_defect_params{}; - max_defect_params.defect = - sidb_defect{fiction::sidb_defect_type::UNKNOWN, -1, is_op_params.simulation_parameters.epsilon_r, - is_op_params.simulation_parameters.lambda_tf}; max_defect_params.additional_scanning_area = {50, 50}; - defect_influence_operational_domain_params defect_params{}; + // for this experiment we use a stray SiDB defect + const auto stray_db = fiction::sidb_defect{fiction::sidb_defect_type::DB, -1, 4.1, 1.8}; + // const auto si_vacancy = fiction::sidb_defect{fiction::sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}; + + max_defect_params.defect = stray_db; + + defect_operational_domain_params defect_params{}; defect_params.defect_influence_params = max_defect_params; defect_params.operational_params = is_op_params; @@ -70,9 +74,9 @@ int main() { const auto layout = read_sqd_layout(file.path().string()); - defect_influence_operational_domain_stats grid_stats{}; + defect_operational_domain_stats grid_stats{}; const auto op_defect_grid = - defect_influence_operational_domain_grid_search(layout, truth_table, 1, defect_params, &grid_stats); + defect_operational_domain_grid_search(layout, truth_table, 1, defect_params, &grid_stats); // Define file paths for the CSV and SQD const auto csv_path = fmt::format("{}{}_grid.csv", gate_folder, gate); @@ -86,17 +90,17 @@ int main() const auto avoidance_grid = defect_avoidance_distance(layout, op_defect_grid); - defect_influence_operational_domain_stats random_stats{}; - const auto op_defect_random = defect_influence_operational_domain_random_sampling( + defect_operational_domain_stats random_stats{}; + const auto op_defect_random = defect_operational_domain_random_sampling( layout, truth_table, 100, defect_params, &random_stats); const auto avoidance_random = defect_avoidance_distance(layout, op_defect_random); const auto csv_path_random = fmt::format("{}{}_random.csv", gate_folder, gate); write_defect_influence_operational_domain(op_defect_random, csv_path_random); - defect_influence_operational_domain_stats contour_stats{}; - const auto op_defect_contour = defect_influence_operational_domain_contour_tracing( - layout, truth_table, 20, defect_params, &contour_stats); + defect_operational_domain_stats contour_stats{}; + const auto op_defect_contour = + defect_operational_domain_quicktrace(layout, truth_table, 20, defect_params, &contour_stats); const auto avoidance_contour = defect_avoidance_distance(layout, op_defect_contour); const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); diff --git a/include/fiction/algorithms/optimization/simulated_annealing.hpp b/include/fiction/algorithms/optimization/simulated_annealing.hpp index 93db21db3..9304bb7c4 100644 --- a/include/fiction/algorithms/optimization/simulated_annealing.hpp +++ b/include/fiction/algorithms/optimization/simulated_annealing.hpp @@ -11,11 +11,13 @@ #include #include #include +#include #include #include #include #include #include +#include namespace fiction { @@ -43,7 +45,7 @@ constexpr auto geometric_temperature_schedule(const double t) noexcept /** * Available temperature schedule types. */ -enum class temperature_schedule +enum class temperature_schedule : uint8_t { /** * Linearly decreasing temperature schedule. @@ -198,7 +200,7 @@ multi_simulated_annealing(const double init_temp, const double final_temp, const assert(std::isfinite(final_temp) && "final_temp must be a finite number"); std::vector> results(instances); - std::vector threads; + std::vector threads{}; threads.reserve(instances); // Function to perform simulated annealing and store the result in the results vector diff --git a/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp b/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp index db6dbf810..d029a91af 100644 --- a/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp +++ b/include/fiction/algorithms/simulation/sidb/calculate_min_bbr_for_all_inputs.hpp @@ -8,7 +8,6 @@ #include "fiction/algorithms/iter/bdl_input_iterator.hpp" #include "fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp" #include "fiction/algorithms/simulation/sidb/can_positive_charges_occur.hpp" -#include "fiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" #include #include diff --git a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp index 0ef035787..8315ffb3d 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp @@ -44,7 +44,7 @@ struct defect_avoidance_distance_result */ template [[nodiscard]] defect_avoidance_distance_result> -defect_avoidance_distance(const Lyt& lyt, const defect_influence_operational_domain& defect_opdomain) noexcept +defect_avoidance_distance(const Lyt& lyt, const defect_operational_domain& defect_opdomain) noexcept { double max_distance = 0; cell max_distance_postion = {}; diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index a4632114a..09d177789 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -33,9 +33,9 @@ namespace fiction { /** - * Parameters to determine the defect influence operational domain. + * Parameters to determine the defect operational domain. */ -struct defect_influence_operational_domain_params +struct defect_operational_domain_params { /** * Parameters to simulate the influence of the atomic defect. @@ -51,20 +51,20 @@ struct defect_influence_operational_domain_params * information indicating whether the SiDB layout remains logically operational. Logically operational implies that the * layout's ground state aligns with a designated Boolean function at the layout's outputs for all feasible input * combinations. This implementation assumes the presence of \f$ n \f$ BDL input wires and a single BDL output wire for - * a given layout. Any algorithm for computing the defect influence operational domain iterates through all \f$ 2^n \f$ + * a given layout. Any algorithm for computing the defect operational domain iterates through all \f$ 2^n \f$ * input combinations, evaluating the layout's output behavior based on the specified Boolean function. The layout is * classified as operational for a particular defect position only if its output behavior is correct across all * input combinations. */ template -struct defect_influence_operational_domain +struct defect_operational_domain { locked_parallel_flat_hash_map operational_values{}; }; /** * Statistics. */ -struct defect_influence_operational_domain_stats +struct defect_operational_domain_stats { /** * The total runtime of the operational domain computation. @@ -92,12 +92,12 @@ namespace detail { template -class defect_influence_operational_domain_impl +class defect_operational_domain_impl { public: - defect_influence_operational_domain_impl(const Lyt& lyt, const std::vector& tt, - const defect_influence_operational_domain_params& ps, - defect_influence_operational_domain_stats& st) : + defect_operational_domain_impl(const Lyt& lyt, const std::vector& tt, + const defect_operational_domain_params& ps, + defect_operational_domain_stats& st) : layout{lyt}, truth_table{tt}, params{ps}, @@ -115,7 +115,7 @@ class defect_influence_operational_domain_impl * coordinates divisible by `step_size` will be checked for being operational. * @return A `defect_influence_operational_domain` object representing the operational domain of the defects. */ - [[nodiscard]] defect_influence_operational_domain grid_search(const std::size_t& step_size) noexcept + [[nodiscard]] defect_operational_domain grid_search(const std::size_t& step_size) noexcept { mockturtle::stopwatch stop{stats.time_total}; const auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); @@ -166,10 +166,10 @@ class defect_influence_operational_domain_impl * * @param samples The number of positions to sample. The actual number of iterations will be the smaller of * the total number of positions or the `samples` value. - * @return A `defect_influence_operational_domain` object representing the operational domain of the defects. + * @return A `defect_operational_domain` object representing the operational domain of the defects. * The return value is marked [[nodiscard]], meaning it must be used by the caller. */ - [[nodiscard]] defect_influence_operational_domain random_sampling(const std::size_t samples) noexcept + [[nodiscard]] defect_operational_domain random_sampling(const std::size_t samples) noexcept { mockturtle::stopwatch stop{stats.time_total}; // Start the stopwatch for performance measurement @@ -223,7 +223,7 @@ class defect_influence_operational_domain_impl return defect_operational_domain; } - [[nodiscard]] defect_influence_operational_domain contour_tracing(const std::size_t samples) noexcept + [[nodiscard]] defect_operational_domain contour_tracing(const std::size_t samples) noexcept { mockturtle::stopwatch stop{stats.time_total}; @@ -593,7 +593,7 @@ class defect_influence_operational_domain_impl /** * The parameters for the operational domain computation. */ - const defect_influence_operational_domain_params& params; + const defect_operational_domain_params& params; /** * North-west cell. */ @@ -621,11 +621,11 @@ class defect_influence_operational_domain_impl /** * The operational domain of the layout. */ - defect_influence_operational_domain defect_operational_domain{}; + defect_operational_domain defect_operational_domain{}; /** * The statistics of the operational domain computation. */ - defect_influence_operational_domain_stats& stats; + defect_operational_domain_stats& stats; /** * Number of simulator invocations. */ @@ -639,36 +639,35 @@ class defect_influence_operational_domain_impl } // namespace detail /** - * Computes the defect influence operational domain of the given SiDB layout. The defect influence - * operational domain is the set of all defect positions for which the layout is logically operational. Logical + * Computes the defect operational domain of the given SiDB layout. The defect operational domain is the set of all defect positions for which the layout is logically operational. Logical * operation is defined as the layout implementing the given truth table. * - * This algorithm uses a grid search to determine the defect influence operational domain. The grid search is performed + * This algorithm uses a grid search to determine the defect operational domain. The grid search is performed * by exhaustively sweeping all possible atomic defect positions in x and y dimensions. * * @tparam Lyt SiDB cell-level layout type. * @tparam TT Truth table type. - * @param lyt Layout to compute the defect influence operational domain for. + * @param lyt Layout to compute the defect operational domain for. * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param step_size The parameter specifying the interval between consecutive defect positions to be evaluated. - * @param params Defect influence operational domain computation parameters. + * @param params Defect operational domain computation parameters. * @param stats Statistics. - * @return The defect influence operational domain of the layout. + * @return The defect operational domain of the layout. */ template -defect_influence_operational_domain -defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vector& spec, +defect_operational_domain +defect_operational_domain_grid_search(const Lyt& lyt, const std::vector& spec, const std::size_t step_size = 1, - const defect_influence_operational_domain_params& params = {}, - defect_influence_operational_domain_stats* stats = nullptr) + const defect_operational_domain_params& params = {}, + defect_operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); static_assert(has_cube_coord_v); - defect_influence_operational_domain_stats st{}; - detail::defect_influence_operational_domain_impl p{lyt, spec, params, st}; + defect_operational_domain_stats st{}; + detail::defect_operational_domain_impl p{lyt, spec, params, st}; const auto result = p.grid_search(step_size); @@ -680,36 +679,35 @@ defect_influence_operational_domain_grid_search(const Lyt& lyt, const std::vecto return result; } /** - * Computes the `defect influence operational domain` of the given SiDB cell-level layout. The defect influence - * operational domain is the set of all defect positions for which the layout is logically operational. Logical + * Computes the `defect operational domain` of the given SiDB cell-level layout. The defect operational domain is the set of all defect positions for which the layout is logically operational. Logical * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed * to be in the same order as the inputs of the truth table. * - * This algorithm uses random sampling to find a part of the defect influence operational domain that might not be + * This algorithm uses random sampling to find a part of the defect operational domain that might not be * complete. It performs a total of `samples` uniformly-distributed random samples within the specified area. * * @tparam Lyt SiDB cell-level layout type. * @tparam TT Truth table type. - * @param lyt Layout to compute the defect influence operational domain for. + * @param lyt Layout to compute the defect operational domain for. * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param samples Number of random samples to perform. - * @param params Defect influence operational domain computation parameters. + * @param params Defect operational domain computation parameters. * @param stats Statistics. - * @return The (partial) defect influence operational domain of the layout. + * @return The (partial) defect operational domain of the layout. */ template -defect_influence_operational_domain -defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::vector& spec, std::size_t samples, - const defect_influence_operational_domain_params& params = {}, - defect_influence_operational_domain_stats* stats = nullptr) +defect_operational_domain +defect_operational_domain_random_sampling(const Lyt& lyt, const std::vector& spec, std::size_t samples, + const defect_operational_domain_params& params = {}, + defect_operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); static_assert(has_cube_coord_v, "Lyt is not based on cube coordinates"); - defect_influence_operational_domain_stats st{}; - detail::defect_influence_operational_domain_impl p{lyt, spec, params, st}; + defect_operational_domain_stats st{}; + detail::defect_operational_domain_impl p{lyt, spec, params, st}; const auto result = p.random_sampling(samples); @@ -722,7 +720,7 @@ defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::v } /** - * Computes the defect influence operational domain of the given SiDB cell-level layout. The defect influence + * Computes the defect operational domain of the given SiDB cell-level layout. The defect * operational domain is the set of all defect positions for which the layout is logically operational. Logical * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed * to be in the same order as the inputs of the truth table. @@ -736,32 +734,28 @@ defect_influence_operational_domain_random_sampling(const Lyt& lyt, const std::v * contour includes the SiDB layout. If it does not, the next random sample point is selected as the starting point * and the process is repeated. * - * @Note This algorithm is an approximation to determine the defect influence operational domain. Therefore, it - * is recommended to analyze the result afterwards to assess whether the contour reflects the desired contour. - * * @tparam Lyt SiDB cell-level layout type. * @tparam TT Truth table type. - * @param lyt Layout to compute the defect influence operational domain for. + * @param lyt Layout to compute the defect operational domain for. * @param spec Expected Boolean function of the layout given as a multi-output truth table. * @param samples Number of samples to perform. - * @param params Defect influence operational domain computation parameters. + * @param params Defect operational domain computation parameters. * @param stats Operational domain computation statistics. - * @return The (partial) defect influence operational domain of the layout. + * @return The (partial) defect operational domain of the layout. */ template -defect_influence_operational_domain -defect_influence_operational_domain_contour_tracing(const Lyt& lyt, const std::vector& spec, - const std::size_t samples, - const defect_influence_operational_domain_params& params = {}, - defect_influence_operational_domain_stats* stats = nullptr) +defect_operational_domain +defect_operational_domain_quicktrace(const Lyt& lyt, const std::vector& spec, const std::size_t samples, + const defect_operational_domain_params& params = {}, + defect_operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(kitty::is_truth_table::value, "TT is not a truth table"); static_assert(has_cube_coord_v, "Lyt is not based on cube coordinates"); - defect_influence_operational_domain_stats st{}; - detail::defect_influence_operational_domain_impl p{lyt, spec, params, st}; + defect_operational_domain_stats st{}; + detail::defect_operational_domain_impl p{lyt, spec, params, st}; const auto result = p.contour_tracing(samples); diff --git a/include/fiction/io/write_defect_influence_operational_domain.hpp b/include/fiction/io/write_defect_influence_operational_domain.hpp index ccab7bf87..403d563ae 100644 --- a/include/fiction/io/write_defect_influence_operational_domain.hpp +++ b/include/fiction/io/write_defect_influence_operational_domain.hpp @@ -50,7 +50,7 @@ struct write_defect_operational_domain_params * empty `write_defect_operational_domain_params` object, which provides standard tags. */ template -inline void write_defect_influence_operational_domain(const defect_influence_operational_domain& defect_opdom, +inline void write_defect_influence_operational_domain(const defect_operational_domain& defect_opdom, std::ostream& os, const write_defect_operational_domain_params& params = {}) { @@ -83,7 +83,7 @@ inline void write_defect_influence_operational_domain(const defect_influence_ope * empty `write_defect_operational_domain_params` object, which provides standard tags. */ template -inline void write_defect_influence_operational_domain(const defect_influence_operational_domain& defect_opdom, +inline void write_defect_influence_operational_domain(const defect_operational_domain& defect_opdom, const std::string_view& filename, const write_defect_operational_domain_params& params = {}) { diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 34413176d..b0e3226b0 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -64,21 +64,21 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); write_sqd_layout( - lyt, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/defect_avoidance_distance/plots/and/and.sqd"); + lyt, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/quicktrace/plots/and/and.sqd"); const auto cube_lyt = convert_layout_to_fiction_coordinates(lyt); const sidb_defect sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}; const maximum_defect_influence_position_and_distance_params sim_params{sidb_defect, sidb_simulation_parameters{2, -0.32}}; - defect_influence_operational_domain_params params{sim_params, + defect_operational_domain_params params{sim_params, is_operational_params{sim_params.simulation_parameters}}; SECTION("Grid Search") { params.defect_influence_params.additional_scanning_area = {20, 20}; - defect_influence_operational_domain_stats stats{}; - const auto defect_influence_domain = defect_influence_operational_domain_grid_search( + defect_operational_domain_stats stats{}; + const auto defect_influence_domain = defect_operational_domain_grid_search( cube_lyt, std::vector{create_or_tt()}, 1, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); @@ -87,8 +87,8 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again SECTION("Random Sampling") { params.defect_influence_params.additional_scanning_area = {20, 20}; - defect_influence_operational_domain_stats stats{}; - const auto defect_influence_domain = defect_influence_operational_domain_random_sampling( + defect_operational_domain_stats stats{}; + const auto defect_influence_domain = defect_operational_domain_random_sampling( cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= 12.579477930); @@ -97,9 +97,9 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again SECTION("Contour Tracing") { params.defect_influence_params.additional_scanning_area = {20, 20}; - defect_influence_operational_domain_stats stats{}; - const auto defect_influence_domain = defect_influence_operational_domain_contour_tracing( - cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); + defect_operational_domain_stats stats{}; + const auto defect_influence_domain = + defect_operational_domain_quicktrace(cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); } diff --git a/test/algorithms/simulation/sidb/is_operational.cpp b/test/algorithms/simulation/sidb/is_operational.cpp index 0e38b2498..d6b57b066 100644 --- a/test/algorithms/simulation/sidb/is_operational.cpp +++ b/test/algorithms/simulation/sidb/is_operational.cpp @@ -132,39 +132,7 @@ TEST_CASE("Bestagon CROSSING gate", "[is-operational]") TEST_CASE("Bestagon AND gate", "[is-operational]") { - const auto lyt = blueprints::bestagon_and(); - using layout = sidb_defect_cell_clk_lyt_siqad; - - layout lyt{}; - - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({23, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 11, 1}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 9, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 8, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + auto lyt = blueprints::bestagon_and(); const sidb_simulation_parameters params{2, -0.32}; From afcec19791db1c9d884279dba6057d9319fb999a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2024 08:38:53 +0000 Subject: [PATCH 137/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...cal_design_with_on_the_fly_gate_design.cpp | 2 +- .../quickrace_vs_grid_search_new_gates.cpp | 6 ++-- .../quicktrace_vs_grid_search_bestagon.cpp | 13 ++++--- .../defect_influence_operational_domain.hpp | 34 +++++++++---------- ...te_defect_influence_operational_domain.hpp | 12 +++---- .../defect_influence_operational_domain.cpp | 16 ++++----- 6 files changed, 40 insertions(+), 43 deletions(-) diff --git a/experiments/physical_design_with_on_the_fly_gate_design/physical_design_with_on_the_fly_gate_design.cpp b/experiments/physical_design_with_on_the_fly_gate_design/physical_design_with_on_the_fly_gate_design.cpp index 4e25a5e77..065d5371e 100644 --- a/experiments/physical_design_with_on_the_fly_gate_design/physical_design_with_on_the_fly_gate_design.cpp +++ b/experiments/physical_design_with_on_the_fly_gate_design/physical_design_with_on_the_fly_gate_design.cpp @@ -32,9 +32,9 @@ #include #include +#include #include #include -#include // This script conducts defect-aware placement and routing with defect-aware on-the-fly SiDB gate design. Thereby, SiDB // circuits can be designed in the presence of atomic defects. diff --git a/experiments/quicktrace/quickrace_vs_grid_search_new_gates.cpp b/experiments/quicktrace/quickrace_vs_grid_search_new_gates.cpp index 6d3c39690..395c01663 100644 --- a/experiments/quicktrace/quickrace_vs_grid_search_new_gates.cpp +++ b/experiments/quicktrace/quickrace_vs_grid_search_new_gates.cpp @@ -81,14 +81,14 @@ int main() for (const auto& gate_lyt : exhaustive_design) { // using grid search to find the minimum defect clearance - defect_operational_domain_stats grid_stats{}; - const auto op_defect_grid = + defect_operational_domain_stats grid_stats{}; + const auto op_defect_grid = defect_influence_operational_domain_grid_search(gate_lyt, truth_table, 1, defect_params, &grid_stats); const auto avoidance_grid = defect_avoidance_distance(gate_lyt, op_defect_grid); // using QuickTrace to find the minimum clearance defect_operational_domain_stats contour_stats{}; - const auto op_defect_contour = + const auto op_defect_contour = defect_operational_domain_quicktrace(gate_lyt, truth_table, 100, defect_params, &contour_stats); const auto avoidance_contour = defect_avoidance_distance(gate_lyt, op_defect_contour); diff --git a/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp b/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp index 6d58ceecd..b828a4d07 100644 --- a/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp +++ b/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp @@ -1,15 +1,14 @@ #include "fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp" - #include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" #include "fiction/io/read_sqd_layout.hpp" #include "fiction/io/write_defect_influence_operational_domain.hpp" #include "fiction/io/write_sqd_layout.hpp" +#include "fiction/technology/sidb_defects.hpp" #include "fiction/types.hpp" #include "fiction/utils/truth_table_utils.hpp" #include "fiction_experiments.hpp" -#include "fiction/technology/sidb_defects.hpp" #include @@ -74,8 +73,8 @@ int main() { const auto layout = read_sqd_layout(file.path().string()); - defect_operational_domain_stats grid_stats{}; - const auto op_defect_grid = + defect_operational_domain_stats grid_stats{}; + const auto op_defect_grid = defect_operational_domain_grid_search(layout, truth_table, 1, defect_params, &grid_stats); // Define file paths for the CSV and SQD @@ -91,15 +90,15 @@ int main() const auto avoidance_grid = defect_avoidance_distance(layout, op_defect_grid); defect_operational_domain_stats random_stats{}; - const auto op_defect_random = defect_operational_domain_random_sampling( - layout, truth_table, 100, defect_params, &random_stats); + const auto op_defect_random = + defect_operational_domain_random_sampling(layout, truth_table, 100, defect_params, &random_stats); const auto avoidance_random = defect_avoidance_distance(layout, op_defect_random); const auto csv_path_random = fmt::format("{}{}_random.csv", gate_folder, gate); write_defect_influence_operational_domain(op_defect_random, csv_path_random); defect_operational_domain_stats contour_stats{}; - const auto op_defect_contour = + const auto op_defect_contour = defect_operational_domain_quicktrace(layout, truth_table, 20, defect_params, &contour_stats); const auto avoidance_contour = defect_avoidance_distance(layout, op_defect_contour); diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 09d177789..d5a17dd04 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -96,8 +96,7 @@ class defect_operational_domain_impl { public: defect_operational_domain_impl(const Lyt& lyt, const std::vector& tt, - const defect_operational_domain_params& ps, - defect_operational_domain_stats& st) : + const defect_operational_domain_params& ps, defect_operational_domain_stats& st) : layout{lyt}, truth_table{tt}, params{ps}, @@ -639,8 +638,9 @@ class defect_operational_domain_impl } // namespace detail /** - * Computes the defect operational domain of the given SiDB layout. The defect operational domain is the set of all defect positions for which the layout is logically operational. Logical - * operation is defined as the layout implementing the given truth table. + * Computes the defect operational domain of the given SiDB layout. The defect operational domain is the set of all + * defect positions for which the layout is logically operational. Logical operation is defined as the layout + * implementing the given truth table. * * This algorithm uses a grid search to determine the defect operational domain. The grid search is performed * by exhaustively sweeping all possible atomic defect positions in x and y dimensions. @@ -656,10 +656,9 @@ class defect_operational_domain_impl */ template defect_operational_domain -defect_operational_domain_grid_search(const Lyt& lyt, const std::vector& spec, - const std::size_t step_size = 1, - const defect_operational_domain_params& params = {}, - defect_operational_domain_stats* stats = nullptr) +defect_operational_domain_grid_search(const Lyt& lyt, const std::vector& spec, const std::size_t step_size = 1, + const defect_operational_domain_params& params = {}, + defect_operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -679,9 +678,10 @@ defect_operational_domain_grid_search(const Lyt& lyt, const std::vector& spe return result; } /** - * Computes the `defect operational domain` of the given SiDB cell-level layout. The defect operational domain is the set of all defect positions for which the layout is logically operational. Logical - * operation is defined as the layout implementing the given truth table. The input BDL pairs of the layout are assumed - * to be in the same order as the inputs of the truth table. + * Computes the `defect operational domain` of the given SiDB cell-level layout. The defect operational domain is the + * set of all defect positions for which the layout is logically operational. Logical operation is defined as the layout + * implementing the given truth table. The input BDL pairs of the layout are assumed to be in the same order as the + * inputs of the truth table. * * This algorithm uses random sampling to find a part of the defect operational domain that might not be * complete. It performs a total of `samples` uniformly-distributed random samples within the specified area. @@ -698,8 +698,8 @@ defect_operational_domain_grid_search(const Lyt& lyt, const std::vector& spe template defect_operational_domain defect_operational_domain_random_sampling(const Lyt& lyt, const std::vector& spec, std::size_t samples, - const defect_operational_domain_params& params = {}, - defect_operational_domain_stats* stats = nullptr) + const defect_operational_domain_params& params = {}, + defect_operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); @@ -744,10 +744,10 @@ defect_operational_domain_random_sampling(const Lyt& lyt, const std::vector& * @return The (partial) defect operational domain of the layout. */ template -defect_operational_domain -defect_operational_domain_quicktrace(const Lyt& lyt, const std::vector& spec, const std::size_t samples, - const defect_operational_domain_params& params = {}, - defect_operational_domain_stats* stats = nullptr) +defect_operational_domain defect_operational_domain_quicktrace(const Lyt& lyt, const std::vector& spec, + const std::size_t samples, + const defect_operational_domain_params& params = {}, + defect_operational_domain_stats* stats = nullptr) { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); diff --git a/include/fiction/io/write_defect_influence_operational_domain.hpp b/include/fiction/io/write_defect_influence_operational_domain.hpp index 403d563ae..781bddb08 100644 --- a/include/fiction/io/write_defect_influence_operational_domain.hpp +++ b/include/fiction/io/write_defect_influence_operational_domain.hpp @@ -50,9 +50,9 @@ struct write_defect_operational_domain_params * empty `write_defect_operational_domain_params` object, which provides standard tags. */ template -inline void write_defect_influence_operational_domain(const defect_operational_domain& defect_opdom, - std::ostream& os, - const write_defect_operational_domain_params& params = {}) +inline void write_defect_influence_operational_domain(const defect_operational_domain& defect_opdom, + std::ostream& os, + const write_defect_operational_domain_params& params = {}) { csv_writer writer{os}; @@ -83,9 +83,9 @@ inline void write_defect_influence_operational_domain(const defect_operational_d * empty `write_defect_operational_domain_params` object, which provides standard tags. */ template -inline void write_defect_influence_operational_domain(const defect_operational_domain& defect_opdom, - const std::string_view& filename, - const write_defect_operational_domain_params& params = {}) +inline void write_defect_influence_operational_domain(const defect_operational_domain& defect_opdom, + const std::string_view& filename, + const write_defect_operational_domain_params& params = {}) { std::ofstream os{filename.data(), std::ofstream::out}; diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index b0e3226b0..5bbb9bf9d 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -63,23 +63,21 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - write_sqd_layout( - lyt, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/quicktrace/plots/and/and.sqd"); + write_sqd_layout(lyt, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/quicktrace/plots/and/and.sqd"); const auto cube_lyt = convert_layout_to_fiction_coordinates(lyt); const sidb_defect sidb_defect{sidb_defect_type::SI_VACANCY, -1, 10.6, 5.9}; const maximum_defect_influence_position_and_distance_params sim_params{sidb_defect, sidb_simulation_parameters{2, -0.32}}; - defect_operational_domain_params params{sim_params, - is_operational_params{sim_params.simulation_parameters}}; + defect_operational_domain_params params{sim_params, is_operational_params{sim_params.simulation_parameters}}; SECTION("Grid Search") { params.defect_influence_params.additional_scanning_area = {20, 20}; defect_operational_domain_stats stats{}; - const auto defect_influence_domain = defect_operational_domain_grid_search( - cube_lyt, std::vector{create_or_tt()}, 1, params, &stats); + const auto defect_influence_domain = + defect_operational_domain_grid_search(cube_lyt, std::vector{create_or_tt()}, 1, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); } @@ -88,8 +86,8 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again { params.defect_influence_params.additional_scanning_area = {20, 20}; defect_operational_domain_stats stats{}; - const auto defect_influence_domain = defect_operational_domain_random_sampling( - cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); + const auto defect_influence_domain = + defect_operational_domain_random_sampling(cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= 12.579477930); } @@ -98,7 +96,7 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again { params.defect_influence_params.additional_scanning_area = {20, 20}; defect_operational_domain_stats stats{}; - const auto defect_influence_domain = + const auto defect_influence_domain = defect_operational_domain_quicktrace(cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); From 652b0587821645de5b93bc8474d9fb3ba9c936bf Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 30 Oct 2024 08:39:36 +0000 Subject: [PATCH 138/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/pybind11_mkdoc_docstrings.hpp | 212 +++++++++--------- 1 file changed, 103 insertions(+), 109 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index e5f96793f..f61231c01 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -3828,7 +3828,7 @@ Parameter ``neutral_defect_spacing_overwrite``: A pair of uint16_t values representing the number of horizontal and vertical SiDBs affected by the given defect type.)doc"; -static const char *__doc_fiction_defect_influence_operational_domain = +static const char *__doc_fiction_defect_operational_domain = R"doc(A defect operational domain defines the positions where a specific atomic defect may exist along with corresponding information indicating whether the SiDB layout remains logically operational. @@ -3836,38 +3836,22 @@ Logically operational implies that the layout's ground state aligns with a designated Boolean function at the layout's outputs for all feasible input combinations. This implementation assumes the presence of :math:` n ` BDL input wires and a single BDL output wire for a -given layout. Any algorithm for computing the defect influence -operational domain iterates through all :math:` 2^n ` input -combinations, evaluating the layout's output behavior based on the -specified Boolean function. The layout is classified as operational -for a particular defect position only if its output behavior is -correct across all input combinations.)doc"; - -static const char *__doc_fiction_defect_influence_operational_domain_contour_tracing = -R"doc(Computes the defect influence operational domain of the given SiDB -cell-level layout. The defect influence operational domain is the set -of all defect positions for which the layout is logically operational. -Logical operation is defined as the layout implementing the given -truth table. The input BDL pairs of the layout are assumed to be in -the same order as the inputs of the truth table. - -This algorithm uses contour tracing to identify operational defect -locations within the SiDB gate layout. It starts by searching for -defect locations on the left side (bounding_box + additional scanning -area). The y-coordinate for these positions is chosen randomly. The -number of samples is determined by the `samples` parameter. - -Then the algorithm moves each defect position to the right, searching -for the last operational defect position. This position is selected as -the starting point for the contour trace. The contour tracing process -checks whether the contour includes the SiDB layout. If it does not, -the next random sample point is selected as the starting point and the -process is repeated. - -@Note This algorithm is an approximation to determine the defect -influence operational domain. Therefore, it is recommended to analyze -the result afterwards to assess whether the contour reflects the -desired contour. +given layout. Any algorithm for computing the defect operational +domain iterates through all :math:` 2^n ` input combinations, +evaluating the layout's output behavior based on the specified Boolean +function. The layout is classified as operational for a particular +defect position only if its output behavior is correct across all +input combinations.)doc"; + +static const char *__doc_fiction_defect_operational_domain_grid_search = +R"doc(Computes the defect operational domain of the given SiDB layout. The +defect operational domain is the set of all defect positions for which +the layout is logically operational. Logical operation is defined as +the layout implementing the given truth table. + +This algorithm uses a grid search to determine the defect operational +domain. The grid search is performed by exhaustively sweeping all +possible atomic defect positions in x and y dimensions. Template parameter ``Lyt``: SiDB cell-level layout type. @@ -3876,34 +3860,53 @@ Template parameter ``TT``: Truth table type. Parameter ``lyt``: - Layout to compute the defect influence operational domain for. + Layout to compute the defect operational domain for. Parameter ``spec``: Expected Boolean function of the layout given as a multi-output truth table. -Parameter ``samples``: - Number of samples to perform. +Parameter ``step_size``: + The parameter specifying the interval between consecutive defect + positions to be evaluated. Parameter ``params``: - Defect influence operational domain computation parameters. + Defect operational domain computation parameters. Parameter ``stats``: - Operational domain computation statistics. + Statistics. Returns: - The (partial) defect influence operational domain of the layout.)doc"; + The defect operational domain of the layout.)doc"; + +static const char *__doc_fiction_defect_operational_domain_operational_values = R"doc()doc"; -static const char *__doc_fiction_defect_influence_operational_domain_grid_search = -R"doc(Computes the defect influence operational domain of the given SiDB -layout. The defect influence operational domain is the set of all -defect positions for which the layout is logically operational. -Logical operation is defined as the layout implementing the given -truth table. +static const char *__doc_fiction_defect_operational_domain_params = R"doc(Parameters to determine the defect operational domain.)doc"; -This algorithm uses a grid search to determine the defect influence -operational domain. The grid search is performed by exhaustively -sweeping all possible atomic defect positions in x and y dimensions. +static const char *__doc_fiction_defect_operational_domain_params_defect_influence_params = R"doc(Parameters to simulate the influence of the atomic defect.)doc"; + +static const char *__doc_fiction_defect_operational_domain_params_operational_params = R"doc(Parameters for the `is_operational` algorithm.)doc"; + +static const char *__doc_fiction_defect_operational_domain_quicktrace = +R"doc(Computes the defect operational domain of the given SiDB cell-level +layout. The defect operational domain is the set of all defect +positions for which the layout is logically operational. Logical +operation is defined as the layout implementing the given truth table. +The input BDL pairs of the layout are assumed to be in the same order +as the inputs of the truth table. + +This algorithm uses contour tracing to identify operational defect +locations within the SiDB gate layout. It starts by searching for +defect locations on the left side (bounding_box + additional scanning +area). The y-coordinate for these positions is chosen randomly. The +number of samples is determined by the `samples` parameter. + +Then the algorithm moves each defect position to the right, searching +for the last operational defect position. This position is selected as +the starting point for the contour trace. The contour tracing process +checks whether the contour includes the SiDB layout. If it does not, +the next random sample point is selected as the starting point and the +process is repeated. Template parameter ``Lyt``: SiDB cell-level layout type. @@ -3912,45 +3915,36 @@ Template parameter ``TT``: Truth table type. Parameter ``lyt``: - Layout to compute the defect influence operational domain for. + Layout to compute the defect operational domain for. Parameter ``spec``: Expected Boolean function of the layout given as a multi-output truth table. -Parameter ``step_size``: - The parameter specifying the interval between consecutive defect - positions to be evaluated. +Parameter ``samples``: + Number of samples to perform. Parameter ``params``: - Defect influence operational domain computation parameters. + Defect operational domain computation parameters. Parameter ``stats``: - Statistics. + Operational domain computation statistics. Returns: - The defect influence operational domain of the layout.)doc"; - -static const char *__doc_fiction_defect_influence_operational_domain_operational_values = R"doc()doc"; - -static const char *__doc_fiction_defect_influence_operational_domain_params = R"doc(Parameters to determine the defect influence operational domain.)doc"; + The (partial) defect operational domain of the layout.)doc"; -static const char *__doc_fiction_defect_influence_operational_domain_params_defect_influence_params = R"doc(Parameters to simulate the influence of the atomic defect.)doc"; - -static const char *__doc_fiction_defect_influence_operational_domain_params_operational_params = R"doc(Parameters for the `is_operational` algorithm.)doc"; - -static const char *__doc_fiction_defect_influence_operational_domain_random_sampling = -R"doc(Computes the `defect influence operational domain` of the given SiDB -cell-level layout. The defect influence operational domain is the set -of all defect positions for which the layout is logically operational. -Logical operation is defined as the layout implementing the given -truth table. The input BDL pairs of the layout are assumed to be in -the same order as the inputs of the truth table. +static const char *__doc_fiction_defect_operational_domain_random_sampling = +R"doc(Computes the `defect operational domain` of the given SiDB cell-level +layout. The defect operational domain is the set of all defect +positions for which the layout is logically operational. Logical +operation is defined as the layout implementing the given truth table. +The input BDL pairs of the layout are assumed to be in the same order +as the inputs of the truth table. This algorithm uses random sampling to find a part of the defect -influence operational domain that might not be complete. It performs a -total of `samples` uniformly-distributed random samples within the -specified area. +operational domain that might not be complete. It performs a total of +`samples` uniformly-distributed random samples within the specified +area. Template parameter ``Lyt``: SiDB cell-level layout type. @@ -3959,7 +3953,7 @@ Template parameter ``TT``: Truth table type. Parameter ``lyt``: - Layout to compute the defect influence operational domain for. + Layout to compute the defect operational domain for. Parameter ``spec``: Expected Boolean function of the layout given as a multi-output @@ -3969,27 +3963,27 @@ Parameter ``samples``: Number of random samples to perform. Parameter ``params``: - Defect influence operational domain computation parameters. + Defect operational domain computation parameters. Parameter ``stats``: Statistics. Returns: - The (partial) defect influence operational domain of the layout.)doc"; + The (partial) defect operational domain of the layout.)doc"; -static const char *__doc_fiction_defect_influence_operational_domain_stats = R"doc(Statistics.)doc"; +static const char *__doc_fiction_defect_operational_domain_stats = R"doc(Statistics.)doc"; -static const char *__doc_fiction_defect_influence_operational_domain_stats_duration = R"doc(The total runtime of the operational domain computation.)doc"; +static const char *__doc_fiction_defect_operational_domain_stats_duration = R"doc(The total runtime of the operational domain computation.)doc"; -static const char *__doc_fiction_defect_influence_operational_domain_stats_num_evaluated_defect_positions = R"doc(Number of evaluated parameter combinations.)doc"; +static const char *__doc_fiction_defect_operational_domain_stats_num_evaluated_defect_positions = R"doc(Number of evaluated parameter combinations.)doc"; -static const char *__doc_fiction_defect_influence_operational_domain_stats_num_non_operational_defect_positions = +static const char *__doc_fiction_defect_operational_domain_stats_num_non_operational_defect_positions = R"doc(Number of parameter combinations, for which the layout is non- operational.)doc"; -static const char *__doc_fiction_defect_influence_operational_domain_stats_num_operational_defect_positions = R"doc(Number of parameter combinations, for which the layout is operational.)doc"; +static const char *__doc_fiction_defect_operational_domain_stats_num_operational_defect_positions = R"doc(Number of parameter combinations, for which the layout is operational.)doc"; -static const char *__doc_fiction_defect_influence_operational_domain_stats_num_simulator_invocations = R"doc(Number of simulator invocations.)doc"; +static const char *__doc_fiction_defect_operational_domain_stats_num_simulator_invocations = R"doc(Number of simulator invocations.)doc"; static const char *__doc_fiction_dependent_cell_mode = R"doc(An enumeration of modes for the dependent cell.)doc"; @@ -4807,21 +4801,21 @@ Parameter ``bdl_iterator``: static const char *__doc_fiction_detail_critical_temperature_impl_stats = R"doc(Statistics.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl = R"doc()doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl = R"doc()doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_contour_tracing = R"doc()doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_contour_tracing = R"doc()doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_current_defect_position = R"doc(The current defect position.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_current_defect_position = R"doc(The current defect position.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_defect_influence_operational_domain_impl = R"doc()doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_defect_operational_domain = R"doc(The operational domain of the layout.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_defect_operational_domain = R"doc(The operational domain of the layout.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_defect_operational_domain_impl = R"doc()doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_determine_nw_se_cells = +static const char *__doc_fiction_detail_defect_operational_domain_impl_determine_nw_se_cells = R"doc(This function determines the northwest and southeast cells based on the gate layout and the additional scan area specified.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_find_last_operational_defect_position_moving_right = +static const char *__doc_fiction_detail_defect_operational_domain_impl_find_last_operational_defect_position_moving_right = R"doc(This function identifies the most recent operational defect position while traversing from left to right towards the SiDB gate. @@ -4832,13 +4826,13 @@ Parameter ``starting_defect_position``: Returns: The last operational defect position.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_find_operational_defect_position_at_left_side = +static const char *__doc_fiction_detail_defect_operational_domain_impl_find_operational_defect_position_at_left_side = R"doc(This function aims to identify an operational defect position within the layout. It does so by selecting a defect position with the leftmost x-coordinate and a randomly selected y-coordinate limited the layout's bounding box.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_grid_search = +static const char *__doc_fiction_detail_defect_operational_domain_impl_grid_search = R"doc(This function divides the search space (defined by `nw_cell` and `se_cell`) into chunks, each processed by a different thread. The search checks if defect positions in the grid are operational based on @@ -4854,27 +4848,27 @@ Parameter ``step_size``: A `defect_influence_operational_domain` object representing the operational domain of the defects.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_has_already_been_sampled = +static const char *__doc_fiction_detail_defect_operational_domain_impl_has_already_been_sampled = R"doc(This function verifies whether the layout has already been analyzed for the specified defect position `c`. Parameter ``c``: Position of the defect.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_is_defect_position_operational = +static const char *__doc_fiction_detail_defect_operational_domain_impl_is_defect_position_operational = R"doc(This function evaluates the operational status of the SiDB gate when a defect is placed at position `c`. Parameter ``c``: Position of the defect.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_layout = R"doc(The SiDB cell-level layout to investigate.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_layout = R"doc(The SiDB cell-level layout to investigate.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_log_stats = +static const char *__doc_fiction_detail_defect_operational_domain_impl_log_stats = R"doc(Helper function that writes the the statistics of the defect operational domain computation to the statistics object.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_moore_neighborhood = +static const char *__doc_fiction_detail_defect_operational_domain_impl_moore_neighborhood = R"doc(Computes the Moore neighborhood of a given cell within the SiDB layout. The Moore neighborhood consists of the eight cells surrounding the central cell in horizontal, vertical, and diagonal directions. @@ -4887,19 +4881,19 @@ Parameter ``c``: empty. If a cell is outside the layout boundaries or occupied, it is not included in the result.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_num_evaluated_defect_positions = R"doc(Number of evaluated defect positions.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_num_evaluated_defect_positions = R"doc(Number of evaluated defect positions.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_num_simulator_invocations = R"doc(Number of simulator invocations.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_num_simulator_invocations = R"doc(Number of simulator invocations.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_nw_bb_layout = R"doc(The north-west bounding box of the layout.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_nw_bb_layout = R"doc(The north-west bounding box of the layout.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_nw_cell = R"doc(North-west cell.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_nw_cell = R"doc(North-west cell.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_params = R"doc(The parameters for the operational domain computation.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_params = R"doc(The parameters for the operational domain computation.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_previous_defect_position = R"doc(The previous defect position.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_previous_defect_position = R"doc(The previous defect position.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_random_sampling = +static const char *__doc_fiction_detail_defect_operational_domain_impl_random_sampling = R"doc(This function performs random sampling of defect positions from a grid area (spanned by `nw_cell` and `se_cell`). The positions are shuffled and divided into chunks, which are processed by different threads to @@ -4912,17 +4906,17 @@ Parameter ``samples``: `samples` value. Returns: - A `defect_influence_operational_domain` object representing - the operational domain of the defects. The return value is marked + A `defect_operational_domain` object representing the + operational domain of the defects. The return value is marked [[nodiscard]], meaning it must be used by the caller.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_se_bb_layout = R"doc(The south-east bounding box of the layout.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_se_bb_layout = R"doc(The south-east bounding box of the layout.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_se_cell = R"doc(South-east cell.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_se_cell = R"doc(South-east cell.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_stats = R"doc(The statistics of the operational domain computation.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_stats = R"doc(The statistics of the operational domain computation.)doc"; -static const char *__doc_fiction_detail_defect_influence_operational_domain_impl_truth_table = R"doc(The specification of the layout.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_truth_table = R"doc(The specification of the layout.)doc"; static const char *__doc_fiction_detail_delete_wires = R"doc(This function deletes wires from the provided From 24c6fcee26c5ecd2d5c9d7898028bf0943d82a6b Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 30 Oct 2024 19:09:36 +0100 Subject: [PATCH 139/221] :truck: add Bestagon gate library with logic cell type. --- .../and/21_hex_inputsdbp_and_v19.sqd | 222 ++++++++++++++ .../cx/22_hex_inputsdbp_cx_try2_v0.sqd | 263 +++++++++++++++++ .../fo2/12_hex_inputsdbp_fo2_v6.sqd | 209 ++++++++++++++ .../ha/22_hex_inputsdbp_ha_v2.sqd | 242 ++++++++++++++++ .../22_hex_inputsdbp_hourglass_v0.sqd | 270 ++++++++++++++++++ ...ex_11_inputsdbp_inv_straight_v0_manual.sqd | 201 +++++++++++++ .../hex_11_inputsdbp_inv_diag_v0_manual.sqd | 200 +++++++++++++ .../nand/21_hex_inputsdbp_nand_v7.sqd | 208 ++++++++++++++ .../nor/21_hex_inputsdbp_nor_v7.sqd | 208 ++++++++++++++ .../or/21_hex_inputsdbp_or_v17.sqd | 222 ++++++++++++++ ...x_11_inputsdbp_wire_straight_v0_manual.sqd | 179 ++++++++++++ .../hex_11_inputsdbp_wire_diag_v0_manual.sqd | 186 ++++++++++++ .../xnor/hex_21_inputsdbp_xnor_v21.sqd | 222 ++++++++++++++ .../xor/hex_21_inputsdbp_xor_v1.sqd | 222 ++++++++++++++ 14 files changed, 3054 insertions(+) create mode 100644 experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd create mode 100644 experiments/bestagon_gates_type_tags/cx/22_hex_inputsdbp_cx_try2_v0.sqd create mode 100644 experiments/bestagon_gates_type_tags/fo2/12_hex_inputsdbp_fo2_v6.sqd create mode 100644 experiments/bestagon_gates_type_tags/ha/22_hex_inputsdbp_ha_v2.sqd create mode 100644 experiments/bestagon_gates_type_tags/hourglass/22_hex_inputsdbp_hourglass_v0.sqd create mode 100644 experiments/bestagon_gates_type_tags/inv/hex_11_inputsdbp_inv_straight_v0_manual.sqd create mode 100644 experiments/bestagon_gates_type_tags/inv_diag/hex_11_inputsdbp_inv_diag_v0_manual.sqd create mode 100644 experiments/bestagon_gates_type_tags/nand/21_hex_inputsdbp_nand_v7.sqd create mode 100644 experiments/bestagon_gates_type_tags/nor/21_hex_inputsdbp_nor_v7.sqd create mode 100644 experiments/bestagon_gates_type_tags/or/21_hex_inputsdbp_or_v17.sqd create mode 100644 experiments/bestagon_gates_type_tags/wire/hex_11_inputsdbp_wire_straight_v0_manual.sqd create mode 100644 experiments/bestagon_gates_type_tags/wire_diag/hex_11_inputsdbp_wire_diag_v0_manual.sqd create mode 100644 experiments/bestagon_gates_type_tags/xnor/hex_21_inputsdbp_xnor_v21.sqd create mode 100644 experiments/bestagon_gates_type_tags/xor/hex_21_inputsdbp_xor_v1.sqd diff --git a/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd b/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd new file mode 100644 index 000000000..44031501b --- /dev/null +++ b/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd @@ -0,0 +1,222 @@ + + + + + save + 0.3.3 + 2023-08-08 17:47:07 + + + + 0.0518456 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/cx/22_hex_inputsdbp_cx_try2_v0.sqd b/experiments/bestagon_gates_type_tags/cx/22_hex_inputsdbp_cx_try2_v0.sqd new file mode 100644 index 000000000..a67e12365 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/cx/22_hex_inputsdbp_cx_try2_v0.sqd @@ -0,0 +1,263 @@ + + + + + save + 0.3.3 + 2023-08-08 17:31:33 + + + + 0.0267006 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/fo2/12_hex_inputsdbp_fo2_v6.sqd b/experiments/bestagon_gates_type_tags/fo2/12_hex_inputsdbp_fo2_v6.sqd new file mode 100644 index 000000000..8ff6051a7 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/fo2/12_hex_inputsdbp_fo2_v6.sqd @@ -0,0 +1,209 @@ + + + + + save + 0.3.3 + 2023-08-08 17:56:30 + + + + 0.019312 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/ha/22_hex_inputsdbp_ha_v2.sqd b/experiments/bestagon_gates_type_tags/ha/22_hex_inputsdbp_ha_v2.sqd new file mode 100644 index 000000000..f864efd3f --- /dev/null +++ b/experiments/bestagon_gates_type_tags/ha/22_hex_inputsdbp_ha_v2.sqd @@ -0,0 +1,242 @@ + + + + + save + 0.3.3 + 2023-08-08 17:34:47 + + + + 0.0467599 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/hourglass/22_hex_inputsdbp_hourglass_v0.sqd b/experiments/bestagon_gates_type_tags/hourglass/22_hex_inputsdbp_hourglass_v0.sqd new file mode 100644 index 000000000..431413552 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/hourglass/22_hex_inputsdbp_hourglass_v0.sqd @@ -0,0 +1,270 @@ + + + + + save + 0.3.3 + 2023-08-08 17:38:12 + + + + 0.018269 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/inv/hex_11_inputsdbp_inv_straight_v0_manual.sqd b/experiments/bestagon_gates_type_tags/inv/hex_11_inputsdbp_inv_straight_v0_manual.sqd new file mode 100644 index 000000000..363b75dc2 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/inv/hex_11_inputsdbp_inv_straight_v0_manual.sqd @@ -0,0 +1,201 @@ + + + + + save + 0.3.3 + 2023-08-08 17:54:44 + + + + 0.0189377 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/inv_diag/hex_11_inputsdbp_inv_diag_v0_manual.sqd b/experiments/bestagon_gates_type_tags/inv_diag/hex_11_inputsdbp_inv_diag_v0_manual.sqd new file mode 100644 index 000000000..2ee5fd277 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/inv_diag/hex_11_inputsdbp_inv_diag_v0_manual.sqd @@ -0,0 +1,200 @@ + + + + + save + 0.3.3 + 2023-08-08 17:49:15 + + + + 0.0243202 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/nand/21_hex_inputsdbp_nand_v7.sqd b/experiments/bestagon_gates_type_tags/nand/21_hex_inputsdbp_nand_v7.sqd new file mode 100644 index 000000000..3c77901a4 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/nand/21_hex_inputsdbp_nand_v7.sqd @@ -0,0 +1,208 @@ + + + + + save + 0.3.3 + 2023-08-08 17:29:19 + + + + 0.0210302 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/nor/21_hex_inputsdbp_nor_v7.sqd b/experiments/bestagon_gates_type_tags/nor/21_hex_inputsdbp_nor_v7.sqd new file mode 100644 index 000000000..e31d6ec08 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/nor/21_hex_inputsdbp_nor_v7.sqd @@ -0,0 +1,208 @@ + + + + + save + 0.3.3 + 2023-08-08 17:44:54 + + + + 0.018718 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/or/21_hex_inputsdbp_or_v17.sqd b/experiments/bestagon_gates_type_tags/or/21_hex_inputsdbp_or_v17.sqd new file mode 100644 index 000000000..9d1964a93 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/or/21_hex_inputsdbp_or_v17.sqd @@ -0,0 +1,222 @@ + + + + + save + 0.3.3 + 2023-08-08 17:25:05 + + + + 0.0232738 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/wire/hex_11_inputsdbp_wire_straight_v0_manual.sqd b/experiments/bestagon_gates_type_tags/wire/hex_11_inputsdbp_wire_straight_v0_manual.sqd new file mode 100644 index 000000000..5cd4857bf --- /dev/null +++ b/experiments/bestagon_gates_type_tags/wire/hex_11_inputsdbp_wire_straight_v0_manual.sqd @@ -0,0 +1,179 @@ + + + + + save + 0.3.3 + 2023-08-08 17:51:04 + + + + 0.0134379 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + output + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/wire_diag/hex_11_inputsdbp_wire_diag_v0_manual.sqd b/experiments/bestagon_gates_type_tags/wire_diag/hex_11_inputsdbp_wire_diag_v0_manual.sqd new file mode 100644 index 000000000..d0b37e465 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/wire_diag/hex_11_inputsdbp_wire_diag_v0_manual.sqd @@ -0,0 +1,186 @@ + + + + + save + 0.3.3 + 2023-08-08 17:52:41 + + + + 0.0149832 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/xnor/hex_21_inputsdbp_xnor_v21.sqd b/experiments/bestagon_gates_type_tags/xnor/hex_21_inputsdbp_xnor_v21.sqd new file mode 100644 index 000000000..8acf84444 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/xnor/hex_21_inputsdbp_xnor_v21.sqd @@ -0,0 +1,222 @@ + + + + + save + 0.3.3 + 2023-08-08 17:40:24 + + + + 0.0144887 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/xor/hex_21_inputsdbp_xor_v1.sqd b/experiments/bestagon_gates_type_tags/xor/hex_21_inputsdbp_xor_v1.sqd new file mode 100644 index 000000000..5f9fb9225 --- /dev/null +++ b/experiments/bestagon_gates_type_tags/xor/hex_21_inputsdbp_xor_v1.sqd @@ -0,0 +1,222 @@ + + + + + save + 0.3.3 + 2023-08-08 17:43:00 + + + + 0.0217771 + + + + + + + + Lattice + Lattice + Design + 0 + 0 + 1 + 0 + + + + 2 + + + + + + Screenshot Overlay + Misc + Overlay + 0 + 0 + 1 + 0 + + + Surface + DB + Design + 0 + 0 + 1 + 0 + + + Metal + Electrode + Design + 1000 + 100 + 1 + 0 + + + + + + + + + + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + output + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + logic + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + 2 + + input + + #ffc8c8c8 + + + + + + \ No newline at end of file From ccb9839684340c66323f2837b4e5aee57de521bc Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 30 Oct 2024 19:10:04 +0100 Subject: [PATCH 140/221] :bug: make sure logic cell type is handled correctly. --- include/fiction/io/read_sqd_layout.hpp | 4 ++++ include/fiction/io/write_sqd_layout.hpp | 1 + .../fiction/technology/sidb_on_the_fly_gate_library.hpp | 7 +++---- test/io/read_sqd_layout.cpp | 6 ++++++ test/io/write_sqd_layout.cpp | 3 ++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/fiction/io/read_sqd_layout.hpp b/include/fiction/io/read_sqd_layout.hpp index 12db847ad..6764a8c71 100644 --- a/include/fiction/io/read_sqd_layout.hpp +++ b/include/fiction/io/read_sqd_layout.hpp @@ -295,6 +295,10 @@ class read_sqd_layout_impl { return sidb_technology::cell_type::NORMAL; } + if (std::string{type} == "logic") + { + return sidb_technology::cell_type::LOGIC; + } throw sqd_parsing_error("Error parsing SQD file: invalid dot type"); } diff --git a/include/fiction/io/write_sqd_layout.hpp b/include/fiction/io/write_sqd_layout.hpp index fc8621799..06ee2cf5b 100644 --- a/include/fiction/io/write_sqd_layout.hpp +++ b/include/fiction/io/write_sqd_layout.hpp @@ -258,6 +258,7 @@ class write_sqd_layout_impl type == sidb_technology::cell_type::NORMAL ? "" : type == sidb_technology::cell_type::INPUT ? fmt::format(siqad::DOT_TYPE, "input") : type == sidb_technology::cell_type::OUTPUT ? fmt::format(siqad::DOT_TYPE, "output") : + type == sidb_technology::cell_type::LOGIC ? fmt::format(siqad::DOT_TYPE, "logic") : ""; if constexpr (has_siqad_coord_v) diff --git a/include/fiction/technology/sidb_on_the_fly_gate_library.hpp b/include/fiction/technology/sidb_on_the_fly_gate_library.hpp index d66d7abd1..c2806cee0 100644 --- a/include/fiction/technology/sidb_on_the_fly_gate_library.hpp +++ b/include/fiction/technology/sidb_on_the_fly_gate_library.hpp @@ -459,10 +459,9 @@ class sidb_on_the_fly_gate_library : public fcn_gate_library\n" " \n" " 2\n" + " \n" + " logic\n" + " \n" + " \n" + " 2\n" " \n" " \n" " \n" @@ -252,6 +257,7 @@ TEST_CASE("Read multi-dot SQD layout with cell type definitions", "[sqd]") CHECK(layout.get_cell_type({0, 1}) == sidb_technology::cell_type::OUTPUT); CHECK(layout.get_cell_type({2, 4}) == sidb_technology::cell_type::NORMAL); CHECK(layout.get_cell_type({2, 5}) == sidb_technology::cell_type::NORMAL); + CHECK(layout.get_cell_type({1, 3}) == sidb_technology::cell_type::LOGIC); } TEST_CASE("Read multi-dot SQD layout with cell type definitions, Si-111", "[sqd]") diff --git a/test/io/write_sqd_layout.cpp b/test/io/write_sqd_layout.cpp index 3473972ae..5f2b45a83 100644 --- a/test/io/write_sqd_layout.cpp +++ b/test/io/write_sqd_layout.cpp @@ -145,12 +145,13 @@ TEST_CASE("Write multi-dot SQD layout with differing dot types", "[sqd]") { using sidb_layout = sidb_cell_clk_lyt; - sidb_layout layout{{4, 4}}; + sidb_layout layout{{4, 6}}; layout.assign_cell_type({0, 0}, sidb_technology::cell_type::INPUT); layout.assign_cell_type({1, 1}, sidb_technology::cell_type::OUTPUT); layout.assign_cell_type({0, 2}, sidb_technology::cell_type::NORMAL); layout.assign_cell_type({0, 3}, sidb_technology::cell_type::OUTPUT); layout.assign_cell_type({4, 4}, sidb_technology::cell_type::INPUT); + layout.assign_cell_type({4, 6}, sidb_technology::cell_type::LOGIC); std::stringstream layout_stream{}; From de8f9b3dc779c9b5eb612b80f883285a8be7d4b4 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 30 Oct 2024 19:14:03 +0100 Subject: [PATCH 141/221] :fire: delete files again and put them to separate PR. --- .../and/21_hex_inputsdbp_and_v19.sqd | 222 -------------- .../cx/22_hex_inputsdbp_cx_try2_v0.sqd | 263 ----------------- .../fo2/12_hex_inputsdbp_fo2_v6.sqd | 209 -------------- .../ha/22_hex_inputsdbp_ha_v2.sqd | 242 ---------------- .../22_hex_inputsdbp_hourglass_v0.sqd | 270 ------------------ ...ex_11_inputsdbp_inv_straight_v0_manual.sqd | 201 ------------- .../hex_11_inputsdbp_inv_diag_v0_manual.sqd | 200 ------------- .../nand/21_hex_inputsdbp_nand_v7.sqd | 208 -------------- .../nor/21_hex_inputsdbp_nor_v7.sqd | 208 -------------- .../or/21_hex_inputsdbp_or_v17.sqd | 222 -------------- ...x_11_inputsdbp_wire_straight_v0_manual.sqd | 179 ------------ .../hex_11_inputsdbp_wire_diag_v0_manual.sqd | 186 ------------ .../xnor/hex_21_inputsdbp_xnor_v21.sqd | 222 -------------- .../xor/hex_21_inputsdbp_xor_v1.sqd | 222 -------------- 14 files changed, 3054 deletions(-) delete mode 100644 experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd delete mode 100644 experiments/bestagon_gates_type_tags/cx/22_hex_inputsdbp_cx_try2_v0.sqd delete mode 100644 experiments/bestagon_gates_type_tags/fo2/12_hex_inputsdbp_fo2_v6.sqd delete mode 100644 experiments/bestagon_gates_type_tags/ha/22_hex_inputsdbp_ha_v2.sqd delete mode 100644 experiments/bestagon_gates_type_tags/hourglass/22_hex_inputsdbp_hourglass_v0.sqd delete mode 100644 experiments/bestagon_gates_type_tags/inv/hex_11_inputsdbp_inv_straight_v0_manual.sqd delete mode 100644 experiments/bestagon_gates_type_tags/inv_diag/hex_11_inputsdbp_inv_diag_v0_manual.sqd delete mode 100644 experiments/bestagon_gates_type_tags/nand/21_hex_inputsdbp_nand_v7.sqd delete mode 100644 experiments/bestagon_gates_type_tags/nor/21_hex_inputsdbp_nor_v7.sqd delete mode 100644 experiments/bestagon_gates_type_tags/or/21_hex_inputsdbp_or_v17.sqd delete mode 100644 experiments/bestagon_gates_type_tags/wire/hex_11_inputsdbp_wire_straight_v0_manual.sqd delete mode 100644 experiments/bestagon_gates_type_tags/wire_diag/hex_11_inputsdbp_wire_diag_v0_manual.sqd delete mode 100644 experiments/bestagon_gates_type_tags/xnor/hex_21_inputsdbp_xnor_v21.sqd delete mode 100644 experiments/bestagon_gates_type_tags/xor/hex_21_inputsdbp_xor_v1.sqd diff --git a/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd b/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd deleted file mode 100644 index 44031501b..000000000 --- a/experiments/bestagon_gates_type_tags/and/21_hex_inputsdbp_and_v19.sqd +++ /dev/null @@ -1,222 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:47:07 - - - - 0.0518456 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/cx/22_hex_inputsdbp_cx_try2_v0.sqd b/experiments/bestagon_gates_type_tags/cx/22_hex_inputsdbp_cx_try2_v0.sqd deleted file mode 100644 index a67e12365..000000000 --- a/experiments/bestagon_gates_type_tags/cx/22_hex_inputsdbp_cx_try2_v0.sqd +++ /dev/null @@ -1,263 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:31:33 - - - - 0.0267006 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/fo2/12_hex_inputsdbp_fo2_v6.sqd b/experiments/bestagon_gates_type_tags/fo2/12_hex_inputsdbp_fo2_v6.sqd deleted file mode 100644 index 8ff6051a7..000000000 --- a/experiments/bestagon_gates_type_tags/fo2/12_hex_inputsdbp_fo2_v6.sqd +++ /dev/null @@ -1,209 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:56:30 - - - - 0.019312 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/ha/22_hex_inputsdbp_ha_v2.sqd b/experiments/bestagon_gates_type_tags/ha/22_hex_inputsdbp_ha_v2.sqd deleted file mode 100644 index f864efd3f..000000000 --- a/experiments/bestagon_gates_type_tags/ha/22_hex_inputsdbp_ha_v2.sqd +++ /dev/null @@ -1,242 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:34:47 - - - - 0.0467599 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/hourglass/22_hex_inputsdbp_hourglass_v0.sqd b/experiments/bestagon_gates_type_tags/hourglass/22_hex_inputsdbp_hourglass_v0.sqd deleted file mode 100644 index 431413552..000000000 --- a/experiments/bestagon_gates_type_tags/hourglass/22_hex_inputsdbp_hourglass_v0.sqd +++ /dev/null @@ -1,270 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:38:12 - - - - 0.018269 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/inv/hex_11_inputsdbp_inv_straight_v0_manual.sqd b/experiments/bestagon_gates_type_tags/inv/hex_11_inputsdbp_inv_straight_v0_manual.sqd deleted file mode 100644 index 363b75dc2..000000000 --- a/experiments/bestagon_gates_type_tags/inv/hex_11_inputsdbp_inv_straight_v0_manual.sqd +++ /dev/null @@ -1,201 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:54:44 - - - - 0.0189377 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/inv_diag/hex_11_inputsdbp_inv_diag_v0_manual.sqd b/experiments/bestagon_gates_type_tags/inv_diag/hex_11_inputsdbp_inv_diag_v0_manual.sqd deleted file mode 100644 index 2ee5fd277..000000000 --- a/experiments/bestagon_gates_type_tags/inv_diag/hex_11_inputsdbp_inv_diag_v0_manual.sqd +++ /dev/null @@ -1,200 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:49:15 - - - - 0.0243202 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/nand/21_hex_inputsdbp_nand_v7.sqd b/experiments/bestagon_gates_type_tags/nand/21_hex_inputsdbp_nand_v7.sqd deleted file mode 100644 index 3c77901a4..000000000 --- a/experiments/bestagon_gates_type_tags/nand/21_hex_inputsdbp_nand_v7.sqd +++ /dev/null @@ -1,208 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:29:19 - - - - 0.0210302 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/nor/21_hex_inputsdbp_nor_v7.sqd b/experiments/bestagon_gates_type_tags/nor/21_hex_inputsdbp_nor_v7.sqd deleted file mode 100644 index e31d6ec08..000000000 --- a/experiments/bestagon_gates_type_tags/nor/21_hex_inputsdbp_nor_v7.sqd +++ /dev/null @@ -1,208 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:44:54 - - - - 0.018718 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/or/21_hex_inputsdbp_or_v17.sqd b/experiments/bestagon_gates_type_tags/or/21_hex_inputsdbp_or_v17.sqd deleted file mode 100644 index 9d1964a93..000000000 --- a/experiments/bestagon_gates_type_tags/or/21_hex_inputsdbp_or_v17.sqd +++ /dev/null @@ -1,222 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:25:05 - - - - 0.0232738 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/wire/hex_11_inputsdbp_wire_straight_v0_manual.sqd b/experiments/bestagon_gates_type_tags/wire/hex_11_inputsdbp_wire_straight_v0_manual.sqd deleted file mode 100644 index 5cd4857bf..000000000 --- a/experiments/bestagon_gates_type_tags/wire/hex_11_inputsdbp_wire_straight_v0_manual.sqd +++ /dev/null @@ -1,179 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:51:04 - - - - 0.0134379 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - output - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/wire_diag/hex_11_inputsdbp_wire_diag_v0_manual.sqd b/experiments/bestagon_gates_type_tags/wire_diag/hex_11_inputsdbp_wire_diag_v0_manual.sqd deleted file mode 100644 index d0b37e465..000000000 --- a/experiments/bestagon_gates_type_tags/wire_diag/hex_11_inputsdbp_wire_diag_v0_manual.sqd +++ /dev/null @@ -1,186 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:52:41 - - - - 0.0149832 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/xnor/hex_21_inputsdbp_xnor_v21.sqd b/experiments/bestagon_gates_type_tags/xnor/hex_21_inputsdbp_xnor_v21.sqd deleted file mode 100644 index 8acf84444..000000000 --- a/experiments/bestagon_gates_type_tags/xnor/hex_21_inputsdbp_xnor_v21.sqd +++ /dev/null @@ -1,222 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:40:24 - - - - 0.0144887 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file diff --git a/experiments/bestagon_gates_type_tags/xor/hex_21_inputsdbp_xor_v1.sqd b/experiments/bestagon_gates_type_tags/xor/hex_21_inputsdbp_xor_v1.sqd deleted file mode 100644 index 5f9fb9225..000000000 --- a/experiments/bestagon_gates_type_tags/xor/hex_21_inputsdbp_xor_v1.sqd +++ /dev/null @@ -1,222 +0,0 @@ - - - - - save - 0.3.3 - 2023-08-08 17:43:00 - - - - 0.0217771 - - - - - - - - Lattice - Lattice - Design - 0 - 0 - 1 - 0 - - - - 2 - - - - - - Screenshot Overlay - Misc - Overlay - 0 - 0 - 1 - 0 - - - Surface - DB - Design - 0 - 0 - 1 - 0 - - - Metal - Electrode - Design - 1000 - 100 - 1 - 0 - - - - - - - - - - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - output - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - logic - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - 2 - - input - - #ffc8c8c8 - - - - - - \ No newline at end of file From da123b1e2021fba1ae1f21c5c4d5c68bbaee27c3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2024 18:19:56 +0000 Subject: [PATCH 142/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/fiction/io/write_sqd_layout.hpp | 2 +- .../fiction/technology/sidb_on_the_fly_gate_library.hpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/fiction/io/write_sqd_layout.hpp b/include/fiction/io/write_sqd_layout.hpp index 06ee2cf5b..0e66161e2 100644 --- a/include/fiction/io/write_sqd_layout.hpp +++ b/include/fiction/io/write_sqd_layout.hpp @@ -258,7 +258,7 @@ class write_sqd_layout_impl type == sidb_technology::cell_type::NORMAL ? "" : type == sidb_technology::cell_type::INPUT ? fmt::format(siqad::DOT_TYPE, "input") : type == sidb_technology::cell_type::OUTPUT ? fmt::format(siqad::DOT_TYPE, "output") : - type == sidb_technology::cell_type::LOGIC ? fmt::format(siqad::DOT_TYPE, "logic") : + type == sidb_technology::cell_type::LOGIC ? fmt::format(siqad::DOT_TYPE, "logic") : ""; if constexpr (has_siqad_coord_v) diff --git a/include/fiction/technology/sidb_on_the_fly_gate_library.hpp b/include/fiction/technology/sidb_on_the_fly_gate_library.hpp index c2806cee0..c74a1ce21 100644 --- a/include/fiction/technology/sidb_on_the_fly_gate_library.hpp +++ b/include/fiction/technology/sidb_on_the_fly_gate_library.hpp @@ -459,9 +459,11 @@ class sidb_on_the_fly_gate_library : public fcn_gate_library Date: Thu, 31 Oct 2024 12:53:41 +0100 Subject: [PATCH 143/221] :art: use switch. --- include/fiction/io/write_sqd_layout.hpp | 38 +++++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/include/fiction/io/write_sqd_layout.hpp b/include/fiction/io/write_sqd_layout.hpp index 0e66161e2..e2b9a71a8 100644 --- a/include/fiction/io/write_sqd_layout.hpp +++ b/include/fiction/io/write_sqd_layout.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -254,12 +255,37 @@ class write_sqd_layout_impl if constexpr (has_sidb_technology_v) { const auto type = this->lyt.get_cell_type(c); - const auto type_str = - type == sidb_technology::cell_type::NORMAL ? "" : - type == sidb_technology::cell_type::INPUT ? fmt::format(siqad::DOT_TYPE, "input") : - type == sidb_technology::cell_type::OUTPUT ? fmt::format(siqad::DOT_TYPE, "output") : - type == sidb_technology::cell_type::LOGIC ? fmt::format(siqad::DOT_TYPE, "logic") : - ""; + + std::string type_str; + + switch (type) + { + case sidb_technology::cell_type::NORMAL: + { + type_str = ""; + break; + } + case sidb_technology::cell_type::INPUT: + { + type_str = fmt::format(siqad::DOT_TYPE, "input"); + break; + } + case sidb_technology::cell_type::OUTPUT: + { + type_str = fmt::format(siqad::DOT_TYPE, "output"); + break; + } + case sidb_technology::cell_type::LOGIC: + { + type_str = fmt::format(siqad::DOT_TYPE, "logic"); + break; + } + default: + { + type_str = ""; + break; + } + } if constexpr (has_siqad_coord_v) { From 0bcf163fbd4dcc6ce7326729a096b151315e7958 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 31 Oct 2024 12:58:03 +0100 Subject: [PATCH 144/221] :art: use switch --- include/fiction/io/write_sqd_layout.hpp | 8 ++--- .../sidb_on_the_fly_gate_library.hpp | 32 ++++++++++++++----- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/include/fiction/io/write_sqd_layout.hpp b/include/fiction/io/write_sqd_layout.hpp index e2b9a71a8..67a62a593 100644 --- a/include/fiction/io/write_sqd_layout.hpp +++ b/include/fiction/io/write_sqd_layout.hpp @@ -260,22 +260,22 @@ class write_sqd_layout_impl switch (type) { - case sidb_technology::cell_type::NORMAL: + case (sidb_technology::cell_type::NORMAL): { type_str = ""; break; } - case sidb_technology::cell_type::INPUT: + case (sidb_technology::cell_type::INPUT): { type_str = fmt::format(siqad::DOT_TYPE, "input"); break; } - case sidb_technology::cell_type::OUTPUT: + case (sidb_technology::cell_type::OUTPUT): { type_str = fmt::format(siqad::DOT_TYPE, "output"); break; } - case sidb_technology::cell_type::LOGIC: + case (sidb_technology::cell_type::LOGIC): { type_str = fmt::format(siqad::DOT_TYPE, "logic"); break; diff --git a/include/fiction/technology/sidb_on_the_fly_gate_library.hpp b/include/fiction/technology/sidb_on_the_fly_gate_library.hpp index c74a1ce21..c55281c45 100644 --- a/include/fiction/technology/sidb_on_the_fly_gate_library.hpp +++ b/include/fiction/technology/sidb_on_the_fly_gate_library.hpp @@ -452,19 +452,35 @@ class sidb_on_the_fly_gate_library : public fcn_gate_library, gate_y_size()> result{}; const auto all_coordinates_in_the_spanned_area = all_coordinates_in_spanned_area({0, 0, 0}, cell{gate_x_size() - 1, gate_y_size() - 1}); - uint64_t counter = 0; + + uint64_t cell_index = 0; for (auto& row : result) { for (auto& cell : row) { - const auto cell_type = lyt.get_cell_type(all_coordinates_in_the_spanned_area[counter]); - cell = (cell_type == Lyt::technology::cell_type::NORMAL || - cell_type == Lyt::technology::cell_type::OUTPUT) ? - 'x' : - (cell_type == Lyt::technology::cell_type::LOGIC) ? 'l' : - ' '; - counter++; + const auto cell_type = lyt.get_cell_type(all_coordinates_in_the_spanned_area[cell_index]); + + switch (cell_type) + { + case (Lyt::technology::cell_type::NORMAL): + case (Lyt::technology::cell_type::OUTPUT): + { + cell = 'x'; + break; + } + case (Lyt::technology::cell_type::LOGIC): + { + cell = 'l'; + break; + } + default: + { + cell = ' '; + break; + } + } + cell_index++; } } From f3fedf15ab0e5eca0368b376907699c3a938333e Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 1 Nov 2024 16:26:31 +0100 Subject: [PATCH 145/221] :snake: fix python bindings. --- .../defect_influence_operational_domain.hpp | 88 ------------ .../sidb/defect_operational_domain.hpp | 95 +++++++++++++ .../determine_physically_valid_parameters.hpp | 14 +- ...defect_influence_position_and_distance.hpp | 4 +- .../pyfiction/inout/read_sqd_layout.hpp | 46 ++---- .../pyfiction/layouts/cartesian_layout.hpp | 132 ++++++++++-------- .../pyfiction/layouts/cell_level_layout.hpp | 85 ++++++----- .../pyfiction/layouts/clocked_layout.hpp | 5 +- .../pyfiction/technology/sidb_lattice.hpp | 60 +------- bindings/pyfiction/pyfiction.cpp | 21 ++- .../sidb/test_defect_operational_domain.py | 28 ++-- cli/cmd/simulation/opdom.hpp | 6 +- docs/cli.rst | 2 +- .../defect_influence_operational_domain.hpp | 9 +- .../simulation/sidb/operational_domain.hpp | 5 +- .../assess_physical_population_stability.cpp | 2 - .../defect_influence_operational_domain.cpp | 58 ++------ .../simulation/sidb/operational_domain.cpp | 22 +-- test/utils/blueprints/layout_blueprints.hpp | 57 ++++++++ 19 files changed, 360 insertions(+), 379 deletions(-) delete mode 100644 bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp create mode 100644 bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp deleted file mode 100644 index 5def11f58..000000000 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// -// Created by Jan Drewniok 18.10.2024 -// - -#ifndef PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP -#define PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP - -#include "pyfiction/documentation.hpp" -#include "pyfiction/types.hpp" - -#include - -#include -#include -#include - -#include - -namespace pyfiction -{ - -namespace detail -{ - -template -void defect_influence_operational_domain_detail(pybind11::module& m) -{ - using namespace pybind11::literals; - - m.def("defect_influence_operational_domain_grid_search", - &fiction::defect_influence_operational_domain_grid_search, "lyt"_a, "spec"_a, "step_size"_a, - "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, - DOC(fiction_defect_influence_operational_domain_grid_search)); - - m.def("defect_influence_operational_domain_random_sampling", - &fiction::defect_influence_operational_domain_random_sampling, "lyt"_a, "spec"_a, "samples"_a, - "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, - DOC(fiction_defect_influence_operational_domain_random_sampling)); - - m.def("defect_influence_operational_contour_tracing", - &fiction::defect_influence_operational_domain_contour_tracing, "lyt"_a, "spec"_a, "samples"_a, - "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, - DOC(fiction_defect_influence_operational_domain_contour_tracing)); -} - -} // namespace detail - -inline void defect_influence_operational_domain(pybind11::module& m) -{ - namespace py = pybind11; - using namespace pybind11::literals; - - py::class_>( - m, "defect_influence_operational_domain_100") - .def(py::init<>()); - - py::class_>( - m, "defect_influence_operational_domain_111") - .def(py::init<>()); - - py::class_(m, "defect_influence_operational_domain_params") - .def(py::init<>()) - .def_readwrite("defect_influence_params", - &fiction::defect_influence_operational_domain_params::defect_influence_params) - .def_readwrite("operational_params", &fiction::defect_influence_operational_domain_params::operational_params); - - py::class_(m, "defect_influence_operational_domain_stats") - .def(py::init<>()) - .def_readonly("time_total", &fiction::defect_influence_operational_domain_stats::time_total) - .def_readonly("num_simulator_invocations", - &fiction::defect_influence_operational_domain_stats::num_simulator_invocations) - .def_readonly("num_evaluated_parameter_combinations", - &fiction::defect_influence_operational_domain_stats::num_evaluated_defect_positions) - .def_readonly("num_operational_defect_positions", - &fiction::defect_influence_operational_domain_stats::num_operational_defect_positions) - .def_readonly("num_operational_defect_positions", - &fiction::defect_influence_operational_domain_stats::num_operational_defect_positions) - .def_readonly("num_non_operational_defect_positions", - &fiction::defect_influence_operational_domain_stats::num_operational_defect_positions); - - // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! - detail::defect_influence_operational_domain_detail(m); - detail::defect_influence_operational_domain_detail(m); -} - -} // namespace pyfiction - -#endif // PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp new file mode 100644 index 000000000..9443a0ccc --- /dev/null +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -0,0 +1,95 @@ +// +// Created by Jan Drewniok 18.10.2024 +// + +#ifndef PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP +#define PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP + +#include "pyfiction/documentation.hpp" +#include "pyfiction/types.hpp" + +#include + +#include +#include +#include + +#include + +namespace pyfiction +{ + +namespace detail +{ + +template +void defect_influence_operational_domain_detail(pybind11::module& m) +{ + using namespace pybind11::literals; + + // todo update docu + + m.def("defect_operational_domain_grid_search", + &fiction::defect_operational_domain_grid_search, "lyt"_a, "spec"_a, "step_size"_a, + "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); + + m.def("defect_operational_domain_random_sampling", + &fiction::defect_operational_domain_random_sampling, "lyt"_a, "spec"_a, "samples"_a, + "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); + + m.def("defect_operational_domain_quicktrace", + &fiction::defect_operational_domain_quicktrace, "lyt"_a, "spec"_a, "samples"_a, + "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); +} + +} // namespace detail + +inline void defect_influence_operational_domain(pybind11::module& m) +{ + namespace py = pybind11; + using namespace pybind11::literals; + + py::class_>( + m, "defect_operational_domain_100") + .def(py::init<>()); + + py::class_>( + m, "defect_operational_domain_111") + .def(py::init<>()); + + py::class_>( + m, "defect_operational_domain_100_cube") + .def(py::init<>()); + + py::class_>( + m, "defect_operational_domain_111_cube") + .def(py::init<>()); + + py::class_(m, "defect_operational_domain_params") + .def(py::init<>()) + .def_readwrite("defect_influence_params", + &fiction::defect_operational_domain_params::defect_influence_params) + .def_readwrite("operational_params", &fiction::defect_operational_domain_params::operational_params); + + py::class_(m, "defect_operational_domain_stats") + .def(py::init<>()) + .def_readonly("time_total", &fiction::defect_operational_domain_stats::time_total) + .def_readonly("num_simulator_invocations", + &fiction::defect_operational_domain_stats::num_simulator_invocations) + .def_readonly("num_evaluated_parameter_combinations", + &fiction::defect_operational_domain_stats::num_evaluated_defect_positions) + .def_readonly("num_operational_defect_positions", + &fiction::defect_operational_domain_stats::num_operational_defect_positions) + .def_readonly("num_operational_defect_positions", + &fiction::defect_operational_domain_stats::num_operational_defect_positions) + .def_readonly("num_non_operational_defect_positions", + &fiction::defect_operational_domain_stats::num_operational_defect_positions); + + // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! + detail::defect_influence_operational_domain_detail(m); + detail::defect_influence_operational_domain_detail(m); +} + +} // namespace pyfiction + +#endif // PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp index 7419aaedf..c7ec72ae3 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp @@ -46,14 +46,16 @@ inline void determine_physically_valid_parameters(pybind11::module& m) [](const fiction::operational_domain& domain, const fiction::parameter_point& pp) { - try - { - return domain.get_value(pp).value(); - } - catch (const std::out_of_range& e) + auto result = domain.get_value(pp); + + // Check if the result has a value + if (result.has_value()) { - throw py::value_error(e.what()); + return result.value(); } + // If no value is present, raise a Python ValueError + throw py::value_error("Invalid parameter point: no excited state number available for the provided parameter."); + }, "pp"_a); diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 18701c247..732297133 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -43,9 +43,7 @@ inline void maximum_defect_influence_distance(pybind11::module& m) .def_readwrite("sim_params", &fiction::maximum_defect_influence_position_and_distance_params::simulation_parameters) .def_readwrite("additional_scanning_area", - &fiction::maximum_defect_influence_position_and_distance_params::additional_scanning_area) - - ; + &fiction::maximum_defect_influence_position_and_distance_params::additional_scanning_area); // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! diff --git a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp index 6add9b6f6..0dce736a2 100644 --- a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp @@ -21,7 +21,7 @@ namespace detail { template -void read_sqd_layout(pybind11::module& m) +void read_sqd_layout(pybind11::module& m, std::string lattice_orientation, std::string coordinate_type) { namespace py = pybind11; using namespace py::literals; @@ -32,48 +32,18 @@ void read_sqd_layout(pybind11::module& m) Lyt (*read_sqd_layout_function_pointer)(const std::string_view&, const std::string_view&) = &fiction::read_sqd_layout; - if constexpr (fiction::is_sidb_lattice_100_v && fiction::has_cube_coord_v) - { - m.def("read_sqd_layout_100_cube", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", - DOC(fiction_read_sqd_layout_3)); - } - else if constexpr (fiction::is_sidb_lattice_100_v && !fiction::has_cube_coord_v) - { - m.def("read_sqd_layout_100", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", - DOC(fiction_read_sqd_layout_3)); - } - else if constexpr (fiction::is_sidb_lattice_111_v && fiction::has_cube_coord_v) - { - m.def("read_sqd_layout_111_cube", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", - DOC(fiction_read_sqd_layout_3)); - } - else if constexpr (fiction::is_sidb_lattice_111_v && !fiction::has_cube_coord_v) - { - m.def("read_sqd_layout_111", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", - DOC(fiction_read_sqd_layout_3)); - } + m.def(fmt::format("read_sqd_layout_{}{}", lattice_orientation, coordinate_type).c_str(), read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", + DOC(fiction_read_sqd_layout_3)); } } // namespace detail -inline void read_sqd_layout_100(pybind11::module& m) +inline void read_sqd_layout(pybind11::module& m) { - detail::read_sqd_layout(m); -} - -inline void read_sqd_layout_111(pybind11::module& m) -{ - detail::read_sqd_layout(m); -} - -inline void read_sqd_layout_100_cube(pybind11::module& m) -{ - detail::read_sqd_layout(m); -} - -inline void read_sqd_layout_111_cube(pybind11::module& m) -{ - detail::read_sqd_layout(m); + detail::read_sqd_layout(m, "100", ""); + detail::read_sqd_layout(m, "111", ""); + detail::read_sqd_layout(m, "100", "_cube"); + detail::read_sqd_layout(m, "111", "_cube"); } } // namespace pyfiction diff --git a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp index ee2a1e25b..427d50b3d 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp @@ -20,92 +20,98 @@ namespace pyfiction { -inline void cartesian_layout(pybind11::module& m) +namespace detail +{ + +template +inline void cartesian_layout_impl(pybind11::module& m) { namespace py = pybind11; using namespace pybind11::literals; + std::string coordinate_type; /** * Cartesian layout. */ - py::class_(m, "cartesian_layout", DOC(fiction_cartesian_layout_overridden)) + if constexpr (fiction::has_cube_coord_v) + { + coordinate_type = "cube"; + } + + py::class_(m, fmt::format("cartesian_layout{}", coordinate_type).c_str(), + DOC(fiction_cartesian_layout_overridden)) .def(py::init<>()) - .def(py::init&>(), "dimension"_a, + .def(py::init&>(), "dimension"_a, DOC(fiction_cartesian_layout_cartesian_layout)) .def( - "coord", [](const py_cartesian_layout& layout, const int64_t x, const int64_t y, const int64_t z) + "coord", [](const CartesianLyt& layout, const int64_t x, const int64_t y, const int64_t z) { return layout.coord(x, y, z); }, "x"_a, "y"_a, "z"_a = 0l, DOC(fiction_cartesian_layout_coord)) - .def("x", &py_cartesian_layout::x, DOC(fiction_cartesian_layout_x)) - .def("y", &py_cartesian_layout::y, DOC(fiction_cartesian_layout_y)) - .def("z", &py_cartesian_layout::z, DOC(fiction_cartesian_layout_z)) - .def("area", &py_cartesian_layout::area, DOC(fiction_cartesian_layout_area)) - .def("resize", &py_cartesian_layout::resize, "dimension"_a, DOC(fiction_cartesian_layout_resize)) - - .def("north", &py_cartesian_layout::north, "c"_a, DOC(fiction_cartesian_layout_north)) - .def("north_east", &py_cartesian_layout::north_east, "c"_a, DOC(fiction_cartesian_layout_north_east)) - .def("east", &py_cartesian_layout::east, "c"_a, DOC(fiction_cartesian_layout_east)) - .def("south_east", &py_cartesian_layout::south_east, "c"_a, DOC(fiction_cartesian_layout_south_east)) - .def("south", &py_cartesian_layout::south, "c"_a, DOC(fiction_cartesian_layout_south)) - .def("south_west", &py_cartesian_layout::south_west, "c"_a, DOC(fiction_cartesian_layout_south_west)) - .def("west", &py_cartesian_layout::west, "c"_a, DOC(fiction_cartesian_layout_west)) - .def("north_west", &py_cartesian_layout::north_west, "c"_a, DOC(fiction_cartesian_layout_north_west)) - .def("above", &py_cartesian_layout::above, "c"_a, DOC(fiction_cartesian_layout_above)) - .def("below", &py_cartesian_layout::below, "c"_a, DOC(fiction_cartesian_layout_below)) - - .def("is_north_of", &py_cartesian_layout::is_north_of, "c1"_a, "c2"_a, - DOC(fiction_cartesian_layout_is_north_of)) - .def("is_east_of", &py_cartesian_layout::is_east_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_east_of)) - .def("is_south_of", &py_cartesian_layout::is_south_of, "c1"_a, "c2"_a, - DOC(fiction_cartesian_layout_is_south_of)) - .def("is_west_of", &py_cartesian_layout::is_west_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_west_of)) - .def("is_adjacent_of", &py_cartesian_layout::is_adjacent_of, "c1"_a, "c2"_a, + .def("x", &CartesianLyt::x, DOC(fiction_cartesian_layout_x)) + .def("y", &CartesianLyt::y, DOC(fiction_cartesian_layout_y)) + .def("z", &CartesianLyt::z, DOC(fiction_cartesian_layout_z)) + .def("area", &CartesianLyt::area, DOC(fiction_cartesian_layout_area)) + .def("resize", &CartesianLyt::resize, "dimension"_a, DOC(fiction_cartesian_layout_resize)) + + .def("north", &CartesianLyt::north, "c"_a, DOC(fiction_cartesian_layout_north)) + .def("north_east", &CartesianLyt::north_east, "c"_a, DOC(fiction_cartesian_layout_north_east)) + .def("east", &CartesianLyt::east, "c"_a, DOC(fiction_cartesian_layout_east)) + .def("south_east", &CartesianLyt::south_east, "c"_a, DOC(fiction_cartesian_layout_south_east)) + .def("south", &CartesianLyt::south, "c"_a, DOC(fiction_cartesian_layout_south)) + .def("south_west", &CartesianLyt::south_west, "c"_a, DOC(fiction_cartesian_layout_south_west)) + .def("west", &CartesianLyt::west, "c"_a, DOC(fiction_cartesian_layout_west)) + .def("north_west", &CartesianLyt::north_west, "c"_a, DOC(fiction_cartesian_layout_north_west)) + .def("above", &CartesianLyt::above, "c"_a, DOC(fiction_cartesian_layout_above)) + .def("below", &CartesianLyt::below, "c"_a, DOC(fiction_cartesian_layout_below)) + + .def("is_north_of", &CartesianLyt::is_north_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_north_of)) + .def("is_east_of", &CartesianLyt::is_east_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_east_of)) + .def("is_south_of", &CartesianLyt::is_south_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_south_of)) + .def("is_west_of", &CartesianLyt::is_west_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_west_of)) + .def("is_adjacent_of", &CartesianLyt::is_adjacent_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_adjacent_of)) - .def("is_adjacent_elevation_of", &py_cartesian_layout::is_adjacent_elevation_of, "c1"_a, "c2"_a, + .def("is_adjacent_elevation_of", &CartesianLyt::is_adjacent_elevation_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_adjacent_elevation_of)) - .def("is_above", &py_cartesian_layout::is_above, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_above)) - .def("is_below", &py_cartesian_layout::is_below, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_below)) - .def("is_northwards_of", &py_cartesian_layout::is_northwards_of, "c1"_a, "c2"_a, + .def("is_above", &CartesianLyt::is_above, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_above)) + .def("is_below", &CartesianLyt::is_below, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_below)) + .def("is_northwards_of", &CartesianLyt::is_northwards_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_northwards_of)) - .def("is_eastwards_of", &py_cartesian_layout::is_eastwards_of, "c1"_a, "c2"_a, + .def("is_eastwards_of", &CartesianLyt::is_eastwards_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_eastwards_of)) - .def("is_southwards_of", &py_cartesian_layout::is_southwards_of, "c1"_a, "c2"_a, + .def("is_southwards_of", &CartesianLyt::is_southwards_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_southwards_of)) - .def("is_westwards_of", &py_cartesian_layout::is_westwards_of, "c1"_a, "c2"_a, + .def("is_westwards_of", &CartesianLyt::is_westwards_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_westwards_of)) - .def("is_at_northern_border", &py_cartesian_layout::is_at_northern_border, "c"_a, + .def("is_at_northern_border", &CartesianLyt::is_at_northern_border, "c"_a, DOC(fiction_cartesian_layout_is_at_northern_border)) - .def("is_at_eastern_border", &py_cartesian_layout::is_at_eastern_border, "c"_a, + .def("is_at_eastern_border", &CartesianLyt::is_at_eastern_border, "c"_a, DOC(fiction_cartesian_layout_is_at_eastern_border)) - .def("is_at_southern_border", &py_cartesian_layout::is_at_southern_border, "c"_a, + .def("is_at_southern_border", &CartesianLyt::is_at_southern_border, "c"_a, DOC(fiction_cartesian_layout_is_at_southern_border)) - .def("is_at_western_border", &py_cartesian_layout::is_at_western_border, "c"_a, + .def("is_at_western_border", &CartesianLyt::is_at_western_border, "c"_a, DOC(fiction_cartesian_layout_is_at_western_border)) - .def("is_at_any_border", &py_cartesian_layout::is_at_any_border, "c"_a, - DOC(fiction_cartesian_layout_is_at_any_border)) + .def("is_at_any_border", &CartesianLyt::is_at_any_border, "c"_a, DOC(fiction_cartesian_layout_is_at_any_border)) - .def("northern_border_of", &py_cartesian_layout::northern_border_of, "c"_a, + .def("northern_border_of", &CartesianLyt::northern_border_of, "c"_a, DOC(fiction_cartesian_layout_northern_border_of)) - .def("eastern_border_of", &py_cartesian_layout::eastern_border_of, "c"_a, + .def("eastern_border_of", &CartesianLyt::eastern_border_of, "c"_a, DOC(fiction_cartesian_layout_eastern_border_of)) - .def("southern_border_of", &py_cartesian_layout::southern_border_of, "c"_a, + .def("southern_border_of", &CartesianLyt::southern_border_of, "c"_a, DOC(fiction_cartesian_layout_southern_border_of)) - .def("western_border_of", &py_cartesian_layout::western_border_of, "c"_a, + .def("western_border_of", &CartesianLyt::western_border_of, "c"_a, DOC(fiction_cartesian_layout_western_border_of)) - .def("is_ground_layer", &py_cartesian_layout::is_ground_layer, "c"_a, - DOC(fiction_cartesian_layout_is_ground_layer)) - .def("is_crossing_layer", &py_cartesian_layout::is_crossing_layer, "c"_a, + .def("is_ground_layer", &CartesianLyt::is_ground_layer, "c"_a, DOC(fiction_cartesian_layout_is_ground_layer)) + .def("is_crossing_layer", &CartesianLyt::is_crossing_layer, "c"_a, DOC(fiction_cartesian_layout_is_crossing_layer)) - .def("is_within_bounds", &py_cartesian_layout::is_within_bounds, "c"_a, - DOC(fiction_cartesian_layout_is_within_bounds)) + .def("is_within_bounds", &CartesianLyt::is_within_bounds, "c"_a, DOC(fiction_cartesian_layout_is_within_bounds)) .def( "coordinates", - [](const py_cartesian_layout& lyt) + [](const CartesianLyt& lyt) { - std::vector> coords{}; + std::vector> coords{}; coords.reserve(lyt.area() * (lyt.z() + 1)); lyt.foreach_coordinate([&coords](const auto& c) { coords.push_back(c); }); return coords; @@ -113,21 +119,21 @@ inline void cartesian_layout(pybind11::module& m) DOC(fiction_cartesian_layout_coordinates)) .def( "ground_coordinates", - [](const py_cartesian_layout& lyt) + [](const CartesianLyt& lyt) { - std::vector> coords{}; + std::vector> coords{}; coords.reserve(lyt.area()); lyt.foreach_ground_coordinate([&coords](const auto& c) { coords.push_back(c); }); return coords; }, DOC(fiction_cartesian_layout_ground_coordinates)) - .def("adjacent_coordinates", &py_cartesian_layout::adjacent_coordinates, "c"_a, + .def("adjacent_coordinates", &CartesianLyt::adjacent_coordinates, "c"_a, DOC(fiction_cartesian_layout_adjacent_coordinates)) - .def("adjacent_opposite_coordinates", &py_cartesian_layout::adjacent_opposite_coordinates, "c"_a, + .def("adjacent_opposite_coordinates", &CartesianLyt::adjacent_opposite_coordinates, "c"_a, DOC(fiction_cartesian_layout_adjacent_opposite_coordinates)) .def("__repr__", - [](const py_cartesian_layout& lyt) -> std::string + [](const CartesianLyt& lyt) -> std::string { std::stringstream stream{}; print_layout(lyt, stream); @@ -137,6 +143,16 @@ inline void cartesian_layout(pybind11::module& m) ; } -} // namespace pyfiction +}; + +inline void cartesian_layout(pybind11::module& m) +{ + detail::cartesian_layout_impl(m); + detail::cartesian_layout_impl(m); +} + + + +}// namespace pyfiction #endif // PYFICTION_CARTESIAN_LAYOUT_HPP diff --git a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp index a70566ce3..1a8fbfe53 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp @@ -29,7 +29,7 @@ namespace detail { template -void fcn_technology_cell_level_layout(pybind11::module& m) +void fcn_technology_cells(pybind11::module& m) { namespace py = pybind11; using namespace pybind11::literals; @@ -72,28 +72,37 @@ void fcn_technology_cell_level_layout(pybind11::module& m) { cell_type.value("LOGIC", Technology::cell_type::LOGIC); } - // NOTE: more technologies go here +} + +template +void fcn_technology_cell_layout(pybind11::module& m, std::string coordinate_name = "") +{ + namespace py = pybind11; + using namespace pybind11::literals; - using py_cartesian_technology_cell_layout = py_cartesian_cell_layout; + // fetch technology name + auto tech_name = std::string{fiction::tech_impl_name}; + std::transform(tech_name.begin(), tech_name.end(), tech_name.begin(), ::tolower); /** * Cell-level clocked Cartesian layout. */ - py::class_( - m, fmt::format("{}_layout", tech_name).c_str(), DOC(fiction_cell_level_layout)) + + py::class_( + m, fmt::format("{}_layout{}", tech_name, coordinate_name).c_str(), DOC(fiction_cell_level_layout)) .def(py::init<>()) - .def(py::init&>(), "dimension"_a, + .def(py::init&>(), "dimension"_a, DOC(fiction_cell_level_layout_cell_level_layout)) .def(py::init( - [](const fiction::aspect_ratio& dimension, + [](const fiction::aspect_ratio& dimension, const std::string& scheme_name, - const std::string& layout_name) -> py_cartesian_technology_cell_layout + const std::string& layout_name) -> CellLyt { if (const auto scheme = - fiction::get_clocking_scheme(scheme_name); + fiction::get_clocking_scheme(scheme_name); scheme.has_value()) { - return py_cartesian_technology_cell_layout{dimension, *scheme, layout_name}; + return CellLyt{dimension, *scheme, layout_name}; } throw std::runtime_error("Given name does not refer to a supported clocking scheme"); @@ -101,62 +110,62 @@ void fcn_technology_cell_level_layout(pybind11::module& m) "dimension"_a, "clocking_scheme"_a = "2DDWave", "layout_name"_a = "", DOC(fiction_cell_level_layout_cell_level_layout_2)) - .def("assign_cell_type", &py_cartesian_technology_cell_layout::assign_cell_type, "c"_a, "ct"_a, + .def("assign_cell_type", &CellLyt::assign_cell_type, "c"_a, "ct"_a, DOC(fiction_cell_level_layout_assign_cell_type)) - .def("get_cell_type", &py_cartesian_technology_cell_layout::get_cell_type, "c"_a, + .def("get_cell_type", &CellLyt::get_cell_type, "c"_a, DOC(fiction_cell_level_layout_get_cell_type)) - .def("is_empty_cell", &py_cartesian_technology_cell_layout::is_empty_cell, "c"_a, + .def("is_empty_cell", &CellLyt::is_empty_cell, "c"_a, DOC(fiction_cell_level_layout_is_empty_cell)) - .def("assign_cell_name", &py_cartesian_technology_cell_layout::assign_cell_name, "c"_a, "n"_a, + .def("assign_cell_name", &CellLyt::assign_cell_name, "c"_a, "n"_a, DOC(fiction_cell_level_layout_assign_cell_name)) - .def("get_cell_name", &py_cartesian_technology_cell_layout::get_cell_name, "c"_a, + .def("get_cell_name", &CellLyt::get_cell_name, "c"_a, DOC(fiction_cell_level_layout_get_cell_name)) - .def("set_layout_name", &py_cartesian_technology_cell_layout::set_layout_name, "name"_a, + .def("set_layout_name", &CellLyt::set_layout_name, "name"_a, DOC(fiction_cell_level_layout_set_layout_name)) - .def("get_layout_name", &py_cartesian_technology_cell_layout::get_layout_name, + .def("get_layout_name", &CellLyt::get_layout_name, DOC(fiction_cell_level_layout_get_layout_name)) - .def("num_cells", &py_cartesian_technology_cell_layout::num_cells, DOC(fiction_cell_level_layout_num_cells)) - .def("is_empty", &py_cartesian_technology_cell_layout::is_empty, DOC(fiction_cell_level_layout_is_empty)) - .def("num_pis", &py_cartesian_technology_cell_layout::num_pis, DOC(fiction_cell_level_layout_num_pis)) - .def("num_pos", &py_cartesian_technology_cell_layout::num_pos, DOC(fiction_cell_level_layout_num_pos)) - .def("is_pi", &py_cartesian_technology_cell_layout::is_pi, "c"_a, DOC(fiction_cell_level_layout_is_pi)) - .def("is_po", &py_cartesian_technology_cell_layout::is_po, "c"_a, DOC(fiction_cell_level_layout_is_po)) + .def("num_cells", &CellLyt::num_cells, DOC(fiction_cell_level_layout_num_cells)) + .def("is_empty", &CellLyt::is_empty, DOC(fiction_cell_level_layout_is_empty)) + .def("num_pis", &CellLyt::num_pis, DOC(fiction_cell_level_layout_num_pis)) + .def("num_pos", &CellLyt::num_pos, DOC(fiction_cell_level_layout_num_pos)) + .def("is_pi", &CellLyt::is_pi, "c"_a, DOC(fiction_cell_level_layout_is_pi)) + .def("is_po", &CellLyt::is_po, "c"_a, DOC(fiction_cell_level_layout_is_po)) .def("cells", - [](const py_cartesian_technology_cell_layout& lyt) + [](const CellLyt& lyt) { - std::vector> cells{}; + std::vector> cells{}; cells.reserve(lyt.num_cells()); lyt.foreach_cell([&cells](const auto& c) { cells.push_back(c); }); return cells; }) .def("pis", - [](const py_cartesian_technology_cell_layout& lyt) + [](const CellLyt& lyt) { - std::vector> pis{}; + std::vector> pis{}; pis.reserve(lyt.num_pis()); lyt.foreach_pi([&pis](const auto& c) { pis.push_back(c); }); return pis; }) .def("pos", - [](const py_cartesian_technology_cell_layout& lyt) + [](const CellLyt& lyt) { - std::vector> pos{}; + std::vector> pos{}; pos.reserve(lyt.num_pos()); lyt.foreach_po([&pos](const auto& c) { pos.push_back(c); }); return pos; }) .def( "bounding_box_2d", - [](const py_cartesian_technology_cell_layout& lyt) + [](const CellLyt& lyt) { - const auto bb = fiction::bounding_box_2d(lyt); + const auto bb = fiction::bounding_box_2d(lyt); return std::make_pair(bb.get_min(), bb.get_max()); }, DOC(fiction_bounding_box_2d_overridden)) .def("__repr__", - [](const py_cartesian_technology_cell_layout& lyt) -> std::string + [](const CellLyt& lyt) -> std::string { std::stringstream stream{}; @@ -171,7 +180,6 @@ void fcn_technology_cell_level_layout(pybind11::module& m) return stream.str(); }) - ; } @@ -179,9 +187,14 @@ void fcn_technology_cell_level_layout(pybind11::module& m) inline void cell_level_layouts(pybind11::module& m) { - detail::fcn_technology_cell_level_layout(m); - detail::fcn_technology_cell_level_layout(m); - detail::fcn_technology_cell_level_layout(m); + detail::fcn_technology_cells(m); + detail::fcn_technology_cells(m); + detail::fcn_technology_cells(m); + + detail::fcn_technology_cell_layout(m); + detail::fcn_technology_cell_layout(m); + detail::fcn_technology_cell_layout(m); + detail::fcn_technology_cell_layout(m, "cube"); } } // namespace pyfiction diff --git a/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp index 756be81e3..888f3cd81 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp @@ -25,7 +25,7 @@ namespace detail { template -void clocked_layout(pybind11::module& m, const std::string& topology) +void clocked_layout(pybind11::module& m, const std::string& topology, const std::string& coordinate_type = "") { namespace py = pybind11; using namespace pybind11::literals; @@ -33,7 +33,7 @@ void clocked_layout(pybind11::module& m, const std::string& topology) /** * Clocked Cartesian layout. */ - py::class_(m, fmt::format("clocked_{}_layout", topology).c_str(), DOC(fiction_clocked_layout)) + py::class_(m, fmt::format("clocked_{}_layout{}", topology, coordinate_type).c_str(), DOC(fiction_clocked_layout)) .def(py::init<>()) .def(py::init&>(), "dimension"_a, DOC(fiction_clocked_layout_clocked_layout)) @@ -89,6 +89,7 @@ void clocked_layout(pybind11::module& m, const std::string& topology) void clocked_layouts(pybind11::module& m) { detail::clocked_layout(m, "cartesian"); + detail::clocked_layout(m, "cartesian", "cube"); detail::clocked_layout(m, "shifted_cartesian"); detail::clocked_layout(m, "hexagonal"); } diff --git a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp index 8d6ad88e0..719c185a8 100644 --- a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp +++ b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp @@ -30,7 +30,7 @@ namespace detail * @tparam LayoutType The layout type (e.g., py_sidb_layout for regular layouts, py_sidb_layout_cube for cube layouts). */ template -void sidb_lattice_cell_level_layout(pybind11::module& m) +void sidb_lattice_cell_level_layout(pybind11::module& m, std::string lattice_name = "", std::string coordinate_tye = "") { namespace py = pybind11; using namespace py::literals; @@ -39,71 +39,25 @@ void sidb_lattice_cell_level_layout(pybind11::module& m) auto orientation = std::string{fiction::sidb_lattice_name}; std::transform(orientation.begin(), orientation.end(), orientation.begin(), ::tolower); - // Define the type alias for the specific SiDB lattice layout being bound - using py_sidb_lattice = fiction::sidb_lattice; - - /** - * SiDB lattice. - */ - if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) - { - py::class_(m, "sidb_100_lattice_cube", DOC(fiction_cell_level_layout), - py::module_local()) - .def(py::init<>()) // Default constructor - .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", - DOC(fiction_sidb_lattice)); - } - else if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) - { - py::class_(m, "sidb_111_lattice_cube", DOC(fiction_cell_level_layout), - py::module_local()) - .def(py::init<>()) // Default constructor - .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", - DOC(fiction_sidb_lattice)); - } - else if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) - { - py::class_(m, "sidb_100_lattice", DOC(fiction_cell_level_layout), - py::module_local()) - .def(py::init<>()) // Default constructor - .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", - DOC(fiction_sidb_lattice)); - } - else if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) - { - py::class_(m, "sidb_111_lattice", DOC(fiction_cell_level_layout), + py::class_(m, fmt::format("sidb_{}_lattice{}", lattice_name, coordinate_tye).c_str(), DOC(fiction_cell_level_layout), py::module_local()) .def(py::init<>()) // Default constructor .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", DOC(fiction_sidb_lattice)); - } } } // namespace detail -inline void sidb_lattices_100_cube(pybind11::module& m) -{ - // Bind the cube-coordinate 100 and 111 SiDB lattices - detail::sidb_lattice_cell_level_layout(m); -} -inline void sidb_lattices_111(pybind11::module& m) -{ - - detail::sidb_lattice_cell_level_layout(m); -} - -inline void sidb_lattices_100(pybind11::module& m) +inline void sidb_lattice(pybind11::module& m) { // Bind the regular 100 and 111 SiDB lattices - detail::sidb_lattice_cell_level_layout(m); + detail::sidb_lattice_cell_level_layout(m, "100"); + detail::sidb_lattice_cell_level_layout(m, "100", "_cube"); + detail::sidb_lattice_cell_level_layout(m, "111"); + detail::sidb_lattice_cell_level_layout(m, "111", "_cube"); } -inline void sidb_lattices_111_cube(pybind11::module& m) -{ - // Bind the regular 100 and 111 SiDB lattices - detail::sidb_lattice_cell_level_layout(m); -} } // namespace pyfiction diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index 350054806..0b9b7653a 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -34,6 +34,7 @@ #include "pyfiction/algorithms/simulation/sidb/convert_potential_to_distance.hpp" #include "pyfiction/algorithms/simulation/sidb/critical_temperature.hpp" #include "pyfiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" +#include "pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp" #include "pyfiction/algorithms/simulation/sidb/detect_bdl_wires.hpp" #include "pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp" #include "pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp" @@ -136,8 +137,8 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::detect_bdl_wires(m); pyfiction::is_operational(m); pyfiction::operational_domain(m); - // pyfiction::defect_influence_operational_domain(m); - // pyfiction::maximum_defect_influence_distance(m); + pyfiction::defect_influence_operational_domain(m); + pyfiction::maximum_defect_influence_distance(m); pyfiction::exhaustive_ground_state_simulation(m); pyfiction::quicksim(m); pyfiction::quickexact(m); @@ -200,14 +201,11 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::sidb_charge_state(m); pyfiction::sidb_nm_position(m); pyfiction::sidb_nm_distance(m); - pyfiction::sidb_lattices_100(m); - // pyfiction::sidb_lattices_100_cube(m); - pyfiction::sidb_lattices_111(m); - // pyfiction::sidb_lattices_111_cube(m); + pyfiction::sidb_lattice(m); pyfiction::charge_distribution_surfaces(m); - /** - * Input/Output - */ + // /** + // * Input/Output + // */ pyfiction::write_dot_layout(m); pyfiction::write_fgl_layout(m); pyfiction::write_qca_layout(m); @@ -221,10 +219,7 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::write_operational_domain(m); pyfiction::read_fgl_layout(m); pyfiction::read_fqca_layout(m); - pyfiction::read_sqd_layout_100(m); - pyfiction::read_sqd_layout_111(m); - pyfiction::read_sqd_layout_100_cube(m); - pyfiction::read_sqd_layout_111_cube(m); + pyfiction::read_sqd_layout(m); /** * Utils diff --git a/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py b/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py index c579de6e4..d4ff769c3 100644 --- a/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py +++ b/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py @@ -6,25 +6,29 @@ dir_path = os.path.dirname(os.path.realpath(__file__)) -class TestOperationalDomain(unittest.TestCase): +class TestDefectOperationalDomain(unittest.TestCase): def test_xor_gate_100_lattice(self): lyt = read_sqd_layout_100_cube(dir_path + "/../../../resources/hex_21_inputsdbp_xor_v1.sqd") - params = defect_influence_operational_domain_params() - params.defect_influence_params.additional_scanning_area = (20, 20) + params = defect_operational_domain_params() + params.operational_params.simulation_parameters.base = 2 + params.operational_params.simulation_parameters.mu_minus = -0.32 + params.defect_influence_params.additional_scanning_area = (50, 50) - stats_grid = defect_influence_operational_domain_stats() - _ = defect_influence_operational_domain_grid_search(lyt, [create_xor_tt()], params, 3, stats_grid) - self.assertGreater(stats_grid.num_operational_parameter_combinations, 0) + params.defect_influence_params.defect = sidb_defect(sidb_defect_type.SI_VACANCY, -1, 10.6, 5.9) - stats_random = defect_influence_operational_domain_stats() - _ = defect_influence_operational_domain_grid_search(lyt, [create_xor_tt()], params, 100, stats_random) - self.assertGreater(stats_random.num_operational_parameter_combinations, 0) + stats_grid = defect_operational_domain_stats() + _ = defect_operational_domain_grid_search(lyt, [create_xor_tt()], 6, params, stats_grid) + self.assertGreater(stats_grid.num_operational_defect_positions, 0) - stats_contour_tracing = defect_influence_operational_domain_stats() - _ = defect_influence_operational_domain_contour_tracing(lyt, [create_xor_tt()], params, 20, stats_contour_tracing) - self.assertGreater(stats_contour_tracing.num_operational_parameter_combinations, 0) + stats_random = defect_operational_domain_stats() + _ = defect_operational_domain_random_sampling(lyt, [create_xor_tt()], 100, params, stats_random) + self.assertGreater(stats_random.num_operational_defect_positions, 0) + + stats_quicktrace = defect_operational_domain_stats() + _ = defect_operational_domain_quicktrace(lyt, [create_xor_tt()], 3, params, stats_quicktrace) + self.assertGreater(stats_quicktrace.num_operational_defect_positions, 0) if __name__ == '__main__': unittest.main() diff --git a/cli/cmd/simulation/opdom.hpp b/cli/cmd/simulation/opdom.hpp index e0430bc63..466d89097 100644 --- a/cli/cmd/simulation/opdom.hpp +++ b/cli/cmd/simulation/opdom.hpp @@ -73,7 +73,7 @@ class opdom_command : public command "Use random sampling instead of grid search with this many random samples"); add_option("--flood_fill,-f", num_random_samples, "Use flood fill instead of grid search with this many initial random samples"); - add_option("--contour_tracing,-c", num_random_samples, + add_option("--quicktrace,-c", num_random_samples, "Use contour tracing instead of grid search with this many random samples"); add_option("filename", filename, "CSV filename to write the operational domain to")->required(); @@ -151,7 +151,7 @@ class opdom_command : public command // make sure that at most one algorithm is selected const std::array algorithm_selections = {is_set("random_sampling"), is_set("flood_fill"), - is_set("contour_tracing")}; + is_set("quicktrace")}; if (std::count(algorithm_selections.cbegin(), algorithm_selections.cend(), true) > 1) { env->out() << "[e] only one algorithm can be selected at a time" << std::endl; @@ -303,7 +303,7 @@ class opdom_command : public command op_domain = fiction::operational_domain_flood_fill(*lyt_ptr, std::vector{*tt_ptr}, num_random_samples, params, &stats); } - else if (is_set("contour_tracing")) + else if (is_set("quicktrace")) { op_domain = fiction::operational_domain_contour_tracing( *lyt_ptr, std::vector{*tt_ptr}, num_random_samples, params, &stats); diff --git a/docs/cli.rst b/docs/cli.rst index 54122c73a..c8d0b2110 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -402,7 +402,7 @@ By default, grid search is applied to explore the operational domain. The algori the following options: - ``--random_sampling``/``-r`` - ``--flood_fill``/``-f`` -- ``--contour_tracing``/``-c`` +- ``--quicktrace``/``-c`` each of which start from a set of random samples, whose number has to be passed as an argument to the flag. See ``opdom -h`` for a full list of arguments. diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index d5a17dd04..6a8c1e35b 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -222,7 +222,7 @@ class defect_operational_domain_impl return defect_operational_domain; } - [[nodiscard]] defect_operational_domain contour_tracing(const std::size_t samples) noexcept + [[nodiscard]] defect_operational_domain quicktrace(const std::size_t samples) noexcept { mockturtle::stopwatch stop{stats.time_total}; @@ -286,8 +286,11 @@ class defect_operational_domain_impl current_neighborhood.front() : next_clockwise_point(current_neighborhood, backtrack_point); - while (next_point != contour_starting_point) + std::size_t counter = 0; + while (next_point != contour_starting_point && counter < 1000) { + counter ++; // avoid infinite loops + const auto operational_status = is_defect_position_operational(next_point); assert(layout.num_defects() == 0 && "more than one defect"); @@ -757,7 +760,7 @@ defect_operational_domain defect_operational_domain_quicktrace(const Lyt& l defect_operational_domain_stats st{}; detail::defect_operational_domain_impl p{lyt, spec, params, st}; - const auto result = p.contour_tracing(samples); + const auto result = p.quicktrace(samples); if (stats) { diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index d20c75860..1a8d63413 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -303,8 +303,9 @@ void validate_sweep_parameters(const operational_domain_params& params) template std::optional contains_key(const MapType& map, const typename MapType::key_type& key) { - auto it = map.find(key); - if (it != map.end()) + const auto it = map.find(key); + + if (it != map.cend()) { return it->second; } diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp index de6b3bfce..8dfaab87a 100644 --- a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp +++ b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp @@ -6,8 +6,6 @@ #include #include -#include "utils/blueprints/layout_blueprints.hpp" - #include #include #include diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 5bbb9bf9d..5d9aacb60 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -5,15 +5,13 @@ #include #include +#include "utils/blueprints/layout_blueprints.hpp" + #include #include #include #include #include -#include -#include -#include -#include #include #include #include @@ -27,43 +25,7 @@ using namespace fiction; TEST_CASE("novel designed AND Gate influence distance function which fails again", "[defect-influence-operational-domain]") { - sidb_cell_clk_lyt_siqad lyt{}; - - lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - - // canvas SiDBs - // ------------- - lyt.assign_cell_type({17, 8, 1}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({21, 8, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 11, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({20, 11, 0}, sidb_technology::cell_type::NORMAL); - // ------------- - - lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - - write_sqd_layout(lyt, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/quicktrace/plots/and/and.sqd"); + const auto lyt = blueprints::bestagon_xor(); const auto cube_lyt = convert_layout_to_fiction_coordinates(lyt); @@ -77,9 +39,9 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again params.defect_influence_params.additional_scanning_area = {20, 20}; defect_operational_domain_stats stats{}; const auto defect_influence_domain = - defect_operational_domain_grid_search(cube_lyt, std::vector{create_or_tt()}, 1, params, &stats); + defect_operational_domain_grid_search(cube_lyt, std::vector{create_xor_tt()}, 3, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, - Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); + Catch::Matchers::WithinAbs(8.42177748459314479, physical_constants::POP_STABILITY_ERR)); } SECTION("Random Sampling") @@ -87,18 +49,18 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again params.defect_influence_params.additional_scanning_area = {20, 20}; defect_operational_domain_stats stats{}; const auto defect_influence_domain = - defect_operational_domain_random_sampling(cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); + defect_operational_domain_random_sampling(cube_lyt, std::vector{create_xor_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= 12.579477930); } - SECTION("Contour Tracing") + SECTION("QuickTrace") { - params.defect_influence_params.additional_scanning_area = {20, 20}; + params.defect_influence_params.additional_scanning_area = {30, 30}; defect_operational_domain_stats stats{}; const auto defect_influence_domain = - defect_operational_domain_quicktrace(cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); + defect_operational_domain_quicktrace(cube_lyt, std::vector{create_xor_tt()}, 5, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, - Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); + Catch::Matchers::WithinAbs(9.62301241815680086, physical_constants::POP_STABILITY_ERR)); } } diff --git a/test/algorithms/simulation/sidb/operational_domain.cpp b/test/algorithms/simulation/sidb/operational_domain.cpp index d9fa8675b..575a7f4f4 100644 --- a/test/algorithms/simulation/sidb/operational_domain.cpp +++ b/test/algorithms/simulation/sidb/operational_domain.cpp @@ -137,7 +137,7 @@ TEST_CASE("Error handling of operational domain algorithms", "[operational-domai std::invalid_argument); } } - SECTION("contour_tracing") + SECTION("quicktrace") { // contour tracing operates only on 2-dimensional parameter spaces for (const auto& params : @@ -195,7 +195,7 @@ TEST_CASE("Error handling of operational domain algorithms", "[operational-domai CHECK_THROWS_AS(operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 1, params), std::invalid_argument); } - SECTION("contour_tracing") + SECTION("quicktrace") { CHECK_THROWS_AS(operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, params), std::invalid_argument); @@ -243,7 +243,7 @@ TEST_CASE("Error handling of operational domain algorithms", "[operational-domai CHECK_THROWS_AS(operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 1, params), std::invalid_argument); } - SECTION("contour_tracing") + SECTION("quicktrace") { CHECK_THROWS_AS(operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, params), std::invalid_argument); @@ -422,7 +422,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") } } } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, op_domain_params, &op_domain_stats); @@ -505,7 +505,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") CHECK(op_domain_stats.num_operational_parameter_combinations == 100); CHECK(op_domain_stats.num_non_operational_parameter_combinations == 0); } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, op_domain_params, &op_domain_stats); @@ -661,7 +661,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") } } } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, op_domain_params, &op_domain_stats); @@ -815,7 +815,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") CHECK(op_domain_stats.num_non_operational_parameter_combinations <= 500); } } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 25, op_domain_params, &op_domain_stats); @@ -924,7 +924,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") CHECK(op_domain_stats.num_non_operational_parameter_combinations <= 176); } } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 50, op_domain_params, &op_domain_stats); @@ -1031,7 +1031,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation", "[operational-domai CHECK(op_domain_stats.num_operational_parameter_combinations == 100); CHECK(op_domain_stats.num_non_operational_parameter_combinations == 0); } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); @@ -1148,7 +1148,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat CHECK(op_domain_stats.num_operational_parameter_combinations == 100); CHECK(op_domain_stats.num_non_operational_parameter_combinations == 0); } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); @@ -1237,7 +1237,7 @@ TEMPLATE_TEST_CASE("AND gate on the H-Si(111)-1x1 surface", "[operational-domain CHECK(op_domain_stats.num_non_operational_parameter_combinations == 0); } } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(layout, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); diff --git a/test/utils/blueprints/layout_blueprints.hpp b/test/utils/blueprints/layout_blueprints.hpp index dba271966..241b42e74 100644 --- a/test/utils/blueprints/layout_blueprints.hpp +++ b/test/utils/blueprints/layout_blueprints.hpp @@ -924,6 +924,7 @@ Lyt and_gate_111_mirrored_on_the_x_axis() noexcept static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(fiction::is_sidb_lattice_111_v, "Lyt should have 111 as lattice orientation"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -972,6 +973,7 @@ Lyt bestagon_crossing() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1025,6 +1027,7 @@ Lyt crossing_bestagon_shape_input_down_output_up() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1083,6 +1086,7 @@ Lyt bestagon_and() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1133,6 +1137,7 @@ Lyt bestagon_fo2() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1180,6 +1185,7 @@ Lyt two_input_two_output_bestagon_skeleton() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1231,6 +1237,7 @@ Lyt two_input_two_output_bestagon_skeleton_input_down_output_up() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1284,6 +1291,7 @@ Lyt two_input_one_output_bestagon_skeleton() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1318,6 +1326,53 @@ Lyt two_input_one_output_bestagon_skeleton() noexcept return lyt; }; + +template +Lyt bestagon_xor() noexcept +{ + static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); + + Lyt lyt{}; + + // input wires + lyt.assign_cell_type({0, 0, 0}, Lyt::cell_type::INPUT); + lyt.assign_cell_type({38, 0, 0}, Lyt::cell_type::INPUT); + + lyt.assign_cell_type({2, 1, 0}, Lyt::cell_type::INPUT); + lyt.assign_cell_type({36, 1, 0}, Lyt::cell_type::INPUT); + + lyt.assign_cell_type({32, 2, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({6, 2, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({30, 3, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({8, 3, 0}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({26, 4, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({12, 4, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({24, 5, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({14, 5, 0}, Lyt::cell_type::NORMAL); + + // canvas + lyt.assign_cell_type({15, 7, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({19, 8, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({17, 9, 1}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({20, 11, 0}, Lyt::cell_type::NORMAL); + + // output wire + lyt.assign_cell_type({19, 13, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({20, 14, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({30, 17, 0}, Lyt::cell_type::OUTPUT); + lyt.assign_cell_type({32, 18, 0}, Lyt::cell_type::OUTPUT); + + lyt.assign_cell_type({36, 19, 0}, Lyt::cell_type::NORMAL); + + return lyt; +}; + /** * This layout represents an AND gate with the typical Bestagon skeleton. However, it shows kinks in the I/O pins for * certain input pattern. @@ -1327,6 +1382,7 @@ Lyt and_gate_with_kink_states() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1375,6 +1431,7 @@ Lyt two_input_left_one_output_right_top_skeleton() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; From 1e78447757018b982a1614a648ab1cec8d5396fb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:27:09 +0000 Subject: [PATCH 146/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sidb/defect_operational_domain.hpp | 34 +++++++----------- .../determine_physically_valid_parameters.hpp | 6 ++-- .../pyfiction/inout/read_sqd_layout.hpp | 4 +-- .../pyfiction/layouts/cartesian_layout.hpp | 6 ++-- .../pyfiction/layouts/cell_level_layout.hpp | 36 ++++++++----------- .../pyfiction/layouts/clocked_layout.hpp | 3 +- .../pyfiction/technology/sidb_lattice.hpp | 13 ++++--- bindings/pyfiction/pyfiction.cpp | 2 +- cli/cmd/simulation/opdom.hpp | 3 +- .../defect_influence_operational_domain.hpp | 2 +- test/utils/blueprints/layout_blueprints.hpp | 1 - 11 files changed, 45 insertions(+), 65 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp index 9443a0ccc..35186c5cd 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -29,17 +29,15 @@ void defect_influence_operational_domain_detail(pybind11::module& m) // todo update docu - m.def("defect_operational_domain_grid_search", - &fiction::defect_operational_domain_grid_search, "lyt"_a, "spec"_a, "step_size"_a, - "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); + m.def("defect_operational_domain_grid_search", &fiction::defect_operational_domain_grid_search, "lyt"_a, + "spec"_a, "step_size"_a, "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); - m.def("defect_operational_domain_random_sampling", - &fiction::defect_operational_domain_random_sampling, "lyt"_a, "spec"_a, "samples"_a, - "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); + m.def("defect_operational_domain_random_sampling", &fiction::defect_operational_domain_random_sampling, + "lyt"_a, "spec"_a, "samples"_a, "params"_a = fiction::defect_operational_domain_params{}, + "stats"_a = nullptr); - m.def("defect_operational_domain_quicktrace", - &fiction::defect_operational_domain_quicktrace, "lyt"_a, "spec"_a, "samples"_a, - "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); + m.def("defect_operational_domain_quicktrace", &fiction::defect_operational_domain_quicktrace, "lyt"_a, + "spec"_a, "samples"_a, "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); } } // namespace detail @@ -49,33 +47,27 @@ inline void defect_influence_operational_domain(pybind11::module& m) namespace py = pybind11; using namespace pybind11::literals; - py::class_>( - m, "defect_operational_domain_100") + py::class_>(m, "defect_operational_domain_100") .def(py::init<>()); - py::class_>( - m, "defect_operational_domain_111") + py::class_>(m, "defect_operational_domain_111") .def(py::init<>()); - py::class_>( - m, "defect_operational_domain_100_cube") + py::class_>(m, "defect_operational_domain_100_cube") .def(py::init<>()); - py::class_>( - m, "defect_operational_domain_111_cube") + py::class_>(m, "defect_operational_domain_111_cube") .def(py::init<>()); py::class_(m, "defect_operational_domain_params") .def(py::init<>()) - .def_readwrite("defect_influence_params", - &fiction::defect_operational_domain_params::defect_influence_params) + .def_readwrite("defect_influence_params", &fiction::defect_operational_domain_params::defect_influence_params) .def_readwrite("operational_params", &fiction::defect_operational_domain_params::operational_params); py::class_(m, "defect_operational_domain_stats") .def(py::init<>()) .def_readonly("time_total", &fiction::defect_operational_domain_stats::time_total) - .def_readonly("num_simulator_invocations", - &fiction::defect_operational_domain_stats::num_simulator_invocations) + .def_readonly("num_simulator_invocations", &fiction::defect_operational_domain_stats::num_simulator_invocations) .def_readonly("num_evaluated_parameter_combinations", &fiction::defect_operational_domain_stats::num_evaluated_defect_positions) .def_readonly("num_operational_defect_positions", diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp index c7ec72ae3..2d0253986 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp @@ -53,9 +53,9 @@ inline void determine_physically_valid_parameters(pybind11::module& m) { return result.value(); } - // If no value is present, raise a Python ValueError - throw py::value_error("Invalid parameter point: no excited state number available for the provided parameter."); - + // If no value is present, raise a Python ValueError + throw py::value_error( + "Invalid parameter point: no excited state number available for the provided parameter."); }, "pp"_a); diff --git a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp index 0dce736a2..eac5dc0c4 100644 --- a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp @@ -32,8 +32,8 @@ void read_sqd_layout(pybind11::module& m, std::string lattice_orientation, std:: Lyt (*read_sqd_layout_function_pointer)(const std::string_view&, const std::string_view&) = &fiction::read_sqd_layout; - m.def(fmt::format("read_sqd_layout_{}{}", lattice_orientation, coordinate_type).c_str(), read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", - DOC(fiction_read_sqd_layout_3)); + m.def(fmt::format("read_sqd_layout_{}{}", lattice_orientation, coordinate_type).c_str(), + read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", DOC(fiction_read_sqd_layout_3)); } } // namespace detail diff --git a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp index 427d50b3d..7d0c1cde5 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp @@ -143,7 +143,7 @@ inline void cartesian_layout_impl(pybind11::module& m) ; } -}; +}; // namespace detail inline void cartesian_layout(pybind11::module& m) { @@ -151,8 +151,6 @@ inline void cartesian_layout(pybind11::module& m) detail::cartesian_layout_impl(m); } - - -}// namespace pyfiction +} // namespace pyfiction #endif // PYFICTION_CARTESIAN_LAYOUT_HPP diff --git a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp index 1a8fbfe53..71e738903 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp @@ -88,19 +88,16 @@ void fcn_technology_cell_layout(pybind11::module& m, std::string coordinate_name * Cell-level clocked Cartesian layout. */ - py::class_( - m, fmt::format("{}_layout{}", tech_name, coordinate_name).c_str(), DOC(fiction_cell_level_layout)) + py::class_(m, fmt::format("{}_layout{}", tech_name, coordinate_name).c_str(), + DOC(fiction_cell_level_layout)) .def(py::init<>()) .def(py::init&>(), "dimension"_a, DOC(fiction_cell_level_layout_cell_level_layout)) .def(py::init( - [](const fiction::aspect_ratio& dimension, - const std::string& scheme_name, + [](const fiction::aspect_ratio& dimension, const std::string& scheme_name, const std::string& layout_name) -> CellLyt { - if (const auto scheme = - fiction::get_clocking_scheme(scheme_name); - scheme.has_value()) + if (const auto scheme = fiction::get_clocking_scheme(scheme_name); scheme.has_value()) { return CellLyt{dimension, *scheme, layout_name}; } @@ -112,18 +109,13 @@ void fcn_technology_cell_layout(pybind11::module& m, std::string coordinate_name .def("assign_cell_type", &CellLyt::assign_cell_type, "c"_a, "ct"_a, DOC(fiction_cell_level_layout_assign_cell_type)) - .def("get_cell_type", &CellLyt::get_cell_type, "c"_a, - DOC(fiction_cell_level_layout_get_cell_type)) - .def("is_empty_cell", &CellLyt::is_empty_cell, "c"_a, - DOC(fiction_cell_level_layout_is_empty_cell)) + .def("get_cell_type", &CellLyt::get_cell_type, "c"_a, DOC(fiction_cell_level_layout_get_cell_type)) + .def("is_empty_cell", &CellLyt::is_empty_cell, "c"_a, DOC(fiction_cell_level_layout_is_empty_cell)) .def("assign_cell_name", &CellLyt::assign_cell_name, "c"_a, "n"_a, DOC(fiction_cell_level_layout_assign_cell_name)) - .def("get_cell_name", &CellLyt::get_cell_name, "c"_a, - DOC(fiction_cell_level_layout_get_cell_name)) - .def("set_layout_name", &CellLyt::set_layout_name, "name"_a, - DOC(fiction_cell_level_layout_set_layout_name)) - .def("get_layout_name", &CellLyt::get_layout_name, - DOC(fiction_cell_level_layout_get_layout_name)) + .def("get_cell_name", &CellLyt::get_cell_name, "c"_a, DOC(fiction_cell_level_layout_get_cell_name)) + .def("set_layout_name", &CellLyt::set_layout_name, "name"_a, DOC(fiction_cell_level_layout_set_layout_name)) + .def("get_layout_name", &CellLyt::get_layout_name, DOC(fiction_cell_level_layout_get_layout_name)) .def("num_cells", &CellLyt::num_cells, DOC(fiction_cell_level_layout_num_cells)) .def("is_empty", &CellLyt::is_empty, DOC(fiction_cell_level_layout_is_empty)) .def("num_pis", &CellLyt::num_pis, DOC(fiction_cell_level_layout_num_pis)) @@ -179,8 +171,7 @@ void fcn_technology_cell_layout(pybind11::module& m, std::string coordinate_name } return stream.str(); - }) - ; + }); } } // namespace detail @@ -191,10 +182,11 @@ inline void cell_level_layouts(pybind11::module& m) detail::fcn_technology_cells(m); detail::fcn_technology_cells(m); - detail::fcn_technology_cell_layout(m); - detail::fcn_technology_cell_layout(m); + detail::fcn_technology_cell_layout(m); + detail::fcn_technology_cell_layout(m); detail::fcn_technology_cell_layout(m); - detail::fcn_technology_cell_layout(m, "cube"); + detail::fcn_technology_cell_layout( + m, "cube"); } } // namespace pyfiction diff --git a/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp index 888f3cd81..09dc0bc5a 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp @@ -33,7 +33,8 @@ void clocked_layout(pybind11::module& m, const std::string& topology, const std: /** * Clocked Cartesian layout. */ - py::class_(m, fmt::format("clocked_{}_layout{}", topology, coordinate_type).c_str(), DOC(fiction_clocked_layout)) + py::class_(m, fmt::format("clocked_{}_layout{}", topology, coordinate_type).c_str(), + DOC(fiction_clocked_layout)) .def(py::init<>()) .def(py::init&>(), "dimension"_a, DOC(fiction_clocked_layout_clocked_layout)) diff --git a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp index 719c185a8..c7bbb5b7d 100644 --- a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp +++ b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp @@ -39,16 +39,16 @@ void sidb_lattice_cell_level_layout(pybind11::module& m, std::string lattice_nam auto orientation = std::string{fiction::sidb_lattice_name}; std::transform(orientation.begin(), orientation.end(), orientation.begin(), ::tolower); - py::class_(m, fmt::format("sidb_{}_lattice{}", lattice_name, coordinate_tye).c_str(), DOC(fiction_cell_level_layout), - py::module_local()) - .def(py::init<>()) // Default constructor - .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", - DOC(fiction_sidb_lattice)); + py::class_( + m, fmt::format("sidb_{}_lattice{}", lattice_name, coordinate_tye).c_str(), DOC(fiction_cell_level_layout), + py::module_local()) + .def(py::init<>()) // Default constructor + .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", + DOC(fiction_sidb_lattice)); } } // namespace detail - inline void sidb_lattice(pybind11::module& m) { // Bind the regular 100 and 111 SiDB lattices @@ -58,7 +58,6 @@ inline void sidb_lattice(pybind11::module& m) detail::sidb_lattice_cell_level_layout(m, "111", "_cube"); } - } // namespace pyfiction #endif // PYFICTION_SIDB_LATTICE_HPP diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index 0b9b7653a..ac393ba65 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -33,8 +33,8 @@ #include "pyfiction/algorithms/simulation/sidb/compute_operational_ratio.hpp" #include "pyfiction/algorithms/simulation/sidb/convert_potential_to_distance.hpp" #include "pyfiction/algorithms/simulation/sidb/critical_temperature.hpp" -#include "pyfiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" #include "pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp" +#include "pyfiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" #include "pyfiction/algorithms/simulation/sidb/detect_bdl_wires.hpp" #include "pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp" #include "pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp" diff --git a/cli/cmd/simulation/opdom.hpp b/cli/cmd/simulation/opdom.hpp index 466d89097..ae87b335f 100644 --- a/cli/cmd/simulation/opdom.hpp +++ b/cli/cmd/simulation/opdom.hpp @@ -150,8 +150,7 @@ class opdom_command : public command } // make sure that at most one algorithm is selected - const std::array algorithm_selections = {is_set("random_sampling"), is_set("flood_fill"), - is_set("quicktrace")}; + const std::array algorithm_selections = {is_set("random_sampling"), is_set("flood_fill"), is_set("quicktrace")}; if (std::count(algorithm_selections.cbegin(), algorithm_selections.cend(), true) > 1) { env->out() << "[e] only one algorithm can be selected at a time" << std::endl; diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 6a8c1e35b..3c83a09ce 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -289,7 +289,7 @@ class defect_operational_domain_impl std::size_t counter = 0; while (next_point != contour_starting_point && counter < 1000) { - counter ++; // avoid infinite loops + counter++; // avoid infinite loops const auto operational_status = is_defect_position_operational(next_point); diff --git a/test/utils/blueprints/layout_blueprints.hpp b/test/utils/blueprints/layout_blueprints.hpp index 241b42e74..170fd1ea7 100644 --- a/test/utils/blueprints/layout_blueprints.hpp +++ b/test/utils/blueprints/layout_blueprints.hpp @@ -1326,7 +1326,6 @@ Lyt two_input_one_output_bestagon_skeleton() noexcept return lyt; }; - template Lyt bestagon_xor() noexcept { From a038155d7715b53bc1db4aa010c4ea4353ce5379 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 1 Nov 2024 15:28:12 +0000 Subject: [PATCH 147/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index dd782cd53..ee5a2a6f1 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -4803,8 +4803,6 @@ static const char *__doc_fiction_detail_critical_temperature_impl_stats = R"doc( static const char *__doc_fiction_detail_defect_operational_domain_impl = R"doc()doc"; -static const char *__doc_fiction_detail_defect_operational_domain_impl_contour_tracing = R"doc()doc"; - static const char *__doc_fiction_detail_defect_operational_domain_impl_current_defect_position = R"doc(The current defect position.)doc"; static const char *__doc_fiction_detail_defect_operational_domain_impl_defect_operational_domain = R"doc(The operational domain of the layout.)doc"; @@ -4893,6 +4891,8 @@ static const char *__doc_fiction_detail_defect_operational_domain_impl_params = static const char *__doc_fiction_detail_defect_operational_domain_impl_previous_defect_position = R"doc(The previous defect position.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_quicktrace = R"doc()doc"; + static const char *__doc_fiction_detail_defect_operational_domain_impl_random_sampling = R"doc(This function performs random sampling of defect positions from a grid area (spanned by `nw_cell` and `se_cell`). The positions are shuffled From 14a934e9b8b6f5914537686f384e5ce45323d6c5 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 1 Nov 2024 16:53:56 +0100 Subject: [PATCH 148/221] :art: small fix. --- .../defect_influence_operational_domain.hpp | 26 ++++++++++--------- .../defect_influence_operational_domain.cpp | 10 +++---- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 6a8c1e35b..1dbf60b08 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -155,7 +155,7 @@ class defect_operational_domain_impl log_stats(); - return defect_operational_domain; + return defect_op_domain; } /** @@ -219,7 +219,7 @@ class defect_operational_domain_impl log_stats(); // Log the statistics after processing // Return the computed operational domain - return defect_operational_domain; + return defect_op_domain; } [[nodiscard]] defect_operational_domain quicktrace(const std::size_t samples) noexcept @@ -254,7 +254,7 @@ class defect_operational_domain_impl // if no operational point was found within the specified number of samples, return if (!operational_starting_point.has_value()) { - return defect_operational_domain; + return defect_op_domain; } // check if the starting point has already been sampled @@ -287,9 +287,11 @@ class defect_operational_domain_impl next_clockwise_point(current_neighborhood, backtrack_point); std::size_t counter = 0; - while (next_point != contour_starting_point && counter < 1000) + while (next_point != contour_starting_point && counter < 100) { - counter ++; // avoid infinite loops + counter++; // avoid infinite loops + + std::cout << counter << std::endl; const auto operational_status = is_defect_position_operational(next_point); @@ -311,7 +313,7 @@ class defect_operational_domain_impl } log_stats(); - return defect_operational_domain; + return defect_op_domain; } private: @@ -383,14 +385,14 @@ class defect_operational_domain_impl const auto operational = [this, &c]() { - defect_operational_domain.operational_values[c] = operational_status::OPERATIONAL; + defect_op_domain.operational_values[c] = operational_status::OPERATIONAL; return operational_status::OPERATIONAL; }; const auto non_operational = [this, &c]() { - defect_operational_domain.operational_values[c] = operational_status::NON_OPERATIONAL; + defect_op_domain.operational_values[c] = operational_status::NON_OPERATIONAL; return operational_status::NON_OPERATIONAL; }; @@ -425,8 +427,8 @@ class defect_operational_domain_impl [[nodiscard]] inline std::optional has_already_been_sampled(const typename Lyt::cell& c) const noexcept { - if (const auto it = defect_operational_domain.operational_values.find(c); - it != defect_operational_domain.operational_values.cend()) + if (const auto it = defect_op_domain.operational_values.find(c); + it != defect_op_domain.operational_values.cend()) { return it->second; } @@ -482,7 +484,7 @@ class defect_operational_domain_impl stats.num_simulator_invocations = num_simulator_invocations; stats.num_evaluated_defect_positions = num_evaluated_defect_positions; - for (const auto& [param_point, status] : defect_operational_domain.operational_values) + for (const auto& [param_point, status] : defect_op_domain.operational_values) { if (status == operational_status::OPERATIONAL) { @@ -623,7 +625,7 @@ class defect_operational_domain_impl /** * The operational domain of the layout. */ - defect_operational_domain defect_operational_domain{}; + defect_operational_domain defect_op_domain{}; /** * The statistics of the operational domain computation. */ diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 5d9aacb60..c8ba9b52d 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -25,7 +25,7 @@ using namespace fiction; TEST_CASE("novel designed AND Gate influence distance function which fails again", "[defect-influence-operational-domain]") { - const auto lyt = blueprints::bestagon_xor(); + const auto lyt = blueprints::bestagon_and(); const auto cube_lyt = convert_layout_to_fiction_coordinates(lyt); @@ -39,7 +39,7 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again params.defect_influence_params.additional_scanning_area = {20, 20}; defect_operational_domain_stats stats{}; const auto defect_influence_domain = - defect_operational_domain_grid_search(cube_lyt, std::vector{create_xor_tt()}, 3, params, &stats); + defect_operational_domain_grid_search(cube_lyt, std::vector{create_and_tt()}, 3, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, Catch::Matchers::WithinAbs(8.42177748459314479, physical_constants::POP_STABILITY_ERR)); } @@ -49,17 +49,17 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again params.defect_influence_params.additional_scanning_area = {20, 20}; defect_operational_domain_stats stats{}; const auto defect_influence_domain = - defect_operational_domain_random_sampling(cube_lyt, std::vector{create_xor_tt()}, 100, params, &stats); + defect_operational_domain_random_sampling(cube_lyt, std::vector{create_and_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= 12.579477930); } SECTION("QuickTrace") { - params.defect_influence_params.additional_scanning_area = {30, 30}; + params.defect_influence_params.additional_scanning_area = {20, 20}; defect_operational_domain_stats stats{}; const auto defect_influence_domain = - defect_operational_domain_quicktrace(cube_lyt, std::vector{create_xor_tt()}, 5, params, &stats); + defect_operational_domain_quicktrace(cube_lyt, std::vector{create_and_tt()}, 5, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, Catch::Matchers::WithinAbs(9.62301241815680086, physical_constants::POP_STABILITY_ERR)); } From 38ff96ce6d558359eadb31859a4f8f6aa92ef851 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:54:40 +0000 Subject: [PATCH 149/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulation/sidb/defect_influence_operational_domain.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 1dbf60b08..a56ff07d6 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -289,7 +289,7 @@ class defect_operational_domain_impl std::size_t counter = 0; while (next_point != contour_starting_point && counter < 100) { - counter++; // avoid infinite loops + counter++; // avoid infinite loops std::cout << counter << std::endl; From 67a493a625a75703b1c2d2ddb3ae35b603121243 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 1 Nov 2024 15:55:32 +0000 Subject: [PATCH 150/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index ee5a2a6f1..930bb607a 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -4805,7 +4805,7 @@ static const char *__doc_fiction_detail_defect_operational_domain_impl = R"doc() static const char *__doc_fiction_detail_defect_operational_domain_impl_current_defect_position = R"doc(The current defect position.)doc"; -static const char *__doc_fiction_detail_defect_operational_domain_impl_defect_operational_domain = R"doc(The operational domain of the layout.)doc"; +static const char *__doc_fiction_detail_defect_operational_domain_impl_defect_op_domain = R"doc(The operational domain of the layout.)doc"; static const char *__doc_fiction_detail_defect_operational_domain_impl_defect_operational_domain_impl = R"doc()doc"; From e358e38a781ef13b5d9ef2fd3a1005ca02997db0 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Sat, 2 Nov 2024 10:14:00 +0100 Subject: [PATCH 151/221] :art: small change. --- include/fiction/io/write_sqd_layout.hpp | 29 +++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/include/fiction/io/write_sqd_layout.hpp b/include/fiction/io/write_sqd_layout.hpp index 67a62a593..3a10634fa 100644 --- a/include/fiction/io/write_sqd_layout.hpp +++ b/include/fiction/io/write_sqd_layout.hpp @@ -280,11 +280,6 @@ class write_sqd_layout_impl type_str = fmt::format(siqad::DOT_TYPE, "logic"); break; } - default: - { - type_str = ""; - break; - } } if constexpr (has_siqad_coord_v) @@ -307,10 +302,26 @@ class write_sqd_layout_impl { const auto type = this->lyt.get_cell_type(c); - const auto color = qca_technology::is_input_cell(type) ? siqad::INPUT_COLOR : - qca_technology::is_output_cell(type) ? siqad::OUTPUT_COLOR : - qca_technology::is_constant_cell(type) ? siqad::CONST_COLOR : - siqad::NORMAL_COLOR; + auto color = siqad::NORMAL_COLOR; + + switch (type) + { + case (qca_technology::is_input_cell(type)): + { + color = siqad::INPUT_COLOR; + break; + } + case (qca_technology::is_output_cell(type)): + { + color = siqad::OUTPUT_COLOR; + break; + } + case (qca_technology::is_constant_cell(type)): + { + siqad::CONST_COLOR; + break; + } + } if (!qca_technology::is_const_1_cell(type)) { From 5090abb6feebfc747f9d5ed89ce204528643a3f4 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Sat, 2 Nov 2024 10:27:13 +0100 Subject: [PATCH 152/221] :art: small fix. --- include/fiction/io/write_sqd_layout.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/fiction/io/write_sqd_layout.hpp b/include/fiction/io/write_sqd_layout.hpp index 3a10634fa..9fd3d0fbd 100644 --- a/include/fiction/io/write_sqd_layout.hpp +++ b/include/fiction/io/write_sqd_layout.hpp @@ -306,17 +306,17 @@ class write_sqd_layout_impl switch (type) { - case (qca_technology::is_input_cell(type)): + case (type == qca_technology::cell_type::INPUT): { color = siqad::INPUT_COLOR; break; } - case (qca_technology::is_output_cell(type)): + case (type == qca_technology::cell_type::OUTPUT): { color = siqad::OUTPUT_COLOR; break; } - case (qca_technology::is_constant_cell(type)): + case (type == qca_technology::cell_type::CONST_0 || type == qca_technology::cell_type::CONST_1): { siqad::CONST_COLOR; break; From dc7b0d5cf42ad42c3d36a6272800e8d5c5bc9e84 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Sat, 2 Nov 2024 10:29:14 +0100 Subject: [PATCH 153/221] :art: clang-tidy fix. --- include/fiction/io/write_sqd_layout.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/io/write_sqd_layout.hpp b/include/fiction/io/write_sqd_layout.hpp index 9fd3d0fbd..266b83e1c 100644 --- a/include/fiction/io/write_sqd_layout.hpp +++ b/include/fiction/io/write_sqd_layout.hpp @@ -302,7 +302,7 @@ class write_sqd_layout_impl { const auto type = this->lyt.get_cell_type(c); - auto color = siqad::NORMAL_COLOR; + const auto *color = siqad::NORMAL_COLOR; switch (type) { From 0e2fba548522ab6a045785aedd9aa83d7469e92d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 2 Nov 2024 09:29:31 +0000 Subject: [PATCH 154/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/fiction/io/write_sqd_layout.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/io/write_sqd_layout.hpp b/include/fiction/io/write_sqd_layout.hpp index 266b83e1c..8a2277f28 100644 --- a/include/fiction/io/write_sqd_layout.hpp +++ b/include/fiction/io/write_sqd_layout.hpp @@ -302,7 +302,7 @@ class write_sqd_layout_impl { const auto type = this->lyt.get_cell_type(c); - const auto *color = siqad::NORMAL_COLOR; + const auto* color = siqad::NORMAL_COLOR; switch (type) { From b8fcf6c1dd2fb95ccc47e84a4733702c03016d62 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Sat, 2 Nov 2024 11:03:23 +0100 Subject: [PATCH 155/221] :art: small fix. --- include/fiction/io/write_sqd_layout.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/fiction/io/write_sqd_layout.hpp b/include/fiction/io/write_sqd_layout.hpp index 8a2277f28..cc8e0af3d 100644 --- a/include/fiction/io/write_sqd_layout.hpp +++ b/include/fiction/io/write_sqd_layout.hpp @@ -306,19 +306,20 @@ class write_sqd_layout_impl switch (type) { - case (type == qca_technology::cell_type::INPUT): + case (qca_technology::cell_type::INPUT): { color = siqad::INPUT_COLOR; break; } - case (type == qca_technology::cell_type::OUTPUT): + case (qca_technology::cell_type::OUTPUT): { color = siqad::OUTPUT_COLOR; break; } - case (type == qca_technology::cell_type::CONST_0 || type == qca_technology::cell_type::CONST_1): + case (qca_technology::cell_type::CONST_0): + case (qca_technology::cell_type::CONST_1): { - siqad::CONST_COLOR; + color = siqad::CONST_COLOR; break; } } From 325c0e39c478ac0fd37c4b269fab843ab4e36e81 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Sat, 2 Nov 2024 13:40:14 +0100 Subject: [PATCH 156/221] :art: small fix. --- .../defect_influence_operational_domain.hpp | 25 ++++++++++++------- .../defect_influence_operational_domain.cpp | 7 +++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index a56ff07d6..1a73afe62 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -270,9 +270,16 @@ class defect_operational_domain_impl assert(layout.num_defects() == 0 && "An atomic defect is added"); // find an operational point on the contour starting from the randomly determined starting point - const auto contour_starting_point = + const auto contour_starting_p = find_last_operational_defect_position_moving_right(*operational_starting_point); + if (!contour_starting_p.has_value()) + { + continue; + } + + const auto contour_starting_point = *contour_starting_p; + // the layout hs to be defect-free. assert(layout.num_defects() == 0 && "An atomic defect is added"); @@ -286,13 +293,8 @@ class defect_operational_domain_impl current_neighborhood.front() : next_clockwise_point(current_neighborhood, backtrack_point); - std::size_t counter = 0; - while (next_point != contour_starting_point && counter < 100) + while (next_point != contour_starting_point) { - counter++; // avoid infinite loops - - std::cout << counter << std::endl; - const auto operational_status = is_defect_position_operational(next_point); assert(layout.num_defects() == 0 && "more than one defect"); @@ -442,9 +444,9 @@ class defect_operational_domain_impl * * @param starting_defect_position The starting position of the defect, from which the traversal towards the right * is conducted while maintaining gate operability. - * @return The last operational defect position. + * @return The last operational defect position. If no non-operational defect is found, std::nullopt is returned. */ - [[nodiscard]] typename Lyt::cell + [[nodiscard]] std::optional find_last_operational_defect_position_moving_right(const typename Lyt::cell& starting_defect_position) noexcept { auto latest_operational_defect_position = starting_defect_position; @@ -473,6 +475,11 @@ class defect_operational_domain_impl } } + if (current_defect_position == latest_operational_defect_position) + { + return std::nullopt; + } + return latest_operational_defect_position; } /** diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index c8ba9b52d..c6166fe58 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -40,8 +40,8 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again defect_operational_domain_stats stats{}; const auto defect_influence_domain = defect_operational_domain_grid_search(cube_lyt, std::vector{create_and_tt()}, 3, params, &stats); - CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, - Catch::Matchers::WithinAbs(8.42177748459314479, physical_constants::POP_STABILITY_ERR)); + CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= + 6.2126117696183147); } SECTION("Random Sampling") @@ -56,11 +56,12 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again SECTION("QuickTrace") { + // 6.21261176961831474 nm is the exact value. params.defect_influence_params.additional_scanning_area = {20, 20}; defect_operational_domain_stats stats{}; const auto defect_influence_domain = defect_operational_domain_quicktrace(cube_lyt, std::vector{create_and_tt()}, 5, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, - Catch::Matchers::WithinAbs(9.62301241815680086, physical_constants::POP_STABILITY_ERR)); + Catch::Matchers::WithinAbs(6.21261176961831474, physical_constants::POP_STABILITY_ERR)); } } From 41b630e48a2743b5b4cc5c4c02b52c0d6f3b41b2 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 2 Nov 2024 12:41:15 +0000 Subject: [PATCH 157/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index 930bb607a..522a02b23 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -4822,7 +4822,8 @@ Parameter ``starting_defect_position``: towards the right is conducted while maintaining gate operability. Returns: - The last operational defect position.)doc"; + The last operational defect position. If no non-operational defect + is found, std::nullopt is returned.)doc"; static const char *__doc_fiction_detail_defect_operational_domain_impl_find_operational_defect_position_at_left_side = R"doc(This function aims to identify an operational defect position within From f7278472492aba794e4f9abe1fd5ca932b182da1 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Sat, 2 Nov 2024 17:03:45 +0100 Subject: [PATCH 158/221] :art: small fix. --- .../sidb/defect_operational_domain.hpp | 32 +++++-------- .../determine_physically_valid_parameters.hpp | 2 + .../pyfiction/inout/read_sqd_layout.hpp | 1 + .../pyfiction/layouts/cartesian_layout.hpp | 3 +- docs/algorithms/sidb_simulation.rst | 47 +++++++++++++------ .../operational_domain_siqad.cpp | 2 - .../quicktrace_vs_grid_search_bestagon.cpp | 6 +-- ...> quicktrace_vs_grid_search_new_gates.cpp} | 13 +++-- .../assess_physical_population_stability.hpp | 2 +- .../simulation/sidb/critical_temperature.hpp | 3 +- .../sidb/defect_avoidance_distance.hpp | 14 +++--- .../defect_influence_operational_domain.hpp | 3 +- ...defect_influence_position_and_distance.hpp | 2 +- ...nce_position_and_distance_of_sidb_gate.hpp | 1 - ...te_defect_influence_operational_domain.hpp | 1 - .../defect_influence_operational_domain.cpp | 6 +-- 16 files changed, 75 insertions(+), 63 deletions(-) rename experiments/quicktrace/{quickrace_vs_grid_search_new_gates.cpp => quicktrace_vs_grid_search_new_gates.cpp} (89%) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp index 35186c5cd..52400425f 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -14,8 +14,6 @@ #include #include -#include - namespace pyfiction { @@ -27,17 +25,15 @@ void defect_influence_operational_domain_detail(pybind11::module& m) { using namespace pybind11::literals; - // todo update docu - m.def("defect_operational_domain_grid_search", &fiction::defect_operational_domain_grid_search, "lyt"_a, - "spec"_a, "step_size"_a, "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); + "spec"_a, "step_size"_a, "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_defect_operational_domain_grid_search)); m.def("defect_operational_domain_random_sampling", &fiction::defect_operational_domain_random_sampling, "lyt"_a, "spec"_a, "samples"_a, "params"_a = fiction::defect_operational_domain_params{}, - "stats"_a = nullptr); + "stats"_a = nullptr, DOC(fiction_defect_operational_domain_random_sampling)); m.def("defect_operational_domain_quicktrace", &fiction::defect_operational_domain_quicktrace, "lyt"_a, - "spec"_a, "samples"_a, "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); + "spec"_a, "samples"_a, "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_defect_operational_domain_quicktrace)); } } // namespace detail @@ -59,23 +55,21 @@ inline void defect_influence_operational_domain(pybind11::module& m) py::class_>(m, "defect_operational_domain_111_cube") .def(py::init<>()); - py::class_(m, "defect_operational_domain_params") + py::class_(m, "defect_operational_domain_params", DOC(fiction_defect_operational_domain_params)) .def(py::init<>()) - .def_readwrite("defect_influence_params", &fiction::defect_operational_domain_params::defect_influence_params) - .def_readwrite("operational_params", &fiction::defect_operational_domain_params::operational_params); + .def_readwrite("defect_influence_params", &fiction::defect_operational_domain_params::defect_influence_params, DOC(fiction_defect_operational_domain_params_defect_influence_params)) + .def_readwrite("operational_params", &fiction::defect_operational_domain_params::operational_params, DOC(fiction_defect_operational_domain_params_operational_params)); - py::class_(m, "defect_operational_domain_stats") + py::class_(m, "defect_operational_domain_stats", DOC(fiction_defect_operational_domain_stats)) .def(py::init<>()) - .def_readonly("time_total", &fiction::defect_operational_domain_stats::time_total) - .def_readonly("num_simulator_invocations", &fiction::defect_operational_domain_stats::num_simulator_invocations) + .def_readonly("time_total", &fiction::defect_operational_domain_stats::time_total, DOC(fiction_defect_operational_domain_stats_duration)) + .def_readonly("num_simulator_invocations", &fiction::defect_operational_domain_stats::num_simulator_invocations, DOC(fiction_defect_operational_domain_stats_num_simulator_invocations)) .def_readonly("num_evaluated_parameter_combinations", - &fiction::defect_operational_domain_stats::num_evaluated_defect_positions) - .def_readonly("num_operational_defect_positions", - &fiction::defect_operational_domain_stats::num_operational_defect_positions) + &fiction::defect_operational_domain_stats::num_evaluated_defect_positions, DOC(fiction_defect_operational_domain_stats_num_evaluated_defect_positions)) .def_readonly("num_operational_defect_positions", - &fiction::defect_operational_domain_stats::num_operational_defect_positions) - .def_readonly("num_non_operational_defect_positions", - &fiction::defect_operational_domain_stats::num_operational_defect_positions); + &fiction::defect_operational_domain_stats::num_operational_defect_positions, DOC(fiction_defect_operational_domain_stats_num_operational_defect_positions)) + .def_readonly("num_non_operational_defect_positions", + &fiction::defect_operational_domain_stats::num_non_operational_defect_positions, DOC(fiction_defect_operational_domain_stats_num_non_operational_defect_positions)); // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! detail::defect_influence_operational_domain_detail(m); diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp index 2d0253986..ca1453d64 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp @@ -14,6 +14,8 @@ #include #include +#include + namespace pyfiction { diff --git a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp index eac5dc0c4..4e74aa22e 100644 --- a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp @@ -13,6 +13,7 @@ #include #include +#include namespace pyfiction { diff --git a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp index 7d0c1cde5..ba07dafeb 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp @@ -16,6 +16,7 @@ #include #include +#include namespace pyfiction { @@ -29,7 +30,7 @@ inline void cartesian_layout_impl(pybind11::module& m) namespace py = pybind11; using namespace pybind11::literals; - std::string coordinate_type; + std::string coordinate_type = ""; /** * Cartesian layout. */ diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index b75f9832e..d4b3cf7cd 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -305,17 +305,36 @@ Operational Domain Computation Defect Influence Operational Domain ################################### -**Header:** ``fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp`` +.. tabs:: + .. tab:: C++ + **Header:** ``fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp`` -.. doxygenstruct:: fiction::defect_operational_domain_params - :members: -.. doxygenstruct:: fiction::defect_influence_operational_domain - :members: -.. doxygenstruct:: fiction::defect_operational_domain_stats - :members: -.. doxygenfunction:: fiction::defect_influence_operational_domain_grid_search -.. doxygenfunction:: fiction::defect_influence_operational_domain_random_sampling -.. doxygenfunction:: fiction::defect_operational_domain_quicktrace + .. doxygenstruct:: fiction::defect_operational_domain_params + :members: + .. doxygenstruct:: fiction::defect_influence_operational_domain + :members: + .. doxygenstruct:: fiction::defect_operational_domain_stats + :members: + .. doxygenfunction:: fiction::defect_influence_operational_domain_grid_search + .. doxygenfunction:: fiction::defect_influence_operational_domain_random_sampling + .. doxygenfunction:: fiction::defect_operational_domain_quicktrace + + .. tab:: Python + .. autoclass:: mnt.pyfiction.defect_operational_domain_params + :members: + .. autoclass:: mnt.pyfiction.defect_influence_operational_domain_100 + :members: + .. autoclass:: mnt.pyfiction.defect_influence_operational_domain_100_cube + :members: + .. autoclass:: mnt.pyfiction.defect_influence_operational_domain_111 + :members: + .. autoclass:: mnt.pyfiction.defect_influence_operational_domain_111_cube + :members: + .. autoclass:: mnt.pyfiction.defect_operational_domain_stats + :members: + .. autofunction:: mnt.pyfiction.defect_influence_operational_domain_grid_search + .. autofunction:: mnt.pyfiction.defect_influence_operational_domain_random_sampling + .. autofunction:: mnt.pyfiction.defect_operational_domain_quicktrace Determine Physically Valid Parameters ##################################### @@ -326,7 +345,7 @@ Determine Physically Valid Parameters .. doxygenfunction:: fiction::determine_physically_valid_parameters - .. tab:: Python + .. tab:: Python .. autoclass:: mnt.pyfiction.determine_physically_valid_parameters @@ -499,8 +518,8 @@ Convert Potential to Distance Maximum Minimum Defect Influence Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -**Header:** ``fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp`` +**Header:** ``fiction/algorithms/simulation/sidb/calculate_defect_clearance.hpp`` -.. doxygenstruct:: fiction::defect_avoidance_distance_result +.. doxygenstruct:: fiction::defect_clearance_result :members: -.. doxygenfunction:: fiction::defect_avoidance_distance +.. doxygenfunction:: fiction::calculate_defect_clearance diff --git a/experiments/operational_domain/operational_domain_siqad.cpp b/experiments/operational_domain/operational_domain_siqad.cpp index d1418c474..3f25bf4d5 100644 --- a/experiments/operational_domain/operational_domain_siqad.cpp +++ b/experiments/operational_domain/operational_domain_siqad.cpp @@ -18,8 +18,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp b/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp index b828a4d07..fabf23572 100644 --- a/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp +++ b/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp @@ -87,12 +87,12 @@ int main() // Write the SQD layout write_sqd_layout(layout, sqd_path); - const auto avoidance_grid = defect_avoidance_distance(layout, op_defect_grid); + const auto avoidance_grid = calculate_defect_clearance(layout, op_defect_grid); defect_operational_domain_stats random_stats{}; const auto op_defect_random = defect_operational_domain_random_sampling(layout, truth_table, 100, defect_params, &random_stats); - const auto avoidance_random = defect_avoidance_distance(layout, op_defect_random); + const auto avoidance_random = calculate_defect_clearance(layout, op_defect_random); const auto csv_path_random = fmt::format("{}{}_random.csv", gate_folder, gate); write_defect_influence_operational_domain(op_defect_random, csv_path_random); @@ -100,7 +100,7 @@ int main() defect_operational_domain_stats contour_stats{}; const auto op_defect_contour = defect_operational_domain_quicktrace(layout, truth_table, 20, defect_params, &contour_stats); - const auto avoidance_contour = defect_avoidance_distance(layout, op_defect_contour); + const auto avoidance_contour = calculate_defect_clearance(layout, op_defect_contour); const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); diff --git a/experiments/quicktrace/quickrace_vs_grid_search_new_gates.cpp b/experiments/quicktrace/quicktrace_vs_grid_search_new_gates.cpp similarity index 89% rename from experiments/quicktrace/quickrace_vs_grid_search_new_gates.cpp rename to experiments/quicktrace/quicktrace_vs_grid_search_new_gates.cpp index 395c01663..144a8a974 100644 --- a/experiments/quicktrace/quickrace_vs_grid_search_new_gates.cpp +++ b/experiments/quicktrace/quicktrace_vs_grid_search_new_gates.cpp @@ -4,8 +4,7 @@ #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" #include "fiction/io/read_sqd_layout.hpp" -#include "fiction/io/write_defect_influence_operational_domain.hpp" -#include "fiction/io/write_sqd_layout.hpp" +#include "fiction/technology/sidb_defects.hpp" #include "fiction/traits.hpp" #include "fiction/types.hpp" #include "fiction/utils/truth_table_utils.hpp" @@ -25,7 +24,7 @@ using namespace fiction; int main() { experiments::experiment simulation_exp{"Benchmark", "Gate Name", "samples", - "wrong output quicktrace"}; + "wrong output of quicktrace"}; static const std::string folder = fmt::format("{}bestagon_gates_type_tags/", EXPERIMENTS_PATH); static const std::string output_folder = fmt::format("{}quicktrace/plots/", EXPERIMENTS_PATH); @@ -73,7 +72,7 @@ int main() const auto exhaustive_design = design_sidb_gates(lyt, truth_table, params_2_in_1_out); // Create gate directory for plots - std::string gate_folder = fmt::format("{}{}/", output_folder, gate); + const std::string gate_folder = fmt::format("{}{}/", output_folder, gate); std::filesystem::create_directories(gate_folder); std::size_t counter_for_wrong_output_of_quicktrace = 0; @@ -83,14 +82,14 @@ int main() // using grid search to find the minimum defect clearance defect_operational_domain_stats grid_stats{}; const auto op_defect_grid = - defect_influence_operational_domain_grid_search(gate_lyt, truth_table, 1, defect_params, &grid_stats); - const auto avoidance_grid = defect_avoidance_distance(gate_lyt, op_defect_grid); + defect_operational_domain_grid_search(gate_lyt, truth_table, 1, defect_params, &grid_stats); + const auto avoidance_grid = calculate_defect_clearance(gate_lyt, op_defect_grid); // using QuickTrace to find the minimum clearance defect_operational_domain_stats contour_stats{}; const auto op_defect_contour = defect_operational_domain_quicktrace(gate_lyt, truth_table, 100, defect_params, &contour_stats); - const auto avoidance_contour = defect_avoidance_distance(gate_lyt, op_defect_contour); + const auto avoidance_contour = calculate_defect_clearance(gate_lyt, op_defect_contour); // check if QuickTrace and grid search give the same result if (std::abs(avoidance_grid.minimum_defect_clearance - avoidance_contour.minimum_defect_clearance) > diff --git a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp index 62b22a360..f9aec0014 100644 --- a/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp +++ b/include/fiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp @@ -77,7 +77,7 @@ struct population_stability_information * required to conduct a charge change as a distance in nanometer. This is possible since the electrostatic * potential is connected to the distance. */ - std::unordered_map distance_corresponding_to_potential{}; + std::unordered_map distance_corresponding_to_potential; /** * Total electrostatic energy (unit: eV) of given charge distribution. */ diff --git a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp index 8a7f6e203..7fe8293cf 100644 --- a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp +++ b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -271,7 +272,7 @@ class critical_temperature_impl std::vector temp_values{}; // unit: K // Calculate the number of iterations as an integer - uint64_t num_iterations = static_cast(std::round(params.max_temperature * 100)); + const auto num_iterations = static_cast(std::round(params.max_temperature * 100)); // Reserve space for the vector temp_values.reserve(num_iterations); for (uint64_t i = 1; i <= num_iterations; i++) diff --git a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp index 8315ffb3d..c08a25d78 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp @@ -15,15 +15,15 @@ namespace fiction { /** - * Results of the defect avoidance distance calculation. + * Results of the defect clearance calculation. * * @tparam CellType */ template -struct defect_avoidance_distance_result +struct defect_clearance_result { /** - * position with maximum distance to the SiDB layout at which the placement of an SiDB defect still causes the gate + * Position with maximum distance to the SiDB layout at which the placement of an SiDB defect still causes the gate * to fail. */ CellType max_distance_postion_of_non_operational_defect{}; @@ -33,7 +33,7 @@ struct defect_avoidance_distance_result double minimum_defect_clearance{}; }; /** - * Calculates the defect avoidance distance of a given gate layout by a given atomic defect. This means that a defect + * Calculates the defect clearance of a given gate layout by a given atomic defect. This means that a defect * must be further away than this distance for the SiDB gate to be operational. This function requires both the defect * operational domain and the layout as input. * @@ -43,8 +43,8 @@ struct defect_avoidance_distance_result * @return The maximum minimum defect influence distance. */ template -[[nodiscard]] defect_avoidance_distance_result> -defect_avoidance_distance(const Lyt& lyt, const defect_operational_domain& defect_opdomain) noexcept +[[nodiscard]] defect_clearance_result> +calculate_defect_clearance(const Lyt& lyt, const defect_operational_domain& defect_opdomain) noexcept { double max_distance = 0; cell max_distance_postion = {}; @@ -76,7 +76,7 @@ defect_avoidance_distance(const Lyt& lyt, const defect_operational_domain& } } - return defect_avoidance_distance_result>{max_distance_postion, max_distance}; + return defect_clearance_result>{max_distance_postion, max_distance}; } } // namespace fiction diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index 1a73afe62..da88b30c0 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -426,7 +425,7 @@ class defect_operational_domain_impl * * @param c Position of the defect. */ - [[nodiscard]] inline std::optional + [[nodiscard]] std::optional has_already_been_sampled(const typename Lyt::cell& c) const noexcept { if (const auto it = defect_op_domain.operational_values.find(c); diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index b40885a92..5206ecfa1 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -179,7 +179,7 @@ class maximum_defect_influence_position_and_distance_impl static const std::size_t num_threads = std::thread::hardware_concurrency(); // calculate the size of each slice - const auto slice_size = (defect_cells.size() + -1) / num_threads; + const auto slice_size = (defect_cells.size() - 1) / num_threads; std::vector threads{}; threads.reserve(num_threads); diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp index 92c319c39..8db201db5 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp @@ -6,7 +6,6 @@ #define FICTION_MAXIMUM_DEFECT_INFLUENCE_POSITION_AND_DISTANCE_OF_SIDB_GATE_HPP #include "fiction/algorithms/iter/bdl_input_iterator.hpp" -#include "fiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" #include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" #include "fiction/traits.hpp" diff --git a/include/fiction/io/write_defect_influence_operational_domain.hpp b/include/fiction/io/write_defect_influence_operational_domain.hpp index 781bddb08..cf60a8208 100644 --- a/include/fiction/io/write_defect_influence_operational_domain.hpp +++ b/include/fiction/io/write_defect_influence_operational_domain.hpp @@ -11,7 +11,6 @@ #include #include -#include #include namespace fiction diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index c6166fe58..5a1f3e44b 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -40,7 +40,7 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again defect_operational_domain_stats stats{}; const auto defect_influence_domain = defect_operational_domain_grid_search(cube_lyt, std::vector{create_and_tt()}, 3, params, &stats); - CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= + CHECK(calculate_defect_clearance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= 6.2126117696183147); } @@ -51,7 +51,7 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again const auto defect_influence_domain = defect_operational_domain_random_sampling(cube_lyt, std::vector{create_and_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); - CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= 12.579477930); + CHECK(calculate_defect_clearance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= 12.579477930); } SECTION("QuickTrace") @@ -61,7 +61,7 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again defect_operational_domain_stats stats{}; const auto defect_influence_domain = defect_operational_domain_quicktrace(cube_lyt, std::vector{create_and_tt()}, 5, params, &stats); - CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, + CHECK_THAT(calculate_defect_clearance(cube_lyt, defect_influence_domain).minimum_defect_clearance, Catch::Matchers::WithinAbs(6.21261176961831474, physical_constants::POP_STABILITY_ERR)); } } From 00977b6258c2ac53540c6b088e0dbd5f32d34b42 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 2 Nov 2024 16:04:29 +0000 Subject: [PATCH 159/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sidb/defect_operational_domain.hpp | 39 ++++++++++++------- .../pyfiction/inout/read_sqd_layout.hpp | 2 +- .../pyfiction/layouts/cartesian_layout.hpp | 2 +- .../defect_influence_operational_domain.hpp | 3 +- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp index 52400425f..1cfb8f837 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -26,14 +26,16 @@ void defect_influence_operational_domain_detail(pybind11::module& m) using namespace pybind11::literals; m.def("defect_operational_domain_grid_search", &fiction::defect_operational_domain_grid_search, "lyt"_a, - "spec"_a, "step_size"_a, "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_defect_operational_domain_grid_search)); + "spec"_a, "step_size"_a, "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr, + DOC(fiction_defect_operational_domain_grid_search)); m.def("defect_operational_domain_random_sampling", &fiction::defect_operational_domain_random_sampling, - "lyt"_a, "spec"_a, "samples"_a, "params"_a = fiction::defect_operational_domain_params{}, - "stats"_a = nullptr, DOC(fiction_defect_operational_domain_random_sampling)); + "lyt"_a, "spec"_a, "samples"_a, "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr, + DOC(fiction_defect_operational_domain_random_sampling)); m.def("defect_operational_domain_quicktrace", &fiction::defect_operational_domain_quicktrace, "lyt"_a, - "spec"_a, "samples"_a, "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr, DOC(fiction_defect_operational_domain_quicktrace)); + "spec"_a, "samples"_a, "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr, + DOC(fiction_defect_operational_domain_quicktrace)); } } // namespace detail @@ -55,21 +57,30 @@ inline void defect_influence_operational_domain(pybind11::module& m) py::class_>(m, "defect_operational_domain_111_cube") .def(py::init<>()); - py::class_(m, "defect_operational_domain_params", DOC(fiction_defect_operational_domain_params)) + py::class_(m, "defect_operational_domain_params", + DOC(fiction_defect_operational_domain_params)) .def(py::init<>()) - .def_readwrite("defect_influence_params", &fiction::defect_operational_domain_params::defect_influence_params, DOC(fiction_defect_operational_domain_params_defect_influence_params)) - .def_readwrite("operational_params", &fiction::defect_operational_domain_params::operational_params, DOC(fiction_defect_operational_domain_params_operational_params)); + .def_readwrite("defect_influence_params", &fiction::defect_operational_domain_params::defect_influence_params, + DOC(fiction_defect_operational_domain_params_defect_influence_params)) + .def_readwrite("operational_params", &fiction::defect_operational_domain_params::operational_params, + DOC(fiction_defect_operational_domain_params_operational_params)); - py::class_(m, "defect_operational_domain_stats", DOC(fiction_defect_operational_domain_stats)) + py::class_(m, "defect_operational_domain_stats", + DOC(fiction_defect_operational_domain_stats)) .def(py::init<>()) - .def_readonly("time_total", &fiction::defect_operational_domain_stats::time_total, DOC(fiction_defect_operational_domain_stats_duration)) - .def_readonly("num_simulator_invocations", &fiction::defect_operational_domain_stats::num_simulator_invocations, DOC(fiction_defect_operational_domain_stats_num_simulator_invocations)) + .def_readonly("time_total", &fiction::defect_operational_domain_stats::time_total, + DOC(fiction_defect_operational_domain_stats_duration)) + .def_readonly("num_simulator_invocations", &fiction::defect_operational_domain_stats::num_simulator_invocations, + DOC(fiction_defect_operational_domain_stats_num_simulator_invocations)) .def_readonly("num_evaluated_parameter_combinations", - &fiction::defect_operational_domain_stats::num_evaluated_defect_positions, DOC(fiction_defect_operational_domain_stats_num_evaluated_defect_positions)) + &fiction::defect_operational_domain_stats::num_evaluated_defect_positions, + DOC(fiction_defect_operational_domain_stats_num_evaluated_defect_positions)) .def_readonly("num_operational_defect_positions", - &fiction::defect_operational_domain_stats::num_operational_defect_positions, DOC(fiction_defect_operational_domain_stats_num_operational_defect_positions)) - .def_readonly("num_non_operational_defect_positions", - &fiction::defect_operational_domain_stats::num_non_operational_defect_positions, DOC(fiction_defect_operational_domain_stats_num_non_operational_defect_positions)); + &fiction::defect_operational_domain_stats::num_operational_defect_positions, + DOC(fiction_defect_operational_domain_stats_num_operational_defect_positions)) + .def_readonly("num_non_operational_defect_positions", + &fiction::defect_operational_domain_stats::num_non_operational_defect_positions, + DOC(fiction_defect_operational_domain_stats_num_non_operational_defect_positions)); // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! detail::defect_influence_operational_domain_detail(m); diff --git a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp index 4e74aa22e..3de2eada4 100644 --- a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp @@ -12,8 +12,8 @@ #include -#include #include +#include namespace pyfiction { diff --git a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp index ba07dafeb..c83854508 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp @@ -15,8 +15,8 @@ #include #include -#include #include +#include namespace pyfiction { diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index da88b30c0..2b0dde008 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -425,8 +425,7 @@ class defect_operational_domain_impl * * @param c Position of the defect. */ - [[nodiscard]] std::optional - has_already_been_sampled(const typename Lyt::cell& c) const noexcept + [[nodiscard]] std::optional has_already_been_sampled(const typename Lyt::cell& c) const noexcept { if (const auto it = defect_op_domain.operational_values.find(c); it != defect_op_domain.operational_values.cend()) From f54a4c44ef14426bd8f419b9ae76faaf03233fb2 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 2 Nov 2024 16:05:29 +0000 Subject: [PATCH 160/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/pybind11_mkdoc_docstrings.hpp | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index 522a02b23..57a57bb22 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -1122,6 +1122,25 @@ static const char *__doc_fiction_bounding_box_2d_x_size = R"doc(The horizontal s static const char *__doc_fiction_bounding_box_2d_y_size = R"doc(The vertical size of the bounding box in layout coordinates.)doc"; +static const char *__doc_fiction_calculate_defect_clearance = +R"doc(Calculates the defect clearance of a given gate layout by a given +atomic defect. This means that a defect must be further away than this +distance for the SiDB gate to be operational. This function requires +both the defect operational domain and the layout as input. + +Template parameter ``Lyt``: + Type representing the SiDB cell-level layout. + +Parameter ``lyt``: + The cell-level layout for which the defect operational domain was + computed. + +Parameter ``defect_opdomain``: + The defect operational domain associated with the layout. + +Returns: + The maximum minimum defect influence distance.)doc"; + static const char *__doc_fiction_calculate_energy_and_state_type = R"doc(This function takes in an SiDB energy distribution. For each charge distribution, the state type is determined (i.e. erroneous, @@ -3774,35 +3793,16 @@ static const char *__doc_fiction_debug_write_dot_layout = R"doc()doc"; static const char *__doc_fiction_debug_write_dot_network = R"doc()doc"; -static const char *__doc_fiction_defect_avoidance_distance = -R"doc(Calculates the defect avoidance distance of a given gate layout by a -given atomic defect. This means that a defect must be further away -than this distance for the SiDB gate to be operational. This function -requires both the defect operational domain and the layout as input. - -Template parameter ``Lyt``: - Type representing the SiDB cell-level layout. - -Parameter ``lyt``: - The cell-level layout for which the defect operational domain was - computed. - -Parameter ``defect_opdomain``: - The defect operational domain associated with the layout. - -Returns: - The maximum minimum defect influence distance.)doc"; - -static const char *__doc_fiction_defect_avoidance_distance_result = -R"doc(Results of the defect avoidance distance calculation. +static const char *__doc_fiction_defect_clearance_result = +R"doc(Results of the defect clearance calculation. Template parameter ``CellType``:)doc"; -static const char *__doc_fiction_defect_avoidance_distance_result_max_distance_postion_of_non_operational_defect = -R"doc(position with maximum distance to the SiDB layout at which the +static const char *__doc_fiction_defect_clearance_result_max_distance_postion_of_non_operational_defect = +R"doc(Position with maximum distance to the SiDB layout at which the placement of an SiDB defect still causes the gate to fail.)doc"; -static const char *__doc_fiction_defect_avoidance_distance_result_minimum_defect_clearance = +static const char *__doc_fiction_defect_clearance_result_minimum_defect_clearance = R"doc(Minimum distance between an SiDB of the gate and the defect at the maximum distance that causes the gate to fail.)doc"; From 0f05a4720c954697702b8aed266e9ca92e2da40b Mon Sep 17 00:00:00 2001 From: Drewniok Date: Sun, 3 Nov 2024 09:23:23 +0100 Subject: [PATCH 161/221] :art: small fix. --- ...aximum_defect_influence_position_and_distance.hpp | 2 +- ..._influence_position_and_distance_of_sidb_gate.cpp | 12 ++++++------ test/utils/math_utils.cpp | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 5206ecfa1..a6d09cbcb 100644 --- a/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -226,7 +226,7 @@ class maximum_defect_influence_position_and_distance_impl /** * Parameters used for the simulation. */ - maximum_defect_influence_position_and_distance_params params{}; + maximum_defect_influence_position_and_distance_params params; /** * The statistics of the maximum defect influence position. */ diff --git a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp index fbf46fd15..bcf39c297 100644 --- a/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp +++ b/test/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.cpp @@ -2,21 +2,21 @@ // Created by Jan Drewniok on 26.06.23. // -#include +#include +#include #include #include "utils/blueprints/layout_blueprints.hpp" -#include #include -#include #include -#include #include -#include -#include +#include #include +#include +#include + using namespace fiction; TEST_CASE("Test influence distance function for Gate") diff --git a/test/utils/math_utils.cpp b/test/utils/math_utils.cpp index 25e8b0a31..c2890c6bf 100644 --- a/test/utils/math_utils.cpp +++ b/test/utils/math_utils.cpp @@ -3,7 +3,6 @@ // #include -#include #include From f1e38d7eef62d632b476b092e06eafaf277641dd Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 4 Nov 2024 13:11:57 +0100 Subject: [PATCH 162/221] :art: print output to fix CI. --- .../test/resources/21_hex_inputsdbp_and_v19.sqd | 4 ++++ .../pyfiction/test/resources/AND_mu_032_111_surface.sqd | 2 +- bindings/pyfiction/test/resources/AND_mu_032_kinks.sqd | 6 +++--- .../hex_11_inputsdbp_inv_straight_v0_manual.sqd | 9 +++++++++ .../pyfiction/test/resources/hex_21_inputsdbp_xor_v1.sqd | 4 ++++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/bindings/pyfiction/test/resources/21_hex_inputsdbp_and_v19.sqd b/bindings/pyfiction/test/resources/21_hex_inputsdbp_and_v19.sqd index c3752f800..51a15b840 100644 --- a/bindings/pyfiction/test/resources/21_hex_inputsdbp_and_v19.sqd +++ b/bindings/pyfiction/test/resources/21_hex_inputsdbp_and_v19.sqd @@ -176,24 +176,28 @@ 2 + logic #ffc8c8c8 2 + logic #ffc8c8c8 2 + logic #ffc8c8c8 2 + logic #ffc8c8c8 diff --git a/bindings/pyfiction/test/resources/AND_mu_032_111_surface.sqd b/bindings/pyfiction/test/resources/AND_mu_032_111_surface.sqd index 6adce8a78..4b5787da4 100644 --- a/bindings/pyfiction/test/resources/AND_mu_032_111_surface.sqd +++ b/bindings/pyfiction/test/resources/AND_mu_032_111_surface.sqd @@ -30,7 +30,7 @@ Overlay 0 0 - 0 + 1 0 diff --git a/bindings/pyfiction/test/resources/AND_mu_032_kinks.sqd b/bindings/pyfiction/test/resources/AND_mu_032_kinks.sqd index 03f8ff537..db20c8f1e 100644 --- a/bindings/pyfiction/test/resources/AND_mu_032_kinks.sqd +++ b/bindings/pyfiction/test/resources/AND_mu_032_kinks.sqd @@ -88,7 +88,7 @@ 2 - + logic #ffc8c8c8 @@ -154,13 +154,13 @@ 2 - + logic #ffc8c8c8 2 - + logic #ffc8c8c8 diff --git a/bindings/pyfiction/test/resources/hex_11_inputsdbp_inv_straight_v0_manual.sqd b/bindings/pyfiction/test/resources/hex_11_inputsdbp_inv_straight_v0_manual.sqd index 9a8df2c3d..97fb5671f 100644 --- a/bindings/pyfiction/test/resources/hex_11_inputsdbp_inv_straight_v0_manual.sqd +++ b/bindings/pyfiction/test/resources/hex_11_inputsdbp_inv_straight_v0_manual.sqd @@ -76,6 +76,7 @@ 2 + logic #ffc8c8c8 @@ -95,6 +96,7 @@ 2 + logic #ffc8c8c8 @@ -114,18 +116,21 @@ 2 + logic #ffc8c8c8 2 + logic #ffc8c8c8 2 + logic #ffc8c8c8 @@ -138,6 +143,7 @@ 2 + logic #ffc8c8c8 @@ -157,6 +163,7 @@ 2 + logic #ffc8c8c8 @@ -169,12 +176,14 @@ 2 + logic #ffc8c8c8 2 + logic #ffc8c8c8 diff --git a/bindings/pyfiction/test/resources/hex_21_inputsdbp_xor_v1.sqd b/bindings/pyfiction/test/resources/hex_21_inputsdbp_xor_v1.sqd index cd801f54f..b8b2bf674 100644 --- a/bindings/pyfiction/test/resources/hex_21_inputsdbp_xor_v1.sqd +++ b/bindings/pyfiction/test/resources/hex_21_inputsdbp_xor_v1.sqd @@ -70,6 +70,7 @@ 2 + logic #ffc8c8c8 @@ -115,6 +116,7 @@ 2 + logic #ffc8c8c8 @@ -127,6 +129,7 @@ 2 + logic #ffc8c8c8 @@ -182,6 +185,7 @@ 2 + logic #ffc8c8c8 From b6b9bc1ad8d1c943be42a78a90413b3965f9346a Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 4 Nov 2024 13:12:09 +0100 Subject: [PATCH 163/221] :art: print output to fix CI. --- .../simulation/sidb/test_defect_operational_domain.py | 3 +++ .../sidb/assess_physical_population_stability.cpp | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py b/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py index d4ff769c3..ccde17c5c 100644 --- a/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py +++ b/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py @@ -20,14 +20,17 @@ def test_xor_gate_100_lattice(self): stats_grid = defect_operational_domain_stats() _ = defect_operational_domain_grid_search(lyt, [create_xor_tt()], 6, params, stats_grid) + print(stats_grid.num_operational_defect_positions) self.assertGreater(stats_grid.num_operational_defect_positions, 0) stats_random = defect_operational_domain_stats() _ = defect_operational_domain_random_sampling(lyt, [create_xor_tt()], 100, params, stats_random) + print(stats_random.num_operational_defect_positions) self.assertGreater(stats_random.num_operational_defect_positions, 0) stats_quicktrace = defect_operational_domain_stats() _ = defect_operational_domain_quicktrace(lyt, [create_xor_tt()], 3, params, stats_quicktrace) + print(stats_quicktrace.num_operational_defect_positions) self.assertGreater(stats_quicktrace.num_operational_defect_positions, 0) if __name__ == '__main__': diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp index 8dfaab87a..438cd5c98 100644 --- a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp +++ b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp @@ -3,15 +3,16 @@ // #include -#include +#include #include #include #include -#include +#include #include +#include +#include #include -#include #include From 3967e2e0e6be9e0b529b3546c8ad2a83cd9e6813 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 4 Nov 2024 13:13:18 +0100 Subject: [PATCH 164/221] :art: integrate Marcel's comment. --- include/fiction/io/write_sqd_layout.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/fiction/io/write_sqd_layout.hpp b/include/fiction/io/write_sqd_layout.hpp index cc8e0af3d..2d23c3f20 100644 --- a/include/fiction/io/write_sqd_layout.hpp +++ b/include/fiction/io/write_sqd_layout.hpp @@ -280,6 +280,13 @@ class write_sqd_layout_impl type_str = fmt::format(siqad::DOT_TYPE, "logic"); break; } + // LCOV_EXCL_START + case (sidb_technology::cell_type::EMPTY): + { + // this case can never happen; it exists to comfort the compilers + break; + } + // LCOV_EXCL_STOP } if constexpr (has_siqad_coord_v) From ee68a733e1605f2d8852688a9f16ecfcb93e09fd Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 4 Nov 2024 13:28:05 +0100 Subject: [PATCH 165/221] :art: small fix in docu. --- docs/algorithms/design_sidb_gates.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/algorithms/design_sidb_gates.rst b/docs/algorithms/design_sidb_gates.rst index 97c431153..7fca26ab3 100644 --- a/docs/algorithms/design_sidb_gates.rst +++ b/docs/algorithms/design_sidb_gates.rst @@ -12,7 +12,6 @@ SiDB Gate Designer .. doxygenstruct:: fiction::design_sidb_gates_params :members: .. doxygenfunction:: fiction::design_sidb_gates - .. doxygenfunction:: fiction::design_sidb_gates_metric_driven_simulated_annealing .. tab:: Python .. autoclass:: mnt.pyfiction.design_sidb_gates_stats From 8e86d53ce758e8546a2e27209df38379d5feb3de Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 4 Nov 2024 14:05:33 +0100 Subject: [PATCH 166/221] :art: rename files. --- .../sidb/defect_operational_domain.hpp | 16 ++++++++-------- .../pyfiction/pybind11_mkdoc_docstrings.hpp | 2 +- bindings/pyfiction/pyfiction.cpp | 2 +- docs/algorithms/sidb_simulation.rst | 4 ++-- docs/io/physical_simulation.rst | 12 ++++++------ .../quicktrace_vs_grid_search_bestagon.cpp | 10 +++++----- .../quicktrace_vs_grid_search_new_gates.cpp | 2 +- .../sidb/defect_avoidance_distance.hpp | 2 +- ..._domain.hpp => defect_operational_domain.hpp} | 8 ++++---- ...n.hpp => write_defect_operational_domain.hpp} | 10 +++++----- .../sidb/defect_influence_operational_domain.cpp | 2 +- 11 files changed, 35 insertions(+), 35 deletions(-) rename include/fiction/algorithms/simulation/sidb/{defect_influence_operational_domain.hpp => defect_operational_domain.hpp} (99%) rename include/fiction/io/{write_defect_influence_operational_domain.hpp => write_defect_operational_domain.hpp} (89%) diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp index 1cfb8f837..b67d8aac3 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -2,13 +2,13 @@ // Created by Jan Drewniok 18.10.2024 // -#ifndef PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP -#define PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP +#ifndef PYFICTION_DEFECT_OPERATIONAL_DOMAIN_HPP +#define PYFICTION_DEFECT_OPERATIONAL_DOMAIN_HPP #include "pyfiction/documentation.hpp" #include "pyfiction/types.hpp" -#include +#include #include #include @@ -21,7 +21,7 @@ namespace detail { template -void defect_influence_operational_domain_detail(pybind11::module& m) +void defect_operational_domain_detail(pybind11::module& m) { using namespace pybind11::literals; @@ -40,7 +40,7 @@ void defect_influence_operational_domain_detail(pybind11::module& m) } // namespace detail -inline void defect_influence_operational_domain(pybind11::module& m) +inline void defect_operational_domain(pybind11::module& m) { namespace py = pybind11; using namespace pybind11::literals; @@ -83,10 +83,10 @@ inline void defect_influence_operational_domain(pybind11::module& m) DOC(fiction_defect_operational_domain_stats_num_non_operational_defect_positions)); // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! - detail::defect_influence_operational_domain_detail(m); - detail::defect_influence_operational_domain_detail(m); + detail::defect_operational_domain_detail(m); + detail::defect_operational_domain_detail(m); } } // namespace pyfiction -#endif // PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP +#endif // PYFICTION_DEFECT_OPERATIONAL_DOMAIN_HPP diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index 57a57bb22..e2ae89905 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -4844,7 +4844,7 @@ Parameter ``step_size``: be checked for being operational. Returns: - A `defect_influence_operational_domain` object representing + A `defect_operational_domain` object representing the operational domain of the defects.)doc"; static const char *__doc_fiction_detail_defect_operational_domain_impl_has_already_been_sampled = diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index ac393ba65..bb192f5fe 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -137,7 +137,7 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::detect_bdl_wires(m); pyfiction::is_operational(m); pyfiction::operational_domain(m); - pyfiction::defect_influence_operational_domain(m); + pyfiction::defect_operational_domain(m); pyfiction::maximum_defect_influence_distance(m); pyfiction::exhaustive_ground_state_simulation(m); pyfiction::quicksim(m); diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index d4b3cf7cd..338e1ec65 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -307,11 +307,11 @@ Defect Influence Operational Domain .. tabs:: .. tab:: C++ - **Header:** ``fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp`` + **Header:** ``fiction/algorithms/simulation/sidb/defect_operational_domain.hpp`` .. doxygenstruct:: fiction::defect_operational_domain_params :members: - .. doxygenstruct:: fiction::defect_influence_operational_domain + .. doxygenstruct:: fiction::defect_operational_domain :members: .. doxygenstruct:: fiction::defect_operational_domain_stats :members: diff --git a/docs/io/physical_simulation.rst b/docs/io/physical_simulation.rst index 2aa9a2841..41a2acd77 100644 --- a/docs/io/physical_simulation.rst +++ b/docs/io/physical_simulation.rst @@ -158,17 +158,17 @@ SiDB Operational Domain .. autofunction:: mnt.pyfiction.write_operational_domain -SiDB Defect Influence Operational Domain -######################################## +SiDB Defect Operational Domain +############################## .. tabs:: .. tab:: C++ - **Header:** ``fiction/io/write_defect_influence_operational_domain.hpp`` + **Header:** ``fiction/io/write_defect_operational_domain.hpp`` - .. doxygenstruct:: fiction::write_defect_influence_operational_domain_params + .. doxygenstruct:: fiction::write_defect_operational_domain_params :members: - .. doxygenfunction:: fiction::write_defect_influence_operational_domain(const operational_domain& opdom, std::ostream& os, const write_defect_influence_operational_domain_params& params = {}) - .. doxygenfunction:: fiction::write_defect_influence_operational_domain(const operational_domain& opdom, const std::string_view& filename, const write_defect_influence_operational_domain_params& params = {}) + .. doxygenfunction:: fiction::write_defect_operational_domain(const operational_domain& opdom, std::ostream& os, const write_defect_operational_domain_params& params = {}) + .. doxygenfunction:: fiction::write_defect_operational_domain(const operational_domain& opdom, const std::string_view& filename, const write_defect_operational_domain_params& params = {}) Technology-independent Gate-level Layouts diff --git a/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp b/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp index fabf23572..533e7d993 100644 --- a/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp +++ b/experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp @@ -1,9 +1,9 @@ #include "fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp" -#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" +#include "fiction/algorithms/simulation/sidb/defect_operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" #include "fiction/io/read_sqd_layout.hpp" -#include "fiction/io/write_defect_influence_operational_domain.hpp" +#include "fiction/io/write_defect_operational_domain.hpp" #include "fiction/io/write_sqd_layout.hpp" #include "fiction/technology/sidb_defects.hpp" #include "fiction/types.hpp" @@ -82,7 +82,7 @@ int main() const auto sqd_path = fmt::format("{}/{}.sqd", gate_folder, gate); // Write the CSV file - write_defect_influence_operational_domain(op_defect_grid, csv_path); + write_defect_operational_domain(op_defect_grid, csv_path); // Write the SQD layout write_sqd_layout(layout, sqd_path); @@ -95,7 +95,7 @@ int main() const auto avoidance_random = calculate_defect_clearance(layout, op_defect_random); const auto csv_path_random = fmt::format("{}{}_random.csv", gate_folder, gate); - write_defect_influence_operational_domain(op_defect_random, csv_path_random); + write_defect_operational_domain(op_defect_random, csv_path_random); defect_operational_domain_stats contour_stats{}; const auto op_defect_contour = @@ -103,7 +103,7 @@ int main() const auto avoidance_contour = calculate_defect_clearance(layout, op_defect_contour); const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate); - write_defect_influence_operational_domain(op_defect_contour, csv_path_contour); + write_defect_operational_domain(op_defect_contour, csv_path_contour); // Log the simulation results simulation_exp(gate, layout.num_cells(), avoidance_grid.max_distance_postion_of_non_operational_defect.x, diff --git a/experiments/quicktrace/quicktrace_vs_grid_search_new_gates.cpp b/experiments/quicktrace/quicktrace_vs_grid_search_new_gates.cpp index 144a8a974..b25077f14 100644 --- a/experiments/quicktrace/quicktrace_vs_grid_search_new_gates.cpp +++ b/experiments/quicktrace/quicktrace_vs_grid_search_new_gates.cpp @@ -1,6 +1,6 @@ #include "fiction/algorithms/physical_design/design_sidb_gates.hpp" #include "fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp" -#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" +#include "fiction/algorithms/simulation/sidb/defect_operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" #include "fiction/io/read_sqd_layout.hpp" diff --git a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp index c08a25d78..051456457 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_avoidance_distance.hpp @@ -5,7 +5,7 @@ #ifndef FICTION_DEFECT_AVOIDANCE_DISTANCE_HPP #define FICTION_DEFECT_AVOIDANCE_DISTANCE_HPP -#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" +#include "fiction/algorithms/simulation/sidb/defect_operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/technology/sidb_nm_distance.hpp" #include "fiction/traits.hpp" diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp similarity index 99% rename from include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp rename to include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp index 2b0dde008..9c107fdd8 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -2,8 +2,8 @@ // Created by Jan Drewniok on 28.12.23. // -#ifndef FICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP -#define FICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP +#ifndef FICTION_DEFECT_OPERATIONAL_DOMAIN_HPP +#define FICTION_DEFECT_OPERATIONAL_DOMAIN_HPP #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" @@ -111,7 +111,7 @@ class defect_operational_domain_impl * * @param step_size The step size used to sample defect positions in the grid. Only positions with x and y * coordinates divisible by `step_size` will be checked for being operational. - * @return A `defect_influence_operational_domain` object representing the operational domain of the defects. + * @return A `defect_operational_domain` object representing the operational domain of the defects. */ [[nodiscard]] defect_operational_domain grid_search(const std::size_t& step_size) noexcept { @@ -779,4 +779,4 @@ defect_operational_domain defect_operational_domain_quicktrace(const Lyt& l } // namespace fiction -#endif // FICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP +#endif // FICTION_DEFECT_OPERATIONAL_DOMAIN_HPP diff --git a/include/fiction/io/write_defect_influence_operational_domain.hpp b/include/fiction/io/write_defect_operational_domain.hpp similarity index 89% rename from include/fiction/io/write_defect_influence_operational_domain.hpp rename to include/fiction/io/write_defect_operational_domain.hpp index cf60a8208..10555e8bf 100644 --- a/include/fiction/io/write_defect_influence_operational_domain.hpp +++ b/include/fiction/io/write_defect_operational_domain.hpp @@ -5,7 +5,7 @@ #ifndef FICTION_WRITE_DEFECT_OPERATIONAL_DOMAIN_HPP #define FICTION_WRITE_DEFECT_OPERATIONAL_DOMAIN_HPP -#include "fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp" +#include "fiction/algorithms/simulation/sidb/defect_operational_domain.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/io/csv_writer.hpp" @@ -17,7 +17,7 @@ namespace fiction { /** - * Parameters for writing a defect influence operational domain to a CSV file. + * Parameters for writing a defect operational domain to a CSV file. */ struct write_defect_operational_domain_params { @@ -49,7 +49,7 @@ struct write_defect_operational_domain_params * empty `write_defect_operational_domain_params` object, which provides standard tags. */ template -inline void write_defect_influence_operational_domain(const defect_operational_domain& defect_opdom, +inline void write_defect_operational_domain(const defect_operational_domain& defect_opdom, std::ostream& os, const write_defect_operational_domain_params& params = {}) { @@ -82,7 +82,7 @@ inline void write_defect_influence_operational_domain(const defect_operational_d * empty `write_defect_operational_domain_params` object, which provides standard tags. */ template -inline void write_defect_influence_operational_domain(const defect_operational_domain& defect_opdom, +inline void write_defect_operational_domain(const defect_operational_domain& defect_opdom, const std::string_view& filename, const write_defect_operational_domain_params& params = {}) { @@ -93,7 +93,7 @@ inline void write_defect_influence_operational_domain(const defect_operational_d throw std::ofstream::failure("could not open file"); } - write_defect_influence_operational_domain(defect_opdom, os, params); + write_defect_operational_domain(defect_opdom, os, params); os.close(); } diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 5a1f3e44b..6fda73df3 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -8,7 +8,7 @@ #include "utils/blueprints/layout_blueprints.hpp" #include -#include +#include #include #include #include From 73160ed42daf6b93d8e5d561ed21f95f85664beb Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Mon, 4 Nov 2024 13:06:39 +0000 Subject: [PATCH 167/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../include/pyfiction/pybind11_mkdoc_docstrings.hpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index e2ae89905..a4d902563 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -4844,8 +4844,8 @@ Parameter ``step_size``: be checked for being operational. Returns: - A `defect_operational_domain` object representing - the operational domain of the defects.)doc"; + A `defect_operational_domain` object representing the + operational domain of the defects.)doc"; static const char *__doc_fiction_detail_defect_operational_domain_impl_has_already_been_sampled = R"doc(This function verifies whether the layout has already been analyzed @@ -18708,7 +18708,7 @@ static const char *__doc_fiction_wiring_reduction_stats_y_size_after = R"doc(Lay static const char *__doc_fiction_wiring_reduction_stats_y_size_before = R"doc(Layout height before the wiring reduction process.)doc"; -static const char *__doc_fiction_write_defect_influence_operational_domain = +static const char *__doc_fiction_write_defect_operational_domain = R"doc(Writes a CSV representation of an operational domain to the specified output stream. The data are written as rows, each corresponding to one set of simulation parameters and their corresponding operational @@ -18738,7 +18738,7 @@ Parameter ``params``: `write_defect_operational_domain_params` object, which provides standard tags.)doc"; -static const char *__doc_fiction_write_defect_influence_operational_domain_2 = +static const char *__doc_fiction_write_defect_operational_domain_2 = R"doc(Writes a CSV representation of an operational domain to the specified file. The data are written as rows, each corresponding to one set of simulation parameters and their corresponding operational status. @@ -18767,9 +18767,7 @@ Parameter ``params``: `write_defect_operational_domain_params` object, which provides standard tags.)doc"; -static const char *__doc_fiction_write_defect_operational_domain_params = -R"doc(Parameters for writing a defect influence operational domain to a CSV -file.)doc"; +static const char *__doc_fiction_write_defect_operational_domain_params = R"doc(Parameters for writing a defect operational domain to a CSV file.)doc"; static const char *__doc_fiction_write_defect_operational_domain_params_non_operational_tag = R"doc(The tag used to represent the non-operational value of a defect From 2785d9ee683d39edab2f2cfb91d3e8fcb55a26a9 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 4 Nov 2024 14:17:04 +0100 Subject: [PATCH 168/221] :art: small clang-tidy fixes. --- include/fiction/io/write_svg_layout.hpp | 36 +++++++++++++------------ 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/include/fiction/io/write_svg_layout.hpp b/include/fiction/io/write_svg_layout.hpp index 9cc4794b3..53606a16e 100644 --- a/include/fiction/io/write_svg_layout.hpp +++ b/include/fiction/io/write_svg_layout.hpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include namespace fiction { @@ -500,9 +502,9 @@ class write_qca_layout_svg_impl cell_descriptions << fmt::format(desc_col.first, desc_col.second, svg::STARTING_OFFSET_TILE_X + svg::STARTING_OFFSET_LATCH_CELL_X + - c.x * svg::CELL_DISTANCE, + (c.x * svg::CELL_DISTANCE), svg::STARTING_OFFSET_TILE_Y + svg::STARTING_OFFSET_LATCH_CELL_Y + - c.y * svg::CELL_DISTANCE); + (c.y * svg::CELL_DISTANCE)); is_sync_elem = true; } @@ -511,14 +513,14 @@ class write_qca_layout_svg_impl { cell_descriptions << fmt::format( desc_col.first, desc_col.second, - svg::STARTING_OFFSET_TILE_X + svg::STARTING_OFFSET_CELL_X + c.x * svg::CELL_DISTANCE, - svg::STARTING_OFFSET_TILE_Y + svg::STARTING_OFFSET_CELL_Y + c.y * svg::CELL_DISTANCE); + svg::STARTING_OFFSET_TILE_X + svg::STARTING_OFFSET_CELL_X + (c.x * svg::CELL_DISTANCE), + svg::STARTING_OFFSET_TILE_Y + svg::STARTING_OFFSET_CELL_Y + (c.y * svg::CELL_DISTANCE)); } } }); - const double viewbox_x = 2 * svg::VIEWBOX_DISTANCE + static_cast(lyt.x() + 1) * svg::CELL_DISTANCE; - const double viewbox_y = 2 * svg::VIEWBOX_DISTANCE + static_cast(lyt.y() + 1) * svg::CELL_DISTANCE; + const double viewbox_x = (2 * svg::VIEWBOX_DISTANCE) + (static_cast(lyt.x() + 1) * svg::CELL_DISTANCE); + const double viewbox_y = (2 * svg::VIEWBOX_DISTANCE) + (static_cast(lyt.y() + 1) * svg::CELL_DISTANCE); os << fmt::format(svg::HEADER, FICTION_VERSION, FICTION_REPO, viewbox_x, viewbox_y, cell_descriptions.str()); } @@ -607,8 +609,8 @@ class write_qca_layout_svg_impl { coord_to_latch_cells[tile_coords] = current_cells.append( fmt::format(desc_col.first, desc_col.second, - svg::STARTING_OFFSET_LATCH_CELL_X + in_tile.x * svg::CELL_DISTANCE, - svg::STARTING_OFFSET_LATCH_CELL_Y + in_tile.y * svg::CELL_DISTANCE)); + svg::STARTING_OFFSET_LATCH_CELL_X + (in_tile.x * svg::CELL_DISTANCE), + svg::STARTING_OFFSET_LATCH_CELL_Y + (in_tile.y * svg::CELL_DISTANCE))); is_sync_elem = true; } @@ -618,8 +620,8 @@ class write_qca_layout_svg_impl { coord_to_cells[tile_coords] = current_cells.append( fmt::format(desc_col.first, desc_col.second, - svg::STARTING_OFFSET_CELL_X + in_tile.x * svg::CELL_DISTANCE, - svg::STARTING_OFFSET_CELL_Y + in_tile.y * svg::CELL_DISTANCE)); + svg::STARTING_OFFSET_CELL_X + (in_tile.x * svg::CELL_DISTANCE), + svg::STARTING_OFFSET_CELL_Y + (in_tile.y * svg::CELL_DISTANCE))); } } }); @@ -674,8 +676,8 @@ class write_qca_layout_svg_impl const auto cell_descriptions = coord_to_cells[coord]; - const double x_pos = svg::STARTING_OFFSET_TILE_X + coord.x * svg::TILE_DISTANCE; - const double y_pos = svg::STARTING_OFFSET_TILE_Y + coord.y * svg::TILE_DISTANCE; + const double x_pos = svg::STARTING_OFFSET_TILE_X + (coord.x * svg::TILE_DISTANCE); + const double y_pos = svg::STARTING_OFFSET_TILE_Y + (coord.y * svg::TILE_DISTANCE); const auto c_descr = fmt::format(descr, x_pos, y_pos, tile_colors[czone], cell_descriptions, @@ -690,12 +692,12 @@ class write_qca_layout_svg_impl for (const auto& [coord, ldscr] : coord_to_latch_tile) { const auto [descr, czone_up, latch_delay] = ldscr; - const auto czone_lo = czone_up + latch_delay % lyt.num_clocks(); + const auto czone_lo = czone_up + (latch_delay % lyt.num_clocks()); const auto cell_descriptions = coord_to_latch_cells[coord]; - const double x_pos = svg::STARTING_OFFSET_LATCH_X + coord.x * svg::TILE_DISTANCE; - const double y_pos = svg::STARTING_OFFSET_LATCH_Y + coord.y * svg::TILE_DISTANCE; + const double x_pos = svg::STARTING_OFFSET_LATCH_X + (coord.x * svg::TILE_DISTANCE); + const double y_pos = svg::STARTING_OFFSET_LATCH_Y + (coord.y * svg::TILE_DISTANCE); const auto t_descr = fmt::format(descr, x_pos, y_pos, tile_colors[czone_lo], tile_colors[czone_up], cell_descriptions, @@ -708,8 +710,8 @@ class write_qca_layout_svg_impl const coordinate length = {(lyt.x() + 1) / lyt.get_tile_size_x(), (lyt.y() + 1) / lyt.get_tile_size_y()}; - const double viewbox_x = 2 * svg::VIEWBOX_DISTANCE + length.x * svg::TILE_DISTANCE; - const double viewbox_y = 2 * svg::VIEWBOX_DISTANCE + length.y * svg::TILE_DISTANCE; + const double viewbox_x = (2 * svg::VIEWBOX_DISTANCE) + (length.x * svg::TILE_DISTANCE); + const double viewbox_y = (2 * svg::VIEWBOX_DISTANCE) + (length.y * svg::TILE_DISTANCE); os << fmt::format(svg::HEADER, FICTION_VERSION, FICTION_REPO, viewbox_x, viewbox_y, tile_descriptions.str()); } From 5a6409d5a21acfdbaffd1a29e7c48ec1bee54571 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 13:17:37 +0000 Subject: [PATCH 169/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/fiction/io/write_defect_operational_domain.hpp | 9 ++++----- include/fiction/io/write_svg_layout.hpp | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/fiction/io/write_defect_operational_domain.hpp b/include/fiction/io/write_defect_operational_domain.hpp index 10555e8bf..567215894 100644 --- a/include/fiction/io/write_defect_operational_domain.hpp +++ b/include/fiction/io/write_defect_operational_domain.hpp @@ -49,9 +49,8 @@ struct write_defect_operational_domain_params * empty `write_defect_operational_domain_params` object, which provides standard tags. */ template -inline void write_defect_operational_domain(const defect_operational_domain& defect_opdom, - std::ostream& os, - const write_defect_operational_domain_params& params = {}) +inline void write_defect_operational_domain(const defect_operational_domain& defect_opdom, std::ostream& os, + const write_defect_operational_domain_params& params = {}) { csv_writer writer{os}; @@ -83,8 +82,8 @@ inline void write_defect_operational_domain(const defect_operational_domain */ template inline void write_defect_operational_domain(const defect_operational_domain& defect_opdom, - const std::string_view& filename, - const write_defect_operational_domain_params& params = {}) + const std::string_view& filename, + const write_defect_operational_domain_params& params = {}) { std::ofstream os{filename.data(), std::ofstream::out}; diff --git a/include/fiction/io/write_svg_layout.hpp b/include/fiction/io/write_svg_layout.hpp index 53606a16e..dd9cfe678 100644 --- a/include/fiction/io/write_svg_layout.hpp +++ b/include/fiction/io/write_svg_layout.hpp @@ -13,7 +13,9 @@ #include #include +#include #include +#include #include #include #include @@ -22,8 +24,6 @@ #include #include #include -#include -#include namespace fiction { From 101d4cf4bee4d3f0d82f5a981b6cde7bf33fc972 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 6 Nov 2024 08:32:09 +0100 Subject: [PATCH 170/221] :art: use one thread to see if that fixes python unit tests in CI. --- .../algorithms/simulation/sidb/defect_operational_domain.hpp | 2 +- ...nce_operational_domain.cpp => defect_operational_domain.cpp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename test/algorithms/simulation/sidb/{defect_influence_operational_domain.cpp => defect_operational_domain.cpp} (100%) diff --git a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp index 9c107fdd8..6e2660331 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -119,7 +119,7 @@ class defect_operational_domain_impl const auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); const std::size_t num_positions = all_possible_defect_positions.size(); - const auto num_threads = std::thread::hardware_concurrency(); // Get the number of hardware threads + const auto num_threads = 1; // Get the number of hardware threads // Determine the chunk size (each thread will process a chunk of positions) std::size_t chunk_size = (num_positions + num_threads - 1) / num_threads; // Distribute positions evenly diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_operational_domain.cpp similarity index 100% rename from test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp rename to test/algorithms/simulation/sidb/defect_operational_domain.cpp From 0477cf80077a1f4ac7bcb5c387ed4f09f6cd67fb Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 6 Nov 2024 09:05:44 +0100 Subject: [PATCH 171/221] :art: try to fix docu. --- docs/algorithms/sidb_simulation.rst | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 338e1ec65..e1f6c496b 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -165,25 +165,6 @@ Temperature Behavior .. autofunction:: mnt.pyfiction.calculate_energy_and_state_type -Maximum Defect Influence Distance -################################# - -**Header:** ``fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp`` - -.. doxygenstruct:: fiction::maximum_defect_influence_position_and_distance_params - :members: -.. doxygenstruct:: fiction::maximum_defect_influence_position_and_distance_stats - :members: -.. doxygenfunction:: fiction::maximum_defect_influence_position_and_distance - - -**Header:** ``fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance_of_sidb_gate.hpp`` - -.. doxygenstruct:: fiction::maximum_defect_influence_position_and_distance_of_sidb_gate_params - :members: -.. doxygenfunction:: fiction::maximum_defect_influence_position_and_distance_of_sidb_gate - - Time-to-Solution (TTS) Statistics ################################# From e125607ef0ee01379b1c47852e87fb1a5c8907b3 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 6 Nov 2024 12:01:09 +0100 Subject: [PATCH 172/221] :sparkles: add function to save defect operational domain. --- .../sidb/defect_operational_domain.hpp | 6 --- .../inout/write_defect_operational_domain.hpp | 53 +++++++++++++++++++ bindings/pyfiction/pyfiction.cpp | 3 ++ .../sidb/defect_operational_domain.hpp | 12 ++--- 4 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 bindings/pyfiction/include/pyfiction/inout/write_defect_operational_domain.hpp diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp index b67d8aac3..1cc8b8945 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -45,12 +45,6 @@ inline void defect_operational_domain(pybind11::module& m) namespace py = pybind11; using namespace pybind11::literals; - py::class_>(m, "defect_operational_domain_100") - .def(py::init<>()); - - py::class_>(m, "defect_operational_domain_111") - .def(py::init<>()); - py::class_>(m, "defect_operational_domain_100_cube") .def(py::init<>()); diff --git a/bindings/pyfiction/include/pyfiction/inout/write_defect_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/inout/write_defect_operational_domain.hpp new file mode 100644 index 000000000..1f214110d --- /dev/null +++ b/bindings/pyfiction/include/pyfiction/inout/write_defect_operational_domain.hpp @@ -0,0 +1,53 @@ +// +// Created by Jan Drewniok on 06.11.2024 +// + +#ifndef PYFICTION_WRITE_DEFECT_OPERATIONAL_DOMAIN_HPP +#define PYFICTION_WRITE_DEFECT_OPERATIONAL_DOMAIN_HPP + +#include "pyfiction/documentation.hpp" +#include "pyfiction/types.hpp" + +#include + +#include + +namespace pyfiction +{ + +namespace detail +{ + +template +inline void write_defect_operational_domain_impl(pybind11::module& m) +{ + namespace py = pybind11; + using namespace py::literals; + + void (*write_defect_operational_domain_pointer)( + const fiction::defect_operational_domain&, const std::string_view&, + const fiction::write_defect_operational_domain_params&) = &fiction::write_defect_operational_domain; + + m.def("write_defect_operational_domain", write_defect_operational_domain_pointer, "opdom"_a, "filename"_a, + "params"_a = fiction::write_defect_operational_domain_params{}); +} + +} + +inline void write_defect_operational_domain(pybind11::module& m) +{ + namespace py = pybind11; + using namespace py::literals; + + py::class_(m, "write_defect_operational_domain_params") + .def(py::init<>()) + .def_readwrite("operational_tag", &fiction::write_defect_operational_domain_params::operational_tag) + .def_readwrite("non_operational_tag", &fiction::write_defect_operational_domain_params::non_operational_tag); + + detail::write_defect_operational_domain_impl(m); + detail::write_defect_operational_domain_impl(m); +} + +} // namespace pyfiction + +#endif // PYFICTION_WRITE_DEFECT_OPERATIONAL_DOMAIN_HPP diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index bb192f5fe..529afce0f 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -59,9 +59,11 @@ #include "pyfiction/inout/read_fgl_layout.hpp" #include "pyfiction/inout/read_fqca_layout.hpp" #include "pyfiction/inout/read_sqd_layout.hpp" +#include "pyfiction/inout/write_defect_operational_domain.hpp" #include "pyfiction/inout/write_dot_layout.hpp" #include "pyfiction/inout/write_fgl_layout.hpp" #include "pyfiction/inout/write_fqca_layout.hpp" +#include "pyfiction/inout/write_defect_operational_domain.hpp" // #include "pyfiction/inout/write_location_and_ground_state.hpp" #include "pyfiction/inout/write_operational_domain.hpp" #include "pyfiction/inout/write_qca_layout.hpp" @@ -217,6 +219,7 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::write_sqd_sim_result(m); // pyfiction::write_location_and_ground_state(m); pyfiction::write_operational_domain(m); + pyfiction::write_defect_operational_domain(m); pyfiction::read_fgl_layout(m); pyfiction::read_fqca_layout(m); pyfiction::read_sqd_layout(m); diff --git a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp index 6e2660331..38291e4c4 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -119,7 +119,7 @@ class defect_operational_domain_impl const auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); const std::size_t num_positions = all_possible_defect_positions.size(); - const auto num_threads = 1; // Get the number of hardware threads + const auto num_threads = std::thread::hardware_concurrency(); // Get the number of hardware threads // Determine the chunk size (each thread will process a chunk of positions) std::size_t chunk_size = (num_positions + num_threads - 1) / num_threads; // Distribute positions evenly @@ -137,19 +137,19 @@ class defect_operational_domain_impl } }; - // Launch multiple threads to process the chunks - std::vector> futures{}; + std::vector threads{}; + threads.reserve(num_threads); for (std::size_t start = 0; start < num_positions; start += chunk_size) { std::size_t end = std::min(start + chunk_size, num_positions); - futures.emplace_back(std::async(std::launch::async, process_chunk, start, end)); + threads.emplace_back(process_chunk, start, end); } // Wait for all threads to complete - for (auto& future : futures) + for (auto& thread : threads) { - future.get(); // Ensure each thread finishes + thread.join(); // Ensure each thread finishes } log_stats(); From 24aae60e89cb7afa1fa18340c94915e2e1702597 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 6 Nov 2024 12:01:57 +0100 Subject: [PATCH 173/221] :thread: replace `future` by `thread` to avoid python 3.13 issues --- .../include/pyfiction/inout/write_operational_domain.hpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/inout/write_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/inout/write_operational_domain.hpp index 5000afbd4..d77da9556 100644 --- a/bindings/pyfiction/include/pyfiction/inout/write_operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/inout/write_operational_domain.hpp @@ -25,9 +25,7 @@ inline void write_operational_domain(pybind11::module& m) .value("ALL_SAMPLES", fiction::write_operational_domain_params::sample_writing_mode::ALL_SAMPLES, DOC(fiction_write_operational_domain_params_sample_writing_mode_ALL_SAMPLES)) .value("OPERATIONAL_ONLY", fiction::write_operational_domain_params::sample_writing_mode::OPERATIONAL_ONLY, - DOC(fiction_write_operational_domain_params_sample_writing_mode_OPERATIONAL_ONLY)) - - ; + DOC(fiction_write_operational_domain_params_sample_writing_mode_OPERATIONAL_ONLY)); py::class_(m, "write_operational_domain_params", DOC(fiction_write_operational_domain_params)) @@ -37,9 +35,7 @@ inline void write_operational_domain(pybind11::module& m) .def_readwrite("non_operational_tag", &fiction::write_operational_domain_params::non_operational_tag, DOC(fiction_write_operational_domain_params_non_operational_tag)) .def_readwrite("writing_mode", &fiction::write_operational_domain_params::writing_mode, - DOC(fiction_write_operational_domain_params_writing_mode)) - - ; + DOC(fiction_write_operational_domain_params_writing_mode)); void (*write_operational_domain_pointer)( const fiction::operational_domain&, From 7702cf06a97e382f77d921203617c41a03bf275b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 6 Nov 2024 11:02:34 +0000 Subject: [PATCH 174/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/pyfiction/inout/write_defect_operational_domain.hpp | 2 +- bindings/pyfiction/pyfiction.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/inout/write_defect_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/inout/write_defect_operational_domain.hpp index 1f214110d..e7b81cfec 100644 --- a/bindings/pyfiction/include/pyfiction/inout/write_defect_operational_domain.hpp +++ b/bindings/pyfiction/include/pyfiction/inout/write_defect_operational_domain.hpp @@ -32,7 +32,7 @@ inline void write_defect_operational_domain_impl(pybind11::module& m) "params"_a = fiction::write_defect_operational_domain_params{}); } -} +} // namespace detail inline void write_defect_operational_domain(pybind11::module& m) { diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index 529afce0f..255f576de 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -63,7 +63,6 @@ #include "pyfiction/inout/write_dot_layout.hpp" #include "pyfiction/inout/write_fgl_layout.hpp" #include "pyfiction/inout/write_fqca_layout.hpp" -#include "pyfiction/inout/write_defect_operational_domain.hpp" // #include "pyfiction/inout/write_location_and_ground_state.hpp" #include "pyfiction/inout/write_operational_domain.hpp" #include "pyfiction/inout/write_qca_layout.hpp" From 830e923d11c6d7c99e85bd731f7b351ce33fb15c Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 6 Nov 2024 13:34:33 +0100 Subject: [PATCH 175/221] :thread: small fix. --- .../algorithms/simulation/sidb/defect_operational_domain.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp index 38291e4c4..0b922979a 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -122,10 +122,10 @@ class defect_operational_domain_impl const auto num_threads = std::thread::hardware_concurrency(); // Get the number of hardware threads // Determine the chunk size (each thread will process a chunk of positions) - std::size_t chunk_size = (num_positions + num_threads - 1) / num_threads; // Distribute positions evenly + const std::size_t chunk_size = (num_positions + num_threads - 1) / num_threads; // Distribute positions evenly // Define a lambda function that processes a chunk of defect positions - auto process_chunk = [&](std::size_t start, std::size_t end) + auto process_chunk = [&](const std::size_t& start, const std::size_t& end) { for (std::size_t i = start; i < end; i += step_size) { From 1ef14c60c77babfe30159f80eb76b5c1474e30ec Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 6 Nov 2024 14:05:02 +0100 Subject: [PATCH 176/221] :thread: small fix. --- .../simulation/sidb/defect_operational_domain.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp index 0b922979a..a017a8c96 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -142,14 +142,17 @@ class defect_operational_domain_impl for (std::size_t start = 0; start < num_positions; start += chunk_size) { - std::size_t end = std::min(start + chunk_size, num_positions); + const std::size_t end = std::min(start + chunk_size, num_positions); threads.emplace_back(process_chunk, start, end); } // Wait for all threads to complete for (auto& thread : threads) { - thread.join(); // Ensure each thread finishes + if (thread.joinable()) + { + thread.join(); + } } log_stats(); From 44ed17b04d34fcf06e6a85ea9a707117ed368be3 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 6 Nov 2024 16:33:54 +0100 Subject: [PATCH 177/221] :thread: use one thread to test CI issues. --- .../algorithms/simulation/sidb/defect_operational_domain.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp index a017a8c96..f29de3d86 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -119,7 +119,7 @@ class defect_operational_domain_impl const auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); const std::size_t num_positions = all_possible_defect_positions.size(); - const auto num_threads = std::thread::hardware_concurrency(); // Get the number of hardware threads + const auto num_threads = 1; // Get the number of hardware threads // Determine the chunk size (each thread will process a chunk of positions) const std::size_t chunk_size = (num_positions + num_threads - 1) / num_threads; // Distribute positions evenly From 350741fa79127a1f47299989bbb13ce7256afa54 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 09:17:44 +0100 Subject: [PATCH 178/221] :thread: use different implementation. --- .../sidb/defect_operational_domain.hpp | 52 +++++++++++-------- .../sidb/defect_operational_domain.cpp | 3 ++ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp index f29de3d86..3c88b8603 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -119,34 +119,42 @@ class defect_operational_domain_impl const auto all_possible_defect_positions = all_coordinates_in_spanned_area(nw_cell, se_cell); const std::size_t num_positions = all_possible_defect_positions.size(); - const auto num_threads = 1; // Get the number of hardware threads + const auto num_threads = std::thread::hardware_concurrency(); // Get the number of hardware threads - // Determine the chunk size (each thread will process a chunk of positions) - const std::size_t chunk_size = (num_positions + num_threads - 1) / num_threads; // Distribute positions evenly - - // Define a lambda function that processes a chunk of defect positions - auto process_chunk = [&](const std::size_t& start, const std::size_t& end) - { - for (std::size_t i = start; i < end; i += step_size) - { - if (static_cast(std::abs(all_possible_defect_positions[i].x)) % step_size == 0 && - static_cast(std::abs(all_possible_defect_positions[i].y)) % step_size == 0) - { - is_defect_position_operational(all_possible_defect_positions[i]); - } - } - }; + // calculate the size of each slice + const auto slice_size = (num_positions + num_threads - 1) / num_threads; std::vector threads{}; threads.reserve(num_threads); - for (std::size_t start = 0; start < num_positions; start += chunk_size) + // launch threads, each with its own slice of random step points + for (auto i = 0ul; i < num_threads; ++i) { - const std::size_t end = std::min(start + chunk_size, num_positions); - threads.emplace_back(process_chunk, start, end); + const auto start = i * slice_size; + const auto end = std::min(start + slice_size, num_positions); + + if (start >= end) + { + break; // no more work to distribute + } + + threads.emplace_back( + [this, start, end, &all_possible_defect_positions, &step_size] + { + for (auto i = start; i < end; ++i) + { + // this ensures that the defects are evenly distributed in a grid-like pattern + if (static_cast(std::abs(all_possible_defect_positions[i].x)) % step_size == + 0 && + static_cast(std::abs(all_possible_defect_positions[i].y)) % step_size == + 0) + { + is_defect_position_operational(all_possible_defect_positions[i]); + } + } + }); } - // Wait for all threads to complete for (auto& thread : threads) { if (thread.joinable()) @@ -489,8 +497,8 @@ class defect_operational_domain_impl */ void log_stats() const noexcept { - stats.num_simulator_invocations = num_simulator_invocations; - stats.num_evaluated_defect_positions = num_evaluated_defect_positions; + stats.num_simulator_invocations = num_simulator_invocations.load(); + stats.num_evaluated_defect_positions = num_evaluated_defect_positions.load(); for (const auto& [param_point, status] : defect_op_domain.operational_values) { diff --git a/test/algorithms/simulation/sidb/defect_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_operational_domain.cpp index 6fda73df3..e8a5aa515 100644 --- a/test/algorithms/simulation/sidb/defect_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_operational_domain.cpp @@ -42,6 +42,9 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again defect_operational_domain_grid_search(cube_lyt, std::vector{create_and_tt()}, 3, params, &stats); CHECK(calculate_defect_clearance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= 6.2126117696183147); + CHECK(stats.num_evaluated_defect_positions == 676); + CHECK(stats.num_operational_defect_positions == 527); + CHECK(stats.num_non_operational_defect_positions == 149); } SECTION("Random Sampling") From 5c8061c71ee49ea2f176675a98b372423c50134b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Nov 2024 08:18:04 +0000 Subject: [PATCH 179/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulation/sidb/defect_operational_domain.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp index 3c88b8603..0537802b9 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -144,10 +144,8 @@ class defect_operational_domain_impl for (auto i = start; i < end; ++i) { // this ensures that the defects are evenly distributed in a grid-like pattern - if (static_cast(std::abs(all_possible_defect_positions[i].x)) % step_size == - 0 && - static_cast(std::abs(all_possible_defect_positions[i].y)) % step_size == - 0) + if (static_cast(std::abs(all_possible_defect_positions[i].x)) % step_size == 0 && + static_cast(std::abs(all_possible_defect_positions[i].y)) % step_size == 0) { is_defect_position_operational(all_possible_defect_positions[i]); } From 7d84d90f8c0f2f1c50790388bc70aa4d5f042641 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 12:40:46 +0100 Subject: [PATCH 180/221] :memo: small fix. --- docs/algorithms/sidb_simulation.rst | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index e1f6c496b..93b2c02c8 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -283,7 +283,7 @@ Operational Domain Computation .. autofunction:: mnt.pyfiction.compute_operational_ratio -Defect Influence Operational Domain +Defect Operational Domain ################################### .. tabs:: @@ -296,25 +296,23 @@ Defect Influence Operational Domain :members: .. doxygenstruct:: fiction::defect_operational_domain_stats :members: - .. doxygenfunction:: fiction::defect_influence_operational_domain_grid_search - .. doxygenfunction:: fiction::defect_influence_operational_domain_random_sampling + .. doxygenfunction:: fiction::defect_operational_domain_grid_search + .. doxygenfunction:: fiction::defect_operational_domain_random_sampling .. doxygenfunction:: fiction::defect_operational_domain_quicktrace .. tab:: Python .. autoclass:: mnt.pyfiction.defect_operational_domain_params :members: - .. autoclass:: mnt.pyfiction.defect_influence_operational_domain_100 + .. autoclass:: mnt.pyfiction.defect_operational_domain_100 :members: - .. autoclass:: mnt.pyfiction.defect_influence_operational_domain_100_cube + .. autoclass:: mnt.pyfiction.defect_operational_domain_100_cube :members: - .. autoclass:: mnt.pyfiction.defect_influence_operational_domain_111 - :members: - .. autoclass:: mnt.pyfiction.defect_influence_operational_domain_111_cube + .. autoclass:: mnt.pyfiction.defect_operational_domain_111_cube :members: .. autoclass:: mnt.pyfiction.defect_operational_domain_stats :members: - .. autofunction:: mnt.pyfiction.defect_influence_operational_domain_grid_search - .. autofunction:: mnt.pyfiction.defect_influence_operational_domain_random_sampling + .. autofunction:: mnt.pyfiction.defect_operational_domain_grid_search + .. autofunction:: mnt.pyfiction.defect_operational_domain_random_sampling .. autofunction:: mnt.pyfiction.defect_operational_domain_quicktrace Determine Physically Valid Parameters From c5b400b1b2538b52d7cc7a1f715766113805a329 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 15:40:08 +0100 Subject: [PATCH 181/221] :memo: small fix. --- docs/io/physical_simulation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/io/physical_simulation.rst b/docs/io/physical_simulation.rst index 41a2acd77..aaaee0c7b 100644 --- a/docs/io/physical_simulation.rst +++ b/docs/io/physical_simulation.rst @@ -167,8 +167,8 @@ SiDB Defect Operational Domain .. doxygenstruct:: fiction::write_defect_operational_domain_params :members: - .. doxygenfunction:: fiction::write_defect_operational_domain(const operational_domain& opdom, std::ostream& os, const write_defect_operational_domain_params& params = {}) - .. doxygenfunction:: fiction::write_defect_operational_domain(const operational_domain& opdom, const std::string_view& filename, const write_defect_operational_domain_params& params = {}) + .. doxygenfunction:: fiction::write_defect_operational_domain(const defect_operational_domain& defect_opdom, std::ostream& os, const write_defect_operational_domain_params& params = {}) + .. doxygenfunction:: fiction::write_defect_operational_domain(const defect_operational_domain& defect_opdom, const std::string_view& filename, const write_defect_operational_domain_params& params = {} Technology-independent Gate-level Layouts From cf63378d2747df518a22b3b7b5094c8cfd044dde Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 15:45:56 +0100 Subject: [PATCH 182/221] :art: small fix. --- .../algorithms/simulation/sidb/defect_operational_domain.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp index 0537802b9..85bceaa39 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -128,9 +128,9 @@ class defect_operational_domain_impl threads.reserve(num_threads); // launch threads, each with its own slice of random step points - for (auto i = 0ul; i < num_threads; ++i) + for (auto t = 0ul; t < num_threads; ++t) { - const auto start = i * slice_size; + const auto start = t * slice_size; const auto end = std::min(start + slice_size, num_positions); if (start >= end) From 4fa497268e29e94d50aa0b450e35405493c4ad58 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 15:57:38 +0100 Subject: [PATCH 183/221] :art: small fix. --- docs/cli.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cli.rst b/docs/cli.rst index c8d0b2110..54122c73a 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -402,7 +402,7 @@ By default, grid search is applied to explore the operational domain. The algori the following options: - ``--random_sampling``/``-r`` - ``--flood_fill``/``-f`` -- ``--quicktrace``/``-c`` +- ``--contour_tracing``/``-c`` each of which start from a set of random samples, whose number has to be passed as an argument to the flag. See ``opdom -h`` for a full list of arguments. From d8c5e38c7904197168077a9e3d30d731de68482d Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 16:33:37 +0100 Subject: [PATCH 184/221] :art: revert changes to understand issue. --- docs/algorithms/sidb_simulation.rst | 62 +++++------------------------ docs/io/physical_simulation.rst | 14 ------- 2 files changed, 11 insertions(+), 65 deletions(-) diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 93b2c02c8..390807ef4 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -165,6 +165,16 @@ Temperature Behavior .. autofunction:: mnt.pyfiction.calculate_energy_and_state_type +Maximum Defect Influence Distance +################################# + +**Header:** ``fiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp`` + +.. doxygenstruct:: fiction::maximum_defect_influence_distance_params + :members: +.. doxygenfunction:: fiction::maximum_defect_influence_position_and_distance + + Time-to-Solution (TTS) Statistics ################################# @@ -283,38 +293,6 @@ Operational Domain Computation .. autofunction:: mnt.pyfiction.compute_operational_ratio -Defect Operational Domain -################################### - -.. tabs:: - .. tab:: C++ - **Header:** ``fiction/algorithms/simulation/sidb/defect_operational_domain.hpp`` - - .. doxygenstruct:: fiction::defect_operational_domain_params - :members: - .. doxygenstruct:: fiction::defect_operational_domain - :members: - .. doxygenstruct:: fiction::defect_operational_domain_stats - :members: - .. doxygenfunction:: fiction::defect_operational_domain_grid_search - .. doxygenfunction:: fiction::defect_operational_domain_random_sampling - .. doxygenfunction:: fiction::defect_operational_domain_quicktrace - - .. tab:: Python - .. autoclass:: mnt.pyfiction.defect_operational_domain_params - :members: - .. autoclass:: mnt.pyfiction.defect_operational_domain_100 - :members: - .. autoclass:: mnt.pyfiction.defect_operational_domain_100_cube - :members: - .. autoclass:: mnt.pyfiction.defect_operational_domain_111_cube - :members: - .. autoclass:: mnt.pyfiction.defect_operational_domain_stats - :members: - .. autofunction:: mnt.pyfiction.defect_operational_domain_grid_search - .. autofunction:: mnt.pyfiction.defect_operational_domain_random_sampling - .. autofunction:: mnt.pyfiction.defect_operational_domain_quicktrace - Determine Physically Valid Parameters ##################################### @@ -324,7 +302,7 @@ Determine Physically Valid Parameters .. doxygenfunction:: fiction::determine_physically_valid_parameters - .. tab:: Python + .. tab:: Python .. autoclass:: mnt.pyfiction.determine_physically_valid_parameters @@ -463,7 +441,6 @@ Assess Population Stability :members: .. doxygenfunction:: fiction::assess_physical_population_stability - .. tab:: Python .. autoclass:: mnt.pyfiction.transition_type :members: @@ -474,13 +451,6 @@ Assess Population Stability .. autofunction:: mnt.pyfiction.assess_physical_population_stability - **Header:** ``fiction/algorithms/simulation/sidb/calculate_min_bbr.hpp`` - - .. doxygenstruct:: fiction::calculate_min_bbr_for_all_inputs_params - :members: - .. doxygenfunction:: fiction::calculate_min_bbr_for_all_inputs - - Convert Potential to Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -492,13 +462,3 @@ Convert Potential to Distance .. tab:: Python .. autofunction:: mnt.pyfiction.convert_potential_to_distance - - -Maximum Minimum Defect Influence Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -**Header:** ``fiction/algorithms/simulation/sidb/calculate_defect_clearance.hpp`` - -.. doxygenstruct:: fiction::defect_clearance_result - :members: -.. doxygenfunction:: fiction::calculate_defect_clearance diff --git a/docs/io/physical_simulation.rst b/docs/io/physical_simulation.rst index aaaee0c7b..69e99db40 100644 --- a/docs/io/physical_simulation.rst +++ b/docs/io/physical_simulation.rst @@ -157,20 +157,6 @@ SiDB Operational Domain :members: .. autofunction:: mnt.pyfiction.write_operational_domain - -SiDB Defect Operational Domain -############################## - -.. tabs:: - .. tab:: C++ - **Header:** ``fiction/io/write_defect_operational_domain.hpp`` - - .. doxygenstruct:: fiction::write_defect_operational_domain_params - :members: - .. doxygenfunction:: fiction::write_defect_operational_domain(const defect_operational_domain& defect_opdom, std::ostream& os, const write_defect_operational_domain_params& params = {}) - .. doxygenfunction:: fiction::write_defect_operational_domain(const defect_operational_domain& defect_opdom, const std::string_view& filename, const write_defect_operational_domain_params& params = {} - - Technology-independent Gate-level Layouts ######################################### From 828e9926733198b3bfb7645404fb956c393cf39c Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 17:21:59 +0100 Subject: [PATCH 185/221] :art: small fix. --- cli/cmd/simulation/opdom.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/cmd/simulation/opdom.hpp b/cli/cmd/simulation/opdom.hpp index ae87b335f..463fb1afa 100644 --- a/cli/cmd/simulation/opdom.hpp +++ b/cli/cmd/simulation/opdom.hpp @@ -73,7 +73,7 @@ class opdom_command : public command "Use random sampling instead of grid search with this many random samples"); add_option("--flood_fill,-f", num_random_samples, "Use flood fill instead of grid search with this many initial random samples"); - add_option("--quicktrace,-c", num_random_samples, + add_option("--contour_tracing,-c", num_random_samples, "Use contour tracing instead of grid search with this many random samples"); add_option("filename", filename, "CSV filename to write the operational domain to")->required(); @@ -150,7 +150,7 @@ class opdom_command : public command } // make sure that at most one algorithm is selected - const std::array algorithm_selections = {is_set("random_sampling"), is_set("flood_fill"), is_set("quicktrace")}; + const std::array algorithm_selections = {is_set("random_sampling"), is_set("flood_fill"), is_set("contour_tracing")}; if (std::count(algorithm_selections.cbegin(), algorithm_selections.cend(), true) > 1) { env->out() << "[e] only one algorithm can be selected at a time" << std::endl; @@ -302,7 +302,7 @@ class opdom_command : public command op_domain = fiction::operational_domain_flood_fill(*lyt_ptr, std::vector{*tt_ptr}, num_random_samples, params, &stats); } - else if (is_set("quicktrace")) + else if (is_set("contour_tracing")) { op_domain = fiction::operational_domain_contour_tracing( *lyt_ptr, std::vector{*tt_ptr}, num_random_samples, params, &stats); From c92a8bf73a79b70b6070fe6460ef91bd686f2a35 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Nov 2024 16:22:43 +0000 Subject: [PATCH 186/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/cmd/simulation/opdom.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/cmd/simulation/opdom.hpp b/cli/cmd/simulation/opdom.hpp index 463fb1afa..e0430bc63 100644 --- a/cli/cmd/simulation/opdom.hpp +++ b/cli/cmd/simulation/opdom.hpp @@ -150,7 +150,8 @@ class opdom_command : public command } // make sure that at most one algorithm is selected - const std::array algorithm_selections = {is_set("random_sampling"), is_set("flood_fill"), is_set("contour_tracing")}; + const std::array algorithm_selections = {is_set("random_sampling"), is_set("flood_fill"), + is_set("contour_tracing")}; if (std::count(algorithm_selections.cbegin(), algorithm_selections.cend(), true) > 1) { env->out() << "[e] only one algorithm can be selected at a time" << std::endl; From 6c1cb6a58350b56ff163155271f02a8784e19f01 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 17:28:31 +0100 Subject: [PATCH 187/221] :arrow_up: use python 3.13 for readthedocs --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index bc4b4adf1..17b7e2578 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -7,7 +7,7 @@ submodules: build: os: ubuntu-22.04 tools: - python: "3.10" + python: 3.13.x apt_packages: - cmake jobs: From 6ff9604d57df070b667e0c00f501d886fa7a89bb Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 17:28:58 +0100 Subject: [PATCH 188/221] :arrow_up: use python 3.13 for readthedocs --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 17b7e2578..cb414b512 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -7,7 +7,7 @@ submodules: build: os: ubuntu-22.04 tools: - python: 3.13.x + python: '3.13.x' apt_packages: - cmake jobs: From aa101cee0233cb5fe7842f2d4315096b0e91bddb Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 17:30:05 +0100 Subject: [PATCH 189/221] :arrow_up: use python 3.13 for readthedocs --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index cb414b512..6827efd47 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -7,7 +7,7 @@ submodules: build: os: ubuntu-22.04 tools: - python: '3.13.x' + python: '3.8.x' apt_packages: - cmake jobs: From 7d03507515bde6cca8e9339a05726b727b78566b Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 17:30:27 +0100 Subject: [PATCH 190/221] :arrow_up: use python 3.8 for readthedocs --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 6827efd47..484dab1bd 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -7,7 +7,7 @@ submodules: build: os: ubuntu-22.04 tools: - python: '3.8.x' + python: 3.8 apt_packages: - cmake jobs: From ba35b533e995de0044008d89b1bc30b564e5b6db Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 7 Nov 2024 17:31:08 +0100 Subject: [PATCH 191/221] :green_heart: use string. --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 484dab1bd..346b970d1 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -7,7 +7,7 @@ submodules: build: os: ubuntu-22.04 tools: - python: 3.8 + python: "3.8" apt_packages: - cmake jobs: From cad11646648b2d6640aba6317a1e7be78735a22e Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 13 Nov 2024 16:57:02 +0100 Subject: [PATCH 192/221] :art: restructure. --- .../pyfiction/layouts/cell_level_layout.hpp | 108 +++++++++++++++++- 1 file changed, 104 insertions(+), 4 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp index 71e738903..fa5130e44 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp @@ -75,7 +75,7 @@ void fcn_technology_cells(pybind11::module& m) } template -void fcn_technology_cell_layout(pybind11::module& m, std::string coordinate_name = "") +void fcn_technology_cell_layout(pybind11::module& m) { namespace py = pybind11; using namespace pybind11::literals; @@ -88,7 +88,7 @@ void fcn_technology_cell_layout(pybind11::module& m, std::string coordinate_name * Cell-level clocked Cartesian layout. */ - py::class_(m, fmt::format("{}_layout{}", tech_name, coordinate_name).c_str(), + py::class_(m, fmt::format("{}_layout", tech_name).c_str(), DOC(fiction_cell_level_layout)) .def(py::init<>()) .def(py::init&>(), "dimension"_a, @@ -174,6 +174,106 @@ void fcn_technology_cell_layout(pybind11::module& m, std::string coordinate_name }); } + +template +void fcn_technology_cell_layout_cube(pybind11::module& m) +{ + namespace py = pybind11; + using namespace pybind11::literals; + + // fetch technology name + auto tech_name = std::string{fiction::tech_impl_name}; + std::transform(tech_name.begin(), tech_name.end(), tech_name.begin(), ::tolower); + + /** + * Cell-level clocked Cartesian layout. + */ + + py::class_(m, fmt::format("{}_layout_cube", tech_name).c_str()) + .def(py::init<>()) + .def(py::init&>(), "dimension"_a, + DOC(fiction_cell_level_layout_cell_level_layout)) + .def(py::init( + [](const fiction::aspect_ratio& dimension, const std::string& scheme_name, + const std::string& layout_name) -> CellLyt + { + if (const auto scheme = fiction::get_clocking_scheme(scheme_name); scheme.has_value()) + { + return CellLyt{dimension, *scheme, layout_name}; + } + + throw std::runtime_error("Given name does not refer to a supported clocking scheme"); + }), + "dimension"_a, "clocking_scheme"_a = "2DDWave", "layout_name"_a = "", + DOC(fiction_cell_level_layout_cell_level_layout_2)) + + .def("assign_cell_type", &CellLyt::assign_cell_type, "c"_a, "ct"_a, + DOC(fiction_cell_level_layout_assign_cell_type)) + .def("get_cell_type", &CellLyt::get_cell_type, "c"_a, DOC(fiction_cell_level_layout_get_cell_type)) + .def("is_empty_cell", &CellLyt::is_empty_cell, "c"_a, DOC(fiction_cell_level_layout_is_empty_cell)) + .def("assign_cell_name", &CellLyt::assign_cell_name, "c"_a, "n"_a, + DOC(fiction_cell_level_layout_assign_cell_name)) + .def("get_cell_name", &CellLyt::get_cell_name, "c"_a, DOC(fiction_cell_level_layout_get_cell_name)) + .def("set_layout_name", &CellLyt::set_layout_name, "name"_a, DOC(fiction_cell_level_layout_set_layout_name)) + .def("get_layout_name", &CellLyt::get_layout_name, DOC(fiction_cell_level_layout_get_layout_name)) + .def("num_cells", &CellLyt::num_cells, DOC(fiction_cell_level_layout_num_cells)) + .def("is_empty", &CellLyt::is_empty, DOC(fiction_cell_level_layout_is_empty)) + .def("num_pis", &CellLyt::num_pis, DOC(fiction_cell_level_layout_num_pis)) + .def("num_pos", &CellLyt::num_pos, DOC(fiction_cell_level_layout_num_pos)) + .def("is_pi", &CellLyt::is_pi, "c"_a, DOC(fiction_cell_level_layout_is_pi)) + .def("is_po", &CellLyt::is_po, "c"_a, DOC(fiction_cell_level_layout_is_po)) + + .def("cells", + [](const CellLyt& lyt) + { + std::vector> cells{}; + cells.reserve(lyt.num_cells()); + lyt.foreach_cell([&cells](const auto& c) { cells.push_back(c); }); + return cells; + }) + .def("pis", + [](const CellLyt& lyt) + { + std::vector> pis{}; + pis.reserve(lyt.num_pis()); + lyt.foreach_pi([&pis](const auto& c) { pis.push_back(c); }); + return pis; + }) + .def("pos", + [](const CellLyt& lyt) + { + std::vector> pos{}; + pos.reserve(lyt.num_pos()); + lyt.foreach_po([&pos](const auto& c) { pos.push_back(c); }); + return pos; + }) + .def( + "bounding_box_2d", + [](const CellLyt& lyt) + { + const auto bb = fiction::bounding_box_2d(lyt); + return std::make_pair(bb.get_min(), bb.get_max()); + }, + DOC(fiction_bounding_box_2d_overridden)) + + .def("__repr__", + [](const CellLyt& lyt) -> std::string + { + std::stringstream stream{}; + + if constexpr (std::is_same_v) + { + print_layout(convert_layout_to_siqad_coordinates(lyt), stream); + } + else + { + print_layout(lyt, stream); + } + + return stream.str(); + }); +} + } // namespace detail inline void cell_level_layouts(pybind11::module& m) @@ -185,8 +285,8 @@ inline void cell_level_layouts(pybind11::module& m) detail::fcn_technology_cell_layout(m); detail::fcn_technology_cell_layout(m); detail::fcn_technology_cell_layout(m); - detail::fcn_technology_cell_layout( - m, "cube"); + detail::fcn_technology_cell_layout_cube( + m); } } // namespace pyfiction From 76cfef14df99a4d2de3e5cd96e308e467ef76ae1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:57:25 +0000 Subject: [PATCH 193/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/pyfiction/layouts/cell_level_layout.hpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp index fa5130e44..ef2ff7c5b 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp @@ -88,8 +88,7 @@ void fcn_technology_cell_layout(pybind11::module& m) * Cell-level clocked Cartesian layout. */ - py::class_(m, fmt::format("{}_layout", tech_name).c_str(), - DOC(fiction_cell_level_layout)) + py::class_(m, fmt::format("{}_layout", tech_name).c_str(), DOC(fiction_cell_level_layout)) .def(py::init<>()) .def(py::init&>(), "dimension"_a, DOC(fiction_cell_level_layout_cell_level_layout)) @@ -174,7 +173,6 @@ void fcn_technology_cell_layout(pybind11::module& m) }); } - template void fcn_technology_cell_layout_cube(pybind11::module& m) { @@ -285,8 +283,8 @@ inline void cell_level_layouts(pybind11::module& m) detail::fcn_technology_cell_layout(m); detail::fcn_technology_cell_layout(m); detail::fcn_technology_cell_layout(m); - detail::fcn_technology_cell_layout_cube( - m); + detail::fcn_technology_cell_layout_cube(m); } } // namespace pyfiction From 15527113c7f8f06a564c55970c506a98012fcf34 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 15 Nov 2024 10:32:25 +0100 Subject: [PATCH 194/221] :arrow_up: use python 3.10 again for readthedocs. --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 346b970d1..bc4b4adf1 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -7,7 +7,7 @@ submodules: build: os: ubuntu-22.04 tools: - python: "3.8" + python: "3.10" apt_packages: - cmake jobs: From c258a8ca9c7ca7df655a41c0eb8ec83247eaa47a Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 18 Nov 2024 08:55:35 +0100 Subject: [PATCH 195/221] :alembic: small fix. --- .../quickcell_vs_automatic_exhaustive_2_input.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/experiments/quickcell/quickcell_vs_automatic_exhaustive_2_input.cpp b/experiments/quickcell/quickcell_vs_automatic_exhaustive_2_input.cpp index 298997f46..e750f6a02 100644 --- a/experiments/quickcell/quickcell_vs_automatic_exhaustive_2_input.cpp +++ b/experiments/quickcell/quickcell_vs_automatic_exhaustive_2_input.cpp @@ -41,10 +41,7 @@ int main() // NOLINT const auto truth_tables = std::vector>{ std::vector{create_and_tt()}, std::vector{create_nand_tt()}, std::vector{create_or_tt()}, - std::vector{create_nor_tt()}, std::vector{create_xor_tt()}, std::vector{create_xnor_tt()}, - std::vector{create_lt_tt()}, std::vector{create_gt_tt()}, std::vector{create_le_tt()}, - std::vector{create_ge_tt()}, create_crossing_wire_tt(), create_half_adder_tt(), - create_double_wire_tt()}; + std::vector{create_nor_tt()}, std::vector{create_xor_tt()}, std::vector{create_xnor_tt()}}; static const std::vector gate_names = {"and", "nand", "or", "nor", "xor", "xnor", "lt", "gt", "le", "ge", "cx", "ha", "hourglass"}; @@ -102,14 +99,12 @@ int main() // NOLINT &stats_automatic_exhaustive_design); } - std::cout << mockturtle::to_seconds(stats_automatic_exhaustive_design.time_total) << '\n'; - std::vector quickcell_design{}; design_sidb_gates_stats stats_quickcell{}; params_2_in_1_out.design_mode = design_sidb_gates_params>::design_sidb_gates_mode::QUICKCELL; - ; + params_2_in_2_out.design_mode = design_sidb_gates_params>::design_sidb_gates_mode::QUICKCELL; From ebb68855437c4b28a3af5f5f038cf2455f612416 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 18 Nov 2024 13:12:46 +0100 Subject: [PATCH 196/221] :alembic: small fix. --- .../quickcell/quickcell_vs_automatic_exhaustive_2_input.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/experiments/quickcell/quickcell_vs_automatic_exhaustive_2_input.cpp b/experiments/quickcell/quickcell_vs_automatic_exhaustive_2_input.cpp index e750f6a02..66bad8c96 100644 --- a/experiments/quickcell/quickcell_vs_automatic_exhaustive_2_input.cpp +++ b/experiments/quickcell/quickcell_vs_automatic_exhaustive_2_input.cpp @@ -18,7 +18,6 @@ #include #include -#include #include #include From bbcad9c849f1adf2bd3149720a59f1836e03c21c Mon Sep 17 00:00:00 2001 From: Drewniok Date: Mon, 18 Nov 2024 18:20:29 +0100 Subject: [PATCH 197/221] :memo: deactivate `exact` to try to solve documentation issue --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index bc4b4adf1..64831e09d 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -13,7 +13,7 @@ build: jobs: pre_build: - echo "Reinstall pyfiction with Z3 enabled" - - z3="ON" python -m pip install --upgrade --upgrade-strategy eager --no-cache-dir .[docs] + - python -m pip install --upgrade --upgrade-strategy eager --no-cache-dir .[docs] sphinx: configuration: docs/conf.py From 12f373da88b49af784a9e1c8b3557cf34116ddb6 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 19 Nov 2024 13:26:03 +0100 Subject: [PATCH 198/221] :memo: try to fix docu issue. --- bindings/pyfiction/pyfiction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index 3d420cfd9..6e5bf2918 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -178,7 +178,7 @@ PYBIND11_MODULE(pyfiction, m, pybind11::mod_gil_not_used()) /** * Algorithms: Physical Design */ - pyfiction::exact(m); + // pyfiction::exact(m); pyfiction::orthogonal(m); pyfiction::graph_oriented_layout_design(m); pyfiction::apply_gate_library(m); From 5a7281056f4e7244df7a63601db2e96a4372f87f Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 19 Nov 2024 12:27:04 +0000 Subject: [PATCH 199/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/pybind11_mkdoc_docstrings.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index 825c586b4..58b151446 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -1122,6 +1122,25 @@ static const char *__doc_fiction_bounding_box_2d_x_size = R"doc(The horizontal s static const char *__doc_fiction_bounding_box_2d_y_size = R"doc(The vertical size of the bounding box in layout coordinates.)doc"; +static const char *__doc_fiction_calculate_defect_clearance = +R"doc(Calculates the defect clearance of a given gate layout by a given +atomic defect. This means that a defect must be further away than this +distance for the SiDB gate to be operational. This function requires +both the defect operational domain and the layout as input. + +Template parameter ``Lyt``: + Type representing the SiDB cell-level layout. + +Parameter ``lyt``: + The cell-level layout for which the defect operational domain was + computed. + +Parameter ``defect_opdomain``: + The defect operational domain associated with the layout. + +Returns: + The maximum minimum defect influence distance.)doc"; + static const char *__doc_fiction_calculate_energy_and_state_type_with_kinks_accepted = R"doc(This function takes in an SiDB energy distribution. For each charge distribution, the state type is determined (i.e. erroneous, From 41159b750ce6513a22fd584ed08bf1f76d5be336 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 19 Nov 2024 13:29:48 +0100 Subject: [PATCH 200/221] :art: include missing header file. --- .../fiction/algorithms/simulation/sidb/operational_domain.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index 1a8d63413..d95e0a9fa 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -5,6 +5,7 @@ #ifndef FICTION_OPERATIONAL_DOMAIN_HPP #define FICTION_OPERATIONAL_DOMAIN_HPP +#include "fiction/algorithms/simulation/sidb/energy_distribution.hpp" #include "fiction/algorithms/simulation/sidb/is_operational.hpp" #include "fiction/algorithms/simulation/sidb/quickexact.hpp" #include "fiction/algorithms/simulation/sidb/quicksim.hpp" From c3dc185f7084788ce35d900c2b77ce6722970da7 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 19 Nov 2024 13:34:18 +0100 Subject: [PATCH 201/221] :memo: small update. --- .../fiction/algorithms/simulation/sidb/operational_domain.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index d95e0a9fa..87e0ada2c 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -344,7 +344,7 @@ class operational_domain_impl * have exactly one output BDL pair. * * @param lyt SiDB cell-level lyt to be evaluated. - * @param spec Expected Boolean function of the lyt given as a multi-output truth table. + * @param tt Expected Boolean function of the lyt given as a multi-output truth table. * @param ps Parameters for the operational domain computation. * @param st Statistics of the process. */ From 639127477974a79569e5e2424c2baf6e747c34d7 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 19 Nov 2024 12:35:14 +0000 Subject: [PATCH 202/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index 58b151446..df9b88e2b 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -7838,7 +7838,7 @@ exactly one output BDL pair. Parameter ``lyt``: SiDB cell-level lyt to be evaluated. -Parameter ``spec``: +Parameter ``tt``: Expected Boolean function of the lyt given as a multi-output truth table. From 4369ae87a9c3e1477975b0d95522267e613c1bd7 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 19 Nov 2024 13:47:00 +0100 Subject: [PATCH 203/221] :white_check_mark: update tests. --- test/algorithms/simulation/sidb/critical_temperature.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/algorithms/simulation/sidb/critical_temperature.cpp b/test/algorithms/simulation/sidb/critical_temperature.cpp index 00eba49e7..fe0bb76df 100644 --- a/test/algorithms/simulation/sidb/critical_temperature.cpp +++ b/test/algorithms/simulation/sidb/critical_temperature.cpp @@ -380,8 +380,6 @@ TEMPLATE_TEST_CASE("Test critical_temperature function", "[critical-temperature] lyt.assign_cell_type({2, 19, 0}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - params.simulation_parameters = sim_params; - params.engine = critical_temperature_params::simulation_engine::EXACT; params.confidence_level = 0.99; params.max_temperature = 350; params.iteration_steps = 80; From 46d99882472b12ecdf2dd3374a3f46b3f034fe23 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:47:24 +0000 Subject: [PATCH 204/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/algorithms/simulation/sidb/critical_temperature.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/algorithms/simulation/sidb/critical_temperature.cpp b/test/algorithms/simulation/sidb/critical_temperature.cpp index fe0bb76df..2a6727095 100644 --- a/test/algorithms/simulation/sidb/critical_temperature.cpp +++ b/test/algorithms/simulation/sidb/critical_temperature.cpp @@ -380,10 +380,10 @@ TEMPLATE_TEST_CASE("Test critical_temperature function", "[critical-temperature] lyt.assign_cell_type({2, 19, 0}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - params.confidence_level = 0.99; - params.max_temperature = 350; - params.iteration_steps = 80; - params.alpha = 0.7; + params.confidence_level = 0.99; + params.max_temperature = 350; + params.iteration_steps = 80; + params.alpha = 0.7; const auto ct = critical_temperature_gate_based(lyt, std::vector{create_crossing_wire_tt()}, params, &critical_stats); From b750c6d88a2be60b23bb9027da85372b2eef08c8 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 19 Nov 2024 13:59:29 +0100 Subject: [PATCH 205/221] :art: use static_cast to use correct type. --- include/fiction/io/write_svg_layout.hpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/fiction/io/write_svg_layout.hpp b/include/fiction/io/write_svg_layout.hpp index 92a20150c..1e07e4fe4 100644 --- a/include/fiction/io/write_svg_layout.hpp +++ b/include/fiction/io/write_svg_layout.hpp @@ -590,15 +590,15 @@ class write_sidb_layout_svg_impl // Shift coordinates for alignment auto shifted_coord = coord; - shifted_coord.x += 1; + shifted_coord.x += static_cast(1); if constexpr (has_siqad_coord_v) { - shifted_coord.y += 1; + shifted_coord.y += static_cast(1); } else { - shifted_coord.y += 2; + shifted_coord.y += static_cast(2); } const auto nm_pos = sidb_nm_position(lyt, shifted_coord); @@ -619,15 +619,15 @@ class write_sidb_layout_svg_impl auto shifted_cell = cell; // shift for padding - shifted_cell.x += 1; + shifted_cell.x += static_cast(1); if constexpr (has_siqad_coord_v) { - shifted_cell.y += 1; + shifted_cell.y += static_cast(1); } else { - shifted_cell.y += 2; + shifted_cell.y += static_cast(2); } const auto nm_pos = sidb_nm_position(lyt, shifted_cell); @@ -649,25 +649,25 @@ class write_sidb_layout_svg_impl // shift for padding - shifted_max.x += 2; + shifted_max.x += static_cast(2); if constexpr (has_siqad_coord_v) { if (shifted_max.z == 1) { - shifted_max.y += 2; + shifted_max.y += static_cast(2); shifted_max.z = 0; } else { - shifted_max.y += 1; + shifted_max.y += static_cast(1); shifted_max.z = 1; } } else { - shifted_max.y += 3; + shifted_max.y += static_cast(3); } // Compute viewBox dimensions From 615fb0db40b7909040b886687b383899ad7e9404 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 19 Nov 2024 14:13:47 +0100 Subject: [PATCH 206/221] :art: static-cast to avoid tpye error. --- .../pyfiction/layouts/cartesian_layout.hpp | 2 +- .../pyfiction/pybind11_mkdoc_docstrings.hpp | 16 +- include/fiction/layouts/cartesian_layout.hpp | 140 +++++++++--------- include/fiction/layouts/hexagonal_layout.hpp | 4 +- test/layouts/cell_level_layout.cpp | 2 +- 5 files changed, 82 insertions(+), 82 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp index c83854508..217fe49c8 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp @@ -113,7 +113,7 @@ inline void cartesian_layout_impl(pybind11::module& m) [](const CartesianLyt& lyt) { std::vector> coords{}; - coords.reserve(lyt.area() * (lyt.z() + 1)); + coords.reserve(lyt.area() * (static_cast(lyt.z() + 1))); lyt.foreach_coordinate([&coords](const auto& c) { coords.push_back(c); }); return coords; }, diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index df9b88e2b..72c08fb9e 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -1293,7 +1293,7 @@ Cartesian grid. Its faces are organized in the following way: +-------+-------+-------+-------+ | | | | | | (0,2) | (1,2) | (2,2) | (3,2) | | | | | | +-------+-------+-------+-------+ \endverbatim -Template parameter ``OffsetCoordinateType``: +Template parameter ``CoordinateType``: The coordinate implementation to be used.)doc"; static const char *__doc_fiction_cartesian_layout_above = @@ -1387,7 +1387,7 @@ static const char *__doc_fiction_cartesian_layout_coord = R"doc(Creates and returns a coordinate in the layout from the given x-, y-, and z-values. -@note This function is equivalent to calling `OffsetCoordinateType(x, +@note This function is equivalent to calling `CoordinateType(x, y, z)`. Template parameter ``X``: @@ -1409,7 +1409,7 @@ Parameter ``z``: z-value. Returns: - A coordinate in the layout of type `OffsetCoordinateType`.)doc"; + A coordinate in the layout of type `CoordinateType`.)doc"; static const char *__doc_fiction_cartesian_layout_coordinates = R"doc(Returns a range of all coordinates accessible in the layout between @@ -8939,7 +8939,7 @@ on a Cartesian coordinate system. It inherits from the `cartesian_layout` class and extends it with specific behavior for finding excess wiring. -Template parameter ``OffsetCoordinateType``: +Template parameter ``CoordinateType``: The type of coordinates used in the layout. Defaults to `offset::ucoord_t` if not explicitly provided.)doc"; @@ -12908,7 +12908,7 @@ coordinates make the most sense here. https://www.redblobgames.com/grids/hexagons/ is a wonderful resource on the topic. -Template parameter ``OffsetCoordinateType``: +Template parameter ``CoordinateType``: The coordinate implementation to be used. Offset coordinates are required. @@ -12996,7 +12996,7 @@ static const char *__doc_fiction_hexagonal_layout_coord = R"doc(Creates and returns a coordinate in the layout from the given x-, y-, and z-values. -@note This function is equivalent to calling `OffsetCoordinateType(x, +@note This function is equivalent to calling `CoordinateType(x, y, z)`. Template parameter ``X``: @@ -13018,7 +13018,7 @@ Parameter ``z``: z-value. Returns: - A coordinate in the layout of type `OffsetCoordinateType`.)doc"; + A coordinate in the layout of type `CoordinateType`.)doc"; static const char *__doc_fiction_hexagonal_layout_coordinates = R"doc(Returns a range of all coordinates accessible in the layout between @@ -16806,7 +16806,7 @@ accordingly: odd_row_cartesian and even_row_cartesian for horizontal shifts and odd_column_cartesian and even_column_cartesian for vertical shifts. All are sketched in ASCII above. -Template parameter ``OffsetCoordinateType``: +Template parameter ``CoordinateType``: The coordinate implementation to be used. Offset coordinates are required. diff --git a/include/fiction/layouts/cartesian_layout.hpp b/include/fiction/layouts/cartesian_layout.hpp index 5706a8ef8..24ecb9d4c 100644 --- a/include/fiction/layouts/cartesian_layout.hpp +++ b/include/fiction/layouts/cartesian_layout.hpp @@ -42,16 +42,16 @@ namespace fiction +-------+-------+-------+-------+ \endverbatim * - * @tparam OffsetCoordinateType The coordinate implementation to be used. + * @tparam CoordinateType The coordinate implementation to be used. */ -template +template class cartesian_layout { public: #pragma region Types and constructors - using coordinate = OffsetCoordinateType; - using aspect_ratio = OffsetCoordinateType; + using coordinate = CoordinateType; + using aspect_ratio = CoordinateType; struct cartesian_layout_storage { @@ -94,7 +94,7 @@ class cartesian_layout /** * Creates and returns a coordinate in the layout from the given x-, y-, and z-values. * - * @note This function is equivalent to calling `OffsetCoordinateType(x, y, z)`. + * @note This function is equivalent to calling `CoordinateType(x, y, z)`. * * @tparam X x-type. * @tparam Y y-type. @@ -102,12 +102,12 @@ class cartesian_layout * @param x x-value. * @param y y-value. * @param z z-value. - * @return A coordinate in the layout of type `OffsetCoordinateType`. + * @return A coordinate in the layout of type `CoordinateType`. */ template - constexpr OffsetCoordinateType coord(const X x, const Y y, const Z z = 0ul) const noexcept + constexpr CoordinateType coord(const X x, const Y y, const Z z = 0ul) const noexcept { - return OffsetCoordinateType(x, y, z); + return CoordinateType(x, y, z); } #pragma endregion @@ -169,7 +169,7 @@ class cartesian_layout * @param c Coordinate whose northern counterpart is desired. * @return Coordinate adjacent and north of `c`. */ - [[nodiscard]] constexpr OffsetCoordinateType north(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] constexpr CoordinateType north(const CoordinateType& c) const noexcept { if (c.y == 0ull) { @@ -189,7 +189,7 @@ class cartesian_layout * @param c Coordinate whose north-eastern counterpart is desired. * @return Coordinate directly north-eastern of `c`. */ - [[nodiscard]] constexpr OffsetCoordinateType north_east(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] constexpr CoordinateType north_east(const CoordinateType& c) const noexcept { if (c.x == x() || c.y == 0ull) { @@ -209,7 +209,7 @@ class cartesian_layout * @param c Coordinate whose eastern counterpart is desired. * @return Coordinate adjacent and east of `c`. */ - [[nodiscard]] OffsetCoordinateType east(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] CoordinateType east(const CoordinateType& c) const noexcept { auto ec = c; @@ -232,7 +232,7 @@ class cartesian_layout * @param c Coordinate whose south-eastern counterpart is desired. * @return Coordinate directly south-eastern of `c`. */ - [[nodiscard]] OffsetCoordinateType south_east(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] CoordinateType south_east(const CoordinateType& c) const noexcept { auto sec = c; @@ -255,7 +255,7 @@ class cartesian_layout * @param c Coordinate whose southern counterpart is desired. * @return Coordinate adjacent and south of `c`. */ - [[nodiscard]] OffsetCoordinateType south(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] CoordinateType south(const CoordinateType& c) const noexcept { auto sc = c; @@ -278,7 +278,7 @@ class cartesian_layout * @param c Coordinate whose south-western counterpart is desired. * @return Coordinate directly south-western of `c`. */ - [[nodiscard]] OffsetCoordinateType south_west(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] CoordinateType south_west(const CoordinateType& c) const noexcept { auto swc = c; @@ -286,7 +286,7 @@ class cartesian_layout { swc.d = 1; } - else if (c.x > 0ull && c.y < y()) + else if (c.x > static_cast< decltype(c.x)>(0) && c.y < y()) { --swc.x; ++swc.y; @@ -301,7 +301,7 @@ class cartesian_layout * @param c Coordinate whose western counterpart is desired. * @return Coordinate adjacent and west of `c`. */ - [[nodiscard]] constexpr OffsetCoordinateType west(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] constexpr CoordinateType west(const CoordinateType& c) const noexcept { if (c.x == 0ull) { @@ -321,7 +321,7 @@ class cartesian_layout * @param c Coordinate whose north-western counterpart is desired. * @return Coordinate directly north-western of `c`. */ - [[nodiscard]] constexpr OffsetCoordinateType north_west(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] constexpr CoordinateType north_west(const CoordinateType& c) const noexcept { if (c.x == 0ull || c.y == 0ull) { @@ -341,7 +341,7 @@ class cartesian_layout * @param c Coordinate whose above counterpart is desired. * @return Coordinate directly above `c`. */ - [[nodiscard]] OffsetCoordinateType above(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] CoordinateType above(const CoordinateType& c) const noexcept { auto ac = c; @@ -363,7 +363,7 @@ class cartesian_layout * @param c Coordinate whose below counterpart is desired. * @return Coordinate directly below `c`. */ - [[nodiscard]] constexpr OffsetCoordinateType below(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] constexpr CoordinateType below(const CoordinateType& c) const noexcept { if (c.z == 0ull) { @@ -382,8 +382,8 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is directly north of `c1`. */ - [[nodiscard]] constexpr bool is_north_of(const OffsetCoordinateType& c1, - const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_north_of(const CoordinateType& c1, + const CoordinateType& c2) const noexcept { return c1 != c2 && north(c1) == c2; } @@ -394,7 +394,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is directly east of `c1`. */ - [[nodiscard]] bool is_east_of(const OffsetCoordinateType& c1, const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] bool is_east_of(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return c1 != c2 && east(c1) == c2; } @@ -405,7 +405,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is directly south of `c1`. */ - [[nodiscard]] bool is_south_of(const OffsetCoordinateType& c1, const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] bool is_south_of(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return c1 != c2 && south(c1) == c2; } @@ -416,8 +416,8 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is directly west of `c1`. */ - [[nodiscard]] constexpr bool is_west_of(const OffsetCoordinateType& c1, - const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_west_of(const CoordinateType& c1, + const CoordinateType& c2) const noexcept { return c1 != c2 && west(c1) == c2; } @@ -428,7 +428,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is either directly north, east, south, or west of `c1`. */ - [[nodiscard]] bool is_adjacent_of(const OffsetCoordinateType& c1, const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] bool is_adjacent_of(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return is_north_of(c1, c2) || is_east_of(c1, c2) || is_south_of(c1, c2) || is_west_of(c1, c2); } @@ -440,8 +440,8 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is either directly north, east, south, or west of `c1` or `c1`'s elevations. */ - [[nodiscard]] bool is_adjacent_elevation_of(const OffsetCoordinateType& c1, - const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] bool is_adjacent_elevation_of(const CoordinateType& c1, + const CoordinateType& c2) const noexcept { return is_adjacent_of(c1, c2) || is_adjacent_of(above(c1), c2) || is_adjacent_of(below(c1), c2); } @@ -452,7 +452,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is directly above `c1`. */ - [[nodiscard]] bool is_above(const OffsetCoordinateType& c1, const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] bool is_above(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return c1 != c2 && above(c1) == c2; } @@ -463,7 +463,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is directly below `c1`. */ - [[nodiscard]] constexpr bool is_below(const OffsetCoordinateType& c1, const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_below(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return c1 != c2 && below(c1) == c2; } @@ -474,8 +474,8 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is somewhere north of `c1`. */ - [[nodiscard]] constexpr bool is_northwards_of(const OffsetCoordinateType& c1, - const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_northwards_of(const CoordinateType& c1, + const CoordinateType& c2) const noexcept { return (c1.z == c2.z) && (c1.y > c2.y) && (c1.x == c2.x); } @@ -486,8 +486,8 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is somewhere east of `c1`. */ - [[nodiscard]] constexpr bool is_eastwards_of(const OffsetCoordinateType& c1, - const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_eastwards_of(const CoordinateType& c1, + const CoordinateType& c2) const noexcept { return (c1.z == c2.z) && (c1.y == c2.y) && (c1.x < c2.x); } @@ -498,8 +498,8 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is somewhere south of `c1`. */ - [[nodiscard]] constexpr bool is_southwards_of(const OffsetCoordinateType& c1, - const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_southwards_of(const CoordinateType& c1, + const CoordinateType& c2) const noexcept { return (c1.z == c2.z) && (c1.y < c2.y) && (c1.x == c2.x); } @@ -510,8 +510,8 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is somewhere west of `c1`. */ - [[nodiscard]] constexpr bool is_westwards_of(const OffsetCoordinateType& c1, - const OffsetCoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_westwards_of(const CoordinateType& c1, + const CoordinateType& c2) const noexcept { return (c1.z == c2.z) && (c1.y == c2.y) && (c1.x > c2.x); } @@ -521,7 +521,7 @@ class cartesian_layout * @param c Coordinate to check for border location. * @return `true` iff `c` is located at the layout's northern border. */ - [[nodiscard]] constexpr bool is_at_northern_border(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] constexpr bool is_at_northern_border(const CoordinateType& c) const noexcept { return c.y == 0ull; } @@ -531,7 +531,7 @@ class cartesian_layout * @param c Coordinate to check for border location. * @return `true` iff `c` is located at the layout's northern border. */ - [[nodiscard]] bool is_at_eastern_border(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] bool is_at_eastern_border(const CoordinateType& c) const noexcept { return c.x == x(); } @@ -541,7 +541,7 @@ class cartesian_layout * @param c Coordinate to check for border location. * @return `true` iff `c` is located at the layout's southern border. */ - [[nodiscard]] bool is_at_southern_border(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] bool is_at_southern_border(const CoordinateType& c) const noexcept { return c.y == y(); } @@ -551,7 +551,7 @@ class cartesian_layout * @param c Coordinate to check for border location. * @return `true` iff `c` is located at the layout's western border. */ - [[nodiscard]] constexpr bool is_at_western_border(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] constexpr bool is_at_western_border(const CoordinateType& c) const noexcept { return c.x == 0ull; } @@ -562,7 +562,7 @@ class cartesian_layout * @param c Coordinate to check for border location. * @return `true` iff `c` is located at any of the layout's borders. */ - [[nodiscard]] bool is_at_any_border(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] bool is_at_any_border(const CoordinateType& c) const noexcept { return is_at_northern_border(c) || is_at_eastern_border(c) || is_at_southern_border(c) || is_at_western_border(c); @@ -574,7 +574,7 @@ class cartesian_layout * @param c Coordinate whose border counterpart is desired. * @return The northern border equivalent of `c`. */ - [[nodiscard]] OffsetCoordinateType northern_border_of(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] CoordinateType northern_border_of(const CoordinateType& c) const noexcept { return {c.x, 0ull, c.z}; } @@ -585,7 +585,7 @@ class cartesian_layout * @param c Coordinate whose border counterpart is desired. * @return The eastern border equivalent of `c`. */ - [[nodiscard]] OffsetCoordinateType eastern_border_of(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] CoordinateType eastern_border_of(const CoordinateType& c) const noexcept { return {x(), c.y, c.z}; } @@ -596,7 +596,7 @@ class cartesian_layout * @param c Coordinate whose border counterpart is desired. * @return The southern border equivalent of `c`. */ - [[nodiscard]] OffsetCoordinateType southern_border_of(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] CoordinateType southern_border_of(const CoordinateType& c) const noexcept { return {c.x, y(), c.z}; } @@ -607,7 +607,7 @@ class cartesian_layout * @param c Coordinate whose border counterpart is desired. * @return The western border equivalent of `c`. */ - [[nodiscard]] OffsetCoordinateType western_border_of(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] CoordinateType western_border_of(const CoordinateType& c) const noexcept { return {0ull, c.y, c.z}; } @@ -617,7 +617,7 @@ class cartesian_layout * @param c Coordinate to check for elevation. * @return `true` iff `c` is in ground layer. */ - [[nodiscard]] constexpr bool is_ground_layer(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] constexpr bool is_ground_layer(const CoordinateType& c) const noexcept { return c.z == decltype(c.z){0}; } @@ -627,7 +627,7 @@ class cartesian_layout * @param c Coordinate to check for elevation. * @return `true` iff `c` is in a crossing layer. */ - [[nodiscard]] constexpr bool is_crossing_layer(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] constexpr bool is_crossing_layer(const CoordinateType& c) const noexcept { return c.z > decltype(c.z){0}; } @@ -637,7 +637,7 @@ class cartesian_layout * @param c Coordinate to check for boundary. * @return `true` iff `c` is located within the layout bounds. */ - [[nodiscard]] constexpr bool is_within_bounds(const OffsetCoordinateType& c) const noexcept + [[nodiscard]] constexpr bool is_within_bounds(const CoordinateType& c) const noexcept { return c.x <= x() && c.y <= y() && c.z <= z(); } @@ -657,10 +657,10 @@ class cartesian_layout * @return An iterator range from `start` to `stop`. If they are not provided, the first/last coordinate is used as * a default. */ - [[nodiscard]] auto coordinates(const OffsetCoordinateType& start = {}, const OffsetCoordinateType& stop = {}) const + [[nodiscard]] auto coordinates(const CoordinateType& start = {}, const CoordinateType& stop = {}) const { return range_t{ - std::make_pair(coord_iterator{strg->dimension, start.is_dead() ? OffsetCoordinateType{0, 0} : start}, + std::make_pair(coord_iterator{strg->dimension, start.is_dead() ? CoordinateType{0, 0} : start}, coord_iterator{strg->dimension, stop.is_dead() ? strg->dimension.get_dead() : stop})}; } /** @@ -673,11 +673,11 @@ class cartesian_layout * @param stop Last coordinate (exclusive) to include in the range of all coordinates. */ template - void foreach_coordinate(Fn&& fn, const OffsetCoordinateType& start = {}, - const OffsetCoordinateType& stop = {}) const + void foreach_coordinate(Fn&& fn, const CoordinateType& start = {}, + const CoordinateType& stop = {}) const { mockturtle::detail::foreach_element( - coord_iterator{strg->dimension, start.is_dead() ? OffsetCoordinateType{0, 0} : start}, + coord_iterator{strg->dimension, start.is_dead() ? CoordinateType{0, 0} : start}, coord_iterator{strg->dimension, stop.is_dead() ? strg->dimension.get_dead() : stop}, fn); } /** @@ -689,15 +689,15 @@ class cartesian_layout * @return An iterator range from `start` to `stop`. If they are not provided, the first/last coordinate in the * ground layer is used as a default. */ - [[nodiscard]] auto ground_coordinates(const OffsetCoordinateType& start = {}, - const OffsetCoordinateType& stop = {}) const + [[nodiscard]] auto ground_coordinates(const CoordinateType& start = {}, + const CoordinateType& stop = {}) const { assert(start.z == 0 && stop.z == 0); const auto ground_layer = aspect_ratio{x(), y(), 0}; return range_t{ - std::make_pair(coord_iterator{ground_layer, start.is_dead() ? OffsetCoordinateType{0, 0} : start}, + std::make_pair(coord_iterator{ground_layer, start.is_dead() ? CoordinateType{0, 0} : start}, coord_iterator{ground_layer, stop.is_dead() ? ground_layer.get_dead() : stop})}; } /** @@ -710,15 +710,15 @@ class cartesian_layout * @param stop Last coordinate (exclusive) to include in the range of all ground coordinates. */ template - void foreach_ground_coordinate(Fn&& fn, const OffsetCoordinateType& start = {}, - const OffsetCoordinateType& stop = {}) const + void foreach_ground_coordinate(Fn&& fn, const CoordinateType& start = {}, + const CoordinateType& stop = {}) const { assert(start.z == 0 && stop.z == 0); const auto ground_layer = aspect_ratio{x(), y(), 0}; mockturtle::detail::foreach_element( - coord_iterator{ground_layer, start.is_dead() ? OffsetCoordinateType{0, 0} : start}, + coord_iterator{ground_layer, start.is_dead() ? CoordinateType{0, 0} : start}, coord_iterator{ground_layer, stop.is_dead() ? ground_layer.get_dead() : stop}, fn); } /** @@ -732,9 +732,9 @@ class cartesian_layout * @param c Coordinate whose adjacent ones are desired. * @return A container that contains all of `c`'s adjacent coordinates. */ - auto adjacent_coordinates(const OffsetCoordinateType& c) const noexcept + auto adjacent_coordinates(const CoordinateType& c) const noexcept { - std::vector cnt{}; + std::vector cnt{}; cnt.reserve(max_fanin_size + 1); // reserve memory foreach_adjacent_coordinate(c, [&cnt](const auto& ac) noexcept { cnt.push_back(ac); }); @@ -752,7 +752,7 @@ class cartesian_layout * @param fn Functor to apply to each of `c`'s adjacent coordinates. */ template - void foreach_adjacent_coordinate(const OffsetCoordinateType& c, Fn&& fn) const + void foreach_adjacent_coordinate(const CoordinateType& c, Fn&& fn) const { const auto apply_if_not_c = [&c, &fn](const auto& cardinal) noexcept { @@ -778,9 +778,9 @@ class cartesian_layout * @param c Coordinate whose opposite ones are desired. * @return A container that contains pairs of `c`'s opposing coordinates. */ - auto adjacent_opposite_coordinates(const OffsetCoordinateType& c) const noexcept + auto adjacent_opposite_coordinates(const CoordinateType& c) const noexcept { - std::vector> cnt{}; + std::vector> cnt{}; cnt.reserve((max_fanin_size + 1) / 2); // reserve memory foreach_adjacent_opposite_coordinates(c, [&cnt](const auto& cp) noexcept { cnt.push_back(cp); }); @@ -796,7 +796,7 @@ class cartesian_layout * @param fn Functor to apply to each of `c`'s opposite adjacent coordinate pairs. */ template - void foreach_adjacent_opposite_coordinates(const OffsetCoordinateType& c, Fn&& fn) const + void foreach_adjacent_opposite_coordinates(const CoordinateType& c, Fn&& fn) const { const auto apply_if_not_c = [&c, &fn](auto cardinal1, auto cardinal2) noexcept { @@ -818,11 +818,11 @@ class cartesian_layout * Initializer for a cartesian layout dimension. When using SiQAD coordinates, it will default the z value to 1 if * the y value is greater than 0. */ - constexpr OffsetCoordinateType initialize_dimension(const OffsetCoordinateType& coord) const + constexpr CoordinateType initialize_dimension(const CoordinateType& coord) const { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) { - return OffsetCoordinateType{coord.x, coord.y, 1}; + return CoordinateType{coord.x, coord.y, 1}; } return coord; diff --git a/include/fiction/layouts/hexagonal_layout.hpp b/include/fiction/layouts/hexagonal_layout.hpp index 3e695105f..c123cfbb3 100644 --- a/include/fiction/layouts/hexagonal_layout.hpp +++ b/include/fiction/layouts/hexagonal_layout.hpp @@ -213,7 +213,7 @@ class hexagonal_layout /** * Creates and returns a coordinate in the layout from the given x-, y-, and z-values. * - * @note This function is equivalent to calling `OffsetCoordinateType(x, y, z)`. + * @note This function is equivalent to calling `CoordinateType(x, y, z)`. * * @tparam X x-type. * @tparam Y y-type. @@ -221,7 +221,7 @@ class hexagonal_layout * @param x x-value. * @param y y-value. * @param z z-value. - * @return A coordinate in the layout of type `OffsetCoordinateType`. + * @return A coordinate in the layout of type `CoordinateType`. */ template constexpr OffsetCoordinateType coord(const X x, const Y y, const Z z = 0ul) const noexcept diff --git a/test/layouts/cell_level_layout.cpp b/test/layouts/cell_level_layout.cpp index 33b905ad8..59507a747 100644 --- a/test/layouts/cell_level_layout.cpp +++ b/test/layouts/cell_level_layout.cpp @@ -16,7 +16,7 @@ using namespace fiction; TEMPLATE_TEST_CASE("Cell-level layout traits", "[cell-level-layout]", qca_cell_clk_lyt, stacked_qca_cell_clk_lyt, - inml_cell_clk_lyt, sidb_100_cell_clk_lyt, sidb_111_cell_clk_lyt) + inml_cell_clk_lyt, sidb_100_cell_clk_lyt, sidb_111_cell_clk_lyt, sidb_111_cell_clk_lyt_siqad, sidb_111_cell_clk_lyt_cube) { CHECK(is_cell_level_layout_v); CHECK(has_foreach_cell_v); From 5f83b49ee01036e308d4d3c5bd908d4d4d1c17bf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:14:20 +0000 Subject: [PATCH 207/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/fiction/layouts/cartesian_layout.hpp | 37 +++++++------------- test/layouts/cell_level_layout.cpp | 3 +- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/include/fiction/layouts/cartesian_layout.hpp b/include/fiction/layouts/cartesian_layout.hpp index 24ecb9d4c..ceaef6515 100644 --- a/include/fiction/layouts/cartesian_layout.hpp +++ b/include/fiction/layouts/cartesian_layout.hpp @@ -286,7 +286,7 @@ class cartesian_layout { swc.d = 1; } - else if (c.x > static_cast< decltype(c.x)>(0) && c.y < y()) + else if (c.x > static_cast(0) && c.y < y()) { --swc.x; ++swc.y; @@ -382,8 +382,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is directly north of `c1`. */ - [[nodiscard]] constexpr bool is_north_of(const CoordinateType& c1, - const CoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_north_of(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return c1 != c2 && north(c1) == c2; } @@ -416,8 +415,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is directly west of `c1`. */ - [[nodiscard]] constexpr bool is_west_of(const CoordinateType& c1, - const CoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_west_of(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return c1 != c2 && west(c1) == c2; } @@ -440,8 +438,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is either directly north, east, south, or west of `c1` or `c1`'s elevations. */ - [[nodiscard]] bool is_adjacent_elevation_of(const CoordinateType& c1, - const CoordinateType& c2) const noexcept + [[nodiscard]] bool is_adjacent_elevation_of(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return is_adjacent_of(c1, c2) || is_adjacent_of(above(c1), c2) || is_adjacent_of(below(c1), c2); } @@ -474,8 +471,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is somewhere north of `c1`. */ - [[nodiscard]] constexpr bool is_northwards_of(const CoordinateType& c1, - const CoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_northwards_of(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return (c1.z == c2.z) && (c1.y > c2.y) && (c1.x == c2.x); } @@ -486,8 +482,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is somewhere east of `c1`. */ - [[nodiscard]] constexpr bool is_eastwards_of(const CoordinateType& c1, - const CoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_eastwards_of(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return (c1.z == c2.z) && (c1.y == c2.y) && (c1.x < c2.x); } @@ -498,8 +493,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is somewhere south of `c1`. */ - [[nodiscard]] constexpr bool is_southwards_of(const CoordinateType& c1, - const CoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_southwards_of(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return (c1.z == c2.z) && (c1.y < c2.y) && (c1.x == c2.x); } @@ -510,8 +504,7 @@ class cartesian_layout * @param c2 Coordinate to test for its location in relation to `c1`. * @return `true` iff `c2` is somewhere west of `c1`. */ - [[nodiscard]] constexpr bool is_westwards_of(const CoordinateType& c1, - const CoordinateType& c2) const noexcept + [[nodiscard]] constexpr bool is_westwards_of(const CoordinateType& c1, const CoordinateType& c2) const noexcept { return (c1.z == c2.z) && (c1.y == c2.y) && (c1.x > c2.x); } @@ -673,8 +666,7 @@ class cartesian_layout * @param stop Last coordinate (exclusive) to include in the range of all coordinates. */ template - void foreach_coordinate(Fn&& fn, const CoordinateType& start = {}, - const CoordinateType& stop = {}) const + void foreach_coordinate(Fn&& fn, const CoordinateType& start = {}, const CoordinateType& stop = {}) const { mockturtle::detail::foreach_element( coord_iterator{strg->dimension, start.is_dead() ? CoordinateType{0, 0} : start}, @@ -689,16 +681,14 @@ class cartesian_layout * @return An iterator range from `start` to `stop`. If they are not provided, the first/last coordinate in the * ground layer is used as a default. */ - [[nodiscard]] auto ground_coordinates(const CoordinateType& start = {}, - const CoordinateType& stop = {}) const + [[nodiscard]] auto ground_coordinates(const CoordinateType& start = {}, const CoordinateType& stop = {}) const { assert(start.z == 0 && stop.z == 0); const auto ground_layer = aspect_ratio{x(), y(), 0}; - return range_t{ - std::make_pair(coord_iterator{ground_layer, start.is_dead() ? CoordinateType{0, 0} : start}, - coord_iterator{ground_layer, stop.is_dead() ? ground_layer.get_dead() : stop})}; + return range_t{std::make_pair(coord_iterator{ground_layer, start.is_dead() ? CoordinateType{0, 0} : start}, + coord_iterator{ground_layer, stop.is_dead() ? ground_layer.get_dead() : stop})}; } /** * Applies a function to all coordinates accessible in the layout's ground layer between `start` and `stop`. The @@ -710,8 +700,7 @@ class cartesian_layout * @param stop Last coordinate (exclusive) to include in the range of all ground coordinates. */ template - void foreach_ground_coordinate(Fn&& fn, const CoordinateType& start = {}, - const CoordinateType& stop = {}) const + void foreach_ground_coordinate(Fn&& fn, const CoordinateType& start = {}, const CoordinateType& stop = {}) const { assert(start.z == 0 && stop.z == 0); diff --git a/test/layouts/cell_level_layout.cpp b/test/layouts/cell_level_layout.cpp index 59507a747..c7b705f89 100644 --- a/test/layouts/cell_level_layout.cpp +++ b/test/layouts/cell_level_layout.cpp @@ -16,7 +16,8 @@ using namespace fiction; TEMPLATE_TEST_CASE("Cell-level layout traits", "[cell-level-layout]", qca_cell_clk_lyt, stacked_qca_cell_clk_lyt, - inml_cell_clk_lyt, sidb_100_cell_clk_lyt, sidb_111_cell_clk_lyt, sidb_111_cell_clk_lyt_siqad, sidb_111_cell_clk_lyt_cube) + inml_cell_clk_lyt, sidb_100_cell_clk_lyt, sidb_111_cell_clk_lyt, sidb_111_cell_clk_lyt_siqad, + sidb_111_cell_clk_lyt_cube) { CHECK(is_cell_level_layout_v); CHECK(has_foreach_cell_v); From aecc06a6612df9016def4c8d19445e555657cd39 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 19 Nov 2024 13:15:16 +0000 Subject: [PATCH 208/221] :memo: Update pyfiction docstrings Signed-off-by: GitHub Actions --- .../pyfiction/pybind11_mkdoc_docstrings.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp index 72c08fb9e..491936a76 100644 --- a/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp +++ b/bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp @@ -1387,8 +1387,8 @@ static const char *__doc_fiction_cartesian_layout_coord = R"doc(Creates and returns a coordinate in the layout from the given x-, y-, and z-values. -@note This function is equivalent to calling `CoordinateType(x, -y, z)`. +@note This function is equivalent to calling `CoordinateType(x, y, +z)`. Template parameter ``X``: x-type. @@ -8939,7 +8939,7 @@ on a Cartesian coordinate system. It inherits from the `cartesian_layout` class and extends it with specific behavior for finding excess wiring. -Template parameter ``CoordinateType``: +Template parameter ``OffsetCoordinateType``: The type of coordinates used in the layout. Defaults to `offset::ucoord_t` if not explicitly provided.)doc"; @@ -12908,7 +12908,7 @@ coordinates make the most sense here. https://www.redblobgames.com/grids/hexagons/ is a wonderful resource on the topic. -Template parameter ``CoordinateType``: +Template parameter ``OffsetCoordinateType``: The coordinate implementation to be used. Offset coordinates are required. @@ -12996,8 +12996,8 @@ static const char *__doc_fiction_hexagonal_layout_coord = R"doc(Creates and returns a coordinate in the layout from the given x-, y-, and z-values. -@note This function is equivalent to calling `CoordinateType(x, -y, z)`. +@note This function is equivalent to calling `CoordinateType(x, y, +z)`. Template parameter ``X``: x-type. @@ -16806,7 +16806,7 @@ accordingly: odd_row_cartesian and even_row_cartesian for horizontal shifts and odd_column_cartesian and even_column_cartesian for vertical shifts. All are sketched in ASCII above. -Template parameter ``CoordinateType``: +Template parameter ``OffsetCoordinateType``: The coordinate implementation to be used. Offset coordinates are required. From fd13dbee3dc0536d8fd0a6a15e35e0ea3fa1145a Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 21 Nov 2024 14:04:53 +0100 Subject: [PATCH 209/221] :art: small fix. --- docs/io/visualization.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/io/visualization.rst b/docs/io/visualization.rst index 1f4c7022a..ba9bdb9b3 100644 --- a/docs/io/visualization.rst +++ b/docs/io/visualization.rst @@ -50,9 +50,6 @@ SVG Images .. doxygenclass:: fiction::unsupported_cell_type_exception - .. doxygenenum:: fiction::color_mode - :members: - .. doxygenstruct:: fiction::write_sidb_layout_svg_params :members: From e03f175a0b6463e682e48747073bcff0b7b49abf Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 21 Nov 2024 14:11:27 +0100 Subject: [PATCH 210/221] :memo: small fix. --- bindings/pyfiction/pyfiction.cpp | 2 +- docs/algorithms/sidb_simulation.rst | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index 6e5bf2918..3d420cfd9 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -178,7 +178,7 @@ PYBIND11_MODULE(pyfiction, m, pybind11::mod_gil_not_used()) /** * Algorithms: Physical Design */ - // pyfiction::exact(m); + pyfiction::exact(m); pyfiction::orthogonal(m); pyfiction::graph_oriented_layout_design(m); pyfiction::apply_gate_library(m); diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 132f27051..6860ef351 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -153,7 +153,8 @@ Temperature Behavior .. doxygenfunction:: fiction::calculate_energy_and_state_type_with_kinks_rejected .. tab:: Python - .. autoclass:: mnt.pyfiction.simulation_engine + + .. autoclass:: mnt.pyfiction.critical_temperature_stats :members: .. autoclass:: mnt.pyfiction.critical_temperature_params :members: @@ -450,11 +451,14 @@ Assess Population Stability .. tab:: Python .. autoclass:: mnt.pyfiction.transition_type :members: - .. autoclass:: mnt.pyfiction.population_stability_information + .. autoclass:: mnt.pyfiction.population_stability_information_100 + :members: + .. autoclass:: mnt.pyfiction.population_stability_information_111 :members: .. autoclass:: mnt.pyfiction.assess_physical_population_stability_params :members: - .. autofunction:: mnt.pyfiction.assess_physical_population_stability + .. autofunction:: mnt.pyfiction.assess_physical_population_stability_100 + .. autofunction:: mnt.pyfiction.assess_physical_population_stability_111 Convert Potential to Distance From c4291ebd8f83eb2dedb4b7a99a2769119e75774e Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 22 Nov 2024 08:15:05 +0100 Subject: [PATCH 211/221] :white_check_mark: small fix. --- test/algorithms/simulation/sidb/critical_temperature.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/algorithms/simulation/sidb/critical_temperature.cpp b/test/algorithms/simulation/sidb/critical_temperature.cpp index 2a6727095..969904f9a 100644 --- a/test/algorithms/simulation/sidb/critical_temperature.cpp +++ b/test/algorithms/simulation/sidb/critical_temperature.cpp @@ -380,6 +380,7 @@ TEMPLATE_TEST_CASE("Test critical_temperature function", "[critical-temperature] lyt.assign_cell_type({2, 19, 0}, sidb_technology::cell_type::NORMAL); lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); + params.operational_params.simulation_parameters = sim_params; params.confidence_level = 0.99; params.max_temperature = 350; params.iteration_steps = 80; From ca59bba58f363f706e57446ff1d8fd592a65fcb2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2024 07:19:51 +0000 Subject: [PATCH 212/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/algorithms/simulation/sidb/critical_temperature.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/algorithms/simulation/sidb/critical_temperature.cpp b/test/algorithms/simulation/sidb/critical_temperature.cpp index 969904f9a..d0c17883e 100644 --- a/test/algorithms/simulation/sidb/critical_temperature.cpp +++ b/test/algorithms/simulation/sidb/critical_temperature.cpp @@ -381,10 +381,10 @@ TEMPLATE_TEST_CASE("Test critical_temperature function", "[critical-temperature] lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); params.operational_params.simulation_parameters = sim_params; - params.confidence_level = 0.99; - params.max_temperature = 350; - params.iteration_steps = 80; - params.alpha = 0.7; + params.confidence_level = 0.99; + params.max_temperature = 350; + params.iteration_steps = 80; + params.alpha = 0.7; const auto ct = critical_temperature_gate_based(lyt, std::vector{create_crossing_wire_tt()}, params, &critical_stats); From b90070bdf076ad3223797c83e3e0901995b3a107 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 22 Nov 2024 08:40:55 +0100 Subject: [PATCH 213/221] :memo: small fix. --- .../pyfiction/include/pyfiction/inout/read_sqd_layout.hpp | 5 +++-- docs/algorithms/sidb_simulation.rst | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp index 3de2eada4..ccf18e026 100644 --- a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp @@ -27,8 +27,6 @@ void read_sqd_layout(pybind11::module& m, std::string lattice_orientation, std:: namespace py = pybind11; using namespace py::literals; - py::register_exception(m, "sqd_parsing_error", PyExc_RuntimeError); - // Common function pointer for all cases Lyt (*read_sqd_layout_function_pointer)(const std::string_view&, const std::string_view&) = &fiction::read_sqd_layout; @@ -41,6 +39,9 @@ void read_sqd_layout(pybind11::module& m, std::string lattice_orientation, std:: inline void read_sqd_layout(pybind11::module& m) { + namespace py = pybind11; + py::register_exception(m, "sqd_parsing_error", PyExc_RuntimeError); + detail::read_sqd_layout(m, "100", ""); detail::read_sqd_layout(m, "111", ""); detail::read_sqd_layout(m, "100", "_cube"); diff --git a/docs/algorithms/sidb_simulation.rst b/docs/algorithms/sidb_simulation.rst index 6860ef351..ee7970a40 100644 --- a/docs/algorithms/sidb_simulation.rst +++ b/docs/algorithms/sidb_simulation.rst @@ -453,7 +453,7 @@ Assess Population Stability :members: .. autoclass:: mnt.pyfiction.population_stability_information_100 :members: - .. autoclass:: mnt.pyfiction.population_stability_information_111 + .. autoclass:: mnt.pyfiction.population_stability_information_111 :members: .. autoclass:: mnt.pyfiction.assess_physical_population_stability_params :members: From 53f137130741203f90bdce3b44acb51075ddeb91 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 22 Nov 2024 09:29:09 +0100 Subject: [PATCH 214/221] :memo: revert changes in the workflow. --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 64831e09d..bc4b4adf1 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -13,7 +13,7 @@ build: jobs: pre_build: - echo "Reinstall pyfiction with Z3 enabled" - - python -m pip install --upgrade --upgrade-strategy eager --no-cache-dir .[docs] + - z3="ON" python -m pip install --upgrade --upgrade-strategy eager --no-cache-dir .[docs] sphinx: configuration: docs/conf.py From 4e7c38fb1c20bc30028345db184cf03d04fe2d3c Mon Sep 17 00:00:00 2001 From: Drewniok Date: Fri, 22 Nov 2024 09:34:15 +0100 Subject: [PATCH 215/221] :memo: try to fix docu. --- bindings/pyfiction/pyfiction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index 3d420cfd9..eebefe97f 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -134,7 +134,7 @@ PYBIND11_MODULE(pyfiction, m, pybind11::mod_gil_not_used()) pyfiction::sidb_simulation_parameters(m); pyfiction::sidb_simulation_result(m); pyfiction::can_positive_charges_occur(m); - pyfiction::assess_physical_population_stability(m); + //pyfiction::assess_physical_population_stability(m); pyfiction::convert_potential_to_distance(m); pyfiction::detect_bdl_pairs(m); pyfiction::detect_bdl_wires(m); From 941e9ae192c03af3ef30e1a1f052310c08de8fa8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2024 08:34:34 +0000 Subject: [PATCH 216/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bindings/pyfiction/pyfiction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index eebefe97f..687c2959b 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -134,7 +134,7 @@ PYBIND11_MODULE(pyfiction, m, pybind11::mod_gil_not_used()) pyfiction::sidb_simulation_parameters(m); pyfiction::sidb_simulation_result(m); pyfiction::can_positive_charges_occur(m); - //pyfiction::assess_physical_population_stability(m); + // pyfiction::assess_physical_population_stability(m); pyfiction::convert_potential_to_distance(m); pyfiction::detect_bdl_pairs(m); pyfiction::detect_bdl_wires(m); From f7e9ed087e3f4e207b2724492058865e529deb59 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Nov 2024 15:29:43 +0000 Subject: [PATCH 217/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../determine_physically_valid_parameters.hpp | 3 ++- include/fiction/io/write_svg_layout.hpp | 18 +++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp b/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp index 62ffa2693..e1a1a30d0 100644 --- a/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp +++ b/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp @@ -28,7 +28,8 @@ void determine_physically_valid_parameters(pybind11::module& m) namespace py = pybind11; m.def("determine_physically_valid_parameters", &fiction::determine_physically_valid_parameters, "cds"_a, - py::args("params") = fiction::operational_domain_params{}, DOC(fiction_determine_physically_valid_parameters)); + py::args("params") = fiction::operational_domain_params{}, + DOC(fiction_determine_physically_valid_parameters)); } } // namespace detail diff --git a/include/fiction/io/write_svg_layout.hpp b/include/fiction/io/write_svg_layout.hpp index 3419251fb..573b4863f 100644 --- a/include/fiction/io/write_svg_layout.hpp +++ b/include/fiction/io/write_svg_layout.hpp @@ -610,16 +610,16 @@ class write_sidb_layout_svg_impl // Shift coordinates for alignment auto shifted_coord = coord; - shifted_coord.x += static_cast(1); + shifted_coord.x += static_cast(1); - if constexpr (has_siqad_coord_v) - { - shifted_coord.y += static_cast(1); - } - else - { - shifted_coord.y += static_cast(2); - } + if constexpr (has_siqad_coord_v) + { + shifted_coord.y += static_cast(1); + } + else + { + shifted_coord.y += static_cast(2); + } const auto nm_pos = sidb_nm_position(lyt, shifted_coord); From e429443e7197e31fde291612fd7f37c010da6f3a Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 28 Nov 2024 16:33:13 +0100 Subject: [PATCH 218/221] :fire: remove python bindings for the moment due to doc issue. --- .../determine_physically_valid_parameters.hpp | 2 +- .../inout/write_operational_domain.hpp | 8 ++- .../pyfiction/layouts/clocked_layout.hpp | 7 +-- .../mnt/pyfiction/include/pyfiction/types.hpp | 50 ++++--------------- bindings/mnt/pyfiction/pyfiction.cpp | 32 ++++++------ .../sidb/test_defect_operational_domain.py | 0 6 files changed, 32 insertions(+), 67 deletions(-) delete mode 100644 bindings/mnt/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py diff --git a/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp b/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp index 62ffa2693..d41e8c0a3 100644 --- a/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp +++ b/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp @@ -27,7 +27,7 @@ void determine_physically_valid_parameters(pybind11::module& m) { namespace py = pybind11; - m.def("determine_physically_valid_parameters", &fiction::determine_physically_valid_parameters, "cds"_a, + m.def("determine_physically_valid_parameters", &fiction::determine_physically_valid_parameters, py::arfs("cds"), py::args("params") = fiction::operational_domain_params{}, DOC(fiction_determine_physically_valid_parameters)); } diff --git a/bindings/mnt/pyfiction/include/pyfiction/inout/write_operational_domain.hpp b/bindings/mnt/pyfiction/include/pyfiction/inout/write_operational_domain.hpp index aa10366cc..c3ddd718c 100644 --- a/bindings/mnt/pyfiction/include/pyfiction/inout/write_operational_domain.hpp +++ b/bindings/mnt/pyfiction/include/pyfiction/inout/write_operational_domain.hpp @@ -24,7 +24,9 @@ inline void write_operational_domain(pybind11::module& m) .value("ALL_SAMPLES", fiction::write_operational_domain_params::sample_writing_mode::ALL_SAMPLES, DOC(fiction_write_operational_domain_params_sample_writing_mode_ALL_SAMPLES)) .value("OPERATIONAL_ONLY", fiction::write_operational_domain_params::sample_writing_mode::OPERATIONAL_ONLY, - DOC(fiction_write_operational_domain_params_sample_writing_mode_OPERATIONAL_ONLY)); + DOC(fiction_write_operational_domain_params_sample_writing_mode_OPERATIONAL_ONLY)) + + ; py::class_(m, "write_operational_domain_params", DOC(fiction_write_operational_domain_params)) @@ -34,7 +36,9 @@ inline void write_operational_domain(pybind11::module& m) .def_readwrite("non_operational_tag", &fiction::write_operational_domain_params::non_operational_tag, DOC(fiction_write_operational_domain_params_non_operational_tag)) .def_readwrite("writing_mode", &fiction::write_operational_domain_params::writing_mode, - DOC(fiction_write_operational_domain_params_writing_mode)); + DOC(fiction_write_operational_domain_params_writing_mode)) + + ; void (*write_operational_domain_pointer)( const fiction::operational_domain&, diff --git a/bindings/mnt/pyfiction/include/pyfiction/layouts/clocked_layout.hpp b/bindings/mnt/pyfiction/include/pyfiction/layouts/clocked_layout.hpp index cbef6fc97..f1ef83dae 100644 --- a/bindings/mnt/pyfiction/include/pyfiction/layouts/clocked_layout.hpp +++ b/bindings/mnt/pyfiction/include/pyfiction/layouts/clocked_layout.hpp @@ -25,16 +25,14 @@ namespace detail { template -void clocked_layout(pybind11::module& m, const std::string& topology, const std::string& coordinate_type = "") +void clocked_layout(pybind11::module& m, const std::string& topology) { namespace py = pybind11; - namespace py = pybind11; /** * Clocked Cartesian layout. */ - py::class_(m, fmt::format("clocked_{}_layout{}", topology, coordinate_type).c_str(), - DOC(fiction_clocked_layout)) + py::class_(m, fmt::format("clocked_{}_layout", topology).c_str(), DOC(fiction_clocked_layout)) .def(py::init<>()) .def(py::init&>(), py::arg("dimension"), DOC(fiction_clocked_layout_clocked_layout)) @@ -91,7 +89,6 @@ void clocked_layout(pybind11::module& m, const std::string& topology, const std: void clocked_layouts(pybind11::module& m) { detail::clocked_layout(m, "cartesian"); - detail::clocked_layout(m, "cartesian", "cube"); detail::clocked_layout(m, "shifted_cartesian"); detail::clocked_layout(m, "hexagonal"); } diff --git a/bindings/mnt/pyfiction/include/pyfiction/types.hpp b/bindings/mnt/pyfiction/include/pyfiction/types.hpp index 2078a3757..14b914fda 100644 --- a/bindings/mnt/pyfiction/include/pyfiction/types.hpp +++ b/bindings/mnt/pyfiction/include/pyfiction/types.hpp @@ -44,10 +44,6 @@ using py_siqad_coordinate = fiction::siqad::coord_t; * Cartesian layout. */ using py_cartesian_layout = fiction::cartesian_layout; -/** - * Cartesian layout based on cube coordinates. - */ -using py_cartesian_layout_cube = fiction::cartesian_layout; /** * Shifted Cartesian layout. */ @@ -61,10 +57,6 @@ using py_hexagonal_layout = fiction::hexagonal_layout>; -/** - * Cartesian clocked layout based on cube coordinate. - */ -using py_cartesian_clocked_layout_cube = fiction::clocked_layout>; /** * Shifted Cartesian clocked layout. */ @@ -101,47 +93,34 @@ using py_hexagonal_obstruction_layout = fiction::obstruction_layout -using py_cartesian_cell_layout = fiction::cell_level_layout; +template +using py_cartesian_cell_layout = fiction::cell_level_layout; /** * QCA cell layout. */ -using py_qca_layout = py_cartesian_cell_layout; +using py_qca_layout = py_cartesian_cell_layout; /** * iNML cell layout. */ -using py_inml_layout = py_cartesian_cell_layout; -/** - * SiDB cell layout. - */ -using py_sidb_layout = py_cartesian_cell_layout; +using py_inml_layout = py_cartesian_cell_layout; /** * SiDB cell layout. */ -using py_sidb_layout_cube = py_cartesian_cell_layout; +using py_sidb_layout = py_cartesian_cell_layout; /** * SiDB lattice layout. */ -template -using py_sidb_lattice = fiction::sidb_lattice; -/** - * SiDB cell layout (with specified H-Si(100)-2x1 lattice orientation). - */ -using py_sidb_100_lattice = py_sidb_lattice; -/** - * SiDB cell layout (with specified H-Si(111)-1x1 lattice orientation). - */ -using py_sidb_111_lattice = py_sidb_lattice; - +template +using py_sidb_lattice = fiction::sidb_lattice; /** * SiDB cell layout (with specified H-Si(100)-2x1 lattice orientation). */ -using py_sidb_100_lattice_cube = py_sidb_lattice; +using py_sidb_100_lattice = py_sidb_lattice; /** * SiDB cell layout (with specified H-Si(111)-1x1 lattice orientation). */ -using py_sidb_111_lattice_cube = py_sidb_lattice; +using py_sidb_111_lattice = py_sidb_lattice; /** * Charge distribution surface. This is a special SiDB cell-level layout that is used for the SiDB simulation @@ -153,8 +132,6 @@ using py_charge_distribution_surface_layout = fiction::charge_distribution_surfa using py_charge_distribution_surface = fiction::charge_distribution_surface; -using py_charge_distribution_surface_cube = fiction::charge_distribution_surface; - /** * Charge distribution surface with underlying H-Si(100)-2x1 lattice. */ @@ -164,15 +141,6 @@ using py_charge_distribution_surface_100 = py_charge_distribution_surface_layout */ using py_charge_distribution_surface_111 = py_charge_distribution_surface_layout; -/** - * Charge distribution surface with underlying H-Si(100)-2x1 lattice based on cube coordinates. - */ -using py_charge_distribution_surface_100_cube = py_charge_distribution_surface_layout; -/** - * Charge distribution surface with underlying H-Si(111)-1x1 lattice based on cube coordinates. - */ -using py_charge_distribution_surface_111_cube = py_charge_distribution_surface_layout; - } // namespace pyfiction #endif // PYFICTION_TYPES_HPP diff --git a/bindings/mnt/pyfiction/pyfiction.cpp b/bindings/mnt/pyfiction/pyfiction.cpp index 687c2959b..239d34107 100644 --- a/bindings/mnt/pyfiction/pyfiction.cpp +++ b/bindings/mnt/pyfiction/pyfiction.cpp @@ -26,24 +26,23 @@ #include "pyfiction/algorithms/physical_design/wiring_reduction.hpp" #include "pyfiction/algorithms/properties/critical_path_length_and_throughput.hpp" #include "pyfiction/algorithms/simulation/logic_simulation.hpp" -#include "pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp" #include "pyfiction/algorithms/simulation/sidb/calculate_energy_and_state_type.hpp" #include "pyfiction/algorithms/simulation/sidb/can_positive_charges_occur.hpp" -#include "pyfiction/algorithms/simulation/sidb/check_simulation_results_for_equivalence.hpp" #include "pyfiction/algorithms/simulation/sidb/compute_operational_ratio.hpp" -#include "pyfiction/algorithms/simulation/sidb/convert_potential_to_distance.hpp" #include "pyfiction/algorithms/simulation/sidb/critical_temperature.hpp" -#include "pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp" #include "pyfiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" #include "pyfiction/algorithms/simulation/sidb/detect_bdl_wires.hpp" -#include "pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp" #include "pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp" -#include "pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp" #include "pyfiction/algorithms/simulation/sidb/energy_distribution.hpp" #include "pyfiction/algorithms/simulation/sidb/exhaustive_ground_state_simulation.hpp" #include "pyfiction/algorithms/simulation/sidb/is_ground_state.hpp" #include "pyfiction/algorithms/simulation/sidb/is_operational.hpp" -#include "pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" +// #include "pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp" +#include "pyfiction/algorithms/simulation/sidb/assess_physical_population_stability.hpp" +#include "pyfiction/algorithms/simulation/sidb/check_simulation_results_for_equivalence.hpp" +#include "pyfiction/algorithms/simulation/sidb/convert_potential_to_distance.hpp" +#include "pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp" +#include "pyfiction/algorithms/simulation/sidb/displacement_robustness_domain.hpp" #include "pyfiction/algorithms/simulation/sidb/minimum_energy.hpp" #include "pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp" #include "pyfiction/algorithms/simulation/sidb/operational_domain.hpp" @@ -59,7 +58,6 @@ #include "pyfiction/inout/read_fgl_layout.hpp" #include "pyfiction/inout/read_fqca_layout.hpp" #include "pyfiction/inout/read_sqd_layout.hpp" -#include "pyfiction/inout/write_defect_operational_domain.hpp" #include "pyfiction/inout/write_dot_layout.hpp" #include "pyfiction/inout/write_fgl_layout.hpp" #include "pyfiction/inout/write_fqca_layout.hpp" @@ -134,14 +132,13 @@ PYBIND11_MODULE(pyfiction, m, pybind11::mod_gil_not_used()) pyfiction::sidb_simulation_parameters(m); pyfiction::sidb_simulation_result(m); pyfiction::can_positive_charges_occur(m); - // pyfiction::assess_physical_population_stability(m); + pyfiction::assess_physical_population_stability(m); pyfiction::convert_potential_to_distance(m); pyfiction::detect_bdl_pairs(m); pyfiction::detect_bdl_wires(m); pyfiction::is_operational(m); pyfiction::operational_domain(m); - pyfiction::defect_operational_domain(m); - pyfiction::maximum_defect_influence_distance(m); + // pyfiction::maximum_defect_influence_distance(m); pyfiction::exhaustive_ground_state_simulation(m); pyfiction::quicksim(m); pyfiction::quickexact(m); @@ -204,11 +201,11 @@ PYBIND11_MODULE(pyfiction, m, pybind11::mod_gil_not_used()) pyfiction::sidb_charge_state(m); pyfiction::sidb_nm_position(m); pyfiction::sidb_nm_distance(m); - pyfiction::sidb_lattice(m); + pyfiction::sidb_lattices(m); pyfiction::charge_distribution_surfaces(m); - // /** - // * Input/Output - // */ + /** + * Input/Output + */ pyfiction::write_dot_layout(m); pyfiction::write_fgl_layout(m); pyfiction::write_qca_layout(m); @@ -220,11 +217,10 @@ PYBIND11_MODULE(pyfiction, m, pybind11::mod_gil_not_used()) pyfiction::write_sqd_sim_result(m); // pyfiction::write_location_and_ground_state(m); pyfiction::write_operational_domain(m); - pyfiction::write_defect_operational_domain(m); pyfiction::read_fgl_layout(m); pyfiction::read_fqca_layout(m); - pyfiction::read_sqd_layout(m); - + pyfiction::read_sqd_layout_100(m); + pyfiction::read_sqd_layout_111(m); /** * Utils */ diff --git a/bindings/mnt/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py b/bindings/mnt/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py deleted file mode 100644 index e69de29bb..000000000 From 4a2388ee5ca6511cf2f020a499852386bcaaeeaf Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 28 Nov 2024 16:40:11 +0100 Subject: [PATCH 219/221] :fire: remove python bindings for the moment due to doc issue. --- .../algorithms/physical_design/apply_gate_library.hpp | 3 +-- .../algorithms/simulation/sidb/defect_operational_domain.hpp | 0 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp diff --git a/bindings/mnt/pyfiction/include/pyfiction/algorithms/physical_design/apply_gate_library.hpp b/bindings/mnt/pyfiction/include/pyfiction/algorithms/physical_design/apply_gate_library.hpp index d3a3c59c0..ffb1a7f41 100644 --- a/bindings/mnt/pyfiction/include/pyfiction/algorithms/physical_design/apply_gate_library.hpp +++ b/bindings/mnt/pyfiction/include/pyfiction/algorithms/physical_design/apply_gate_library.hpp @@ -32,8 +32,7 @@ void apply_fcn_gate_library(pybind11::module& m, const std::string& lib_name) { namespace py = pybind11; - using py_cartesian_technology_cell_layout = - py_cartesian_cell_layout, py_cartesian_clocked_layout>; + using py_cartesian_technology_cell_layout = py_cartesian_cell_layout>; m.def(fmt::format("apply_{}_library", lib_name).c_str(), &fiction::apply_gate_library, py::arg("layout"), diff --git a/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp deleted file mode 100644 index e69de29bb..000000000 From d8351cf241d748399a809aee239516116ce89034 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Thu, 28 Nov 2024 16:46:01 +0100 Subject: [PATCH 220/221] :art: small fix. --- .../simulation/sidb/determine_physically_valid_parameters.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp b/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp index 789054060..49893f5bc 100644 --- a/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp +++ b/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp @@ -28,7 +28,7 @@ void determine_physically_valid_parameters(pybind11::module& m) namespace py = pybind11; m.def("determine_physically_valid_parameters", &fiction::determine_physically_valid_parameters, py::arg("cds"), - py::args("params") = fiction::operational_domain_params{}, + py::arg("params") = fiction::operational_domain_params{}, DOC(fiction_determine_physically_valid_parameters)); } From 35a6266904b02d7a29ac8c07b91decb9eab50470 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Nov 2024 15:48:15 +0000 Subject: [PATCH 221/221] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commi?= =?UTF-8?q?t=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulation/sidb/determine_physically_valid_parameters.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp b/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp index 49893f5bc..d57a9c799 100644 --- a/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp +++ b/bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp @@ -28,8 +28,7 @@ void determine_physically_valid_parameters(pybind11::module& m) namespace py = pybind11; m.def("determine_physically_valid_parameters", &fiction::determine_physically_valid_parameters, py::arg("cds"), - py::arg("params") = fiction::operational_domain_params{}, - DOC(fiction_determine_physically_valid_parameters)); + py::arg("params") = fiction::operational_domain_params{}, DOC(fiction_determine_physically_valid_parameters)); } } // namespace detail