6 #include "catch2/catch.hpp" 10 #define IS_SET(byte,bit) (((byte) & (1UL << (bit))) >> (bit)) 13 using namespace Catch::Matchers;
27 std::size_t
calc_hammingDist(std::size_t pattern1, std::size_t pattern2, std::size_t len_bin_pattern){
28 std::size_t num_diffs = 0;
30 for(
int i = 0; i < len_bin_pattern; i++){
44 std::map<std::size_t, double>
expected_amplitude(std::vector<std::size_t>& target_vec, std::size_t test, std::size_t len_bin_pattern){
46 double norm_factor = 0.0;
49 std::map<std::size_t, double> exp_amp;
51 exp_amp.insert(pair<std::size_t, double>(target_vec[i],(
double)
calc_hammingDist(target_vec[i],test, len_bin_pattern)));
54 for(
auto& [k,v] : exp_amp){
55 v = sin(v * 0.5* M_PI / (
double) len_bin_pattern);
59 norm_factor = sqrt(norm_factor);
61 for(
auto& [k,v] : exp_amp){
72 TEST_CASE(
"Test Hamming distance with Roatation about y axis routine",
"[hammingroty]"){
73 const std::size_t max_qubits = 6;
74 double mach_eps = 7./3. - 4./3. -1.;
87 DYNAMIC_SECTION(
"Testing test pattern (integer format) = " <<
test_pattern ){
96 auto &r =
sim.getQubitRegister();
127 REQUIRE(r[i].real() + 10*mach_eps == Approx(0.).margin(1e-12));
128 REQUIRE(r[i].imag() + 10*mach_eps == Approx(0.).margin(1e-12) );
132 REQUIRE(r[i].real() + 10*mach_eps == Approx(0.).margin(1e-12));
133 REQUIRE(r[i].imag() + 10*mach_eps == Approx(0.).margin(1e-12) );
140 REQUIRE(r[i].imag() + 10*mach_eps == Approx(0.).margin(1e-12) );
144 REQUIRE(r[i].real() + 10*mach_eps == Approx(0.).margin(1e-12));
145 REQUIRE(r[i].imag() + 10*mach_eps == Approx(0.).margin(1e-12) );
std::size_t calc_hammingDist(std::size_t pattern1, std::size_t pattern2, std::size_t len_bin_pattern)
Calulates the Hamming distance between two binary strings stored as integers.
#define IS_SET(byte, bit)
Functions to compute the Hamming distance between a test pattern and the states in memory using y rot...
Class definition for IntelSimulator. The purpose of this class is to map the functionality of the und...
Class definition for implementing the Hamming distance routine along with controlled Y rotations to e...
TEST_CASE("Test Hamming distance with Roatation about y axis routine","[hammingroty]")
Test the Hamming distance routine which uses Y rotations to encode the Hamming distance into each sta...
std::map< std::size_t, double > expected_amplitude(std::vector< std::size_t > &target_vec, std::size_t test, std::size_t len_bin_pattern)
Classically calculates the Hamming distance between each binary string in a vector and a test binary ...