惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
博客园_首页
J
Java Code Geeks
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
量子位
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
N
Netflix TechBlog - Medium
Hugging Face - Blog
Hugging Face - Blog
B
Blog
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
宝玉的分享
宝玉的分享
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
The Cost of Garbage in Quantum Computing: Why You Must Cl...
Malcolm Low · 2026-05-16 · via DEV Community

Malcolm Low

Originally published on malcolmlow.net

In quantum computing, anything that "knows" what a qubit is doing acts as a Witness. Leftover data (Junk Bits) on an ancilla qubit act as witnesses, destroying the interference your algorithm needs to work.


1 . The Observer Effect

Consider a simple circuit where a qubit passes through two Hadamard gates. Classically, two inversions cancel. Quantum mechanically, the same is true — only if no information leaks out between them.

Case A: Ideal — No Junk

q0: |0> --H-----------H-- => |0>  (100% probability)

Enter fullscreen mode Exit fullscreen mode

The two Hadamard gates cancel perfectly. Measurement always yields |0>.

Case B: Broken — With Junk

q0: |0> --H----*-------H-- => |0> or |1>  (50/50 noise)
               |
q1: |0> -------X---------- => |junk>      (records q0's path)

Enter fullscreen mode Exit fullscreen mode

The ancilla qubit q1 becomes entangled with q0. It now "knows" which path q0 took — and that knowledge destroys the interference.


2 . Mathematical Working

Ideal Case — interference works:

Start:    |0>
After H:  (1/sqrt2)(|0> + |1>)
After H:  (1/2)(|0> + |1> + |0> - |1>) = |0>   (cancel!)

Enter fullscreen mode Exit fullscreen mode

The |1> terms cancel — constructive interference on |0>.

Junk Case — interference destroyed:

Start:          |0>|0>
After H on q0:  (1/sqrt2)(|0> + |1>)|0>
After CX:       (1/sqrt2)(|00> + |11>)    <- entangled!
After H on q0:  (1/2)(|00> + |10> + |01> - |11>)

Enter fullscreen mode Exit fullscreen mode

The terms cannot cancel because q1 differs in each: |00> vs |10> are orthogonal states. Interference is destroyed.


3 . The Solution: Uncomputation

To restore interference, follow the Compute-Copy-Uncompute pattern:

q_in : |x> --[COMPUTE]--+--[UNCOMPUTE]-- |x>    (unchanged)
                        |
q_anc: |0> -------------+--[UNCOMPUTE]-- |0>     (cleaned)
                        |
q_out: |0> -------------+--------------- |f(x)>  (result)

Enter fullscreen mode Exit fullscreen mode

Step by step:

  1. Compute — apply your function gates, writing the result onto q_anc
  2. Copy — CNOT the result from q_anc into q_out
  3. Uncompute — run the compute gates in reverse, resetting q_anc to |0>

With q_anc back to |0>, the witness is gone and interference is fully restored.


4 . Qiskit Implementation

from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator

qc = QuantumCircuit(3)
# q0 = input, q1 = ancilla, q2 = output

qc.h(0)
qc.cx(0, 1)   # COMPUTE:    entangle q0 -> q1 (creates junk)
qc.cx(1, 2)   # COPY:       copy result q1 -> q2
qc.cx(0, 1)   # UNCOMPUTE:  reverse compute, reset q1 -> |0>
qc.h(0)       # Interference fully restored

qc.measure_all()
counts = AerSimulator().run(transpile(qc, AerSimulator())).result().get_counts()
print(f"Resulting state: {counts}")

Enter fullscreen mode Exit fullscreen mode

The same circuit as a wire diagram (@ = control, X = target):

q0: |0> --H--@---------@--H-- M
             |         |
q1: |0> -----X----@----X----- M   (ancilla: |0> -> junk -> |0>)
                  |
q2: |0> ----------X---------- M   (output: holds f(x))

Enter fullscreen mode Exit fullscreen mode

The second cx(0,1) exactly reverses the first, leaving q1 in |0>. With the witness removed, the final h(0) performs clean interference and q0 deterministically outputs |0>.


5 . Why This Matters in Practice

Uncomputation is not just a theoretical nicety. In real quantum algorithms:

Context Why it matters
Grover's oracle Must leave ancilla qubits clean after marking the target, or subsequent diffusion steps decohere
Arithmetic circuits Reversible adders/multipliers accumulate garbage at every intermediate step — all must be uncomputed before measurement
Fault-tolerant circuits Strict qubit budgets; junk bits consume physical qubits that could otherwise be used for error correction

The Compute-Copy-Uncompute pattern is the standard solution across all three contexts.


Quantum Series 2025 · Built with Qiskit 1.x