QuEST_validation.h File Reference
#include "QuEST.h"
#include <stdio.h>

Go to the source code of this file.

Functions

void validateAmpIndex (Qureg qureg, long long int ampInd, const char *caller)
 
void validateBitEncoding (int numQubits, enum bitEncoding encoding, const char *caller)
 
void validateControlState (int *controlState, int numControlQubits, const char *caller)
 
void validateControlTarget (Qureg qureg, int controlQubit, int targetQubit, const char *caller)
 
void validateDensityMatrQureg (Qureg qureg, const char *caller)
 
void validateDiagonalOp (Qureg qureg, DiagonalOp op, const char *caller)
 
void validateDiagOpInit (DiagonalOp, const char *caller)
 
void validateDiagPauliHamil (DiagonalOp op, PauliHamil hamil, const char *caller)
 
void validateDiagPauliHamilFromFile (PauliHamil h, int numRanks, const char *caller)
 
void validateFileOpened (int opened, char *fn, const char *caller)
 
void validateHamilFileCoeffParsed (int parsed, PauliHamil h, FILE *file, char *fn, const char *caller)
 
void validateHamilFileParams (int numQubits, int numTerms, FILE *file, char *fn, const char *caller)
 
void validateHamilFilePauliCode (enum pauliOpType code, PauliHamil h, FILE *file, char *fn, const char *caller)
 
void validateHamilFilePauliParsed (int parsed, PauliHamil h, FILE *file, char *fn, const char *caller)
 
void validateHamilParams (int numQubits, int numTerms, const char *caller)
 
void validateMatchingQuregDims (Qureg qureg1, Qureg qureg2, const char *caller)
 
void validateMatchingQuregPauliHamilDims (Qureg qureg, PauliHamil hamil, const char *caller)
 
void validateMatchingQuregTypes (Qureg qureg1, Qureg qureg2, const char *caller)
 
void validateMatrixInit (ComplexMatrixN matr, const char *caller)
 
void validateMeasurementProb (qreal prob, const char *caller)
 
void validateMultiControls (Qureg qureg, int *controlQubits, int numControlQubits, const char *caller)
 
void validateMultiControlsMultiTargets (Qureg qureg, int *controlQubits, int numControlQubits, int *targetQubits, int numTargetQubits, const char *caller)
 
void validateMultiControlsTarget (Qureg qureg, int *controlQubits, int numControlQubits, int targetQubit, const char *caller)
 
void validateMultiQubitKrausMap (Qureg qureg, int numTargs, ComplexMatrixN *ops, int numOps, const char *caller)
 
void validateMultiQubitMatrix (Qureg qureg, ComplexMatrixN u, int numTargs, const char *caller)
 
void validateMultiQubitMatrixFitsInNode (Qureg qureg, int numTargets, const char *caller)
 
void validateMultiQubits (Qureg qureg, int *qubits, int numQubits, const char *caller)
 
void validateMultiQubitUnitaryMatrix (Qureg qureg, ComplexMatrixN u, int numTargs, const char *caller)
 
void validateMultiRegBitEncoding (int *numQubitsPerReg, int numRegs, enum bitEncoding encoding, const char *caller)
 
void validateMultiTargets (Qureg qurge, int *targetQubits, int numTargetQubits, const char *caller)
 
void validateMultiVarPhaseFuncOverrides (int *numQubitsPerReg, const int numRegs, enum bitEncoding encoding, long long int *overrideInds, int numOverrides, const char *caller)
 
void validateMultiVarPhaseFuncTerms (int *numQubitsPerReg, int numRegs, enum bitEncoding encoding, qreal *exponents, int *numTermsPerReg, const char *caller)
 
void validateNormProbs (qreal prob1, qreal prob2, const char *caller)
 
void validateNumAmps (Qureg qureg, long long int startInd, long long int numAmps, const char *caller)
 
void validateNumElems (DiagonalOp op, long long int startInd, long long int numElems, const char *caller)
 
void validateNumPauliSumTerms (int numTerms, const char *caller)
 
void validateNumQubitsInDiagOp (int numQubits, int numRanks, const char *caller)
 
void validateNumQubitsInMatrix (int numQubits, const char *caller)
 
void validateNumQubitsInQureg (int numQubits, int numRanks, const char *caller)
 
void validateNumRanks (int numRanks, const char *caller)
 
void validateOneQubitDampingProb (qreal prob, const char *caller)
 
void validateOneQubitDephaseProb (qreal prob, const char *caller)
 
void validateOneQubitDepolProb (qreal prob, const char *caller)
 
void validateOneQubitKrausMap (Qureg qureg, ComplexMatrix2 *ops, int numOps, const char *caller)
 
void validateOneQubitPauliProbs (qreal probX, qreal probY, qreal probZ, const char *caller)
 
void validateOneQubitUnitaryMatrix (ComplexMatrix2 u, const char *caller)
 
void validateOutcome (int outcome, const char *caller)
 
void validatePauliCodes (enum pauliOpType *pauliCodes, int numPauliCodes, const char *caller)
 
void validatePauliHamil (PauliHamil hamil, const char *caller)
 
void validatePhaseFuncName (enum phaseFunc funcCode, int numRegs, int numParams, const char *caller)
 
void validatePhaseFuncOverrides (const int numQubits, enum bitEncoding encoding, long long int *overrideInds, int numOverrides, const char *caller)
 
void validatePhaseFuncTerms (int numQubits, enum bitEncoding encoding, qreal *coeffs, qreal *exponents, int numTerms, long long int *overrideInds, int numOverrides, const char *caller)
 
void validateProb (qreal prob, const char *caller)
 
void validateQubitSubregs (Qureg qureg, int *qubits, int *numQubitsPerReg, const int numReg, const char *caller)
 
void validateSecondQuregStateVec (Qureg qureg2, const char *caller)
 
void validateStateIndex (Qureg qureg, long long int stateInd, const char *caller)
 
void validateStateVecQureg (Qureg qureg, const char *caller)
 
void validateTarget (Qureg qureg, int targetQubit, const char *caller)
 
void validateTrotterParams (int order, int reps, const char *caller)
 
void validateTwoQubitDephaseProb (qreal prob, const char *caller)
 
void validateTwoQubitDepolProb (qreal prob, const char *caller)
 
void validateTwoQubitKrausMap (Qureg qureg, ComplexMatrix4 *ops, int numOps, const char *caller)
 
void validateTwoQubitUnitaryMatrix (Qureg qureg, ComplexMatrix4 u, const char *caller)
 
void validateUniqueTargets (Qureg qureg, int qubit1, int qubit2, const char *caller)
 
void validateUnitaryComplexPair (Complex alpha, Complex beta, const char *caller)
 
void validateVector (Vector vector, const char *caller)
 

Detailed Description

Provides validation defined in QuEST_validation.c which is used exclusively by QuEST.c

Author
Tyson Jones
Ania Brown (original testing of qubit indices, unitarity, valid collapse probability)
Balint Koczor (Kraus maps)

Definition in file QuEST_validation.h.

Function Documentation

◆ validateAmpIndex()

void validateAmpIndex ( Qureg  qureg,
long long int  ampInd,
const char *  caller 
)

Definition at line 382 of file QuEST_validation.c.

382  {
383  long long int indMax = 1LL << qureg.numQubitsRepresented;
384  QuESTAssert(ampInd>=0 && ampInd<indMax, E_INVALID_AMP_INDEX, caller);
385 }

References E_INVALID_AMP_INDEX, Qureg::numQubitsRepresented, and QuESTAssert().

Referenced by getAmp(), getDensityAmp(), getImagAmp(), getProbAmp(), getRealAmp(), and validateNumAmps().

◆ validateBitEncoding()

void validateBitEncoding ( int  numQubits,
enum bitEncoding  encoding,
const char *  caller 
)

Definition at line 966 of file QuEST_validation.c.

966  {
967  QuESTAssert(
968  encoding == UNSIGNED ||
969  encoding == TWOS_COMPLEMENT,
970  E_INVALID_BIT_ENCODING, caller);
971 
972  if (encoding == TWOS_COMPLEMENT)
973  QuESTAssert(numQubits > 1, E_INVALID_NUM_QUBITS_TWOS_COMPLEMENT, caller);
974 }

References E_INVALID_BIT_ENCODING, E_INVALID_NUM_QUBITS_TWOS_COMPLEMENT, QuESTAssert(), TWOS_COMPLEMENT, and UNSIGNED.

Referenced by applyPhaseFunc(), and applyPhaseFuncOverrides().

◆ validateControlState()

void validateControlState ( int *  controlState,
int  numControlQubits,
const char *  caller 
)

Definition at line 468 of file QuEST_validation.c.

468  {
469  for (int i=0; i < numControlQubits; i++)
470  QuESTAssert(controlState[i] == 0 || controlState[i] == 1, E_INVALID_CONTROLS_BIT_STATE, caller);
471 }

References E_INVALID_CONTROLS_BIT_STATE, and QuESTAssert().

Referenced by multiStateControlledUnitary().

◆ validateControlTarget()

void validateControlTarget ( Qureg  qureg,
int  controlQubit,
int  targetQubit,
const char *  caller 
)

◆ validateDensityMatrQureg()

◆ validateDiagonalOp()

void validateDiagonalOp ( Qureg  qureg,
DiagonalOp  op,
const char *  caller 
)

◆ validateDiagOpInit()

void validateDiagOpInit ( DiagonalOp  ,
const char *  caller 
)

◆ validateDiagPauliHamil()

void validateDiagPauliHamil ( DiagonalOp  op,
PauliHamil  hamil,
const char *  caller 
)

◆ validateDiagPauliHamilFromFile()

void validateDiagPauliHamilFromFile ( PauliHamil  h,
int  numRanks,
const char *  caller 
)

Definition at line 727 of file QuEST_validation.c.

727  {
728  // hamil itself already validated as general Pauli Hamiltonian
729 
730  // destroy hamil before raising exceptions if validation fails
731  int isValid;
732 
733  // mustn't be more elements than can fit in the type
734  unsigned int maxQubits = calcLog2(SIZE_MAX);
735  isValid = hamil.numQubits <= maxQubits;
736  if (!isValid)
737  destroyPauliHamil(hamil);
738  QuESTAssert(isValid, E_NUM_AMPS_EXCEED_TYPE, caller);
739 
740  // must be at least one amplitude per node
741  long unsigned int numElems = (1UL<<hamil.numQubits);
742  isValid = numElems >= numRanks;
743  if (!isValid)
744  destroyPauliHamil(hamil);
745  QuESTAssert(isValid, E_DISTRIB_DIAG_OP_TOO_SMALL, caller);
746 
747  // must contain only I and Z
748  for (int p=0; p<hamil.numSumTerms*hamil.numQubits; p++) {
749  isValid = hamil.pauliCodes[p] == PAULI_I || hamil.pauliCodes[p] == PAULI_Z;
750  if (!isValid)
751  destroyPauliHamil(hamil);
752 
753  QuESTAssert(isValid, E_PAULI_HAMIL_NOT_DIAGONAL, caller);
754  }
755 }

References calcLog2(), destroyPauliHamil(), E_DISTRIB_DIAG_OP_TOO_SMALL, E_NUM_AMPS_EXCEED_TYPE, E_PAULI_HAMIL_NOT_DIAGONAL, PauliHamil::numQubits, PauliHamil::numSumTerms, PAULI_I, PAULI_Z, PauliHamil::pauliCodes, and QuESTAssert().

Referenced by createDiagonalOpFromPauliHamilFile().

◆ validateFileOpened()

void validateFileOpened ( int  opened,
char *  fn,
const char *  caller 
)

Definition at line 543 of file QuEST_validation.c.

543  {
544  if (!opened) {
545 
548  }
549 }

References E_CANNOT_OPEN_FILE, errMsgBuffer, errorMessages, and invalidQuESTInputError().

Referenced by createPauliHamilFromFile(), initStateFromSingleFile(), and writeRecordedQASMToFile().

◆ validateHamilFileCoeffParsed()

void validateHamilFileCoeffParsed ( int  parsed,
PauliHamil  h,
FILE *  file,
char *  fn,
const char *  caller 
)

Definition at line 673 of file QuEST_validation.c.

673  {
674  if (!parsed) {
676  fclose(file);
677 
680  }
681 }

References destroyPauliHamil(), E_CANNOT_PARSE_PAULI_HAMIL_FILE_COEFF, errMsgBuffer, errorMessages, and invalidQuESTInputError().

Referenced by createPauliHamilFromFile().

◆ validateHamilFileParams()

void validateHamilFileParams ( int  numQubits,
int  numTerms,
FILE *  file,
char *  fn,
const char *  caller 
)

Definition at line 664 of file QuEST_validation.c.

664  {
665  if (!(numQubits > 0 && numTerms > 0)) {
666  fclose(file);
667 
670  }
671 }

References E_INVALID_PAULI_HAMIL_FILE_PARAMS, errMsgBuffer, errorMessages, and invalidQuESTInputError().

Referenced by createPauliHamilFromFile().

◆ validateHamilFilePauliCode()

void validateHamilFilePauliCode ( enum pauliOpType  code,
PauliHamil  h,
FILE *  file,
char *  fn,
const char *  caller 
)

Definition at line 693 of file QuEST_validation.c.

693  {
694  if (!isValidPauliCode(code)) {
696  fclose(file);
697 
700  }
701 }

References destroyPauliHamil(), E_INVALID_PAULI_HAMIL_FILE_PAULI_CODE, errMsgBuffer, errorMessages, invalidQuESTInputError(), and isValidPauliCode().

Referenced by createPauliHamilFromFile().

◆ validateHamilFilePauliParsed()

void validateHamilFilePauliParsed ( int  parsed,
PauliHamil  h,
FILE *  file,
char *  fn,
const char *  caller 
)

Definition at line 683 of file QuEST_validation.c.

683  {
684  if (!parsed) {
686  fclose(file);
687 
690  }
691 }

References destroyPauliHamil(), E_CANNOT_PARSE_PAULI_HAMIL_FILE_PAULI, errMsgBuffer, errorMessages, and invalidQuESTInputError().

Referenced by createPauliHamilFromFile().

◆ validateHamilParams()

void validateHamilParams ( int  numQubits,
int  numTerms,
const char *  caller 
)

Definition at line 651 of file QuEST_validation.c.

651  {
652  QuESTAssert(numQubits > 0 && numTerms > 0, E_INVALID_PAULI_HAMIL_PARAMS, caller);
653 }

References E_INVALID_PAULI_HAMIL_PARAMS, and QuESTAssert().

Referenced by createPauliHamil(), initDiagonalOpFromPauliHamil(), initPauliHamil(), and validatePauliHamil().

◆ validateMatchingQuregDims()

◆ validateMatchingQuregPauliHamilDims()

void validateMatchingQuregPauliHamilDims ( Qureg  qureg,
PauliHamil  hamil,
const char *  caller 
)

◆ validateMatchingQuregTypes()

void validateMatchingQuregTypes ( Qureg  qureg1,
Qureg  qureg2,
const char *  caller 
)

◆ validateMatrixInit()

void validateMatrixInit ( ComplexMatrixN  matr,
const char *  caller 
)

Definition at line 486 of file QuEST_validation.c.

486  {
487 
488  /* note that for (most) compilers which don't automatically initialise
489  * pointers to NULL, this can only be used to check the mallocs in createComplexMatrixN
490  * succeeded. It can not be used to differentiate whether a user actually attempted
491  * to initialise or create their ComplexMatrixN instance.
492  */
493  QuESTAssert(matr.real != NULL && matr.imag != NULL, E_COMPLEX_MATRIX_NOT_INIT, caller);
494 }

References E_COMPLEX_MATRIX_NOT_INIT, ComplexMatrixN::imag, QuESTAssert(), and ComplexMatrixN::real.

Referenced by createComplexMatrixN(), destroyComplexMatrixN(), initComplexMatrixN(), validateMultiQubitKrausMap(), and validateMultiQubitMatrix().

◆ validateMeasurementProb()

void validateMeasurementProb ( qreal  prob,
const char *  caller 
)

Definition at line 527 of file QuEST_validation.c.

527  {
528  QuESTAssert(prob>REAL_EPS, E_COLLAPSE_STATE_ZERO_PROB, caller);
529 }

References E_COLLAPSE_STATE_ZERO_PROB, and QuESTAssert().

