Quick Example
Deutsch-Jozsa: Quantum Circuit Example
Constant vs balanced function
What this example teaches
Identify the fixed balanced oracle f(x)=x.
Expected result
Input wire q0 is always 1. The browser shows all wires: 10 and 11 each have ideal probability 1/2; the last bit is an auxiliary wire.
Browser bit strings list physical wires q0 first, including auxiliary wires. Native classical-register strings can use another order; inspect the declared measurements.
These are ideal probabilities. Sampled frequencies fluctuate when more than one outcome is possible; they need not match percentages exactly. An ideal outcome with probability 100% has no finite-shot variation. Hardware noise is a separate effect.
Try the example
The link opens the editor. Save existing work, then choose Examples → Deutsch-Jozsa → framework. Click Run, choose an available browser simulator, then click Run in browser. The link does not preselect or execute the example.
Scope and limitations
- The oracle is the fixed one-bit balanced function f(x)=x; no arbitrary black-box function is accepted.
These expected answers describe the fixed circuit. This page does not establish a completed hosted or hardware run. Read the user guide for this example.
Inspect and download the circuit
Inspect the same fixed circuit in five frameworks. Browser execution translates supported circuit definitions into OpenQASM; it does not run general Python. Outside Marqov, Qiskit, Cirq, and Marqov snippets need a separate simulator invocation. PennyLane invokes its QNode and stores sampled counts in result.
OpenQASM
// Deutsch-Jozsa — determine if f(x) is constant or balanced
// Oracle: f(x) = x (balanced)
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
creg c[1];
// Initialize: input in |+>, output in |->
h q[0];
x q[1];
h q[1];
// Oracle: CNOT implements f(x) = x
cx q[0],q[1];
// Interference
h q[0];
// Measure input qubit: 0 = constant, 1 = balanced
measure q[0] -> c[0];
Download OpenQASM circuitQiskit
# Deutsch-Jozsa — determine if f(x) is constant or balanced
# Oracle: f(x) = x (balanced)
from qiskit import QuantumCircuit
qc = QuantumCircuit(2, 1)
# Initialize: input in |+>, output in |->
qc.h(0)
qc.x(1)
qc.h(1)
# Oracle: CNOT implements f(x) = x
qc.cx(0, 1)
# Interference
qc.h(0)
# Measure: 0 = constant, 1 = balanced
qc.measure(0, 0)
Download Qiskit circuitCirq
# Deutsch-Jozsa — determine if f(x) is constant or balanced
# Oracle: f(x) = x (balanced)
import cirq
q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit([
# Initialize: input in |+>, output in |->
cirq.H(q0),
cirq.X(q1),
cirq.H(q1),
# Oracle: CNOT implements f(x) = x
cirq.CNOT(q0, q1),
# Interference
cirq.H(q0),
# Measure: 0 = constant, 1 = balanced
cirq.measure(q0, key="result"),
])
Download Cirq circuitPennyLane
# Deutsch-Jozsa — determine if f(x) is constant or balanced
# Oracle: f(x) = x (balanced)
import pennylane as qml
dev = qml.device("default.qubit", wires=2, shots=1000)
@qml.qnode(dev)
def deutsch_jozsa():
# Initialize: input in |+>, output in |->
qml.Hadamard(wires=0)
qml.PauliX(wires=1)
qml.Hadamard(wires=1)
# Oracle: CNOT implements f(x) = x
qml.CNOT(wires=[0, 1])
# Interference
qml.Hadamard(wires=0)
# Measure: 0 = constant, 1 = balanced
return qml.counts(wires=[0])
result = deutsch_jozsa()
Download PennyLane circuitMarqov
# Deutsch-Jozsa — determine if f(x) is constant or balanced
# Oracle: f(x) = x (balanced)
from marqov import Circuit
circuit = (
Circuit()
.h(0).x(1).h(1) # Initialize
.cnot(0, 1) # Oracle
.h(0) # Interference
)
Download Marqov circuitSources and provenance
These references explain the concept and gate conventions. The snippets originate in Marqov's internal example collection; an upstream code attribution has not been established.
Snapshot identity
- Source revision
df5a80cd474144684bf69dbda237b28ce40cc48c- Example version
8de97e8303d9529f5d1ba5c27b71c3e4e11b2ff5251c5b49101990584509c1c1
The source revision identifies the editor collection used for this snapshot. The example version identifies its five exact code variants; neither is evidence of a hosted run.
Go deeper
For a paper-based experiment with scientific comparisons and execution evidence, read Research Replications. Its published scope and availability are separate from this small teaching circuit.