Skip to content

Piecewise Linear Amplitude Loading

The piecewise linear amplitude loading function performs the following operation:

\(|d\rangle |0\rangle \rightarrow \sqrt{1-\tilde{f}(d)}|d\rangle |0\rangle + \sqrt{\tilde{f}(d)}|d\rangle |1\rangle\)

for any input, \(|d\rangle\), piecewise linear function \(f(d)\). Where \(\tilde{f}\) is a normalized and rescaled function of the given \(f(d)\):

\(\tilde{f}(d) = 2c \cdot \frac{f(\phi(d)) - f_{min}}{f_{max} - f_{min}} - c + 0.5\)

when:

\(\phi(d) = x_{min} + \frac{x_{max} - x_{min}}{2^{n} - 1}d\)

\(c\) is the given rescaling factor. \(f_{min}\), \(f_{max}\) are the minimal and maximal values of the function in the given domain, and \(x_{min}\), \(x_{max}\) are the boundaries of the domain.

The linear functions and the transitions between them are defined by the affine_maps and breakpoints fields, respectively, which are expected to be ordered. Each linear function is defined by an AffineMap object, that has two attributes - offset and slope. For example, AffineMap(offset=a, slope=b) represents f(x) = a + bx. The function is approximated using piecewise linear rotation amplitude loading, and expected to work for small enough rescaling factors, such that Taylor approximations work in leading order.

The function is intended to serve as a basis for computations of the expectation value of \(f(x)\), where the probability is set by the initial distribution of \(d\) as in [1]. The function is automatically scaled to be approximated by piecewise linear rotation amplitude loading. To do the inverse transformation, use the "compute_expectation_value" method of PiecewiseLinearAmplitudeLoading params, as in the SDK example below.

Syntax

Function: PiecewiseLinearAmplitudeLoading

Parameters:

  • num_qubits: PositiveInt
  • breakpoints: List[float]
  • affine_maps: List[AffineMap]
  • rescaling_factor: float

Example 1 - generation

{
  "functions": [
    {
      "name": "main",
      "body": [
          {
              "function": "PiecewiseLinearAmplitudeLoading",
              "function_params": {
                  "num_qubits": 3,
                  "breakpoints": [0.5, 3.14, 5.0],
                  "affine_maps": [
                    {"offset": 0, "slope": 0},
                    {"offset": -3.14, "slope": 1.6}
                  ],
                  "rescaling_factor": 0.001
              }
          }
      ]
    }
  ]
}
from classiq.builtin_functions import PiecewiseLinearAmplitudeLoading
from classiq import Model, synthesize

model = Model()
amplitude_loading_params = PiecewiseLinearAmplitudeLoading(
    num_qubits=3,
    breakpoints=[0.5, 3.14, 5.0],
    affine_maps=[{"offset": 0, "slope": 0}, {"offset": -3.14, "slope": 1.6}],
    rescaling_factor=0.001,
)
model.PiecewiseLinearAmplitudeLoading(amplitude_loading_params)
qprog = synthesize(model.get_model())

Example 2 - computing the expectation value

from classiq.builtin_functions import PiecewiseLinearAmplitudeLoading

amplitude_loading_params = PiecewiseLinearAmplitudeLoading(
    num_qubits=3,
    breakpoints=[0.5, 3.14, 5.0],
    affine_maps=[{"offset": 0, "slope": 0}, {"offset": -3.14, "slope": 1.6}],
    rescaling_factor=0.001,
)
scaled_expectation_value = 0.7  # Probability of 1 after some execution
expectation_value = amplitude_loading_params.compute_expectation_value(
    scaled_expectation_value
)

References

[1]Nikitas Stamatopoulos, Daniel J. Egger, Yue Sun, Christa Zoufal, Raban Iten, Ning Shen, Stefan Woerner, “Option Pricing using Quantum Computers” Jul. 2020, Accessed: Jul. 04, 2023. https://arxiv.org/abs/1905.02666