Blog

Circuit of the month Dec 21: creating sophisticated oracles

18
December
,
2021

Oracles are a very important component of quantum computing algorithms. An oracle is essentially a "black box" function that is used as input to another algorithm. For instance, in a Grover search, the oracle identifies which values match the search and which values do not match the search.

Creating a simple oracle is a relatively simple matter. For instance, consider the oracle that is part of the Grover circuit below, part of the Qiskit textbook

The task if this particular oracle is to mark states |101> and |110> so that they be amplified by the next part of the circuit.

But what happens when you want to write a more sophisticated oracle? For instance, assume that you have three quantum variables, a, b and c. Each variable is not a single qubit but a register that is comprised of several qubits. Let's assume that a is 2 qubits wide, b is also 2 qubits wide and c is 3 qubits wide. Our oracle is designed to identify combinations of a, b and c such that (using the Python notation):

 a+ b + (c & 15) % 8 ^ 3 & a ^ 10 == 4

This oracle is more complex and depending on the user preferences, it might look something like this:

You can see the high-level functionality and then some higher level detail in some of the individual blocks.

Such an oracle would take a long time to create.

Unless you are using the Classiq platform. Here's the code that creates this oracle on Classiq:

{
  "qubit_count": 40,
  "max_depth": 1000,
  "logic_flow": [
    {
      "function": "Arithmetic",
      "function_params": {
        "expression": "(a + b + (c & 15)) % 8 ^ 3 & a ^ 10 == 4",
        "definitions": {"a": {"size": 2}, "b": {"size":2}, "c": {"size":3}},
        "method": "pebble",
        "qubit_count": 30
    },
    "add_as_single_gate": false
  ]
}

In addition to the obvious degrees of freedom in writing a different arithmetic expression or changing the width of each variable, one could control the desired number of qubits, the method of creating the oracle, and many additional parameters.

Here's how the full circuit looks like. Hover above the colored blocks below and click on the "+" signs on the blocks below to expand and keep expanding the circuit to your heart's content

Classiq Interactive Visualization - Oracle

Classiq logo

Complex oracle, created on Dec 17, 2021 using the Classiq quantum algorithm design platform

There was some error with the script

Oracles are a very important component of quantum computing algorithms. An oracle is essentially a "black box" function that is used as input to another algorithm. For instance, in a Grover search, the oracle identifies which values match the search and which values do not match the search.

Creating a simple oracle is a relatively simple matter. For instance, consider the oracle that is part of the Grover circuit below, part of the Qiskit textbook

The task if this particular oracle is to mark states |101> and |110> so that they be amplified by the next part of the circuit.

But what happens when you want to write a more sophisticated oracle? For instance, assume that you have three quantum variables, a, b and c. Each variable is not a single qubit but a register that is comprised of several qubits. Let's assume that a is 2 qubits wide, b is also 2 qubits wide and c is 3 qubits wide. Our oracle is designed to identify combinations of a, b and c such that (using the Python notation):

 a+ b + (c & 15) % 8 ^ 3 & a ^ 10 == 4

This oracle is more complex and depending on the user preferences, it might look something like this:

You can see the high-level functionality and then some higher level detail in some of the individual blocks.

Such an oracle would take a long time to create.

Unless you are using the Classiq platform. Here's the code that creates this oracle on Classiq:

{
  "qubit_count": 40,
  "max_depth": 1000,
  "logic_flow": [
    {
      "function": "Arithmetic",
      "function_params": {
        "expression": "(a + b + (c & 15)) % 8 ^ 3 & a ^ 10 == 4",
        "definitions": {"a": {"size": 2}, "b": {"size":2}, "c": {"size":3}},
        "method": "pebble",
        "qubit_count": 30
    },
    "add_as_single_gate": false
  ]
}

In addition to the obvious degrees of freedom in writing a different arithmetic expression or changing the width of each variable, one could control the desired number of qubits, the method of creating the oracle, and many additional parameters.

Here's how the full circuit looks like. Hover above the colored blocks below and click on the "+" signs on the blocks below to expand and keep expanding the circuit to your heart's content

Classiq Interactive Visualization - Oracle

Classiq logo

Complex oracle, created on Dec 17, 2021 using the Classiq quantum algorithm design platform

There was some error with the script

Start Creating Quantum Software Without Limits

contact us