Commit 482233b6 authored by Nguyen, Thien's avatar Nguyen, Thien

Added QLanczos to the Python example

Signed-off-by: Nguyen, Thien's avatarThien Nguyen <nguyentm@ornl.gov>
parent 8d4bac6c
# Simple 1-qubit demonstration of the Quatum Imaginary Time Evolution algorithm
# Simple 1-qubit demonstration of the Quatum Imaginary Time Evolution/QLanczos algorithm
# Reference: https://www.nature.com/articles/s41567-019-0704-4
# Target H = 1/sqrt(2)(X + Z)
# Expected minimum value: -1.0
......@@ -12,9 +12,6 @@ qpu = xacc.getAccelerator('qpp')
# Construct the Hamiltonian as an XACC PauliOperator
ham = xacc.getObservable('pauli', '0.70710678118 X0 + 0.70710678118 Z0')
# We just need 1 qubit
buffer = xacc.qalloc(1)
# See Fig. 2 (e) of https://www.nature.com/articles/s41567-019-0704-4
# Horizontal axis: 0 -> 2.5
# The number of Trotter steps
......@@ -30,13 +27,27 @@ qite = xacc.getAlgorithm('qite', {
'step-size': stepSize,
'steps': nbSteps
})
# We just need 1 qubit
qiteBuffer = xacc.qalloc(1)
qiteResult = qite.execute(qiteBuffer)
# Create the QLanczos algorithm
qLanczos = xacc.getAlgorithm('QLanczos', {
'accelerator': qpu,
'observable': ham,
'step-size': stepSize,
'steps': nbSteps
})
qLanczosBuffer = xacc.qalloc(1)
qLanczosResult = qLanczos.execute(qLanczosBuffer)
result = qite.execute(buffer)
# Plot the energies
qiteEnergies = qiteBuffer.getInformation('exp-vals')
qLanczosEnergies = qLanczosBuffer.getInformation('exp-vals')
# Expected result: ~ -1
print('Min energy value = ', buffer.getInformation('opt-val'))
E = buffer.getInformation('exp-vals')
# Reproduce Fig. 2(e) of https://www.nature.com/articles/s41567-019-0704-4
plt.plot(np.arange(0, nbSteps + 1) * stepSize, E, 'ro', label = 'XACC QITE')
plt.plot(np.arange(0, nbSteps + 1) * stepSize, qiteEnergies, 'ro-', label = 'QITE')
plt.plot(np.arange(0, (nbSteps + 1)//2) * 2 * stepSize, qLanczosEnergies, 'k*-', label = 'QLanczos')
plt.legend()
plt.grid()
plt.show()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment