This repository contains the work carried out as part of the screening process for the Quantum Open Source Foundation mentorship programme. It aims to explore the problem set out in Task 1. Code.
The task is described as follows:
Implement, on a quantum simulator of your choice, the following 4 qubit state |(ψ)>:
Where the number of layers, denoted with L, has to be considered as a parameter. We call ¨Layer¨ the combination of 1 yellow + 1 green block, so, for example, U1 + U2 is a layer. The odd/even variational blocks are given by:
The angles θi, are variational parameters, lying in the interval (0, 2), initialized at random. Double qubit gates are CZ gates.
Report with a plot, as a function of the number of layers, L, the minimum distance:
ε = minθ || |(ψ(θ))> - |(φ(θ))> ||,
where |(φ(θ))> is a randomly generated vector on 4 qubits and the norm || | v> ||, of a state | v>, simply denotes the square root of the sum of the modulus square of the components of |v >. The right set of parameters i,n can be found via any method of choice (e.g. grid-search or gradient descent)
The 4 qubit state was implemented using Qiskit Terra. The circuit was constructed using qiskit.circuit. The functions used to create the gates in the circuit were implemented to allow parameterisation of the Rz and Rx gate angles as well as the number of layers in the circuit. The resulting circuit was simulated using StateVectorSimulator from Qiskit Aer. The resulting statevector was taken as a representation of |(ψ)> in the computational basis.
The target state, |(φ(θ))>, was represented by generating an array of 24 random numbers in the complex plane with modulus ≤ 1 and normalising. After initialsing the variational parameters randomly, the circuit was simulated and the resulting statevector used to calculate || |(ψ(θ))> - |(φ(θ))> || as described above.
In order to find the correct paramaters to find the minimum distance, ε, || |(ψ(θ))> - |(φ(θ))> || was treated as a cost function to be minimised using gradient descent. The iterative process can be described by the equation:
θn = θn-1 - γn-1 ∇ε(θn-1),
where γ is the learning rate and ∇ε is the gradient of the cost function with respect to the variational parameters, θ.
The gradient was calculated using the deriv method from Qiskit Aqua's analytic quantum gradient descent optimiser class (AQGD). This method is based on parameter-shift rules in which the analytic derivative for a quantum gate can be calculated simply by finding the difference between the resulting states for two sets of parameters (NB: this is distinct from finite-differences methods).
The learning rate, γ, was varied using the Barzilai-Borwei method. This method iterates γ using the following relation:
γn = |Δθ.Δε| / |Δε|2,
where Δθ = θn - θn-1 and Δε = ∇ε(θn) - ∇ε(θn-1). γ0 was taken as 0.1.
For each new set of variational parameters, the distance was calculated and stored. For each number of layers, L, gradient descent would be iterated n times and ε taken as the minimum value of the distances. If the improvement between iterations was less than 0.1% then the process was stopped. This was repeated for each L and ε was plotted against L using matplotlib.
The code for the task was written in python and is in the file Task-1-Circuit.py. The Qiskit, NumPy, and Matplotlib libraries are required to run it. Running it will produce a graph like that below.
A plot of the results for 1 ≤ L ≤ 9 and n ≤ 200 is presented below.
Through trial and error it was found that roughly less than 200 iterations were sufficient to converge on a value for ε for each L < 10. However, for values of L ≤ 3, the algorithim tended to give different values for ε. This suggests that either local minima were found and possibly that the choice of the Barzilai-Borwei method for learning parameter adjustment may be improved upon. Or, the minimum distance for small layers was dpendent on what target state was randomly generated. Nevertheless, the Barzilai-Borwei method was more successful than use of just a constant learning rate.
For L ≥ 5, the algorithm produced values for that are approximately zero. This is consistent with the findings in https://arxiv.org/pdf/quant-ph/0602174.pdf, which proposes a general quantum circuit pattern that can be used to implement any n-qubit quantum gate. The circuit shares a similar structure to the one used in this task by having layers of one-qubit gates and cascades of controlled Pauli gates. It is shown that n+1 layers are required, consistent with the results here.
https://arXiv:quant-ph/0407010 states 2n+1 − 2 one-qubit rotations and ⌈1/4 * (2n+1 − 3n − 2)⌉ CNOT gates is the lower bound for the number of qubits to produce an arbitary state with n qubits.
Even with only a handful of qubits and layers the calculations are intensive on a classical computer. Would different classical simulations and algorithms help us to explore larger quantum circuits?
The results here show that increasing the depth of the circuit for a fixed number of qubits will not help one get a more precise answer after a certain point. But will using a smaller/larger number of layers require fewer/more iterations to find |φ>? What is the associated computational cost? This question particuarly important went considering NISQs where noise and coherence times play an important role.


