You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Copilot/copilotimplement objective direction migration (#61)
core objective sense and energy semantics
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: fgfuchs <2428162+fgfuchs@users.noreply.github.com>
To create a custom QAOA ansatz, specify a [problem](qaoa/problems/base_problem.py), a [mixer](qaoa/mixers/base_mixer.py), and an [initial state](qaoa/initialstates/base_initialstate.py). These base classes each have an abstract method `def create_circuit:` that must be implemented. The problem base class additionally requires `def cost:`.
148
+
To create a custom QAOA ansatz, specify a [problem](qaoa/problems/base_problem.py), a [mixer](qaoa/mixers/base_mixer.py), and an [initial state](qaoa/initialstates/base_initialstate.py). These base classes each have an abstract method `def create_circuit:` that must be implemented. A custom problem should define `objective_sense` and `objective_value()`. The phase separator must encode `energy(x)` as above.
123
149
124
150
This library already contains several standard implementations.
Sampling high-dimensional target functions quickly becomes intractable for depth $p>1$. The library therefore **iteratively increases the depth**. At each depth a **local optimization** algorithm (e.g. COBYLA) finds a local minimum, using the following **initial guess**:
179
205
180
-
- At depth $p=1$: parameters $(\gamma, \beta)$ are taken from the minimum of the sampled cost landscape.
206
+
- At depth $p=1$: parameters $(\gamma, \beta)$ are taken from the minimum of the sampled energy landscape.
181
207
- At depth $p>1$: two strategies are available, controlled by the `interpolate` parameter:
182
208
183
209
***Interpolation** (`interpolate=True`, default): uses the [INTERP heuristic](https://arxiv.org/pdf/1812.01041.pdf) to produce a smooth initial guess by interpolating the optimal angles from depth $p-1$. Works well for vanilla QAOA.
184
210
185
-
***Layer-by-layer grid scan** (`interpolate=False`): the best angles from depth $p-1$ are *locked* and a 2-D grid search is performed over the new layer's parameters. Because the grid includes $(γ=0, β=0)$ — which adds an identity layer reproducing the depth-$(p-1)$ result — the initial cost at depth $p$ is guaranteed to be ≤ cost at depth $p-1$, ensuring a monotonically increasing approximation ratio. Recommended for multi-angle and orbit ansätze.
211
+
***Layer-by-layer grid scan** (`interpolate=False`): the best angles from depth $p-1$ are *locked* and a 2-D grid search is performed over the new layer's parameters. Because the grid includes $(γ=0, β=0)$ — which adds an identity layer reproducing the depth-$(p-1)$ result — the initial energy at depth $p$ is guaranteed to be ≤ energy at depth $p-1$, ensuring a monotonically increasing approximation ratio. Recommended for multi-angle and orbit ansätze.
186
212
187
213
```python
188
214
# Interpolation (default)
@@ -224,16 +250,24 @@ qaoa = QAOA(
224
250
225
251
## Extract Results
226
252
227
-
Once `qaoa.optimize(depth=p)` is run, extract the expectation value, variance, and parameters for each depth $1\leq i \leq p$:
253
+
Once `qaoa.optimize(depth=p)` is run, extract the best energy, variance,
254
+
objective value, and parameters for each depth $1\leq i \leq p$:
228
255
229
256
```python
230
-
qaoa.get_Exp(depth=i)
257
+
qaoa.get_energy(depth=i)
258
+
qaoa.get_objective(depth=i)
231
259
qaoa.get_Var(depth=i)
232
260
qaoa.get_gamma(depth=i)
233
261
qaoa.get_beta(depth=i)
234
262
```
235
263
236
-
Additionally, for every optimizer call at each depth, the **angles, expectation value, variance, maximum cost, minimum cost, and number of shots** are stored in:
264
+
The legacy compatibility aliases `problem.cost()`, `problem.computeMinMaxCosts()`,
265
+
and `qaoa.get_Exp()` are not part of the API anymore. Use
266
+
`objective_value()`, `objective_bounds()`, `get_energy()`, and
267
+
`get_objective()` directly.
268
+
269
+
Additionally, for every optimizer call at each depth, the optimizer history,
270
+
variance, best solutions, and shot counts are stored in:
0 commit comments