Commit 39576a52 authored by Mccaskey, Alex's avatar Mccaskey, Alex

minor cleanup, setup circuit benchmark to run without accelerator execution.

Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent b6171f6c
Pipeline #114007 passed with stages
in 65 minutes and 2 seconds
......@@ -18,6 +18,12 @@ int main() {
auto q = qalloc(1);
// Run the kernel
testKernel(q);
{
class testKernel t(q);
t.optimize_only = true;
// kernel executed upon destruction,
// will only build up circuit and run pass manager
}
std::cout << "NInsts: " << quantum::program->nInstructions() << "\n";
}
#endif
\ No newline at end of file
......@@ -15,11 +15,11 @@ __qpu__ void ccnot(qreg q) {
// algorithm name and an optimizer.
decompose {
// Create the unitary matrix
UnitaryMatrix ccnot = UnitaryMatrix::Identity(8, 8);
ccnot(6, 6) = 0.0;
ccnot(7, 7) = 0.0;
ccnot(6, 7) = 1.0;
ccnot(7, 6) = 1.0;
UnitaryMatrix ccnot_mat = UnitaryMatrix::Identity(8, 8);
ccnot_mat(6, 6) = 0.0;
ccnot_mat(7, 7) = 0.0;
ccnot_mat(6, 7) = 1.0;
ccnot_mat(7, 6) = 1.0;
}
(q);
......
......@@ -206,6 +206,12 @@ public:
OS << ", " << program_parameters[i];
}
OS << ");\n";
OS << "if (optimize_only) {\n";
OS << "xacc::internal_compiler::execute_pass_manager();\n";
OS << "return;\n";
OS << "}\n";
OS << "if (is_callable) {\n";
if (bufferNames.size() > 1) {
OS << "xacc::AcceleratorBuffer * buffers[" << bufferNames.size()
......
......@@ -45,8 +45,13 @@ protected:
// Turn off destructor execution, useful for
// qcor developers, not to be used by clients / programmers
bool disable_destructor = false;
public:
// Flag to indicate we only want to
// run the pass manager and not execute
bool optimize_only = false;
// Default constructor, takes quantum kernel function arguments
QuantumKernel(Args... args) : args_tuple(std::forward_as_tuple(args...)) {}
......
......@@ -65,7 +65,7 @@ std::vector<PassStat> PassManager::optimize(
stat.gateCountBefore = PassStat::countGates(program);
xacc::ScopeTimer timer(passName, false);
auto xaccOptTransform =
xacc::getService<xacc::IRTransformation>(passName, false);
xacc::getIRTransformation(passName);
// Graciously ignores passes which cannot be located.
if (xaccOptTransform) {
xaccOptTransform->apply(program, nullptr);
......
......@@ -37,6 +37,18 @@ void simplified_qrt_call_two_qbits(const char *gate_name,
{buffer_name_1, tgt_idx});
}
void execute_pass_manager() {
qcor::internal::PassManager passManager(__opt_level);
const auto optData = passManager.optimize(::quantum::program);
if (__print_opt_stats) {
// Prints out the Optimizer Stats if requested.
for (const auto &passData : optData) {
std::cout << passData.toString(false);
}
}
}
} // namespace internal_compiler
} // namespace xacc
namespace quantum {
......@@ -300,14 +312,7 @@ 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_pass_manager();
xacc::internal_compiler::execute(buffer, program);
clearProgram();
}
......
......@@ -133,6 +133,7 @@ void simplified_qrt_call_two_qbits(const char *gate_name,
const char *buffer_name_2,
const std::size_t src_idx,
const std::size_t tgt_idx);
void execute_pass_manager();
class xacc_to_qrt_mapper
: public xacc::quantum::AllGateVisitor,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment