Static MPFs (qiskit_addon_mpf.static)

Static MPFs.

Linear system of equations utilities

class LSE(A, b)[source]

A namedtuple representing a linear system of equations.

\[A x = b\]

Create new instance of LSE(A, b)

Parameters:
A: ndarray

The left hand side of the LSE.

b: ndarray

The right hand side of the LSE.

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

solve()[source]

Return the solution to this LSE: \(x=A^{-1}b\).

Returns:

The solution to this LSE.

Raises:

ValueError – if this LSE is parameterized with unassigned values.

Return type:

ndarray

property x: Variable

Returns the $x$ Variable.

setup_lse(trotter_steps, *, order=1, symmetric=False)[source]

Return the linear system of equations for computing the static MPF coefficients.

This function constructs the following linear system of equations:

\[A x = b,\]

with

\[\begin{split}A_{0,j} &= 1 \\ A_{i>0,j} &= k_{j}^{-(\chi + s(i-1))} \\ b_0 &= 1 \\ b_{i>0} &= 0\end{split}\]

where $\chi$ is the order, $s$ is $2$ if symmetric is True and $1$ oterhwise, $k_{j}$ are the trotter_steps, and $x$ are the variables to solve for. The indices $i$ and $j$ start at $0$.

Here is an example:

>>> from qiskit_addon_mpf.static import setup_lse
>>> lse = setup_lse([1,2,3], order=2, symmetric=True)
>>> print(lse.A)
[[1.         1.         1.        ]
 [1.         0.25       0.11111111]
 [1.         0.0625     0.01234568]]
>>> print(lse.b)
[1. 0. 0.]
Parameters:
  • trotter_steps (list[int] | Parameter) – the sequence of trotter steps from which to build $A$. Rather than a list of integers, this may also be a Parameter instance of the desired size. In this case, the constructed LSE is parameterized whose values must be assigned before it can be solved.

  • order (int) – the order of the individual product formulas making up the MPF.

  • symmetric (bool) – whether the individual product formulas making up the MPF are symmetric. For example, the Lie-Trotter formula is not symmetric, while Suzuki-Trotter is.

Returns:

An LSE.

Return type:

LSE

Exact static MPF coefficients

setup_exact_model(lse)[source]

Construct a cvxpy.Problem for finding exact static MPF coefficients.

Note

The coefficients found via this optimization problem will be identical to the analytical ones obtained from the LSE.solve() method. This additional interface exists to highlight the parallel to the setup_approximate_model() interface. It also serves educational purposes for how-to approach optimization problems targeting MPF coefficients.

The optimization problem constructed by this class is defined as follows:

  • the cost function minimizes the L1-norm (norm1) of the variables (LSE.x)

  • the constraints correspond to each equation of the LSE:

    \[\sum_j A_{ij} x_j = b_i\]

Here is an example:

>>> from qiskit_addon_mpf.static import setup_lse, setup_exact_model
>>> lse = setup_lse([1,2,3], order=2, symmetric=True)
>>> problem, coeffs = setup_exact_model(lse)
>>> print(problem)
minimize norm1(x)
subject to Sum([1. 1. 1.] @ x, None, False) == 1.0
           Sum([1. 0.25   0.11111111] @ x, None, False) == 0.0
           Sum([1. 0.0625 0.01234568] @ x, None, False) == 0.0

You can then solve the problem and extract the expansion coefficients like so:

>>> final_cost = problem.solve()
>>> print(coeffs.value)  
[ 0.04166667 -1.06666667  2.025     ]
Parameters:

lse (LSE) – the linear system of equations from which to build the model.

Returns:

The optimization problem and coefficients variable.

Return type:

tuple[Problem, Variable]

References

[1]: A. Carrera Vazquez et al., Quantum 7, 1067 (2023).

https://quantum-journal.org/papers/q-2023-07-25-1067/

Approximate static MPF coefficients

setup_approximate_model(lse, *, max_l1_norm=10.0)[source]

Construct a cvxpy.Problem for finding approximate static MPF coefficients.

The optimization problem constructed by this class is defined as follows:

  • the cost function minimizes the sum of squares (sum_squares()) of the distances to an exact solution for all equations of the LSE:

    \[\sum_i \left( \sum_j A_{ij} x_j - b_i \right)^2\]
  • two constraints are set:

    1. the variables must sum to 1: \(\sum_i x_i == 1\)

    2. the L1-norm (norm1) of the variables is bounded by max_l1_norm

Here is an example:

>>> from qiskit_addon_mpf.static import setup_lse, setup_approximate_model
>>> lse = setup_lse([1,2,3], order=2, symmetric=True)
>>> problem, coeffs = setup_approximate_model(lse, max_l1_norm=3.0)
>>> print(problem)
minimize quad_over_lin(Vstack([1. 1.     1.]         @ x + -1.0,
                              [1. 0.25   0.11111111] @ x + -0.0,
                              [1. 0.0625 0.01234568] @ x + -0.0), 1.0)
subject to Sum(x, None, False) == 1.0
           norm1(x) <= 3.0

You can then solve the problem and extract the expansion coefficients like so:

>>> final_cost = problem.solve()
>>> print(coeffs.value)  
[ 0.03513467 -1.          1.96486533]
Parameters:
  • lse (LSE) – the linear system of equations from which to build the model.

  • max_l1_norm (float) – the upper limit to use for the constrain of the L1-norm of the variables.

Returns:

The optimization problem and coefficients variable.

Return type:

tuple[Problem, Variable]

References

[1]: S. Zhuk et al., arXiv:2306.12569 (2023).

https://arxiv.org/abs/2306.12569