Skip to content

Instantly share code, notes, and snippets.

@victor-iyi
Created March 22, 2021 05:38
Show Gist options
  • Save victor-iyi/c22766fab6f219d16537a04c3b5d2671 to your computer and use it in GitHub Desktop.
Save victor-iyi/c22766fab6f219d16537a04c3b5d2671 to your computer and use it in GitHub Desktop.
Hello World Quantum computing using Google's cirq library
import cirq
# print(cirq.google.Sycamore)
a = cirq.NamedQubit('a')
b = cirq.NamedQubit('b')
# Create Circuit (logic-gate like)
circuit = cirq.Circuit(
cirq.H(a),
cirq.CNOT(a, b),
cirq.measure(a, b)
)
print(circuit)
# print(repr(circuit))
for i, moment in enumerate(circuit):
print(f'Moment - {i}: {moment}')
# Run on a simulator
simulator = cirq.Simulator()
# Run circuit on simulator with 20 repetitions.
simulator.run(circuit, repetitions=20)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment