Quantum gates are elementary units used to program quantum computers.
Each quantum gate can interact with 1 or more qubits. Quantum gates are represented by matrices of size 2x22x2. The action performed by a quantum gate on a qubit is the multiplication of the qubit's state vector by the matrix corresponding to the gate. All quantum gates must be reversible, that is, their inputs must be able to be predicted from their outputs.
We will use Hadamard (H) gates, in order to obtain a superposition of states, and a controlled NOT gate (CX or CNOT), in order to entangle the variables representing the photon and bomb with each other. Measuring the output of the circuit will now be a probabilistic process. The result we are interested in, in which the bomb did not explode and detector A was activated, should read with a probability close to 25%.
Among the simplest and most popular quantum gates is the X gate written as an array:
It is equivalent to the classical NOT gate. Its exemplary use on the cubit in the state |ψ〉= α|0〉+ β|1〉 is illustrated by calculations:
The following code compartment contains a short program that defines a quantum circuit. It applies an X operation on 1 qubit initialized (by default) with state |0〉, and then reads the result.
The next step is to read the result of the quantum circuit. In this case, the circuit will return the same result in a deterministic manner. Therefore, you can check the result of a single run of the circuit. In this case, the value1 was measured once, which is the expected result after applying the NOT operation to the input state |0〉.
Since usually the states are probabilistic in nature, a histogram of the distribution of measured values is often used to visualize the results. For this case, it will be a histogram with a single value and a reading probability of 100%.