Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

⚗️ Updated QuickCell experiment #643

Merged
merged 18 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,23 @@ int main() // NOLINT
static const std::string folder = fmt::format("{}sidb_gate_libraries/bestagon_gates/", EXPERIMENTS_PATH);

const auto truth_tables_and_names =
std::array<std::pair<std::vector<tt>, std::string>, 11>{{{std::vector<tt>{create_id_tt()}, "wire"},
std::array<std::pair<std::vector<tt>, std::string>, 14>{{{std::vector<tt>{create_id_tt()}, "wire"},
{std::vector<tt>{create_id_tt()}, "wire_diag"},
{std::vector<tt>{create_not_tt()}, "inv"},
{std::vector<tt>{create_not_tt()}, "inv_diag"},
{std::vector<tt>{create_and_tt()}, "and"},
{std::vector<tt>{create_nand_tt()}, "nand"},
{std::vector<tt>{create_or_tt()}, "or"},
{std::vector<tt>{create_nor_tt()}, "nor"},
{std::vector<tt>{create_xor_tt()}, "xor"},
{std::vector<tt>{create_xnor_tt()}, "xnor"},
{create_fan_out_tt(), "fo2"},
{create_crossing_wire_tt(), "cx"},
{create_half_adder_tt(), "ha"},
{create_double_wire_tt(), "hourglass"}}};

double mean_ratio_num_op_sketch_to_num_op_exact = 0.0;

for (const auto& [truth_table, gate] : truth_tables_and_names)
{
const auto lyt = read_sqd_layout<sidb_100_cell_clk_lyt_siqad>(fmt::format("{}/{}.sqd", folder, gate), gate);
Expand All @@ -100,6 +105,10 @@ int main() // NOLINT
write_operational_domain(op_domain_gs_exact, fmt::format("{}/exact_{}.csv", folder, gate));
write_operational_domain(op_domain_gs_sketch, fmt::format("{}/sketch_{}.csv", folder, gate));

mean_ratio_num_op_sketch_to_num_op_exact +=
static_cast<double>(op_domain_stats_sketch.num_operational_parameter_combinations) /
static_cast<double>(op_domain_stats_gs_exact.num_operational_parameter_combinations);

opdomain_exp(
// Benchmark
gate, lyt.num_cells(),
Expand All @@ -120,6 +129,8 @@ int main() // NOLINT
opdomain_exp.table();
}

opdomain_exp("Average", 0, 0, 0.0, 0, 0.0, mean_ratio_num_op_sketch_to_num_op_exact, 0.0);

opdomain_exp.save();
opdomain_exp.table();

Expand Down
123 changes: 67 additions & 56 deletions experiments/quicktrace/quicktrace_vs_grid_search_bestagon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,80 +33,91 @@ int main() // NOLINT
"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("{}quicktrace/plots/", EXPERIMENTS_PATH);
static const std::string bestagon_folder = fmt::format("{}sidb_gate_libraries/bestagon_gates/", EXPERIMENTS_PATH);
static const std::string plot_folder = fmt::format("{}quicktrace/plots/", EXPERIMENTS_PATH);

static const std::array<std::pair<std::string, std::vector<tt>>, 9> gates = {
static const std::array<std::pair<std::string, std::vector<tt>>, 10> gates = {
std::make_pair("and", std::vector<tt>{create_and_tt()}),
std::make_pair("xor", std::vector<tt>{create_xor_tt()}),
std::make_pair("nand", std::vector<tt>{create_nand_tt()}),
std::make_pair("or", std::vector<tt>{create_or_tt()}),
std::make_pair("xnor", std::vector<tt>{create_xnor_tt()}),
std::make_pair("fo2", std::vector<tt>{create_fan_out_tt()}),
std::make_pair("nor", std::vector<tt>{create_nor_tt()}),
std::make_pair("nand", std::vector<tt>{create_nand_tt()}),
std::make_pair("xor", std::vector<tt>{create_xor_tt()}),
std::make_pair("xnor", std::vector<tt>{create_xnor_tt()}),
std::make_pair("wire", std::vector<tt>{create_id_tt()}),
std::make_pair("wire_diag", std::vector<tt>{create_id_tt()}),
std::make_pair("inv", std::vector<tt>{create_not_tt()}),
std::make_pair("wire", std::vector<tt>{create_id_tt()})};
std::make_pair("inv_diag", std::vector<tt>{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};
const is_operational_params is_op_params{sidb_simulation_parameters{2, -0.32, 5.6, 5.0}};

// 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};

defect_influence_params<fiction::cell<sidb_100_cell_clk_lyt_cube>> params{};
params.additional_scanning_area = {50, 50};
params.additional_scanning_area = {100, 100};
params.defect = stray_db;
params.operational_params = is_op_params;

std::size_t total_number_of_samples_grid = 0;
std::size_t total_number_of_samples_quicktrace = 0;

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<sidb_100_cell_clk_lyt_cube>(file.path().string());

defect_influence_stats grid_stats{};
const auto op_defect_grid = defect_influence_grid_search(layout, truth_table, params, 1, &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_domain(op_defect_grid, csv_path);

// Write the SQD layout
write_sqd_layout(layout, sqd_path);

const auto avoidance_grid = calculate_defect_clearance(layout, op_defect_grid);

defect_influence_stats random_stats{};
const auto op_defect_random =
defect_influence_random_sampling(layout, truth_table, 100, params, &random_stats);
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_domain(op_defect_random, csv_path_random);

defect_influence_stats contour_stats{};
const auto op_defect_contour = defect_influence_quicktrace(layout, truth_table, 20, params, &contour_stats);
const auto avoidance_contour = calculate_defect_clearance(layout, op_defect_contour);
// Create a folder where the defect influence plots are stored
std::filesystem::create_directories(plot_folder);

// Create a folder where the defect influence CSV files of each gate are stored
const auto plot_folder_for_given_gate = fmt::format("{}{}/", plot_folder, gate);
std::filesystem::create_directories(plot_folder_for_given_gate);

// read the Bestagon SiDB layout
const auto layout = read_sqd_layout<sidb_100_cell_clk_lyt_cube>(fmt::format("{}{}.sqd", bestagon_folder, gate));

// Write the SQD layout
write_sqd_layout(layout, fmt::format("{}/{}.sqd", plot_folder_for_given_gate, gate));

// grid search
defect_influence_stats grid_stats{};
const auto defect_inf_grid = defect_influence_grid_search(layout, truth_table, params, 1, &grid_stats);
total_number_of_samples_grid += grid_stats.num_evaluated_defect_positions;

// Write the defect influence domain to a CSV file
write_defect_influence_domain(defect_inf_grid, fmt::format("{}{}_grid.csv", plot_folder_for_given_gate, gate));
const auto clearance_grid_search = calculate_defect_clearance(layout, defect_inf_grid);

// random sampling
defect_influence_stats random_stats{};
const auto defect_inf_random =
defect_influence_random_sampling(layout, truth_table, 100, params, &random_stats);
const auto clearance_random = calculate_defect_clearance(layout, defect_inf_random);
write_defect_influence_domain(defect_inf_random,
fmt::format("{}{}_random.csv", plot_folder_for_given_gate, gate));

// quicktrace
defect_influence_stats quicktrace_stats{};
const auto defect_inf_quicktrace =
defect_influence_quicktrace(layout, truth_table, 20, params, &quicktrace_stats);
total_number_of_samples_quicktrace += quicktrace_stats.num_evaluated_defect_positions;
const auto clearance_quicktrace = calculate_defect_clearance(layout, defect_inf_quicktrace);
write_defect_influence_domain(defect_inf_quicktrace,
fmt::format("{}{}_quicktrace.csv", plot_folder_for_given_gate, gate));

// Log the simulation results
simulation_exp(gate, layout.num_cells(), clearance_grid_search.defect_position.x,
clearance_grid_search.defect_position.y, clearance_grid_search.defect_clearance_distance,
grid_stats.num_evaluated_defect_positions, clearance_random.defect_clearance_distance,
random_stats.num_evaluated_defect_positions, clearance_quicktrace.defect_clearance_distance,
quicktrace_stats.num_evaluated_defect_positions);
simulation_exp.save();
simulation_exp.table();
}

const auto csv_path_contour = fmt::format("{}{}_contour.csv", gate_folder, gate);
write_defect_influence_domain(op_defect_contour, csv_path_contour);
// Log the total number of samples
simulation_exp("Total", 0, 0.0, 0.0, 0.0, total_number_of_samples_grid, 0.0, 0, 0.0,
total_number_of_samples_quicktrace);
simulation_exp.save();
simulation_exp.table();

// Log the simulation results
simulation_exp(gate, layout.num_cells(), avoidance_grid.defect_position.x, avoidance_grid.defect_position.y,
avoidance_grid.defect_clearance_distance, grid_stats.num_evaluated_defect_positions,
avoidance_random.defect_clearance_distance, random_stats.num_evaluated_defect_positions,
avoidance_contour.defect_clearance_distance, contour_stats.num_evaluated_defect_positions);
simulation_exp.save();
simulation_exp.table();
}
}
return EXIT_SUCCESS;
}
Loading