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

Fix #276: Use regex to parse config file #284

Merged
merged 1 commit into from
Jun 24, 2023
Merged
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
Fix #276: Use regex to parse config file
  • Loading branch information
boschmitt committed Jun 24, 2023
commit d62391f72ea676b8e3080761130ce64ec0210043
21 changes: 9 additions & 12 deletions runtime/cudaq/platform/default/rest/RemoteRESTQPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ std::string get_quake_by_name(const std::string &);

namespace {

constexpr char platformLoweringConfig[] = "PLATFORM_LOWERING_CONFIG";
constexpr char codeEmissionType[] = "CODEGEN_EMISSION";

/// @brief The RemoteRESTQPU is a subtype of QPU that enables the
/// execution of CUDA Quantum kernels on remotely hosted quantum computing
/// services via a REST Client / Server interaction. This type is meant
Expand Down Expand Up @@ -211,15 +208,15 @@ class RemoteRESTQPU : public cudaq::QPU {

// Loop through the file, extract the pass pipeline and CODEGEN Type
auto lines = cudaq::split(configContents, '\n');
for (auto &line : lines) {
if (line.find(platformLoweringConfig) != std::string::npos) {
auto keyVal = cudaq::split(line, '=');
auto value = std::regex_replace(keyVal[1], std::regex("\""), "");
cudaq::info("Appending lowering pipeline: {}", value);
passPipelineConfig += "," + value;
} else if (line.find(codeEmissionType) != std::string::npos) {
auto keyVal = cudaq::split(line, '=');
codegenTranslation = keyVal[1];
std::regex pipeline("PLATFORM_LOWERING_CONFIG\\s*=\\s*\"(\\S+)\"");
boschmitt marked this conversation as resolved.
Show resolved Hide resolved
std::regex emissionType("CODEGEN_EMISSION\\s*=\\s*(\\S+)");
std::smatch match;
for (const std::string &line : lines) {
if (std::regex_search(line, match, pipeline)) {
cudaq::info("Appending lowering pipeline: {}", match[1].str());
passPipelineConfig += "," + match[1].str();
} else if (std::regex_search(line, match, emissionType)) {
codegenTranslation = match[1].str();
}
}

Expand Down