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

Functions for applying general many-qubit diagonal matrices, as DiagMatr. More...

Functions

void applyControlledDiagMatr (Qureg qureg, int control, int *targets, int numTargets, DiagMatr matrix)
 
void applyControlledDiagMatr (Qureg qureg, int control, std::vector< int > targets, DiagMatr matrix)
 
void applyControlledDiagMatrPower (Qureg qureg, int control, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)
 
void applyControlledDiagMatrPower (Qureg qureg, int control, std::vector< int > targets, DiagMatr matrix, qcomp exponent)
 
void applyDiagMatr (Qureg qureg, int *targets, int numTargets, DiagMatr matrix)
 
void applyDiagMatr (Qureg qureg, std::vector< int > targets, DiagMatr matrix)
 
void applyDiagMatrPower (Qureg qureg, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)
 
void applyDiagMatrPower (Qureg qureg, std::vector< int > targets, DiagMatr matrix, qcomp exponent)
 
void applyMultiControlledDiagMatr (Qureg qureg, int *controls, int numControls, int *targets, int numTargets, DiagMatr matrix)
 
void applyMultiControlledDiagMatr (Qureg qureg, std::vector< int > controls, std::vector< int > targets, DiagMatr matrix)
 
void applyMultiControlledDiagMatrPower (Qureg qureg, int *controls, int numControls, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)
 
void applyMultiControlledDiagMatrPower (Qureg qureg, std::vector< int > controls, std::vector< int > targets, DiagMatr matrix, qcomp exponent)
 
void applyMultiStateControlledDiagMatr (Qureg qureg, int *controls, int *states, int numControls, int *targets, int numTargets, DiagMatr matrix)
 
void applyMultiStateControlledDiagMatr (Qureg qureg, std::vector< int > controls, std::vector< int > states, std::vector< int > targets, DiagMatr matrix)
 
void applyMultiStateControlledDiagMatrPower (Qureg qureg, int *controls, int *states, int numControls, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)
 
void applyMultiStateControlledDiagMatrPower (Qureg qureg, std::vector< int > controls, std::vector< int > states, std::vector< int > targets, DiagMatr matrix, qcomp exponent)
 
void multiplyDiagMatr (Qureg qureg, int *targets, int numTargets, DiagMatr matrix)
 
void multiplyDiagMatr (Qureg qureg, std::vector< int > targets, DiagMatr matrix)
 
void multiplyDiagMatrPower (Qureg qureg, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)
 
void multiplyDiagMatrPower (Qureg qureg, std::vector< int > targets, DiagMatr matrix, qcomp exponent)
 

Detailed Description

Functions for applying general many-qubit diagonal matrices, as DiagMatr.

Function Documentation

◆ applyControlledDiagMatr() [1/2]

void applyControlledDiagMatr ( Qureg qureg,
int control,
int * targets,
int numTargets,
DiagMatr matrix )
Note
Documentation for this function or struct is under construction!

Definition at line 361 of file operations.cpp.

361 {
362
363 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, &control, nullptr, 1, targets, numTargets, matrix, __func__);
364}

Referenced by applyControlledDiagMatr().

◆ applyControlledDiagMatr() [2/2]

void applyControlledDiagMatr ( Qureg qureg,
int control,
std::vector< int > targets,
DiagMatr matrix )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 388 of file operations.cpp.

388 {
389
390 applyControlledDiagMatr(qureg, control, targets.data(), targets.size(), matrix);
391}
void applyControlledDiagMatr(Qureg qureg, int control, int *targets, int numTargets, DiagMatr matrix)

◆ applyControlledDiagMatrPower() [1/2]

void applyControlledDiagMatrPower ( Qureg qureg,
int control,
int * targets,
int numTargets,
DiagMatr matrix,
qcomp exponent )
Note
Documentation for this function or struct is under construction!

Definition at line 439 of file operations.cpp.

