Tests for quantum arithmetic using the (QFT) implementation.
More...
#include "catch2/catch.hpp"
#include "Simulator.hpp"
#include "IntelSimulator.cpp"
#include <memory>
#include "arithmetic.hpp"
#include <bitset>
Go to the source code of this file.
|
| TEST_CASE ("Arithmetic subtraction","[arithmetic]") |
| Test Arithmetic: subtraction. More...
|
|
| TEST_CASE ("Arithmetic summation","[arithmetic]") |
| Test Arithmetic: Summation. More...
|
|
Tests for quantum arithmetic using the (QFT) implementation.
- Author
- Lee J. O'Riordan (lee.o.nosp@m.rior.nosp@m.dan@i.nosp@m.chec.nosp@m..ie)
- Version
- 0.1
- Date
- 2019-09-10
- Copyright
- Copyright (c) 2019
Definition in file test_arithmetic.cpp.
◆ TEST_CASE() [1/2]
TEST_CASE |
( |
"Arithmetic subtraction" |
, |
|
|
"" |
[arithmetic] |
|
) |
| |
Test Arithmetic: subtraction.
Definition at line 27 of file test_arithmetic.cpp.
31 auto& r =
sim.getQubitRegister();
35 CAPTURE(r1_min, r1_max, r2_min, r2_max );
37 for(std::size_t pattern = 0; pattern < 1<<(
num_qubits/2); pattern ++){
38 unsigned int bitmask = 0x1;
41 for (
unsigned int i=0; i <= r1_max -1; i++){
43 a += (
unsigned int) pow(2,i);
45 for (
unsigned int j = r2_min; j <= r2_max; j++){
46 if ( (pattern & bitmask) > 0 ){
51 CAPTURE(pattern, a, bitmask);
52 arr.
sub_reg(
sim, r1_min, r1_max, r2_min, r2_max);
53 std::string result=
"";
56 for (
unsigned int j = r2_min; j <= r2_max; j++){
57 result += std::to_string( r.GetProbability( j )).at(0);
61 std::reverse(result.begin(), result.end());
62 std::cout <<
"Sub = " << std::bitset<4>(a) <<
"-" << std::bitset<4>(pattern) <<
"=> Expected:=" << std::bitset<4>(a-pattern) <<
" : Actual:=" << result << std::endl;
Class definition for IntelSimulator. The purpose of this class is to map the functionality of the und...
Class definition for bit-wise summation and subtraction of qubits.
static void sub_reg(SimulatorType &qReg, const unsigned int r1_min, const unsigned int r1_max, const unsigned int r2_min, const unsigned int r2_max)
Implements |r1>|r2> -> |r1>|r1-r2>. If r1 < r2 the state will underflow, with the subtraction continu...
References ncu_opt_tester::num_qubits, ncu_opt_tester::sim, and QNLP::Arithmetic< SimulatorType >::sub_reg().
◆ TEST_CASE() [2/2]
TEST_CASE |
( |
"Arithmetic summation" |
, |
|
|
"" |
[arithmetic] |
|
) |
| |
Test Arithmetic: Summation.
Definition at line 72 of file test_arithmetic.cpp.
73 std::size_t min_idx=0, max_idx=3;
77 auto& r =
sim.getQubitRegister();
79 SECTION(
"OLD_TEST",
"[arithmetic]"){
81 for(
int pattern = 0; pattern < 1<<(
num_qubits/2); pattern ++){
82 unsigned int bitmask = 0x1;
85 for (
unsigned int i=0; i <= r1_max -1; i++){
87 a += (
unsigned int) pow(2,i);
89 for (
unsigned int j = r2_min; j <= r2_max; j++){
90 if ( (pattern & bitmask) > 0 ){
95 arr.
sum_reg(
sim, r1_min, r1_max, r2_min, r2_max);
96 std::string result=
"";
98 for (
unsigned int j = r2_min; j <= r2_max; j++){
99 result += std::to_string( r.GetProbability( j )).at(0);
101 std::reverse(result.begin(), result.end());
102 std::cout <<
"Sub = " << std::bitset<4>(a) <<
"-" << std::bitset<4>(pattern) <<
"=> Expected:=" << std::bitset<4>(a-pattern) <<
" : Actual:=" << result << std::endl;
Class definition for IntelSimulator. The purpose of this class is to map the functionality of the und...
static void sum_reg(SimulatorType &qSim, CST r1_min, CST r1_max, CST r2_min, CST r2_max)
Implements |r1>|r2> -> |r1>|r1+r2>. Required bits to represent |r1+r2> should be available prior to c...
Class definition for bit-wise summation and subtraction of qubits.
References ncu_opt_tester::num_qubits, ncu_opt_tester::sim, and QNLP::Arithmetic< SimulatorType >::sum_reg().