39 lines
814 B
Python
39 lines
814 B
Python
import cirq
|
|
|
|
# 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)
|
|
|
|
|
|
# ----- Tutorial
|
|
import cirq
|
|
import numpy as np
|
|
import matplotlib
|
|
|
|
# Print Google's 72-qbit Bristlecone
|
|
print(cirq.google.Bristlecone)
|
|
|
|
# Use named Qubits
|
|
a = cirq.NamedQubit("a")
|
|
b = cirq.NamedQubit("b")
|
|
c = cirq.NamedQubit("c")
|
|
ops = [cirq.H(a), cirq.H(b), cirq.CNOT(b, c), cirq.H(b)]
|
|
circuit = cirq.Circuit.from_ops(ops)
|
|
print(circuit)
|
|
|
|
for i, moment in enumerate(circuit):
|
|
print('Moment {}: {}'.format(i, moment))
|