Referenced by collapseToOutcome().

◆ validateMultiControls()

void validateMultiControls ( Qureg  qureg,
int *  controlQubits,
int  numControlQubits,
const char *  caller 
)

Definition at line 436 of file QuEST_validation.c.

436  {
437  validateNumControls(qureg, numControlQubits, caller);
438  for (int i=0; i < numControlQubits; i++)
439  validateControl(qureg, controlQubits[i], caller);
440 
441  QuESTAssert(areUniqueQubits(controlQubits, numControlQubits), E_CONTROLS_NOT_UNIQUE, caller);
442 }

References areUniqueQubits(), E_CONTROLS_NOT_UNIQUE, QuESTAssert(), validateControl(), and validateNumControls().

Referenced by validateMultiControlsMultiTargets(), and validateMultiControlsTarget().

◆ validateMultiControlsMultiTargets()

void validateMultiControlsMultiTargets ( Qureg  qureg,
int *  controlQubits,
int  numControlQubits,
int *  targetQubits,
int  numTargetQubits,
const char *  caller 
)

Definition at line 459 of file QuEST_validation.c.

459  {
460  validateMultiControls(qureg, controlQubits, numControlQubits, caller);
461  validateMultiTargets(qureg, targetQubits, numTargetQubits, caller);
462  long long int ctrlMask = getQubitBitMask(controlQubits, numControlQubits);
463  long long int targMask = getQubitBitMask(targetQubits, numTargetQubits);
464  int overlap = ctrlMask & targMask;
465  QuESTAssert(!overlap, E_CONTROL_TARGET_COLLISION, caller);
466 }

References E_CONTROL_TARGET_COLLISION, getQubitBitMask(), QuESTAssert(), validateMultiControls(), and validateMultiTargets().

Referenced by applyMultiControlledMatrixN(), controlledMultiQubitUnitary(), controlledTwoQubitUnitary(), multiControlledMultiQubitNot(), multiControlledMultiQubitUnitary(), multiControlledMultiRotatePauli(), multiControlledMultiRotateZ(), and multiControlledTwoQubitUnitary().

◆ validateMultiControlsTarget()

void validateMultiControlsTarget ( Qureg  qureg,
int *  controlQubits,
int  numControlQubits,
int  targetQubit,
const char *  caller 
)

Definition at line 452 of file QuEST_validation.c.

452  {
453  validateTarget(qureg, targetQubit, caller);
454  validateMultiControls(qureg, controlQubits, numControlQubits, caller);
455  for (int i=0; i < numControlQubits; i++)
456  QuESTAssert(controlQubits[i] != targetQubit, E_TARGET_IN_CONTROLS, caller);
457 }

References E_TARGET_IN_CONTROLS, QuESTAssert(), validateMultiControls(), and validateTarget().

Referenced by multiControlledUnitary(), and multiStateControlledUnitary().

◆ validateMultiQubitKrausMap()

void validateMultiQubitKrausMap ( Qureg  qureg,
int  numTargs,
ComplexMatrixN ops,
int  numOps,
const char *  caller 
)

Definition at line 634 of file QuEST_validation.c.

634  {
635  int opNumQubits = numTargs;
636  int superOpNumQubits = 2*opNumQubits;
637  int maxNumOps = superOpNumQubits*superOpNumQubits;
638  QuESTAssert(numOps>0 && numOps <= maxNumOps, E_INVALID_NUM_N_QUBIT_KRAUS_OPS, caller);
639 
640  for (int n=0; n<numOps; n++) {
641  validateMatrixInit(ops[n], __func__);
642  QuESTAssert(ops[n].numQubits == numTargs, E_MISMATCHING_NUM_TARGS_KRAUS_SIZE, caller);
643  }
644 
645  validateMultiQubitMatrixFitsInNode(qureg, superOpNumQubits, caller);
646 
647  int isPos = isCompletelyPositiveMapN(ops, numOps);
648  QuESTAssert(isPos, E_INVALID_KRAUS_OPS, caller);
649 }

References E_INVALID_KRAUS_OPS, E_INVALID_NUM_N_QUBIT_KRAUS_OPS, E_MISMATCHING_NUM_TARGS_KRAUS_SIZE, isCompletelyPositiveMapN(), QuESTAssert(), validateMatrixInit(), and validateMultiQubitMatrixFitsInNode().

Referenced by mixMultiQubitKrausMap().

◆ validateMultiQubitMatrix()

void validateMultiQubitMatrix ( Qureg  qureg,
ComplexMatrixN  u,
int  numTargs,
const char *  caller 
)

◆ validateMultiQubitMatrixFitsInNode()

void validateMultiQubitMatrixFitsInNode ( Qureg  qureg,
int  numTargets,
const char *  caller 
)

◆ validateMultiQubits()

void validateMultiQubits ( Qureg  qureg,
int *  qubits,
int  numQubits,
const char *  caller 
)

Definition at line 444 of file QuEST_validation.c.

444  {
445  QuESTAssert(numQubits>0 && numQubits<=qureg.numQubitsRepresented, E_INVALID_NUM_QUBITS, caller);
446  for (int i=0; i < numQubits; i++)
447  QuESTAssert(qubits[i]>=0 && qubits[i]<qureg.numQubitsRepresented, E_INVALID_QUBIT_INDEX, caller);
448 
449  QuESTAssert(areUniqueQubits(qubits, numQubits), E_QUBITS_NOT_UNIQUE, caller);
450 }

References areUniqueQubits(), E_INVALID_NUM_QUBITS, E_INVALID_QUBIT_INDEX, E_QUBITS_NOT_UNIQUE, Qureg::numQubitsRepresented, and QuESTAssert().

Referenced by applyPhaseFunc(), applyPhaseFuncOverrides(), multiControlledPhaseFlip(), and multiControlledPhaseShift().

◆ validateMultiQubitUnitaryMatrix()

void validateMultiQubitUnitaryMatrix ( Qureg  qureg,
ComplexMatrixN  u,
int  numTargs,
const char *  caller 
)

◆ validateMultiRegBitEncoding()

void validateMultiRegBitEncoding ( int *  numQubitsPerReg,
int  numRegs,
enum bitEncoding  encoding,
const char *  caller 
)

Definition at line 976 of file QuEST_validation.c.

976  {
977  QuESTAssert(
978  encoding == UNSIGNED ||
979  encoding == TWOS_COMPLEMENT,
980  E_INVALID_BIT_ENCODING, caller);
981 
982  if (encoding == TWOS_COMPLEMENT)
983  for (int r=0; r<numRegs; r++)
984  QuESTAssert(numQubitsPerReg[r] > 1, E_INVALID_NUM_QUBITS_TWOS_COMPLEMENT, caller);
985 }

References E_INVALID_BIT_ENCODING, E_INVALID_NUM_QUBITS_TWOS_COMPLEMENT, QuESTAssert(), TWOS_COMPLEMENT, and UNSIGNED.

Referenced by applyMultiVarPhaseFunc(), applyMultiVarPhaseFuncOverrides(), applyNamedPhaseFunc(), applyNamedPhaseFuncOverrides(), applyParamNamedPhaseFunc(), and applyParamNamedPhaseFuncOverrides().

◆ validateMultiTargets()

void validateMultiTargets ( Qureg  qurge,
int *  targetQubits,
int  numTargetQubits,
const char *  caller 
)

Definition at line 428 of file QuEST_validation.c.

428  {
429  validateNumTargets(qureg, numTargetQubits, caller);
430  for (int i=0; i < numTargetQubits; i++)
431  validateTarget(qureg, targetQubits[i], caller);
432 
433  QuESTAssert(areUniqueQubits(targetQubits, numTargetQubits), E_TARGETS_NOT_UNIQUE, caller);
434 }

References areUniqueQubits(), E_TARGETS_NOT_UNIQUE, QuESTAssert(), validateNumTargets(), and validateTarget().

Referenced by applyMatrix4(), applyMatrixN(), applyQFT(), calcExpecPauliProd(), calcProbOfAllOutcomes(), mixMultiQubitKrausMap(), mixTwoQubitKrausMap(), multiQubitNot(), multiQubitUnitary(), multiRotatePauli(), multiRotateZ(), twoQubitUnitary(), and validateMultiControlsMultiTargets().

