QNLP  v1.0
QNLP::IntelSimulator Class Reference

Class definition for IntelSimulator. The purpose of this class is to map the functionality of the underlying quantum simulator to this class so that it can be used as the template for the CRTP templated SimulatorGeneral class. More...

Inheritance diagram for QNLP::IntelSimulator:
Inheritance graph
Collaboration diagram for QNLP::IntelSimulator:
Collaboration graph

Public Types

using TMDP = qhipster::TinyMatrix< ComplexDP, 2, 2, 32 >
 
using QRDP = QubitRegister< ComplexDP >
 
using CST = const std::size_t
 

Public Member Functions

 IntelSimulator (int numQubits, bool useFusion=false)
 Construct a new Intel Simulator object. The constructor also sets up and initialises the MPI environemnt if MPI is enabled in the build process. More...
 
 ~IntelSimulator ()
 Destroy the Intel Simulator object. More...
 
void applyGateU (const TMDP &U, CST qubitIndex, std::string label="U")
 Apply arbitrary user-defined unitary gate to qubit at qubit_idx. More...
 
void applyGateI (std::size_t qubitIndex)
 Apply the Identity gate to the given qubit. More...
 
void applyGatePhaseShift (std::size_t qubit_idx, double angle)
 Apply phase shift to given Qubit; [[1 0] [0 exp(i*angle)]]. More...
 
void applyGateSqrtSwap (std::size_t qubit_idx0, std::size_t qubit_idx1)
 Performs Sqrt SWAP gate between two given qubits (half way SWAP) More...
 
void applyGateCCX (std::size_t ctrl_qubit0, std::size_t ctrl_qubit1, std::size_t target_qubit)
 Controlled controlled NOT (CCNOT, CCX) gate. More...
 
void applyGateCSwap (std::size_t ctrl_qubit, std::size_t qubit_swap0, std::size_t qubit_swap1)
 
void applyGateX (CST qubitIndex)
 Apply the Pauli X gate to the given qubit. More...
 
void applyGateY (CST qubitIndex)
 Apply the Pauli Y gate to the given qubit. More...
 
void applyGateZ (CST qubitIndex)
 Apply the Pauli Z gate to the given qubit. More...
 
void applyGateH (CST qubitIndex)
 Apply the Hadamard gate to the given qubit. More...
 
void applyGateSqrtX (CST qubitIndex)
 Apply the Sqrt{Pauli X} gate to the given qubit. More...
 
void applyGateRotX (CST qubitIndex, double angle)
 Apply the given Rotation about X-axis to the given qubit. More...
 
void applyGateRotY (CST qubitIndex, double angle)
 Apply the given Rotation about Y-axis to the given qubit. More...
 
void applyGateRotZ (CST qubitIndex, double angle)
 Apply the given Rotation about Z-axis to the given qubit. More...
 
TMDP getGateX ()
 Get the Pauli-X gate. More...
 
TMDP getGateY ()
 Get the Pauli-Y gate. More...
 
TMDP getGateZ ()
 Get the Pauli-Z gate. More...
 
TMDP getGateI ()
 Get the Identity. More...
 
TMDP getGateH ()
 Get the Hadamard gate. More...
 
void applyGateCU (const TMDP &U, CST control, CST target, std::string label="U")
 Apply the given controlled unitary gate on target qubit. More...
 
void applyGateCX (CST control, CST target)
 Apply Controlled Pauli-X (CNOT) on target qubit. More...
 
void applyGateCY (CST control, CST target)
 Apply Controlled Pauli-Y on target qubit. More...
 
void applyGateCZ (CST control, CST target)
 Apply Controlled Pauli-Z on target qubit. More...
 
void applyGateCH (CST control, CST target)
 Apply Controlled Hadamard on target qubit. More...
 
void applyGateCPhaseShift (double angle, unsigned int control, unsigned int target)
 Perform controlled phase shift gate. More...
 
void applyGateCRotX (CST control, CST target, const double theta)
 Apply the given Controlled Rotation about X-axis to the given qubit. More...
 
void applyGateCRotY (CST control, CST target, double theta)
 Apply the given Controlled Rotation about Y-axis to the given qubit. More...
 
void applyGateCRotZ (CST control, CST target, const double theta)
 Apply the given Controlled Rotation about Z-axis to the given qubit. More...
 
void applyGateSwap (CST qubit_idx0, CST qubit_idx1)
 Swap the qubits at the given indices. More...
 
QubitRegister< ComplexDP > & getQubitRegister ()
 Get the Qubit Register object. More...
 
const QubitRegister< ComplexDP > & getQubitRegister () const
 Get the Qubit Register object. More...
 
std::size_t getNumQubits ()
 Get the number of Qubits. More...
 
void initRegister ()
 (Re)Initialise the underlying register of the encapsulated simulator to well-defined state (|0....0>) More...
 
void applyAmplitudeNorm ()
 Apply normalization to the amplitudes of each state. This is required after a qubit in a state is collapsed. More...
 
bool applyMeasurement (CST target, bool normalize=true)
 Apply measurement to a target qubit, randomly collapsing the qubit proportional to the amplitude and returns the collapsed value. If built with MPI enabled, this member function collpases the corresponding qubit in each state across all processes. More...
 
void collapseToBasisZ (CST target, bool collapseValue)
 Apply measurement to a target qubit with respect to the Z-basis, collapsing to a specified value (0 or 1). Amplitudes are r-normalized afterwards. More...
 
void PrintStates (std::string x, std::vector< std::size_t > qubits={})
 Prints the string x and then for each state of the specified qubits in the superposition, prints each its amplitude, followed by state and then by the probability of that state. Note that this state observation method is not a permitted quantum operation, however it is provided for convenience and debugging/testing. More...
 
std::pair< std::size_t, std::size_t > getGateCounts ()
 Print 1 and 2 qubit gate call counts. More...
 
complex< double > overlap (IntelSimulator &sim)
 Compute overlap between different simulators. Number of qubits must be the same. More...
 
void applyGateX (std::size_t qubit_idx)
 Apply the Pauli X gate to the given qubit. More...
 
void applyGateY (std::size_t qubit_idx)
 Apply the Pauli Y gate to the given qubit. More...
 
void applyGateZ (std::size_t qubit_idx)
 Apply the Pauli Z gate to the given qubit. More...
 
void applyGateH (std::size_t qubit_idx)
 Apply the Hadamard gate to the given qubit. More...
 
void applyGateSqrtX (std::size_t qubit_idx)
 Apply the Sqrt{Pauli X} gate to the given qubit. More...
 
void applyGateRotX (std::size_t qubit_idx, double angle_rad)
 Apply the given Rotation about X-axis to the given qubit. More...
 
void applyGateRotY (std::size_t qubit_idx, double angle_rad)
 Apply the given Rotation about Y-axis to the given qubit. More...
 
void applyGateRotZ (std::size_t qubit_idx, double angle_rad)
 Apply the given Rotation about Z-axis to the given qubit. More...
 
void applyGateU (const Mat2x2Type &U, std::size_t qubit_idx)
 Apply arbitrary user-defined unitary gate to qubit at qubit_idx. More...
 
void applyGateCU (const Mat2x2Type &U, const std::size_t control, const std::size_t target, std::string label="CU")
 Apply the given controlled unitary gate on target qubit. More...
 
void applyGateCX (const std::size_t control, const std::size_t target)
 Apply Controlled Pauli-X (CNOT) on target qubit. More...
 
void applyGateCY (const std::size_t control, const std::size_t target)
 Apply Controlled Pauli-Y on target qubit. More...
 
void applyGateCZ (const std::size_t control, const std::size_t target)
 Apply Controlled Pauli-Z on target qubit. More...
 
void applyGateCH (const std::size_t control, const std::size_t target)
 Apply Controlled Hadamard on target qubit. More...
 
void applyGateSwap (std::size_t qubit_idx0, std::size_t qubit_idx1)
 Swap the qubits at the given indices. More...
 
void applyGatePhaseShift (double angle, std::size_t qubit_idx)
 Apply phase shift to given Qubit; [[1 0] [0 exp(i*angle)]]. More...
 
void applyGateCPhaseShift (double angle, std::size_t control, std::size_t target)
 Perform controlled phase shift gate. More...
 
void applyGateCRotX (std::size_t ctrl_qubit, std::size_t qubit_idx, double angle_rad)
 Apply the given Controlled Rotation about X-axis to the given qubit. More...
 
void applyGateCRotY (std::size_t ctrl_qubit, std::size_t qubit_idx, double angle_rad)
 Apply the given Controlled Rotation about Y-axis to the given qubit. More...
 
void applyGateCRotZ (std::size_t ctrl_qubit, std::size_t qubit_idx, double angle_rad)
 Apply the given Controlled Rotation about Z-axis to the given qubit. More...
 
void applyQFT (std::size_t minIdx, std::size_t maxIdx)
 Apply the forward Quantum Fourier transform (QFT) to the given register index range. More...
 
void applyIQFT (std::size_t minIdx, std::size_t maxIdx)
 Apply the inverse Quantum Fourier transform (IQFT) to the given register index range. More...
 
void sumReg (std::size_t r0_minIdx, std::size_t r0_maxIdx, std::size_t r1_minIdx, std::size_t r1_maxIdx)
 Applies |r1>|r2> -> |r1>|r1+r2> More...
 
void subReg (std::size_t r0_minIdx, std::size_t r0_maxIdx, std::size_t r1_minIdx, std::size_t r1_maxIdx)
 Applies |r1>|r2> -> |r1>|r1-r2> More...
 
void applyGateNCU (const Mat2x2Type &U, const std::vector< std::size_t > &ctrlIndices, std::size_t target, std::string label)
 Apply n-control unitary gate to the given qubit target. More...
 
void applyGateNCU (const Mat2x2Type &U, const std::vector< std::size_t > &ctrlIndices, const std::vector< std::size_t > &auxIndices, std::size_t target, std::string label)
 Apply n-control sigma_x gate to the given qubit target, using auxiliary qubits for 5CX optimisation. More...
 
void applyOracleU (std::size_t bit_pattern, const std::vector< std::size_t > &ctrlIndices, std::size_t target, const Mat2x2Type &U, std::string gateLabel)
 Apply oracle to match given binary index with non adjacent controls. More...
 
void applyOracleU (std::size_t bit_pattern, const std::vector< std::size_t > &ctrlIndices, const std::vector< std::size_t > &auxIndices, std::size_t target, const Mat2x2Type &U, std::string gateLabel)
 Apply oracle to match given binary index with non adjacent controls. More...
 
