coeffs = [1/2, 1/8, 1/4]
obs = [qml.PauliZ(0) @ qml.PauliZ(1), qml.PauliZ(0), qml.PauliZ(1)]
H = qml.Hamiltonian(coeffs, obs)# Create the Hamiltonian here
control_wires = [2, 3]
estimation_wires = [4, 5, 6, 7, 8 ,9]
dev = qml.device(“default.qubit”)
@qml.qnode(dev)
def prep_sel_prep_qpe(state):
“”"
Applies QPE to the PrepSelPrep encoding for the Hamiltonian H with some initial ground state
Args:
- state (list(float)): The initial state ground state candidate
Returns:
- np.ndarray(float): The output probabilities
"""
####################
###YOUR CODE HERE###
####################
qml.StatePrep(state, wires=[0, 1])
# 2. Apply Hadamards to the estimation wires to create a superposition.
for wire in estimation_wires:
qml.Hadamard(wires=wire)
# 3. Apply the controlled unitary operations C-(U^(2^k)).
# This requires repeating the application of the controlled unitary.
for k in range(len(estimation_wires)):
control_qubit = estimation_wires[k]
# U^(2^k) is implemented by applying U, 2^k times.
for _ in range(2**k):
qml.ctrl(qml.PrepSelPrep(H, control_wires), control=control_qubit)
# 4. Apply the inverse Quantum Fourier Transform (this was the main bug).
qml.QFT(wires=estimation_wires)
return qml.probs(wires=estimation_wires)
We know the matrix is diagonal, so the set of eigenstates is the computational basis
results = [prep_sel_prep_qpe(state) for state in np.eye(4)]
lambda_ = sum([abs(coeff) for coeff in H.terms()[0]])
eigenvalues = [lambda_ * np.cos(2 * np.pi * np.argmax(result) / 2 ** (len(estimation_wires))) for result in results]
Print the eigenvalues
print("E = ", eigenvalues)
Incorrect: your PREPSELPREP-QPE circuit isn’t quite right yet!, Can someone help me debug what is going wrong with my code.