[−][src]Function qip::measurement_ops::measure_prob
pub fn measure_prob<P: Precision>(
n: u64,
measured: u64,
indices: &[u64],
input: &[Complex<P>],
input_offset: Option<u64>,
multithread: bool
) -> P
Calculate the probability of a given measurement. measured
gives the bits (as a u64) which has
been measured from the qubits at indices
in the order supplied by indices
. input
gives the
state from which to measure, representing a total of n
qubits. And input_offset
gives the
actual index of the lowest indexed entry in input
in case it's split across multiple vectors
(as for distributed computation)
Keep in mind that qubits are big-endian to match kron product standards.
|abc>
means q0=a
, q1=b
, q2=c
Examples
use qip::state_ops::from_reals; use qip::measurement_ops::measure_prob; // Make the state |10>, index 0 is always |1> and index 1 is always |0> let input = from_reals(&[0.0, 0.0, 1.0, 0.0]); let p = measure_prob(2, 0, &[0], &input, None, false); assert_eq!(p, 0.0); let p = measure_prob(2, 1, &[0], &input, None, false); assert_eq!(p, 1.0); let p = measure_prob(2, 1, &[0, 1], &input, None, false); assert_eq!(p, 1.0); let p = measure_prob(2, 2, &[1, 0], &input, None, false); assert_eq!(p, 1.0);