Skip to content

Commit 4b0ded7

Browse files
authored
Add an option to emit target-specific payload
A new option ``-emit=qe-qem`` (Quantum Engine QEM) is introduced for qss-compiler to look up PayLoad from PayloadRegistry with a target name. If no Payload is set, error is thrown.
2 parents e4fc918 + 7e04d58 commit 4b0ded7

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

lib/API/api.cpp

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,15 @@ static llvm::cl::opt<enum InputType> inputType(
121121
"load the input file as a QOBJ file")));
122122

123123
namespace {
124-
enum Action { None, DumpAST, DumpASTPretty, DumpMLIR, DumpWaveMem, GenQEM };
124+
enum Action {
125+
None,
126+
DumpAST,
127+
DumpASTPretty,
128+
DumpMLIR,
129+
DumpWaveMem,
130+
GenQEM,
131+
GenQEQEM
132+
};
125133
} // anonymous namespace
126134
static llvm::cl::opt<enum Action> emitAction(
127135
"emit", llvm::cl::init(Action::None),
@@ -134,10 +142,14 @@ static llvm::cl::opt<enum Action> emitAction(
134142
"output the waveform memory")),
135143
llvm::cl::values(clEnumValN(GenQEM, "qem",
136144
"generate a quantum executable module (qem) "
137-
"for execution on hardware")));
145+
"for execution on hardware")),
146+
llvm::cl::values(clEnumValN(
147+
GenQEQEM, "qe-qem",
148+
"generate a target-specific quantum executable module (qeqem) "
149+
"for execution on hardware")));
138150

139151
namespace qss {
140-
enum FileExtension { None, AST, ASTPRETTY, QASM, QOBJ, MLIR, WMEM, QEM };
152+
enum FileExtension { None, AST, ASTPRETTY, QASM, QOBJ, MLIR, WMEM, QEM, QEQEM };
141153
} // namespace qss
142154

143155
auto fileExtensionToStr(const qss::FileExtension &inExt) -> std::string {
@@ -163,6 +175,9 @@ auto fileExtensionToStr(const qss::FileExtension &inExt) -> std::string {
163175
case qss::FileExtension::QEM:
164176
return "qem";
165177
break;
178+
case qss::FileExtension::QEQEM:
179+
return "qeqem";
180+
break;
166181
default:
167182
return "none";
168183
break;
@@ -204,6 +219,9 @@ auto fileExtensionToAction(const qss::FileExtension &inExt) -> Action {
204219
case qss::FileExtension::QEM:
205220
return Action::GenQEM;
206221
break;
222+
case qss::FileExtension::QEQEM:
223+
return Action::GenQEQEM;
224+
break;
207225
default:
208226
break;
209227
}
@@ -225,6 +243,8 @@ auto strToFileExtension(const std::string &extStr) -> qss::FileExtension {
225243
return qss::FileExtension::WMEM;
226244
if (extStr == "qem" || extStr == "QEM")
227245
return qss::FileExtension::QEM;
246+
if (extStr == "qeqem" || extStr == "QEQEM")
247+
return qss::FileExtension::QEQEM;
228248
return qss::FileExtension::None;
229249
}
230250

@@ -535,20 +555,29 @@ compile_(int argc, char const **argv, std::string *outputString,
535555
auto outputFile = mlir::openOutputFile(outputFilename, &errorMessage);
536556
std::unique_ptr<qssc::payload::Payload> payload = nullptr;
537557

538-
if (emitAction == Action::GenQEM) {
558+
if (emitAction == Action::GenQEQEM && !config.targetName.has_value())
559+
return llvm::createStringError(
560+
llvm::inconvertibleErrorCode(),
561+
"Unsupported target-specific payload: no target");
562+
if (emitAction == Action::GenQEM || emitAction == Action::GenQEQEM) {
563+
const std::filesystem::path payloadPath(outputFilename.c_str());
564+
const std::string fNamePrefix = payloadPath.stem();
565+
const auto payloadName =
566+
(emitAction == Action::GenQEM) ? "ZIP" : config.targetName.value();
567+
auto payloadInfo =
568+
qssc::payload::registry::PayloadRegistry::lookupPluginInfo(payloadName);
569+
if (payloadInfo == llvm::None)
570+
return llvm::createStringError(llvm::inconvertibleErrorCode(),
571+
"Unsupported target-specific payload: " +
572+
payloadName);
539573
if (outputFilename == "-") {
540-
auto payloadInfo =
541-
qssc::payload::registry::PayloadRegistry::lookupPluginInfo("ZIP");
542574
payload = std::move(
543575
payloadInfo.getValue()->createPluginInstance(llvm::None).get());
544576
} else {
545-
const std::filesystem::path payloadPath(outputFilename.c_str());
546-
const std::string fNamePrefix = payloadPath.stem();
547-
const qssc::payload::PayloadConfig config{fNamePrefix, fNamePrefix};
548-
auto payloadInfo =
549-
qssc::payload::registry::PayloadRegistry::lookupPluginInfo("ZIP");
550-
payload =
551-
std::move(payloadInfo.getValue()->createPluginInstance(config).get());
577+
const qssc::payload::PayloadConfig payloadConfig{fNamePrefix,
578+
fNamePrefix};
579+
payload = std::move(
580+
payloadInfo.getValue()->createPluginInstance(payloadConfig).get());
552581
}
553582
}
554583

0 commit comments

Comments
 (0)