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 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 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 validateMultiTargets (Qureg qurge, int *targetQubits, int numTargetQubits, 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 validateProb (qreal prob, 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 346 of file QuEST_validation.c.

346  {
347  long long int indMax = 1LL << qureg.numQubitsRepresented;
348  QuESTAssert(ampInd>=0 && ampInd<indMax, E_INVALID_AMP_INDEX, caller);
349 }

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

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

◆ validateControlState()

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

Definition at line 432 of file QuEST_validation.c.

432  {
433  for (int i=0; i < numControlQubits; i++)
434  QuESTAssert(controlState[i] == 0 || controlState[i] == 1, E_INVALID_CONTROLS_BIT_STATE, caller);
435 }

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 
)

Definition at line 673 of file QuEST_validation.c.

673  {
674  QuESTAssert(op.real != NULL && op.imag != NULL, E_DIAGONAL_OP_NOT_INITIALISED, caller);
675 }

References E_DIAGONAL_OP_NOT_INITIALISED, DiagonalOp::imag, QuESTAssert(), and DiagonalOp::real.

Referenced by destroyDiagonalOp(), initDiagonalOp(), setDiagonalOpElems(), syncDiagonalOp(), and validateDiagonalOp().

◆ validateFileOpened()

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

Definition at line 507 of file QuEST_validation.c.

507  {
508  if (!opened) {
509 
512  }
513 }

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 637 of file QuEST_validation.c.

637  {
638  if (!parsed) {
640  fclose(file);
641 
644  }
645 }

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 628 of file QuEST_validation.c.

628  {
629  if (!(numQubits > 0 && numTerms > 0)) {
630  fclose(file);
631 
634  }
635 }

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 657 of file QuEST_validation.c.

657  {
658  if (!isValidPauliCode(code)) {
660  fclose(file);
661 
664  }
665 }

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 647 of file QuEST_validation.c.

647  {
648  if (!parsed) {
650  fclose(file);
651 
654  }
655 }

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 615 of file QuEST_validation.c.

615  {
616  QuESTAssert(numQubits > 0 && numTerms > 0, E_INVALID_PAULI_HAMIL_PARAMS, caller);
617 }

References E_INVALID_PAULI_HAMIL_PARAMS, and QuESTAssert().

Referenced by createPauliHamil(), 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 450 of file QuEST_validation.c.

450  {
451 
452  /* note that for (most) compilers which don't automatically initialise
453  * pointers to NULL, this can only be used to check the mallocs in createComplexMatrixN
454  * succeeded. It can not be used to differentiate whether a user actually attempted
455  * to initialise or create their ComplexMatrixN instance.
456  */
457  QuESTAssert(matr.real != NULL && matr.imag != NULL, E_COMPLEX_MATRIX_NOT_INIT, caller);
458 }

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 491 of file QuEST_validation.c.

491  {
492  QuESTAssert(prob>REAL_EPS, E_COLLAPSE_STATE_ZERO_PROB, caller);
493 }

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 400 of file QuEST_validation.c.

400  {
401  validateNumControls(qureg, numControlQubits, caller);
402  for (int i=0; i < numControlQubits; i++)
403  validateControl(qureg, controlQubits[i], caller);
404 
405  QuESTAssert(areUniqueQubits(controlQubits, numControlQubits), E_CONTROLS_NOT_UNIQUE, caller);
406 }

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 423 of file QuEST_validation.c.

423  {
424  validateMultiControls(qureg, controlQubits, numControlQubits, caller);
425  validateMultiTargets(qureg, targetQubits, numTargetQubits, caller);
426  long long int ctrlMask = getQubitBitMask(controlQubits, numControlQubits);
427  long long int targMask = getQubitBitMask(targetQubits, numTargetQubits);
428  int overlap = ctrlMask & targMask;
429  QuESTAssert(!overlap, E_CONTROL_TARGET_COLLISION, caller);
430 }

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

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

◆ validateMultiControlsTarget()

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

Definition at line 416 of file QuEST_validation.c.

416  {
417  validateTarget(qureg, targetQubit, caller);
418  validateMultiControls(qureg, controlQubits, numControlQubits, caller);
419  for (int i=0; i < numControlQubits; i++)
420  QuESTAssert(controlQubits[i] != targetQubit, E_TARGET_IN_CONTROLS, caller);
421 }

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 598 of file QuEST_validation.c.

598  {
599  int opNumQubits = numTargs;
600  int superOpNumQubits = 2*opNumQubits;
601  int maxNumOps = superOpNumQubits*superOpNumQubits;
602  QuESTAssert(numOps>0 && numOps <= maxNumOps, E_INVALID_NUM_N_QUBIT_KRAUS_OPS, caller);
603 
604  for (int n=0; n<numOps; n++) {
605  validateMatrixInit(ops[n], __func__);
606  QuESTAssert(ops[n].numQubits == numTargs, E_MISMATCHING_NUM_TARGS_KRAUS_SIZE, caller);
607  }
608 
609  validateMultiQubitMatrixFitsInNode(qureg, superOpNumQubits, caller);
610 
611  int isPos = isCompletelyPositiveMapN(ops, numOps);
612  QuESTAssert(isPos, E_INVALID_KRAUS_OPS, caller);
613 }

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 408 of file QuEST_validation.c.

408  {
409  QuESTAssert(numQubits>0 && numQubits<=qureg.numQubitsRepresented, E_INVALID_NUM_QUBITS, caller);
410  for (int i=0; i < numQubits; i++)
411  QuESTAssert(qubits[i]>=0 && qubits[i]<qureg.numQubitsRepresented, E_INVALID_QUBIT_INDEX, caller);
412 
413  QuESTAssert(areUniqueQubits(qubits, numQubits), E_QUBITS_NOT_UNIQUE, caller);
414 }

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

Referenced by multiControlledPhaseFlip(), and multiControlledPhaseShift().

◆ validateMultiQubitUnitaryMatrix()

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

◆ validateMultiTargets()

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

Definition at line 392 of file QuEST_validation.c.

392  {
393  validateNumTargets(qureg, numTargetQubits, caller);
394  for (int i=0; i < numTargetQubits; i++)
395  validateTarget(qureg, targetQubits[i], caller);
396 
397  QuESTAssert(areUniqueQubits(targetQubits, numTargetQubits), E_TARGETS_NOT_UNIQUE, caller);
398 }

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

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

◆ validateNormProbs()

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

Definition at line 519 of file QuEST_validation.c.

519  {
520  validateProb(prob1, caller);
521  validateProb(prob2, caller);
522 
523  qreal sum = prob1 + prob2;
524  QuESTAssert(absReal(1 - sum) < REAL_EPS, E_UNNORM_PROBS, caller);
525 }

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 351 of file QuEST_validation.c.

351  {
352  validateAmpIndex(qureg, startInd, caller);
353  QuESTAssert(numAmps >= 0 && numAmps <= qureg.numAmpsTotal, E_INVALID_NUM_AMPS, caller);
354  QuESTAssert(numAmps + startInd <= qureg.numAmpsTotal, E_INVALID_OFFSET_NUM_AMPS_QUREG, caller);
355 }

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 357 of file QuEST_validation.c.

357  {
358  long long int indMax = 1LL << op.numQubits;
359  QuESTAssert(startInd >= 0 && startInd < indMax, E_INVALID_ELEM_INDEX, caller);
360  QuESTAssert(numElems >= 0 && numElems <= indMax, E_INVALID_NUM_ELEMS, caller);
361  QuESTAssert(numElems + startInd <= indMax, E_INVALID_OFFSET_NUM_ELEMS_DIAG, caller);
362 }

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 570 of file QuEST_validation.c.

570  {
571  QuESTAssert(numTerms > 0, E_INVALID_NUM_SUM_TERMS, caller);
572 }

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 329 of file QuEST_validation.c.

329  {
330  QuESTAssert(numQubits>0, E_INVALID_NUM_CREATE_QUBITS, caller);
331 
332  // mustn't be more amplitudes than can fit in the type
333  unsigned int maxQubits = calcLog2(SIZE_MAX);
334  QuESTAssert( numQubits <= maxQubits, E_NUM_AMPS_EXCEED_TYPE, caller);
335 
336  // must be at least one amplitude per node
337  long unsigned int numAmps = (1UL<<numQubits);
338  QuESTAssert(numAmps >= numRanks, E_DISTRIB_DIAG_OP_TOO_SMALL, caller);
339 }

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 325 of file QuEST_validation.c.

325  {
326  QuESTAssert(numQubits>0, E_INVALID_NUM_QUBITS, caller);
327 }

References E_INVALID_NUM_QUBITS, and QuESTAssert().

Referenced by createComplexMatrixN().

◆ validateNumQubitsInQureg()

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

Definition at line 313 of file QuEST_validation.c.

313  {
314  QuESTAssert(numQubits>0, E_INVALID_NUM_CREATE_QUBITS, caller);
315 
316  // mustn't be more amplitudes than can fit in the type
317  unsigned int maxQubits = calcLog2(SIZE_MAX);
318  QuESTAssert( numQubits <= maxQubits, E_NUM_AMPS_EXCEED_TYPE, caller);
319 
320  // must be at least one amplitude per node
321  long unsigned int numAmps = (1UL<<numQubits);
322  QuESTAssert(numAmps >= numRanks, E_DISTRIB_QUREG_TOO_SMALL, caller);
323 }

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 299 of file QuEST_validation.c.

299  {
300 
301  /* silly but robust way to determine if numRanks is a power of 2,
302  * in lieu of bit-twiddling (e.g. AND with all-ones) which may be
303  * system / precsision dependent
304  */
305  int isValid = 0;
306  for (int exp2 = 1; exp2 <= numRanks; exp2 *= 2)
307  if (exp2 == numRanks)
308  isValid = 1;
309 
310  QuESTAssert(isValid, E_INVALID_NUM_RANKS, caller);
311 }

References E_INVALID_NUM_RANKS, and QuESTAssert().

Referenced by createQuESTEnv().

◆ validateOneQubitDampingProb()

void validateOneQubitDampingProb ( qreal  prob,
const char *  caller 
)

Definition at line 542 of file QuEST_validation.c.

542  {
543  validateProb(prob, caller);
544  QuESTAssert(prob <= 1.0, E_INVALID_ONE_QUBIT_DEPOL_PROB, caller);
545 }

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

Referenced by mixDamping().

◆ validateOneQubitDephaseProb()

void validateOneQubitDephaseProb ( qreal  prob,
const char *  caller 
)

Definition at line 527 of file QuEST_validation.c.

527  {
528  validateProb(prob, caller);
529  QuESTAssert(prob <= 1/2.0, E_INVALID_ONE_QUBIT_DEPHASE_PROB, caller);
530 }

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

Referenced by mixDephasing().

◆ validateOneQubitDepolProb()

void validateOneQubitDepolProb ( qreal  prob,
const char *  caller 
)

Definition at line 537 of file QuEST_validation.c.

537  {
538  validateProb(prob, caller);
539  QuESTAssert(prob <= 3/4.0, E_INVALID_ONE_QUBIT_DEPOL_PROB, caller);
540 }

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 574 of file QuEST_validation.c.

574  {
575  int opNumQubits = 1;
576  int superOpNumQubits = 2*opNumQubits;
577  int maxNumOps = superOpNumQubits*superOpNumQubits;
578  QuESTAssert(numOps > 0 && numOps <= maxNumOps, E_INVALID_NUM_ONE_QUBIT_KRAUS_OPS, caller);
579 
580  validateMultiQubitMatrixFitsInNode(qureg, superOpNumQubits, caller);
581 
582  int isPos = isCompletelyPositiveMap2(ops, numOps);
583  QuESTAssert(isPos, E_INVALID_KRAUS_OPS, caller);
584 }

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 552 of file QuEST_validation.c.

552  {
553  validateProb(probX, caller);
554  validateProb(probY, caller);
555  validateProb(probZ, caller);
556 
557  qreal probNoError = 1 - probX - probY - probZ;
558  QuESTAssert(probX <= probNoError, E_INVALID_ONE_QUBIT_PAULI_PROBS, caller);
559  QuESTAssert(probY <= probNoError, E_INVALID_ONE_QUBIT_PAULI_PROBS, caller);
560  QuESTAssert(probZ <= probNoError, E_INVALID_ONE_QUBIT_PAULI_PROBS, caller);
561 }

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 487 of file QuEST_validation.c.

487  {
488  QuESTAssert(outcome==0 || outcome==1, E_INVALID_QUBIT_OUTCOME, caller);
489 }

References E_INVALID_QUBIT_OUTCOME, and QuESTAssert().

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

◆ validatePauliCodes()

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

Definition at line 563 of file QuEST_validation.c.

563  {
564  for (int i=0; i < numPauliCodes; i++) {
565  enum pauliOpType code = pauliCodes[i];
567  }
568 }

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

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

◆ validatePauliHamil()

void validatePauliHamil ( PauliHamil  hamil,
const char *  caller 
)

◆ validateProb()

void validateProb ( qreal  prob,
const char *  caller 
)

◆ validateSecondQuregStateVec()

void validateSecondQuregStateVec ( Qureg  qureg2,
const char *  caller 
)

Definition at line 503 of file QuEST_validation.c.

503  {
505 }

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 341 of file QuEST_validation.c.

341  {
342  long long int stateMax = 1LL << qureg.numQubitsRepresented;
343  QuESTAssert(stateInd>=0 && stateInd<stateMax, E_INVALID_STATE_INDEX, caller);
344 }

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 667 of file QuEST_validation.c.

667  {
668  int isEven = (order % 2) == 0;
669  QuESTAssert(order > 0 && (isEven || order==1), E_INVALID_TROTTER_ORDER, caller);
670  QuESTAssert(reps > 0, E_INVALID_TROTTER_REPS, caller);
671 }

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 532 of file QuEST_validation.c.

532  {
533  validateProb(prob, caller);
534  QuESTAssert(prob <= 3/4.0, E_INVALID_TWO_QUBIT_DEPHASE_PROB, caller);
535 }

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

Referenced by mixTwoQubitDephasing().

◆ validateTwoQubitDepolProb()

void validateTwoQubitDepolProb ( qreal  prob,
const char *  caller 
)

Definition at line 547 of file QuEST_validation.c.

547  {
548  validateProb(prob, caller);
549  QuESTAssert(prob <= 15/16.0, E_INVALID_TWO_QUBIT_DEPOL_PROB, caller);
550 }

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 586 of file QuEST_validation.c.

586  {
587  int opNumQubits = 2;
588  int superOpNumQubits = 2*opNumQubits;
589  int maxNumOps = superOpNumQubits*superOpNumQubits;
590  QuESTAssert(numOps > 0 && numOps <= maxNumOps, E_INVALID_NUM_TWO_QUBIT_KRAUS_OPS, caller);
591 
592  validateMultiQubitMatrixFitsInNode(qureg, superOpNumQubits, caller);
593 
594  int isPos = isCompletelyPositiveMap4(ops, numOps);
595  QuESTAssert(isPos, E_INVALID_KRAUS_OPS, caller);
596 }

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 378 of file QuEST_validation.c.

378  {
379  validateTarget(qureg, qubit1, caller);
380  validateTarget(qureg, qubit2, caller);
381  QuESTAssert(qubit1 != qubit2, E_TARGETS_NOT_UNIQUE, caller);
382 }

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 471 of file QuEST_validation.c.

471  {
473 }

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 475 of file QuEST_validation.c.

475  {
476  QuESTAssert(getVectorMagnitude(vec) > REAL_EPS, E_ZERO_VECTOR, caller);
477 }

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

Referenced by controlledRotateAroundAxis(), and rotateAroundAxis().

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_INVALID_QUBIT_OUTCOME
@ E_CANNOT_PARSE_PAULI_HAMIL_FILE_COEFF
int isMatrix2Unitary(ComplexMatrix2 u)
@ E_INVALID_PAULI_CODE
@ E_NON_UNITARY_MATRIX
void validateHamilParams(int numQubits, int numTerms, const char *caller)
@ E_INVALID_ONE_QUBIT_DEPHASE_PROB
void validateMultiQubitMatrixFitsInNode(Qureg qureg, int numTargets, const char *caller)
@ E_CANNOT_FIT_MULTI_QUBIT_MATRIX
@ E_INVALID_NUM_N_QUBIT_KRAUS_OPS
@ E_INVALID_ELEM_INDEX
int isMatrix4Unitary(ComplexMatrix4 u)
@ 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
void validateProb(qreal prob, const char *caller)
@ E_NON_UNITARY_COMPLEX_PAIR
@ E_INVALID_CONTROLS_BIT_STATE
@ E_INVALID_TROTTER_ORDER
@ E_INVALID_NUM_TWO_QUBIT_KRAUS_OPS
@ E_DISTRIB_DIAG_OP_TOO_SMALL
@ 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
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_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:213
@ 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:162
@ E_MISMATCHING_NUM_TARGS_KRAUS_SIZE
void validateMultiTargets(Qureg qureg, int *targetQubits, int numTargetQubits, const char *caller)
int isValidPauliCode(enum pauliOpType code)
@ 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:181
@ 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:166
long long int getQubitBitMask(int *qubits, int numQubits)
Definition: QuEST_common.c:44
@ E_MISMATCHING_QUREG_DIAGONAL_OP_SIZE
@ E_INVALID_AMP_INDEX
qreal ** real
Definition: QuEST.h:139
@ 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
qreal ** imag
Definition: QuEST.h:140
@ E_MISMATCHING_QUREG_DIMENSIONS
@ E_INVALID_TROTTER_REPS
char errMsgBuffer[1024]
@ E_INVALID_NUM_CREATE_QUBITS
void validateDiagOpInit(DiagonalOp op, const char *caller)
int isDensityMatrix
Whether this instance is a density-state representation.
Definition: QuEST.h:206
int numQubits
Definition: QuEST.h:138
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:73
@ E_INVALID_PAULI_HAMIL_FILE_PARAMS
int numQubits
The number of qubits for which this Hamiltonian is defined.
Definition: QuEST.h:168
@ E_UNNORM_PROBS
int numQubitsRepresented
The number of qubits represented in either the state-vector or density matrix.
Definition: QuEST.h:208
long long int numAmpsTotal
Total number of amplitudes, which are possibly distributed among machines.
Definition: QuEST.h:215
void destroyPauliHamil(PauliHamil h)
Destroy a PauliHamil instance, created with either createPauliHamil() or createPauliHamilFromFile().
Definition: QuEST.c:1163
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)
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