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

Functions for overwriting the elements of matrices. More...

Functions

void setCompMatr (CompMatr matr, qcomp **vals)
 
void setCompMatr (CompMatr out, std::vector< std::vector< qcomp > > in)
 
void setDiagMatr (DiagMatr out, qcomp *in)
 
void setDiagMatr (DiagMatr out, std::vector< qcomp > in)
 
void setDiagMatrFromMultiDimLists (DiagMatr out, void *lists, int *numQubitsPerDim, int numDims)
 
void setDiagMatrFromMultiVarFunc (DiagMatr out, qcomp(*func)(qindex *), int *numQubitsPerVar, int numVars, int areSigned)
 
void setFullStateDiagMatr (FullStateDiagMatr out, qindex startInd, qcomp *in, qindex numElems)
 
void setFullStateDiagMatr (FullStateDiagMatr out, qindex startInd, std::vector< qcomp > in)
 
void setFullStateDiagMatrFromMultiDimLists (FullStateDiagMatr out, void *lists, int *numQubitsPerDim, int numDims)
 
void setFullStateDiagMatrFromMultiVarFunc (FullStateDiagMatr out, qcomp(*func)(qindex *), int *numQubitsPerVar, int numVars, int areSigned)
 
void setFullStateDiagMatrFromPauliStrSum (FullStateDiagMatr out, PauliStrSum in)
 
void setInlineCompMatr (CompMatr matr, int numQb, std::vector< std::vector< qcomp > > in)
 
void setInlineDiagMatr (DiagMatr matr, int numQb, std::vector< qcomp > in)
 
void setInlineFullStateDiagMatr (FullStateDiagMatr matr, qindex startInd, qindex numElems, std::vector< qcomp > in)
 

Detailed Description

Functions for overwriting the elements of matrices.

Function Documentation

◆ setCompMatr() [1/2]

void setCompMatr ( CompMatr matr,
qcomp ** vals )
Note
Documentation for this function or struct is under construction!

Definition at line 427 of file matrices.cpp.

427 {
428 validate_matrixFields(out, __func__);
429 validate_matrixNewElemsPtrNotNull(in, out.numRows, __func__);
430
431 setAndSyncDenseMatrElems(out, in);
432}

Referenced by TEST_CASE(), and TEST_CASE().

◆ setCompMatr() [2/2]

void setCompMatr ( CompMatr out,
std::vector< std::vector< qcomp > > in )
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

◆ setDiagMatr() [1/2]

void setDiagMatr ( DiagMatr out,
qcomp * in )
Note
Documentation for this function or struct is under construction!

Definition at line 435 of file matrices.cpp.

435 {
436 validate_matrixFields(out, __func__);
437 validate_matrixNewElemsPtrNotNull(in, __func__);
438
439 // overwrite CPU memory
440 cpu_copyArray(out.cpuElems, in, out.numElems);
441
442 // overwrite GPU elements; validation gauranteed to pass
443 syncDiagMatr(out);
444}
void syncDiagMatr(DiagMatr matr)
Definition matrices.cpp:378

◆ setDiagMatr() [2/2]

void setDiagMatr ( DiagMatr out,
std::vector< qcomp > in )
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

◆ setDiagMatrFromMultiDimLists()

void setDiagMatrFromMultiDimLists ( DiagMatr out,
void * lists,
int * numQubitsPerDim,
int numDims )
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!

Definition at line 708 of file matrices.cpp.

708 {
709 validate_matrixFields(out, __func__);
710 validate_multiVarFuncQubits(out.numQubits, numQubitsPerDim, numDims, __func__);
711
712 vector<qindex> listInds(numDims);
713
714 // set each element of the diagonal in-turn, which is embarrassingly parallel,
715 // although we do not parallelise - the DiagMatr is intendedly small
716 for (qindex elemInd=0; elemInd<out.numElems; elemInd++) {
717
718 // nested list indices = unsigned integer values of variables
719 fast_getSubQuregValues(elemInd, numQubitsPerDim, numDims, false, listInds.data());
720
721 // update only the CPU elems
722 out.cpuElems[elemInd] = util_getElemFromNestedPtrs(lists, listInds.data(), numDims);
723 }
724
725 // overwrite all GPU elems
726 syncDiagMatr(out);
727}

◆ setDiagMatrFromMultiVarFunc()

void setDiagMatrFromMultiVarFunc ( DiagMatr out,
qcomp(* func )(qindex *),
int * numQubitsPerVar,
int numVars,
int areSigned )
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!

Definition at line 674 of file matrices.cpp.

