QCOR
quantum_phase_estimation.hpp
1 #pragma once
2 
3 // Common QCOR kernels to support iterative Quantum Phase Estimation algorithm.
4 
5 // First-order Trotter evolution
6 __qpu__ void pauli_trotter_evolution(qreg q, qcor::PauliOperator pauli_ham,
7  double evo_time, int num_time_slices) {
8  const double theta = evo_time / num_time_slices;
9  for (int i = 0; i < num_time_slices; ++i) {
10  exp_i_theta(q, theta, pauli_ham);
11  }
12 }
13 
14 // Raise Pauli evolution to a power: i.e. U^power.
15 __qpu__ void pauli_power_trotter_evolution(qreg q,
16  qcor::PauliOperator pauli_ham,
17  double evo_time, int num_time_slices,
18  int power) {
19  for (int i = 0; i < power; ++i) {
20  pauli_trotter_evolution(q, pauli_ham, evo_time, num_time_slices);
21  }
22 }
23 
24 // Kernel for a single iteration of iterative QPE
30 __qpu__ void pauli_qpe_iter(qreg q, int k, double omega,
31  qcor::PauliOperator pauli_ham, int num_time_slices,
32  int measure) {
33  // Ancilla qubit is the last qubit in the register
34  auto anc_idx = q.size() - 1;
35  // Hadamard on ancilla qubit
36  H(q[anc_idx]);
37  // Controlled-U
38  int power = 1 << (k - 1);
39  double evo_time = -2 * M_PI;
40  pauli_power_trotter_evolution::ctrl(anc_idx, q, pauli_ham, evo_time,
41  num_time_slices, power);
42 
43  // Rz on ancilla qubit
44  Rz(q[anc_idx], omega);
45  // Hadamard on ancilla qubit
46  H(q[anc_idx]);
47  if (measure) {
48  Measure(q[anc_idx]);
49  }
50 }