The Quantum Exact Simulation Toolkit v4.2.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 applyControlledDiagMatrPower (Qureg qureg, int control, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)
 
void applyDiagMatr (Qureg qureg, int *targets, int numTargets, DiagMatr matrix)
 
void applyDiagMatrPower (Qureg qureg, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)
 
void applyMultiControlledDiagMatr (Qureg qureg, int *controls, int numControls, int *targets, int numTargets, DiagMatr matrix)
 
void applyMultiControlledDiagMatrPower (Qureg qureg, int *controls, int numControls, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)
 
void applyMultiStateControlledDiagMatr (Qureg qureg, int *controls, int *states, int numControls, int *targets, int numTargets, DiagMatr matrix)
 
void applyMultiStateControlledDiagMatrPower (Qureg qureg, int *controls, int *states, int numControls, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)
 

Detailed Description

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

Function Documentation

◆ applyControlledDiagMatr()

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

Definition at line 303 of file operations.cpp.

303 {
304
305 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, &control, nullptr, 1, targets, numTargets, matrix, __func__);
306}

Referenced by applyControlledDiagMatr().

◆ applyControlledDiagMatrPower()

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

Definition at line 366 of file operations.cpp.

366 {
367 validate_quregFields(qureg, __func__);
368 validate_controlAndTargets(qureg, control, targets, numTargets, __func__);
369 validate_matrixDimMatchesTargets(matrix, numTargets, __func__); // also checks fields and is-synced
370 validate_matrixIsUnitary(matrix, __func__);
371 validate_matrixExpIsNonDiverging(matrix, exponent, __func__);
372 validate_unitaryExponentIsReal(exponent, __func__);
373
374 // notice exponent is a 'qcomp' not a 'qreal' despite validation; see applyMultiStateControlledDiagMatrPower()
375
376 // harmlessly re-validates
377 applyMultiStateControlledDiagMatrPower(qureg, &control, nullptr, 1, targets, numTargets, matrix, exponent);
378}
void applyMultiStateControlledDiagMatrPower(Qureg qureg, int *controls, int *states, int numControls, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)

Referenced by applyControlledDiagMatrPower().

◆ applyDiagMatr()

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

Definition at line 298 of file operations.cpp.

298 {
299
300 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, nullptr, nullptr, 0, targets, numTargets, matrix, __func__);
301}

Referenced by applyDiagMatr().

◆ applyDiagMatrPower()

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

This function is equivalent to applyDiagMatr() except that matrix is raised to the given exponent.

Definition at line 352 of file operations.cpp.

352 {
353 validate_quregFields(qureg, __func__);
354 validate_targets(qureg, targets, numTargets, __func__);
355 validate_matrixDimMatchesTargets(matrix, numTargets, __func__); // also checks fields and is-synced
356 validate_matrixIsUnitary(matrix, __func__);
357 validate_matrixExpIsNonDiverging(matrix, exponent, __func__);
358 validate_unitaryExponentIsReal(exponent, __func__);
359
360 // notice exponent is a 'qcomp' not a 'qreal' despite validation; see applyMultiStateControlledDiagMatrPower()
361
362 // harmlessly re-validates
363 applyMultiStateControlledDiagMatrPower(qureg, nullptr, nullptr, 0, targets, numTargets, matrix, exponent);
364}

Referenced by applyDiagMatrPower().

◆ applyMultiControlledDiagMatr()

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

Definition at line 308 of file operations.cpp.

308 {
309
310 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, nullptr, numControls, targets, numTargets, matrix, __func__);
311}

Referenced by applyMultiControlledDiagMatr().

◆ applyMultiControlledDiagMatrPower()

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!
See also

Definition at line 380 of file operations.cpp.

380 {
381 validate_quregFields(qureg, __func__);
382 validate_controlsAndTargets(qureg, controls, numControls, targets, numTargets, __func__);
383 validate_matrixDimMatchesTargets(matrix, numTargets, __func__); // also checks fields and is-synced
384 validate_matrixIsUnitary(matrix, __func__);
385 validate_matrixExpIsNonDiverging(matrix, exponent, __func__);
386 validate_unitaryExponentIsReal(exponent, __func__);
387
388 // notice exponent is a 'qcomp' not a 'qreal' despite validation; see applyMultiStateControlledDiagMatrPower()
389
390 // harmlessly re-validates
391 applyMultiStateControlledDiagMatrPower(qureg, controls, nullptr, numControls, targets, numTargets, matrix, exponent);
392}

Referenced by applyMultiControlledDiagMatrPower().

◆ applyMultiStateControlledDiagMatr()

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!
See also
applyMultiStateControlledCompMatr1()

Definition at line 313 of file operations.cpp.

313 {
314
315 validateAndApplyAnyCtrlAnyTargUnitaryMatrix(qureg, controls, states, numControls, targets, numTargets, matrix, __func__);
316}

Referenced by applyMultiStateControlledDiagMatr().

◆ applyMultiStateControlledDiagMatrPower()

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!
See also

Definition at line 394 of file operations.cpp.

394 {
395 validate_quregFields(qureg, __func__);
396 validate_controlsAndTargets(qureg, controls, numControls, targets, numTargets, __func__);
397 validate_controlStates(states, numControls, __func__); // can be nullptr, ignoring numControls
398 validate_matrixDimMatchesTargets(matrix, numTargets, __func__);
399 validate_matrixIsUnitary(matrix, __func__);
400 validate_matrixExpIsNonDiverging(matrix, exponent, __func__);
401 validate_unitaryExponentIsReal(exponent, __func__);
402
403 // unlike calcExpecDiagMatrPower which accepts a 'qreal' exponent,
404 // this function accepts a 'qcomp'. This is because it always
405 // evaluates the relatively numerically unstable pow(qcomp,qcomp)
406 // overload, rather than pow(qreal,qreal), since there is no reason
407 // to think matrix is real (unitarity permits it to be complex).
408 // As such, despite unitarity requiring exponent is also real, we
409 // accept a qcomp types so that complex exponents can be passed
410 // when numerical validation is disabled without a separate func.
411
412 bool conj = false;
413 auto ctrlVec = util_getVector(controls, numControls);
414 auto stateVec = util_getVector(states, numControls); // empty if states==nullptr
415 auto targVec = util_getVector(targets, numTargets);
416 localiser_statevec_anyCtrlAnyTargDiagMatr(qureg, ctrlVec, stateVec, targVec, matrix, exponent, conj);
417
418 if (!qureg.isDensityMatrix)
419 return;
420
421 conj = true;
422 ctrlVec = util_getBraQubits(ctrlVec, qureg);
423 targVec = util_getBraQubits(targVec, qureg);
424 localiser_statevec_anyCtrlAnyTargDiagMatr(qureg, ctrlVec, stateVec, targVec, matrix, exponent, conj);
425}

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