Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
main_marty_preinit.cpp
Go to the documentation of this file.
1#include "HyperisoMaster.h"
2#include "MartyInterface.h"
4
5#include <filesystem>
6#include <iostream>
7#include <optional>
8#include <string>
9#include <unordered_map>
10
11namespace fs = std::filesystem;
12
13namespace {
14
15struct CliOptions {
16 std::optional<fs::path> marty_path;
17 fs::path lha_file = fs::path(project_root.data()) / "Test" / "InputFiles" / "testinput_thdm.lha";
18 std::string wilson = "C7";
19 std::string model = "SM";
20 double q_match = 81.0;
21 std::optional<fs::path> model_header;
22 bool validate_only = false;
23};
24
25void print_usage(const char* argv0)
26{
27 std::cout
28 << "Usage: " << argv0 << " [options]\n\n"
29 << "Options:\n"
30 << " --marty <path> Existing MARTY install prefix, include/, lib/, marty.h, or libmarty.*\n"
31 << " --lha <path> LHA input file used to initialize Hyperiso\n"
32 << " --model-header <path> MARTY model header used by generated code\n"
33 << " --wilson <name> Wilson coefficient/basis to generate, default: C7\n"
34 << " --model <name> Model name used in generated code, default: SM\n"
35 << " --q <value> Matching scale, default: 81\n"
36 << " --validate-only Resolve/validate MARTY and init Hyperiso, then stop\n"
37 << " -h, --help Show this help\n\n"
38 << "Examples:\n"
39 << " " << argv0 << " --marty /opt/MARTY_INSTALL --validate-only\n"
40 << " " << argv0 << " --marty /opt/MARTY_INSTALL --wilson C7 --model SM --q 81\n";
41}
42
43fs::path default_model_header_from(const MartyRuntimeConfig::InstallInfo& marty)
44{
45 const fs::path installed_header = marty.include_dir / "marty" / "models" / "sm.h";
46 if (fs::exists(installed_header)) {
47 return installed_header;
48 }
49
50 const fs::path bundled_source_header =
51 fs::path(project_tp_root.data()) / "MARTY" / "src" / "MARTY" / "src" / "marty" / "models" / "sm.h";
52 if (fs::exists(bundled_source_header)) {
53 return bundled_source_header;
54 }
55
56 // Last-resort fallback: keep a deterministic path and let MartyInterface's
57 // normal file checks report the precise problem if the user runs generation.
58 return installed_header;
59}
60
61CliOptions parse_args(int argc, char** argv)
62{
63 CliOptions opts;
64
65 const std::unordered_map<std::string, std::string> aliases = {
66 {"--marty-path", "--marty"},
67 {"--marty-install", "--marty"},
68 {"--input", "--lha"},
69 {"--model-path", "--model-header"},
70 {"--Q", "--q"}
71 };
72
73 for (int i = 1; i < argc; ++i) {
74 std::string key = argv[i];
75 if (auto alias = aliases.find(key); alias != aliases.end()) {
76 key = alias->second;
77 }
78
79 auto require_value = [&](const std::string& option) -> std::string {
80 if (i + 1 >= argc) {
81 throw std::runtime_error("Missing value after " + option);
82 }
83 return argv[++i];
84 };
85
86 if (key == "-h" || key == "--help") {
87 print_usage(argv[0]);
88 std::exit(0);
89 } else if (key == "--marty") {
90 opts.marty_path = fs::path(require_value(key));
91 } else if (key == "--lha") {
92 opts.lha_file = fs::path(require_value(key));
93 } else if (key == "--model-header") {
94 opts.model_header = fs::path(require_value(key));
95 } else if (key == "--wilson") {
96 opts.wilson = require_value(key);
97 } else if (key == "--model") {
98 opts.model = require_value(key);
99 } else if (key == "--q") {
100 opts.q_match = std::stod(require_value(key));
101 } else if (key == "--validate-only") {
102 opts.validate_only = true;
103 } else {
104 throw std::runtime_error("Unknown option: " + key);
105 }
106 }
107
108 return opts;
109}
110
111void print_marty_resolution(const MartyRuntimeConfig::InstallInfo& info)
112{
113 std::cout << "MARTY resolution:\n"
114 << " source : " << info.source << "\n"
115 << " requested : " << info.requested_path.string() << "\n"
116 << " prefix : " << info.prefix.string() << "\n"
117 << " include : " << info.include_dir.string() << "\n"
118 << " library : " << info.marty_library.string() << "\n";
119
120 if (info.has_executable) {
121 std::cout << " executable: " << info.marty_executable.string() << "\n";
122 } else {
123 std::cout << " executable: not found, not required by current generated-code pipeline\n";
124 }
125}
126
127} // namespace
128
129int main(int argc, char** argv)
130{
131 try {
132 const CliOptions opts = parse_args(argc, argv);
133
134 HyperisoMaster hyp;
135
136 if (opts.marty_path.has_value()) {
137 // This is the new pre-init API being tested. It validates and stores
138 // the external MARTY installation before Hyperiso initialization.
139 hyp.pre_init_set_marty_path(opts.marty_path->string());
140 }
141
142 auto marty = MartyRuntimeConfig::resolve();
143 if (!marty.valid) {
144 std::cerr << "Invalid MARTY runtime: " << marty.error << "\n";
145 std::cerr << "Pass --marty <MARTY_INSTALL> or build with -DBUILD_WITH_MARTY=ON.\n";
146 return 2;
147 }
148 print_marty_resolution(marty);
149
150 HyperisoConfig config;
151 config.model = Model::SM;
156
157 std::cout << "Initializing Hyperiso with LHA: " << opts.lha_file.string() << "\n";
158 hyp.init(opts.lha_file.string(), config);
159
160 if (opts.validate_only) {
161 std::cout << "Validation finished successfully.\n";
162 return 0;
163 }
164
165 const fs::path model_header = opts.model_header.value_or(default_model_header_from(marty));
166 if (!fs::exists(model_header)) {
167 std::cerr << "Model header not found: " << model_header.string() << "\n";
168 std::cerr << "Pass --model-header <path/to/model.h>.\n";
169 return 3;
170 }
171
172 std::cout << "Running MartyInterface.calculate(" << opts.wilson
173 << ", " << opts.model
174 << ", Q=" << opts.q_match
175 << ")\n";
176 std::cout << "Model header: " << model_header.string() << "\n";
177
178 MartyInterface marty_interface;
179 marty_interface.calculate(
180 opts.wilson,
181 opts.model,
182 opts.q_match,
183 model_header.string()
184 );
185
186 std::cout << "MARTY pipeline finished.\n";
187 return 0;
188 } catch (const std::exception& e) {
189 std::cerr << "Fatal error: " << e.what() << "\n";
190 return 1;
191 }
192}
@ HAS_TH_OBSERVABLE_INPUT
User provided theoretical observable input.
@ HAS_WILSON_INPUT
User provided Wilson coefficient input.
@ IS_LHA_SPECTRUM
Input LHA file already contains a spectrum.
@ HYP_AS_SM_MARTY
If true, use Hyperiso as SM values for Wilson coefficients (up to NNLO).
High-level helpers for initializing and monitoring the Hyperiso framework.
High-level façade around MARTY-based code generation and compilation.
High-level interface to initialize and monitor the main framework configuration.
void init(const std::string &lhaFile, HyperisoConfig config)
Initializes Hyperiso using a LHA file and a full Config object.
void pre_init_set_marty_path(const std::string &martyInstallPath)
Registers an existing MARTY installation before init().
High-level interface to MARTY-based code generation and execution.
void calculate(std::string wilson, std::string model, double Q_match, std::string model_path)
Convenience shortcut to generate, compile, and run the full pipeline.
static InstallInfo resolve()
Resolve the MARTY install that should be used now.
Configuration object controlling model, input flags and optional MARTY resources.
Definition Config.h:24
std::map< ExternalFlag, bool > flags
External flags describing the nature of the inputs.
Definition Config.h:26
Model model
Current model.
Definition Config.h:33
std::filesystem::path marty_executable
std::filesystem::path requested_path
std::filesystem::path marty_library