Random circuit generation#
There are several functions defined in quex.qrandom module to generate random circuits.
Hardware-Efficient Ansätze#
In Quantum Machine Learning, generating uniform pseudo-random states is critical. Quex uses mathematically rigorous spherical mapping (the \(\arccos\) Jacobian transformation) to prevent pole-bunching on the Bloch sphere, ensuring true Haar-uniformity.
import quex as qx
# Generate a static, fully evaluated random circuit with 3 qubits and depth 2
# Note: "Depth" here refers to Layers (Rotation + Entanglement)
qc_static = qx.random_ansatz(num_qubits=6, depth=6)
print("Static Random Circuit:")
print(qc_static)
print(f"Compiler Operations Depth: {qc_static.depth}")
Static Random Circuit:
q[0]: ───[RY(2.21)]───■────[RX(1.84)]──[RZ(5.42)]───────────────■────[RY(5.21)]──[RX(1.94)]───────────────■────[RZ(1.21)]───────
│ │ │
q[1]: ───[RZ(5.03)]───X────[RX(4.24)]──────■───────[RZ(3.94)]───X────[RY(2.99)]──────■───────[RY(1.85)]───X────[RX(3.57)]───■───
│ │ │
q[2]: ───[RX(4.55)]───■────[RY(1.93)]──────X───────[RZ(2.98)]───■────[RZ(2.96)]──────X───────[RZ(1.04)]───■────[RX(6.26)]───X───
│ │ │
q[3]: ───[RX(4.77)]───X────[RX(1.64)]──────■───────[RX(0.23)]───X────[RZ(1.13)]──────■───────[RX(5.11)]───X────[RY(4.7)]────■───
│ │ │
q[4]: ───[RX(1.62)]───■────[RZ(5.23)]──────X───────[RY(3.84)]───■────[RX(4.02)]──────X───────[RZ(5.18)]───■────[RY(3.74)]───X───
│ │ │
q[5]: ───[RX(2.42)]───X────[RX(6.21)]──[RY(2.13)]───────────────X────[RY(1.02)]──[RX(0.9)]────────────────X────[RY(4.16)]───────
Compiler Operations Depth: 12
random_ansatz_U uses Unitary rotation gates, to generate uniform rotation of qubits, coupled with entanglement.
qc_static = qx.random_ansatz_U(num_qubits=6, depth=6)
print("Static Random Circuit:")
print(qc_static)
print(f"Compiler Operations Depth: {qc_static.depth}")
Static Random Circuit:
q[0]: ───[U(1.26,4.79,3.44)]───■────[U(1.42,3.88,5.65)]──[U(1.32,2.87,2.72)]────────────────────────■────[U(1.36,4.61,1.05)]──[U(0.99,4.96,0.25)]────────────────────────■────[U(1.66,1.14,3.23)]───────
│ │ │
q[1]: ───[U(1.24,4.09,1.76)]───X────[U(1.56,0.85,5.54)]───────────■───────────[U(1.81,5.42,2.21)]───X─────[U(2.1,1.72,2.62)]───────────■───────────[U(2.68,5.73,3.08)]───X─────[U(1.52,0.46,5.4)]───■───
│ │ │
q[2]: ───[U(2.68,4.62,3.33)]───■─────[U(1.65,0.7,3.77)]───────────X───────────[U(1.59,0.01,5.24)]───■────[U(2.02,4.93,4.88)]───────────X───────────[U(1.51,0.03,2.18)]───■─────[U(0.85,2.16,6.1)]───X───
│ │ │
q[3]: ───[U(2.52,2.29,2.66)]───X─────[U(1.1,4.92,4.6)]────────────■───────────[U(0.54,0.36,4.25)]───X────[U(0.84,2.07,4.11)]───────────■───────────[U(0.23,4.11,0.27)]───X────[U(1.29,4.59,0.18)]───■───
│ │ │
q[4]: ───[U(1.18,2.46,0.42)]───■─────[U(0.22,5.31,0.9)]───────────X────────────[U(1.35,5.35,1.7)]───■────[U(0.95,5.07,4.92)]───────────X────────────[U(1.66,3.6,5.63)]───■─────[U(0.49,6.21,4.2)]───X───
│ │ │
q[5]: ───[U(2.79,5.79,2.77)]───X────[U(0.69,2.66,3.03)]───[U(1.86,4.0,5.3)]─────────────────────────X────[U(2.22,3.02,3.69)]──[U(0.05,4.21,6.16)]────────────────────────X────[U(1.52,4.78,3.07)]───────
Compiler Operations Depth: 12