# %% [markdown]
# # Cirq NISQ Payground
# Here are some code snippets that I'm playing with to learn quantum computing concepts
# 
# use the following command to install cirq:
# ```bash
# pip install cirq
# ```

#%%
import cirq


grid_length = 3

qbits = [cirq.GridQubit(i,j) for i in range(grid_length) for j in range(grid_length)]

circuit = cirq.Circuit()

circuit.append([cirq.H(q) for q in qbits if (q.row + q.col) % 2 == 0],
  strategy=cirq.InsertStrategy.EARLIEST)
circuit.append([cirq.X.on(q) for q in qbits if (q.row + q.col) % 2 == 1],
  strategy=cirq.InsertStrategy.NEW_THEN_INLINE)

print(circuit)

# iterate over moment
for i, m in enumerate(circuit):
    print('Moment {}: {}'.format(i, m))


simulator = cirq.Simulator()
circuit.append(cirq.measure(*qbits, key='x'))
results = simulator.run(circuit, repetitions=100)
print(results.histogram(key='x'))