Skip to content
Construct PsiQDK Algorithms

state_preparation

state_preparation

AliasSampling

AliasSampling(qrom: QROM, usp: UniformStatePreparation, **kwargs)

Bases: Qubrick

Qubrick for implementing alias sampling.

Parameters:

Name Type Description Default
qrom Qubrick

Data lookup instance.

required
usp Qubrick

Uniform state preparation instance.

required
**kwargs dict[str, Any]

Other arguments to pass to the init.

{}

qrom instance-attribute

qrom: Incomplete = qrom

usp instance-attribute

usp: Incomplete = usp

compute_num_states staticmethod

compute_num_states(input_list)

Helper to compute number of states to prepare in alias sampling (works for symbolics & numerics).

Parameters:

Name Type Description Default
input_list list or SymbolicArray

List of coefficients to prepare.

required

Returns:

Type Description
tuple

Number of states to prepare, and value to pad combined list by.

Raises:

Type Description
ValueError

If the inputs are not the correct type for either numerics or symbolics.

compute

compute(prep_reg, input_list, bit_precision, lambda_val=None, ctrl: int = 0, **kwargs) -> None

State preparation by alias sampling.

Note

Uses the circuit in Fig. 11 of "Encoding Electronic Spectra in Quantum Circuits with Linear T Complexity" (arXiv:1805.03662 ⧉).

Parameters:

Name Type Description Default
prep_reg Qubits or SymbolicQubits

Register to prepare coefficients onto.

required
input_list list or SymbolicArray

List of coefficients to prepare.

required
bit_precision int or Parameter

Number of bits to represent each coefficient.

required
lambda_val int or Parameter

Power-of-two knob to trade off between gates and qubits. If None (default), then optimal lambda is calculated.

None
ctrl Qubits, SymbolicQubits, or int

Control register. Defaults to no control, i.e. ctrl=0.

0
**kwargs dict[str, Any]

Other arguments to pass to the compute.

{}

LKSMultiplexor

LKSMultiplexor(qrom, gate, **kwargs)

Bases: Qubrick

Multiplexor using data-lookup oracles.

The construction is detailed in "Trading T gates for dirty qubits in state preparation and unitary synthesis" (arXiv:1812.00954 ⧉). Circuit described in Appendix D.

Parameters:

Name Type Description Default
qrom Qubrick

Data-loader for loading angles to bits_of_precision-bits of precision.

required
gate op

Rotation gate type to use in multiplexed rotations.

required
**kwargs dict[str, Any]

Other arguments to pass to the init.

{}

qrom instance-attribute

qrom: Incomplete = qrom

gate instance-attribute

gate: Incomplete = gate

compute

compute(index_reg, tgt, angles, bits_of_precision, lambda_val=None, **kwargs) -> None

Compute circuit for LKS multiplexor.

Parameters:

Name Type Description Default
index_reg Qubits

Index register.

required
tgt Qubits

Register to apply rotations onto.

required
angles list or None

List of angles to supply to rotations.

required
bits_of_precision int

Bits of precision for rotations.

required
lambda_val int

Power-of-two knob to trade off between gates and qubits. If None (default), then optimal lambda is calculated and the clean decomposition will be used.

None
**kwargs dict[str, Any]

Other arguments to pass to the compute.

{}
Note

We want to apply single-qubit \(\text{RY}\) rotations conditioned on different significant bits. We truncate the exact angle and obtain an integer approximation of it, and so, each angle we apply is \(\frac{2\pi a_k} {2^{k + 1}}\). However, we express \(\text{RY}\) rotations as \(\text{RY}(\theta) = e^{iY \frac{\theta}{2}}\). If you account for this factor of 2 in the denominator, and also convert from radians to degrees \((\frac{180}{\pi})\), you end up using:

\[\text{angle} = \frac{\frac{2\pi a_k}{2^{k + 1}}}{2} \times \frac{180}{\pi} = \frac{180 a_k}{2^{k + 1}}\]

LKSStatePrep

LKSStatePrep(coeffs, mplxr, **kwargs)

Bases: Qubrick

State preparation detailed in "Trading T gates for dirty qubits in state preparation and unitary synthesis" (arXiv:1812.00954 ⧉).

This routine works for real, positive coefficients.

Parameters:

Name Type Description Default
coeffs list or None

List of coefficients to load into state.

required
mplxr Qubrick

Multiplexor to use in state prep.

required
**kwargs dict[str, Any]

Other arguments to pass to the init.

{}

coeffs instance-attribute

coeffs: Incomplete = coeffs

mplxr instance-attribute

mplxr: Incomplete = mplxr

angles instance-attribute

angles: Incomplete

compute

compute(qbits, **mplxr_kwargs) -> None

Compute circuit for LKS state prep.

Parameters:

Name Type Description Default
qbits Qubits

Qubits to prep state on.

required
**mplxr_kwargs dict

Dictionary with keyword arguments to pass to the multiplexor.

{}

Other Parameters:

Name Type Description
bits_of_precision int

Bits of precision for rotations.

lambda_val int

Power-of-two knob to trade off between gates and qubits. If None, then optimal lambda is calculated and the clean decomposition will be used.

ArbitraryStatePrep

ArbitraryStatePrep(amps, multiplexor=None, **kwargs)

Bases: Qubrick

State preparation based on the routine in "Transformation of quantum states using uniformly controlled rotations" (arXiv:quant-ph/0407010 ⧉).

Realizes:

\[ \text{PREP}\ket{0} = \frac{\sum_i a_i}{\sum_i|a_i|^2}\ket{i} \]
Note

This routine prepares the desired state up to a global phase. When checking the validity of this routine, one should check fidelity rather than exact state vector matching. The other consequence is that controlling this routine will lead to (incorrect) relative phases.

Parameters:

Name Type Description Default
multiplexor (Qubrick, None)

Which multiplexing scheme to use in state prep. Defaults to NaiveMultiplexedRotations().

None
amps list or None

List of amplitudes to load into state.

required
**kwargs dict[str, Any]

Other arguments to pass to the init.

{}

multiplexor instance-attribute

multiplexor: Incomplete = multiplexor

amps instance-attribute

amps: Incomplete = amps

complex_amps instance-attribute

complex_amps: Incomplete

set_angles

set_angles(y_angles, z_angles=None) -> None

Set angles if none computed. Z angles defaults to None.

compute

compute(qbits, ctrl: int = 0, **kwargs) -> None

Compute the arbitrary state preparation circuit.

Parameters:

Name Type Description Default
qbits Qubits

Qubits to operate on.

required
ctrl Qubits or int

Register to control the on. Defaults to 0.

0
**kwargs dict[str, Any]

Other arguments to pass to the compute.

{}

PrepareNaive

PrepareNaive(coeffs, multiplexor=None, **kwargs)

Bases: Qubrick

State preparation based on the routine in "Transformation of quantum states using uniformly controlled rotations" (arXiv:quant-ph/0407010 ⧉).

Realizes:

\[\text{PREP}\ket{0} = \frac{\sum_i \sqrt{a_i}}{\sum_i|a_i|}\ket{i}\]
Warning

This function only works for real and positive coefficients.

Parameters:

Name Type Description Default
multiplexor Qubrick

Which multiplexing scheme to use in state prep. Defaults to NaiveMultiplexedRotations().

None
coeffs list or None

List of coefficients to load into state.

required
**kwargs dict[str, Any]

Other arguments to pass to the init.

{}

multiplexor instance-attribute

multiplexor: Incomplete = multiplexor

coeffs instance-attribute

coeffs: Incomplete = coeffs

y_angles instance-attribute

y_angles: Incomplete

set_angles

set_angles(y_angles) -> None

Set angles if none computed.

compute

compute(qbits, ctrl: int = 0, **kwargs) -> None

Compute the state preparation circuit.

Parameters:

Name Type Description Default
qbits Qubits

Qubits to operate on.

required
ctrl (Qubits, int)

A register to control this operation on. Default to 0.

0
**kwargs dict[str, Any]

Other arguments to pass to the compute.

