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

Functions for effecting destructive measurements. More...

Functions

qreal applyForcedMultiQubitMeasurement (Qureg qureg, int *qubits, int *outcomes, int numQubits)
 
qreal applyForcedQubitMeasurement (Qureg qureg, int target, int outcome)
 
qindex applyMultiQubitMeasurement (Qureg qureg, int *qubits, int numQubits)
 
qindex applyMultiQubitMeasurementAndGetProb (Qureg qureg, int *qubits, int numQubits, qreal *probability)
 
int applyQubitMeasurement (Qureg qureg, int target)
 
int applyQubitMeasurementAndGetProb (Qureg qureg, int target, qreal *probability)
 

Detailed Description

Functions for effecting destructive measurements.

Function Documentation

◆ applyForcedMultiQubitMeasurement()

qreal applyForcedMultiQubitMeasurement ( Qureg qureg,
int * qubits,
int * outcomes,
int numQubits )
Note
Documentation for this function or struct is under construction!
Attention
This function's input validation has not yet been tested, so erroneous usage may produce unexpected output. Please use with caution!

Definition at line 1417 of file operations.cpp.

1417 {
1418 validate_quregFields(qureg, __func__);
1419 validate_targets(qureg, qubits, numQubits, __func__);
1420 validate_measurementOutcomesAreValid(outcomes, numQubits, __func__);
1421
1422 auto qubitVec = util_getVector(qubits, numQubits);
1423 auto outcomeVec = util_getVector(outcomes, numQubits);
1424
1425 // ensure probability of the forced measurement outcome is not negligible
1426 qreal prob = calcProbOfMultiQubitOutcome(qureg, qubits, outcomes, numQubits); // harmlessly re-validates
1427 validate_measurementOutcomesProbNotZero(outcomes, numQubits, prob, __func__);
1428
1429 // project to the outcome, renormalising the surviving states
1430 (qureg.isDensityMatrix)?
1431 localiser_densmatr_multiQubitProjector(qureg, qubitVec, outcomeVec, prob):
1432 localiser_statevec_multiQubitProjector(qureg, qubitVec, outcomeVec, prob);
1433
1434 return prob;
1435}
qreal calcProbOfMultiQubitOutcome(Qureg qureg, int *qubits, int *outcomes, int numQubits)

Referenced by TEST_CASE().

◆ applyForcedQubitMeasurement()

qreal applyForcedQubitMeasurement ( Qureg qureg,
int target,
int outcome )
Note
Documentation for this function or struct is under construction!
Attention
This function's input validation has not yet been tested, so erroneous usage may produce unexpected output. Please use with caution!

Definition at line 1347 of file operations.cpp.

1347 {
1348 validate_quregFields(qureg, __func__);
1349 validate_target(qureg, target, __func__);
1350 validate_measurementOutcomeIsValid(outcome, __func__);
1351
1352 // note that we do not merely invoke applyForcedMultiQubitMeasurement()
1353 // because we must validate the renormalising probability and
1354 // report this function's name during the error message
1355 qreal prob = calcProbOfQubitOutcome(qureg, target, outcome); // harmlessly re-validates
1356 validate_measurementOutcomeProbNotZero(outcome, prob, __func__);
1357
1358 // project to the outcome, renormalising the surviving states
1359 (qureg.isDensityMatrix)?
1360 localiser_densmatr_multiQubitProjector(qureg, {target}, {outcome}, prob):
1361 localiser_statevec_multiQubitProjector(qureg, {target}, {outcome}, prob);
1362
1363 return prob;
1364}
qreal calcProbOfQubitOutcome(Qureg qureg, int qubit, int outcome)

Referenced by TEST_CASE().

◆ applyMultiQubitMeasurement()

qindex applyMultiQubitMeasurement ( Qureg qureg,
int * qubits,
int numQubits )
Note
Documentation for this function or struct is under construction!
Attention
This function's input validation has not yet been tested, so erroneous usage may produce unexpected output. Please use with caution!

Definition at line 1378 of file operations.cpp.

1378 {
1379 validate_quregFields(qureg, __func__);
1380 validate_targets(qureg, qubits, numQubits, __func__);
1381
1382 qreal prob = 0; // ignored
1383
1384 // below validates post-measurement and would report 'AndGetProb' function suffix. Eh!
1385 return applyMultiQubitMeasurementAndGetProb(qureg, qubits, numQubits, &prob);
1386}
qindex applyMultiQubitMeasurementAndGetProb(Qureg qureg, int *qubits, int numQubits, qreal *probability)

