To execute this pipeline interactively, ensure the Quanifi NiFi container is running from your project directory:

docker compose up -d

Verify the container status with docker compose ps. Once healthy, navigate to https://localhost:8443/nifi and log in with Username: admin, Password: quanifipassword. For custom processor bundles and building the Qrisp flow, refer to the Docker Quickstart Guide.

Module 2: The Deutsch-Jozsa Algorithm

Learn the quintessential quantum algorithm that proved quantum computers can solve specific computational problems exponentially faster than any classical algorithm.

1. The Problem for Software Engineers

Imagine you are testing a third-party microservice API that accepts an $n$-bit binary payload and returns a single boolean:

def evaluate_flag(x: int) -> bool:
    # Black-box implementation
    ...

The provider promises that this service adheres to one of two behaviors:

  • Constant: It returns the exact same value (always 0 or always 1) for every single possible input.
  • Balanced: It returns 0 for exactly half of the possible inputs, and 1 for the other half.
Computational Model Worst-Case Queries Required For $n=32$ bits
Classical Computing $$\frac{2^n}{2} + 1 = 2^{n-1} + 1$$ $$2,147,483,649\text{ calls}$$
Quantum Computing (Deutsch-Jozsa) $$1\text{ query}$$ $$1\text{ call}$$

In classical computing, even if you test 100 inputs and all return 0, you cannot be certain the 101st input won't return 1. In the worst case, you must check more than half the search space.

The Deutsch-Jozsa algorithm determines whether the function is constant or balanced in exactly 1 single evaluation, regardless of whether $n=3$ or $n=1,000,000$!

2. How the Quantum Magic Works (Without Physics Jargon)

How can a single call know the global property of an entire function? The secret is a technique called Phase Kickback combined with Hadamard Interference.

💡 The Analogy: Audio Waves Canceling Noise

Think of noise-canceling headphones. If two sound waves of equal volume meet in phase (+1 and +1), they amplify. If one wave is inverted (-1 and +1), they completely destroy each other to total silence (0). Deutsch-Jozsa encodes the function's output into the phase (positive or negative sign) of each possible input.

|0⟩ q0 |0⟩ q1 |0⟩ q2 |1⟩ anc H H H H Oracle U_f |x⟩|y ⊕ f(x)⟩ H H H M M M Readout
Figure 2.1: Quantum circuit for the Deutsch-Jozsa algorithm over 3 input qubits plus 1 ancilla.

Step-by-Step Execution:

  1. Initialize in Superposition: All $n$ input qubits start in $\vert 0\rangle$ and pass through a Hadamard ($H$) gate, creating an equal superposition of all $2^n$ possible inputs simultaneously.
  2. The Ancilla Trick (Phase Kickback): A helper qubit (ancilla) is initialized to $\vert 1\rangle$ and flipped with $H$ into $\vert-\rangle = \frac{\vert 0\rangle - \vert 1\rangle}{\sqrt{2}}$. When the oracle gate $U_f$ evaluates $\vert x\rangle \vert y \oplus f(x)\rangle$, the value $f(x)$ is "kicked back" as a phase factor $(-1)^{f(x)}$ onto the input state!
  3. Inverse Hadamard Transform: A second layer of $H$ gates converts the phase differences back into measurable bit amplitudes.
  4. The Decisive Readout Rule:
    • If $f$ is Constant: Every input received the same phase. All paths constructively interfere onto $\vert 00\dots0\rangle$. You will measure all zeros with 100% certainty.
    • If $f$ is Balanced: Exactly half the inputs received a $+1$ phase and half received a $-1$ phase. They completely cancel each other out at $\vert 00\dots0\rangle$! You will measure any non-zero bitstring.

3. Running Deutsch-Jozsa on Quanifi

In Quanifi, this entire workflow runs as an automated data pipeline inside NiFi 2.11:

Deutsch-Jozsa Canvas Pipeline
Figure 2.2: The Deutsch-Jozsa pipeline in Quanifi (NiFi 2.11). ↔ Scroll horizontally to inspect processors • Click to enlarge

Pipeline Components:

  • DJ — Trigger (GenerateFlowFile): Emits a trigger FlowFile to initiate the test run.
  • Qrisp Deutsch-Jozsa (QrispDeutschJozsa): High-level quantum processor. It synthesizes the oracle, compiles the circuit into OpenQASM 2.0, executes the statevector simulation, and attaches verdict attributes.
  • DJ — Report (QuanifiReport): Takes the completed FlowFile, generates a full visual HTML audit card with circuit diagram and probability distributions, and writes it to reports/qrisp-deutsch-jozsa.html.

Triggering the Flow:

  1. Make sure Docker is running (docker compose up -d).
  2. Open NiFi at https://localhost:8443/nifi and enter the Qrisp Components & Textbook Algorithms group.
  3. Right-click on DJ — Trigger and click Run Once (or start and immediately stop it).
  4. Watch the FlowFile move across the queue into Qrisp Deutsch-Jozsa and then into DJ — Report. In ~2 seconds, all queues return to 0.

4. How to Read and Interpret the Results

After the flow finishes, open the generated HTML report file in your browser:

open reports/qrisp-deutsch-jozsa.html

Look at the resulting metadata attributes card:

Attribute Observed Value Meaning for Engineers
deutsch_jozsa.verdict balanced The algorithm's verified classification of the oracle function.
deutsch_jozsa.is_constant false Boolean flag indicating if function was constant.
sim.top_result 100 The measured binary state. Because this is not 000, the function is provably balanced!
sim.top_probability 1.0000 Deterministic probability of measuring the top state.
circuit.format qasm2 The circuit was exported in standard OpenQASM 2.0, ensuring framework portability.
Hands-on Exercise 2.1

Testing a Constant Oracle

Right now, the processor is configured to test a balanced oracle. What happens when we point it at a constant function?

Your Task:

  1. In the NiFi canvas (https://localhost:8443/nifi), right-click on Qrisp Deutsch-Jozsa and click Stop.
  2. Right-click it again, select Configure, and switch to the PROPERTIES tab.
  3. Change the Function Type property from balanced to constant_zero. Click Apply.
  4. Right-click the processor and click Start (it should show a green play icon).
  5. Trigger a new run: right-click DJ — Trigger and select Run Once.
  6. Refresh reports/qrisp-deutsch-jozsa.html. What is the new sim.top_result and deutsch_jozsa.verdict?
👉 Click to Reveal Exercise Solution & Explanation

Solution:

When you inspect the newly appended run card in reports/qrisp-deutsch-jozsa.html, you will see:

  • sim.top_result: 000 (all zeros).
  • sim.top_probability: 1.0000 (100% of the 1024 shots measured 000).
  • deutsch_jozsa.verdict: constant.
  • deutsch_jozsa.is_constant: true.

Why did this happen? In a constant function, $f(x) = 0$ for every input $x$. Because the oracle imparts no relative phase flips across the input states, the inverse Hadamard transform perfectly reconstructs the initial state $\vert 000\rangle$. If even a single shot had measured a non-zero state, we would know with mathematical certainty that the function is not constant.