state_preparation
state_preparation ¶
AliasSampling ¶
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. |
{}
|
compute_num_states
staticmethod
¶
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 ¶
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
|
ctrl
|
Qubits, SymbolicQubits, or int
|
Control register. Defaults to no control, i.e. |
0
|
**kwargs
|
dict[str, Any]
|
Other arguments to pass to the compute. |
{}
|
LKSMultiplexor ¶
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. |
{}
|
compute ¶
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
|
**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:
LKSStatePrep ¶
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. |
{}
|
compute ¶
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 |
ArbitraryStatePrep ¶
Bases: Qubrick
State preparation based on the routine in "Transformation of quantum states using uniformly controlled rotations" (arXiv:quant-ph/0407010 ⧉).
Realizes:
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 |
None
|
amps
|
list or None
|
List of amplitudes to load into state. |
required |
**kwargs
|
dict[str, Any]
|
Other arguments to pass to the init. |
{}
|
PrepareNaive ¶
Bases: Qubrick
State preparation based on the routine in "Transformation of quantum states using uniformly controlled rotations" (arXiv:quant-ph/0407010 ⧉).
Realizes:
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 |
None
|
coeffs
|
list or None
|
List of coefficients to load into state. |
required |
**kwargs
|
dict[str, Any]
|
Other arguments to pass to the init. |
{}
|
compute ¶
PrepareClockState ¶
Bases: Qubrick
Prepares a clock state.
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 ¶
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 ¶
Bases: Qubrick
Prepares a W state.
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. |
{}
|
PrepareWStatePowerTwo ¶
Bases: Qubrick
Prepares a W state for power of two target size.
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.
RealUSP ¶
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
|
succ_reg
|
Qubits
|
Qubit to herald success. Defaults to |
None
|
error_param
|
float
|
Parameter determining the accuracy of truncated rotation
angles. If |
None
|
ctrl
|
Qubits or int
|
Register to control the USP on. Defaults to |
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 ¶
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 ¶
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
|
ctrl
|
Qubits or int
|
Register to control the USP on. Defaults to |
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 ¶
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 ¶
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 |
0
|
**kwargs
|
dict[str, Any]
|
Other arguments to pass to the compute. |
{}
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the register passed in is too small. |