{}

PrepareClockState

PrepareClockState(**kwargs)

Bases: Qubrick

Prepares a clock state.

\[\text{PREP}|0\rangle^{\otimes n} = \sum_{k=0}^n \sqrt{p_k} |1\rangle^{\otimes k} |0\rangle^{\otimes n - k}\]
Example

For \(n = 3\) the output state will be of the form \(\sqrt{p_0}|000\rangle + \sqrt{p_1}|100\rangle + \sqrt{p_2}|110\rangle + \sqrt{p_3}|111\rangle\).

The ket-states should be understood as a unary representation of an integer. For example, \(|1110\rangle\) is 3 in decimal, and \(|1000\rangle\) is 1 in decimal.

Note

The controlled version only ensures \(\text{c-PREP}|+\rangle|0\rangle^{\otimes n} = |0\rangle|0\rangle^{\otimes n}+|1\rangle \text{PREP}|0\rangle^{\otimes n}\). In other words, if the input state is not zero, there is still an action of this Qubrick.

compute

compute(target, probs, ctrl: int = 0) -> None

Prepare the clock state according to given probabilities.

Parameters:

Name Type Description Default
target Qubits

Target qubits.

required
probs list

List of probabilities, such that the output state is of the form \(\sqrt{p_0}|000\rangle + \sqrt{p_1}|100\rangle + \sqrt{p_2}|110\rangle + \sqrt{p_3}|111\rangle\).

required
ctrl (Qubits, int)

Control register. Default to 0.

0

PrepareWState

PrepareWState(khot_prep=None, wpower2_prep=None, **kwargs)

Bases: Qubrick

Prepares a W state.

\[\text{PREP}|0\rangle^{\otimes n} = \sum_{k=1}^n |0\rangle^{\otimes k-1}|1\rangle|0\rangle^{\otimes n - k}\]
Note

The controlled version only ensures \(\text{c-PREP}|+\rangle|0\rangle^{\otimes n} = |0\rangle|0\rangle^{\otimes n} + |1\rangle\text{PREP}|0\rangle^{\otimes n}\). In other words, if the input state is not zero, there is still an action of this Qubrick.

Parameters:

Name Type Description Default
khot_prep Qubrick

Qubrick to implement a Clock state.

None
wpower2_prep Qubrick

Qubrick to prepare a W state over a power-of-two number of amplitudes.

None
**kwargs dict[str, Any]

Other arguments to pass to the init.

{}

k_hot instance-attribute

k_hot: Incomplete = PrepareClockState() if khot_prep is None else khot_prep

wpower_two instance-attribute

wpower_two: Incomplete = PrepareWStatePowerTwo() if wpower2_prep is None else wpower2_prep

compute

compute(target: Qubits, ctrl: Qubits | int = 0)

Prepares a W state.

Parameters:

Name Type Description Default
target Qubits

Target qubits.

required
ctrl (Qubits, int)

Control register. Default to 0.

0

PrepareWStatePowerTwo

PrepareWStatePowerTwo(**kwargs)

Bases: Qubrick

Prepares a W state for power of two target size.

\[\text{PREP}|0\rangle^{\otimes 2^n} =\sum_{k=1}^{2^n} |0\rangle^{\otimes k-1}|1\rangle|0\rangle^{\otimes 2^n - k}\]
Note

The controlled version only ensures \(\text{c-PREP}|+\rangle|0\rangle^{\otimes 2^n} = |0\rangle|0\rangle^{\otimes 2^n} + |1\rangle\text{PREP}|0\rangle^{\otimes 2^n}\). In other words, if the input state is not zero, there is still an action of this Qubrick.

compute

compute(target: Qubits, ctrl: Qubits | int = 0)

Prepares a W state for power-of-two target size.

Parameters:

Name Type Description Default
target Qubits

Target qubits.

required
ctrl (Qubits, int)

Control register. Default to 0.

0

RealUSP

RealUSP(**kwargs)

Bases: Qubrick

Qubrick for performing Uniform State Preparation.

