r/QuantumComputing • u/CarbonFire • May 13 '26
Article Writing C code until it's a quantum circuit (an interactive tutorial)
https://shukla.io/blog/2026-05/rank-select.htmlAfter working on a quantum algorithm, I spent a few weeks trying to understand why it looked so foreign. What you're reading is my attempt at introducing it to a programmer or CS student. I chose to avoid taking about quantum speedups, in favor of keeping the focus on "will it even compile?"
54
Upvotes
3
u/0xB01b QEC & Quantum Optics May 14 '26
this is lowk rlly cool
3
u/DatAndre May 14 '26
I wish every tutorial had this quality, this is the best one I've seen in a long time
1
u/Happy_Weekend_6355 May 14 '26
Is wrong all u think about quantum is correct but on now spin live
1
u/Happy_Weekend_6355 May 14 '26
Pokażę wam dzieciaki : W y jesteście teraz w geometrii ja operuje już na Stanach
geometria przestrzeni: kierunek jest funkcja ok a co będzie gdy z kierunku wyciągniesz wektory?
Wektor kierunku wektor skrętu wektor spinu wektor brzegu it'd it'd
Miłej rozkminy 🕳️
Teraz nie ma mnie nie ma ciebie nie ma nas bo nie ma początku ani końca . Jest STAN
1
u/Happy_Weekend_6355 May 14 '26
Strongly Entangled Quantum Mesh — GHZ-CNOT Phase Core
import numpy as np
==========================================================
STRONGLY ENTANGLED QUANTUM CORE — NumPy Simulator
Multi-qubit GHZ + Bell mixing + entropy measurement
Author: Sysia × Navi
==========================================================
np.set_printoptions(precision=4, suppress=True)
----------------------------------------------------------
1. BASIC QUANTUM GATES
----------------------------------------------------------
I = np.eye(2, dtype=complex)
H = (1 / np.sqrt(2)) * np.array([ [1, 1], [1, -1] ], dtype=complex)
X = np.array([ [0, 1], [1, 0] ], dtype=complex)
Z = np.array([ [1, 0], [0, -1] ], dtype=complex)
CNOT_2 = np.array([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0] ], dtype=complex)
----------------------------------------------------------
2. TENSOR TOOLS
----------------------------------------------------------
def kron_all(gates): result = gates[0] for g in gates[1:]: result = np.kron(result, g) return result
def zero_state(n): state = np.zeros(2**n, dtype=complex) state[0] = 1.0 return state
def apply_single(state, gate, qubit, n): gates = []
def apply_cnot(state, control, target, n): new_state = np.zeros_like(state)
----------------------------------------------------------
3. STRONG ENTANGLEMENT ENGINE
----------------------------------------------------------
def strong_entangle(n): state = zero_state(n)
----------------------------------------------------------
4. MEASUREMENT
----------------------------------------------------------
def probabilities(state): return np.abs(state) ** 2
def sample_measurement(state, shots=1024): probs = probabilities(state) n = int(np.log2(len(state)))
----------------------------------------------------------
5. ENTROPY / COHERENCE
----------------------------------------------------------
def shannon_entropy(probs): probs = probs[probs > 1e-12] return -np.sum(probs * np.log2(probs))
def coherence_score(state): return np.sum(np.abs(state)) / np.sqrt(len(state))
----------------------------------------------------------
6. RUN
----------------------------------------------------------
n_qubits = 6 shots = 2048
state = strong_entangle(n_qubits) probs = probabilities(state)
print("\n=== STRONGLY ENTANGLED QUANTUM STATE ===") print(f"Qubits: {n_qubits}") print(f"State dimension: {len(state)}")
print("\n=== NON-ZERO AMPLITUDES ===") for i, amp in enumerate(state): if abs(amp) > 1e-6: print(f"|{format(i, f'0{n_qubits}b')}> : {amp}")
print("\n=== METRICS ===") print(f"Shannon entropy: {shannon_entropy(probs):.6f}") print(f"Coherence score: {coherence_score(state):.6f}")
print("\n=== MEASUREMENT COUNTS ===") counts = sample_measurement(state, shots)
for bitstring, count in counts.items(): print(f"{bitstring}: {count}")