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

🎨 support cds as input for all simulators #310

Merged
merged 14 commits into from
Oct 12, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ template <typename Lyt>
// The charge layout is initialized with negatively charged SiDBs. Therefore, the local electrostatic potentials are
// maximal. In this extreme case, if the banding is not sufficient for any SiDB to be positively charged, it will
// not be for any other charge distribution. Therefore, no positively charged SiDBs can occur.
const charge_distribution_surface charge_lyt{lyt, sim_params, sidb_charge_state::NEGATIVE};
charge_distribution_surface charge_lyt{lyt};
Drewniok marked this conversation as resolved.
Show resolved Hide resolved
charge_lyt.assign_physical_parameters(sim_params);
charge_lyt.assign_all_charge_states(sidb_charge_state::NEGATIVE);

charge_lyt.foreach_cell(
[&result, &mu_plus, charge_lyt](const auto& c) noexcept
{
Expand Down
143 changes: 103 additions & 40 deletions include/fiction/algorithms/simulation/sidb/quickexact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ class quickexact_impl
public:
quickexact_impl(const Lyt& lyt, const quickexact_params<Lyt>& parameter) :
layout{lyt},
charge_lyt{lyt, parameter.physical_parameters, sidb_charge_state::NEGATIVE},
charge_lyt{lyt},
params{parameter}
{}
{
charge_lyt.assign_all_charge_states(sidb_charge_state::NEGATIVE);
charge_lyt.assign_physical_parameters(parameter.physical_parameters);
}

sidb_simulation_result<Lyt> run() noexcept
{
Expand Down Expand Up @@ -104,54 +107,82 @@ class quickexact_impl
// If the layout consists of SiDBs that do not need to be negatively charged.
if (!all_sidbs_in_lyt_without_negative_preassigned_ones.empty())
{
// The first cell from all_sidbs_in_lyt_without_negative_preassigned_ones is chosen as the
// dependent-cell to initialize the layout (pre-assigned negatively charged SiDBs were erased with
// generate_layout_without_negative_sidbs). All SiDBs are set to neutrally charged.
charge_distribution_surface charge_lyt_with_assigned_dependent_cell{
layout, params.physical_parameters, sidb_charge_state::NEUTRAL,
all_sidbs_in_lyt_without_negative_preassigned_ones[0]};

charge_lyt_with_assigned_dependent_cell.assign_local_external_potential(
params.local_external_potential);
charge_lyt_with_assigned_dependent_cell.assign_global_external_potential(params.global_potential);

if constexpr (has_get_sidb_defect_v<Lyt>)
{
// The first cell from all_sidbs_in_lyt_without_negative_preassigned_ones is chosen as the
// dependent-cell to initialize the layout (pre-assigned negatively charged SiDBs were erased
// with generate_layout_without_negative_sidbs). All SiDBs are set to neutrally charged.
charge_distribution_surface charge_lyt_with_assigned_dependent_cell{
Drewniok marked this conversation as resolved.
Show resolved Hide resolved
static_cast<sidb_defect_cell_clk_lyt_siqad>(layout)};
charge_lyt_with_assigned_dependent_cell.assign_physical_parameters(params.physical_parameters);
charge_lyt_with_assigned_dependent_cell.assign_all_charge_states(sidb_charge_state::NEUTRAL);
charge_lyt_with_assigned_dependent_cell.assign_dependent_cell(
all_sidbs_in_lyt_without_negative_preassigned_ones[0]);

charge_lyt_with_assigned_dependent_cell.assign_local_external_potential(
params.local_external_potential);
charge_lyt_with_assigned_dependent_cell.assign_global_external_potential(
params.global_potential);

for (const auto& [cell, defect] : real_placed_defects)
{
charge_lyt_with_assigned_dependent_cell.add_sidb_defect_to_potential_landscape(cell,
defect);
}
}

// IMPORTANT: The pre-assigned negatively charged SiDBs (they have to be negatively charged to
// fulfill the population stability) are considered as negatively charged defects in the layout.
// Hence, there are no "real" defects assigned, but in order to set some SiDBs with a fixed negative
// charge, this way of implementation is chosen.
for (const auto& cell : preassigned_negative_sidbs)
{
charge_lyt_with_assigned_dependent_cell.add_sidb_defect_to_potential_landscape(
cell, sidb_defect{sidb_defect_type::UNKNOWN, -1,
charge_lyt_with_assigned_dependent_cell.get_phys_params().epsilon_r,
charge_lyt_with_assigned_dependent_cell.get_phys_params().lambda_tf});
}
// IMPORTANT: The pre-assigned negatively charged SiDBs (they have to be negatively charged to
// fulfill the population stability) are considered as negatively charged defects in the layout.
// Hence, there are no "real" defects assigned, but in order to set some SiDBs with a fixed
// negative charge, this way of implementation is chosen.
for (const auto& cell : preassigned_negative_sidbs)
{
charge_lyt_with_assigned_dependent_cell.add_sidb_defect_to_potential_landscape(
cell, sidb_defect{sidb_defect_type::UNKNOWN, -1,
charge_lyt_with_assigned_dependent_cell.get_phys_params().epsilon_r,
charge_lyt_with_assigned_dependent_cell.get_phys_params().lambda_tf});
}

// Update all local potentials, system energy and physically validity. The Flag is set to "Variable"
// to allow dependent cell to change its charge state based on the N-1 SiDBs to fulfill the local
// population stability in its position.
charge_lyt_with_assigned_dependent_cell.update_after_charge_change(dependent_cell_mode::VARIABLE);
// Update all local potentials, system energy and physically validity. The Flag is set to
// "Variable" to allow dependent cell to change its charge state based on the N-1 SiDBs to
// fulfill the local population stability in its position.
Drewniok marked this conversation as resolved.
Show resolved Hide resolved
charge_lyt_with_assigned_dependent_cell.update_after_charge_change(
dependent_cell_mode::VARIABLE);

// If no positively charged SiDB can occur in the layout.
if (!three_state_simulation_required)
{
result.additional_simulation_parameters.emplace_back("base_number", uint64_t{2});
two_state_simulation(charge_lyt_with_assigned_dependent_cell);
conduct_simulation(three_state_simulation_required, charge_lyt_with_assigned_dependent_cell);
}
// If positively charged SiDBs can occur in the layout, 3-state simulation is conducted.
else
{
result.additional_simulation_parameters.emplace_back("base_number", uint64_t{3});
three_state_simulation(charge_lyt_with_assigned_dependent_cell);
charge_distribution_surface charge_lyt_with_assigned_dependent_cell{
Drewniok marked this conversation as resolved.
Show resolved Hide resolved
static_cast<sidb_cell_clk_lyt_siqad>(layout)};
charge_lyt_with_assigned_dependent_cell.assign_physical_parameters(params.physical_parameters);
charge_lyt_with_assigned_dependent_cell.assign_all_charge_states(sidb_charge_state::NEUTRAL);
charge_lyt_with_assigned_dependent_cell.assign_dependent_cell(
all_sidbs_in_lyt_without_negative_preassigned_ones[0]);

charge_lyt_with_assigned_dependent_cell.assign_local_external_potential(
params.local_external_potential);
charge_lyt_with_assigned_dependent_cell.assign_global_external_potential(
params.global_potential);

// IMPORTANT: The pre-assigned negatively charged SiDBs (they have to be negatively charged to
// fulfill the population stability) are considered as negatively charged defects in the layout.
// Hence, there are no "real" defects assigned, but in order to set some SiDBs with a fixed
// negative charge, this way of implementation is chosen.
for (const auto& cell : preassigned_negative_sidbs)
{
charge_lyt_with_assigned_dependent_cell.add_sidb_defect_to_potential_landscape(
cell, sidb_defect{sidb_defect_type::UNKNOWN, -1,
charge_lyt_with_assigned_dependent_cell.get_phys_params().epsilon_r,
charge_lyt_with_assigned_dependent_cell.get_phys_params().lambda_tf});
}
Drewniok marked this conversation as resolved.
Show resolved Hide resolved

// Update all local potentials, system energy and physically validity. The Flag is set to
// "Variable" to allow dependent cell to change its charge state based on the N-1 SiDBs to
// fulfill the local population stability in its position.
Drewniok marked this conversation as resolved.
Show resolved Hide resolved
charge_lyt_with_assigned_dependent_cell.update_after_charge_change(
dependent_cell_mode::VARIABLE);

conduct_simulation(three_state_simulation_required, charge_lyt_with_assigned_dependent_cell);
}
}

Expand Down Expand Up @@ -272,10 +303,13 @@ class quickexact_impl
/**
* This function conducts 2-state physical simulation (negative, neutral).
*
* @tparam ChargeLyt Type of the charge distribution surface.
* @param charge_layout Initialized charge layout.
*/
void two_state_simulation(charge_distribution_surface<Lyt>& charge_layout) noexcept
template <typename ChargeLyt>
void two_state_simulation(ChargeLyt& charge_layout) noexcept
{
static_assert(is_cell_level_layout_v<ChargeLyt>, "ChargeLyt is not a cell-level layout");
Drewniok marked this conversation as resolved.
Show resolved Hide resolved
charge_layout.assign_base_number(2);
uint64_t previous_charge_index = 0;

Expand Down Expand Up @@ -320,10 +354,13 @@ class quickexact_impl
/**
* This function conducts 3-state physical simulation (negative, neutral, positive).
*
* @tparam ChargeLyt Type of the charge distribution surface.
* @param charge_layout Initialized charge layout.
*/
void three_state_simulation(charge_distribution_surface<Lyt>& charge_layout) noexcept
template <typename ChargeLyt>
void three_state_simulation(ChargeLyt& charge_layout) noexcept
Drewniok marked this conversation as resolved.
Show resolved Hide resolved
{
static_assert(is_cell_level_layout_v<ChargeLyt>, "ChargeLyt is not a cell-level layout");
charge_layout.assign_all_charge_states(sidb_charge_state::NEGATIVE);
charge_layout.update_after_charge_change();
// Not executed to detect if 3-state simulation is required, but to detect the SiDBs that could be positively
Expand Down Expand Up @@ -466,7 +503,6 @@ class quickexact_impl
* - It assigns the local external potential from the `params.local_external_potential` configuration to the charge
* layout.
* - It assigns the global external potential from `params.global_potential` to the charge layout.
*
*/
void initialize_charge_layout() noexcept
{
Expand Down Expand Up @@ -495,7 +531,34 @@ class quickexact_impl
// store the number of SiDBs, since the number of active cells changes during simulation.
number_of_sidbs = charge_lyt.num_cells();
}

/**
* This function conducts physical simulation on the given charge layout based on the specified parameters.
* If three-state simulation is not required, it performs a two-state simulation with a base number of 2.
* If three-state simulation is required, it performs a three-state simulation with a base number of 3.
* The simulation results are stored in the 'result' object, including additional simulation parameters.
Drewniok marked this conversation as resolved.
Show resolved Hide resolved
*
* @tparam ChargeLyt The type representing the charge layout to simulate.
* @param three_state_simulation_required `True` if a three-state simulation is required, `false` otherwise.
* @param charge_layout A reference to the charge layout to be simulated.
Drewniok marked this conversation as resolved.
Show resolved Hide resolved
*/
template <typename ChargeLyt>
void conduct_simulation(const bool three_state_simulation_required, ChargeLyt& charge_layout)
Drewniok marked this conversation as resolved.
Show resolved Hide resolved
{
Drewniok marked this conversation as resolved.
Show resolved Hide resolved
if (!three_state_simulation_required)
{
result.additional_simulation_parameters.emplace_back("base_number", uint64_t{2});
two_state_simulation(charge_layout);
}
// If positively charged SiDBs can occur in the layout, 3-state simulation is conducted.
else
{
result.additional_simulation_parameters.emplace_back("base_number", uint64_t{3});
three_state_simulation(charge_layout);
}
}
/**
*
* This function is used to generate a layout without the SiDBs that are pre-assigned to be negatively charged in a
* physically-valid layout.
*/
Expand Down
Loading
Loading