QNLP  v1.0
diffusion.hpp
Go to the documentation of this file.
1 
12 #ifndef QNLP_DIFFUSION
13 #define QNLP_DIFFUSION
14 
15 #include <cstddef>
16 #include <cmath>
17 #include <complex>
18 #include <vector>
19 
20 namespace QNLP{
26  template <class SimulatorType>
27  class Diffusion{
28  public:
29 
34  Diffusion() {};
35 
40  ~Diffusion() {};
41 
49  void applyOpDiffusion( SimulatorType& sim, const std::vector<std::size_t>& ctrlIndices, const std::size_t target){
50  //For n-controlled not
51  for(auto& ctrl : ctrlIndices){
52  sim.applyGateH(ctrl);
53  sim.applyGateX(ctrl);
54  }
55  sim.applyGateH(target);
56  sim.applyGateX(target);
57 
58  sim.applyGateNCU(sim.getGateZ(), ctrlIndices, target, "Z");
59 
60  sim.applyGateX(target);
61  sim.applyGateH(target);
62 
63  for(auto& ctrl : ctrlIndices){
64  sim.applyGateX(ctrl);
65  sim.applyGateH(ctrl);
66  }
67  }
68  };
69 }
70 #endif
Class definition for applying Grover diffusion to a marked register.
Definition: diffusion.hpp:27
void applyOpDiffusion(SimulatorType &sim, const std::vector< std::size_t > &ctrlIndices, const std::size_t target)
Application of the Grover diffusion operator to already marked register. Follows the Q = -A S_0 A str...
Definition: diffusion.hpp:49
~Diffusion()
Destroy the Diffusion object.
Definition: diffusion.hpp:40
Diffusion()
Construct a new Diffusion object.
Definition: diffusion.hpp:34