Skip to content

Commit

Permalink
change bindArguments interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorii committed Nov 1, 2023
1 parent 81047e0 commit f14634d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 42 deletions.
12 changes: 12 additions & 0 deletions include/API/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
#include <string_view>
#include <unordered_map>

namespace {
enum Action {
None,
DumpAST,
DumpASTPretty,
DumpMLIR,
DumpWaveMem,
GenQEM,
GenQEQEM
};
} // anonymous namespace

namespace qssc {

/// @brief Call the qss-compiler
Expand Down
3 changes: 2 additions & 1 deletion include/HAL/TargetSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef TARGETSYSTEM_H
#define TARGETSYSTEM_H

#include "API/api.h"
#include "Arguments/Arguments.h"

#include "llvm/ADT/Optional.h"
Expand Down Expand Up @@ -92,7 +93,7 @@ class TargetSystem : public Target {
payload::Payload &payload) = 0;

virtual llvm::Optional<qssc::arguments::BindArgumentsImplementationFactory *>
getBindArgumentsImplementationFactory() {
getBindArgumentsImplementationFactory(Action action) {
return llvm::None;
};

Expand Down
11 changes: 0 additions & 11 deletions lib/API/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,6 @@ static llvm::cl::opt<enum InputType> inputType(
llvm::cl::values(clEnumValN(QOBJ, "qobj",
"load the input file as a QOBJ file")));

namespace {
enum Action {
None,
DumpAST,
DumpASTPretty,
DumpMLIR,
DumpWaveMem,
GenQEM,
GenQEQEM
};
} // anonymous namespace
static llvm::cl::opt<enum Action> emitAction(
"emit", llvm::cl::init(Action::None),
llvm::cl::desc("Select the kind of output desired"),
Expand Down
51 changes: 21 additions & 30 deletions lib/API/bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,14 @@ using json = nlohmann::json;
static llvm::cl::OptionCategory qsscBindCat_(" Options for parameter binding",
"Options that binds parameters");

namespace {
enum GenAction { None, GenQEM, GenQEQEM };
} // anonymous namespace

static llvm::cl::opt<enum GenAction> emitGenAction(
"emit", llvm::cl::init(GenAction::None),
llvm::cl::desc("Select method used to generate input"),
// llvm::cl::values(clEnumValN(DumpAST, "ast", "output the AST dump")),
// llvm::cl::values(clEnumValN(DumpASTPretty, "ast-pretty",
// "pretty print the AST")),
// llvm::cl::values(clEnumValN(DumpMLIR, "mlir", "output the MLIR dump")),
// llvm::cl::values(clEnumValN(DumpWaveMem, "wavemem",
// "output the waveform memory")),
llvm::cl::values(clEnumValN(GenAction::GenQEM, "qem",
"a quantum executable module (qem) "
"for execution on hardware")),
llvm::cl::values(
clEnumValN(GenAction::GenQEQEM, "qe-qem",
static llvm::cl::opt<enum Action>
emitAction("emit", llvm::cl::init(Action::None),
llvm::cl::desc("Select method used to generate input"),
llvm::cl::values(clEnumValN(Action::GenQEM, "qem",
"a quantum executable module (qem) "
"for execution on hardware")),
llvm::cl::values(clEnumValN(
Action::GenQEQEM, "qe-qem",
"a target-specific quantum executable module (qeqem) "
"for execution on hardware")));

Expand All @@ -85,8 +75,7 @@ static llvm::cl::opt<std::string>
llvm::cl::cat(qsscBindCat_));

static llvm::cl::opt<std::string>
configPathStr("config",
llvm::cl::desc("configuration path for target."),
configPathStr("config", llvm::cl::desc("configuration path for target."),
llvm::cl::value_desc("configPath"), llvm::cl::init("-"),
llvm::cl::cat(qsscBindCat_));

Expand Down Expand Up @@ -123,8 +112,9 @@ class MapAngleArgumentSource : public qssc::arguments::ArgumentSource {
};

llvm::Error
_bindArguments(std::string_view target, std::string_view configPath,
std::string_view moduleInput, std::string_view payloadOutputPath,
_bindArguments(std::string_view target, Action action,
std::string_view configPath, std::string_view moduleInput,
std::string_view payloadOutputPath,
std::unordered_map<std::string, double> const &arguments,
bool treatWarningsAsErrors, bool enableInMemoryInput,
std::string *inMemoryOutput,
Expand Down Expand Up @@ -155,7 +145,8 @@ _bindArguments(std::string_view target, std::string_view configPath,

MapAngleArgumentSource source(arguments);

auto factory = targetInst.get()->getBindArgumentsImplementationFactory();
auto factory =
targetInst.get()->getBindArgumentsImplementationFactory(action);
if ((!factory.hasValue()) || (factory.getValue() == nullptr)) {
return qssc::emitDiagnostic(
onDiagnostic, qssc::Severity::Error,
Expand All @@ -178,9 +169,9 @@ int qssc::bindArguments(
const std::optional<qssc::DiagnosticCallback> &onDiagnostic) {

if (auto err =
_bindArguments(target, configPath, moduleInput, payloadOutputPath,
arguments, treatWarningsAsErrors, enableInMemoryInput,
inMemoryOutput, onDiagnostic)) {
_bindArguments(target, Action::GenQEM, configPath, moduleInput,
payloadOutputPath, arguments, treatWarningsAsErrors,
enableInMemoryInput, inMemoryOutput, onDiagnostic)) {
llvm::logAllUnhandledErrors(std::move(err), llvm::errs());
return 1;
}
Expand Down Expand Up @@ -210,7 +201,7 @@ llvm::Error bind_(int argc, char const **argv, std::string *outputString,
for (auto &[paramName, paramValue] : inputArgs.items())
argsMap[paramName] = (double)paramValue;

if (emitGenAction == GenAction::None) {
if (emitAction == Action::None) {
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to detect an emit option! Please specify the "
Expand Down Expand Up @@ -247,9 +238,9 @@ llvm::Error bind_(int argc, char const **argv, std::string *outputString,
bool treatWarningsAsErrors = false;
bool enableInMemoryInput = false;

return _bindArguments(targetStr, configPathStr, inputQemFile, outputQemFile,
argsMap, treatWarningsAsErrors, enableInMemoryInput,
nullptr, std::nullopt);
return _bindArguments(targetStr, emitAction, configPathStr, inputQemFile,
outputQemFile, argsMap, treatWarningsAsErrors,
enableInMemoryInput, nullptr, std::nullopt);
}

int qssc::bind(int argc, char const **argv, std::string *outputString,
Expand Down

0 comments on commit f14634d

Please sign in to comment.