QNLP  v1.0
QNLP::HammingDistance< SimulatorType > Class Template Reference

Class definition for implementing the Hamming distance routine along with controlled Y rotations to encode the Hamming distance into the states' amplitudes. More...

#include <hamming.hpp>

Collaboration diagram for QNLP::HammingDistance< SimulatorType >:
Collaboration graph

Public Member Functions

 HammingDistance ()=delete
 Construct a new Hamming Distance Rot Y object (disabled) More...
 
 HammingDistance (const std::size_t len_bin_pattern_)
 Construct a new Hamming Distance Rot Y object. More...
 
 ~HammingDistance ()
 Destroy the Hamming Distance Rot Y object. More...
 

Static Public Member Functions

static void computeHammingDistanceRotY (SimulatorType &qSim, const std::vector< std::size_t > &reg_memory, const std::vector< std::size_t > &reg_auxiliary, std::size_t len_bin_pattern)
 Computes Hamming Distance; adjusts each state's amplitude proportional to the Hamming distance between the state's training pattern and the test pattern using rotations about y for each mattern qubit. More...
 
static void computeHammingDistanceOverwriteAux (SimulatorType &qSim, const std::vector< std::size_t > &reg_memory, const std::vector< std::size_t > &reg_auxiliary)
 Computes Hamming Distance; Overwrites the pattern in reg_auxiliary to track bit differences from reg_memory. More...
 

Private Types

using Mat2x2Type = decltype(std::declval< SimulatorType >().getGateX())
 

Private Attributes

std::size_t len_bin_pattern
 

Detailed Description

template<class SimulatorType>
class QNLP::HammingDistance< SimulatorType >

Class definition for implementing the Hamming distance routine along with controlled Y rotations to encode the Hamming distance into the states' amplitudes.

Template Parameters
SimulatorTypeClass simulator type

Definition at line 26 of file hamming.hpp.

Member Typedef Documentation

◆ Mat2x2Type

template<class SimulatorType>
using QNLP::HammingDistance< SimulatorType >::Mat2x2Type = decltype(std::declval<SimulatorType>().getGateX())
private

Definition at line 29 of file hamming.hpp.

Constructor & Destructor Documentation

◆ HammingDistance() [1/2]

template<class SimulatorType>
QNLP::HammingDistance< SimulatorType >::HammingDistance ( )
delete

Construct a new Hamming Distance Rot Y object (disabled)

◆ HammingDistance() [2/2]

template<class SimulatorType>
QNLP::HammingDistance< SimulatorType >::HammingDistance ( const std::size_t  len_bin_pattern_)
inline

Construct a new Hamming Distance Rot Y object.

Parameters
len_bin_pattern_Length of binary string which the Hamming distance is to be computed upon

Definition at line 45 of file hamming.hpp.

45  {
46  len_bin_pattern = len_bin_pattern_;
47  };
std::size_t len_bin_pattern
Definition: hamming.hpp:31

References QNLP::HammingDistance< SimulatorType >::len_bin_pattern.

◆ ~HammingDistance()

template<class SimulatorType>
QNLP::HammingDistance< SimulatorType >::~HammingDistance ( )
inline

Destroy the Hamming Distance Rot Y object.

Definition at line 53 of file hamming.hpp.

53  {
54  };

Member Function Documentation

◆ computeHammingDistanceOverwriteAux()

template<class SimulatorType>
static void QNLP::HammingDistance< SimulatorType >::computeHammingDistanceOverwriteAux ( SimulatorType &  qSim,
const std::vector< std::size_t > &  reg_memory,
const std::vector< std::size_t > &  reg_auxiliary 
)
inlinestatic

Computes Hamming Distance; Overwrites the pattern in reg_auxiliary to track bit differences from reg_memory.

Parameters
qSimQuantum simulator instance.
reg_memoryA vector containing the indices of the qubits of the memory register.
reg_auxiliaryA vector containing the indices of the qubits of the auxiliary register.