674 {
675 validate_matrixFields(out, __func__);
676 validate_multiVarFuncQubits(out.numQubits, numQubitsPerVar, numVars, __func__);
677 validate_funcVarSignedFlag(areSigned, __func__);
678
679 vector<qindex> varValues(numVars);
680
681 // set each element of the diagonal in-turn; user's callback might not be thread-safe
682 for (qindex elemInd=0; elemInd<out.numElems; elemInd++) {
683 fast_getSubQuregValues(elemInd, numQubitsPerVar, numVars, areSigned, varValues.data());
684
685 // call user function, and update only the CPU elems
686 out.cpuElems[elemInd] = callbackFunc(varValues.data());
687 }
688
689 // overwrite all GPU elems
690 syncDiagMatr(out);
691}

◆ setFullStateDiagMatr() [1/2]

void setFullStateDiagMatr ( FullStateDiagMatr out,
qindex startInd,
qcomp * in,
qindex numElems )
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!

Definition at line 447 of file matrices.cpp.

447 {
448 validate_matrixFields(out, __func__);
449 validate_fullStateDiagMatrNewElems(out, startInd, numElems, __func__);
450 validate_matrixNewElemsPtrNotNull(in, __func__);
451
452 // overwrites both the CPU and GPU memory (if it exists), maintaining consistency.
453 // note that cpu_copyArray() isn't called directly here like setDiagMatr() above
454 // because we must handle when 'out' is and isn't distributed
455 localiser_fullstatediagmatr_setElems(out, startInd, in, numElems);
456
457 // even though we have not necessarily overwritten every element, we must mark
458 // the matrix as synced so that it can be subsequently used without error
459 markMatrixAsSynced(out);
460}

◆ setFullStateDiagMatr() [2/2]

void setFullStateDiagMatr ( FullStateDiagMatr out,
qindex startInd,
std::vector< qcomp > in )
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Remarks
This function is only available in C++.

◆ setFullStateDiagMatrFromMultiDimLists()

void setFullStateDiagMatrFromMultiDimLists ( FullStateDiagMatr out,
void * lists,
int * numQubitsPerDim,
int numDims )
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!

Definition at line 730 of file matrices.cpp.

730 {
731 validate_matrixFields(out, __func__);
732 validate_multiVarFuncQubits(out.numQubits, numQubitsPerDim, numDims, __func__);
733
734 // possibly use multithreading, but never GPU acceleration, due to the
735 // arbitrarily nested nature of the input lists
736 cpu_fullstatediagmatr_setElemsFromMultiDimLists(out, lists, numQubitsPerDim, numDims);
737
738 // overwrite all GPU elems
740}
void syncFullStateDiagMatr(FullStateDiagMatr matr)
Definition matrices.cpp:379

◆ setFullStateDiagMatrFromMultiVarFunc()

void setFullStateDiagMatrFromMultiVarFunc ( FullStateDiagMatr out,
qcomp(* func )(qindex *),
int * numQubitsPerVar,
int numVars,
int areSigned )
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!

Definition at line 694 of file matrices.cpp.

694 {
695 validate_matrixFields(out, __func__);
696 validate_multiVarFuncQubits(out.numQubits, numQubitsPerVar, numVars, __func__);
697 validate_funcVarSignedFlag(areSigned, __func__);
698
699 // we assume callbackFunc is thread-safe (!!!!) and possibly use multithreading, but never
700 // GPU acceleration, since we cannot invoke user callback functions from GPU kernels
701 cpu_fullstatediagmatr_setElemsFromMultiVarFunc(out, callbackFunc, numQubitsPerVar, numVars, areSigned);
702
703 // overwrite all GPU elems
705}

◆ setFullStateDiagMatrFromPauliStrSum()

void setFullStateDiagMatrFromPauliStrSum ( FullStateDiagMatr out,
PauliStrSum in )
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!

Definition at line 641 of file matrices.cpp.

641 {
642 validate_matrixFields(out, __func__);
643 validate_pauliStrSumFields(in, __func__);
644 validate_pauliStrSumCanInitMatrix(out, in, __func__);
645
646 // permit 'in' to be non-Hermitian since it does not determine 'out' unitarity
647
648 // unlike other FullStateDiagMatr initialisers, we employ an accelerated
649 // backend since the input data 'in' is expectedly significantly smaller
650 // than the created data in 'out', making parallelisation worthwhile as
651 // the memory-movement costs of copying 'in' to a GPU are small
652 localiser_fullstatediagmatr_setElemsToPauliStrSum(out, in);
653
654 markMatrixAsSynced(out);
655}

◆ setInlineCompMatr()

void setInlineCompMatr ( CompMatr matr,
int numQb,
std::vector< std::vector< qcomp > > in )
Note
Documentation for this function or struct is under construction!

Referenced by TEST_CASE().

◆ setInlineDiagMatr()

void setInlineDiagMatr ( DiagMatr matr,
int numQb,
std::vector< qcomp > in )
Note
Documentation for this function or struct is under construction!

Referenced by TEST_CASE().

◆ setInlineFullStateDiagMatr()

void setInlineFullStateDiagMatr ( FullStateDiagMatr matr,
qindex startInd,
qindex numElems,
std::vector< qcomp > in )
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!