Quickstart: Building and Running Circuits

Quickstart: Building and Running Circuits#

Welcome to Quex! Let’s build a simple Bell State (maximally entangled qubits).

import quex as qx

# 1. Define the geometry (The "Atoms" equivalent)
qc = qx.Circuit(num_qubits=2)

# 2. Add standard operations
qc.add_operation("h", 0)
qc.add_operation("cx", [0, 1])

# 3. Quex features a built-in topological visualizer
print("Circuit Topology:")
print(qc)
Circuit Topology:
q[0]: ───[H]───■───
               │   
q[1]: ─────────X───

To execute this, we attach a Simulator to our circuit. This completely decouples the math engine from the physical layout.

# Attach the lean Numpy backend
qc.simulator = qx.NumpySimulator()

# Run the simulation
state = qc.run()

print("Final Statevector:")
print(state.flatten())

vec = state.flatten()
prob = (vec * vec.conj()).real
print("Probabilities:")
print(prob)
Final Statevector:
[0.70710678+0.j 0.        +0.j 0.        +0.j 0.70710678+0.j]
Probabilities:
[0.5 0.  0.  0.5]