My question is related to a similar question which did not get a satisfactory answer. Since it was asked in 2020 and was somewhat general, I hope to ask a similar question in 2022 with a concrete piece of code that I would like to get help with.

A quantum oracle $O_f$ is an operation that is usually used by higher-level quantum algorithms like Grover's quantum search, DJ algorithm, etc.

$O_f$ is usually defined in terms of a classical binary function $f:\{0,1\}^n \rightarrow \{0,1\}^m$. So, implementation of an oracle $O_f$ boils down to implementing $f(x)$ as a quantum circuit. I suppose the resulting circuit does not have any quantum effects because we just map a classical circuit to a quantum circuit.

Since $f(x)$ is entirely classical computation, I would like to know if there are compilers that take high-level description of $f(x)$ in terms of the standard programming constructs if, for, while and produce a quantum circuit $O_f$?

For example, I'm interested in getting a quantum circuit for the following function $f:\{0,1\}^n \rightarrow \{0,1\}$ that performs the primality test:

def primality_test(num):
    for i in range(2, int(sqrt(num))+1):
        if num % i == 0: #if remainder is zero, `num` is not prime
           return 0
    return 1

I will appreciate any links to compilers or libraries that can do the conversion.


1 Answer 1


HODL (Higher-Level Oracle Description Language) is a tool that makes it easy to write classical oracles using a C-style syntax. It compiles to OpenQASM 2.0, and more recently, Quantum Intermediate Representation. Here is a medium article I wrote explaining the syntax in more detail: https://medium.com/@atamb/an-introduction-to-creating-quantum-oracles-with-hodl-df0b4233f862. And for the Qiskit library: https://medium.com/@atamb/writing-qiskit-oracles-with-hodl-377859287861.

For example, here is a simple oracle in HODL:

function some_oracle(super var, int num) {
   if(var * num < num) {

HODL only supports classically-controlled for and while loops, but it does support quantum-conditioned if-else statements. It supports all arithmetic, relational and Boolean operators except division and modulo. There's a handy Qiskit library too: https://medium.com/@atamb/writing-qiskit-oracles-with-hodl-377859287861.

Here is the GitHub: https://github.com/at2005/HODL

And language whitepaper: https://arxiv.org/abs/2110.12487

  • 1
    $\begingroup$ Hi ! Thanks! This looks very interesting. Aside working with C, how does HODL compare with qiskit's classicalFunction class? $\endgroup$
    – MonteNero
    Commented Jul 31, 2022 at 19:17
  • $\begingroup$ From the Qiskit documentation: "The type Int1 means the classical function will only operate at bit level...The type Int1 means the classical function will only operate at bit level." $\endgroup$
    – At2005
    Commented Aug 1, 2022 at 0:02
  • $\begingroup$ You can use HODL within Qiskit too pretty easily, just have to import the library: medium.com/@atamb/writing-qiskit-oracles-with-hodl-377859287861 $\endgroup$
    – At2005
    Commented Aug 1, 2022 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.