qml.MottonenStatePreparation¶
- MottonenStatePreparation = <Subroutine: MottonenStatePreparation>[source]¶
Prepares an arbitrary state on the given wires using a decomposition into gates developed by Möttönen et al. (2004).
The state is prepared via a sequence of uniformly controlled rotations. A uniformly controlled rotation on a target qubit is composed from all possible controlled rotations on the qubit and can be used to address individual elements of the state vector.
In the work of Möttönen et al., inverse state preparation is executed by first equalizing the phases of the state vector via uniformly controlled Z rotations, and then rotating the now real state vector into the direction of the state \(|0\rangle\) via uniformly controlled Y rotations.
This code is adapted from code written by Carsten Blank for PennyLane-Qiskit.
Warning
Due to non-trivial classical processing of the state vector, this template is not always fully differentiable.
- Parameters:
state_vector (tensor_like) – Input array of shape
(2^n,), wherenis the number of wires the state preparation acts on. The input array must be normalized.wires (Iterable) – wires that the template acts on
Example
MottonenStatePreparationcreates any arbitrary state on the given wires depending on the input state vector.dev = qml.device('default.qubit', wires=3) @qml.qnode(dev) def circuit(state): qml.MottonenStatePreparation(state_vector=state, wires=range(3)) return qml.state() state = np.array([1, 2j, 3, 4j, 5, 6j, 7, 8j]) state = state / np.linalg.norm(state) print(qml.draw(circuit, level="device", max_length=80)(state))
0: ──RY(2.35)─╭●───────────╭●──────────────╭●────────────────────────╭● 1: ──RY(2.09)─╰X──RY(0.21)─╰X─╭●───────────│────────────╭●───────────│─ 2: ──RY(1.88)─────────────────╰X──RY(0.10)─╰X──RY(0.08)─╰X──RY(0.15)─╰X ──╭●────────╭●────╭●────╭●─╭GlobalPhase(-0.79)─┤ ╭State ──╰X────────╰X─╭●─│──╭●─│──├GlobalPhase(-0.79)─┤ ├State ───RZ(1.57)────╰X─╰X─╰X─╰X─╰GlobalPhase(-0.79)─┤ ╰State
The state preparation can be checked by running:
>>> print(np.allclose(state, circuit(state))) True