Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QI2-717] remove asyncio usage from qaoa circuit #114

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
104 changes: 100 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
qi = "quantuminspire.cli.command_list:app"

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.9"
napocornejo marked this conversation as resolved.
Show resolved Hide resolved
typer = {extras = ["all"], version = "^0.9.0"}
qutechopenql = "^0.11.1"
pydantic = "^1.10.9"
Expand All @@ -42,6 +42,9 @@ pytest-mock = "^3.12.0"
isort = "^5.11.4"
black = "^23.11.0"
pytest-asyncio = "^0.21.1"
networkx = "^3.1"
numpy = "^1.23.5"
scipy = "^1.10.1"
napocornejo marked this conversation as resolved.
Show resolved Hide resolved

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