qiu_quantum_computing.phase_propagator.qubit_encoding
¶
The encoding of the integer indices of an axis in the basis states of qubits.
An axis of 2**n samples is represented by n qubits, with the sample at array
position k in the basis state |k>, k = sum_i 2^i x_i in little-endian order.
The basis state thus encodes the integer index axis.index[k], which depends on the
index ordering of the axis:
NATURAL: the unsigned integersum_i 2^i x_i.FFT: the two's complement integer-2^(n-1) x_(n-1) + sum_(i<n-1) 2^i x_i.CENTERED: the two's complement integer of the bits with the most significant one flipped,-2^(n-1) (1 - x_(n-1)) + sum_(i<n-1) 2^i x_i.
Functions:
-
num_qubits_of–Return the number of qubits representing the axis.
-
is_msb_flipped–Whether the bit weights refer to the flipped most significant bit.
-
bit_weights–Return the weights
w_iof the bits in the encoded integer indices.
num_qubits_of
¶
num_qubits_of(axis: IntegerAxis) -> int
Return the number of qubits representing the axis.
Parameters:
-
axis(IntegerAxis) –An axis of
2**nsamples, withn >= 1.
Returns:
-
int–The number of qubits
n.
Raises:
-
ValueError–If the axis does not have
2**nsamples withn >= 1.
Source code in packages/qiu-quantum-computing/src/qiu_quantum_computing/phase_propagator/qubit_encoding.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
is_msb_flipped
¶
is_msb_flipped(ordering: IndexOrdering) -> bool
Whether the bit weights refer to the flipped most significant bit.
For such orderings, circuits built from the bit weights must flip the most significant qubit before and after applying them.
Returns:
-
bool–True for the
CENTEREDordering, False otherwise.
Source code in packages/qiu-quantum-computing/src/qiu_quantum_computing/phase_propagator/qubit_encoding.py
38 39 40 41 42 43 44 45 46 47 | |
bit_weights
¶
bit_weights(num_qubits: int, ordering: IndexOrdering) -> list[int]
Return the weights w_i of the bits in the encoded integer indices.
The integer encoded by the basis state |x_(n-1) ... x_0> is sum_i w_i x'_i,
where x'_i = x_i, except for the most significant bit, which is flipped for
the orderings of is_msb_flipped.
Parameters:
-
num_qubits(int) –The number of qubits
n. -
ordering(IndexOrdering) –The index ordering of the axis.
Returns:
Source code in packages/qiu-quantum-computing/src/qiu_quantum_computing/phase_propagator/qubit_encoding.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |