Skip to content

workbench_algorithms.experimental.subroutines.state_preparation

Subpackage for experimental state prep qubricks.

AliasSampling

AliasSampling(
    qrom: QROM,
    usp: UniformStatePreparation,
    lambda_val=None,
    **kwargs,
)

Bases: Qubrick

Qubrick for implementing alias sampling.

Parameters:

Name Type Description Default
qrom QROM

Data lookup instance.

required
usp UniformStatePreparation

Uniform state preparation instance.

required
lambda_val int

SEL-SWAP tunable parameter for QROM, default to None where optimal lambda (based on Toffoli counts) is calculated

None
**kwargs dict[str, Any]

Other arguments to pass to the init.

{}

compute

compute(
    psi: Qubits,
    data: StatePrepDataInterface,
    ctrl: Qubits | int = 0,
    *,
    usp_rotator: Qubits | None = None,
    coin_toss_reg: Qubits | None = None,
)

State preparation by alias sampling.

Note

Uses the circuit in Fig. 11 of arXiv:1805.03662 <https://arxiv.org/abs/1805.03662>_.

Parameters:

Name Type Description Default
psi Qubits

Register to prepare coefficients onto.

required
data StatePrepDataInterface

a data storage interface that hold all the classical precomputation numbers

required
ctrl Qubits | int

Control register.

0
usp_rotator Qubits | None

Qubit to rotate as part of USP. Needs to be supplied if this Qubrick is used with a coherent uncomputation (such as in LCU), but will be allocated on the fly if not supplied.

None
coin_toss_reg Qubits | None

Qubits register used to load the coin toss state (uniform state) in for the alias sampling protocol. Needs to be supplied if this Qubrick is used with a coherent uncomputation (such as in LCU), but will be allocated on the fly if not supplied.

None

ArbitraryStatePrep

ArbitraryStatePrep(
    amplitude_prep: AmplitudePreparation,
    phase_prep: PhasePreparation | None = None,
    **kwargs,
)

Bases: Qubrick

Qubrick for preparing states with arbitrary coefficients.

The strategy used is straightforward: first we prepare the amplitudes for the state such that the probabilities for each basis state are correct, then we prepare the phases to get the full state.

Parameters:

Name Type Description Default
amplitude_prep AmplitudePreparation

Qubrick to prepare the amplitudes for the state.

required
phase_prep PhasePreparation | None

Qubrick to prepare the phases given the amplitudes have already been prepared.

None
kwargs dict[str, Any]

Other key word arguments to pass to the constructor.

{}

compute

compute(
    psi: Qubits,
    data: StatePrepDataInterface,
    ctrl: Qubits | int = 0,
)

Compute the arbitrary state prep.

Note

This Qubrick makes no assumptions about how the amplitudes and phases are prepared and so all data processing is delegated to those Qubricks.

Parameters:

Name Type Description Default
psi Qubits

Register to prepare the state on.

required
data StatePrepDataInterface

Dataclass encoding the specification of the state.

required
ctrl Qubits | int

Register to control the state preparation.

0

FlattenedRotArray

FlattenedRotArray(mplxr: MultiplexedRotations, **kwargs)

Bases: Qubrick

Implements a state sub-preparation using a single set of multiplexed rotations.

Note
  • This only works with PHASE ops, so can only be used for a phase fixup, and can't be used with the Gray code multiplexor, which relies on the structure of RZ gates to work.
  • There is no global phase correction to do with this Qubrick.

Parameters:

Name Type Description Default
mplxr MultiplexedRotations

The Qubrick that will implement the individual multiplexed rotations

required
kwargs dict[str, Any]

Other key word arguments to pass to the constructor.

{}

mplxr property

mplxr: MultiplexedRotations

Getter for the multiplexor Qubrick.

compute

compute(
    psi: Qubits,
    data: StatePrepDataInterface,
    ctrl: Qubits | int = 0,
)

Compute the multiplexor.

Parameters:

Name Type Description Default
psi Qubits

The qubits to apply the rotations onto.

required
data StatePrepDataInterface

A dataclass encoding the rotation data

required
ctrl Qubits | int

Qubits to control the operation on.

0

MultiplexedRotationData dataclass

MultiplexedRotationData(
    opcode: str,
    angles: Iterable[float],
    epsilon: float,
    bits_of_precision: int | None = None,
)

Data class for handling data for multiplexed rotations.

Parameters:

Name Type Description Default
opcode str

Encodes the type of rotation op to be applied, one of SupportedOps.

required
angles Iterable[float]

The list of rotation angles to be applied.

required
epsilon float

The accuracy that the multiplexed rotations are to be applied to.

required
bits_of_precision int | None

For QROM-based multiplexors, the number of bits of precision to be used in the rotations.

None

ProgrammableRotArray

ProgrammableRotArray(
    op,
    mplxr: MultiplexedRotations,
    fix_global_phase: bool = False,
    **kwargs,
)

Bases: Qubrick

Implements a state sub-preparation using a cascade of uniformly controlled rotations.

Essentially, it is a data storage "terminology" coined by this microsoft paper (see appendix VII, section B, subsection 1) where we need a 2D array of angles (each row of size 1, 2, 4, 8, ...), similar to the multiplexed Givens rotation.

Parameters:

Name Type Description Default
op SupportedOps

Encodes the type of rotation op to be applied, one of SupportedOps.

required
mplxr MultiplexedRotations

The Qubrick that will implement the individual multiplexed rotations

required
fix_global_phase bool

Whether to fix up the global phase (for statevector validation) or prepare the state up to global phase. This correction is always applied when the Qubrick is controlled.

False
kwargs dict[str, Any]

Other key word arguments to pass to the constructor.

{}

op property

op: SupportedOps

Getter for the op in the programmable rot array.

mplxr property

mplxr: MultiplexedRotations

Getter for the multiplexor qubrick.

fix_global_phase property

fix_global_phase: bool

Getter for the fix global phase attribute.

compute

compute(
    psi: Qubits,
    data: StatePrepDataInterface,
    ctrl: Qubits | int = 0,
)

Compute the rotation array.

ProgrammableRotArrayData dataclass

ProgrammableRotArrayData(
    opcode: str,
    coefficients: Iterable[float],
    epsilon: float,
    _bits_of_precision: int | None = None,
)

Data class for handling data for multiplexed rotations.

Parameters:

Name Type Description Default
opcode str

Encodes the type of rotation op to be applied, one of SupportedOps.

required
coefficients Iterable[float]

The coefficients of the state to be loaded.

required
epsilon float

The accuracy that the multiplexed rotations are to be applied to.

required
_bits_of_precision int | None

Override the default bits of precision argument with a custom value. NOTE: this may result in loss of fidelity if the value is not chosen carefully - users are recommended to leave this unset unless they know what they are doing.

None

angles cached property

angles: list[float]

Get the angles corresponding to the particular set of rotations to be applied.

bits_of_precision cached property

bits_of_precision: int

Get the number of bits of precision for QROM-based multiplexors.

is_positive_real

is_positive_real(coeffs: Iterable[float | complex]) -> bool

Checks whether the coeffs are all positive real.