ReconProxy#
- class pulserver.proxy.ReconProxy[source]#
Bases:
objectRoutes each series of an MRD stream to a reconstruction.
A client connection carries one series and is served by a thread of its own: an optional config text, the header, one acquisition per readout of the chain and a
CLOSE. The header’spulserver_designuser parameter names the design of the store the series was played from. Its readout table enriches the header and every acquisition; the samples are passed on as received, demodulated to the prescribed field-of-view centre by the playout (pulserver.ir.prescribe()). The reconstruction receives the chain’s sequence description as ISMRMRD waveforms, after the header and before the first acquisition (waveforms()); they are not sent back to the client. The reconstruction plugin is the one the client’s config text names. A series that breaks these rules, or whose stream ends without itsCLOSEor an acquisition flaggedLAST_IN_MEASUREMENT, is refused with a text naming the reason and aCLOSE, and what the client still sends is discarded until it closes the connection.The series is reconstructed by a local worker or, with
forward, by the MRD server at that address, which is sent a config file message namingforward_configor else the series’ plugin (the client’s config text is not forwarded) and decides by its own slots and queue when the series runs. Images, DICOM and text go back to the client as they arrive, once the client’s stream has ended whole: what arrives before is held until then, and dropped with a series that is refused. The client’s close closes the reconstruction’s stream, and the reconstruction’s close closes the client. A message the proxy has no reader for ends what goes back, with a text naming its type. Once the client’s stream ends, the proxy waits for the reconstruction to close unlessrecon_timeoutcaps it.A local series holds a slot while it runs. On a host with GPUs, found through
CUDA_VISIBLE_DEVICESornvidia-smi, each slot holds one GPU,gpu_slotsslots per GPU, and the reconstruction reads it ascontext.device. A series that finds every slot busy, or the host’s available memory short of one reconstruction’s budget while another series of this proxy runs, is queued: its enriched stream is written to a file ofqueuewhile it arrives, its client stays connected, and the file is replayed to a worker and deleted once a slot and the memory are free.The series of one exam share a directory under the system’s temporary directory, through which a reconstruction reads what an earlier series of the exam stored in its
ExamCache. The directory is deleted once a header names another exam, or nothing has leased it forEXAM_IDLEseconds, and no series of the exam still runs on any proxy.A series whose sequence sets
EnablePmcis corrected for motion while it plays: the poses its reconstruction states are published into the pose file the scan reads,motion.bufin the scan’s directory of the store, rather than sent to the client. A forwarded series publishes the poses the server passes back.What goes back to a client is also written to a directory under the system’s temporary directory, shared with every other proxy on this host, and removed once the client has had all of it. When the client has gone, it is kept: a client opening a series with the same
measurementIDis sent it, once complete, in place of a new reconstruction. Kept output nobody takes up is removed after a day. Withdicom_receiver, the DICOM images of a series whose client has gone are stored to that receiver once the reconstruction ends, and the output is kept only if it did not store them all.- Parameters:
store (Path | str) – Design store, one directory per scan, as the design calls write it.
plugins (PluginPath, default=None) – Directories of reconstruction plugin files,
<plugin>.py, in search order; required unless the proxy forwards.slots (int, default=None) – Series reconstructed at once; derived from memory and the GPUs when
None.gpu_slots (int, default=1) – Series reconstructed at once on each GPU, when
slotsisNone.spares (int, default=1) – Warm worker processes waiting for a series.
recon_timeout (float, default=None) – Seconds a reconstruction may take after the stream ends before it is stopped and the client told so;
Nonewaits for its close. A local worker is terminated; a forwarded series’ connection is closed.queue (Path | str, default=None) – Directory the queued series are written to; a temporary directory, removed on
close(), whenNone.slot_directory (Path | str, default=None) – Directory the slots are held in, shared with every other proxy on this host so they count against one set;
DEFAULT_SLOT_DIRECTORYwhenNone.exam_directory (Path | str, default=None) – Directory the caches of an exam are held in, shared with every other proxy on this host so a map one series measures reaches a series on another;
DEFAULT_EXAM_DIRECTORYwhenNone. A directory the proxy creates is readable by its owner alone; one that exists is used with the permissions it has. An exam’s directory is removed when the last proxy on that exam lets go of it.forward (tuple[str, int], default=None) –
(host, port)of the MRD server that reconstructs every series; local workers whenNone.forward_config (str, default=None) – Config name sent to that server instead of the reconstruction plugin.
dicom (bool, default=False) – Convert each image to DICOM, from the enriched header, before it is relayed, whatever reconstructed it. Needed by a client that reads DICOM alone, with a plugin that emits images.
save_to (Path | str, default=None) – Directory each series is kept in, as the scanner sent it, so that it can be reconstructed again offline; not kept when
None. A series is written tomrd_<time>.h5.partand renamedmrd_<time>.h5once its stream has ended.idle_timeout (float, default=None) – Seconds without a client after which
serve()returns, counted from the last client to leave; never whenNone.dicom_receiver (DicomReceiver, default=None) – Where the DICOM images of a series whose client has gone are stored; they are held for the client’s return when
None.
- Attributes:
workers (WorkerPool | None) – The spares assignments are taken from;
Nonewhen forwarding.exams (ExamCacheManager | None) – The current exam and its directory;
Nonewhen forwarding.queue (Path | None) – The queue directory;
Nonewhen forwarding.
- Raises:
ValueError – If the proxy neither forwards nor has a plugin directory.
Methods
Listen on |
|
Stop accepting clients, wait for running series and release the spares. |
|
Accept clients until |
|
Make |
Attributes
Port the server listens on. |