QAOA (Quantum Approximate Optimization Algorithm) on PixAI Stable Diffusion prompt
image: PixAI generated (sample) https://pixai.art/artwork/2022351811178270069?utm_source=copy_android
Use QAOA -Quantum Approximate Optimazation Algorithm to optimize the prompt given for Stable Diffusion-based generator on PixAI, for the AI artists.
Result:
🎯 Optimization targets (6 Qubits): ['officer', 'blue eyes', 'shirt', 'epaulettes', 'military', 'lady']
Loading semantic model...Loading weights: 100% 103/103 [00:00<00:00, 3446.13it/s]
⚙️ QUBO configured for exactly 5 words (Penalty P=50.0)
🔄 Running QAOA (Depth=3, 5 restarts)... Please wait. ➔ Restart 1: Energy -1092.55 (New Best) ➔ Restart 2: Energy -1206.45 (New Best)
✅ Optimization complete.
============================================================
🚀 QAOA Results (LLM + Quantum Fusion)
============================================================
Best bit string : 011111
Overall probability : 10.40%
Probability AMONG VALID: 26.74%
Words selected : 5 / 5
✅ Constraint SATISFIED!
📝 Optimized Prompt: blue eyes, shirt, epaulettes, military, lady
========================================================================================================================
🔍 LLM 语义契合度矩阵 (Cosine Similarity * 10)============================================================
officer blue eyes shirt epaulettes military lady officer 10.00 2.63 3.26 2.39 6.03 4.03 blue eyes 10.00 2.48 1.86 2.62 2.71 shirt 10.00 2.44 3.63 3.33 epaulettes 10.00 1.21 2.79 military 10.00 2.72 lady 10.00 ============================================================
Modified the Quantum optimization code with the user-defined weight as a list (favorable = -n, unfavorable = +n)
Sample: https://pixai.art/artwork/2026474065196894875?utm_source=copy_android
The optimized prompt: officer, shirt, military, blonde hair, uniform, school
P = 50 # P: Penalty function
h = np.array([ -50.0, # officer → 想要 → 负数
30.0, # blue eyes → 不想要 → 正数
-10.0, # shirt → 弱想要
-60.0, # epaulettes → 非常想要
-80.0, # military → 最想要
50.0, # lady → 不想要
-50.0, # blonde hair
-80.0, # green eyes
30.0, # brown hair → 不想要
-30.0, # uniform
20.0, # school → 不想要
-80.0, # jacket])
h *= 10.0J = np.zeros((num_qubits, num_qubits))
for i in range(num_qubits):
for j in range(i + 1, num_qubits):
affinity = cosine_scores[i, j] * 10.0
J[i, j] = -affinity + 2 * P
h = np.array([P * (1 - 2 * K)] * num_qubits) + h

