◆ validateMultiVarPhaseFuncOverrides()

void validateMultiVarPhaseFuncOverrides ( int *  numQubitsPerReg,
const int  numRegs,
enum bitEncoding  encoding,
long long int *  overrideInds,
int  numOverrides,
const char *  caller 
)

Definition at line 886 of file QuEST_validation.c.

886  {
887  QuESTAssert(numOverrides>=0, E_INVALID_NUM_PHASE_FUNC_OVERRIDES, caller);
888 
889  if (encoding == UNSIGNED) {
890  int i=0;
891  for (int v=0; v<numOverrides; v++) {
892  for (int r=0; r<numRegs; r++) {
893  long long int maxInd = (1LL << numQubitsPerReg[r]) - 1;
894  QuESTAssert(overrideInds[i]>=0 && overrideInds[i]<=maxInd, E_INVALID_PHASE_FUNC_OVERRIDE_UNSIGNED_INDEX, caller);
895  i++;
896  }
897  }
898  }
899  else if (encoding == TWOS_COMPLEMENT) {
900  int i=0;
901  for (int v=0; v<numOverrides; v++) {
902  for (int r=0; r<numRegs; r++) {
903  int numValQubits = numQubitsPerReg[r] - 1; // removing sign bit
904  long long int minInd = - (1LL << numValQubits);
905  long long int maxInd = (1LL << numValQubits) - 1;
906  QuESTAssert(overrideInds[i]>=minInd && overrideInds[i]<=maxInd, E_INVALID_PHASE_FUNC_OVERRIDE_TWOS_COMPLEMENT_INDEX, caller);
907  i++;
908  }
909  }
910  }
911 }

References E_INVALID_NUM_PHASE_FUNC_OVERRIDES, E_INVALID_PHASE_FUNC_OVERRIDE_TWOS_COMPLEMENT_INDEX, E_INVALID_PHASE_FUNC_OVERRIDE_UNSIGNED_INDEX, QuESTAssert(), TWOS_COMPLEMENT, and UNSIGNED.

Referenced by applyMultiVarPhaseFuncOverrides(), applyNamedPhaseFuncOverrides(), and applyParamNamedPhaseFuncOverrides().

◆ validateMultiVarPhaseFuncTerms()

void validateMultiVarPhaseFuncTerms ( int *  numQubitsPerReg,
int  numRegs,
enum bitEncoding  encoding,
qreal exponents,
int *  numTermsPerReg,
const char *  caller 
)

Definition at line 836 of file QuEST_validation.c.

836  {
838  for (int r=0; r<numRegs; r++)
839  QuESTAssert(numTermsPerReg[r]>0, E_INVALID_NUM_PHASE_FUNC_TERMS, caller);
840 
841  int numTotalTerms = 0;
842  for (int r=0; r<numRegs; r++)
843  numTotalTerms += numTermsPerReg[r];
844 
845  int hasFractionExpo = 0;
846  int hasNegativeExpo = 0;
847  for (int t=0; t<numTotalTerms; t++) {
848  // this is only true if exponent is precisely an integer, else pow() will NaN
849  if (floor(exponents[t]) != exponents[t])
850  hasFractionExpo = 1;
851  if (exponents[t] < 0)
852  hasNegativeExpo = 1;
853  }
854 
855  QuESTAssert(!hasNegativeExpo, E_NEGATIVE_EXPONENT_MULTI_VAR, caller);
856 
857  if (encoding == TWOS_COMPLEMENT)
858  QuESTAssert(!hasFractionExpo, E_FRACTIONAL_EXPONENT_MULTI_VAR, caller);
859 }

References E_FRACTIONAL_EXPONENT_MULTI_VAR, E_INVALID_NUM_PHASE_FUNC_TERMS, E_INVALID_NUM_SUBREGISTERS, E_NEGATIVE_EXPONENT_MULTI_VAR, MAX_NUM_REGS_APPLY_ARBITRARY_PHASE, QuESTAssert(), and TWOS_COMPLEMENT.

Referenced by applyMultiVarPhaseFunc(), and applyMultiVarPhaseFuncOverrides().

◆ validateNormProbs()

void validateNormProbs ( qreal  prob1,
qreal  prob2,
const char *  caller 
)

Definition at line 555 of file QuEST_validation.c.

555  {
556  validateProb(prob1, caller);
557  validateProb(prob2, caller);
558 
559  qreal sum = prob1 + prob2;
560  QuESTAssert(absReal(1 - sum) < REAL_EPS, E_UNNORM_PROBS, caller);
561 }

References E_UNNORM_PROBS, qreal, QuESTAssert(), and validateProb().

◆ validateNumAmps()

void validateNumAmps ( Qureg  qureg,
long long int  startInd,
long long int  numAmps,
const char *  caller 
)

Definition at line 387 of file QuEST_validation.c.

387  {
388  validateAmpIndex(qureg, startInd, caller);
389  QuESTAssert(numAmps >= 0 && numAmps <= qureg.numAmpsTotal, E_INVALID_NUM_AMPS, caller);
390  QuESTAssert(numAmps + startInd <= qureg.numAmpsTotal, E_INVALID_OFFSET_NUM_AMPS_QUREG, caller);
391 }

References E_INVALID_NUM_AMPS, E_INVALID_OFFSET_NUM_AMPS_QUREG, Qureg::numAmpsTotal, QuESTAssert(), and validateAmpIndex().

Referenced by setAmps().

◆ validateNumElems()

void validateNumElems ( DiagonalOp  op,
long long int  startInd,
long long int  numElems,
const char *  caller 
)

Definition at line 393 of file QuEST_validation.c.

393  {
394  long long int indMax = 1LL << op.numQubits;
395  QuESTAssert(startInd >= 0 && startInd < indMax, E_INVALID_ELEM_INDEX, caller);
396  QuESTAssert(numElems >= 0 && numElems <= indMax, E_INVALID_NUM_ELEMS, caller);
397  QuESTAssert(numElems + startInd <= indMax, E_INVALID_OFFSET_NUM_ELEMS_DIAG, caller);
398 }

References E_INVALID_ELEM_INDEX, E_INVALID_NUM_ELEMS, E_INVALID_OFFSET_NUM_ELEMS_DIAG, DiagonalOp::numQubits, and QuESTAssert().

Referenced by setDiagonalOpElems().

◆ validateNumPauliSumTerms()

void validateNumPauliSumTerms ( int  numTerms,
const char *  caller 
)

Definition at line 606 of file QuEST_validation.c.

606  {
607  QuESTAssert(numTerms > 0, E_INVALID_NUM_SUM_TERMS, caller);
608 }

References E_INVALID_NUM_SUM_TERMS, and QuESTAssert().

Referenced by applyPauliSum(), and calcExpecPauliSum().

◆ validateNumQubitsInDiagOp()

void validateNumQubitsInDiagOp ( int  numQubits,
int  numRanks,
const char *  caller 
)

Definition at line 365 of file QuEST_validation.c.

365  {
366  QuESTAssert(numQubits>0, E_INVALID_NUM_CREATE_QUBITS, caller);
367 
368  // mustn't be more amplitudes than can fit in the type
369  unsigned int maxQubits = calcLog2(SIZE_MAX);
370  QuESTAssert( numQubits <= maxQubits, E_NUM_AMPS_EXCEED_TYPE, caller);
371 
372  // must be at least one amplitude per node
373  long unsigned int numAmps = (1UL<<numQubits);
374  QuESTAssert(numAmps >= numRanks, E_DISTRIB_DIAG_OP_TOO_SMALL, caller);
375 }

References calcLog2(), E_DISTRIB_DIAG_OP_TOO_SMALL, E_INVALID_NUM_CREATE_QUBITS, E_NUM_AMPS_EXCEED_TYPE, and QuESTAssert().

Referenced by createDiagonalOp().

◆ validateNumQubitsInMatrix()

void validateNumQubitsInMatrix ( int  numQubits,
const char *  caller 
)

Definition at line 361 of file QuEST_validation.c.

361  {
362  QuESTAssert(numQubits>0, E_INVALID_NUM_QUBITS, caller);
363 }

References E_INVALID_NUM_QUBITS, and QuESTAssert().

Referenced by createComplexMatrixN().

◆ validateNumQubitsInQureg()

void validateNumQubitsInQureg ( int  numQubits,
int  numRanks,
const char *  caller 
)

Definition at line 349 of file QuEST_validation.c.

349  {
350  QuESTAssert(numQubits>0, E_INVALID_NUM_CREATE_QUBITS, caller);
351 
352  // mustn't be more amplitudes than can fit in the type
353  unsigned int maxQubits = calcLog2(SIZE_MAX);
354  QuESTAssert( numQubits <= maxQubits, E_NUM_AMPS_EXCEED_TYPE, caller);
355 
356  // must be at least one amplitude per node
357  long unsigned int numAmps = (1UL<<numQubits);
358  QuESTAssert(numAmps >= numRanks, E_DISTRIB_QUREG_TOO_SMALL, caller);
359 }

References calcLog2(), E_DISTRIB_QUREG_TOO_SMALL, E_INVALID_NUM_CREATE_QUBITS, E_NUM_AMPS_EXCEED_TYPE, and QuESTAssert().

Referenced by createDensityQureg(), and createQureg().

◆ validateNumRanks()

void validateNumRanks ( int  numRanks,
const char *  caller 
)

Definition at line 335 of file QuEST_validation.c.

335  {
336 
337  /* silly but robust way to determine if numRanks is a power of 2,
338  * in lieu of bit-twiddling (e.g. AND with all-ones) which may be
339  * system / precsision dependent
340  */
341  int isValid = 0;
342  for (int exp2 = 1; exp2 <= numRanks; exp2 *= 2)
343  if (exp2 == numRanks)
344  isValid = 1;
345 
346  QuESTAssert(isValid, E_INVALID_NUM_RANKS, caller);
347 }

References E_INVALID_NUM_RANKS, and QuESTAssert().

Referenced by createQuESTEnv().

◆ validateOneQubitDampingProb()

void validateOneQubitDampingProb ( qreal  prob,
const char *  caller 
)

Definition at line 578 of file QuEST_validation.c.

578  {
579  validateProb(prob, caller);
580  QuESTAssert(prob <= 1.0, E_INVALID_ONE_QUBIT_DEPOL_PROB, caller);
581 }

References E_INVALID_ONE_QUBIT_DEPOL_PROB, QuESTAssert(), and validateProb().

Referenced by mixDamping().

◆ validateOneQubitDephaseProb()

void validateOneQubitDephaseProb ( qreal  prob,
const char *  caller 
)

Definition at line 563 of file QuEST_validation.c.

563  {
564  validateProb(prob, caller);
565  QuESTAssert(prob <= 1/2.0, E_INVALID_ONE_QUBIT_DEPHASE_PROB, caller);
566 }

References E_INVALID_ONE_QUBIT_DEPHASE_PROB, QuESTAssert(), and validateProb().

Referenced by mixDephasing().

◆ validateOneQubitDepolProb()

void validateOneQubitDepolProb ( qreal  prob,
const char *  caller 
)

Definition at line 573 of file QuEST_validation.c.

573  {
574  validateProb(prob, caller);
575  QuESTAssert(prob <= 3/4.0, E_INVALID_ONE_QUBIT_DEPOL_PROB, caller);
576 }

References E_INVALID_ONE_QUBIT_DEPOL_PROB, QuESTAssert(), and validateProb().

Referenced by mixDepolarising().

◆ validateOneQubitKrausMap()

void validateOneQubitKrausMap ( Qureg  qureg,
ComplexMatrix2 ops,
int  numOps,
const char *  caller 
)

Definition at line 610 of file QuEST_validation.c.

610  {
611  int opNumQubits = 1;
612  int superOpNumQubits = 2*opNumQubits;
613  int maxNumOps = superOpNumQubits*superOpNumQubits;
614  QuESTAssert(numOps > 0 && numOps <= maxNumOps, E_INVALID_NUM_ONE_QUBIT_KRAUS_OPS, caller);
615 
616  validateMultiQubitMatrixFitsInNode(qureg, superOpNumQubits, caller);
617 
618  int isPos = isCompletelyPositiveMap2(ops, numOps);
619  QuESTAssert(isPos, E_INVALID_KRAUS_OPS, caller);
620 }

References E_INVALID_KRAUS_OPS, E_INVALID_NUM_ONE_QUBIT_KRAUS_OPS, isCompletelyPositiveMap2(), QuESTAssert(), and validateMultiQubitMatrixFitsInNode().

Referenced by mixKrausMap().

◆ validateOneQubitPauliProbs()

void validateOneQubitPauliProbs ( qreal  probX,
qreal  probY,
qreal  probZ,
const char *  caller 
)

Definition at line 588 of file QuEST_validation.c.

588  {
589  validateProb(probX, caller);
590  validateProb(probY, caller);
591  validateProb(probZ, caller);
592 
593  qreal probNoError = 1 - probX - probY - probZ;
594  QuESTAssert(probX <= probNoError, E_INVALID_ONE_QUBIT_PAULI_PROBS, caller);
595  QuESTAssert(probY <= probNoError, E_INVALID_ONE_QUBIT_PAULI_PROBS, caller);
596  QuESTAssert(probZ <= probNoError, E_INVALID_ONE_QUBIT_PAULI_PROBS, caller);
597 }

References E_INVALID_ONE_QUBIT_PAULI_PROBS, qreal, QuESTAssert(), and validateProb().

Referenced by mixPauli().

◆ validateOneQubitUnitaryMatrix()

void validateOneQubitUnitaryMatrix ( ComplexMatrix2  u,
const char *  caller 
)

◆ validateOutcome()

void validateOutcome ( int  outcome,
const char *  caller 
)

Definition at line 523 of file QuEST_validation.c.

523  {
524  QuESTAssert(outcome==0 || outcome==1, E_INVALID_QUBIT_OUTCOME, caller);
525 }

References E_INVALID_QUBIT_OUTCOME, and QuESTAssert().

Referenced by applyProjector(), calcProbOfOutcome(), collapseToOutcome(), and initStateOfSingleQubit().

◆ validatePauliCodes()

void validatePauliCodes ( enum pauliOpType pauliCodes,
int  numPauliCodes,
const char *  caller 
)

Definition at line 599 of file QuEST_validation.c.

599  {
600  for (int i=0; i < numPauliCodes; i++) {
601  enum pauliOpType code = pauliCodes[i];
603  }
604 }

References E_INVALID_PAULI_CODE, isValidPauliCode(), and QuESTAssert().

Referenced by applyPauliSum(), calcExpecPauliProd(), calcExpecPauliSum(), initPauliHamil(), multiControlledMultiRotatePauli(), multiRotatePauli(), and validatePauliHamil().

◆ validatePauliHamil()

void validatePauliHamil ( PauliHamil  hamil,
const char *  caller 
)

◆ validatePhaseFuncName()

void validatePhaseFuncName ( enum phaseFunc  funcCode,
int  numRegs,
int  numParams,
const char *  caller 
)

Definition at line 913 of file QuEST_validation.c.

913  {
914 
915  QuESTAssert(
916  funcCode == NORM ||
917  funcCode == INVERSE_NORM ||
918  funcCode == SCALED_NORM ||
919  funcCode == SCALED_INVERSE_NORM ||
920  funcCode == SCALED_INVERSE_SHIFTED_NORM ||
921  funcCode == PRODUCT ||
922  funcCode == INVERSE_PRODUCT ||
923  funcCode == SCALED_PRODUCT ||
924  funcCode == SCALED_INVERSE_PRODUCT ||
925  funcCode == DISTANCE ||
926  funcCode == INVERSE_DISTANCE ||
927  funcCode == SCALED_DISTANCE ||
928  funcCode == SCALED_INVERSE_DISTANCE ||
930  E_INVALID_PHASE_FUNC_NAME, caller);
931 
932  if (funcCode == NORM ||
933  funcCode == PRODUCT ||
934  funcCode == DISTANCE)
935  QuESTAssert(numParams == 0, E_INVALID_NUM_NAMED_PHASE_FUNC_PARAMS, caller);
936 
937  if (funcCode == INVERSE_NORM ||
938  funcCode == INVERSE_PRODUCT ||
939  funcCode == INVERSE_DISTANCE)
940  QuESTAssert(numParams == 1, E_INVALID_NUM_NAMED_PHASE_FUNC_PARAMS, caller);
941 
942  if (funcCode == SCALED_NORM ||
943  funcCode == SCALED_PRODUCT ||
944  funcCode == SCALED_DISTANCE)
945  QuESTAssert(numParams == 1, E_INVALID_NUM_NAMED_PHASE_FUNC_PARAMS, caller);
946 
947  if (funcCode == SCALED_INVERSE_NORM ||
948  funcCode == SCALED_INVERSE_PRODUCT ||
949  funcCode == SCALED_INVERSE_DISTANCE)
950  QuESTAssert(numParams == 2, E_INVALID_NUM_NAMED_PHASE_FUNC_PARAMS, caller);
951 
952  if (funcCode == SCALED_INVERSE_SHIFTED_NORM)
953  QuESTAssert(numParams == 2 + numRegs, E_INVALID_NUM_NAMED_PHASE_FUNC_PARAMS, caller);
954 
955  if (funcCode == SCALED_INVERSE_SHIFTED_DISTANCE)
956  QuESTAssert(numParams == 2 + numRegs / 2, E_INVALID_NUM_NAMED_PHASE_FUNC_PARAMS, caller);
957 
958  if (funcCode == DISTANCE ||
959  funcCode == INVERSE_DISTANCE ||
960  funcCode == SCALED_DISTANCE ||
961  funcCode == SCALED_INVERSE_DISTANCE ||
963  QuESTAssert(numRegs%2 == 0, E_INVALID_NUM_REGS_DISTANCE_PHASE_FUNC, caller);
964 }

References DISTANCE, E_INVALID_NUM_NAMED_PHASE_FUNC_PARAMS, E_INVALID_NUM_REGS_DISTANCE_PHASE_FUNC, E_INVALID_PHASE_FUNC_NAME, INVERSE_DISTANCE, INVERSE_NORM, INVERSE_PRODUCT, NORM, PRODUCT, QuESTAssert(), SCALED_DISTANCE, SCALED_INVERSE_DISTANCE, SCALED_INVERSE_NORM, SCALED_INVERSE_PRODUCT, SCALED_INVERSE_SHIFTED_DISTANCE, SCALED_INVERSE_SHIFTED_NORM, SCALED_NORM, and SCALED_PRODUCT.

Referenced by applyNamedPhaseFunc(), applyNamedPhaseFuncOverrides(), applyParamNamedPhaseFunc(), and applyParamNamedPhaseFuncOverrides().

◆ validatePhaseFuncOverrides()

void validatePhaseFuncOverrides ( const int  numQubits,
enum bitEncoding  encoding,
long long int *  overrideInds,
int  numOverrides,
const char *  caller 
)

Definition at line 862 of file QuEST_validation.c.

862  {
863  QuESTAssert(numOverrides>=0, E_INVALID_NUM_PHASE_FUNC_OVERRIDES, caller);
864  QuESTAssert(numOverrides<=(1<<numQubits), E_INVALID_NUM_PHASE_FUNC_OVERRIDES, caller);
865 
866  long long int maxInd;
867  long long int minInd;
868 
869  if (encoding == UNSIGNED) {
870  minInd = 0;
871  maxInd = (1LL << numQubits) - 1;
872  for (int v=0; v<numOverrides; v++)
873  QuESTAssert(overrideInds[v]>=minInd && overrideInds[v]<=maxInd, E_INVALID_PHASE_FUNC_OVERRIDE_UNSIGNED_INDEX, caller);
874  }
875 
876  if (encoding == TWOS_COMPLEMENT) {
877  int numValQubits = numQubits - 1; // removing sign bit
878  minInd = - (1LL << numValQubits);
879  maxInd = (1LL << numValQubits) - 1;
880  for (int v=0; v<numOverrides; v++)
881  QuESTAssert(overrideInds[v]>=minInd && overrideInds[v]<=maxInd, E_INVALID_PHASE_FUNC_OVERRIDE_TWOS_COMPLEMENT_INDEX, caller);
882  }
883 
884 }

References E_INVALID_NUM_PHASE_FUNC_OVERRIDES, E_INVALID_PHASE_FUNC_OVERRIDE_TWOS_COMPLEMENT_INDEX, E_INVALID_PHASE_FUNC_OVERRIDE_UNSIGNED_INDEX, QuESTAssert(), TWOS_COMPLEMENT, and UNSIGNED.

Referenced by applyPhaseFuncOverrides().

◆ validatePhaseFuncTerms()

void validatePhaseFuncTerms ( int  numQubits,
enum bitEncoding  encoding,
qreal coeffs,
qreal exponents,
int  numTerms,
long long int *  overrideInds,
int  numOverrides,
const char *  caller 
)

Definition at line 773 of file QuEST_validation.c.

773  {
774  QuESTAssert(numTerms>0, E_INVALID_NUM_PHASE_FUNC_TERMS, caller);
775 
776  int hasFractionExpo = 0;
777  int hasNegativeExpo = 0;
778  for (int t=0; t<numTerms; t++) {
779  // this is only true if exponent is precisely an integer, else pow() will NaN
780  if (floor(exponents[t]) != exponents[t])
781  hasFractionExpo = 1;
782  if (exponents[t] < 0)
783  hasNegativeExpo = 1;
784  }
785 
786  // ensure negative exponents are supplied along with a zero-index override
787  if (hasNegativeExpo) {
788  int hasZeroOverride = 0;
789  for (int v=0; v<numOverrides; v++) {
790  if (overrideInds[v] == 0LL) {
791  hasZeroOverride = 1;
792  break;
793  }
794  }
795  QuESTAssert(hasZeroOverride, E_NEGATIVE_EXPONENT_WITHOUT_ZERO_OVERRIDE, caller);
796  }
797 
798  // ensure fractional powers not used with negative numbers, unless overriden
799  if (hasFractionExpo && encoding == TWOS_COMPLEMENT) {
800  long long int numNegInds = (1LL << (numQubits-1));
801 
802  // immediately disqualify if insufficient overrides are given to cover every negative number
803  QuESTAssert(numOverrides >= numNegInds, E_FRACTIONAL_EXPONENT_WITHOUT_NEG_OVERRIDE, caller);
804 
805  int allNegsOverriden;
806 
807  // if there are 16 or fewer qubits (0.5mB cache), use a stack array to tick off overrides
808  if (numQubits < 16) {
809 
810  // flags for {-1,-2,...}; at index {abs(-1)-1, abs(-2)-2, ...}
811  long long int negIsOverriden[32768]; // [numNegInds];
812  for (int i=0; i<numNegInds; i++)
813  negIsOverriden[i] = 0;
814 
815  for (int v=0; v<numOverrides; v++)
816  if (overrideInds[v] < 0)
817  negIsOverriden[ -1 - overrideInds[v] ] = 1;
818 
819  allNegsOverriden = 1;
820  for (int i=0; i<numNegInds; i++) {
821  if (!negIsOverriden[i]) {
822  allNegsOverriden = 0;
823  break;
824  }
825  }
826  }
827  // otherwise, we must trust the user, else impose significant slowdowns on good users
828  else {
829  allNegsOverriden = 1;
830  }
831 
832  QuESTAssert(allNegsOverriden, E_FRACTIONAL_EXPONENT_WITHOUT_NEG_OVERRIDE, caller);
833  }
834 }

References E_FRACTIONAL_EXPONENT_WITHOUT_NEG_OVERRIDE, E_INVALID_NUM_PHASE_FUNC_TERMS, E_NEGATIVE_EXPONENT_WITHOUT_ZERO_OVERRIDE, QuESTAssert(), and TWOS_COMPLEMENT.

Referenced by applyPhaseFunc(), and applyPhaseFuncOverrides().

◆ validateProb()

void validateProb ( qreal  prob,
const char *  caller 
)

◆ validateQubitSubregs()

void validateQubitSubregs ( Qureg  qureg,
int *  qubits,
int *  numQubitsPerReg,
const int  numReg,
const char *  caller 
)

Definition at line 757 of file QuEST_validation.c.

757  {
759 
760  int i=0;
761  for (int r=0; r<numRegs; r++) {
762  QuESTAssert(numQubitsPerReg[r]>0 && numQubitsPerReg[r]<=qureg.numQubitsRepresented, E_INVALID_NUM_QUBITS, caller);
763 
764  for (int q=0; q < numQubitsPerReg[r]; q++) {
765  QuESTAssert(qubits[i]>=0 && qubits[i]<qureg.numQubitsRepresented, E_INVALID_QUBIT_INDEX, caller);
766  i++;
767  }
768  }
769 
770  QuESTAssert(areUniqueQubits(qubits, i), E_QUBITS_NOT_UNIQUE, caller);
771 }

References areUniqueQubits(), E_INVALID_NUM_QUBITS, E_INVALID_NUM_SUBREGISTERS, E_INVALID_QUBIT_INDEX, E_QUBITS_NOT_UNIQUE, MAX_NUM_REGS_APPLY_ARBITRARY_PHASE, Qureg::numQubitsRepresented, and QuESTAssert().

Referenced by applyMultiVarPhaseFunc(), applyMultiVarPhaseFuncOverrides(), applyNamedPhaseFunc(), applyNamedPhaseFuncOverrides(), applyParamNamedPhaseFunc(), and applyParamNamedPhaseFuncOverrides().

◆ validateSecondQuregStateVec()

void validateSecondQuregStateVec ( Qureg  qureg2,
const char *  caller 
)

Definition at line 539 of file QuEST_validation.c.

539  {
541 }

References E_SECOND_ARG_MUST_BE_STATEVEC, Qureg::isDensityMatrix, and QuESTAssert().

Referenced by calcFidelity(), and initPureState().

◆ validateStateIndex()

void validateStateIndex ( Qureg  qureg,
long long int  stateInd,
const char *  caller 
)

Definition at line 377 of file QuEST_validation.c.

377  {
378  long long int stateMax = 1LL << qureg.numQubitsRepresented;
379  QuESTAssert(stateInd>=0 && stateInd<stateMax, E_INVALID_STATE_INDEX, caller);
380 }

References E_INVALID_STATE_INDEX, Qureg::numQubitsRepresented, and QuESTAssert().

Referenced by initClassicalState().

◆ validateStateVecQureg()

void validateStateVecQureg ( Qureg  qureg,
const char *  caller 
)

◆ validateTarget()

◆ validateTrotterParams()

void validateTrotterParams ( int  order,
int  reps,
const char *  caller 
)

Definition at line 703 of file QuEST_validation.c.

703  {
704  int isEven = (order % 2) == 0;
705  QuESTAssert(order > 0 && (isEven || order==1), E_INVALID_TROTTER_ORDER, caller);
706  QuESTAssert(reps > 0, E_INVALID_TROTTER_REPS, caller);
707 }

References E_INVALID_TROTTER_ORDER, E_INVALID_TROTTER_REPS, and QuESTAssert().

Referenced by applyTrotterCircuit().

◆ validateTwoQubitDephaseProb()

void validateTwoQubitDephaseProb ( qreal  prob,
const char *  caller 
)

Definition at line 568 of file QuEST_validation.c.

568  {
569  validateProb(prob, caller);
570  QuESTAssert(prob <= 3/4.0, E_INVALID_TWO_QUBIT_DEPHASE_PROB, caller);
571 }

References E_INVALID_TWO_QUBIT_DEPHASE_PROB, QuESTAssert(), and validateProb().

Referenced by mixTwoQubitDephasing().

◆ validateTwoQubitDepolProb()

void validateTwoQubitDepolProb ( qreal  prob,
const char *  caller 
)

Definition at line 583 of file QuEST_validation.c.

583  {
584  validateProb(prob, caller);
585  QuESTAssert(prob <= 15/16.0, E_INVALID_TWO_QUBIT_DEPOL_PROB, caller);
586 }

References E_INVALID_TWO_QUBIT_DEPOL_PROB, QuESTAssert(), and validateProb().

Referenced by mixTwoQubitDepolarising().

◆ validateTwoQubitKrausMap()

void validateTwoQubitKrausMap ( Qureg  qureg,
ComplexMatrix4 ops,
int  numOps,
const char *  caller 
)

Definition at line 622 of file QuEST_validation.c.

622  {
623  int opNumQubits = 2;
624  int superOpNumQubits = 2*opNumQubits;
625  int maxNumOps = superOpNumQubits*superOpNumQubits;
626  QuESTAssert(numOps > 0 && numOps <= maxNumOps, E_INVALID_NUM_TWO_QUBIT_KRAUS_OPS, caller);
627 
628  validateMultiQubitMatrixFitsInNode(qureg, superOpNumQubits, caller);
629 
630  int isPos = isCompletelyPositiveMap4(ops, numOps);
631  QuESTAssert(isPos, E_INVALID_KRAUS_OPS, caller);
632 }

References E_INVALID_KRAUS_OPS, E_INVALID_NUM_TWO_QUBIT_KRAUS_OPS, isCompletelyPositiveMap4(), QuESTAssert(), and validateMultiQubitMatrixFitsInNode().

Referenced by mixTwoQubitKrausMap().

◆ validateTwoQubitUnitaryMatrix()

void validateTwoQubitUnitaryMatrix ( Qureg  qureg,
ComplexMatrix4  u,
const char *  caller 
)

◆ validateUniqueTargets()

void validateUniqueTargets ( Qureg  qureg,
int  qubit1,
int  qubit2,
const char *  caller 
)

Definition at line 414 of file QuEST_validation.c.

414  {
415  validateTarget(qureg, qubit1, caller);
416  validateTarget(qureg, qubit2, caller);
417  QuESTAssert(qubit1 != qubit2, E_TARGETS_NOT_UNIQUE, caller);
418 }

References E_TARGETS_NOT_UNIQUE, QuESTAssert(), and validateTarget().

Referenced by mixTwoQubitDephasing(), mixTwoQubitDepolarising(), sqrtSwapGate(), and swapGate().

◆ validateUnitaryComplexPair()

void validateUnitaryComplexPair ( Complex  alpha,
Complex  beta,
const char *  caller 
)

Definition at line 507 of file QuEST_validation.c.

507  {
509 }

References E_NON_UNITARY_COMPLEX_PAIR, isComplexPairUnitary(), and QuESTAssert().

Referenced by compactUnitary(), and controlledCompactUnitary().

◆ validateVector()

void validateVector ( Vector  vector,
const char *  caller 
)

Definition at line 511 of file QuEST_validation.c.

511  {
512  QuESTAssert(getVectorMagnitude(vec) > REAL_EPS, E_ZERO_VECTOR, caller);
513 }

References E_ZERO_VECTOR, getVectorMagnitude(), and QuESTAssert().

Referenced by controlledRotateAroundAxis(), and rotateAroundAxis().

@ INVERSE_PRODUCT
Definition: QuEST.h:233
pauliOpType
Codes for specifying Pauli operators.
Definition: QuEST.h:96
@ E_INVALID_TWO_QUBIT_DEPOL_PROB
@ E_NUM_AMPS_EXCEED_TYPE
void validateTarget(Qureg qureg, int targetQubit, const char *caller)
@ E_MISMATCHING_PAULI_HAMIL_DIAGONAL_OP_SIZE
@ E_INVALID_QUBIT_OUTCOME
@ E_CANNOT_PARSE_PAULI_HAMIL_FILE_COEFF
int isMatrix2Unitary(ComplexMatrix2 u)
@ E_PAULI_HAMIL_NOT_DIAGONAL
@ PAULI_Z
Definition: QuEST.h:96
@ DISTANCE
Definition: QuEST.h:234
@ E_INVALID_NUM_PHASE_FUNC_TERMS
@ E_INVALID_PAULI_CODE
@ E_NON_UNITARY_MATRIX
void validateHamilParams(int numQubits, int numTerms, const char *caller)
@ PAULI_I
Definition: QuEST.h:96
@ E_INVALID_ONE_QUBIT_DEPHASE_PROB
void validateMultiQubitMatrixFitsInNode(Qureg qureg, int numTargets, const char *caller)
@ E_INVALID_NUM_REGS_DISTANCE_PHASE_FUNC
@ E_CANNOT_FIT_MULTI_QUBIT_MATRIX
@ E_INVALID_NUM_N_QUBIT_KRAUS_OPS
@ E_INVALID_ELEM_INDEX
int isMatrix4Unitary(ComplexMatrix4 u)
@ TWOS_COMPLEMENT
Definition: QuEST.h:269
@ E_MISMATCHING_QUREG_TYPES
void validateNumControls(Qureg qureg, int numControlQubits, const char *caller)
int isCompletelyPositiveMap4(ComplexMatrix4 *ops, int numOps)
@ E_CANNOT_PARSE_PAULI_HAMIL_FILE_PAULI
@ E_INVALID_QUBIT_INDEX
@ E_INVALID_PHASE_FUNC_NAME
void validateProb(qreal prob, const char *caller)
@ E_INVALID_BIT_ENCODING
@ NORM
Definition: QuEST.h:232
@ E_NON_UNITARY_COMPLEX_PAIR
@ SCALED_INVERSE_DISTANCE
Definition: QuEST.h:234
@ UNSIGNED
Definition: QuEST.h:269
@ E_INVALID_NUM_SUBREGISTERS
@ E_INVALID_CONTROLS_BIT_STATE
@ E_INVALID_TROTTER_ORDER
@ E_INVALID_NUM_TWO_QUBIT_KRAUS_OPS
@ E_DISTRIB_DIAG_OP_TOO_SMALL
@ INVERSE_DISTANCE
Definition: QuEST.h:234
@ E_SECOND_ARG_MUST_BE_STATEVEC
@ E_INVALID_NUM_SUM_TERMS
@ E_DEFINED_ONLY_FOR_STATEVECS
#define qreal
void validateMatrixInit(ComplexMatrixN matr, const char *caller)
int isCompletelyPositiveMap2(ComplexMatrix2 *ops, int numOps)
@ E_INVALID_PAULI_HAMIL_FILE_PAULI_CODE
@ E_NEGATIVE_EXPONENT_MULTI_VAR
unsigned int calcLog2(long unsigned int num)
returns log2 of numbers which must be gauranteed to be 2^n
void validateControl(Qureg qureg, int controlQubit, const char *caller)
@ E_INVALID_PROB
void validateNumTargets(Qureg qureg, int numTargetQubits, const char *caller)
int isMatrixNUnitary(ComplexMatrixN u)
@ E_QUBITS_NOT_UNIQUE
@ E_INVALID_PHASE_FUNC_OVERRIDE_TWOS_COMPLEMENT_INDEX
@ E_CONTROL_TARGET_COLLISION
void invalidQuESTInputError(const char *errMsg, const char *errFunc)
An internal function called when invalid arguments are passed to a QuEST API call,...
@ E_DEFINED_ONLY_FOR_DENSMATRS
@ E_INVALID_KRAUS_OPS
@ E_INVALID_OFFSET_NUM_AMPS_QUREG
@ E_INVALID_STATE_INDEX
int areUniqueQubits(int *qubits, int numQubits)
@ E_TARGET_IN_CONTROLS
@ E_INVALID_NUM_QUBITS
long long int numAmpsPerChunk
Number of probability amplitudes held in stateVec by this process In the non-MPI version,...
Definition: QuEST.h:332
@ E_TARGET_IS_CONTROL
@ E_INVALID_PAULI_HAMIL_PARAMS
@ E_INVALID_UNITARY_SIZE
@ E_INVALID_ONE_QUBIT_PAULI_PROBS
enum pauliOpType * pauliCodes
The Pauli operators acting on each qubit, flattened over every operator.
Definition: QuEST.h:281
@ E_MISMATCHING_NUM_TARGS_KRAUS_SIZE
@ SCALED_PRODUCT
Definition: QuEST.h:233
void validateMultiTargets(Qureg qureg, int *targetQubits, int numTargetQubits, const char *caller)
int isValidPauliCode(enum pauliOpType code)
#define MAX_NUM_REGS_APPLY_ARBITRARY_PHASE
@ E_INVALID_TARGET_QUBIT
@ E_COMPLEX_MATRIX_NOT_INIT
@ E_CANNOT_OPEN_FILE
@ E_DISTRIB_QUREG_TOO_SMALL
int numQubits
The number of qubits this operator can act on (informing its size)
Definition: QuEST.h:300
@ E_INVALID_NUM_ONE_QUBIT_KRAUS_OPS
int numSumTerms
The number of terms in the weighted sum, or the number of Pauli products.
Definition: QuEST.h:285
long long int getQubitBitMask(int *qubits, int numQubits)
Definition: QuEST_common.c:50
@ E_MISMATCHING_QUREG_DIAGONAL_OP_SIZE
@ E_INVALID_AMP_INDEX
@ SCALED_INVERSE_SHIFTED_NORM
Definition: QuEST.h:232
qreal ** real
Definition: QuEST.h:189
@ E_INVALID_NUM_RANKS
@ E_INVALID_TWO_QUBIT_DEPHASE_PROB
@ E_MISMATCHING_PAULI_HAMIL_QUREG_NUM_QUBITS
static const char * errorMessages[]
void QuESTAssert(int isValid, ErrorCode code, const char *func)
@ E_INVALID_NUM_AMPS
@ E_COLLAPSE_STATE_ZERO_PROB
@ E_TARGETS_NOT_UNIQUE
@ INVERSE_NORM
Definition: QuEST.h:232
qreal ** imag
Definition: QuEST.h:190
@ E_MISMATCHING_QUREG_DIMENSIONS
@ E_INVALID_TROTTER_REPS
@ PRODUCT
Definition: QuEST.h:233
char errMsgBuffer[1024]
@ E_INVALID_NUM_CREATE_QUBITS
void validateDiagOpInit(DiagonalOp op, const char *caller)
@ E_INVALID_NUM_NAMED_PHASE_FUNC_PARAMS
int isDensityMatrix
Whether this instance is a density-state representation.
Definition: QuEST.h:325
int numQubits
Definition: QuEST.h:188
void validateAmpIndex(Qureg qureg, long long int ampInd, const char *caller)
@ E_INVALID_OFFSET_NUM_ELEMS_DIAG
qreal getVectorMagnitude(Vector vec)
Definition: QuEST_common.c:79
@ E_INVALID_PAULI_HAMIL_FILE_PARAMS
int numQubits
The number of qubits informing the Hilbert dimension of the Hamiltonian.
Definition: QuEST.h:287
@ E_UNNORM_PROBS
int numQubitsRepresented
The number of qubits represented in either the state-vector or density matrix.
Definition: QuEST.h:327
@ E_INVALID_NUM_PHASE_FUNC_OVERRIDES
@ E_INVALID_PHASE_FUNC_OVERRIDE_UNSIGNED_INDEX
long long int numAmpsTotal
Total number of amplitudes, which are possibly distributed among machines.
Definition: QuEST.h:334
@ SCALED_DISTANCE
Definition: QuEST.h:234
@ E_FRACTIONAL_EXPONENT_MULTI_VAR
@ E_INVALID_NUM_QUBITS_TWOS_COMPLEMENT
void destroyPauliHamil(PauliHamil h)
Destroy a PauliHamil instance, created with either createPauliHamil() or createPauliHamilFromFile().
Definition: QuEST.c:1414
int isCompletelyPositiveMapN(ComplexMatrixN *ops, int numOps)
void validateMultiControls(Qureg qureg, int *controlQubits, int numControlQubits, const char *caller)
@ E_INVALID_NUM_ELEMS
void validateMultiQubitMatrix(Qureg qureg, ComplexMatrixN u, int numTargs, const char *caller)
@ E_NEGATIVE_EXPONENT_WITHOUT_ZERO_OVERRIDE
@ SCALED_INVERSE_SHIFTED_DISTANCE
Definition: QuEST.h:234
@ SCALED_NORM
Definition: QuEST.h:232
@ SCALED_INVERSE_PRODUCT
Definition: QuEST.h:233
int isComplexPairUnitary(Complex alpha, Complex beta)
void validatePauliCodes(enum pauliOpType *pauliCodes, int numPauliCodes, const char *caller)
@ E_DIAGONAL_OP_NOT_INITIALISED
@ E_INVALID_ONE_QUBIT_DEPOL_PROB
@ E_ZERO_VECTOR
@ E_CONTROLS_NOT_UNIQUE
@ E_FRACTIONAL_EXPONENT_WITHOUT_NEG_OVERRIDE
@ SCALED_INVERSE_NORM
Definition: QuEST.h:232