The Quantum Exact Simulation Toolkit v4.0.0
Loading...
Searching...
No Matches
Constructors

Functions for creating and initialising Pauli data structures. More...

Functions

PauliStrSum createInlinePauliStrSum (const char *str)
 
PauliStrSum createInlinePauliStrSum (std::string str)
 
PauliStrSum createPauliStrSum (PauliStr *strings, qcomp *coeffs, qindex numTerms)
 
PauliStrSum createPauliStrSum (std::vector< PauliStr > strings, std::vector< qcomp > coeffs)
 
PauliStrSum createPauliStrSumFromFile (const char *fn)
 
PauliStrSum createPauliStrSumFromFile (std::string fn)
 
PauliStrSum createPauliStrSumFromReversedFile (const char *fn)
 
PauliStrSum createPauliStrSumFromReversedFile (std::string fn)
 
PauliStr getPauliStr (const char *paulis, int *indices, int numPaulis)
 
PauliStr getPauliStr (int *paulis, int *indices, int numPaulis)
 
PauliStr getPauliStr (std::string paulis)
 
PauliStr getPauliStr (std::string paulis, int *indices, int numPaulis)
 
PauliStr getPauliStr (std::string paulis, std::vector< int > indices)
 

Detailed Description

Functions for creating and initialising Pauli data structures.

Function Documentation

◆ createInlinePauliStrSum() [1/2]

PauliStrSum createInlinePauliStrSum ( const char * str)
Note
Documentation for this function or struct is under construction!

Definition at line 418 of file paulis.cpp.

418 {
419
420 // str must be null-terminated
421 return createInlinePauliStrSum(string(str));
422}
PauliStrSum createInlinePauliStrSum(const char *str)
Definition paulis.cpp:418

Referenced by createInlinePauliStrSum().

◆ createInlinePauliStrSum() [2/2]

PauliStrSum createInlinePauliStrSum ( std::string str)
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

◆ createPauliStrSum() [1/2]

PauliStrSum createPauliStrSum ( PauliStr * strings,
qcomp * coeffs,
qindex numTerms )
Note
Documentation for this function or struct is under construction!

Definition at line 385 of file paulis.cpp.

385 {
386
387 // note we do not require nor impose the strings to be unique
388 validate_newPauliStrSumParams(numTerms, __func__);
389
390 // create struct
391 PauliStrSum out = {
392 .numTerms = numTerms,
393 .strings = cpu_allocPauliStrings(numTerms), // nullptr if failed
394 .coeffs = cpu_allocArray(numTerms), // nullptr if failed
395 .isApproxHermitian = util_allocEpsilonSensitiveHeapFlag(), // nullptr if failed
396 };
397
398 // if either alloc failed, clear both before validation to avoid leak
399 freeAllMemoryIfAnyAllocsFailed(out);
400 validate_newPauliStrSumAllocs(out, numTerms*sizeof(PauliStr), numTerms*sizeof(qcomp), __func__);
401
402 // otherwise copy given data into new heap structure, and set initial flags
403 cpu_copyPauliStrSum(out, strings, coeffs);
404 util_setFlagToUnknown(out.isApproxHermitian);
405
406 return out;
407}

◆ createPauliStrSum() [2/2]

PauliStrSum createPauliStrSum ( std::vector< PauliStr > strings,
std::vector< qcomp > coeffs )
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

◆ createPauliStrSumFromFile() [1/2]

PauliStrSum createPauliStrSumFromFile ( const char * fn)
Note
Documentation for this function or struct is under construction!

Definition at line 431 of file paulis.cpp.

431 {
432
433 // fn must be null-terminated
434 return createPauliStrSumFromFile(string(fn));
435}
PauliStrSum createPauliStrSumFromFile(const char *fn)
Definition paulis.cpp:431

Referenced by createPauliStrSumFromFile().

◆ createPauliStrSumFromFile() [2/2]

PauliStrSum createPauliStrSumFromFile ( std::string fn)
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

◆ createPauliStrSumFromReversedFile() [1/2]

PauliStrSum createPauliStrSumFromReversedFile ( const char * fn)
Note
Documentation for this function or struct is under construction!

Definition at line 448 of file paulis.cpp.

448 {
449
450 // fn must be null-terminated
451 return createPauliStrSumFromReversedFile(string(fn));
452}
PauliStrSum createPauliStrSumFromReversedFile(const char *fn)
Definition paulis.cpp:448

Referenced by createPauliStrSumFromReversedFile(), and TEST_CASE().

◆ createPauliStrSumFromReversedFile() [2/2]

PauliStrSum createPauliStrSumFromReversedFile ( std::string fn)
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

◆ getPauliStr() [1/5]

PauliStr getPauliStr ( const char * paulis,
int * indices,
int numPaulis )
Note
Documentation for this function or struct is under construction!

Definition at line 296 of file paulis.cpp.

296 {
297 validate_newPauliStrParams(paulis, indices, numPaulis, MAX_NUM_PAULIS_PER_STR, __func__);
298
299 // begin masks at all-identity 'I' = 0
300 PAULI_MASK_TYPE lowPaulis = 0;
301 PAULI_MASK_TYPE highPaulis = 0;
302
303 // change targeted indices to the given Paulis
304 for (int i=0; i<numPaulis; i++) {
305
306 // cast single Pauli to full precision mask to enable below shifts
307 auto pauli = (PAULI_MASK_TYPE) parser_getPauliIntFromChar(paulis[i]);
308
309 // add the Pauli to either the lower or upper pauli masks
310 if (indices[i] < MAX_NUM_PAULIS_PER_MASK)
311 lowPaulis |= pauli << (2*indices[i]);
312 else
313 highPaulis |= pauli << (2*(indices[i] - MAX_NUM_PAULIS_PER_MASK));
314 }
315
316 // return a new stack PauliStr instance, returning by copy
317 return {
318 .lowPaulis = lowPaulis,
319 .highPaulis = highPaulis
320 };
321}

Referenced by applyMultiStateControlledMultiQubitNot(), applyMultiStateControlledPauliX(), applyMultiStateControlledPauliY(), applyMultiStateControlledRotateX(), applyMultiStateControlledRotateY(), applyMultiStateControlledRotateZ(), getPauliStr(), multiplyMultiQubitNot(), and TEST_CASE().

◆ getPauliStr() [2/5]

PauliStr getPauliStr ( int * paulis,
int * indices,
int numPaulis )
Note
Documentation for this function or struct is under construction!

Definition at line 324 of file paulis.cpp.

324 {
325 validate_newPauliStrParams(paulis, indices, numPaulis, MAX_NUM_PAULIS_PER_STR, __func__);
326
327 // validation ensures never causes stack overflow
328 char pauliChars[MAX_NUM_PAULIS_PER_STR + 1]; // +1 for null-terminal
329
330 // made a char array from the pauli codes
331 for (int i=0; i<numPaulis; i++)
332 pauliChars[i] = "IXYZ"[paulis[i]];
333
334 // including the trailing null char, used to infer string end/length
335 pauliChars[numPaulis] = '\0';
336
337 return getPauliStr(pauliChars, indices, numPaulis);
338}
PauliStr getPauliStr(const char *paulis, int *indices, int numPaulis)
Definition paulis.cpp:296

◆ getPauliStr() [3/5]

PauliStr getPauliStr ( std::string paulis)
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

◆ getPauliStr() [4/5]

PauliStr getPauliStr ( std::string paulis,
int * indices,
int numPaulis )
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

◆ getPauliStr() [5/5]

PauliStr getPauliStr ( std::string paulis,
std::vector< int > indices )
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.