void applyOraclePhase (std::size_t bit_pattern, const std::vector< std::size_t > &ctrlIndices, std::size_t target)
 Apply oracle to match given binary index with linearly adjacent controls. More...
 
void applyDiffusion (const std::vector< std::size_t > &ctrlIndices, std::size_t target)
 Apply diffusion operator on marked state. More...
 
void encodeToRegister (std::size_t target_pattern, const std::vector< std::size_t > target_register, std::size_t len_bin_pattern)
 Encodes a defined binary pattern into a defined target register (initially in state |00...0>) of all quantum states in the superposition. More...
 
void encodeBinToSuperpos_unique (const std::vector< std::size_t > &reg_memory, const std::vector< std::size_t > &reg_auxiliary, const std::vector< std::size_t > &bin_patterns, const std::size_t len_bin_pattern)
 Encode inputted binary strings to the memory register specified as a superposition of states. Note that this implementation does not allow for multiple instances of the same input pattern but allows for 0 to be encoded. More...
 
void applyHammingDistanceRotY (std::size_t test_pattern, const std::vector< std::size_t > reg_mem, const std::vector< std::size_t > reg_auxiliary, std::size_t len_bin_pattern)
 Computes the relative Hamming distance between the test pattern and the pattern stored in each state of the superposition, storing the result in the amplitude of the corresponding state. More...
 
void applyHammingDistanceOverwrite (std::size_t test_pattern, const std::vector< std::size_t > reg_mem, const std::vector< std::size_t > reg_auxiliary, std::size_t len_bin_pattern)
 Computes the relative Hamming distance between the test pattern and the pattern stored in each state of the superposition, overwriting the aux register pattern with the resulting bit differences. More...
 
bool applyMeasurement (std::size_t target, bool normalize=true)
 Apply measurement to a target qubit, randomly collapsing the qubit proportional to the amplitude and returns the collapsed value. More...
 
std::size_t applyMeasurementToRegister (std::vector< std::size_t > target_qubits, bool normalize=true)
 Apply measurement to a set of target qubits, randomly collapsing the qubits proportional to the amplitude and returns the bit string of the qubits in the order they are represented in the vector of indexes, in the form of an unsigned integer. More...
 
void groupQubits (const std::vector< std::size_t > reg_auxiliary, bool lsb=true)
 Group all set qubits to MSB in register (ie |010100> -> |000011>) More...
 
void collapseToBasisZ (std::size_t target, bool collapseValue)
 Apply measurement to a target qubit with respect to the Z-basis, collapsing to a specified value (0 or 1). Amplitudes are r-normalized afterwards. More...
 
void initCaches ()
 Initialise caches used in NCU operation. More...
 
void addUToCache (std::string gateLabel, const Mat2x2Type &U)
 Adds a matrix to the cache, assigning it to a defined label. This is used in the caching for the NCU operation. More...
 
Mat2x2Type matrixSqrt (const Mat2x2Type &U)
 Calculates the unitary matrix square root (U == VV, where V is returned) More...
 
void InvertRegister (const unsigned int minIdx, const unsigned int maxIdx)
 Invert the register about the given indides: 0,1,2...n-1,n -> n,n-1,...,1,0. More...
 

Static Public Member Functions

static Mat2x2Type adjointMatrix (const Mat2x2Type &U)
 Function to calculate the adjoint of an input matrix. More...
 

Protected Attributes

std::any sim_ncu
 

Private Member Functions

void collapseQubit (CST target, bool collapseValue)
 Collapses specified qubit in register to the collapseValue without applying normalization. More...
 
double getStateProbability (CST target)
 Get the probability of the specified qubit being in the state |1> More...
 

Private Attributes

const std::size_t uid
 
std::size_t numQubits
 
QRDP qubitRegister
 
std::vector< TMDPgates
 
std::size_t gate_count_1qubit
 
std::size_t gate_count_2qubit
 
std::random_device rd
 
std::mt19937 mt
 
std::uniform_real_distribution< double > dist
 

Detailed Description

Class definition for IntelSimulator. The purpose of this class is to map the functionality of the underlying quantum simulator to this class so that it can be used as the template for the CRTP templated SimulatorGeneral class.

Definition at line 35 of file IntelSimulator.cpp.

Member Typedef Documentation

◆ CST

using QNLP::IntelSimulator::CST = const std::size_t

Definition at line 39 of file IntelSimulator.cpp.

◆ QRDP

using QNLP::IntelSimulator::QRDP = QubitRegister<ComplexDP>

Definition at line 38 of file IntelSimulator.cpp.

◆ TMDP

using QNLP::IntelSimulator::TMDP = qhipster::TinyMatrix<ComplexDP, 2, 2, 32>

Definition at line 37 of file IntelSimulator.cpp.

Constructor & Destructor Documentation

◆ IntelSimulator()

QNLP::IntelSimulator::IntelSimulator ( int  numQubits,
bool  useFusion = false 
)
inline

Construct a new Intel Simulator object. The constructor also sets up and initialises the MPI environemnt if MPI is enabled in the build process.

Parameters
numQubitsNumber of qubits in quantum register
useFusionImplement gate fusion (default is False)

Definition at line 47 of file IntelSimulator.cpp.

47  : SimulatorGeneral<IntelSimulator>(),
49  qubitRegister(QubitRegister<ComplexDP> (numQubits, "base", 0)),
50  gates(5), uid( reinterpret_cast<std::size_t>(this) ){
51 
52  //Define Pauli X
53  gates[0](0,0) = ComplexDP(0.,0.); gates[0](0,1) = ComplexDP(1.,0.);
54  gates[0](1,0) = ComplexDP(1.,0.); gates[0](1,1) = ComplexDP(0.,0.);
55 
56  //Define Pauli Y
57  gates[1](0,0) = ComplexDP(0.,0.); gates[1](0,1) = -ComplexDP(0.,1.);
58  gates[1](1,0) = ComplexDP(0.,1.); gates[1](1,1) = ComplexDP(0.,0.);
59 
60  //Define Pauli Z
61  gates[2](0,0) = ComplexDP(1.,0.); gates[2](0,1) = ComplexDP(0.,0.);
62  gates[2](1,0) = ComplexDP(0.,0.); gates[2](1,1) = ComplexDP(-1.,0.);
63 
64  //Define I
65  gates[3](0,0) = ComplexDP(1.,0.); gates[3](0,1) = ComplexDP(0.,0.);
66  gates[3](1,0) = ComplexDP(0.,0.); gates[3](1,1) = ComplexDP(1.,0.);
67 
68  //Define Pauli H
69  double coeff = (1./sqrt(2.));
70  gates[4](0,0) = coeff*ComplexDP(1.,0.); gates[4](0,1) = coeff*ComplexDP(1.,0.);
71  gates[4](1,0) = coeff*ComplexDP(1.,0.); gates[4](1,1) = -coeff*ComplexDP(1.,0.);
72 
73  //Ensure the cache maps are populated before use.
74  this->initCaches();
75 
76  #ifdef ENABLE_MPI //If for some strange reason the MPI environement is not enable through the Base CRTP class, enable using Intel-QS
77  int mpi_is_init;
78  MPI_Initialized(&mpi_is_init);
79  if (! mpi_is_init){ // Attempt init using Intel-QS MPI env
80  int argc_tmp = 0;
81  char** argv_tmp = new char*[argc_tmp];
82 
83  qhipster::mpi::Environment env(argc_tmp, argv_tmp); //we do not expect to pass any params here
84  delete argv_tmp;
85  }
86  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
87  #endif
88 
89  /* Set up random number generator for randomly collapsing qubit to 0 or 1
90  *
91  * Note: a random number will be generated on rank 0 and then broadcasted
92  * to all ranks so that each rank collapses the respective qubit to the
93  * same value.
94  */
95  std::mt19937 mt_(rd());
96  std::uniform_real_distribution<double> dist_(0.0,1.0);
97  mt = mt_;
98  dist = dist_;
99  if(useFusion == true){
100  qubitRegister.TurnOnFusion();
101  std::cerr << "Warning: enabling fusion may cause inconsistent results." << std::endl;
102  }
103  gate_count_1qubit = 0;
104  gate_count_2qubit = 0;
105  }
std::size_t gate_count_2qubit
const std::size_t uid
std::random_device rd
std::uniform_real_distribution< double > dist
std::vector< TMDP > gates
std::size_t gate_count_1qubit
void initCaches()
Initialise caches used in NCU operation.
Definition: Simulator.hpp:687

References dist, gate_count_1qubit, gate_count_2qubit, gates, QNLP::SimulatorGeneral< IntelSimulator >::initCaches(), mt, qubitRegister, ncu_opt_tester::rank, and rd.

Here is the call graph for this function:

◆ ~IntelSimulator()

QNLP::IntelSimulator::~IntelSimulator ( )
inline

Destroy the Intel Simulator object.

Definition at line 111 of file IntelSimulator.cpp.

111 { }

Member Function Documentation

◆ addUToCache()

void QNLP::SimulatorGeneral< IntelSimulator >::addUToCache ( std::string  gateLabel,
const Mat2x2Type &  U 
)
inlineinherited

Adds a matrix to the cache, assigning it to a defined label. This is used in the caching for the NCU operation.

Template Parameters
Mat2x2TypeMatrix type to be cached
Parameters
gateLabelLabel assigned to the matrix being cached
UMatrix to be cached

Definition at line 703 of file Simulator.hpp.

703  {
704  #if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
705  std::experimental::any_cast<NCU<DerivedType>&>(sim_ncu).getGateCache().addToCache(static_cast<DerivedType&>(*this), gateLabel, U, 16);
706  #else
707  std::any_cast<NCU<DerivedType>&>(sim_ncu).getGateCache().addToCache(static_cast<DerivedType&>(*this), gateLabel, U, 16);
708  #endif
709  }

◆ adjointMatrix()

static Mat2x2Type QNLP::SimulatorGeneral< IntelSimulator >::adjointMatrix ( const Mat2x2Type &  U)
inlinestaticinherited

Function to calculate the adjoint of an input matrix.

Template Parameters
Mat2x2TypeMatrix type
Parameters
UUnitary matrix to be adjointed
Returns
openqu::TinyMatrix<Type, 2, 2, 32> U^{\dagger}

Definition at line 757 of file Simulator.hpp.

