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

Class definition for bit-wise grouping in register. More...

#include <bit_group.hpp>

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

Static Public Member Functions

static void bit_group (SimulatorType &qSim, const std::vector< std::size_t > &qreg_idx, const std::vector< std::size_t > &qaux_idx, bool lsb=true)
 Swaps all qubits in register indices given by qreg_idx to their right-most positions. Method works by pairing qubits using even-odd indexed cycles iteratively until all qubits are in the correct positions. Intermediate qubit reset operation may not be realisable on all platforms (Hadarmard followed by SigmaZ projection to |0>) More...
 

Static Private Member Functions

static void q_ops (SimulatorType &qSim, std::size_t qreg_idx0, std::size_t qreg_idx1, const std::vector< std::size_t > &qaux_idx)
 Swap the qubits if qreg_idx0 is set and qreg_idx1 is not. Uses Auxiliary qubits qaux_idx which are set to |10> at start and end of operations. More...
 
static void bit_swap_pair (SimulatorType &qSim, const std::vector< std::size_t > &qreg_idx, const std::vector< std::size_t > &qaux_idx, bool lsb)
 Swaps all qubits in register indices given by qreg_idx to their right-most positions. Method works by pairing qubits using even-odd indexed cycles iteratively until all qubits are in the correct positions. More...
 

Detailed Description

template<class SimulatorType>
class QNLP::BitGroup< SimulatorType >

Class definition for bit-wise grouping in register.

Template Parameters
SimulatorType

Definition at line 25 of file bit_group.hpp.

Member Function Documentation

◆ bit_group()

template<class SimulatorType >
static void QNLP::BitGroup< SimulatorType >::bit_group ( SimulatorType &  qSim,
const std::vector< std::size_t > &  qreg_idx,
const std::vector< std::size_t > &  qaux_idx,
bool  lsb = true 
)
inlinestatic

Swaps all qubits in register indices given by qreg_idx to their right-most positions. Method works by pairing qubits using even-odd indexed cycles iteratively until all qubits are in the correct positions. Intermediate qubit reset operation may not be realisable on all platforms (Hadarmard followed by SigmaZ projection to |0>)

Parameters
qSimQuantum simulator object derived from SimulatorGeneral
qreg_idxIndices of the qSim register to group to the LSB position.
qaux_idxIndices of auxiliary qubits in qSim register in |00> state
lsbIndicates if to shift the values to the MSB or LSB equivalent positions.

Definition at line 114 of file bit_group.hpp.

114  {
115  bit_swap_pair(qSim, qreg_idx, qaux_idx, lsb);
116  }
static void bit_swap_pair(SimulatorType &qSim, const std::vector< std::size_t > &qreg_idx, const std::vector< std::size_t > &qaux_idx, bool lsb)
Swaps all qubits in register indices given by qreg_idx to their right-most positions....
Definition: bit_group.hpp:83

References QNLP::BitGroup< SimulatorType >::bit_swap_pair().

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

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

◆ bit_swap_pair()

template<class SimulatorType >
static void QNLP::BitGroup< SimulatorType >::bit_swap_pair ( SimulatorType &  qSim,
const std::vector< std::size_t > &  qreg_idx,
const std::vector< std::size_t > &  qaux_idx,
bool  lsb 
)
inlinestaticprivate

Swaps all qubits in register indices given by qreg_idx to their right-most positions. Method works by pairing qubits using even-odd indexed cycles iteratively until all qubits are in the correct positions.

Parameters
qSimQuantum simulator object derived from SimulatorGeneral
qreg_idxIndices of the qSim register to group to the LSB position.
qaux_idxIndices of auxiliary qubits in qSim register in |00> state

Definition at line 83 of file bit_group.hpp.

83  {
84  bool isOdd = qreg_idx.size() % 2;
85  qSim.applyGateX(qaux_idx[0]);
86 
87  for(std::size_t num_steps = 0; num_steps < qreg_idx.size(); num_steps++){
88  for(int i = 0; i < qreg_idx.size()-1; i+=2){
89  if(i + 1 + isOdd < qreg_idx.size()){
90  if(lsb)
91  q_ops(qSim, qreg_idx[i + isOdd], qreg_idx[i + 1 + isOdd], qaux_idx);
92  else
93  q_ops(qSim, qreg_idx[i + 1 + isOdd], qreg_idx[i + isOdd], qaux_idx);
94 
95  }
96  }
97  isOdd = !isOdd;
98  }
99  qSim.applyGateX(qaux_idx[0]);
100  }
static void q_ops(SimulatorType &qSim, std::size_t qreg_idx0, std::size_t qreg_idx1, const std::vector< std::size_t > &qaux_idx)
Swap the qubits if qreg_idx0 is set and qreg_idx1 is not. Uses Auxiliary qubits qaux_idx which are se...
Definition: bit_group.hpp:36

References QNLP::BitGroup< SimulatorType >::q_ops().

Referenced by QNLP::BitGroup< SimulatorType >::bit_group().

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

◆ q_ops()

template<class SimulatorType >
static void QNLP::BitGroup< SimulatorType >::q_ops ( SimulatorType &  qSim,
std::size_t  qreg_idx0,
std::size_t  qreg_idx1,
const std::vector< std::size_t > &  qaux_idx 
)
inlinestaticprivate

Swap the qubits if qreg_idx0 is set and qreg_idx1 is not. Uses Auxiliary qubits qaux_idx which are set to |10> at start and end of operations.

Parameters
qSimQuantum simulator object derived from SimulatorGeneral
qreg_idx0Index of qubit 0 in qSim qubit register
qreg_idx1Index of qubit 1 in qSim qubit register
qaux_idxIndices of auxiliary qubits in qSim qubit register that are set to |10>

Definition at line 36 of file bit_group.hpp.

36  {
37 
38  //Swap if C0 is set and C1 is not
39  qSim.applyGateCCX(qreg_idx0, qaux_idx[0], qaux_idx[1]);
40  qSim.applyGateCCX(qreg_idx1, qreg_idx0, qaux_idx[1]);
41  qSim.applyGateCSwap(qaux_idx[1], qreg_idx0, qreg_idx1);
42 
43  //Reset Aux gate to |0>
44  qSim.applyGateH(qaux_idx[1]);
45  qSim.collapseToBasisZ(qaux_idx[1], 0);
46  }

Referenced by QNLP::BitGroup< SimulatorType >::bit_swap_pair().

Here is the caller graph for this function:

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