Definition at line 102 of file hamming.hpp.

104  {
105 
106  // Require length of auxiliary register to have n+2 qubits
107  assert(reg_memory.size() + 1 < reg_auxiliary.size());
108 
109  for(std::size_t i = 0; i < reg_memory.size(); i++){
110  qSim.applyGateX(reg_auxiliary[i]);
111  qSim.applyGateCCX(reg_memory[i], reg_auxiliary[i], *(reg_auxiliary.end()-2) );
112  qSim.applyGateX(reg_auxiliary[i]);
113  qSim.applyGateCSwap(reg_memory[i], reg_auxiliary[i], *(reg_auxiliary.end()-2) );
114  }
115  }

References QNLP_Python_MPI::reg_auxiliary, and QNLP_EndToEnd_MPI::reg_memory.

Referenced by QNLP::SimulatorGeneral< IntelSimulator >::applyHammingDistanceOverwrite().

Here is the caller graph for this function:

◆ computeHammingDistanceRotY()

template<class SimulatorType>
static void QNLP::HammingDistance< SimulatorType >::computeHammingDistanceRotY ( SimulatorType &  qSim,
const std::vector< std::size_t > &  reg_memory,
const std::vector< std::size_t > &  reg_auxiliary,
std::size_t  len_bin_pattern 
)
inlinestatic

Computes Hamming Distance; adjusts each state's amplitude proportional to the Hamming distance between the state's training pattern and the test pattern using rotations about y for each mattern qubit.

Parameters
qSimQuantum simulator instance.
reg_memoryA vector containing the indices of the qubits of the memory register.
reg_auxiliaryA vector containing the indices of the qubits of the auxiliary register.
len_bin_patternlength of binary pattern ie length of memory register.

Definition at line 64 of file hamming.hpp.

67  {
68 
69  double theta = M_PI / (double) len_bin_pattern;
70  auto Ry = qSim.getGateI();
71 
72  Ry(0,0) = std::complex<double>( cos(theta/2), 0.);
73  Ry(0,1) = std::complex<double>(-sin(theta/2), 0.);
74  Ry(1,0) = std::complex<double>( sin(theta/2), 0.);
75  Ry(1,1) = std::complex<double>( cos(theta/2), 0.);
76 
77  qSim.addUToCache("RY", Ry);
78 
79  std::size_t len_reg_auxiliary;
81 
82  // Require length of auxiliary register to have n+2 qubits
83  assert(reg_memory.size() + 1 < len_reg_auxiliary);
84 
85  for(std::size_t i = 0; i < len_bin_pattern; i++){
86  qSim.applyGateNCU(Ry, std::vector<std::size_t> {reg_auxiliary[i], reg_memory[i]}, reg_auxiliary[len_reg_auxiliary-2], "RY");
87  qSim.applyGateX(reg_memory[i]);
88  qSim.applyGateX(reg_auxiliary[i]);
89  qSim.applyGateNCU(Ry, std::vector<std::size_t> {reg_auxiliary[i], reg_memory[i]}, reg_auxiliary[len_reg_auxiliary-2], "RY");
90  qSim.applyGateX(reg_memory[i]);
91  qSim.applyGateX(reg_auxiliary[i]);
92  }
93  }
std::size_t len_bin_pattern
Definition: hamming.hpp:31

References QNLP::HammingDistance< SimulatorType >::len_bin_pattern, QNLP_Python_MPI::len_reg_auxiliary, QNLP_Python_MPI::reg_auxiliary, and QNLP_EndToEnd_MPI::reg_memory.

Referenced by QNLP::SimulatorGeneral< IntelSimulator >::applyHammingDistanceRotY().

Here is the caller graph for this function:

Field Documentation

◆ len_bin_pattern

template<class SimulatorType>
std::size_t QNLP::HammingDistance< SimulatorType >::len_bin_pattern
private

The documentation for this class was generated from the following file: