# Creating an ansatz for variational quantum algorithms?

I was recently reading through the tutorial on the Cirq documentation about creating variational quantum algorithms, and I came to the section on ansatz preparation. The way that the ansatz is constructed in the tutorial is:

1. Apply an XPowGate for the same parameter for all qubits. This is the method we have written above.
2. Apply a ZPowGate for the same parameter for all qubits where the transverse field term h is +1.
3. Apply a CZPowGate for the same parameter between all qubits where the coupling field term J is +1. If the field is -1 apply CZPowGate conjugated by X gates on all qubits.

Now, I know that there is no single, consistent way to construct an ansatz, but I was wondering, how exactly was this ansatz arrived at, and how do we know that it is correct? The reason I ask this is because I was curious, and I changed the ZPow gate to an XPow gate, and got radically different results for the minimized energy.

Take a look again at the Hamiltonian, which is $$H = \sum_{\langle i, j \rangle} J_{i j} Z_i Z_j + \sum_{i} h_i Z_i$$ Then notice that ZPowGate is generated by the the Pauli Z operator, and CZPowGate is equivalent to an operator generated by $$Z \otimes Z$$ up to single-qubit rotations. The idea is that Step 2 of the ansatz corresponds to applying a pulse generated by the term on the right-hand side, and Step 3 corresponds to applying a pulse generated by the term on the left-hand side. Applying pulse sequences generated by terms of the Hamiltonian of interest is a common motivation for ansatz choice (see here, here, or here for papers that use this principle).
An alternative view of why it makes sense to include Step 1, and this kind of ansatz more generally, is explained in Section VI of the QAOA paper. The idea is motivated by quantum computation by adiabatic evolution. In such a computation, one prepares the ground state of an easy Hamiltonian, which in this case would be $$B = \sum_{i} X_i$$ and evolve under the time-dependent Hamiltonian $$G(t) = (1 - \frac{t}{T} B) + \frac{t}{T} H$$ for some total evolution time $$T$$. It turns out that a large enough evolution time $$T$$ will guarantee that the system ends up in the ground state of $$H$$. If you discretize this time evolution, you will get a bunch of time-steps which are like the ansatz: each time step has a gate generated by X on each qubit, and then gates generated by terms of the Hamiltonian. The idea then is to fix the number of time steps and then take the angles of the individual gates to be variational parameters. For a large enough number of ansatz steps, there will certainly be some choice of angles that gives the ground state, but the hope is that a small number of ansatz steps will suffice.
• Classically, each spin can be +1 or -1. There are $2^n$ possible spin configurations, where $n$ is the number of spins. Each configuration is assigned a scalar energy value according to the energy function. When mapping this problem to a quantum problem, the energy function is replaced with a Hamiltonian, and the values of the energy function correspond to eigenvalues of the Hamiltonian. It turns out that replacing each spin variable with a Pauli Z operator accomplishes exactly this mapping, with computational basis vectors being the eigenvectors. – Kevin Sung Feb 28 at 17:33