439 {
440 validate_quregFields(qureg, __func__);
441 validate_controlAndTargets(qureg, control, targets, numTargets, __func__);
442 validate_matrixDimMatchesTargets(matrix, numTargets, __func__); // also checks fields and is-synced
443 validate_matrixIsUnitary(matrix, __func__);
444 validate_matrixExpIsNonDiverging(matrix, exponent, __func__);
445 validate_unitaryExponentIsReal(exponent, __func__);
446
447 // notice exponent is a 'qcomp' not a 'qreal' despite validation; see applyMultiStateControlledDiagMatrPower()
448
449 // harmlessly re-validates
450 applyMultiStateControlledDiagMatrPower(qureg, &control, nullptr, 1, targets, numTargets, matrix, exponent);
451}
void applyMultiStateControlledDiagMatrPower(Qureg qureg, int *controls, int *states, int numControls, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)

Referenced by applyControlledDiagMatrPower().

◆ applyControlledDiagMatrPower() [2/2]

void applyControlledDiagMatrPower ( Qureg qureg,
int control,
std::vector< int > targets,
DiagMatr matrix,
qcomp exponent )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 512 of file operations.cpp.

512 {
513
514 applyControlledDiagMatrPower(qureg, control, targets.data(), targets.size(), matrix, exponent);
515}
void applyControlledDiagMatrPower(Qureg qureg, int control, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)

◆ applyDiagMatr() [1/2]

void applyDiagMatr ( Qureg qureg,
int * targets,
int numTargets,
DiagMatr matrix )
Note
Documentation for this function or struct is under construction!

Definition at line 356 of file operations.cpp.

356 {
357
358 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, nullptr, nullptr, 0, targets, numTargets, matrix, __func__);
359}

Referenced by applyDiagMatr().

◆ applyDiagMatr() [2/2]

void applyDiagMatr ( Qureg qureg,
std::vector< int > targets,
DiagMatr matrix )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 383 of file operations.cpp.

383 {
384
385 applyDiagMatr(qureg, targets.data(), targets.size(), matrix);
386}
void applyDiagMatr(Qureg qureg, int *targets, int numTargets, DiagMatr matrix)

◆ applyDiagMatrPower() [1/2]

void applyDiagMatrPower ( Qureg qureg,
int * targets,
int numTargets,
DiagMatr matrix,
qcomp exponent )
Note
Documentation for this function or struct is under construction!

Definition at line 425 of file operations.cpp.

425 {
426 validate_quregFields(qureg, __func__);
427 validate_targets(qureg, targets, numTargets, __func__);
428 validate_matrixDimMatchesTargets(matrix, numTargets, __func__); // also checks fields and is-synced
429 validate_matrixIsUnitary(matrix, __func__);
430 validate_matrixExpIsNonDiverging(matrix, exponent, __func__);
431 validate_unitaryExponentIsReal(exponent, __func__);
432
433 // notice exponent is a 'qcomp' not a 'qreal' despite validation; see applyMultiStateControlledDiagMatrPower()
434
435 // harmlessly re-validates
436 applyMultiStateControlledDiagMatrPower(qureg, nullptr, nullptr, 0, targets, numTargets, matrix, exponent);
437}

Referenced by applyDiagMatrPower().

◆ applyDiagMatrPower() [2/2]

void applyDiagMatrPower ( Qureg qureg,
std::vector< int > targets,
DiagMatr matrix,
qcomp exponent )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 507 of file operations.cpp.

507 {
508
509 applyDiagMatrPower(qureg, targets.data(), targets.size(), matrix, exponent);
510}
void applyDiagMatrPower(Qureg qureg, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)

◆ applyMultiControlledDiagMatr() [1/2]

void applyMultiControlledDiagMatr ( Qureg qureg,
int * controls,
int numControls,
int * targets,
int numTargets,
DiagMatr matrix )
Note
Documentation for this function or struct is under construction!

Definition at line 366 of file operations.cpp.

366 {
367
368 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, nullptr, numControls, targets, numTargets, matrix, __func__);
369}

Referenced by applyMultiControlledDiagMatr().

◆ applyMultiControlledDiagMatr() [2/2]

void applyMultiControlledDiagMatr ( Qureg qureg,
std::vector< int > controls,
std::vector< int > targets,
DiagMatr matrix )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 393 of file operations.cpp.

393 {
394
395 applyMultiControlledDiagMatr(qureg, controls.data(), controls.size(), targets.data(), targets.size(), matrix);
396}
void applyMultiControlledDiagMatr(Qureg qureg, int *controls, int numControls, int *targets, int numTargets, DiagMatr matrix)

◆ applyMultiControlledDiagMatrPower() [1/2]

void applyMultiControlledDiagMatrPower ( Qureg qureg,
int * controls,
int numControls,
int * targets,
int numTargets,
DiagMatr matrix,
qcomp exponent )
Note
Documentation for this function or struct is under construction!

Definition at line 453 of file operations.cpp.

453 {
454 validate_quregFields(qureg, __func__);
455 validate_controlsAndTargets(qureg, controls, numControls, targets, numTargets, __func__);
456 validate_matrixDimMatchesTargets(matrix, numTargets, __func__); // also checks fields and is-synced
457 validate_matrixIsUnitary(matrix, __func__);
458 validate_matrixExpIsNonDiverging(matrix, exponent, __func__);
459 validate_unitaryExponentIsReal(exponent, __func__);
460
461 // notice exponent is a 'qcomp' not a 'qreal' despite validation; see applyMultiStateControlledDiagMatrPower()
462
463 // harmlessly re-validates
464 applyMultiStateControlledDiagMatrPower(qureg, controls, nullptr, numControls, targets, numTargets, matrix, exponent);
465}

Referenced by applyMultiControlledDiagMatrPower().

◆ applyMultiControlledDiagMatrPower() [2/2]

void applyMultiControlledDiagMatrPower ( Qureg qureg,
std::vector< int > controls,
std::vector< int > targets,
DiagMatr matrix,
qcomp exponent )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 517 of file operations.cpp.

517 {
518
519 applyMultiControlledDiagMatrPower(qureg, controls.data(), controls.size(), targets.data(), targets.size(), matrix, exponent);
520}
void applyMultiControlledDiagMatrPower(Qureg qureg, int *controls, int numControls, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)

◆ applyMultiStateControlledDiagMatr() [1/2]

void applyMultiStateControlledDiagMatr ( Qureg qureg,
int * controls,
int * states,
int numControls,
int * targets,
int numTargets,
DiagMatr matrix )
Note
Documentation for this function or struct is under construction!

Definition at line 371 of file operations.cpp.

371 {
372
373 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, targets, numTargets, matrix, __func__);
374}

Referenced by applyMultiStateControlledDiagMatr().

◆ applyMultiStateControlledDiagMatr() [2/2]

void applyMultiStateControlledDiagMatr ( Qureg qureg,
std::vector< int > controls,
std::vector< int > states,
std::vector< int > targets,
DiagMatr matrix )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 398 of file operations.cpp.

398 {
399 validate_controlsMatchStates(controls.size(), states.size(), __func__);
400
401 applyMultiStateControlledDiagMatr(qureg, controls.data(), states.data(), controls.size(), targets.data(), targets.size(), matrix);
402}
void applyMultiStateControlledDiagMatr(Qureg qureg, int *controls, int *states, int numControls, int *targets, int numTargets, DiagMatr matrix)

◆ applyMultiStateControlledDiagMatrPower() [1/2]

void applyMultiStateControlledDiagMatrPower ( Qureg qureg,
int * controls,
int * states,
int numControls,
int * targets,
int numTargets,
DiagMatr matrix,
qcomp exponent )
Note
Documentation for this function or struct is under construction!

Definition at line 467 of file operations.cpp.