757  {
758  Mat2x2Type Uadjoint(U);
759  std::complex<double> tmp;
760  tmp = Uadjoint(0,1);
761  Uadjoint(0,1) = Uadjoint(1,0);
762  Uadjoint(1,0) = tmp;
763  Uadjoint(0,0) = std::conj(Uadjoint(0,0));
764  Uadjoint(0,1) = std::conj(Uadjoint(0,1));
765  Uadjoint(1,0) = std::conj(Uadjoint(1,0));
766  Uadjoint(1,1) = std::conj(Uadjoint(1,1));
767  return Uadjoint;
768  }

◆ applyAmplitudeNorm()

void QNLP::IntelSimulator::applyAmplitudeNorm ( )
inline

Apply normalization to the amplitudes of each state. This is required after a qubit in a state is collapsed.

Definition at line 642 of file IntelSimulator.cpp.

642  {
643  this->qubitRegister.Normalize();
644  }

References qubitRegister.

Referenced by applyMeasurement(), and collapseToBasisZ().

Here is the caller graph for this function:

◆ applyDiffusion()

void QNLP::SimulatorGeneral< IntelSimulator >::applyDiffusion ( const std::vector< std::size_t > &  ctrlIndices,
std::size_t  target 
)
inlineinherited

Apply diffusion operator on marked state.

Parameters
ctrlIndicesVector of control line indices
targetTarget qubit index to apply Ctrl-Z upon.

Definition at line 536 of file Simulator.hpp.

536  {
537  Diffusion<DerivedType> diffusion;
538  diffusion.applyOpDiffusion(static_cast<DerivedType&>(*this), ctrlIndices, target);
539  }

◆ applyGateCCX()

void QNLP::IntelSimulator::applyGateCCX ( std::size_t  ctrl_qubit0,
std::size_t  ctrl_qubit1,
std::size_t  target_qubit 
)
inline

Controlled controlled NOT (CCNOT, CCX) gate.

Parameters
ctrl_qubit0Control qubit 0
ctrl_qubit1Control qubit 1
target_qubitTarget qubit

Definition at line 193 of file IntelSimulator.cpp.

193  {
194  this->applyGateNCU(this->getGateX(), std::vector<std::size_t> {ctrl_qubit0, ctrl_qubit1}, target_qubit, "X");
195  }
void applyGateNCU(const Mat2x2Type &U, const std::vector< std::size_t > &ctrlIndices, std::size_t target, std::string label)
Apply n-control unitary gate to the given qubit target.
Definition: Simulator.hpp:462
TMDP getGateX()
Get the Pauli-X gate.

References QNLP::SimulatorGeneral< IntelSimulator >::applyGateNCU(), and getGateX().

Here is the call graph for this function:

◆ applyGateCH() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateCH ( const std::size_t  control,
const std::size_t  target 
)
inlineinherited

Apply Controlled Hadamard on target qubit.

Parameters
controlQubit index acting as control
targetQubit index acting as target

Definition at line 294 of file Simulator.hpp.

294  {
295  static_cast<DerivedType*>(this)->applyGateCH(control, target);
296  }

◆ applyGateCH() [2/2]

void QNLP::IntelSimulator::applyGateCH ( CST  control,
CST  target 
)
inline

Apply Controlled Hadamard on target qubit.

Parameters
controlQubit index acting as control
targetQubit index acting as target

Definition at line 496 of file IntelSimulator.cpp.

496  {
497  #ifndef RESOURCE_ESTIMATE
498  qubitRegister.ApplyCHadamard(control, target);
499  #endif
500 
502 
503  #ifdef GATE_LOGGING
504  writer.twoQubitGateCall( "H", getGateH().tostr(), control, target );
505  #endif
506  }
std::size_t gate_count_2qubit
TMDP getGateH()
Get the Hadamard gate.

References gate_count_2qubit, getGateH(), qubitRegister, and ncu_opt_tester::target.

Here is the call graph for this function:

◆ applyGateCPhaseShift() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateCPhaseShift ( double  angle,
std::size_t  control,
std::size_t  target 
)
inlineinherited

Perform controlled phase shift gate.

Parameters
angleAngle of phase shift in rads
controlIndex of control qubit
targetIndex of target qubit

Definition at line 335 of file Simulator.hpp.

335  {
336  static_cast<DerivedType*>(this)->applyGateCPhaseShift(angle, control, target);
337  }

◆ applyGateCPhaseShift() [2/2]

void QNLP::IntelSimulator::applyGateCPhaseShift ( double  angle,
unsigned int  control,
unsigned int  target 
)
inline

Perform controlled phase shift gate.

Parameters
angleAngle of phase shift in rads
controlIndex of control qubit
targetIndex of target qubit

Definition at line 515 of file IntelSimulator.cpp.

515  {
516  TMDP U(gates[3]);
517  U(1, 1) = ComplexDP(cos(angle), sin(angle));
518 
519  #ifndef RESOURCE_ESTIMATE
520  qubitRegister.ApplyControlled1QubitGate(control, target, U);
521  #endif
522 
524 
525  #ifdef GATE_LOGGING
526  writer.twoQubitGateCall( "CPhase", U.tostr(), control, target );
527  #endif
528  }
std::size_t gate_count_2qubit
qhipster::TinyMatrix< ComplexDP, 2, 2, 32 > TMDP
std::vector< TMDP > gates

References gate_count_2qubit, gates, qubitRegister, and ncu_opt_tester::target.

◆ applyGateCRotX() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateCRotX ( std::size_t  ctrl_qubit,
std::size_t  qubit_idx,
double  angle_rad 
)
inlineinherited

Apply the given Controlled Rotation about X-axis to the given qubit.

Parameters
ctrl_qubitControl qubit
qubit_idxIndex of qubit to rotate about X-axis
angle_radRotation angle

Definition at line 373 of file Simulator.hpp.

373  {
374  static_cast<DerivedType&>(*this).applyGateCRotX(ctrl_qubit, qubit_idx, angle_rad);
375  }

◆ applyGateCRotX() [2/2]

void QNLP::IntelSimulator::applyGateCRotX ( CST  control,
CST  target,
const double  theta 
)
inline

Apply the given Controlled Rotation about X-axis to the given qubit.

Parameters
controlControl qubit
targetIndex of qubit to rotate about X-axis
thetaRotation angle

Definition at line 537 of file IntelSimulator.cpp.

537  {
538  #ifndef RESOURCE_ESTIMATE
539  qubitRegister.ApplyCRotationX(control, target, theta);
540  #endif
541 
543 
544  #ifdef GATE_LOGGING
545  writer.twoQubitGateCall( "CR_X", getGateI().tostr(), control, target );
546  #endif
547  }
std::size_t gate_count_2qubit
TMDP getGateI()
Get the Identity.

References gate_count_2qubit, getGateI(), qubitRegister, and ncu_opt_tester::target.

Here is the call graph for this function:

◆ applyGateCRotY() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateCRotY ( std::size_t  ctrl_qubit,
std::size_t  qubit_idx,
double  angle_rad 
)
inlineinherited

Apply the given Controlled Rotation about Y-axis to the given qubit.

Parameters
ctrl_qubitControl qubit
qubit_idxIndex of qubit to rotate about Y-axis
angle_radRotation angle

Definition at line 384 of file Simulator.hpp.

384  {
385  static_cast<DerivedType&>(*this).applyGateCRotY(ctrl_qubit, qubit_idx, angle_rad);
386  }

◆ applyGateCRotY() [2/2]

void QNLP::IntelSimulator::applyGateCRotY ( CST  control,
CST  target,
double  theta 
)
inline

Apply the given Controlled Rotation about Y-axis to the given qubit.

Parameters
controlControl qubit
targetIndex of qubit to rotate about Y-axis
thetaRotation angle

Definition at line 556 of file IntelSimulator.cpp.

556  {
557  #ifndef RESOURCE_ESTIMATE
558  qubitRegister.ApplyCRotationY(control, target, theta);
559  #endif
560 
562 
563  #ifdef GATE_LOGGING
564  writer.twoQubitGateCall( "CR_Y", getGateI().tostr(), control, target );
565  #endif
566  }
std::size_t gate_count_2qubit
TMDP getGateI()
Get the Identity.

References gate_count_2qubit, getGateI(), qubitRegister, and ncu_opt_tester::target.

Here is the call graph for this function:

◆ applyGateCRotZ() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateCRotZ ( std::size_t  ctrl_qubit,
std::size_t  qubit_idx,
double  angle_rad 
)
inlineinherited

Apply the given Controlled Rotation about Z-axis to the given qubit.

Parameters
ctrl_qubitControl qubit
qubit_idxIndex of qubit to rotate about Z-axis
angle_radRotation angle

Definition at line 395 of file Simulator.hpp.

395  {
396  static_cast<DerivedType&>(*this).applyGateCRotZ(ctrl_qubit, qubit_idx, angle_rad);
397  }

◆ applyGateCRotZ() [2/2]

void QNLP::IntelSimulator::applyGateCRotZ ( CST  control,
CST  target,
const double  theta 
)
inline

Apply the given Controlled Rotation about Z-axis to the given qubit.

Parameters
controlControl qubit
targetIndex of qubit to rotate about Z-axis
thetaRotation angle

Definition at line 575 of file IntelSimulator.cpp.

575  {
576  #ifndef RESOURCE_ESTIMATE
577  qubitRegister.ApplyCRotationZ(control, target, theta);
578  #endif
579 
581 
582  #ifdef GATE_LOGGING
583  writer.twoQubitGateCall( "CR_Z", getGateI().tostr(), control, target );
584  #endif
585  }
std::size_t gate_count_2qubit
TMDP getGateI()
Get the Identity.

References gate_count_2qubit, getGateI(), qubitRegister, and ncu_opt_tester::target.

Here is the call graph for this function:

◆ applyGateCSwap()

void QNLP::IntelSimulator::applyGateCSwap ( std::size_t  ctrl_qubit,
std::size_t  qubit_swap0,
std::size_t  qubit_swap1 
)
inline
   @brief Controlled SWAP gate (Controlled swap decomposition taken from arXiV:1301.3727

)

   @param ctrl_qubit Control qubit
   @param qubit_swap0 Swap qubit 0
   @param qubit_swap1 Swap qubit 1

Definition at line 205 of file IntelSimulator.cpp.

