Skip to main content
KetQat

Appearance

Quantum Fourier transform (statevector)

Apply the QFT gate sequence to a basis, uniform or random state on up to 16 qubits and compare it with the DFT definition.

Officially provided by KetQat — method by Coppersmith (1994), Shor (1994) and others. KetQat prepares, verifies and maintains this product; it does not claim to have invented the method. Read the origin statement.

What it does and who it is for

Applies the quantum Fourier transform, or its inverse, as the real gate sequence (Hadamards, controlled phase rotations and the final qubit reversal) to a state vector on your machine. The input is a computational basis state, the uniform superposition or a seeded random state. The output is compared with an independent reference: the DFT column written straight from its definition for a basis state, the known |0...0> result for the uniform state, and the full DFT matrix product for a random state of up to 10 qubits. The inverse transform is then applied and the round-trip error reported, and the output state is sampled with a seed.

The convention is stated and checked rather than assumed: QFT|j> = (1/sqrt N) sum_k exp(+2 pi i j k / N)|k>, little-endian, so a flipped sign or a reversed bit order would show up as a non-zero deviation. Pure Python: the algorithms extra is used only for seeded sampling.

Use cases

  • Check that the QFT circuit equals the discrete Fourier transform, column by column, to floating-point precision
  • Show that a basis state transforms to a flat magnitude distribution and the uniform state to |0...0>
  • Fix the sign and bit-order convention of a QFT before building phase estimation or Shor-type circuits on it

Use it on your computer

This page never runs anything. Copy the commands into your own terminal; the product runs locally with no account and no telemetry.
  1. Install

    Installs the KetQat SDK from commit 2cedabbd814f, the exact version whose product definition this page shows. The SDK is not on PyPI yet, so pip install ketqat alone will not work.

    Terminal
    pip install "ketqat[algorithms] @ git+https://github.com/ketqat/ketqat-sdk@2cedabbd814fd199b1989c8ceb1e9efa1744c2c0#subdirectory=python"
  2. Run the example

    Save it as example.py and run python example.py. Or use the CLI: ketqat catalog run [email protected].

    Python
    import json
    from ketqat_runner import catalog
    
    record = catalog.run("[email protected]", seed=7, n_qubits=4, input_state="basis", basis_index=1, shots=1000)
    result = record.result
    print(json.dumps({
        "status": record.status,
        "dimension": result["dimension"],
        "matches_dft_column": result["max_deviation_from_reference"] < 1e-9,
        "round_trip_is_identity": result["round_trip_error"] < 1e-9,
        "output_is_flat": result["max_magnitude_deviation_from_flat"] < 1e-9,
        "output_norm": round(result["output_norm"], 9),
    }))
    
    Expected output (fields the example must print)
    {
      "status": "succeeded",
      "dimension": 16,
      "output_norm": 1,
      "output_is_flat": true,
      "matches_dft_column": true,
      "round_trip_is_identity": true
    }

    Verified with

    SDK
    0.3.0
    Python
    3.12.12
    Platform
    macOS-27.0.1-arm64 Python 3.12.12 (maintainer run in a clean virtualenv, test_catalog_examples.py)
    Date
    1 Nov 2026
  3. Optional: tell us it ran

    ketqat report RUN_ID sends an opt-in usage report: product, version, succeeded/failed, time and SDK version only. It shows you the exact payload first and needs an API token from Settings. Nothing is sent unless you run it.

Inputs and outputs

Inputs

Inputs of Quantum Fourier transform (statevector)
NameTypeDefaultAllowed valuesDescription
n_qubitsinteger4maximum: 16; minimum: 1Register size n; the state has N = 2^n amplitudes.
input_statestringbasisenum: basis, uniform, randombasis (|basis_index>), uniform ((1/sqrt N) sum_j |j>) or random (seeded complex Gaussian amplitudes, normalised).
basis_indexinteger1minimum: 0j for input_state=basis, in [0, 2^n - 1]. Ignored otherwise.
inversebooleanfalse—Apply the inverse transform (negative phases) instead of the forward one.
shotsinteger1000maximum: 100000; minimum: 1Measurement samples drawn from the output state.

