Skip to content
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
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ authors = [
{ name = "Soroush Hoseini", email = "soroushhoseini0@gmail.com" },
]
dependencies = [
"fastapi[standard]>=0.115.14",
"httpx>=0.28.1",
"numpy<2.0",
"pyfirmata2>=2.5.0",
"pyzmq>=26.2.0",
Expand All @@ -28,6 +26,13 @@ dependencies = [
[project.scripts]
pqn = "pqnstack.cli:app"

[project.optional-dependencies]
webapp = [
"fastapi>=0.115.14",
"httpx>=0.28.1",
"pydantic>=2.11.7",
]

[dependency-groups]
dev = ["mypy>=1.13.0", "pytest-cov>=6.0.0", "ruff>=0.8.0"]

Expand All @@ -36,6 +41,7 @@ dev = ["mypy>=1.13.0", "pytest-cov>=6.0.0", "ruff>=0.8.0"]
files = ["src"]
strict = true
pretty = true
plugins = ['pydantic.mypy']

enable_error_code = ["ignore-without-code"]

Expand Down
18 changes: 10 additions & 8 deletions src/pqnstack/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import httpx
from fastapi import Depends
from fastapi import FastAPI
from fastapi import status
from pydantic import BaseModel

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
app = FastAPI()

# Constants
HTTP_OK = 200


async def get_http_client() -> AsyncGenerator[httpx.AsyncClient, None]:
async with httpx.AsyncClient() as client:
Expand Down Expand Up @@ -49,8 +47,12 @@ async def chsh(basis: tuple[float, float], other_node_address: str, http_client:

for i in range(2):
for perp in [False, True]:
r = await http_client.get(f"http://{other_node_address}/chsh/set_basis?i={i}&perp={perp}")
if r.status_code != HTTP_OK:
r = await http_client.get(
f"http://{other_node_address}/chsh/request-angle-by-basis?i={i}&perp={perp}"
Comment thread
marcosfrenkel marked this conversation as resolved.
Outdated
)

# TODO: Handle other status codes
if r.status_code != status.HTTP_200_OK:
logger.error("Failed to request follower: %s", r.text)
return {"error": "Failed to request follower"}
# count = local_instruments.measure(measurement_config) # ruff: noqa: ERA001
Expand All @@ -66,8 +68,8 @@ async def chsh(basis: tuple[float, float], other_node_address: str, http_client:
return sum(expectations)


@app.get("/chsh/set_basis")
async def request_basis(i: int, *, perp: bool) -> bool:
angle = state.chsh_basis[i] + 90 * perp
@app.post("/chsh/request-angle-by-basis")
async def request_angle_by_basis(index: int, *, perp: bool = False) -> bool:
angle = state.chsh_basis[index] + 90 * perp
logger.info("moving waveplate", extra={"angle": angle})
return True
Loading
Loading