iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📕

Build Your Own Quantum Computer for Everyone: Chapter 1 - Creating a Qubit on an FPGA: Burning Complex Numbers (Complete Edition)

に公開
2026/02/18

― Compressing the Infinite Hilbert Space into 64 bits ―


  • Bonjin
    "Quantum is a world of infinite dimensions, right?"

  • Eddie
    "That's correct."

  • Bonjin
    "And you're putting that into an FPGA... are you sane?"

  • Eddie
    "It's precisely because I'm sane that it's interesting."


1. The World of Equations: Infinite Ideals

A single qubit is defined as:

|\psi\rangle = \alpha |0\rangle + \beta |1\rangle

Where,

|\alpha|^2 + |\beta|^2 = 1

What matters here is:

  • α, β are complex numbers
  • Phase is a continuous variable
  • The Hilbert space is continuously infinite

Mathematically, infinite precision is assumed.


2. Reality: Finite Circuits

An FPGA is:

  • Finite bit-width
  • Finite clock
  • Finite DSPs
  • Finite voltage levels

This is where the first collision occurs.

Stuffing infinite equations into finite circuits.

This is the essence of quantum engine design.


3. The Philosophy of Bit-Width Determination

Why Q1.15?

■ Reason 1: Normalization Condition

Amplitudes are in the range [-1, 1].

1 bit for the integer part is sufficient.

■ Reason 2: Error Tolerance

Precision required for Hadamard:

\frac{1}{\sqrt{2}} ≈ 0.70710678

Using fixed-point:

Error ≈ 10^-5

This is sufficient to reproduce quantum interference.


■ Reason 3: DSP Efficiency

The DSP in the Tang Nano 4K is an 18x18 multiplier.

16 bits is just right.

Here, mathematics meets the hardware halfway.


4. Complete Block Diagram

                    +---------------------+
                    |  Host Interface     |
                    | (UART / SPI)        |
                    +----------+----------+
                               |
                               v
                    +---------------------+
                    |  Control FSM        |
                    +----------+----------+
                               |
                               v
+---------------------+  +---------------------+
| State Register      |  | Gate Matrix Loader  |
| αr αi βr βi         |  | H, I                |
+----------+----------+  +----------+----------+
           |                        |
           +------------+-----------+
                        v
               +------------------+
               |  Complex ALU     |
               |  (Add/Sub/Mul)   |
               +---------+--------+
                         |
                         v
               +------------------+
               |  Normalize Unit  |
               +---------+--------+
                         |
                         v
               +------------------+
               | Measurement Unit |
               +------------------+

This is basically a "CPU".


5. Timing Analysis

Clock: 100MHz

■ H-gate Application

  1. α+β → 1 cycle
  2. α-β → 1 cycle
  3. ×0.707 → 2 cycles (DSP pipeline)
  4. Write-back → 1 cycle

Total: 5–6 cycles

One quantum gate ≈ 60ns

Better than a giant dilution refrigerator (maybe?)


6. The Problem of Unitarity

In theory:

U^\dagger U = I

In fixed-point arithmetic, they don't match perfectly.

Errors accumulate.

So, a design decision is required.

■ Choices

A. Do not normalize (Follow the ideal)
B. Normalize periodically (Deal with reality)

We choose B here.

This is where we "draw the line."

7. Normalization Circuit Details

norm = \sqrt{|\alpha|^2 + |\beta|^2}

Inverse square root approximation:

Newton-Raphson

x_{n+1} = x_n (1.5 - 0.5 n x_n^2)

FPGA implementation:

  • 2 iterations are sufficient
  • Uses 3 DSPs

Approaching the infinite within the finite.

This is engineering.


8. Measurement: From Determinism to Probability

In the world of equations:

Measurement = Projection operator

In the world of circuits:

  • LFSR
  • Comparator
  • Branching

Here, we introduce "non-determinism" for the first time.

It is a pseudo-random number, but the structure is the same.


9. Divergence Between Equations and Implementation

Ideal:

H^2 = I

Implementation:

Repeating H 1000 times results in a slight deviation.

This is where we realize:

Equations assume infinite precision.
Hardware battles with finite precision.

This gap is reality.

The moment you wake up from a dream.

But at the same time,

the moment quantum mechanics changes from a "mystery" to a "structure."


10. Additional Experiment Items

Experiment 4: Applying H 10,000 times

[Amplitude error log here]

Experiment 5: Comparison of Normalization ON/OFF

[Comparison table here]

Experiment 6: Add Phase Rotation Gate (Z Gate)

Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}

[Result screenshot here]


11. Philosophical Summary

  • Mathematics is an ideal
  • Circuits are constraints
  • Constraints create innovation
  • Quantum is not a mystery
  • Quantum is DSP (a bold claim)

  • Average Joe
    "So... quantum isn't special?"

  • Eddie
    "Only the scale is special."