Outputs

Outputs of Quantum Fourier transform (statevector)
NameTypeDescription
max_deviation_from_referencenumberLargest |amplitude difference| between the circuit output and the independent reference named in reference; null when the O(N^2) matrix reference is skipped (random input above 10 qubits).
round_trip_errornumberLargest |amplitude difference| after applying the opposite transform to the output.
output_normnumberNorm of the output state (1 for a unitary transform).
max_magnitude_deviation_from_flatnumberFor a basis-state input: largest deviation of |amplitude| from 1/sqrt N over the output.
output_amplitudesobject[][real, imaginary] pairs of the output state, listed up to 5 qubits; null above.
countsobjectSeeded measurement counts of the output, bitstring (most significant qubit first) to count; the eight most probable outcomes are listed in top_outcomes.

Sample result

4 qubits, basis state |0001>: the gate-level output equals the DFT column to 12 decimals, every output magnitude is 1/4 (flat), the inverse transform returns the input exactly, and 1000 seeded shots spread over all 16 outcomes.

Generated with

Product version
1.0.0
Seed
7
Parameters
{"shots":1000,"inverse":false,"n_qubits":4,"basis_index":1,"input_state":"basis"}
SDK
0.3.0
Python
3.12.12
Platform
macOS-27.0.1-arm64-arm-64bit
Result data (JSON)
{
  "shots": 1000,
  "counts": {
    "1000": 62,
    "1001": 64,
    "1010": 67,
    "1011": 52,
    "1100": 73,
    "1101": 59,
    "1110": 60,
    "1111": 61,
    "0000": 65,
    "0001": 59,
    "0010": 73,
    "0011": 60,
    "0100": 65,
    "0101": 57,
    "0110": 61,
    "0111": 62
  },
  "inverse": false,
  "n_qubits": 4,
  "dimension": 16,
  "execution": "statevector simulation of the gate sequence (pure Python), seeded sampling of the output",
  "reference": "DFT column (1/sqrt(N)) exp(+-2 pi i j k / N), written from the definition",
  "convention": "QFT|j> = (1/sqrt(N)) sum_k exp(+2 pi i j k / N)|k>, little-endian (qubit 0 is the least significant bit); the inverse carries the opposite sign",
  "input_state": {
    "kind": "basis",
    "description": "|1> = |0001>"
  },
  "output_norm": 1,
  "top_outcomes": [
    {
      "integer": 0,
      "bitstring": "0000",
      "probability": 0.0625
    },
    {
      "integer": 2,
      "bitstring": "0010",
      "probability": 0.0625
    },
    {
      "integer": 4,
      "bitstring": "0100",
      "probability": 0.0625
    },
    {
      "integer": 7,
      "bitstring": "0111",
      "probability": 0.0625
    },
    {
      "integer": 8,
      "bitstring": "1000",
      "probability": 0.0625
    },
    {
      "integer": 10,
      "bitstring": "1010",
      "probability": 0.0625
    },
    {
      "integer": 12,
      "bitstring": "1100",
      "probability": 0.0625
    },
    {
      "integer": 15,
      "bitstring": "1111",
      "probability": 0.0625
    }
  ],
  "round_trip_error": 0,
  "distinct_outcomes": 16,
  "output_amplitudes": [
    [
      0.25,
      0
    ],
    [
      0.230969883128,
      0.095670858091
    ],
    [
      0.176776695297,
      0.176776695297
    ],
    [
      0.095670858091,
      0.230969883128
    ],
    [
      0,
      0.25
    ],
    [
      -0.095670858091,
      0.230969883128
    ],
    [
      -0.176776695297,
      0.176776695297
    ],
    [
      -0.230969883128,
      0.095670858091
    ],
    [
      -0.25,
      0
    ],
    [
      -0.230969883128,
      -0.095670858091
    ],
    [
      -0.176776695297,
      -0.176776695297
    ],
    [
      -0.095670858091,
      -0.230969883128
    ],
    [
      0,
      -0.25
    ],
    [
      0.095670858091,
      -0.230969883128
    ],
    [
      0.176776695297,
      -0.176776695297
    ],
    [
      0.230969883128,
      -0.095670858091
    ]
  ],
  "max_deviation_from_reference": 0,
  "max_magnitude_deviation_from_flat": 0
}

