# Cirq Programming 1: Single Qubit Gates

I used the Cirq programming language to program single qubit gates after understanding chapter 6, “Quantum Gates” of Quantum Computing as a High School Module.

While doing this, I was able to create a quantum circuit that implemented the X Gate, and Hadamard Gate using Cirq language. In this blog post, I will explain the functions of the Hadamard Gate, and the X Gate and how to program them using Cirq.

Qubits have two definite states, 0 or 1, as well as a superposition state. In superposition, qubits are neither 0 nor 1, but instead they are both. The superposition has a certain probability of being 0 or 1. When a qubit in superposition is measured, the superposition of the qubit will collapse, and the qubit will fall into one of the definite states based on the probabilities in the superposition.

Let’s look first at the Hadamard Gate.

The Hadamard Gate is used to put qubits into a superposition state. When a Hadamard Gate is applied to a qubit, the qubit is put into a superposition with a 50/50 chance of falling back into 0 or 1 when measured. Another thing to note about the Hadamard Gate is that by applying it twice to a qubit, you can recover the initial state of the qubit. So, if a qubit started in the 1 state, and 2 Hadamard Gates were applied in succession, then the qubit would be measured as 1 100% of the time.

Using Google’s Cirq language, I was able to produce the set of a 50/50 chance of being 0 or 1 by just applying one Hadamard gate, which puts the qubit into superposition, and then measuring the qubit. The code and a sample output are shown below: