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

🎨 Ensured SiQAD compatibility of SiDB simulation result writer #197

Merged
merged 15 commits into from
May 1, 2023
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
45 changes: 25 additions & 20 deletions include/fiction/io/write_sqd_sim_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class write_sqd_sim_result_impl

return cells;
}

/**
* Writes the engine information to the output stream in XML format.
*/
Expand Down Expand Up @@ -208,6 +209,7 @@ class write_sqd_sim_result_impl

os << siqad::CLOSE_SIM_PARAMS;
}

/**
* Writes the physical locations of all SiDBs to the output stream in XML format.
*/
Expand All @@ -225,6 +227,7 @@ class write_sqd_sim_result_impl

os << siqad::CLOSE_PHYSLOC;
}

/**
* Writes all charge distributions to the output stream in XML format.
*/
Expand All @@ -246,26 +249,27 @@ class write_sqd_sim_result_impl
[](const auto& a, const auto& b) { return a->get_system_energy() < b->get_system_energy(); });

// write the distributions to the output stream
std::for_each(ordered_surface_pointers.cbegin(), ordered_surface_pointers.cend(),
[this](const auto& surface)
{
// obtain the charges in the same order as the cells
std::vector<sidb_charge_state> ordered_charges{};
ordered_charges.reserve(ordered_cells.size());

std::for_each(ordered_cells.cbegin(), ordered_cells.cend(),
[&ordered_charges, &surface](const auto& c)
{ ordered_charges.push_back(surface->get_charge_state(c)); });

os << fmt::format(
siqad::DIST_ENERGY,
surface->get_system_energy(), // system energy
1, // occurrence count
surface->is_physically_valid() ? 1 : 0, // physical validity
sim_result.physical_parameters.base, // simulation state count
charge_configuration_to_string(ordered_charges) // charge distribution as a string
);
});
std::for_each(
ordered_surface_pointers.cbegin(), ordered_surface_pointers.cend(),
[this](const auto& surface)
{
// obtain the charges in the same order as the cells
std::vector<sidb_charge_state> ordered_charges{};
ordered_charges.reserve(ordered_cells.size());

std::for_each(ordered_cells.cbegin(), ordered_cells.cend(),
[&ordered_charges, &surface](const auto& c)
{ ordered_charges.push_back(surface->get_charge_state(c)); });

os << fmt::format(
siqad::DIST_ENERGY,
surface->get_system_energy(), // system energy
1, // occurrence count
surface->is_physically_valid() ? 1 : 0, // physical validity
3, // simulation state count (fixed to 3 since state count = 2 is not supported by SiQAD yet).
charge_configuration_to_string(ordered_charges) // charge distribution as a string
);
});

os << siqad::CLOSE_ELEC_DIST;
}
Expand Down Expand Up @@ -293,6 +297,7 @@ void write_sqd_sim_result(const sidb_simulation_result<Lyt>& sim_result, std::os

p.run();
}

/**
* Writes an SiDB simulation result to an XML file that is used by SiQAD (https://github.com/siqad/siqad), a physical
* simulator for the SiDB technology platform.
Expand Down
2 changes: 1 addition & 1 deletion test/io/write_sqd_sim_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ TEST_CASE("Write simulation result with ExGS simulation", "[sqd-sim-result]")
" </physloc>\n"
" <elec_dist>\n"
" <dist energy=\"0.246027\" count=\"1\" physically_valid=\"1\" "
"state_count=\"2\">-0-0-0-</dist>\n"
"state_count=\"3\">-0-0-0-</dist>\n"
" </elec_dist>\n"
"</sim_out>\n",
FICTION_VERSION, FICTION_REPO, fmt::format("{:%Y-%m-%d %H:%M:%S}", fmt::localtime(std::time(nullptr))),
Expand Down