Assumptions, scope and limitations

Assumptions

  • Ideal, noiseless gates: Hadamards and controlled phase rotations are applied exactly; no rotation is truncated (the exact, not the approximate, QFT).
  • Little-endian qubit order (qubit 0 is the least significant bit) and the +2 pi i j k / N sign for the forward transform.

Scope

  • 1 to 16 qubits, forward or inverse transform, basis, uniform or seeded random input.
  • Deviation from an independent reference, round-trip error, output norm and seeded sampling of the output.

Limitations

  • A statevector simulation in pure Python: 16 qubits is the ceiling, and it says nothing about running on hardware.
  • Gate counts and depth are not reported, and the approximate QFT (dropping small rotations) is not offered.
  • For random input above 10 qubits the O(N^2) matrix reference is skipped; only the round-trip error and the norm are checked.
  • Sampled counts are reproducible for the same seed with the same NumPy version; NumPy does not guarantee identical random streams across versions.
  • Tested on macOS and Linux only; Windows is untested.

Environment and resources

Runs
Locally, on your computer
Type
Simulation
Python
>=3.10
Operating systems
Linux, macOS
Resources
4 qubits: milliseconds. 16 qubits (65536 amplitudes, forward and inverse, basis-state reference): ~4 s and under 50 MB on a 2024 laptop. The matrix reference for random input costs O(N^2) and is applied only up to 10 qubits (~0.5 s).
SDK extras
algorithms
Minimum SDK
0.3.0

Validation

Verified: the example was executed by CI, validation tests exist and limitations are recorded.

Versions and changelog

  1. 1.0.01 Nov 2026currentShown on this page

    • First catalog release, wrapping the SDK's existing gate-level QFT with reference comparison, round trip and seeded sampling.

    Needs SDK 0.3.0 or later with extras: algorithms.

All product changelogs

Origin, license and credits

KetQat implementation of published methods

The quantum Fourier transform circuit is due to Coppersmith (1994) and was introduced as the core of Shor's factoring algorithm (1994); the discrete Fourier transform it implements is classical. KetQat wrote this pure-Python gate-level implementation (fourier.py), the DFT reference it is checked against, the validation tests and this catalog entry. KetQat did not invent the method.

Upstream software

License of what you receive

Apache-2.0 — see Licensing.

Contributors

People credited for this product. KetQat publishes and maintains it; contributors are credited for their work and are not sellers.

  • dorakingx · KetQat maintainer: implementation, validation and catalog entry

How to contribute

References

  1. Don Coppersmith (1994). An approximate Fourier transform useful in quantum factoring. IBM Research Report RC 19642.arXiv:quant-ph/0201067
  2. Peter W. Shor (1994). Algorithms for quantum computation: discrete logarithms and factoring. Proceedings of the 35th Annual Symposium on Foundations of Computer Science, 124-134.DOI 10.1109/SFCS.1994.365700
  3. Michael A. Nielsen, Isaac L. Chuang (2010). Quantum Computation and Quantum Information: 10th Anniversary Edition. Cambridge University Press.DOI 10.1017/CBO9780511976667

Usage

No usage reports yet

Distinct signed-in accounts that chose to send at least one usage report (ketqat report) for this product in the last 90 days. KetQat staff, test and bot accounts are excluded. Reports are opt-in, so this is not a count of all users.

Computed 10 Nov 2026, 17:24 UTC.

Reviews

Not yet rated

Be the first to rate this product after you run it.

Mean of visible reviews. Hidden reviews and reviews by KetQat staff, test and bot accounts are excluded. Pro status gives no extra weight.

Sign in to review this product. One review per person; you can edit it later.

No reviews yet.