2026-08-04 14:24:55 -04:00
|
|
|
module;
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
export module experiment;
|
|
|
|
|
|
|
|
|
|
export namespace experiment {
|
|
|
|
|
struct ExperimentResult {
|
|
|
|
|
std::string experiment_name;
|
|
|
|
|
std::string case_name;
|
|
|
|
|
std::map<std::string, std::string> parameters;
|
|
|
|
|
std::map<std::string, double> metrics;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ExperimentRegistry {
|
|
|
|
|
public:
|
2026-09-01 11:50:13 -04:00
|
|
|
static ExperimentRegistry &instance() {
|
2026-08-04 14:24:55 -04:00
|
|
|
static ExperimentRegistry registry;
|
|
|
|
|
return registry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void add_result(ExperimentResult result) {
|
|
|
|
|
std::scoped_lock lock(m_mutex);
|
|
|
|
|
m_results.push_back(std::move(result));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] std::vector<ExperimentResult> results() const {
|
|
|
|
|
std::scoped_lock lock(m_mutex);
|
|
|
|
|
return m_results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_output_path(std::string output_path) {
|
|
|
|
|
std::scoped_lock lock(m_mutex);
|
|
|
|
|
m_output_path = std::move(output_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] std::string output_path() const {
|
|
|
|
|
std::scoped_lock lock(m_mutex);
|
|
|
|
|
return m_output_path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
mutable std::mutex m_mutex;
|
|
|
|
|
std::vector<ExperimentResult> m_results;
|
|
|
|
|
std::string m_output_path{"accuracy_budget.csv"};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inline void record_experiment_result(
|
2026-09-01 11:50:13 -04:00
|
|
|
const std::string &experiment_name,
|
|
|
|
|
const std::string &case_name,
|
|
|
|
|
std::map<
|
|
|
|
|
std::string,
|
|
|
|
|
std::string> parameters,
|
|
|
|
|
std::map<
|
|
|
|
|
std::string,
|
|
|
|
|
double> metrics
|
2026-08-04 14:24:55 -04:00
|
|
|
) {
|
2026-09-01 11:50:13 -04:00
|
|
|
ExperimentRegistry::instance().add_result(
|
|
|
|
|
{.experiment_name = experiment_name,
|
|
|
|
|
.case_name = case_name,
|
|
|
|
|
.parameters = std::move(parameters),
|
|
|
|
|
.metrics = std::move(metrics)}
|
|
|
|
|
);
|
2026-08-04 14:24:55 -04:00
|
|
|
}
|
2026-09-01 11:50:13 -04:00
|
|
|
} // namespace experiment
|