-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "b1f28f06", | ||
"metadata": {}, | ||
"source": [ | ||
"# The sampler version of VQE\n", | ||
"\n", | ||
"The VQE is originally formulated for minimizing the expectation value of some Hamiltonian $H$. The best solution is the parameter set that yields the smallest energy. \n", | ||
"\n", | ||
"In a classical optimization setting, where $H$ is a diagonal matrix, the goals, results and methods are slightly different than in the general case:\n", | ||
"* the best result is the best _measurement/bitstring_, not the best energy\n", | ||
"* we can use aggregation functions on the single measurements (like CVaR) which is only possible for diagonal Hamiltonians \n", | ||
"* the Hamiltonian can be given as function on bitstrings\n", | ||
"\n", | ||
"Therefore we suggest to add a `SamplerVQE` (`SamplingVQE`?) that's specific to this use case and can be leveraged in QAOA and Qiskit Optimization." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "83e818b2", | ||
"metadata": {}, | ||
"source": [ | ||
"### Signature" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "52a93f3d", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"class SamplerVQE:\n", | ||
" def __init__(\n", | ||
" self,\n", | ||
" ansatz: QuantumCircuit,\n", | ||
" optimizer: Union[Optimizer, Minimizer],\n", | ||
" sampler: Sampler,\n", | ||
" gradient: EstimatorGradient, # bit weird that's it's not a sampler gradient\n", | ||
" aggregation: Union[float, AGGREATOR], # CVaR alpha if a float, but any aggregation possible\n", | ||
" ) -> None:\n", | ||
" ...\n", | ||
" \n", | ||
" def compute_minimum_eigenvalue(\n", | ||
" self,\n", | ||
" operator: OperatorBase, # could also support a function f: bitstr -> float\n", | ||
" aux_operators: ListOrDict[operator]\n", | ||
" ) -> SamplerVQEResult:\n", | ||
" ..." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0e602c65", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"@dataclass\n", | ||
"def SamplerVQEResult:\n", | ||
" # same as VQE\n", | ||
" eigenvalue: float\n", | ||
" cost_function_evals: int\n", | ||
" optimal_point: np.ndarray\n", | ||
" optimal_parameters: Dict[Parameter, float]\n", | ||
" optimizer_time: float\n", | ||
" \n", | ||
" # different\n", | ||
" best_measurement: str\n", | ||
" final_samples: QuasiDistribution # could also be called \"eigenstate\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "f0a0c332", | ||
"metadata": {}, | ||
"source": [ | ||
"### QAOA\n", | ||
"\n", | ||
"**Note** If QAOA inherits from `SamplerVQE` the new version can only handle diagonal Hamiltonians, not like right now any Hamiltonian!\n", | ||
"\n", | ||
"#### Option 1\n", | ||
"\n", | ||
"QAOA inherits from `SamplerVQE` and can from now on only handle diagonal Hamiltonians." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "81ed65d5", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"class QAOA(SamplerVQE)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d8197208", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Option 2\n", | ||
"\n", | ||
"QAOA still inherits from `VQE` and we add a new `SamplerQAOA` inheriting from `SamplerVQE`" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4b160fb9", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"class QAOA(VQE)\n", | ||
"class SamplerQAOA(SamplerVQE)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "98f9c873", | ||
"metadata": {}, | ||
"source": [ | ||
"### SamplerMinimumEigensolver\n", | ||
"\n", | ||
"Should we add a `SamplingMinimumEigensolver` as common base class of `SamplerVQE`, `(Sampler)QAOA` and add a `SamplerNumPyMES`?" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "a6cd9697", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Pro SamplerMES\n", | ||
"\n", | ||
"* The `SamplerVQE` cannot be used as drop-in replacement for other MES as it only supports diagonal Hamiltonians.\n", | ||
"* Results types also differ\n", | ||
"* We can have a classical, exact reference algo: `SamplerNumPyMES`" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "bddeeb77", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Contra SamplerMES\n", | ||
"\n", | ||
"The alternative solution would be that `SamplerVQE` & co. derive from `MinimumEigensolver` but raise an error if the Hamiltonian is not diagonal.\n", | ||
"\n", | ||
"* The `MinimumEigenOptimizer` could continue to just accept any MES (otherwise we have to start supporting MES and SamplerMES)\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |