In a Bernstein–Vazirani oracle, several data qubits can interact with one shared target qubit. The logical interaction graph is a star. A physical path has maximum degree two, so a large star cannot be embedded directly on it. The compiler needs to change the placement, the interaction order or the gate synthesis.

The shared qubit can move while it interacts

CNOT gates with distinct controls and a common target commute. If the shared target visits the controls along a connected path, routing can be interleaved with the logical interactions. On a CZ-native device with arbitrary single-qubit gates, an ordinary CNOT can be implemented with one CZ, a SWAP with three, and a CNOT followed by a SWAP on the same pair with two CZ using a combined two-qubit decomposition.

The separate CNOT and SWAP construction uses four CZ for an interaction followed by a move. The standard SWAP is a sequence of three CNOTs with alternating directions. Prepending a CNOT of the first direction cancels the first gate of that sequence, leaving two CNOTs. Each can be converted to one CZ with local gates. That gives a structured reference for a compiler that searches over both placement and native gates.

Illustration: a target moving along a line

# Logical order after interacting and moving a shared target.
order = ['a','b','c','target']
visited=[]
for right in range(3,0,-1):
    assert order[right]=='target'
    visited.append(order[right-1])
    order[right-1],order[right]=order[right],order[right-1]
assert visited==['c','b','a'] and order[0]=='target'

The final order is different from the input order. A compiler must account for that permutation in subsequent gates or measurements.

What a benchmark needs to establish

Compare the same oracle on the same usable hardware graph and native instruction set. Include a structured moving-target reference alongside general compilation methods. Check every output operation against the target, retain the final logical mapping, and distinguish the original CNOT count from a proven lower bound: resynthesis can change the gate count of an equivalent operation.

Bernstein–Vazirani also makes the scope of a verification check particularly clear. With the usual prepared target state, phase kickback can implement the oracle's action on that state without reproducing its action on every input. Testing the expected secret on a prepared input therefore checks the algorithm's behavior at that input. Full operation equivalence requires a stronger check.

This structure is relevant to shared ancillas and repeated interactions in other circuits. A strong compiler benchmark identifies where the overhead comes from and tests the same mathematical operation across implementations.

Explore the 4colors Quantum Compiler.