![]() |
The Quantum Exact Simulation Toolkit v4.2.0
|
Functions for non-destructively calculating the probabilities of measurement outcomes. More...
Functions | |
| qreal | calcProbOfBasisState (Qureg qureg, qindex index) |
| qreal | calcProbOfMultiQubitOutcome (Qureg qureg, int *qubits, int *outcomes, int numQubits) |
| qreal | calcProbOfQubitOutcome (Qureg qureg, int qubit, int outcome) |
| void | calcProbsOfAllMultiQubitOutcomes (qreal *outcomeProbs, Qureg qureg, int *qubits, int numQubits) |
Functions for non-destructively calculating the probabilities of measurement outcomes.
| qreal calcProbOfBasisState | ( | Qureg | qureg, |
| qindex | index ) |
Calculates the probability of the full computational basis state of the specified index. This is the probability that, when measured in the \( \hat{Z} \) basis, every qubit of qureg is consistent with the bits of index.
Indexing is little-endian and from zero, such that (for example) computational basis state \( \ket{0011} \) (where qubits at indices \(0\) and \(1\) are in the \(\ket{1}\) state) corresponds to index \( = 3 \). The maximum legal index of an \(N\)-qubit register is index \( = 2^N-1 \).
Let \( i = \) index.
qureg is a statevector \( \svpsi \), this function returns \[ P(i) = |\braket{i}{\psi}|^2 = |\psi_i|^2 \]
where \(\psi_i\) is the \(i\)-th amplitude of \(\svpsi\).qureg is a density matrix \(\dmrho\), this function returns \[ P(i) = \re{ \tr{ \ketbra{i}{i} \dmrho } } = \re{ \bra{i} \dmrho \ket{i} } = \re{ \dmrho_{ii} } \]
where \( \dmrho_{ii} \) is the \(i\)-th diagonal element of \(\dmrho\), and is real whenever \( \dmrho \) is valid (or at least, Hermitian).When qureg is correctly normalised, these quantities are within \([0, 1]\), and satisfy
\[ \sum\limits_{i=0}^{2^N-1} P(i) = 1 \]
where \(N\) is the number of qubits in qureg.
qureg amplitude directly and evaluating the probability. index. I.e. index and computing their overlap. | [in] | qureg | the reference state, which is unchanged. |
| [in] | index | the index of the queried basis state among the ordered set of all basis states. |
index. | error |
|
Definition at line 224 of file calculations.cpp.
Referenced by TEST_CASE().
| qreal calcProbOfMultiQubitOutcome | ( | Qureg | qureg, |
| int * | qubits, | ||
| int * | outcomes, | ||
| int | numQubits ) |
Calculates the probability that the given list of qubits are simultaneously in the respective single-qubit states specified in outcomes.
Let \(q_j\) and \(x_j\) notate the \(j\)-th qubit in qubits and its respective outcome in outcomes.
qureg is a statevector \( \svpsi \), this function returns \[ \tr{ \bigotimes\limits_j \ketbra{x_j}{x_j}_{q_j} \; \ketbra{\psi}{\psi} } = \sum\limits_i |\psi_i|^2 \prod\limits_j \delta_{x_j, \, i_{[q_j]}} \]
where \(\psi_i\) is the \(i\)-th amplitude of \(\svpsi\), and \(i_{[q]}\) notates the \(q\)-th bit of \(i\).qureg is a density matrix \( \dmrho \), this function returns \[ \tr{ \bigotimes\limits_j \ketbra{x_j}{x_j}_{q_j} \; \dmrho } = \sum\limits_i \re{\dmrho_{ii}} \prod\limits_j \delta_{x_j, \, i_{[q_j]}} \]
where \( \dmrho_{ii} \) is the \(i\)-th diagonal element of \(\dmrho\). This is real whenever \(\dmrho\) is validly normalised (specifically, Hermitian).When qureg is correctly normalised, these quantities are within \([0, 1]\), and their sum across all possible values of outcomes equals one.
qureg into it (i.e. forcing that measurement outcome). That approach is however slower and modifies qureg, whereas this function leaves qureg unchanged. | [in] | qureg | the reference state, which is unchanged. |
| [in] | qubits | a list of target qubits to query. |
| [in] | outcomes | a list of corresponding qubit outcomes (each 0 or 1). |
| [in] | numQubits | the length of list qubits (and outcomes). |
| error |
|
| seg-fault |
|
Definition at line 251 of file calculations.cpp.
Referenced by applyForcedMultiQubitMeasurement(), calcProbOfMultiQubitOutcome(), calcProbOfQubitOutcome(), and TEST_CASE().
| qreal calcProbOfQubitOutcome | ( | Qureg | qureg, |
| int | qubit, | ||
| int | outcome ) |
Calculates the probability of the single qubit at index qubit being in the given computational basis outcome (0 or 1).
Let \( q = \) qubit and \( x = \) outcome, and let \(\ketbra{x}{x}_q\) notate a projector operating upon qubit \( q \).
qureg is a statevector \( \svpsi \), this function returns \[ P_q(x) = \tr{ \ketbra{x}{x}_q \, \ketbra{\psi}{\psi} } = \sum\limits_i |\psi_i|^2 \delta_{x,i_{[q]}} \]
where \(\psi_i\) is the \(i\)-th amplitude of \(\svpsi\), and \(i_{[q]}\) notates the \(q\)-th bit of \(i\).qureg is a density matrix \( \dmrho \), this function returns \[ P_q(x) = \tr{ \ketbra{x}{x}_q \, \dmrho } = \sum\limits_i \re{ \dmrho_{ii} } \delta_{x,i_{[q]}} \]
where \( \dmrho_{ii} \) is the \(i\)-th diagonal element of \(\dmrho\). This is real whenever \(\dmrho\) is validly normalised (specifically, Hermitian).When qureg is correctly normalised, these quantities are within \([0, 1]\), and satisfy
\[ P_q(x=0) + P_q(x=1) = 1. \]
| [in] | qureg | the reference state, which is unchanged. |
| [in] | qubit | the target qubit to query. |
| [in] | outcome | the outcome of qubit to query (i.e. 0 oe 1). |
| error |
|
Definition at line 241 of file calculations.cpp.
Referenced by applyForcedQubitMeasurement(), applyQubitMeasurementAndGetProb(), and TEST_CASE().
| void calcProbsOfAllMultiQubitOutcomes | ( | qreal * | outcomeProbs, |
| Qureg | qureg, | ||
| int * | qubits, | ||
| int | numQubits ) |
Populates outcomeProbs with the probabilities of the specified list of qubits being in all of their possible, simultaneous outcomes (of which there are 2^ numQubits).
The list qubits is taken to be in order of increasing significance, determining the ordering of the output outcomeProbs. For example, if qubits \( = \{ 1, 3 \} \), then outcomeProbs will be populated with four values; the probabilities of qubits \((3,1)\) being in the respective simultaneously outcomes \((0,0), \, (0,1), \, (1,0) \) and \((1,1)\). In contrast, qubits \( = \{ 3, 1 \} \) would see the middle two outputs swapped.
Let \( n = \) numQubits, and \( q_i \) be the \(i\)-th element of qubits, such that qubits = \( \{ q_0, q_1, \dots, q_{n-1} \} \). Let \( P_{\ket{q_{n-1} \dots q_1 q_0}}(\ket{i}) \) denote the probability that the specified substate is in the computational basis substate \(\ket{i}\). Explicitly, that qubit \(q_j\) is in the outcome given by the \(j\)-th bit of \(n\)-digit integer \(i\) (simultaneously for all \(j\)).
Then, this function sets
\[ \text{outcomeProbs}[i] = P_{\ket{q_{n-1} \dots q_1 q_0}}(\ket{i}) \]
for all \(i \in \{0, 1, \dots 2^n-1\} \).
Explicitly, expressing substate \(\ket{i}\) in terms of its individual qubits;
\[ \begin{gathered} \text{outcomeProbs}[0] = P_{\ket{q_{n-1} \dots q_1 q_0}}( \ket{0\dots00} ) \\ \text{outcomeProbs}[1] = P_{\ket{q_{n-1} \dots q_1 q_0}}( \ket{0\dots01} ) \\ \text{outcomeProbs}[2] = P_{\ket{q_{n-1} \dots q_1 q_0}}( \ket{0\dots10} ) \\ \text{outcomeProbs}[3] = P_{\ket{q_{n-1} \dots q_1 q_0}}( \ket{0\dots11} ) \\ \vdots \\ \text{outcomeProbs}[2^n-1] = P_{\ket{q_{n-1} \dots q_1 q_0}}( \ket{1\dots11} ) \end{gathered} \]
Each probability is that which would be output by calcProbOfMultiQubitOutcome() when passed qubits and the bits of \( i \).
When qureg is correctly normalised, all probabilities are within \([0, 1]\), and the sum of all elements written to outcomeProbs equals one.
outcomeProbs in-turn with the output of calcProbOfMultiQubitOutcome(). | [out] | outcomeProbs | the array to which the output is written. |
| [in] | qureg | the reference state, which is unchanged. |
| [in] | qubits | a list of target qubits to query. |
| [in] | numQubits | the length of list qubits. |
| error |
|
| seg-fault |
|
Definition at line 265 of file calculations.cpp.
Referenced by applyMultiQubitMeasurementAndGetProb(), calcProbsOfAllMultiQubitOutcomes(), and TEST_CASE().