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

Class definition for defining and applying an Oracle. More...

#include <oracle.hpp>

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

Public Member Functions

 Oracle ()
 Construct a new Oracle object. More...
 
 ~Oracle ()
 Destroy the Oracle object. More...
 

Static Public Member Functions

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 appropriate PauliX gates to the control lines to call the NCU with the given matrix. More...
 
static void bitStringNCU (SimulatorType &s, std::size_t bitstring, const std::vector< std::size_t > &ctrl_indices, const std::vector< std::size_t > &aux_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 appropriate PauliX gates to the control lines to call the NCU with the given matrix. Optimised variant using auxiliary qubits to reduce circuit depth. More...
 
static void bitStringPhaseOracle (SimulatorType &s, std::size_t bitstring, const std::vector< std::size_t > &ctrlIndices, std::size_t target)
 Takes bitstring as the binary pattern and indices as the qubits to operate upon. Applies the appropriate PauliX gates to the control lines to call the NCU with the given matrix. More...
 

Private Types

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

Detailed Description

template<class SimulatorType>
class QNLP::Oracle< SimulatorType >

Class definition for defining and applying an Oracle.

Template Parameters
SimulatorTypeClass Simulator type

Definition at line 26 of file oracle.hpp.

Member Typedef Documentation

◆ Mat2x2Type

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

Definition at line 29 of file oracle.hpp.

Constructor & Destructor Documentation

◆ Oracle()

template<class SimulatorType>
QNLP::Oracle< SimulatorType >::Oracle ( )
inline

Construct a new Oracle object.

Definition at line 36 of file oracle.hpp.

36 {};

◆ ~Oracle()

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

Destroy the Oracle object.

Definition at line 42 of file oracle.hpp.

42 {};

Member Function Documentation

◆ bitStringNCU() [1/2]

template<class SimulatorType>
static void QNLP::Oracle< SimulatorType >::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 
)
inlinestatic

Takes bitstring as the binary pattern and indices as the qubits to operate upon. Applies the appropriate PauliX gates to the control lines to call the NCU with the given matrix.

Parameters
sInstance of quantum simulator
bitstringBinary pattern represented by a std::size_t bitstring
ctrl_indicesIndices of the control qubits in the register
targetQubit acting as target
UUnitary matrix to apply
gateLabelLabel to assign operation for U

Definition at line 54 of file oracle.hpp.

54  {
55  std::size_t bitmask = 0b1;
56  std::vector<std::size_t> reverse_pattern;
57  for(std::size_t i = 0; i < ctrl_indices.size() + 1; ++i){
58  //If the bitstring contains a 1 at desired index, will be true;
59  //We wish to apply X to any state that is false, then undo
60  if( ! (bitstring & (bitmask<<i) ) ){
61  reverse_pattern.push_back(i);
62  if( i < ctrl_indices.size())
63  s.applyGateX(ctrl_indices[i]);
64  else
65  s.applyGateX(target);
66  }
67  }
68  s.applyGateNCU(U, ctrl_indices, target, gateLabel);
69  //Undo PauliX ops
70  for(auto& revIdx : reverse_pattern){
71  if( revIdx < ctrl_indices.size()){
72  s.applyGateX(ctrl_indices[revIdx]);
73  }
74  else{
75  s.applyGateX(target);
76  }
77  }
78  }

References ncu_opt_tester::target.

Referenced by QNLP::SimulatorGeneral< IntelSimulator >::applyOracleU(), QNLP::Oracle< SimulatorType >::bitStringPhaseOracle(), and TEST_CASE().

Here is the caller graph for this function:

◆ bitStringNCU() [2/2]

template<class SimulatorType>
static void QNLP::Oracle< SimulatorType >::bitStringNCU ( SimulatorType &  s,
std::size_t  bitstring,
const std::vector< std::size_t > &  ctrl_indices,
const std::vector< std::size_t > &  aux_indices,
const std::size_t  target,
const Mat2x2Type U,
std::string  gateLabel 
)
inlinestatic

Takes bitstring as the binary pattern and indices as the qubits to operate upon. Applies the appropriate PauliX gates to the control lines to call the NCU with the given matrix. Optimised variant using auxiliary qubits to reduce circuit depth.

Parameters
sInstance of quantum simulator
bitstringBinary pattern represented by a std::size_t bitstring
ctrl_indicesIndices of the control qubits in the register
aux_indicesIndices of the auxiliary qubits in the register to reduce depth. State will be returned to pre-method call values.
targetQubit acting as target
UUnitary matrix to apply
gateLabelLabel to assign operation for U

Definition at line 92 of file oracle.hpp.

92  {
93  std::size_t bitmask = 0b1;
94  std::vector<std::size_t> reverse_pattern;
95  for(std::size_t i = 0; i < ctrl_indices.size() + 1; ++i){
96  //If the bitstring contains a 1 at desired index, will be true;
97  //We wish to apply X to any state that is false, then undo
98  if( ! (bitstring & (bitmask<<i) ) ){
99  reverse_pattern.push_back(i);
100  if( i < ctrl_indices.size())
101  s.applyGateX(ctrl_indices[i]);
102  else
103  s.applyGateX(target);
104  }
105  }
106  s.applyGateNCU(U, ctrl_indices, aux_indices, target, gateLabel);
107  //Undo PauliX ops
108  for(auto& revIdx : reverse_pattern){
109  if( revIdx < ctrl_indices.size()){
110  s.applyGateX(ctrl_indices[revIdx]);
111  }
112  else{
113  s.applyGateX(target);
114  }
115  }
116  }

References ncu_opt_tester::target.

◆ bitStringPhaseOracle()

template<class SimulatorType>
static void QNLP::Oracle< SimulatorType >::bitStringPhaseOracle ( SimulatorType &  s,
std::size_t  bitstring,
const std::vector< std::size_t > &  ctrlIndices,
std::size_t  target 
)
inlinestatic

Takes bitstring as the binary pattern and indices as the qubits to operate upon. Applies the appropriate PauliX gates to the control lines to call the NCU with the given matrix.

Parameters
sSimulator object
bitstringBinary pattern represented by a std::size_t bitstring
ctrlIndicesIndices of the control qubits in the register
targetQubit acting as target

Definition at line 126 of file oracle.hpp.

126  {
127  std::size_t num_qubits = s.getNumQubits();
128  assert ( (1<<num_qubits) < bitstring );
129  bitStringNCU(s, bitstring, ctrlIndices, target, s.getGateZ(), "Z");
130  }
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...
Definition: oracle.hpp:54

References QNLP::Oracle< SimulatorType >::bitStringNCU(), ncu_opt_tester::num_qubits, and ncu_opt_tester::target.

Referenced by QNLP::SimulatorGeneral< IntelSimulator >::applyOraclePhase(), and TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

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