...
 
Commits (10)
......@@ -29,7 +29,7 @@ Navigate to ``https://localhost:3000`` in your browser to open the IDE and get s
Compiler (C++14): GNU 6.1+, Clang 3.4+
CMake 3.9+ (for build)
XACC: see https://xacc.readthedocs.io/en/latest/install.html#building-xacc
LLVM/Clang [Syntax Handler Fork](https://github.com/hfinkel/llvm-project-csp).
LLVM/Clang [Syntax Handler Fork](https://github.com/ornl-qci/llvm-project-csp).
```
## Linux Build Instructions
......
// Run a suite of circuit optimization benchmarks.
#include "qcor.hpp"
// Need to pass -DTEST_SOURCE_FILE=\"test_case_filename\" and -I resources/ to
// the qcor compiler: e.g.
// qcor -qpu qpp -DTEST_SOURCE_FILE=\"adder_8.qasm\" -I resources/
// circuit_opt_benchmark.cpp
#ifdef TEST_SOURCE_FILE
__qpu__ void testKernel(qreg q) {
using qcor::openqasm;
#include TEST_SOURCE_FILE
}
int main() {
// Allocate just 1 qubit, we don't actually want to run the simulation.
auto q = qalloc(1);
// Run the kernel
testKernel(q);
}
#endif
\ No newline at end of file
# Run circuit optimization benchmarks
import glob
import os
import sys
import subprocess
import pathlib
qcorExe = str(pathlib.Path.home()) + "/.xacc/bin/qcor"
# Configurations:
# Optimization level to run:
OPT_LEVEL = 1
dirPath = os.path.dirname(os.path.realpath(__file__))
listOfSrcFiles = glob.glob(dirPath + "/resources/*.qasm")
listOfTestCases = []
for srcFile in listOfSrcFiles:
testCaseName = os.path.splitext(os.path.basename(srcFile))[0] + ".out"
listOfTestCases.append(testCaseName)
print("Compile test case: ", testCaseName)
process = subprocess.Popen([qcorExe, "-DTEST_SOURCE_FILE=\"" + srcFile + "\"", "-o", testCaseName, "-opt", str(OPT_LEVEL), "-print-opt-stats", "circuit_opt_benchmark.cpp"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
for testCase in listOfTestCases:
print("Run Benchmark: ", testCase)
testExe = dirPath + "/" + testCase
process = subprocess.run([testExe], stdout=sys.stdout, stderr=subprocess.PIPE)
OPENQASM 2.0;
include "qelib1.inc";
qreg qubits[24];
cx qubits[3],qubits[2];
cx qubits[8],qubits[7];
cx qubits[14],qubits[13];
cx qubits[21],qubits[20];
cx qubits[3],qubits[4];
cx qubits[8],qubits[9];
cx qubits[14],qubits[15];
cx qubits[21],qubits[22];
ccx qubits[0],qubits[1],qubits[3];
ccx qubits[5],qubits[6],qubits[8];
ccx qubits[11],qubits[12],qubits[14];
ccx qubits[18],qubits[19],qubits[21];
ccx qubits[2],qubits[3],qubits[4];
ccx qubits[7],qubits[8],qubits[9];
ccx qubits[7],qubits[8],qubits[10];
ccx qubits[13],qubits[14],qubits[15];
ccx qubits[13],qubits[14],qubits[16];
ccx qubits[20],qubits[21],qubits[22];
ccx qubits[20],qubits[21],qubits[23];
cx qubits[6],qubits[5];
cx qubits[12],qubits[11];
cx qubits[19],qubits[18];
cx qubits[5],qubits[8];
cx qubits[11],qubits[14];
cx qubits[18],qubits[21];
ccx qubits[7],qubits[8],qubits[10];
ccx qubits[13],qubits[14],qubits[16];
ccx qubits[20],qubits[21],qubits[23];
ccx qubits[16],qubits[23],qubits[17];
ccx qubits[15],qubits[23],qubits[22];
ccx qubits[4],qubits[10],qubits[9];
ccx qubits[9],qubits[17],qubits[22];
ccx qubits[9],qubits[16],qubits[15];
ccx qubits[16],qubits[23],qubits[17];
ccx qubits[7],qubits[8],qubits[10];
ccx qubits[13],qubits[14],qubits[16];
ccx qubits[20],qubits[21],qubits[23];
cx qubits[5],qubits[8];
cx qubits[11],qubits[14];
cx qubits[18],qubits[21];
cx qubits[6],qubits[5];
cx qubits[12],qubits[11];
cx qubits[19],qubits[18];
ccx qubits[7],qubits[8],qubits[10];
ccx qubits[13],qubits[14],qubits[16];
ccx qubits[20],qubits[21],qubits[23];
ccx qubits[0],qubits[1],qubits[3];
ccx qubits[5],qubits[6],qubits[8];
ccx qubits[11],qubits[12],qubits[14];
ccx qubits[18],qubits[19],qubits[21];
cx qubits[3],qubits[2];
cx qubits[8],qubits[7];
cx qubits[14],qubits[13];
cx qubits[21],qubits[20];
cx qubits[6],qubits[5];
cx qubits[12],qubits[11];
cx qubits[19],qubits[18];
cx qubits[6],qubits[8];
cx qubits[12],qubits[14];
cx qubits[19],qubits[21];
cx qubits[4],qubits[6];
cx qubits[9],qubits[12];
cx qubits[15],qubits[19];
ccx qubits[0],qubits[1],qubits[3];
ccx qubits[5],qubits[6],qubits[8];
ccx qubits[11],qubits[12],qubits[14];
ccx qubits[18],qubits[19],qubits[21];
cx qubits[3],qubits[2];
cx qubits[8],qubits[7];
cx qubits[14],qubits[13];
cx qubits[21],qubits[20];
ccx qubits[0],qubits[1],qubits[3];
ccx qubits[5],qubits[6],qubits[8];
ccx qubits[11],qubits[12],qubits[14];
ccx qubits[18],qubits[19],qubits[21];
cx qubits[6],qubits[5];
cx qubits[12],qubits[11];
cx qubits[19],qubits[18];
cx qubits[4],qubits[6];
cx qubits[9],qubits[12];
cx qubits[15],qubits[19];
cx qubits[6],qubits[8];
cx qubits[12],qubits[14];
cx qubits[19],qubits[21];
cx qubits[1],qubits[0];
cx qubits[6],qubits[5];
cx qubits[12],qubits[11];
cx qubits[19],qubits[18];
x qubits[0];
x qubits[2];
x qubits[5];
x qubits[7];
x qubits[11];
x qubits[13];
cx qubits[3],qubits[2];
cx qubits[8],qubits[7];
cx qubits[14],qubits[13];
ccx qubits[0],qubits[1],qubits[3];
ccx qubits[5],qubits[6],qubits[8];
ccx qubits[11],qubits[12],qubits[14];
cx qubits[6],qubits[5];
cx qubits[12],qubits[11];
ccx qubits[7],qubits[8],qubits[10];
ccx qubits[13],qubits[14],qubits[16];
cx qubits[5],qubits[8];
cx qubits[11],qubits[14];
ccx qubits[7],qubits[8],qubits[10];
ccx qubits[13],qubits[14],qubits[16];
ccx qubits[9],qubits[16],qubits[15];
ccx qubits[4],qubits[10],qubits[9];
ccx qubits[7],qubits[8],qubits[10];
ccx qubits[13],qubits[14],qubits[16];
cx qubits[5],qubits[8];
cx qubits[11],qubits[14];
ccx qubits[7],qubits[8],qubits[10];
ccx qubits[13],qubits[14],qubits[16];
cx qubits[6],qubits[5];
cx qubits[12],qubits[11];
ccx qubits[7],qubits[8],qubits[9];
ccx qubits[13],qubits[14],qubits[15];
ccx qubits[2],qubits[3],qubits[4];
ccx qubits[0],qubits[1],qubits[3];
ccx qubits[5],qubits[6],qubits[8];
ccx qubits[11],qubits[12],qubits[14];
cx qubits[3],qubits[4];
cx qubits[8],qubits[9];
cx qubits[14],qubits[15];
cx qubits[3],qubits[2];
cx qubits[8],qubits[7];
cx qubits[14],qubits[13];
x qubits[0];
x qubits[2];
x qubits[5];
x qubits[7];
x qubits[11];
x qubits[13];
OPENQASM 2.0;
include "qelib1.inc";
qreg qubits[9];
x qubits[5];
h qubits[0];
h qubits[1];
h qubits[2];
h qubits[3];
h qubits[4];
x qubits[4];
x qubits[0];
x qubits[1];
ccx qubits[0],qubits[1],qubits[6];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[3],qubits[7],qubits[8];
h qubits[5];
ccx qubits[4],qubits[8],qubits[5];
ccx qubits[3],qubits[7],qubits[8];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[0],qubits[1],qubits[6];
x qubits[4];
x qubits[0];
x qubits[1];
h qubits[0];
h qubits[1];
h qubits[2];
h qubits[3];
h qubits[4];
x qubits[4];
x qubits[0];
x qubits[1];
x qubits[2];
x qubits[3];
ccx qubits[0],qubits[1],qubits[6];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[3],qubits[7],qubits[4];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[0],qubits[1],qubits[6];
x qubits[4];
x qubits[0];
x qubits[1];
x qubits[2];
x qubits[3];
h qubits[0];
h qubits[1];
h qubits[2];
h qubits[3];
h qubits[4];
x qubits[4];
x qubits[0];
x qubits[1];
ccx qubits[0],qubits[1],qubits[6];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[3],qubits[7],qubits[8];
ccx qubits[4],qubits[8],qubits[5];
ccx qubits[3],qubits[7],qubits[8];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[0],qubits[1],qubits[6];
x qubits[4];
x qubits[0];
x qubits[1];
h qubits[0];
h qubits[1];
h qubits[2];
h qubits[3];
h qubits[4];
x qubits[4];
x qubits[0];
x qubits[1];
x qubits[2];
x qubits[3];
ccx qubits[0],qubits[1],qubits[6];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[3],qubits[7],qubits[4];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[0],qubits[1],qubits[6];
x qubits[4];
x qubits[0];
x qubits[1];
x qubits[2];
x qubits[3];
h qubits[0];
h qubits[1];
h qubits[2];
h qubits[3];
h qubits[4];
x qubits[4];
x qubits[0];
x qubits[1];
ccx qubits[0],qubits[1],qubits[6];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[3],qubits[7],qubits[8];
ccx qubits[4],qubits[8],qubits[5];
ccx qubits[3],qubits[7],qubits[8];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[0],qubits[1],qubits[6];
x qubits[4];
x qubits[0];
x qubits[1];
h qubits[0];
h qubits[1];
h qubits[2];
h qubits[3];
h qubits[4];
x qubits[4];
x qubits[0];
x qubits[1];
x qubits[2];
x qubits[3];
ccx qubits[0],qubits[1],qubits[6];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[3],qubits[7],qubits[4];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[0],qubits[1],qubits[6];
x qubits[4];
x qubits[0];
x qubits[1];
x qubits[2];
x qubits[3];
h qubits[0];
h qubits[1];
h qubits[2];
h qubits[3];
h qubits[4];
x qubits[4];
x qubits[0];
x qubits[1];
ccx qubits[0],qubits[1],qubits[6];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[3],qubits[7],qubits[8];
ccx qubits[4],qubits[8],qubits[5];
ccx qubits[3],qubits[7],qubits[8];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[0],qubits[1],qubits[6];
x qubits[4];
x qubits[0];
x qubits[1];
h qubits[0];
h qubits[1];
h qubits[2];
h qubits[3];
h qubits[4];
x qubits[4];
x qubits[0];
x qubits[1];
x qubits[2];
x qubits[3];
ccx qubits[0],qubits[1],qubits[6];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[3],qubits[7],qubits[4];
ccx qubits[2],qubits[6],qubits[7];
ccx qubits[0],qubits[1],qubits[6];
x qubits[4];
x qubits[0];
x qubits[1];
x qubits[2];
x qubits[3];
h qubits[0];
h qubits[1];
h qubits[2];
h qubits[3];
h qubits[4];
This diff is collapsed.
FROM xacc/deploy-base
run apt-get update && apt-get install -y ninja-build \
&& git clone https://github.com/hfinkel/llvm-project-csp llvm \
&& git clone https://github.com/ornl-qci/llvm-project-csp llvm \
&& cd llvm && mkdir build && cd build \
&& cmake -G Ninja ../llvm -DCMAKE_INSTALL_PREFIX=$HOME/.llvm -DBUILD_SHARED_LIBS=TRUE -DLLVM_ENABLE_DUMP=TRUE -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS=clang \
&& cmake --build . --target install \
......
......@@ -113,9 +113,7 @@ std::string run_token_collector(clang::Preprocessor &PP,
i++;
std::vector<std::string> arguments;
while (Toks[i].isNot(clang::tok::r_paren)) {
std::cout << "TOKEN HERE: " << PP.getSpelling(Toks[i]) << "\n";
if (Toks[i].isNot(clang::tok::comma)) {
std::cout << "Adding " << PP.getSpelling(Toks[i]) << " to args.\n";
arguments.push_back(PP.getSpelling(Toks[i]));
}
i++;
......
......@@ -83,8 +83,6 @@ void UnitaryTokenCollector::collect(clang::Preprocessor &PP,
}
ss << "\n";
std::cout << "HOWDY: " << var_name << ", " << bufferNames[0] << "\n";
std::cout << ss.str() << "\n";
// Add the qfast decomp and hook up to the qrt program.
ss << "auto decomposed_program = "
"__internal__::decompose_unitary(decompose_algo_name, "
......
......@@ -21,6 +21,13 @@ public:
internal_startup() {
#ifdef __internal__qcor__compile__backend
quantum::initialize(__internal__qcor__compile__backend, "empty");
#endif
#ifdef __internal__qcor__compile__opt__level
xacc::internal_compiler::__opt_level =
__internal__qcor__compile__opt__level;
#endif
#ifdef __internal__qcor__compile__opt__print__stats
xacc::internal_compiler::__print_opt_stats = true;
#endif
}
};
......
#include "pass_manager.hpp"
#include "InstructionIterator.hpp"
#include "xacc.hpp"
#include "xacc_service.hpp"
#include <iomanip>
#include <numeric>
namespace {
std::string
printGateCountComparison(const std::unordered_map<std::string, int> &before,
const std::unordered_map<std::string, int> &after) {
std::stringstream stream;
const size_t nbColumns = 3;
const size_t columnWidth = 8;
const auto totalWidth = nbColumns * columnWidth + 8;
stream << std::string(totalWidth, '-') << "\n";
// Print headers:
stream << "| " << std::left << std::setw(8) << "GATE"
<< " |";
stream << std::left << std::setw(8) << "BEFORE"
<< " |";
stream << std::left << std::setw(8) << "AFTER"
<< " |\n";
stream << std::string(totalWidth, '-') << "\n";
const auto printEachRow = [&](const std::string &gateName, int countBefore,
int countAfter) {
stream << "| " << std::setw(8) << gateName << " |";
stream << std::setw(8) << countBefore << " |";
stream << std::setw(8) << countAfter << " |\n";
};
for (const auto &[gateName, countBefore] : before) {
const auto iter = after.find(gateName);
const auto countAfter = (iter == after.end()) ? 0 : iter->second;
printEachRow(gateName, countBefore, countAfter);
}
stream << std::string(totalWidth, '-') << "\n";
return stream.str();
}
} // namespace
namespace qcor {
namespace internal {
PassManager::PassManager(int level) : m_level(level) {}
std::vector<PassStat> PassManager::optimize(
std::shared_ptr<xacc::CompositeInstruction> program) const {
std::vector<PassStat> passData;
// Selects the list of passes based on the optimization level.
const auto passesToRun = [&]() {
if (m_level == 1) {
return std::vector<std::string>(std::begin(LEVEL1_PASSES),
std::end(LEVEL1_PASSES));
} else if (m_level == 2) {
return std::vector<std::string>(std::begin(LEVEL2_PASSES),
std::end(LEVEL2_PASSES));
}
return std::vector<std::string>();
}();
for (const auto &passName : passesToRun) {
PassStat stat;
stat.passName = passName;
// Counts gate before:
stat.gateCountBefore = PassStat::countGates(program);
xacc::ScopeTimer timer(passName, false);
auto xaccOptTransform =
xacc::getService<xacc::IRTransformation>(passName, false);
// Graciously ignores passes which cannot be located.
if (xaccOptTransform) {
xaccOptTransform->apply(program, nullptr);
}
// Stores the elapsed time.
stat.wallTimeMs = timer.getDurationMs();
// Counts gate after:
stat.gateCountAfter = PassStat::countGates(program);
passData.emplace_back(std::move(stat));
}
return passData;
}
std::unordered_map<std::string, int> PassStat::countGates(
const std::shared_ptr<xacc::CompositeInstruction> &program) {
std::unordered_map<std::string, int> gateCount;
xacc::InstructionIterator iter(program);
while (iter.hasNext()) {
auto next = iter.next();
if (!next->isComposite()) {
if (gateCount.find(next->name()) == gateCount.end()) {
gateCount[next->name()] = 1;
} else {
gateCount[next->name()] += 1;
}
}
}
return gateCount;
}
std::string PassStat::toString(bool shortForm) const {
const auto countNumberOfGates =
[](const std::unordered_map<std::string, int> &gateCount) {
return std::accumulate(gateCount.begin(), gateCount.end(), 0,
[](const int previousSum, const auto &element) {
return previousSum + element.second;
});
};
std::stringstream ss;
const std::string separator(40, '*');
ss << separator << "\n";
ss << std::string((separator.size() - passName.size()) / 2, ' ') << passName
<< "\n";
ss << separator << "\n";
ss << " - Elapsed time: " << wallTimeMs << " [ms]\n";
ss << " - Number of Gates Before: " << countNumberOfGates(gateCountBefore)
<< "\n";
ss << " - Number of Gates After: " << countNumberOfGates(gateCountAfter)
<< "\n";
if (!shortForm) {
// Prints the full gate count table if required (long form)
ss << printGateCountComparison(gateCountBefore, gateCountAfter);
}
return ss.str();
}
} // namespace internal
} // namespace qcor
\ No newline at end of file
#pragma once
#include <memory>
#include <unordered_map>
#include <vector>
namespace xacc {
class CompositeInstruction;
}
namespace qcor {
namespace internal {
// Stats about an optimization pass:
struct PassStat {
// Name of the pass
std::string passName;
// Count per gate
std::unordered_map<std::string, int> gateCountBefore;
std::unordered_map<std::string, int> gateCountAfter;
// Elapsed-time of this pass.
double wallTimeMs;
// Helper to collect stats.
static std::unordered_map<std::string, int>
countGates(const std::shared_ptr<xacc::CompositeInstruction> &program);
// Pretty printer.
std::string toString(bool shortForm = true) const;
};
class PassManager {
public:
PassManager(int level);
// Optimizes the input program.
// Returns the full statistics about all the passes that have been executed.
std::vector<PassStat>
optimize(std::shared_ptr<xacc::CompositeInstruction> program) const;
// List of passes for level 1:
// Ordered list of passes to be executed.
// Can have duplicated entries (run multiple times).
static const constexpr char *const LEVEL1_PASSES[] = {
"rotation-folding",
// Merge single-qubit gates before running the circuit-optimizer
// so that there are potentially more patterns emerged.
"single-qubit-gate-merging",
"circuit-optimizer",
};
// Level 2 is experimental, brute-force optimization
// which could result in long runtime.
static const constexpr char *const LEVEL2_PASSES[] = {
"rotation-folding",
"single-qubit-gate-merging",
"circuit-optimizer",
// Try to look for any two-qubit blocks
// which can be simplified.
"two-qubit-block-merging",
// Re-run those simpler optimizers to
// make sure all simplification paterns are captured.
"single-qubit-gate-merging",
"circuit-optimizer",
};
private:
int m_level;
};
} // namespace internal
} // namespace qcor
\ No newline at end of file
#include "qrt.hpp"
#include "Instruction.hpp"
#include "PauliOperator.hpp"
#include "pass_manager.hpp"
#include "xacc.hpp"
#include "xacc_internal_compiler.hpp"
#include "xacc_service.hpp"
#include <Eigen/Dense>
#include <Utils.hpp>
std::vector<int> xacc::internal_compiler::__controlledIdx = {};
namespace xacc {
namespace internal_compiler {
// Extern vars:
int __opt_level = 0;
bool __print_opt_stats = false;
std::vector<int> __controlledIdx = {};
void simplified_qrt_call_one_qbit(const char *gate_name,
const char *buffer_name,
const std::size_t idx) {
......@@ -296,6 +300,14 @@ void exp(qreg q, const double theta, std::shared_ptr<xacc::Observable> H) {
}
void submit(xacc::AcceleratorBuffer *buffer) {
qcor::internal::PassManager passManager(__opt_level);
const auto optData = passManager.optimize(program);
if (__print_opt_stats) {
// Prints out the Optimizer Stats if requested.
for (const auto &passData : optData) {
std::cout << passData.toString(false);
}
}
xacc::internal_compiler::execute(buffer, program);
clearProgram();
}
......
......@@ -19,23 +19,24 @@ class Observable;
namespace quantum {
// This represents the public API for the xacc-enabled
// qcor quantum runtime library. The goal here is to provide
// and API that compilers can translate high-level
// quantum kernel language representations to
// (written in openqasm, quil, xasm, etc). The implementation of this API
// seeks to build up an xacc::CompositeInstruction with each individual
// quantum instruction invocation. Once done, clients can invoke
// the submit method to launch the built up program the
// user specified backend.
// This represents the public API for the xacc-enabled
// qcor quantum runtime library. The goal here is to provide
// and API that compilers can translate high-level
// quantum kernel language representations to
// (written in openqasm, quil, xasm, etc). The implementation of this API
// seeks to build up an xacc::CompositeInstruction with each individual
// quantum instruction invocation. Once done, clients can invoke
// the submit method to launch the built up program the
// user specified backend.
// Clients must invoke initialize before building up the CompositeInstruction.
// This call will take the name of the backend and the name of the CompositeInstruction.
// This call will take the name of the backend and the name of the
// CompositeInstruction.
// Note the qubit type is a typedef from xacc, falls back to a
// std::pair<std::string, std::size_t> where the string represents
// the variable name of the qubit register the qubit belongs to, and the
// size_t represents the qubit index in that register.
// Note the qubit type is a typedef from xacc, falls back to a
// std::pair<std::string, std::size_t> where the string represents
// the variable name of the qubit register the qubit belongs to, and the
// size_t represents the qubit index in that register.
extern std::shared_ptr<xacc::CompositeInstruction> program;
extern std::shared_ptr<xacc::IRProvider> provider;
......@@ -50,7 +51,7 @@ void one_qubit_inst(const std::string &name, const qubit &qidx,
void two_qubit_inst(const std::string &name, const qubit &qidx1,
const qubit &qidx2, std::vector<double> parameters = {});
// Common single-qubit gates.
// Common single-qubit gates.
void h(const qubit &qidx);
void x(const qubit &qidx);
void y(const qubit &qidx);
......@@ -66,7 +67,8 @@ void ry(const qubit &qidx, const double theta);
void rz(const qubit &qidx, const double theta);
// U1(theta) gate
void u1(const qubit &qidx, const double theta);
void u3(const qubit& qidx, const double theta, const double phi, const double lambda);
void u3(const qubit &qidx, const double theta, const double phi,
const double lambda);
// Measure-Z
void mz(const qubit &qidx);
......@@ -78,16 +80,16 @@ void cz(const qubit &src_idx, const qubit &tgt_idx);
void ch(const qubit &src_idx, const qubit &tgt_idx);
void swap(const qubit &src_idx, const qubit &tgt_idx);
// Common parameterized 2 qubit gates.
// Common parameterized 2 qubit gates.
void cphase(const qubit &src_idx, const qubit &tgt_idx, const double theta);
void crz(const qubit &src_idx, const qubit &tgt_idx, const double theta);
// exponential of i * theta * H, where H is an Observable pointer
void exp(qreg q, const double theta, xacc::Observable& H);
void exp(qreg q, const double theta, xacc::Observable &H);
void exp(qreg q, const double theta, xacc::Observable *H);
void exp(qreg q, const double theta, std::shared_ptr<xacc::Observable> H);
// Submission API. Submit the constructed CompositeInstruction operating
// Submission API. Submit the constructed CompositeInstruction operating
// on the provided AcceleratorBuffer(s) (note qreg wraps an AcceleratorBuffer)
void submit(xacc::AcceleratorBuffer *buffer);
void submit(xacc::AcceleratorBuffer **buffers, const int nBuffers);
......@@ -109,6 +111,15 @@ namespace internal_compiler {
// Current runtime controlled bit indices
// (if the current kernel is wrapped in a Controlled block)
extern std::vector<int> __controlledIdx;
// Optimization level: parsed from command line input.
// Convention:
// 0 : no optimization
// 1 : standard optimization (within reasonable walltime limit)
// 2 : extensive optimization (TBD)
extern int __opt_level;
// Should we print out the circuit optimizer stats.
// Disabled by default. Enabled by qcor CLI option.
extern bool __print_opt_stats;
void simplified_qrt_call_one_qbit(const char *gate_name,
const char *buffer_name,
......@@ -123,8 +134,9 @@ void simplified_qrt_call_two_qbits(const char *gate_name,
const std::size_t src_idx,
const std::size_t tgt_idx);
class xacc_to_qrt_mapper : public xacc::quantum::AllGateVisitor,
public xacc::InstructionVisitor<xacc::quantum::Circuit> {
class xacc_to_qrt_mapper
: public xacc::quantum::AllGateVisitor,
public xacc::InstructionVisitor<xacc::quantum::Circuit> {
protected:
std::string &buffer_name_to_measure;
......
......@@ -76,6 +76,21 @@ def main(argv=None):
sys.argv.remove('-print-qir')
sHandlerArgs += ['-Xclang', '-load', '-Xclang', '@CMAKE_INSTALL_PREFIX@/qopt-plugins/libprint_llvm_qir.so']
# Optimization level for flattened (runtime) kernel
# Default: 0 (no optimization)
qrtOptLevel = 0
if '-opt' in sys.argv[1:]:
sidx = sys.argv.index('-opt')
qrtOptLevel = sys.argv[sidx+1]
sys.argv.remove(qrtOptLevel)
sys.argv.remove('-opt')
sys.argv += ['-D__internal__qcor__compile__opt__level='+qrtOptLevel]
# Enable runtime kernel optimization stats print-out:
# i.e. passes that are executed and their info (walltime, gate count reduction, etc.)
if '-print-opt-stats' in sys.argv[1:]:
sys.argv.remove('-print-opt-stats')
sys.argv += ['-D__internal__qcor__compile__opt__print__stats']
# Get the filename we are compiling or the object file
filename = ''
fileType = ''
......