Commit d1e76020 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

adding help readme to qcor executable

parent cbbc7a8f
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
#include <qalloc>

// Define a multi-register kernel
__qpu__ void bell_multi(qreg q, qreg r) {
  H(q[0]);
  CX(q[0], q[1]);
  H(r[0]);
  CX(r[0], r[1]);
  Measure(q);
  Measure(r);
}

int main() {

  // Create two qubit registers, each size 2
  auto q = qalloc(2);
  auto r = qalloc(2);

  // Run the quantum kernel
  bell_multi(q, r);

  // dump the results
  q.print();
  r.print();
}
 No newline at end of file
+20 −37
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ using namespace clang;
namespace {

std::string qpu_name = "tnqvm";
int shots = 1024;
int shots = 0;

class QCORSyntaxHandler : public SyntaxHandler {
public:
@@ -84,14 +84,20 @@ public:

    // Get Tokens as a string, rewrite code
    // with XACC api calls
    auto kernel_src_and_compiler = qcor::run_token_collector(PP, Toks, function_prototype);
    auto kernel_src_and_compiler =
        qcor::run_token_collector(PP, Toks, function_prototype);
    auto kernel_src = kernel_src_and_compiler.first;
    auto compiler_name = kernel_src_and_compiler.second;

    // std::cout << "HELLO:\n" << kernel_src << "\n";
    // Write new source code in place of the
    // provided quantum code tokens
    OS << "compiler_InitializeXACC(\"" + qpu_name + "\", "+std::to_string(shots)+");\n";
    if (shots > 0) {
      OS << "compiler_InitializeXACC(\"" + qpu_name + "\", " +
                std::to_string(shots) + ");\n";
    } else {
      OS << "compiler_InitializeXACC(\"" + qpu_name + "\");\n";
    }
    for (auto &buf : bufferNames) {
      OS << buf << ".setNameAndStore(\"" + buf + "\");\n";
    }
@@ -103,8 +109,7 @@ public:
    // OS << "optimize(program);\n";

    OS << "if (__execute) {\n";
    OS << "program->updateRuntimeArguments(" << program_parameters[0]; //args...);
    // setRuntimeArguments(" << program_parameters[0];
    OS << "program->updateRuntimeArguments(" << program_parameters[0];
    for (int i = 1; i < program_parameters.size(); i++) {
      OS << ", " << program_parameters[i];
    }
@@ -125,7 +130,9 @@ public:
    OS << ");\n";

    OS << "}\n";
    std::cout << "HELLO:\n" << OS.str() << "\n";
    auto s = OS.str();
    qcor::info("[qcor syntax-handler] Rewriting " + kernel_name + " to\n\n" +
               function_prototype + "{\n" + s.substr(2, s.length()) + "\n}");
  }

  void AddToPredefines(llvm::raw_string_ostream &OS) override {
@@ -139,31 +146,6 @@ public:
  bool HandleTopLevelDecl(DeclGroupRef DG) override { return true; }
};

class DoNothingConsumer2 : public ASTConsumer {
public:
  bool HandleTopLevelDecl(DeclGroupRef DG) override { std::cout << "CONSUMING THIS BITCH\n";return true; }
};



class QCORTEST : public PluginASTAction {
public:
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
                                                 llvm::StringRef) override {
    std::cout << "HERE WE ARE, OPPORTUNITY TO OUTPUT SOURCE MAYBE? \n";
    return std::make_unique<DoNothingConsumer2>();
  }


  bool ParseArgs(const CompilerInstance &CI,
                 const std::vector<std::string> &args) override {
    return true;
  }

  PluginASTAction::ActionType getActionType() override {
    return AddAfterMainAction;
  }
};
class QCORArgs : public PluginASTAction {
public:
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
@@ -171,7 +153,6 @@ public:
    return std::make_unique<DoNothingConsumer>();
  }


  bool ParseArgs(const CompilerInstance &CI,
                 const std::vector<std::string> &args) override {
    for (unsigned i = 0, e = args.size(); i != e; ++i) {
@@ -188,6 +169,8 @@ public:
      } else if (args[i] == "-shots") {
        ++i;
        shots = std::stoi(args[i]);
      } else if (args[i] == "-qcor-verbose") {
        qcor::set_verbose(true);
      }
    }
    return true;
+3 −0
Original line number Diff line number Diff line
@@ -5,6 +5,9 @@

namespace qcor {

void set_verbose(bool verbose) {xacc::set_verbose(verbose);}
void info(const std::string& s) {xacc::info(s);}

std::pair<std::string, std::string>
run_token_collector(clang::Preprocessor &PP, clang::CachedTokens &Toks,
                    const std::string &function_prototype) {
+3 −0
Original line number Diff line number Diff line
@@ -13,6 +13,9 @@ std::pair<std::string, std::string>
run_token_collector(clang::Preprocessor &PP, clang::CachedTokens &Toks,
                    const std::string &function_prototype);

void set_verbose(bool verbose);
void info(const std::string& s);

} // namespace qcor

#endif
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ protected:
    auto tmp_child = qalloc(qreg.size());
    auto val = qcor::__internal__::observe(kernel, observable, tmp_child);
    qreg.addChild(tmp_child);
    return val;
  }
public:
  const std::string name() const override { return "vqe"; }
Loading