#include "diffusion.hpp"
#include "oracle.hpp"
#include "Simulator.hpp"
#include "IntelSimulator.cpp"
#include "catch2/catch.hpp"
#include <bitset>
 
Go to the source code of this file.
 | 
|   | TEST_CASE ("4 qubit diffusion using module","[diffusion]") | 
|   | Test diffusion for 4 qubits.  More...
  | 
|   | 
|   | TEST_CASE ("8 qubit diffusion using module","[diffusion]") | 
|   | Test diffusion for 8 qubits.  More...
  | 
|   | 
|   | TEST_CASE ("4 qubit diffusion using Simulator method","[diffusion]") | 
|   | Test diffusion for 4 qubits using Simulator method.  More...
  | 
|   | 
|   | TEST_CASE ("8 qubit diffusion using Simulator method","[diffusion]") | 
|   | Test diffusion for 8 qubits using Simulator method.  More...
  | 
|   | 
◆ Type
◆ TEST_CASE() [1/4]
      
        
          | TEST_CASE  | 
          ( | 
          "4 qubit diffusion using module"  | 
          ,  | 
        
        
           | 
           | 
          ""  | 
          [diffusion]  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Test diffusion for 4 qubits. 
Definition at line 17 of file test_diffusion.cpp.
   20     auto& reg = 
sim.getQubitRegister();
    21     double previous_prob = 0.;
    23     SECTION(
"2^4 bit patterns (16)"){
    25         std::vector<std::size_t> bit_patterns;
    26         for(std::size_t s = 0; s < (std::size_t)(0b1 << 
num_qubits); s++){
    27             bit_patterns.push_back(s);
    31         std::vector<std::size_t> ctrl_indices;
    33             ctrl_indices.push_back(i);
    42         for(
auto &i : bit_patterns){
    43             DYNAMIC_SECTION(
"bitStringNCU with pattern " << i){
    51                 for(
int iteration = 1 ; iteration < (M_PI/4)*sqrt( (0b1<<
num_qubits) / 1); iteration++){
    63                         REQUIRE( abs(reg[i])*abs(reg[i]) > abs(reg[0])*abs(reg[0]) );
    66                         REQUIRE( abs(reg[i])*abs(reg[i]) > abs(reg[1])*abs(reg[1]) );
    68                     REQUIRE( abs(reg[i])*abs(reg[i]) > previous_prob );
    69                     previous_prob = abs(reg[i])*abs(reg[i]);
 
Class definition for IntelSimulator. The purpose of this class is to map the functionality of the und...
 
Class definition for defining and applying an Oracle.
 
Class definition for applying Grover diffusion to a marked register.
 
static void bitStringNCU(SimulatorType &s, std::size_t bitstring, const std::vector< std::size_t > &ctrl_indices, const std::size_t target, const Mat2x2Type &U, std::string gateLabel)
Takes bitstring as the binary pattern and indices as the qubits to operate upon. Applies the appropri...
 
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...
 
 
References QNLP::Diffusion< SimulatorType >::applyOpDiffusion(), QNLP::Oracle< SimulatorType >::bitStringNCU(), ncu_opt_tester::num_qubits, and ncu_opt_tester::sim.
 
 
◆ TEST_CASE() [2/4]
      
        
          | TEST_CASE  | 
          ( | 
          "8 qubit diffusion using module"  | 
          ,  | 
        
        
           | 
           | 
          ""  | 
          [diffusion]  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Test diffusion for 8 qubits. 
Definition at line 80 of file test_diffusion.cpp.
   83     auto& reg = 
sim.getQubitRegister();
    84     double previous_prob = 0.;
    86     SECTION(
"2^8 bit patterns (256)"){
    88         std::vector<std::size_t> bit_patterns;
    89         for(std::size_t s = 0; s < (std::size_t)(0b1 << 
num_qubits); s++){
    90             bit_patterns.push_back(s);
    94         std::vector<std::size_t> ctrl_indices;
    96             ctrl_indices.push_back(i);
   105         for(
auto &i : bit_patterns){
   106             DYNAMIC_SECTION(
"bitStringNCU with pattern " << i){
   115                 for(
int iteration = 1 ; iteration < (M_PI/4)*sqrt( (0b1<<
num_qubits) / 1); iteration++){
   120                     CAPTURE( reg[i], i );
   125                     CAPTURE( reg[i], i );
   127                         REQUIRE( abs(reg[i])*abs(reg[i]) > abs(reg[0])*abs(reg[0]) );
   130                         REQUIRE( abs(reg[i])*abs(reg[i]) > abs(reg[1])*abs(reg[1]) );
   132                     REQUIRE( abs(reg[i])*abs(reg[i]) > previous_prob );
   133                     previous_prob = abs(reg[i])*abs(reg[i]);
 
Class definition for IntelSimulator. The purpose of this class is to map the functionality of the und...
 
Class definition for defining and applying an Oracle.
 
Class definition for applying Grover diffusion to a marked register.
 
static void bitStringNCU(SimulatorType &s, std::size_t bitstring, const std::vector< std::size_t > &ctrl_indices, const std::size_t target, const Mat2x2Type &U, std::string gateLabel)
Takes bitstring as the binary pattern and indices as the qubits to operate upon. Applies the appropri...
 
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...
 
 
References QNLP::Diffusion< SimulatorType >::applyOpDiffusion(), QNLP::Oracle< SimulatorType >::bitStringNCU(), ncu_opt_tester::num_qubits, and ncu_opt_tester::sim.
 
 
◆ TEST_CASE() [3/4]
      
        
          | TEST_CASE  | 
          ( | 
          "4 qubit diffusion using Simulator method"  | 
          ,  | 
        
        
           | 
           | 
          ""  | 
          [diffusion]  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Test diffusion for 4 qubits using Simulator method. 
Definition at line 144 of file test_diffusion.cpp.
  147     auto& reg = 
sim.getQubitRegister();
   148     double previous_prob = 0.;
   150     SECTION(
"2^4 bit patterns (16)"){
   152         std::vector<std::size_t> bit_patterns;
   153         for(std::size_t s = 0; s < (std::size_t)(0b1 << 
num_qubits); s++){
   154             bit_patterns.push_back(s);
   158         std::vector<std::size_t> ctrl_indices;
   159         for(std::size_t i = 0; i < 
num_qubits-1; ++i){
   160             ctrl_indices.push_back(i);
   164         for(
auto &i : bit_patterns){
   165             DYNAMIC_SECTION(
"bitStringNCU with pattern " << i){
   173                 for(
int iteration = 1 ; iteration < (M_PI/4)*sqrt( (0b1<<
num_qubits) / 1); iteration++){
   178                     CAPTURE( reg[i], i );
   181                     CAPTURE( reg[i], i );
   183                         REQUIRE( abs(reg[i])*abs(reg[i]) > abs(reg[0])*abs(reg[0]) );
   186                         REQUIRE( abs(reg[i])*abs(reg[i]) > abs(reg[1])*abs(reg[1]) );
   188                     REQUIRE( abs(reg[i])*abs(reg[i]) > previous_prob );
   189                     previous_prob = abs(reg[i])*abs(reg[i]);
 
Class definition for IntelSimulator. The purpose of this class is to map the functionality of the und...
 
 
References ncu_opt_tester::num_qubits, and ncu_opt_tester::sim.
 
 
◆ TEST_CASE() [4/4]
      
        
          | TEST_CASE  | 
          ( | 
          "8 qubit diffusion using Simulator method"  | 
          ,  | 
        
        
           | 
           | 
          ""  | 
          [diffusion]  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Test diffusion for 8 qubits using Simulator method. 
Definition at line 200 of file test_diffusion.cpp.
  203     auto& reg = 
sim.getQubitRegister();
   204     double previous_prob = 0.;
   206     SECTION(
"2^8 bit patterns (256)"){
   208         std::vector<std::size_t> bit_patterns;
   209         for(std::size_t s = 0; s < (std::size_t)(0b1 << 
num_qubits); s++){
   210             bit_patterns.push_back(s);
   214         std::vector<std::size_t> ctrl_indices;
   215         for(std::size_t i = 0; i < 
num_qubits-1; ++i){
   216             ctrl_indices.push_back(i);
   220         for(
auto &i : bit_patterns){
   221             DYNAMIC_SECTION(
"bitStringNCU with pattern " << i){
   230                 for(
int iteration = 1 ; iteration < (M_PI/4)*sqrt( (0b1<<
num_qubits) / 1); iteration++){
   235                     CAPTURE( reg[i], i );
   238                     CAPTURE( reg[i], i );
   241                         REQUIRE( abs(reg[i])*abs(reg[i]) > abs(reg[0])*abs(reg[0]) );
   244                         REQUIRE( abs(reg[i])*abs(reg[i]) > abs(reg[1])*abs(reg[1]) );
   246                     REQUIRE( abs(reg[i])*abs(reg[i]) > previous_prob );
   247                     previous_prob = abs(reg[i])*abs(reg[i]);
 
Class definition for IntelSimulator. The purpose of this class is to map the functionality of the und...
 
 
References ncu_opt_tester::num_qubits, and ncu_opt_tester::sim.