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

✨ Compile time flows and CLI simulation update #349

Merged
merged 64 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
5c94c5a
:sparkles: Added CMake options for select flow compilation
marcelwa Dec 7, 2023
f7b4cd7
:art: Simplified layout printing from store
marcelwa Dec 7, 2023
175d006
:sparkles: Added SQD reading and CDS printing to the CLI
marcelwa Dec 7, 2023
959e0f5
:sparkles: Added QuickExact to the CLI
marcelwa Dec 7, 2023
6aa8a40
:sparkles: Added QuickSim to the CLI
marcelwa Dec 7, 2023
a803b1e
:bug: Try to pacify MSVC
marcelwa Dec 7, 2023
e80c846
:bug: Removed base option for the quicksim CLI command
marcelwa Dec 9, 2023
cbc5e0a
:art: Adjusted `minimum_energy` to be more C++-ish
marcelwa Dec 9, 2023
6511546
:sparkles: Added a `minimum_energy_distribution` function to obtain t…
marcelwa Dec 9, 2023
9a6eb1a
:memo: Fixed a wrong header in the documentation and added a missing …
marcelwa Dec 9, 2023
936b7d2
:art: Make the quicksim and quickexact commands pick the minimum ener…
marcelwa Dec 9, 2023
fc0e3e4
:bug: Fixed cyclic dependency
marcelwa Dec 9, 2023
9b4fe3c
:boom: Made `additional_simulation_parameters` in `sidb_simulation_re…
marcelwa Dec 9, 2023
00e06fd
:sparkles: Made the quicksim CLI command log its additional parameters
marcelwa Dec 9, 2023
ec54e2e
Merge branch 'main' into compile-time-flows
marcelwa Dec 9, 2023
87bad9e
:sparkles: Display proper cell type names in the CLI's `ps -c` and `s…
marcelwa Dec 9, 2023
ea30b91
Merge remote-tracking branch 'origin/compile-time-flows' into compile…
marcelwa Dec 9, 2023
828d3cf
:white_check_mark: update unit tests after code changes.
Drewniok Dec 10, 2023
6a91562
:white_check_mark: update test after code changes.
Drewniok Dec 10, 2023
97c7469
Merge remote-tracking branch 'origin/compile-time-flows' into compile…
Drewniok Dec 10, 2023
81215b4
:art: remove ``else`` after return.
Drewniok Dec 10, 2023
7940028
:art: ClangFormat changes
Dec 10, 2023
6491bfc
:memo: Add documentation to the CLI chapter in the RTD pages.
Drewniok Dec 11, 2023
bd85ff6
Merge remote-tracking branch 'upstream/compile-time-flows' into compi…
Drewniok Dec 11, 2023
ef1285e
:memo: revert wrong changes.
Drewniok Dec 11, 2023
ae803fa
:art: three as a base number is not supported by quicksim.
Drewniok Dec 11, 2023
6630695
:memo: change position of simulation paragraph.
Drewniok Dec 11, 2023
816a2dc
:white_check_mark: update test due to code changes.
Drewniok Dec 11, 2023
086e90a
:green_heart: try to fix macos issue.
Drewniok Dec 11, 2023
016c9c7
:art: add global potential and automatic base number detection.
Drewniok Dec 11, 2023
1d18e12
:memo: Extended documentation on `minimum_energy` to reflect the erro…
marcelwa Dec 11, 2023
89e6344
:bug: Fixed unit
marcelwa Dec 11, 2023
69c3286
:memo: Small doc update
marcelwa Dec 11, 2023
b931dd1
:memo: Revert Jan's change
marcelwa Dec 11, 2023
41353da
Merge branch 'main' into compile-time-flows
Drewniok Dec 11, 2023
7d13b46
:bug Add missing header
Drewniok Dec 11, 2023
532b492
:art: delete automatic base number detection.
Drewniok Dec 11, 2023
13b171c
:bug: Set CMP0135 only if CMake >= 3.24 is used
marcelwa Dec 11, 2023
2b5938d
Merge remote-tracking branch 'origin/compile-time-flows' into compile…
marcelwa Dec 11, 2023
b0130bb
:art: disable automatic base number detection in CLI.
Drewniok Dec 12, 2023
b5c425a
:memo: add variable names.
Drewniok Dec 12, 2023
7af9e05
Merge branch 'main' into compile-time-flows
Drewniok Dec 12, 2023
52b4a39
:art: Cleaned up includes
marcelwa Dec 12, 2023
3ec4190
:fire: Remove base toggle from quickexact and quicksim CLI commands
marcelwa Dec 13, 2023
5519f1f
:art: Further header include fixes
marcelwa Dec 13, 2023
1f02017
:art: Adjustments to logging and [[nodiscard]]
marcelwa Dec 13, 2023
0ef8e89
:sparkles: Added Operational Domain computation to the CLI
marcelwa Dec 13, 2023
3d31d81
:sparkles: Added Operational Domain computation to the CLI
marcelwa Dec 13, 2023
bee789c
:memo: Added Operational Domain CLI documentation
marcelwa Dec 13, 2023
f5ec42d
Merge remote-tracking branch 'origin/compile-time-flows' into compile…
marcelwa Dec 13, 2023
4e60b69
:bug: Added missing includes to `critical_temperature`
marcelwa Dec 13, 2023
965553a
:memo: Small doc fix
marcelwa Dec 13, 2023
d64b12a
:bug: Added missing includes to `quicksim`
marcelwa Dec 13, 2023
2659106
:bug: Added missing includes to `quicksim`'s tests
marcelwa Dec 14, 2023
70b57ba
:art: Code cleanup in `critical_temperature`
marcelwa Dec 14, 2023
12c80b0
:art: Added physical parameters used for the simulation to the `criti…
marcelwa Dec 14, 2023
51943c4
:bug: Fix logging for `quickexact` and `quicksim` CLI commands
marcelwa Dec 14, 2023
6bf65d3
:bug: Fix `opdom` error when no PI/PO cells are available
marcelwa Dec 14, 2023
50fc863
:sparkles: Added command `temp` for critical temperature SiDB simulat…
marcelwa Dec 14, 2023
3a70265
:art: Added missing header and `std::forward`
marcelwa Dec 14, 2023
40044e0
Merge branch 'main' into compile-time-flows
marcelwa Dec 14, 2023
bb40f45
:bug: fix unit bug.
Drewniok Dec 14, 2023
870d0ea
:art: set description to meV.
Drewniok Dec 14, 2023
091f3a8
Merge branch 'main' into compile-time-flows
marcelwa Dec 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ add_executable(fiction ${SOURCES})
# Link against the project settings, libfiction and alice
target_link_libraries(fiction PRIVATE libfiction alice)

# Compile-time decisions on which flows to compile

# Logic synthesis flow
option(FICTION_LOGIC_SYNTHESIS_FLOW "Enable the logic synthesis flow for the fiction CLI" ON)
if(FICTION_LOGIC_SYNTHESIS_FLOW)
target_compile_definitions(fiction PRIVATE FICTION_LOGIC_SYNTHESIS_FLOW)
endif()

# Physical design flow
option(FICTION_PHYSICAL_DESIGN_FLOW "Enable the physical design flow for the fiction CLI" ON)
if(FICTION_PHYSICAL_DESIGN_FLOW)
target_compile_definitions(fiction PRIVATE FICTION_PHYSICAL_DESIGN_FLOW)
endif()

# Physical simulation flow
option(FICTION_SIMULATION_FLOW "Enable the physical simulation flow for the fiction CLI" ON)
if(FICTION_SIMULATION_FLOW)
target_compile_definitions(fiction PRIVATE FICTION_SIMULATION_FLOW)
endif()

# Strip the executable if we are in Release mode
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(CMAKE_STRIP)
Expand Down
72 changes: 46 additions & 26 deletions cli/cmd/io/read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <fiction/io/network_reader.hpp>
#include <fiction/io/read_fgl_layout.hpp>
#include <fiction/io/read_fqca_layout.hpp>
#include <fiction/io/read_sqd_layout.hpp>
#include <fiction/types.hpp>

#include <alice/alice.hpp>
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -23,9 +24,9 @@ namespace alice
*
* Currently parses Verilog, AIGER, and BLIF using the lorina parsers.
*
* Parses FGL and FQCA via custom reader functions.
*
* For more information see: https://github.com/hriener/lorina
*
* Parses FGL, SQD, and FQCA via custom reader functions.
*/
class read_command : public command
{
Expand All @@ -40,54 +41,57 @@ class read_command : public command
"which will be put into the respective store. Current supported file types are:\n"
"Logic networks: Verilog, AIGER, BLIF.\n"
"Gate-level layouts: FGL.\n"
"Cell-level layouts: FQCA.\n"
"Cell-level layouts: SQD, FQCA.\n"
"In a directory, only files with extension '.v', '.aig', '.blif' are considered.")
{
add_option("filename", filename, "Filename or directory")->required();
add_option("topology", topology,
"Topology for gate-level layouts. Can be 'cartesian' or of the form "
"'<odd|even>_<row|column>_<cartesian|hex>'");
add_flag("--aig,-a", "Parse file as AIG");
add_flag("--xag,-x", "Parse file as XAG");
add_flag("--mig,-m", "Parse file as MIG");
add_flag("--tec,-t", "Parse file as technology network");
add_flag("--fgl,-f", "Parse file as fiction gate-level layout");
add_flag("--qca,-q", "Parse file as QCA cell-level layout");
add_flag("--sort,-s", sort, "Sort networks in given directory by vertex count prior to storing them");
add_flag("--aig,-a", "Parse Verilog file as AIG");
add_flag("--xag,-x", "Parse Verilog file as XAG");
add_flag("--mig,-m", "Parse Verilog file as MIG");
add_flag("--tec,-t", "Parse Verilog file as technology network");
add_flag("--fgl,-f", "Parse FGL file as fiction gate-level layout");
add_flag("--sqd,-s", "Parse SQD file as SiDB cell-level layout");
add_flag("--fqca,-q", "Parse FQCA file as QCA cell-level layout");
add_flag("--sort", sort, "Sort networks in given directory by node count prior to storing them");
}

protected:
/**
* Function to perform the read call. Reads Verilog and creates a logic_network.
* Function to perform the read call. Reads a network or layout from a file.
*/
void execute() override
{
const auto store_ntks = [&](auto&& reader)
{
for (const auto& ln : reader.get_networks(sort))
{
store<fiction::logic_network_t>().extend() = ln;
}
};

if (!is_set("aig") && !is_set("xag") && !is_set("mig") && !is_set("tec") && !is_set("fgl") && !is_set("qca"))
if (!is_set("aig") && !is_set("xag") && !is_set("mig") && !is_set("tec") && !is_set("fgl") && !is_set("sqd") &&
!is_set("fqca"))
{
env->out() << "[e] at least one network or layout type must be specified" << std::endl;
}
else if ((is_set("aig") || is_set("xag") || is_set("mig") || is_set("tec")) && is_set("fql"))
else if ((is_set("aig") || is_set("xag") || is_set("mig") || is_set("tec")) && is_set("fgl"))
{
env->out() << "[e] cannot parse files as both logic networks and gate-level layouts" << std::endl;
}
else if ((is_set("aig") || is_set("xag") || is_set("mig") || is_set("tec")) && is_set("qca"))
else if ((is_set("aig") || is_set("xag") || is_set("mig") || is_set("tec")) &&
(is_set("sqd") || is_set("fqca")))
{
env->out() << "[e] cannot parse files as both logic networks and cell-level layouts" << std::endl;
}
else if (is_set("fql") && is_set("qca"))
else if (is_set("fgl") && (is_set("sqd") || is_set("fqca")))
{
env->out() << "[e] cannot parse files as both gate-level and cell-level layouts" << std::endl;
}
else
{
const auto store_ntks = [&](auto&& reader)
{
for (const auto& ln : reader.get_networks(sort))
{
store<fiction::logic_network_t>().extend() = ln;
}
};

try
{
if (is_set("aig"))
Expand All @@ -114,7 +118,7 @@ class read_command : public command

store_ntks(reader);
}
if (is_set("fgl") || is_set("qca"))
if (is_set("fgl") || is_set("sqd") || is_set("fqca"))
{
if (std::filesystem::exists(filename))
{
Expand Down Expand Up @@ -205,7 +209,23 @@ class read_command : public command
<< std::endl;
}
}
if (is_set("qca"))
else if (is_set("sqd"))
{
try
{
const auto layout_name = std::filesystem::path{filename}.stem().string();

store<fiction::cell_layout_t>().extend() =
std::make_shared<fiction::sidb_cell_clk_lyt>(
fiction::read_sqd_layout<fiction::sidb_cell_clk_lyt>(filename,
layout_name));
}
catch (const fiction::sqd_parsing_error& e)
{
env->out() << e.what() << std::endl;
}
}
else if (is_set("fqca"))
{
try
{
Expand Down Expand Up @@ -250,7 +270,7 @@ class read_command : public command
}
catch (...)
{
env->out() << "[e] no networks or layouts were read" << std::endl;
env->out() << "[e] I/O error: no file could be read" << std::endl;
}
}

Expand Down
175 changes: 175 additions & 0 deletions cli/cmd/simulation/quickexact.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
//
// Created by marcel on 06.12.23.
//

#ifndef FICTION_CMD_QUICKEXACT_HPP
#define FICTION_CMD_QUICKEXACT_HPP

#include <fiction/algorithms/simulation/sidb/quickexact.hpp>
#include <fiction/traits.hpp>
#include <fiction/types.hpp>
#include <fiction/utils/name_utils.hpp>

marcelwa marked this conversation as resolved.
Show resolved Hide resolved
#include <alice/alice.hpp>
marcelwa marked this conversation as resolved.
Show resolved Hide resolved

#include <variant>

namespace alice
{
/**
*
*/
class quickexact_command : public command
{
public:
/**
* Standard constructor. Adds descriptive information, options, and flags.
*
* @param e alice::environment that specifies stores etc.
*/
explicit quickexact_command(const environment::ptr& e) :
command(e, "QuickExact 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.")
{
add_option("--epsilon_r,-e", physical_params.epsilon_r, "Electric permittivity of the substrate (unit-less)",
true);
add_option("--lambda_tf,-l", physical_params.lambda_tf, "Thomas-Fermi screening distance (unit: nm)", true);
add_option("--mu_minus,-m", physical_params.mu_minus, "Energy transition level (0/-) (unit: eV)", true);
add_option("--base,-b", physical_params.base,
"2-state (neutral/negative) vs. 3-state (positive/neutral/negative) simulation", true);
add_option("--global_potential,-g", params.global_potential,
"Global potential applied to the entire layout (unit: V)", true);
}

protected:
/**
* Function to perform the simulation call.
*/
void execute() override
{
// reset sim result
sim_result = {};

if (physical_params.epsilon_r <= 0)
{
env->out() << "[e] epsilon_r must be positive" << std::endl;
reset_params();
return;
}

if (physical_params.lambda_tf <= 0)
{
env->out() << "[e] lambda_tf must be positive" << std::endl;
reset_params();
return;
}

if (physical_params.base != 2 && physical_params.base != 3)
{
env->out() << "[e] base must be 2 or 3" << std::endl;
reset_params();
return;
}

auto& s = store<fiction::cell_layout_t>();

// error case: empty cell layout store
if (s.empty())
{
env->out() << "[w] no cell layout in store" << std::endl;
reset_params();
return;
}

const auto get_name = [](auto&& lyt_ptr) -> std::string { return fiction::get_name(*lyt_ptr); };

const auto quickexact = [this, &get_name](auto&& lyt_ptr)
{
using Lyt = typename std::decay_t<decltype(lyt_ptr)>::element_type;

if constexpr (fiction::has_sidb_technology_v<Lyt>)
{
if constexpr (fiction::is_charge_distribution_surface_v<Lyt>)
{
env->out() << fmt::format(
"[w] {} already possesses a charge distribution; no simulation is conducted",
get_name(lyt_ptr))
<< std::endl;
}
else
{
params.physical_parameters = physical_params;

sim_result = fiction::quickexact(*lyt_ptr, params);

marcelwa marked this conversation as resolved.
Show resolved Hide resolved
if (sim_result.charge_distributions.empty())
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
{
env->out() << fmt::format("[e] ground state of {} could not be determined", get_name(lyt_ptr))
<< std::endl;
}
else
{
store<fiction::cell_layout_t>().extend() =
std::make_shared<fiction::cds_sidb_cell_clk_lyt>(sim_result.charge_distributions.front());
}
}
}
else
{
env->out() << fmt::format("[e] {} is not an SiDB layout", get_name(lyt_ptr)) << std::endl;
}
};

std::visit(quickexact, s.current());

reset_params();
}

private:
/**
* Physical parameters for the simulation.
*/
fiction::sidb_simulation_parameters physical_params{2, -0.32, 5.6, 5.0};
/**
* QuickExact parameters.
*/
fiction::quickexact_params<fiction::sidb_cell_clk_lyt> params{};
/**
* Simulation result.
*/
fiction::sidb_simulation_result<fiction::sidb_cell_clk_lyt> sim_result{};

/**
* Logs the resulting information in a log file.
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
*
* @return JSON object containing details about the simulation.
*/
nlohmann::json log() const override
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
{
return nlohmann::json{
{"Algorithm name", sim_result.algorithm_name},
{"Simulation runtime", sim_result.simulation_runtime.count()},
{"Physical parameters",
{"base", sim_result.physical_parameters.base},
{"epsilon_r", sim_result.physical_parameters.epsilon_r},
{"lambda_tf", sim_result.physical_parameters.lambda_tf},
{"mu_minus", sim_result.physical_parameters.mu_minus}},
{"Ground state energy (meV)", sim_result.charge_distributions.front().get_system_energy()},
{"Number of stable states", sim_result.charge_distributions.size()}};
}
/**
* Resets the parameters to their default values.
*/
void reset_params()
{
physical_params = fiction::sidb_simulation_parameters{2, -0.32, 5.6, 5.0};
params = {};
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
}
};

ALICE_ADD_COMMAND(quickexact, "Simulation")
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
marcelwa marked this conversation as resolved.
Show resolved Hide resolved

} // namespace alice

#endif // FICTION_CMD_QUICKEXACT_HPP
Loading
Loading