Skip to content

Commit

Permalink
[QI2-717] remove asyncio usage from qaoa circuit (#114)
Browse files Browse the repository at this point in the history
* [QI2-717] remove asyncio usage from qaoa circuit

* [QI2-717] Updated python version for dependencies. Parametrized testing circuits test.

* [QI2-719] Revert to python 3.8, remove libraries, remove test
  • Loading branch information
napocornejo authored Nov 28, 2023
1 parent ba23a7e commit 47442c5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
13 changes: 1 addition & 12 deletions examples/qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
The algorithm is the Quantum Approximate Optimization Algorithm, as documented on
https://www.quantuminspire.com/kbase/qaoa/
"""
import asyncio
from concurrent.futures import ThreadPoolExecutor
from typing import Any, Callable, Dict, List

Expand Down Expand Up @@ -110,18 +109,8 @@ def f(theta):
beta = theta[:P]
gamma = theta[P:]
circuit = qaoa_circuit(graph, beta, gamma)
# This slightly awkward. f needs to by a normal (non async) function since scipy can only minimize those.
# However, in the classical backend there is already an asycio event loop so we can't just call
#
# result = asyncio.run(qi.execute_circuit(circuit, SHOTS))
#
# and we have to do it in a separate thread instead. Ideally we solve these issues in
# the classical so that we do not expose the end user to such technical difficulties.
with ThreadPoolExecutor(1) as pool:
coro = qi.execute_circuit(circuit, SHOTS)
future = pool.submit(lambda: asyncio.run(coro))
result = future.result()

result = qi.execute_circuit(circuit, SHOTS)
counts = result.results
energy = compute_maxcut_energy(counts, graph)
# right now the platform has no way to make intermediate results
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ isort = "^5.11.4"
black = "^23.11.0"
pytest-asyncio = "^0.21.1"


[tool.pytest.ini_options]
addopts = "-v --cov --cov-report term-missing:skip-covered --cov-report xml"
asyncio_mode = "auto"
Expand Down

0 comments on commit 47442c5

Please sign in to comment.