q/main.py
2025-04-02 13:42:30 +04:00

47 lines
805 B
Python

from spinqit import (
CNOT,
BasicSimulatorConfig,
Circuit,
H,
X,
get_basic_simulator,
get_compiler,
view,
)
# Write the program
circ = Circuit()
q = circ.allocateQubits(2)
circ << (X, q[1])
circ << (H, q[0])
circ << (H, q[1])
circ << (CNOT, (q[0], q[1]))
circ << (H, q[0])
circ << (H, q[1])
# Choose the compiler and backend
comp = get_compiler("native")
engine = get_basic_simulator()
# Compile
optimization_level = 0
exe = comp.compile(circ, optimization_level)
view.draw(exe)
# Run
config = BasicSimulatorConfig()
config.configure_shots(1024)
result = engine.execute(exe, config)
print(result.counts)
view.draw(exe)
# Run
config = BasicSimulatorConfig()
config.configure_shots(1024)
result = engine.execute(exe, config)
print(result.counts)
print(result.counts)