2

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.

MonteNero
  • 2,396
  • 4
  • 22
  • 1
    Qiskit has some functionality for this https://qiskit.org/documentation/stubs/qiskit.circuit.classicalfunction.ClassicalFunction.html – Nikita Nemkov Jul 29 '22 at 08:33

1 Answers1

2

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) {
      mark(var,pi);
   }
}

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

At2005
  • 171
  • 8
  • 1
    Hi ! Thanks! This looks very interesting. Aside working with C, how does HODL compare with qiskit's classicalFunction class? – MonteNero Jul 31 '22 at 19:17
  • 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." – At2005 Aug 01 '22 at 00:02
  • You can use HODL within Qiskit too pretty easily, just have to import the library: https://medium.com/@atamb/writing-qiskit-oracles-with-hodl-377859287861 – At2005 Aug 01 '22 at 00:06