setup_approximate_model¶
- 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 theLSE
:\[\sum_i \left( \sum_j A_{ij} x_j - b_i \right)^2\]two constraints are set:
the variables must sum to 1: \(\sum_i x_i == 1\)
the L1-norm (
norm1
) of the variables is bounded bymax_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:
- Returns:
The optimization problem and coefficients variable.
- Return type:
References
- [1]: S. Zhuk et al., arXiv:2306.12569 (2023).