quantum/02_cirq.py

22 lines
496 B
Python
Raw Normal View History

import cirq
2019-10-06 17:42:53 +02:00
def main():
# Pick a qubit.
qubit = cirq.GridQubit(0, 0)
# Create a circuit
circuit = cirq.Circuit.from_ops(
cirq.X(qubit)**0.5, # Square root of NOT.
cirq.measure(qubit, key='m') # Measurement.
)
print("Circuit:")
print(circuit)
# Simulate the circuit several times.
simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=20)
print("Results:")
print(result)
if __name__ == "__main__":
main()