12. Conclusion of this Chapter

  • Implemented a qubit with 64 bits
  • Burned unitary into DSP
  • Reproduced measurement via probabilistic branching
  • Experienced the collision between the infinite and the finite

Once you've come this far, there's no turning back.

Next is 4 dimensions.

2 qubits.

Entanglement.

The Hilbert space expands all at once.


📦 Chapter 1 Appendix

Complete FPGA Implementation Procedure (Targeting Tang Nano 4K)


0. Prerequisites

  • Tang Nano 4K
  • Gowin IDE installed
  • USB connection verified
  • Operating clock: 27MHz or 100MHz

1. Project Creation

■ Project Name

quantum_bit_engine_q15

■ Device

GW1NSR-LV4CQN48PC7/I6

■ Top Module

quantum_top.v

2. Directory Structure

quantum_bit_engine_q15/
 ├── src/
 │    ├── quantum_top.v
 │    ├── complex_add.v
 │    ├── complex_mul.v
 │    ├── hadamard.v
 │    └── measure.v
 └── constraints/
      └── pin.cst

3. Fixed-Point Definition (Q1.15)

`define Q_WIDTH 16
`define Q_FRAC  15

4. Complex Addition Module

module complex_add(
    input signed [15:0] ar, ai,
    input signed [15:0] br, bi,
    output signed [15:0] cr, ci
);
assign cr = ar + br;
assign ci = ai + bi;
endmodule

5. Complex Multiplication Module

module complex_mul(
    input signed [15:0] ar, ai,
    input signed [15:0] br, bi,
    output signed [15:0] cr, ci
);

wire signed [31:0] mult1 = ar * br;
wire signed [31:0] mult2 = ai * bi;
wire signed [31:0] mult3 = ar * bi;
wire signed [31:0] mult4 = ai * br;

assign cr = (mult1 - mult2) >>> `Q_FRAC;
assign ci = (mult3 + mult4) >>> `Q_FRAC;

endmodule

6. Hadamard Gate Implementation

H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}

Inverse of √2 (Q1.15):

localparam signed INV_SQRT2 = 16'sd23170; // 1/sqrt(2)
module hadamard(
    input signed [15:0] ar, ai,
    input signed [15:0] br, bi,
    output signed [15:0] ar_o, ai_o,
    output signed [15:0] br_o, bi_o
);

wire signed [15:0] sum_r = ar + br;
wire signed [15:0] sum_i = ai + bi;
wire signed [15:0] diff_r = ar - br;
wire signed [15:0] diff_i = ai - bi;

assign ar_o = (sum_r * INV_SQRT2) >>> `Q_FRAC;
assign ai_o = (sum_i * INV_SQRT2) >>> `Q_FRAC;
assign br_o = (diff_r * INV_SQRT2) >>> `Q_FRAC;
assign bi_o = (diff_i * INV_SQRT2) >>> `Q_FRAC;

endmodule

7. Measurement Module

Probability:

P(0) = |\alpha|^2
module measure(
    input signed [15:0] ar, ai,
    input signed [15:0] br, bi,
    input [15:0] rand,
    output reg result
);

wire signed [31:0] p0 = (ar*ar + ai*ai) >>> `Q_FRAC;

always @(*) begin
    result = (rand < p0);
end

endmodule

8. Top Module

module quantum_top(
    input clk,
    input btn,
    output led
);

// Initial state |0>
reg signed [15:0] alpha_r = 16'sd32767;
reg signed [15:0] alpha_i = 0;
reg signed [15:0] beta_r  = 0;
reg signed [15:0] beta_i  = 0;

// Apply Hadamard
wire signed [15:0] ar_o, ai_o, br_o, bi_o;

hadamard H(
    alpha_r, alpha_i,
    beta_r, beta_i,
    ar_o, ai_o,
    br_o, bi_o
);

// Update on button press
always @(posedge clk) begin
    if(btn) begin
        alpha_r <= ar_o;
        alpha_i <= ai_o;
        beta_r  <= br_o;
        beta_i  <= bi_o;
    end
end

assign led = beta_r[15]; // Provisional display

endmodule

9. Pin Assignment Example (pin.cst)

IO_LOC "clk"  P3;
IO_LOC "btn"  P4;
IO_LOC "led"  P5;

10. Synthesis Steps

  1. Synthesize
  2. Place & Route
  3. Generate Bitstream
  4. Download

11. Verification

  1. Initial state: |0>
  2. Press button
  3. Apply Hadamard
  4. |+> state

Success if the LED flickers.


12. Experiment Record (for notes)

■ Synthesis Results

[LUT/DSP utilization screenshot here]


■ Timing Analysis

[Fmax result here]


■ Hardware Photo

[Tang Nano photo here]


■ Output Log

[Measurement probability log here]

Discussion