Skip to content

Commit

Permalink
docs: fix notebooks after renames
Browse files Browse the repository at this point in the history
  • Loading branch information
mrossinek committed Nov 15, 2024
1 parent f61b9d4 commit 87c2b9c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions docs/how_tos/choose_trotter_steps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"source": [
"### Preparing our LSE\n",
"\n",
"In a first step, we prepare the LSE, $Ax=b$, leveraging a feature of the [setup_lse](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.static.setup_lse.html) function that allows us to use a [cvxpy.Parameter](https://www.cvxpy.org/api_reference/cvxpy.expressions.html#parameter) object for our $k_j$ values."
"In a first step, we prepare the LSE, $Ax=b$, leveraging a feature of the [setup_static_lse](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.static.setup_static_lse.html) function that allows us to use a [cvxpy.Parameter](https://www.cvxpy.org/api_reference/cvxpy.expressions.html#parameter) object for our $k_j$ values."
]
},
{
Expand Down Expand Up @@ -133,10 +133,10 @@
"outputs": [],
"source": [
"import cvxpy as cp\n",
"from qiskit_addon_mpf.static import setup_lse\n",
"from qiskit_addon_mpf.static import setup_static_lse\n",
"\n",
"ks = cp.Parameter(3, integer=True)\n",
"lse = setup_lse(ks, order=order, symmetric=symmetric)"
"lse = setup_static_lse(ks, order=order, symmetric=symmetric)"
]
},
{
Expand Down
14 changes: 7 additions & 7 deletions docs/how_tos/using_approximate_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"source": [
"# How to use the approximate model\n",
"\n",
"You have already seen a first example of the [setup_approximate_model](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.static.setup_approximate_model.html) function in the [Getting started](https://qiskit.github.io/qiskit-addon-mpf/tutorials/01_getting_started.html) tutorial.\n",
"You have already seen a first example of the [setup_sum_of_squares_problem](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.costs.setup_sum_of_squares_problem.html) function in the [Getting started](https://qiskit.github.io/qiskit-addon-mpf/tutorials/01_getting_started.html) tutorial.\n",
"In this guide, we are going to revisit that function in more detail."
]
},
Expand Down Expand Up @@ -92,7 +92,7 @@
"source": [
"## Choosing $k_j$\n",
"\n",
"In this guide, we are going to focus on the tweaks that we can apply to the [cvxpy.Problem](https://www.cvxpy.org/api_reference/cvxpy.problems.html#cvxpy.Problem) and its solver that are returned by the [setup_approximate_model](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.static.setup_approximate_model.html). Therefore, we are not concerned with choosing any specific $k_j$ values and can simply reuse the ones from the [Getting started](https://qiskit.github.io/qiskit-addon-mpf/tutorials/01_getting_started.html) tutorial."
"In this guide, we are going to focus on the tweaks that we can apply to the [cvxpy.Problem](https://www.cvxpy.org/api_reference/cvxpy.problems.html#cvxpy.Problem) and its solver that are returned by the [setup_sum_of_squares_problem](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.costs.setup_sum_of_squares_problem.html). Therefore, we are not concerned with choosing any specific $k_j$ values and can simply reuse the ones from the [Getting started](https://qiskit.github.io/qiskit-addon-mpf/tutorials/01_getting_started.html) tutorial."
]
},
{
Expand Down Expand Up @@ -135,9 +135,9 @@
},
"outputs": [],
"source": [
"from qiskit_addon_mpf.static import setup_lse\n",
"from qiskit_addon_mpf.static import setup_static_lse\n",
"\n",
"lse = setup_lse(trotter_steps, order=2, symmetric=True)"
"lse = setup_static_lse(trotter_steps, order=2, symmetric=True)"
]
},
{
Expand Down Expand Up @@ -222,7 +222,7 @@
"\n",
"Now, we will construct the approximate model.\n",
"The idea of using approximate solutions $\\tilde{x}$ in order to ensure a smaller L1-norm was proposed by [Zhuk et al., 2023].\n",
"The model is already explained in detail in the API documentation of [setup_approximate_model](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.static.setup_approximate_model.html) so we refrain from repeating it here.\n",
"The model is already explained in detail in the API documentation of [setup_sum_of_squares_problem](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.costs.setup_sum_of_squares_problem.html) so we refrain from repeating it here.\n",
"Suffice to say, that the model consists of two constraints which ensure that the coefficients, $\\tilde{x}$, sum to $1$ and it enforces their L1-norm to be smaller than the user-provided `max_l1_norm` value.\n",
"The optimization objective is to minimize the deviation of $A\\tilde{x}=b$.\n",
"\n",
Expand Down Expand Up @@ -255,9 +255,9 @@
}
],
"source": [
"from qiskit_addon_mpf.static import setup_approximate_model\n",
"from qiskit_addon_mpf.costs import setup_sum_of_squares_problem\n",
"\n",
"model, coeff_var = setup_approximate_model(lse, max_l1_norm=3)\n",
"model, coeff_var = setup_sum_of_squares_problem(lse, max_l1_norm=3)\n",
"print(model)"
]
},
Expand Down
18 changes: 9 additions & 9 deletions docs/tutorials/01_getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
"\n",
"Determining the static MPF coefficients for a given set of $k_j$ values amounts to solving a linear system of equations:\n",
"$Ax=b$, where $x$ are our coefficients of interest, $A$ is a matrix depending on $k_j$ and the type of PF we use ($S$), and $b$ is a vector of constraints.\n",
"For brevity, we are not going to go into more detail here and instead refer you to the documentation of [LSE](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.static.LSE.html).\n",
"For brevity, we are not going to go into more detail here and instead refer you to the documentation of [LSE](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.costs.LSE.html).\n",
"\n",
"We can find a solution for $x$ analytically as $x = A^{-1}b$, see e.g. [Carrera Vazquez et al., 2023] or [Zhuk et al., 2023].\n",
"However, this exact solution can be _\"ill-conditioned\"_ resulting in very large L1-norms of our coefficients, $x$, which can lead to bad performance of the MPF.\n",
Expand Down Expand Up @@ -369,9 +369,9 @@
}
],
"source": [
"from qiskit_addon_mpf.static import setup_lse\n",
"from qiskit_addon_mpf.static import setup_static_lse\n",
"\n",
"lse = setup_lse(trotter_steps, order=2, symmetric=True)\n",
"lse = setup_static_lse(trotter_steps, order=2, symmetric=True)\n",
"print(lse)"
]
},
Expand Down Expand Up @@ -433,7 +433,7 @@
"source": [
"#### Optimizing for $x$ using an exact model\n",
"\n",
"Alternatively to computing $x=A^{-1}b$, you can also use [setup_exact_model](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.static.setup_exact_model.html) to construct a [cvxpy.Problem](https://www.cvxpy.org/api_reference/cvxpy.problems.html#cvxpy.Problem) instance which uses the LSE as constraints and whose optimal solution will yield $x$.\n",
"Alternatively to computing $x=A^{-1}b$, you can also use [setup_exact_problem](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.costs.setup_exact_problem.html) to construct a [cvxpy.Problem](https://www.cvxpy.org/api_reference/cvxpy.problems.html#cvxpy.Problem) instance which uses the LSE as constraints and whose optimal solution will yield $x$.\n",
"\n",
"In the next section, it will be clear why this interface exists."
]
Expand All @@ -459,9 +459,9 @@
}
],
"source": [
"from qiskit_addon_mpf.static import setup_exact_model\n",
"from qiskit_addon_mpf.costs import setup_exact_problem\n",
"\n",
"model_exact, coeffs_exact = setup_exact_model(lse)\n",
"model_exact, coeffs_exact = setup_exact_problem(lse)\n",
"model_exact.solve()\n",
"print(coeffs_exact.value)"
]
Expand Down Expand Up @@ -524,7 +524,7 @@
"It may happen that the L1 norm for the chosen set of $k_j$ values is deemed too high.\n",
"If that is the case and you cannot choose a different set of $k_j$ values, you can use an approximate solution to the LSE instead of an exact one.\n",
"\n",
"To do so, simply use [setup_approximate_model](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.static.setup_approximate_model.html) to construct a different [cvxpy.Problem](https://www.cvxpy.org/api_reference/cvxpy.problems.html#cvxpy.Problem) instance which constrains the L1-norm to a chosen threshold while minimizing the difference of $Ax$ and $b$."
"To do so, simply use [setup_sum_of_squares_problem](https://qiskit.github.io/qiskit-addon-mpf/stubs/qiskit_addon_mpf.costs.setup_sum_of_squares_problem.html) to construct a different [cvxpy.Problem](https://www.cvxpy.org/api_reference/cvxpy.problems.html#cvxpy.Problem) instance which constrains the L1-norm to a chosen threshold while minimizing the difference of $Ax$ and $b$."
]
},
{
Expand All @@ -550,9 +550,9 @@
}
],
"source": [
"from qiskit_addon_mpf.static import setup_approximate_model\n",
"from qiskit_addon_mpf.costs import setup_sum_of_squares_problem\n",
"\n",
"model_approx, coeffs_approx = setup_approximate_model(lse, max_l1_norm=3.0)\n",
"model_approx, coeffs_approx = setup_sum_of_squares_problem(lse, max_l1_norm=3.0)\n",
"model_approx.solve()\n",
"print(coeffs_approx.value)\n",
"print(np.linalg.norm(coeffs_approx.value, ord=1))"
Expand Down

0 comments on commit 87c2b9c

Please sign in to comment.