Skip to content

pyro: optional client lock so one client can't interrupt another's measurement - #445

Open
JayChien04717 wants to merge 4 commits into
openquantumhardware:mainfrom
JayChien04717:pyro-client-lock
Open

JayChien04717 wants to merge 4 commits into
openquantumhardware:mainfrom
JayChien04717:pyro-client-lock

Conversation

@JayChien04717

Copy link
Copy Markdown

Motivation

In our lab, several users calibrate chips on one shared QICK board, each from their own PC. To support this multi-user chip calibration, the board must be shared safely: when one user starts a measurement, it must not break another user's calibration run that is already in progress, and a waiting user should be able to see that the board is busy.

Problem

When several PCs connect to the same start_server() QickSoc, a second client's acquire() silently aborts the first client's measurement: start_readout() stops the tProc and the streamer loop. The first client gets no error. Because stop_flag is then cleared again, the first client's poll_data() loop can go on to consume the second client's data packets, so both clients may end up with corrupted results.

Change (pyro.py only)

start_server() gets two new options, client_lock=True and lock_hold_time=5.0. With the lock enabled:

  • The QickSoc class and the autoproxied members (tProc, streamer) are wrapped so that every public method goes through a lock.
  • A client owns the board while it has a call in progress, and for lock_hold_time seconds after its last call. This covers the client-side gaps between rounds and between sweep points.
  • Other clients wait in a FIFO queue; their calls block until the board is free. Existing client code works unchanged and simply queues.
  • Ownership is released when all of the owner's connections close.
  • Internal calls from server-side threads (the streamer worker, and calls made during QickSoc construction) are never locked.
  • New methods that never wait for the lock:
    • get_lock_status(): owner, queue, the owner's progress.
    • wait_for_lock(timeout): a bounded wait that keeps the caller's place in the queue and returns the same status dict. Clients can poll it to show who holds the board and how far along that client is, and can stay cancellable while waiting.
    • report_lock_progress(info): the owner publishes its progress. The server-side readout progress of the current round is included as a fallback.

Notes

  • Clients are identified by peer IP address, not by connection. Pyro4 closes and reopens a proxy's connection after a KeyboardInterrupt during a call, and autoproxied objects use connections of their own. With per-connection identity, a client's own cleanup calls after Ctrl-C (e.g. stop_tproc) would queue behind itself. As a consequence, several notebooks on the same PC share ownership.
  • client_lock defaults to True here. If maintainers would prefer opt-in, I can change the default to False.
  • Testing on a ZCU216 with two PCs: with the first version, a second client waited until the first one finished or was interrupted. The IP-keyed identity and wait_for_lock() have not been tested on hardware yet.

🤖 Generated with Claude Code

Jay and others added 4 commits November 4, 2026 10:51
Previously, if two clients shared one QickSoc server, a second client's
start_readout() silently aborted the first client's readout, and the first
client's poll_data() loop could then consume the second client's data.

start_server() now (by default) wraps the QickSoc class and its autoproxied
members so every public method goes through a per-connection lock. A client
owns the QICK while it has a call in progress and for lock_hold_time seconds
after its last call; other clients' calls block until it is idle or
disconnects. Internal calls from server-side threads are not locked.
Adds soc.get_lock_status() and client_lock/lock_hold_time options.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Waiting clients can now see why they're waiting and for how long:
- queued clients are served first-come-first-served
- wait_for_lock(timeout) waits for at most `timeout` seconds while keeping the
  caller's place in the queue, and returns a status dict (granted, owner,
  queue position, owner progress), so clients can poll and stay cancellable
- report_lock_progress(info) lets the owner publish its progress; the
  server-side readout progress of the current round is included as a fallback
- get_lock_status() reports the same status without waiting

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pyro4 drops and reopens a proxy's connection after a KeyboardInterrupt during
a call, and autoproxied members (soc.streamer, soc.tproc) use their own
connections. Keying the lock on the connection made a client's own cleanup
calls after Ctrl-C (e.g. stop_tproc) queue behind itself for lock_hold_time,
so they timed out. Ownership is now per peer IP; a client is released on
disconnect only once all of its connections are closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants