uniqc.algorithmics.state_preparation.rotation_prepare module#

Arbitrary state preparation via rotation method.

Uses the Shende–Bullock–Markov (SBM) decomposition: disentangles qubits one at a time, then reverses the gate sequence.

uniqc.algorithmics.state_preparation.rotation_prepare.rotation_prepare(circuit, target_vector, qubits=None)[source]#

Prepare an arbitrary quantum state from a complex amplitude vector.

Uses the Shende–Bullock–Markov state-preparation algorithm. The method works by computing the circuit that would disentangle the target state back to |00...0>, collecting the gates, then applying them in reverse order.

Gate count: O(2^n) for n qubits.

The vector is automatically normalised.

Parameters:
  • circuit (Circuit) – Quantum circuit to operate on (mutated in-place).

  • target_vector (ndarray) – 1-D complex array of length 2**n specifying the target state amplitudes.

  • qubits (List[int] | None) – Qubit indices to use. None → first n qubits.

Raises:
  • ValueErrortarget_vector length is not a power of 2.

  • ValueErrortarget_vector is the zero vector.

Return type:

None

Example

>>> import numpy as np
>>> from uniqc.circuit_builder import Circuit
>>> from uniqc.algorithmics.state_preparation import rotation_prepare
>>> target = np.array([1, 0, 0, 1]) / np.sqrt(2)  # Bell state
>>> c = Circuit()
>>> rotation_prepare(c, target)