Referenced by TEST_CASE().

◆ applyMultiQubitMeasurementAndGetProb()

qindex applyMultiQubitMeasurementAndGetProb ( Qureg qureg,
int * qubits,
int numQubits,
qreal * probability )
Note
Documentation for this function or struct is under construction!
Attention
This function's input validation has not yet been tested, so erroneous usage may produce unexpected output. Please use with caution!

Definition at line 1388 of file operations.cpp.

1388 {
1389 validate_quregFields(qureg, __func__);
1390 validate_targets(qureg, qubits, numQubits, __func__);
1391
1392 // find the probability of all possible outcomes
1393 qindex numProbs = powerOf2(numQubits);
1394 vector<qreal> probs(numProbs);
1395 calcProbsOfAllMultiQubitOutcomes(probs.data(), qureg, qubits, numQubits); // harmlessly re-validates
1396
1397 // we cannot meaningfully sample these probs if not normalised
1398 validate_measurementProbsAreNormalised(probs, __func__);
1399
1400 // randomly choose an outcome
1401 qindex outcome = rand_getRandomMultiQubitOutcome(probs);
1402 *probability = probs[outcome];
1403
1404 // map outcome to individual qubit outcomes
1405 auto qubitVec = util_getVector(qubits, numQubits);
1406 auto outcomeVec = vector<int>(numQubits);
1407 getBitsFromInteger(outcomeVec.data(), outcome, numQubits);
1408
1409 // project to the outcomes, renormalising the surviving states
1410 (qureg.isDensityMatrix)?
1411 localiser_densmatr_multiQubitProjector(qureg, qubitVec, outcomeVec, *probability):
1412 localiser_statevec_multiQubitProjector(qureg, qubitVec, outcomeVec, *probability);
1413
1414 return outcome;
1415}
void calcProbsOfAllMultiQubitOutcomes(qreal *outcomeProbs, Qureg qureg, int *qubits, int numQubits)

Referenced by applyMultiQubitMeasurement(), and TEST_CASE().

◆ applyQubitMeasurement()

int applyQubitMeasurement ( Qureg qureg,
int target )
Note
Documentation for this function or struct is under construction!
Attention
This function's input validation has not yet been tested, so erroneous usage may produce unexpected output. Please use with caution!

Definition at line 1314 of file operations.cpp.

1314 {
1315 validate_quregFields(qureg, __func__);
1316 validate_target(qureg, target, __func__);
1317
1318 qreal prob = 0; // ignored
1319 return applyQubitMeasurementAndGetProb(qureg, target, &prob); // harmlessly re-validates
1320}
int applyQubitMeasurementAndGetProb(Qureg qureg, int target, qreal *probability)

Referenced by TEST_CASE().

◆ applyQubitMeasurementAndGetProb()

int applyQubitMeasurementAndGetProb ( Qureg qureg,
int target,
qreal * probability )
Note
Documentation for this function or struct is under construction!
Attention
This function's input validation has not yet been tested, so erroneous usage may produce unexpected output. Please use with caution!

Definition at line 1322 of file operations.cpp.

1322 {
1323 validate_quregFields(qureg, __func__);
1324 validate_target(qureg, target, __func__);
1325
1326 // we do not assume state normalisation (that is posteriori checked),
1327 // so we must perform two reductions; one for each outcome. We choose
1328 // to re-enumerate the state (potentially doubling caching costs) to
1329 // avoid the nuisances/race-cons of parallel adding to two scalars.
1330 vector<qreal> probs(2);
1331 probs[0] = calcProbOfQubitOutcome(qureg, target, 0); // harmlessly re-validates
1332 probs[1] = calcProbOfQubitOutcome(qureg, target, 1); // " "
1333 validate_measurementProbsAreNormalised(probs, __func__);
1334
1335 // randomly choose the outcome
1336 int outcome = rand_getRandomSingleQubitOutcome(probs[0]);
1337 *probability = probs[outcome];
1338
1339 // collapse to the outcome
1340 (qureg.isDensityMatrix)?
1341 localiser_densmatr_multiQubitProjector(qureg, {target}, {outcome}, *probability):
1342 localiser_statevec_multiQubitProjector(qureg, {target}, {outcome}, *probability);
1343
1344 return outcome;
1345}

Referenced by applyQubitMeasurement(), and TEST_CASE().