25 template <
class SimulatorType>
29 using Mat2x2Type = decltype(std::declval<SimulatorType>().getGateX());
54 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){
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){
60 if( ! (bitstring & (bitmask<<i) ) ){
61 reverse_pattern.push_back(i);
62 if( i < ctrl_indices.size())
63 s.applyGateX(ctrl_indices[i]);
68 s.applyGateNCU(U, ctrl_indices,
target, gateLabel);
70 for(
auto& revIdx : reverse_pattern){
71 if( revIdx < ctrl_indices.size()){
72 s.applyGateX(ctrl_indices[revIdx]);
92 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){
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){
98 if( ! (bitstring & (bitmask<<i) ) ){
99 reverse_pattern.push_back(i);
100 if( i < ctrl_indices.size())
101 s.applyGateX(ctrl_indices[i]);
106 s.applyGateNCU(U, ctrl_indices, aux_indices,
target, gateLabel);
108 for(
auto& revIdx : reverse_pattern){
109 if( revIdx < ctrl_indices.size()){
110 s.applyGateX(ctrl_indices[revIdx]);
~Oracle()
Destroy the Oracle object.
decltype(std::declval< SimulatorType >().getGateX()) Mat2x2Type
Class definition for defining and applying an Oracle.
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 appropri...
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...
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 appropri...
Oracle()
Construct a new Oracle object.