liveBook · Manning

Butterfly pattern

As explained in Building Quantum Software with Python

A butterfly pattern is a computational pattern that recombines pairs of values with a formula to produce updated values.

The butterfly pattern recombines pairs of values with a formula to produce updated values. In quantum computing, elementary gates apply this operation to amplitude pairs, while quantum parallelism processes affected pairs simultaneously. section 1.3.1 section 12.3

A target qubit determines which amplitudes form pairs. A single-qubit gate uses a two-by-two unitary matrix to recombine each pair; controlled operations reduce the number of affected pairs. section 12.3 section 12.3.1

A direct simulator implementation follows this sequence:

  • Generate the index pairs for a chosen target qubit. section 4.3.3
  • Read each pair’s amplitudes as x and y. section 4.3.3
  • Replace the pair with the matrix product defined by the gate. section 4.3.3
  • Repeat across all pairs; the simulator processes them sequentially even though the quantum operation acts in parallel. section 4.3.3

Applying an X gate

For a three-qubit state, applying an X gate to target qubit 0 swaps every identified amplitude pair. Applying it to target qubit 2 produces a different pairing pattern. Butterfly diagrams visualize both the pair locations and the resulting state rearrangement. section 4.3.3

Beyond one target qubit

State-conversion functions can arrange a multi-qubit state into a matrix, apply a four-by-four unitary transformation, reconstruct the state, and verify equivalence with a QuantumCircuit execution. section 12.3.1

Single-pair butterfly diagram
sidebar figure

Use the single-pair butterfly diagram to trace how two values enter a gate formula and emerge as updated values. section 1.3.1

How Building Quantum Software with Python covers it

How deep it goes
Descends from visual pairing to Python state simulation and matrix reconstruction, stopping short of advanced Fourier-transform treatment.
Examples
Uses X-gate swaps, three-qubit amplitude tables, butterfly diagrams, and four-by-four unitary transformations.
What it assumes
Assumes basic qubit-state and gate concepts while building pair processing, target indexing, and matrix transformations explicitly.
What you can do after
Apply it via Python to simulate gate transformations, inspect target-dependent pairings, and compare reconstructed states with circuit execution.
How it connects
Connects quantum gates, quantum parallelism, superposition, unitary matrices, and the fast Fourier transform.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Quantum Software with Python. The section links point to the parts of the book it draws on.