205  {
206  //V = sqrt(X)
207  TMDP V;
208  V(0,0) = {0.5, 0.5};
209  V(0,1) = {0.5, -0.5};
210  V(1,0) = {0.5, -0.5};
211  V(1,1) = {0.5, 0.5};
212 
213  TMDP V_dag;
214  V_dag(0,0) = {0.5, -0.5};
215  V_dag(0,1) = {0.5, 0.5};
216  V_dag(1,0) = {0.5, 0.5};
217  V_dag(1,1) = {0.5, -0.5};
218 
219  applyGateCX(qubit_swap1, qubit_swap0);
220  applyGateCU(V, qubit_swap0, qubit_swap1, "X");
221  applyGateCU(V, ctrl_qubit, qubit_swap1, "X");
222 
223  applyGateCX(ctrl_qubit, qubit_swap0);
224  applyGateCU(V_dag, qubit_swap0, qubit_swap1, "X");
225  applyGateCX(qubit_swap1, qubit_swap0);
226  applyGateCX(ctrl_qubit, qubit_swap0);
227  }
void applyGateCX(CST control, CST target)
Apply Controlled Pauli-X (CNOT) on target qubit.
void applyGateCU(const TMDP &U, CST control, CST target, std::string label="U")
Apply the given controlled unitary gate on target qubit.
qhipster::TinyMatrix< ComplexDP, 2, 2, 32 > TMDP

References applyGateCU(), and applyGateCX().

Here is the call graph for this function:

◆ applyGateCU() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateCU ( const Mat2x2Type &  U,
const std::size_t  control,
const std::size_t  target,
std::string  label = "CU" 
)
inlineinherited

Apply the given controlled unitary gate on target qubit.

Parameters
UUser-defined arbitrary 2x2 unitary gate (matrix)
controlQubit index acting as control
targetQubit index acting as target

Definition at line 254 of file Simulator.hpp.

254  {
255  static_cast<DerivedType*>(this)->applyGateCU(U, control, target, label);
256  }

◆ applyGateCU() [2/2]

void QNLP::IntelSimulator::applyGateCU ( const TMDP U,
CST  control,
CST  target,
std::string  label = "U" 
)
inline

Apply the given controlled unitary gate on target qubit.

Parameters
UUser-defined arbitrary 2x2 unitary gate (matrix)
controlQubit index acting as control
targetQubit index acting as target
labelOptional parameter to label the gate U

Definition at line 424 of file IntelSimulator.cpp.

424  {
425  #ifndef RESOURCE_ESTIMATE
426  qubitRegister.ApplyControlled1QubitGate(control, target, U);
427  #endif
428 
430 
431  #ifdef GATE_LOGGING
432  writer.twoQubitGateCall( label, U.tostr(), control, target );
433  #endif
434  }
std::size_t gate_count_2qubit

References gate_count_2qubit, qubitRegister, and ncu_opt_tester::target.

Referenced by applyGateCSwap().

Here is the caller graph for this function:

◆ applyGateCX() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateCX ( const std::size_t  control,
const std::size_t  target 
)
inlineinherited

Apply Controlled Pauli-X (CNOT) on target qubit.

Parameters
controlQubit index acting as control
targetQubit index acting as target

Definition at line 264 of file Simulator.hpp.

264  {
265  static_cast<DerivedType*>(this)->applyGateCX(control, target);
266  }

◆ applyGateCX() [2/2]

void QNLP::IntelSimulator::applyGateCX ( CST  control,
CST  target 
)
inline

Apply Controlled Pauli-X (CNOT) on target qubit.

Parameters
controlQubit index acting as control
targetQubit index acting as target

Definition at line 442 of file IntelSimulator.cpp.

442  {
443  #ifndef RESOURCE_ESTIMATE
444  qubitRegister.ApplyCPauliX(control, target);
445  #endif
446 
448 
449  #ifdef GATE_LOGGING
450  writer.twoQubitGateCall( "X", getGateX().tostr(), control, target );
451  #endif
452  }
std::size_t gate_count_2qubit
TMDP getGateX()
Get the Pauli-X gate.

References gate_count_2qubit, getGateX(), qubitRegister, and ncu_opt_tester::target.

Referenced by applyGateCSwap().

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

◆ applyGateCY() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateCY ( const std::size_t  control,
const std::size_t  target 
)
inlineinherited

Apply Controlled Pauli-Y on target qubit.

Parameters
controlQubit index acting as control
targetQubit index acting as target

Definition at line 274 of file Simulator.hpp.

274  {
275  static_cast<DerivedType*>(this)->applyGateCY(control, target);
276  }

◆ applyGateCY() [2/2]

void QNLP::IntelSimulator::applyGateCY ( CST  control,
CST  target 
)
inline

Apply Controlled Pauli-Y on target qubit.

Parameters
controlQubit index acting as control
targetQubit index acting as target

Definition at line 460 of file IntelSimulator.cpp.

460  {
461  #ifndef RESOURCE_ESTIMATE
462  qubitRegister.ApplyCPauliY(control, target);
463  #endif
464 
466 
467  #ifdef GATE_LOGGING
468  writer.twoQubitGateCall( "Y", getGateY().tostr(), control, target );
469  #endif
470  }
std::size_t gate_count_2qubit
TMDP getGateY()
Get the Pauli-Y gate.

References gate_count_2qubit, getGateY(), qubitRegister, and ncu_opt_tester::target.

Here is the call graph for this function:

◆ applyGateCZ() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateCZ ( const std::size_t  control,
const std::size_t  target 
)
inlineinherited

Apply Controlled Pauli-Z on target qubit.

Parameters
controlQubit index acting as control
targetQubit index acting as target

Definition at line 284 of file Simulator.hpp.

284  {
285  static_cast<DerivedType*>(this)->applyGateCZ(control, target);
286  }

◆ applyGateCZ() [2/2]

void QNLP::IntelSimulator::applyGateCZ ( CST  control,
CST  target 
)
inline

Apply Controlled Pauli-Z on target qubit.

Parameters
controlQubit index acting as control
targetQubit index acting as target

Definition at line 478 of file IntelSimulator.cpp.

478  {
479  #ifndef RESOURCE_ESTIMATE
480  qubitRegister.ApplyCPauliZ(control, target);
481  #endif
482 
484 
485  #ifdef GATE_LOGGING
486  writer.twoQubitGateCall( "Z", getGateZ().tostr(), control, target );
487  #endif
488  }
std::size_t gate_count_2qubit
TMDP getGateZ()
Get the Pauli-Z gate.

References gate_count_2qubit, getGateZ(), qubitRegister, and ncu_opt_tester::target.

Here is the call graph for this function:

◆ applyGateH() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateH ( std::size_t  qubit_idx)
inlineinherited

Apply the Hadamard gate to the given qubit.

Parameters
qubit_idx

Definition at line 155 of file Simulator.hpp.

155  {
156  static_cast<DerivedType&>(*this).applyGateH(qubit_idx);
157  }

◆ applyGateH() [2/2]

void QNLP::IntelSimulator::applyGateH ( CST  qubitIndex)
inline

Apply the Hadamard gate to the given qubit.

Parameters
qubitIndex

Definition at line 287 of file IntelSimulator.cpp.

287  {
288  #ifndef RESOURCE_ESTIMATE
289  qubitRegister.ApplyHadamard(qubitIndex);
290  #endif
291 
293 
294  #ifdef GATE_LOGGING
295  writer.oneQubitGateCall("H", getGateH().tostr(), qubitIndex);
296  #endif
297  }
std::size_t gate_count_1qubit
TMDP getGateH()
Get the Hadamard gate.

References gate_count_1qubit, getGateH(), and qubitRegister.

Here is the call graph for this function:

◆ applyGateI()

void QNLP::IntelSimulator::applyGateI ( std::size_t  qubitIndex)
inline

Apply the Identity gate to the given qubit.

Parameters
qubitIndex

Definition at line 138 of file IntelSimulator.cpp.

138  {
139  #ifndef RESOURCE_ESTIMATE
140  applyGateU(getGateI(), qubitIndex, "I");
141  #endif
142 
144 
145  #ifdef GATE_LOGGING
146  writer.oneQubitGateCall("I", getGateI().tostr(), qubitIndex);
147  #endif
148  }
TMDP getGateI()
Get the Identity.
void applyGateU(const TMDP &U, CST qubitIndex, std::string label="U")
Apply arbitrary user-defined unitary gate to qubit at qubit_idx.
std::size_t gate_count_1qubit

References applyGateU(), gate_count_1qubit, and getGateI().

Here is the call graph for this function:

◆ applyGateNCU() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateNCU ( const Mat2x2Type &  U,
const std::vector< std::size_t > &  ctrlIndices,
std::size_t  target,
std::string  label 
)
inlineinherited

Apply n-control unitary gate to the given qubit target.

Template Parameters
Mat2x2Type2x2 Matrix type of unitary gate in the format expected by the derived simulator object; decltype(simulator.getGateX()) can be used in template
Parameters
U2x2 unitary matrix
ctrlIndicesVector of the control lines for NCU operation
targetTarget qubit index to apply nCU
labelGate label string (U, X, Y, etc.)

Definition at line 462 of file Simulator.hpp.

462  {
463  #if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
464  std::experimental::any_cast<NCU<DerivedType>&>(sim_ncu).applyNQubitControl(static_cast<DerivedType&>(*this), ctrlIndices, {}, target, label, U, 0);
465  #else
466  std::any_cast<NCU<DerivedType>&>(sim_ncu).applyNQubitControl(static_cast<DerivedType&>(*this), ctrlIndices, {}, target, label, U, 0);
467  #endif
468  }

