qiu_quantum_computing.state_preparation
¶
Circuits preparing a quantum state from the all-zero state.
Functions:
-
state_preparation_circuit–Return a circuit preparing the state from the all-zero state.
-
decomposed_state_preparation–Return a circuit of elementary gates preparing the state from the all-zero state.
-
state_preparation_unitary–Return a dense unitary whose first column is the state.
state_preparation_circuit
¶
state_preparation_circuit(state: Statevector | ArrayLike, *, method: SynthesisMethod = GATE, inverse: bool = False) -> QuantumCircuit
Return a circuit preparing the state from the all-zero state.
The circuit implements a unitary U with U|0...0> = |state> exactly, including
the global phase. Its inverse, with inverse=True, maps the state back to the
all-zero state.
Parameters:
-
state(Statevector | ArrayLike) –The normalized state to prepare.
-
method(SynthesisMethod, default:GATE) –How the preparation is represented in the circuit: -
GATE(default): a single QiskitStatePreparationgate, synthesized by Qiskit when transpiling. Note that Qiskit's synthesis prepares wrong states for some inputs (qiskit 2.2 to 2.5), seedecomposed_state_preparation. -DECOMPOSED: elementaryry,rzandcxgates, synthesized bydecomposed_state_preparation. -DENSE: a single unitary gate of the matrix ofstate_preparation_unitary. -
inverse(bool, default:False) –If True, return the circuit mapping the state to the all-zero state.
Returns:
-
QuantumCircuit–The state preparation circuit.
Source code in packages/qiu-quantum-computing/src/qiu_quantum_computing/state_preparation.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
decomposed_state_preparation
¶
decomposed_state_preparation(state: Statevector | ArrayLike) -> QuantumCircuit
Return a circuit of elementary gates preparing the state from the all-zero state.
The synthesis of Möttönen et al., "Transformation of quantum states using
uniformly controlled rotations" (2005), first sets the magnitudes of the
amplitudes with uniformly controlled ry rotations, from the most significant
qubit down, and then their phases with uniformly controlled rz rotations and
the global phase of the circuit. It uses at most 2**(n+1) - 4 CNOT gates for
n qubits, and skips the phase stage for real non-negative states.
All angles are computed with arctan2 and sums, without eigendecompositions,
unlike Qiskit's StatePreparation, whose isometry synthesis prepares wrong
states when two of its intermediate single-qubit gates are close but not equal.
Parameters:
-
state(Statevector | ArrayLike) –The normalized state to prepare.
Returns:
-
QuantumCircuit–The circuit of
ry,rzandcxgates.
Source code in packages/qiu-quantum-computing/src/qiu_quantum_computing/state_preparation.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
state_preparation_unitary
¶
state_preparation_unitary(state: Statevector | ArrayLike) -> Operator
Return a dense unitary whose first column is the state.
The unitary is -e^(i theta) H, where H is the Householder reflection swapping
|0...0> and -e^(-i theta)|state>, with theta the phase of the first
amplitude. It is exact and numerically stable, and takes O(4**n) memory.
Parameters:
-
state(Statevector | ArrayLike) –The normalized state to prepare.
Returns:
-
Operator–The unitary operator
UwithU|0...0> = |state>.
Source code in packages/qiu-quantum-computing/src/qiu_quantum_computing/state_preparation.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |