Parameterized Circuits & Late Binding#
Quex is built for high-throughput optimization. If you pass string variables to gates, Quex treats the circuit as a static template.
import quex as qx
# Generate a parameterized template
qc = qx.random_ansatz_P(num_qubits=6, depth=3, parameterized=True)
print("Template Structure:")
print(qc)
print(f"Circuit depth: {qc.depth}")
Template Structure:
q[0]: ───[U(t_0,p_0,l_0)]───■──────[U(t_6,p_6,l_6)]───[U(t_12,p_12,l_12)]────────────────────────■───
│ │
q[1]: ───[U(t_1,p_1,l_1)]───X──────[U(t_7,p_7,l_7)]────────────■───────────[U(t_13,p_13,l_13)]───X───
│
q[2]: ───[U(t_2,p_2,l_2)]───■──────[U(t_8,p_8,l_8)]────────────X───────────[U(t_14,p_14,l_14)]───■───
│ │
q[3]: ───[U(t_3,p_3,l_3)]───X──────[U(t_9,p_9,l_9)]────────────■───────────[U(t_15,p_15,l_15)]───X───
│
q[4]: ───[U(t_4,p_4,l_4)]───■────[U(t_10,p_10,l_10)]───────────X───────────[U(t_16,p_16,l_16)]───■───
│ │
q[5]: ───[U(t_5,p_5,l_5)]───X────[U(t_11,p_11,l_11)]──[U(t_17,p_17,l_17)]────────────────────────X───
Circuit depth: 6
When you add string parameters, Quex automatically registers them in the qc.parameters dictionary.
If a parameter is newly discovered, Quex defaults it to 0.0 so the circuit remains instantly runnable.
print("Auto-registered State (Initial Angles):")
for key, val in qc.parameters.items():
print(f"{key}: {val:.3f}")
# You can update the inherent state of the circuit directly
qc.parameters["t_0"] = 3.14159
qc.simulator = qx.NumpySimulator()
state = qc.run()
print("\nSuccessfully executed parameterized state!")
Auto-registered State (Initial Angles):
t_0: 1.489
p_0: 3.508
l_0: 4.637
t_1: 2.156
p_1: 1.192
l_1: 0.437
t_2: 0.905
p_2: 3.795
l_2: 0.100
t_3: 0.630
p_3: 3.411
l_3: 1.646
t_4: 1.289
p_4: 2.340
l_4: 2.409
t_5: 1.478
p_5: 4.703
l_5: 1.854
t_6: 2.075
p_6: 2.320
l_6: 4.882
t_7: 2.375
p_7: 3.789
l_7: 6.108
t_8: 2.380
p_8: 3.327
l_8: 3.885
t_9: 2.142
p_9: 4.471
l_9: 5.757
t_10: 1.281
p_10: 2.899
l_10: 5.913
t_11: 1.670
p_11: 6.278
l_11: 1.769
t_12: 2.913
p_12: 3.025
l_12: 0.280
t_13: 1.055
p_13: 5.744
l_13: 1.462
t_14: 0.318
p_14: 1.994
l_14: 1.566
t_15: 2.522
p_15: 1.823
l_15: 0.616
t_16: 2.038
p_16: 1.386
l_16: 3.915
t_17: 2.318
p_17: 4.696
l_17: 4.541
Successfully executed parameterized state!