From "Even more efficient quantum computations of chemistry through tensor hypercontraction" (arXiv:2011.03494 ⧉).

Note
  • This is the version based on the instructions (steps 1-7) under Eq. A15 of Appendix A.
  • A circuit diagram showing a similar implementation (but over two target registers) is shown in Fig. (3).

compute

compute(d, target_qreg, rotator=None, succ_reg=None, error_param=None, ctrl: int = 0, **kwargs) -> None

Prepare a uniformly distributed state.

Conceptually, starts by factoring \(d = 2^k L\), although this explicit calculation has been replaced by the num_trailing_zeros and highest_bit functions for better performance. Just applying Hadamard gates creates the desired equal superposition over k of the qubits. For the remaining qubits we need to also perform amplitude amplification to keep only basis states with value < d.

Utilizes one auxiliary qubit, the 'rotator', such that CZ gates perform the required reflections.

This routine uses RY rotations, resulting in only real amplitudes.

If no error_param is provided, the rotations are treated as ideal and the probability of success is 1.0. If an error_param is provided, the probability of success will be <=1.0 and a flag qubit will store the result via a comparator. This qubit can be optionally provided via succ_reg.

Parameters:

Name Type Description Default
d int

The number of nonzero terms required.

required
target_qreg Qubits

The register to operate on.

required
rotator Qubits

Register to perform rotation on. Defaults to None, in which case, it is allocated by the Qubrick.

None
succ_reg Qubits

Qubit to herald success. Defaults to None, in which case, it is allocated by the Qubrick.

None
error_param float

Parameter determining the accuracy of truncated rotation angles. If None (default), angles are exact and no success qubit is output.

None
ctrl Qubits or int

Register to control the USP on. Defaults to 0.

0
**kwargs dict[str, Any]

Other arguments to pass to the compute.

{}

Raises:

Type Description
RuntimeError

If the register passed in is too small.

Note

The effect of setting various default args has not been tested.

USP

USP(**kwargs)

Bases: Qubrick

Qubrick for performing Uniform State Preparation.

From Fig. 12 in "Encoding Electronic Spectra in Quantum Circuits with Linear T Complexity" (arXiv:1805.03662 ⧉).

compute

compute(d, target_qreg, error_param=None, ctrl: int = 0, **kwargs) -> None

Prepare a uniformly distributed state.

Conceptually, starts by factoring \(d = 2^k L\), although this explicit calculation has been replaced by the num_trailing_zeros and highest_bit functions for better performance. Just applying Hadamard gates creates the desired equal superposition over k of the qubits. For the remaining qubits we need to also perform amplitude amplification to keep only basis states with value < d.

Parameters:

Name Type Description Default
d int

Desired number of uniform terms.

required
target_qreg Qubits

The register to operate on.

required
error_param float

Parameter determining the accuracy of truncated rotation angles. If None (default), angles are exact and no success qubit is output.

None
ctrl Qubits or int

Register to control the USP on. Defaults to None.

0
**kwargs dict[str, Any]

Other arguments to pass to the compute.

{}

Raises:

Type Description
ValueError

If the register passed in is too small.

Note

The effect of setting various default args has not been tested. Creates desired state up to global phase.

ZeroAncillaUSP

ZeroAncillaUSP(qc=None, **kwargs)

Bases: Qubrick

Qubrick for performing Uniform State Preparation without auxiliary qubits.

Adapted from "An efficient quantum algorithm for preparation of uniform quantum superposition states" (arXiv:2306.11747 ⧉).

compute

compute(d, target_qreg, ctrl: int = 0, **kwargs) -> None

Prepare a uniformly distributed state.

Utilizes binary decomposition of \(d\), controlled Ry and Hadamard gates to avoid auxiliary qubit usage.

Parameters:

Name Type Description Default
d int

Desired number of uniform terms.

required
target_qreg Qubits

The register to operate on.

required
ctrl Qubits or int

Register to control the USP on. Defaults to None.

0
**kwargs dict[str, Any]

Other arguments to pass to the compute.

{}

Raises:

Type Description
RuntimeError

If the register passed in is too small.