qir-alliance/qcor

PassManager called after kernel invocation from kernel

ausbin opened this issue · 0 comments

With the following example program (ghz.cpp),

__qpu__ void cascadingCNOT(qreg q) {
    for (std::size_t i = 1; i < q.size(); i++) {
        CNOT(q[i-1], q[i]);
    }
}
__qpu__ void ghz(qreg q) {
    H(q[0]);
    cascadingCNOT(q);
    Measure(q);
}
int main() {
    set_verbose(true);
    auto q = qalloc(32);
    ghz(q);
    q.print();
}

if you change 32 in the qalloc() to the number of qubits on the backend you're targeting (I was using ibm:ibmq_qasm_simulator), you can hopefully reproduce the following runtime error:

$ ./ghz
terminate called after throwing an instance of 'std::logic_error'
  what():  Not enough physical qubits
Aborted (core dumped)

The root cause of this appears to be the SyntaxHandler generating the following code that unconditionally runs the PassManager:

xacc::internal_compiler::execute_pass_manager();
if (optimize_only) {
	return;
}
if (is_callable) {
	quantum::submit(q.results());
}