◆ applyGateNCU() [2/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateNCU ( const Mat2x2Type &  U,
const std::vector< std::size_t > &  ctrlIndices,
const std::vector< std::size_t > &  auxIndices,
std::size_t  target,
std::string  label 
)
inlineinherited

Apply n-control sigma_x gate to the given qubit target, using auxiliary qubits for 5CX optimisation.

Template Parameters
Mat2x2Type2x2 Matrix type of unitary gate in the format expected by the derived simulator object; decltype(simulator.getGateX()) can be used in template
Parameters
U2x2 unitary matrix
minIdxLowest index of the control lines expected for nCU
maxIdxHighest index of the control lines expected for the nCU
targetTarget qubit index to apply nCU

Definition at line 480 of file Simulator.hpp.

480  {
481  #if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
482  std::experimental::any_cast<NCU<DerivedType>&>(sim_ncu).applyNQubitControl(static_cast<DerivedType&>(*this), ctrlIndices, auxIndices, target, label, U, 0);
483  #else
484  std::any_cast<NCU<DerivedType>&>(sim_ncu).applyNQubitControl(static_cast<DerivedType&>(*this), ctrlIndices, auxIndices, target, label, U, 0);
485  #endif
486  }

◆ applyGatePhaseShift() [1/2]

void QNLP::IntelSimulator::applyGatePhaseShift ( std::size_t  qubit_idx,
double  angle 
)
inline

Apply phase shift to given Qubit; [[1 0] [0 exp(i*angle)]].

Parameters
qubit_idxQubit index to perform phase shift upon
angleAngle of phase shift in rads

Definition at line 156 of file IntelSimulator.cpp.

156  {
157  //Phase gate is identity with 1,1 index modulated by angle
158  TMDP U(gates[3]);
159  U(1, 1) = ComplexDP(cos(angle), sin(angle));
160 
161  #ifndef RESOURCE_ESTIMATE
162  applyGateU(U, qubit_idx, "Phase:=" + std::to_string(angle));
163  #endif
164 
166 
167  #ifdef GATE_LOGGING
168  writer.oneQubitGateCall("PShift(theta=" + std::to_string(angle) + ")", U.tostr(), qubitIndex);
169  #endif
170 
171  }
void applyGateU(const TMDP &U, CST qubitIndex, std::string label="U")
Apply arbitrary user-defined unitary gate to qubit at qubit_idx.
qhipster::TinyMatrix< ComplexDP, 2, 2, 32 > TMDP
std::vector< TMDP > gates
std::size_t gate_count_1qubit

References applyGateU(), gate_count_1qubit, and gates.

Here is the call graph for this function:

◆ applyGatePhaseShift() [2/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGatePhaseShift ( double  angle,
std::size_t  qubit_idx 
)
inlineinherited

Apply phase shift to given Qubit; [[1 0] [0 exp(i*angle)]].

Parameters
angleAngle of phase shift in rads
qubit_idxQubit index to perform phase shift upon

Definition at line 324 of file Simulator.hpp.

324  {
325  static_cast<DerivedType*>(this)->applyGatePhaseShift(angle, qubit_idx);
326  }

◆ applyGateRotX() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateRotX ( std::size_t  qubit_idx,
double  angle_rad 
)
inlineinherited

Apply the given Rotation about X-axis to the given qubit.

Parameters
qubit_idxIndex of qubit to rotate about X-axis
angle_radRotation angle

Definition at line 172 of file Simulator.hpp.

172  {
173  static_cast<DerivedType&>(*this).applyGateRotX(qubit_idx, angle_rad);
174  }

◆ applyGateRotX() [2/2]

void QNLP::IntelSimulator::applyGateRotX ( CST  qubitIndex,
double  angle 
)
inline

Apply the given Rotation about X-axis to the given qubit.

Parameters
qubitIndexIndex of qubit to rotate about X-axis
angleRotation angle

Definition at line 326 of file IntelSimulator.cpp.

326  {
327  #ifndef RESOURCE_ESTIMATE
328  qubitRegister.ApplyRotationX(qubitIndex, angle);
329  #endif
330 
332 
333  #ifdef GATE_LOGGING
334  writer.oneQubitGateCall(
335  "R_X(\\theta=" + std::to_string(angle) + ")",
336  getGateI().tostr(),
337  qubitIndex
338  );
339  #endif
340  };
TMDP getGateI()
Get the Identity.
std::size_t gate_count_1qubit

References gate_count_1qubit, getGateI(), and qubitRegister.

Here is the call graph for this function:

◆ applyGateRotY() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateRotY ( std::size_t  qubit_idx,
double  angle_rad 
)
inlineinherited

Apply the given Rotation about Y-axis to the given qubit.

Parameters
qubit_idxIndex of qubit to rotate about Y-axis
angle_radRotation angle

Definition at line 181 of file Simulator.hpp.

181  {
182  static_cast<DerivedType&>(*this).applyGateRotY(qubit_idx, angle_rad);
183  }

◆ applyGateRotY() [2/2]

void QNLP::IntelSimulator::applyGateRotY ( CST  qubitIndex,
double  angle 
)
inline

Apply the given Rotation about Y-axis to the given qubit.

Parameters
qubitIndexIndex of qubit to rotate about X-axis
angleRotation angle

Definition at line 348 of file IntelSimulator.cpp.

348  {
349  #ifndef RESOURCE_ESTIMATE
350  qubitRegister.ApplyRotationY(qubitIndex, angle);
351  #endif
352 
354 
355  #ifdef GATE_LOGGING
356  writer.oneQubitGateCall(
357  "R_Y(\\theta=" + std::to_string(angle) + ")",
358  getGateI().tostr(),
359  qubitIndex
360  );
361  #endif
362  };
TMDP getGateI()
Get the Identity.
std::size_t gate_count_1qubit

References gate_count_1qubit, getGateI(), and qubitRegister.

Here is the call graph for this function:

◆ applyGateRotZ() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateRotZ ( std::size_t  qubit_idx,
double  angle_rad 
)
inlineinherited

Apply the given Rotation about Z-axis to the given qubit.

Parameters
qubit_idxIndex of qubit to rotate about Z-axis
angle_radRotation angle

Definition at line 190 of file Simulator.hpp.

190  {
191  static_cast<DerivedType&>(*this).applyGateRotZ(qubit_idx, angle_rad);
192  }

◆ applyGateRotZ() [2/2]

void QNLP::IntelSimulator::applyGateRotZ ( CST  qubitIndex,
double  angle 
)
inline

Apply the given Rotation about Z-axis to the given qubit.

Parameters
qubitIndexIndex of qubit to rotate about X-axis
angleRotation angle

Definition at line 370 of file IntelSimulator.cpp.

370  {
371  #ifndef RESOURCE_ESTIMATE
372  qubitRegister.ApplyRotationZ(qubitIndex, angle);
373  #endif
374 
376 
377  #ifdef GATE_LOGGING
378  writer.oneQubitGateCall(
379  "R_Z(\\theta=" + std::to_string(angle) + ")",
380  getGateI().tostr(),
381  qubitIndex
382  );
383  #endif
384  };
TMDP getGateI()
Get the Identity.
std::size_t gate_count_1qubit

References gate_count_1qubit, getGateI(), and qubitRegister.

Here is the call graph for this function:

◆ applyGateSqrtSwap()

void QNLP::IntelSimulator::applyGateSqrtSwap ( std::size_t  qubit_idx0,
std::size_t  qubit_idx1 
)
inline

Performs Sqrt SWAP gate between two given qubits (half way SWAP)

Parameters
qubit_idx0Qubit index 0
qubit_idx1Qubit index 1

Definition at line 180 of file IntelSimulator.cpp.

180  {
181  std::cerr << "NOT YET IMPLEMENTED" << std::endl;
182  std::abort();
183  }

◆ applyGateSqrtX() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateSqrtX ( std::size_t  qubit_idx)
inlineinherited

Apply the Sqrt{Pauli X} gate to the given qubit.

Parameters
qubit_idx

Definition at line 163 of file Simulator.hpp.

163  {
164  static_cast<DerivedType&>(*this).applyGateSqrtX(qubit_idx);
165  }

◆ applyGateSqrtX() [2/2]

void QNLP::IntelSimulator::applyGateSqrtX ( CST  qubitIndex)
inline

Apply the Sqrt{Pauli X} gate to the given qubit.

Parameters
qubit_idx

Definition at line 304 of file IntelSimulator.cpp.

304  {
305  #ifndef RESOURCE_ESTIMATE
306  qubitRegister.ApplyPauliSqrtX(qubitIndex);
307  #endif
308 
310 
311  #ifdef GATE_LOGGING
312  writer.oneQubitGateCall(
313  "\\sqrt[2]{X}",
314  matrixSqrt<decltype(getGateX())>(getGateX()).tostr(),
315  qubitIndex
316  );
317  #endif
318  };
TMDP getGateX()
Get the Pauli-X gate.
std::size_t gate_count_1qubit
Mat2x2Type matrixSqrt(const Mat2x2Type &U)
Calculates the unitary matrix square root (U == VV, where V is returned)
Definition: Simulator.hpp:729

References gate_count_1qubit, getGateX(), QNLP::SimulatorGeneral< IntelSimulator >::matrixSqrt(), and qubitRegister.

Here is the call graph for this function:

◆ applyGateSwap() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateSwap ( std::size_t  qubit_idx0,
std::size_t  qubit_idx1 
)
inlineinherited

Swap the qubits at the given indices.

Parameters
qubit_idx0Index of qubit 0 to swap &(0 -> 1)
qubit_idx1Index of qubit 1 to swap &(1 -> 0)

Definition at line 304 of file Simulator.hpp.

304  {
305  static_cast<DerivedType*>(this)->applyGateSwap(qubit_idx0,qubit_idx1);
306  }

◆ applyGateSwap() [2/2]

void QNLP::IntelSimulator::applyGateSwap ( CST  qubit_idx0,
CST  qubit_idx1 
)
inline

Swap the qubits at the given indices.

Parameters
qubit_idx0Index of qubit 0 to swap &(0 -> 1)
qubit_idx1Index of qubit 1 to swap &(1 -> 0)

Definition at line 593 of file IntelSimulator.cpp.

593  {
594  qubitRegister.ApplySwap(qubit_idx0, qubit_idx1);
595  #ifdef GATE_LOGGING
596  writer.twoQubitGateCall( "SWAP", getGateI().tostr(), qubit_idx0, qubit_idx1 );
597  #endif
598  }
TMDP getGateI()
Get the Identity.

References getGateI(), and qubitRegister.

Here is the call graph for this function:

◆ applyGateU() [1/2]

void QNLP::IntelSimulator::applyGateU ( const TMDP U,
CST  qubitIndex,
std::string  label = "U" 
)
inline

Apply arbitrary user-defined unitary gate to qubit at qubit_idx.

Parameters
UUser-defined unitary 2x2 matrix of templated type Mat2x2Type
qubitIndexIndex of qubit to apply gate upon
labelLabel for the gate U

Definition at line 121 of file IntelSimulator.cpp.

121  {
122  #ifndef RESOURCE_ESTIMATE
123  qubitRegister.Apply1QubitGate(qubitIndex, U);
124  #endif
125 
127 
128  #ifdef GATE_LOGGING
129  writer.oneQubitGateCall(label, U.tostr(), qubitIndex);
130  #endif
131  }
std::size_t gate_count_1qubit

References gate_count_1qubit, and qubitRegister.

Referenced by applyGateI(), and applyGatePhaseShift().

Here is the caller graph for this function:

◆ applyGateU() [2/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateU ( const Mat2x2Type &  U,
std::size_t  qubit_idx 
)
inlineinherited

Apply arbitrary user-defined unitary gate to qubit at qubit_idx.

Parameters
UUser-defined unitary 2x2 matrix of templated type Mat2x2Type
qubit_idxIndex of qubit to apply gate upon

Definition at line 201 of file Simulator.hpp.

201  {
202  static_cast<DerivedType*>(this)->applyGateU(U, qubit_idx);
203  }

◆ applyGateX() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateX ( std::size_t  qubit_idx)
inlineinherited

Apply the Pauli X gate to the given qubit.

Parameters
qubit_idx

Definition at line 123 of file Simulator.hpp.

123  {
124  static_cast<DerivedType&>(*this).applyGateX(qubit_idx);
125  };

◆ applyGateX() [2/2]

void QNLP::IntelSimulator::applyGateX ( CST  qubitIndex)
inline

Apply the Pauli X gate to the given qubit.

Parameters
qubitIndex

Definition at line 236 of file IntelSimulator.cpp.

236  {
237  #ifndef RESOURCE_ESTIMATE
238  qubitRegister.ApplyPauliX(qubitIndex);
239  #endif
240 
242 
243  #ifdef GATE_LOGGING
244  writer.oneQubitGateCall("X", getGateX().tostr(), qubitIndex);
245  #endif
246  }
TMDP getGateX()
Get the Pauli-X gate.
std::size_t gate_count_1qubit

References gate_count_1qubit, getGateX(), and qubitRegister.

Here is the call graph for this function:

◆ applyGateY() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateY ( std::size_t  qubit_idx)
inlineinherited

Apply the Pauli Y gate to the given qubit.

Parameters
qubit_idx

Definition at line 131 of file Simulator.hpp.

131  {
132  static_cast<DerivedType&>(*this).applyGateY(qubit_idx);
133  }

◆ applyGateY() [2/2]

void QNLP::IntelSimulator::applyGateY ( CST  qubitIndex)
inline

Apply the Pauli Y gate to the given qubit.

Parameters
qubitIndex

Definition at line 253 of file IntelSimulator.cpp.

253  {
254  #ifndef RESOURCE_ESTIMATE
255  qubitRegister.ApplyPauliY(qubitIndex);
256  #endif
257 
259 
260  #ifdef GATE_LOGGING
261  writer.oneQubitGateCall("Y", getGateY().tostr(), qubitIndex);
262  #endif
263  }
std::size_t gate_count_1qubit
TMDP getGateY()
Get the Pauli-Y gate.

References gate_count_1qubit, getGateY(), and qubitRegister.

Here is the call graph for this function:

◆ applyGateZ() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyGateZ ( std::size_t  qubit_idx)
inlineinherited

Apply the Pauli Z gate to the given qubit.

Parameters
qubit_idx

Definition at line 139 of file Simulator.hpp.

139  {
140  static_cast<DerivedType&>(*this).applyGateZ(qubit_idx);
141  }

◆ applyGateZ() [2/2]

void QNLP::IntelSimulator::applyGateZ ( CST  qubitIndex)
inline

Apply the Pauli Z gate to the given qubit.

Parameters
qubitIndex

Definition at line 270 of file IntelSimulator.cpp.

270  {
271  #ifndef RESOURCE_ESTIMATE
272  qubitRegister.ApplyPauliZ(qubitIndex);
273  #endif
274 
276 
277  #ifdef GATE_LOGGING
278  writer.oneQubitGateCall("Z", getGateZ().tostr(), qubitIndex);
279  #endif
280  }
std::size_t gate_count_1qubit
TMDP getGateZ()
Get the Pauli-Z gate.

References gate_count_1qubit, getGateZ(), and qubitRegister.

Here is the call graph for this function:

◆ applyHammingDistanceOverwrite()

void QNLP::SimulatorGeneral< IntelSimulator >::applyHammingDistanceOverwrite ( std::size_t  test_pattern,
const std::vector< std::size_t >  reg_mem,
const std::vector< std::size_t >  reg_auxiliary,
std::size_t  len_bin_pattern 
)
inlineinherited

Computes the relative Hamming distance between the test pattern and the pattern stored in each state of the superposition, overwriting the aux register pattern with the resulting bit differences.

Parameters
test_patternThe binary pattern used as the the basis for the Hamming Distance.
reg_memVector containing the indices of the register qubits that contain the training patterns.
reg_auxiliaryVector containing the indices of the register qubits which the first len_bin_pattern qubits will store the test_pattern.

Definition at line 609 of file Simulator.hpp.

612  {
613 
614  assert(reg_mem.size() < reg_auxiliary.size()-1);
615 
616  // Encode test pattern to auxiliary register
617  encodeToRegister(test_pattern, reg_auxiliary, len_bin_pattern);
618 
619  HammingDistance<DerivedType>::computeHammingDistanceOverwriteAux(static_cast<DerivedType&>(*this), reg_mem, reg_auxiliary);
620  }
void encodeToRegister(std::size_t target_pattern, const std::vector< std::size_t > target_register, std::size_t len_bin_pattern)
Encodes a defined binary pattern into a defined target register (initially in state |00....
Definition: Simulator.hpp:548

◆ applyHammingDistanceRotY()

void QNLP::SimulatorGeneral< IntelSimulator >::applyHammingDistanceRotY ( std::size_t  test_pattern,
const std::vector< std::size_t >  reg_mem,
const std::vector< std::size_t >  reg_auxiliary,
std::size_t  len_bin_pattern 
)
inlineinherited

Computes the relative Hamming distance between the test pattern and the pattern stored in each state of the superposition, storing the result in the amplitude of the corresponding state.

Parameters
test_patternThe binary pattern used as the the basis for the Hamming Distance.
reg_memVector containing the indices of the register qubits that contain the training patterns.
reg_auxiliaryVector containing the indices of the register qubits which the first len_bin_pattern qubits will store the test_pattern.
len_bin_patternLength of the binary patterns

Definition at line 584 of file Simulator.hpp.

587  {
588 
589  assert(len_bin_pattern < reg_auxiliary.size()-1);
590 
591  // Encode test pattern to auxiliary register
592  encodeToRegister(test_pattern, reg_auxiliary, len_bin_pattern);
593 
594  HammingDistance<DerivedType> hamming_operator(len_bin_pattern);
595  hamming_operator.computeHammingDistanceRotY(static_cast<DerivedType&>(*this), reg_mem, reg_auxiliary, len_bin_pattern);
596 
597  // Un-encode test pattern from auxiliary register
598  encodeToRegister(test_pattern, reg_auxiliary, len_bin_pattern);
599  }
void encodeToRegister(std::size_t target_pattern, const std::vector< std::size_t > target_register, std::size_t len_bin_pattern)
Encodes a defined binary pattern into a defined target register (initially in state |00....
Definition: Simulator.hpp:548

◆ applyIQFT()

void QNLP::SimulatorGeneral< IntelSimulator >::applyIQFT ( std::size_t  minIdx,
std::size_t  maxIdx 
)
inlineinherited

Apply the inverse Quantum Fourier transform (IQFT) to the given register index range.

Parameters
minIdxLowest qubit index of the IQFT range
maxIdxHighest qubit index of the IQFT range

Definition at line 433 of file Simulator.hpp.

433  {
434  QFT<decltype(static_cast<DerivedType&>(*this))>::applyIQFT(static_cast<DerivedType&>(*this), minIdx, maxIdx);
435  }
void applyIQFT(std::size_t minIdx, std::size_t maxIdx)
Apply the inverse Quantum Fourier transform (IQFT) to the given register index range.
Definition: Simulator.hpp:433

◆ applyMeasurement() [1/2]

bool QNLP::SimulatorGeneral< IntelSimulator >::applyMeasurement ( std::size_t  target,
bool  normalize = true 
)
inlineinherited

Apply measurement to a target qubit, randomly collapsing the qubit proportional to the amplitude and returns the collapsed value.

Returns
bool Value that qubit is randomly collapsed to
Parameters
targetThe index of the qubit being collapsed
normalizeOptional argument specifying whether amplitudes shoud be normalized (true) or not (false). Default value is true.

Definition at line 629 of file Simulator.hpp.

629  {
630  return static_cast<DerivedType*>(this)->applyMeasurement(target, normalize);
631  }

◆ applyMeasurement() [2/2]

bool QNLP::IntelSimulator::applyMeasurement ( CST  target,
bool  normalize = true 
)
inline

Apply measurement to a target qubit, randomly collapsing the qubit proportional to the amplitude and returns the collapsed value. If built with MPI enabled, this member function collpases the corresponding qubit in each state across all processes.

Returns
bool Value that qubit is randomly collapsed to
Parameters
targetThe index of the qubit being collapsed
normalizeOptional argument specifying whether amplitudes should be normalized (true) or not (false). Default value is true.

Definition at line 653 of file IntelSimulator.cpp.

653  {
654  double rand;
655  bool bit_val;
656 
657  #ifdef ENABLE_MPI
658  if(rank == 0){
659  rand = dist(mt);
660  }
661  MPI_Bcast(&rand, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
662  MPI_Barrier(MPI_COMM_WORLD);
663  #else
664  rand = dist(mt);
665  #endif
666  collapseQubit(target, (bit_val = ( rand < getStateProbability(target) ) ) );
667  if(normalize){
669  }
670  return bit_val;
671  }
void applyAmplitudeNorm()
Apply normalization to the amplitudes of each state. This is required after a qubit in a state is col...
double getStateProbability(CST target)
Get the probability of the specified qubit being in the state |1>
void collapseQubit(CST target, bool collapseValue)
Collapses specified qubit in register to the collapseValue without applying normalization.
std::uniform_real_distribution< double > dist

References applyAmplitudeNorm(), collapseQubit(), dist, getStateProbability(), mt, ncu_opt_tester::rank, and ncu_opt_tester::target.

Here is the call graph for this function:

◆ applyMeasurementToRegister()

std::size_t QNLP::SimulatorGeneral< IntelSimulator >::applyMeasurementToRegister ( std::vector< std::size_t >  target_qubits,
bool  normalize = true 
)
inlineinherited

Apply measurement to a set of target qubits, randomly collapsing the qubits proportional to the amplitude and returns the bit string of the qubits in the order they are represented in the vector of indexes, in the form of an unsigned integer.

Returns
std::size_t Integer representing the binary string of the collapsed qubits, ordered by least significant digit corresponding to first qubit in target vector of indices
Parameters
target_qubitsVector of indices of qubits being collapsed
normalizeOptional argument specifying whether amplitudes shoud be normalized (true) or not (false). Default value is true.

Definition at line 640 of file Simulator.hpp.

640  {
641  // Store current state of training register in it's integer format
642  std::size_t val = 0;
643  for(int j = target_qubits.size() - 1; j > -1; j--){
644  val |= (static_cast<DerivedType*>(this)->applyMeasurement(target_qubits[j], normalize) << j);
645  }
646  return val;
647  }

◆ applyOraclePhase()

void QNLP::SimulatorGeneral< IntelSimulator >::applyOraclePhase ( std::size_t  bit_pattern,
const std::vector< std::size_t > &  ctrlIndices,
std::size_t  target 
)
inlineinherited

Apply oracle to match given binary index with linearly adjacent controls.

Parameters
bit_patternOracle pattern in binary
ctrlIndicesControl lines for oracle
targetTarget qubit index to apply Z gate upon

Definition at line 524 of file Simulator.hpp.

524  {
525  //applyOracleU<decltype(static_cast<DerivedType*>(this)->getGateZ())>(bit_pattern, ctrlIndices, target, static_cast<DerivedType*>(this)->getGateZ());
526  Oracle<DerivedType> oracle;
527  oracle.bitStringPhaseOracle(static_cast<DerivedType&>(*this), bit_pattern, ctrlIndices, target );
528  }

◆ applyOracleU() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyOracleU ( std::size_t  bit_pattern,
const std::vector< std::size_t > &  ctrlIndices,
std::size_t  target,
const Mat2x2Type &  U,
std::string  gateLabel 
)
inlineinherited

Apply oracle to match given binary index with non adjacent controls.

Parameters
bit_patternOracle state pattern (bitstring: 0-> |0>, 1-> |1>)
U2x2 unitary matrix to apply
ctrlIndicesControl indices for operation
targetTarget qubit index to apply U on
gateLabelLabel used to access required cached matrix for NCU

Definition at line 498 of file Simulator.hpp.

498  {
499  Oracle<DerivedType>::bitStringNCU(static_cast<DerivedType&>(*this), bit_pattern, ctrlIndices, target, U, gateLabel);
500  }

◆ applyOracleU() [2/2]

void QNLP::SimulatorGeneral< IntelSimulator >::applyOracleU ( std::size_t  bit_pattern,
const std::vector< std::size_t > &  ctrlIndices,
const std::vector< std::size_t > &  auxIndices,
std::size_t  target,
const Mat2x2Type &  U,
std::string  gateLabel 
)
inlineinherited

Apply oracle to match given binary index with non adjacent controls.

Parameters
bit_patternOracle state pattern (bitstring: 0-> |0>, 1-> |1>)
U2x2 unitary matrix to apply
ctrlIndicesControl indices for operation
auxIndicesAuxiliary indices for operation
targetTarget qubit index to apply U on
gateLabelLabel used to access required cached matrix for NCU

Definition at line 513 of file Simulator.hpp.

513  {
514  Oracle<DerivedType>::bitStringNCU(static_cast<DerivedType&>(*this), bit_pattern, ctrlIndices, auxIndices, target, U, gateLabel);
515  }

◆ applyQFT()

void QNLP::SimulatorGeneral< IntelSimulator >::applyQFT ( std::size_t  minIdx,
std::size_t  maxIdx 
)
inlineinherited

Apply the forward Quantum Fourier transform (QFT) to the given register index range.

Parameters
minIdxLowest qubit index of the QFT range
maxIdxHighest qubit index of the QFT range

Definition at line 423 of file Simulator.hpp.

423  {
424  QFT<decltype(static_cast<DerivedType&>(*this))>::applyQFT(static_cast<DerivedType&>(*this), minIdx, maxIdx);
425  }
void applyQFT(std::size_t minIdx, std::size_t maxIdx)
Apply the forward Quantum Fourier transform (QFT) to the given register index range.
Definition: Simulator.hpp:423

◆ collapseQubit()

void QNLP::IntelSimulator::collapseQubit ( CST  target,
bool  collapseValue 
)
inlineprivate

Collapses specified qubit in register to the collapseValue without applying normalization.

Parameters
targetIndex of qubit to be collapsed
collapseValueValue qubit is collapsed to (0 or 1)

Definition at line 758 of file IntelSimulator.cpp.

758  {
759  qubitRegister.CollapseQubit(target, collapseValue);
760  }

References qubitRegister, and ncu_opt_tester::target.

Referenced by applyMeasurement(), and collapseToBasisZ().

Here is the caller graph for this function:

◆ collapseToBasisZ() [1/2]

void QNLP::SimulatorGeneral< IntelSimulator >::collapseToBasisZ ( std::size_t  target,
bool  collapseValue 
)
inlineinherited

Apply measurement to a target qubit with respect to the Z-basis, collapsing to a specified value (0 or 1). Amplitudes are r-normalized afterwards.

Parameters
targetThe index of the qubit being collapsed
collapseValueThe value that the register will be collapsed to (either 0 ro 1).

Definition at line 671 of file Simulator.hpp.

671  {
672  static_cast<DerivedType*>(this)->collapseToBasisZ(target, collapseValue);
673  }

◆ collapseToBasisZ() [2/2]

void QNLP::IntelSimulator::collapseToBasisZ ( CST  target,
bool  collapseValue 
)
inline

Apply measurement to a target qubit with respect to the Z-basis, collapsing to a specified value (0 or 1). Amplitudes are r-normalized afterwards.

Parameters
targetThe index of the qubit being collapsed
collapseValueThe value that the register will be collapsed to (either 0 ro 1).

Definition at line 679 of file IntelSimulator.cpp.

679  {
680  collapseQubit(target, collapseValue);
682  }
void applyAmplitudeNorm()
Apply normalization to the amplitudes of each state. This is required after a qubit in a state is col...
void collapseQubit(CST target, bool collapseValue)
Collapses specified qubit in register to the collapseValue without applying normalization.

References applyAmplitudeNorm(), collapseQubit(), and ncu_opt_tester::target.

Here is the call graph for this function:

◆ encodeBinToSuperpos_unique()

void QNLP::SimulatorGeneral< IntelSimulator >::encodeBinToSuperpos_unique ( const std::vector< std::size_t > &  reg_memory,
const std::vector< std::size_t > &  reg_auxiliary,
const std::vector< std::size_t > &  bin_patterns,
const std::size_t  len_bin_pattern 
)
inlineinherited

Encode inputted binary strings to the memory register specified as a superposition of states. Note that this implementation does not allow for multiple instances of the same input pattern but allows for 0 to be encoded.

Parameters
reg_memorystd::vector of unsigned integers containing the indices of the circuit's memory register
reg_auxiliarystd::vector of unsigned integers type containing the indices of the circuit's auxiliary register
bin_patternsstd::vector of unsigned integers representing the binary patterns to encode
len_bin_patternThe length of the binary patterns being encoded

Definition at line 567 of file Simulator.hpp.

570  {
571 
572  EncodeBinIntoSuperpos<DerivedType> encoder(bin_patterns.size(), len_bin_pattern);
573  encoder.encodeBinInToSuperpos_unique(static_cast<DerivedType&>(*this), reg_memory, reg_auxiliary, bin_patterns);
574  }

◆ encodeToRegister()

void QNLP::SimulatorGeneral< IntelSimulator >::encodeToRegister ( std::size_t  target_pattern,
const std::vector< std::size_t >  target_register,
std::size_t  len_bin_pattern 
)
inlineinherited

Encodes a defined binary pattern into a defined target register (initially in state |00...0>) of all quantum states in the superposition.

Parameters
target_patternThe binary pattern that is to be encoded
target_registerVector containing the indices of the register qubits that the pattern is to be encoded into (beginning at least significant digit). Note, the target register is expected to be in the state consisting of all 0's before the encoding.
Lengthof the binary pattern to be encoded

Definition at line 548 of file Simulator.hpp.

550  {
551 
552  for(std::size_t i = 0; i < len_bin_pattern; i++){
553  if(IS_SET(target_pattern,i)){
554  applyGateX(target_register[i]);
555  }
556  }
557  }
#define IS_SET(byte, bit)
Definition: Simulator.hpp:58
void applyGateX(std::size_t qubit_idx)
Apply the Pauli X gate to the given qubit.
Definition: Simulator.hpp:123

◆ getGateCounts()

std::pair<std::size_t, std::size_t> QNLP::IntelSimulator::getGateCounts ( )
inline

Print 1 and 2 qubit gate call counts.

Definition at line 709 of file IntelSimulator.cpp.

709  {
710  std::cout << "######### Gate counts #########" << std::endl;
711  std::cout << "1 qubit = " << gate_count_1qubit << std::endl;
712  std::cout << "2 qubit = " << gate_count_2qubit << std::endl;
713  std::cout << "total = " << gate_count_1qubit + gate_count_2qubit << std::endl;
714  std::cout << "###############################" << std::endl;
715  return std::make_pair(gate_count_1qubit, gate_count_2qubit);
716  }
std::size_t gate_count_2qubit
std::size_t gate_count_1qubit

References gate_count_1qubit, and gate_count_2qubit.

◆ getGateH()

TMDP QNLP::IntelSimulator::getGateH ( )
inline

Get the Hadamard gate.

Returns
TMDP return type of Hadamard gate

Definition at line 414 of file IntelSimulator.cpp.

414 { return gates[4]; }
std::vector< TMDP > gates

References gates.

Referenced by applyGateCH(), and applyGateH().

Here is the caller graph for this function:

◆ getGateI()

TMDP QNLP::IntelSimulator::getGateI ( )
inline

Get the Identity.

Returns
TMDP return type of the Identity

Definition at line 408 of file IntelSimulator.cpp.

408 { return gates[3]; }
std::vector< TMDP > gates

References gates.

Referenced by applyGateCRotX(), applyGateCRotY(), applyGateCRotZ(), applyGateI(), applyGateRotX(), applyGateRotY(), applyGateRotZ(), and applyGateSwap().

Here is the caller graph for this function:

◆ getGateX()

TMDP QNLP::IntelSimulator::getGateX ( )
inline

Get the Pauli-X gate.

Returns
TMDP return type of Pauli-X gate

Definition at line 390 of file IntelSimulator.cpp.

390 { return gates[0]; }
std::vector< TMDP > gates

References gates.

Referenced by applyGateCCX(), applyGateCX(), applyGateSqrtX(), and applyGateX().

Here is the caller graph for this function:

◆ getGateY()

TMDP QNLP::IntelSimulator::getGateY ( )
inline

Get the Pauli-Y gate.

Returns
TMDP return type of Pauli-Y gate

Definition at line 396 of file IntelSimulator.cpp.

396 { return gates[1]; }
std::vector< TMDP > gates

References gates.

Referenced by applyGateCY(), and applyGateY().

Here is the caller graph for this function:

◆ getGateZ()

TMDP QNLP::IntelSimulator::getGateZ ( )
inline

Get the Pauli-Z gate.

Returns
TMDP return type of Pauli-Z gate

Definition at line 402 of file IntelSimulator.cpp.

402 { return gates[2]; }
std::vector< TMDP > gates

References gates.

Referenced by applyGateCZ(), and applyGateZ().

Here is the caller graph for this function:

◆ getNumQubits()

std::size_t QNLP::IntelSimulator::getNumQubits ( )
inline

Get the number of Qubits.

Returns
std::size_t Number of qubits in register

Definition at line 623 of file IntelSimulator.cpp.

623  {
624  return numQubits;
625  }

References numQubits.

Referenced by TEST_CASE().

Here is the caller graph for this function:

◆ getQubitRegister() [1/2]

QubitRegister<ComplexDP>& QNLP::IntelSimulator::getQubitRegister ( )
inline

Get the Qubit Register object.

Returns
QubitRegister<ComplexDP>& Returns a refernce to the Qubit Register object

Definition at line 605 of file IntelSimulator.cpp.

605  {
606  return this->qubitRegister;
607  }

References qubitRegister.

Referenced by TEST_CASE().

Here is the caller graph for this function:

◆ getQubitRegister() [2/2]

const QubitRegister<ComplexDP>& QNLP::IntelSimulator::getQubitRegister ( ) const
inline

Get the Qubit Register object.

Returns
const QubitRegister<ComplexDP>& Returns a refernce to the Qubit Register object

Definition at line 614 of file IntelSimulator.cpp.

614  {
615  return this->qubitRegister;
616  };

References qubitRegister.

◆ getStateProbability()

double QNLP::IntelSimulator::getStateProbability ( CST  target)
inlineprivate

Get the probability of the specified qubit being in the state |1>

Parameters
targetTarget qubit
Returns
double Probability that the target qubit is in the state |1>

Definition at line 768 of file IntelSimulator.cpp.

768  {
769  return qubitRegister.GetProbability(target);
770  }

References qubitRegister, and ncu_opt_tester::target.

Referenced by applyMeasurement().

Here is the caller graph for this function:

◆ groupQubits()

void QNLP::SimulatorGeneral< IntelSimulator >::groupQubits ( const std::vector< std::size_t >  reg_auxiliary,
bool  lsb = true 
)
inlineinherited

Group all set qubits to MSB in register (ie |010100> -> |000011>)

Parameters
reg_memThe indices of the qubits to perform operation upon
reg_auxiliaryThe auxiliary control qubit register set to |......10> at the beginning, and guaranteed to be set the same at end.
lsbShifts to LSB position in register if true; MSB otherwise.

Definition at line 656 of file Simulator.hpp.

656  {
657  assert( reg_auxiliary.size() >= 2);
658 
659  const std::vector<std::size_t> reg_ctrl ( reg_auxiliary.end()-2, reg_auxiliary.end() );
660  const std::vector<std::size_t> sub_reg (reg_auxiliary.begin(), reg_auxiliary.end()-2 ) ;
661 
662  BitGroup<DerivedType>::bit_group(static_cast<DerivedType&>(*this), sub_reg, reg_ctrl, lsb);
663  }

◆ initCaches()

void QNLP::SimulatorGeneral< IntelSimulator >::initCaches ( )
inlineinherited

Initialise caches used in NCU operation.

Definition at line 687 of file Simulator.hpp.

687  {
688  #if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
689  std::experimental::any_cast<NCU<DerivedType>&>(sim_ncu).initialiseMaps(static_cast<DerivedType&>(*this), 16);
690  #else
691  std::any_cast<NCU<DerivedType>&>(sim_ncu).initialiseMaps(static_cast<DerivedType&>(*this), 16);
692  #endif
693  }

◆ initRegister()

void QNLP::IntelSimulator::initRegister ( )
inline

(Re)Initialise the underlying register of the encapsulated simulator to well-defined state (|0....0>)

Definition at line 631 of file IntelSimulator.cpp.

631  {
632  this->qubitRegister.Initialize("base",0);
633  this->initCaches();
634  gate_count_1qubit = 0;
635  gate_count_2qubit = 0;
636  }
std::size_t gate_count_2qubit
std::size_t gate_count_1qubit
void initCaches()
Initialise caches used in NCU operation.
Definition: Simulator.hpp:687

References gate_count_1qubit, gate_count_2qubit, QNLP::SimulatorGeneral< IntelSimulator >::initCaches(), and qubitRegister.

Here is the call graph for this function:

◆ InvertRegister()

void QNLP::SimulatorGeneral< IntelSimulator >::InvertRegister ( const unsigned int  minIdx,
const unsigned int  maxIdx 
)
inlineinherited

Invert the register about the given indides: 0,1,2...n-1,n -> n,n-1,...,1,0.

Parameters
minIdxThe lower index of the inversion
maxIdxThe upper index of the inversion

Definition at line 776 of file Simulator.hpp.

776  {
777  unsigned int range2 = ((maxIdx - minIdx)%2 == 1) ? (maxIdx - minIdx)/2 +1 : (maxIdx - minIdx)/2;
778  for(unsigned int idx = 0; idx < range2; idx++){
779  applyGateSwap(minIdx+idx, maxIdx-idx);
780  }
781  }
void applyGateSwap(std::size_t qubit_idx0, std::size_t qubit_idx1)
Swap the qubits at the given indices.
Definition: Simulator.hpp:304

◆ matrixSqrt()

Mat2x2Type QNLP::SimulatorGeneral< IntelSimulator >::matrixSqrt ( const Mat2x2Type &  U)
inlineinherited

Calculates the unitary matrix square root (U == VV, where V is returned)

Template Parameters
Mat2x2TypeMatrix type
Parameters
UUnitary matrix to be rooted
Returns
openqu::TinyMatrix<Type, 2, 2, 32> V such that VV == U

Definition at line 729 of file Simulator.hpp.

729  {
730  Mat2x2Type V(U);
731  std::complex<double> delta = U(0,0)*U(1,1) - U(0,1)*U(1,0);
732  std::complex<double> tau = U(0,0) + U(1,1);
733  std::complex<double> s = sqrt(delta);
734  std::complex<double> t = sqrt(tau + 2.0*s);
735 
736  //must be a way to vectorise these; TinyMatrix have a scale/shift option?
737  V(0,0) += s;
738  V(1,1) += s;
739  std::complex<double> scale_factor(1.,0.);
740  scale_factor/=t;
741  V(0,0) *= scale_factor; //(std::complex<double>(1.,0.)/t);
742  V(0,1) *= scale_factor; //(1/t);
743  V(1,0) *= scale_factor; //(1/t);
744  V(1,1) *= scale_factor; //(1/t);
745 
746  return V;
747  }

◆ overlap()

complex<double> QNLP::IntelSimulator::overlap ( IntelSimulator sim)
inline

Compute overlap between different simulators. Number of qubits must be the same.

Definition at line 723 of file IntelSimulator.cpp.

723  {
724  if(sim.uid != this->uid){
725  return qubitRegister.ComputeOverlap(sim.qubitRegister);
726  }
727  else{
728  return std::numeric_limits<double>::quiet_NaN();
729  }
730  }

References qubitRegister, and ncu_opt_tester::sim.

◆ PrintStates()

void QNLP::IntelSimulator::PrintStates ( std::string  x,
std::vector< std::size_t >  qubits = {} 
)
inline

Prints the string x and then for each state of the specified qubits in the superposition, prints each its amplitude, followed by state and then by the probability of that state. Note that this state observation method is not a permitted quantum operation, however it is provided for convenience and debugging/testing.

Parameters
xString to be printed to stdout
qubitsIndices of qubits in register to be printed

Definition at line 690 of file IntelSimulator.cpp.

690  {}){
691  qubitRegister.Print(x,qubits);
692  }

◆ subReg()

void QNLP::SimulatorGeneral< IntelSimulator >::subReg ( std::size_t  r0_minIdx,
std::size_t  r0_maxIdx,
std::size_t  r1_minIdx,
std::size_t  r1_maxIdx 
)
inlineinherited

Applies |r1>|r2> -> |r1>|r1-r2>

Definition at line 448 of file Simulator.hpp.

448  {
449  Arithmetic<decltype(static_cast<DerivedType&>(*this))>::sub_reg(static_cast<DerivedType&>(*this), r0_minIdx, r0_maxIdx, r1_minIdx, r1_maxIdx);
450  }

◆ sumReg()

void QNLP::SimulatorGeneral< IntelSimulator >::sumReg ( std::size_t  r0_minIdx,
std::size_t  r0_maxIdx,
std::size_t  r1_minIdx,
std::size_t  r1_maxIdx 
)
inlineinherited

Applies |r1>|r2> -> |r1>|r1+r2>

Definition at line 441 of file Simulator.hpp.

441  {
442  Arithmetic<decltype(static_cast<DerivedType&>(*this))>::sum_reg(static_cast<DerivedType&>(*this), r0_minIdx, r0_maxIdx, r1_minIdx, r1_maxIdx);
443  }

Field Documentation

◆ dist

std::uniform_real_distribution<double> QNLP::IntelSimulator::dist
private

Definition at line 748 of file IntelSimulator.cpp.

Referenced by applyMeasurement(), and IntelSimulator().

◆ gate_count_1qubit

◆ gate_count_2qubit

◆ gates

std::vector<TMDP> QNLP::IntelSimulator::gates
private

◆ mt

std::mt19937 QNLP::IntelSimulator::mt
private

Definition at line 747 of file IntelSimulator.cpp.

Referenced by applyMeasurement(), and IntelSimulator().

◆ numQubits

std::size_t QNLP::IntelSimulator::numQubits
private

Definition at line 736 of file IntelSimulator.cpp.

Referenced by getNumQubits().

◆ qubitRegister

◆ rd

std::random_device QNLP::IntelSimulator::rd
private

Definition at line 746 of file IntelSimulator.cpp.

Referenced by IntelSimulator().

◆ sim_ncu

std::any QNLP::SimulatorGeneral< IntelSimulator >::sim_ncu
protectedinherited

Definition at line 104 of file Simulator.hpp.

◆ uid

const std::size_t QNLP::IntelSimulator::uid
private

Definition at line 734 of file IntelSimulator.cpp.


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