467 {
468 validate_quregFields(qureg, __func__);
469 validate_controlsAndTargets(qureg, controls, numControls, targets, numTargets, __func__);
470 validate_controlStates(states, numControls, __func__); // can be nullptr, ignoring numControls
471 validate_matrixDimMatchesTargets(matrix, numTargets, __func__);
472 validate_matrixIsUnitary(matrix, __func__);
473 validate_matrixExpIsNonDiverging(matrix, exponent, __func__);
474 validate_unitaryExponentIsReal(exponent, __func__);
475
476 // unlike calcExpecDiagMatrPower which accepts a 'qreal' exponent,
477 // this function accepts a 'qcomp'. This is because it always
478 // evaluates the relatively numerically unstable pow(qcomp,qcomp)
479 // overload, rather than pow(qreal,qreal), since there is no reason
480 // to think matrix is real (unitarity permits it to be complex).
481 // As such, despite unitarity requiring exponent is also real, we
482 // accept a qcomp types so that complex exponents can be passed
483 // when numerical validation is disabled without a separate func.
484
485 bool conj = false;
486 auto ctrlVec = util_getVector(controls, numControls);
487 auto stateVec = util_getVector(states, numControls); // empty if states==nullptr
488 auto targVec = util_getVector(targets, numTargets);
489 localiser_statevec_anyCtrlAnyTargDiagMatr(qureg, ctrlVec, stateVec, targVec, matrix, exponent, conj);
490
491 if (!qureg.isDensityMatrix)
492 return;
493
494 conj = true;
495 ctrlVec = util_getBraQubits(ctrlVec, qureg);
496 targVec = util_getBraQubits(targVec, qureg);
497 localiser_statevec_anyCtrlAnyTargDiagMatr(qureg, ctrlVec, stateVec, targVec, matrix, exponent, conj);
498}

Referenced by applyControlledDiagMatrPower(), applyDiagMatrPower(), applyMultiControlledDiagMatrPower(), and applyMultiStateControlledDiagMatrPower().

◆ applyMultiStateControlledDiagMatrPower() [2/2]

void applyMultiStateControlledDiagMatrPower ( Qureg qureg,
std::vector< int > controls,
std::vector< int > states,
std::vector< int > targets,
DiagMatr matrix,
qcomp exponent )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 522 of file operations.cpp.

522 {
523 validate_controlsMatchStates(controls.size(), states.size(), __func__);
524
525 applyMultiStateControlledDiagMatrPower(qureg, controls.data(), states.data(), controls.size(), targets.data(), targets.size(), matrix, exponent);
526}

◆ multiplyDiagMatr() [1/2]

void multiplyDiagMatr ( Qureg qureg,
int * targets,
int numTargets,
DiagMatr matrix )
Note
Documentation for this function or struct is under construction!

Definition at line 346 of file operations.cpp.

346 {
347 validate_quregFields(qureg, __func__);
348 validate_targets(qureg, targets, numTargets, __func__);
349 validate_matrixDimMatchesTargets(matrix, numTargets, __func__); // also validates fields and is-sync, but not unitarity
350
351 bool conj = false;
352 qcomp exponent = 1;
353 localiser_statevec_anyCtrlAnyTargDiagMatr(qureg, {}, {}, util_getVector(targets, numTargets), matrix, exponent, conj);
354}

Referenced by multiplyDiagMatr().

◆ multiplyDiagMatr() [2/2]

void multiplyDiagMatr ( Qureg qureg,
std::vector< int > targets,
DiagMatr matrix )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 378 of file operations.cpp.

378 {
379
380 multiplyDiagMatr(qureg, targets.data(), targets.size(), matrix);
381}
void multiplyDiagMatr(Qureg qureg, int *targets, int numTargets, DiagMatr matrix)

◆ multiplyDiagMatrPower() [1/2]

void multiplyDiagMatrPower ( Qureg qureg,
int * targets,
int numTargets,
DiagMatr matrix,
qcomp exponent )
Note
Documentation for this function or struct is under construction!

Definition at line 415 of file operations.cpp.

415 {
416 validate_quregFields(qureg, __func__);
417 validate_targets(qureg, targets, numTargets, __func__);
418 validate_matrixDimMatchesTargets(matrix, numTargets, __func__); // also validates fields and is-sync, but not unitarity
419 validate_matrixExpIsNonDiverging(matrix, exponent, __func__); // harmlessly re-validates fields and is-sync
420
421 bool conj = false;
422 localiser_statevec_anyCtrlAnyTargDiagMatr(qureg, {}, {}, util_getVector(targets, numTargets), matrix, exponent, conj);
423}

Referenced by multiplyDiagMatrPower().

◆ multiplyDiagMatrPower() [2/2]

void multiplyDiagMatrPower ( Qureg qureg,
std::vector< int > targets,
DiagMatr matrix,
qcomp exponent )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 502 of file operations.cpp.

502 {
503
504 multiplyDiagMatrPower(qureg, targets.data(), targets.size(), matrix, exponent);
505}
void multiplyDiagMatrPower(Qureg qureg, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)