Reconstruction session#

TL;DR

  • The proxy speaks Gadgetron’s MRD streaming messages: one series per connection, images back on the same one.

  • The client’s config names the recon plugin, so one design can be reconstructed by any plugin.

  • Each series runs in its own worker process, queued on disk when every slot is busy or memory is short, or is forwarded to a reconstruction server.

The scanner’s reconstruction client opens a connection per series, sends a config, the MRD header and the acquisitions, and reads images back. The proxy on the other end refuses a series it cannot serve, enriches it from its design (MRD enrichment), and runs your recon plugin on it. Lesson 4 of the Course runs one series through it.

Capabilities#

  • Accepts one series per connection and returns its images, then closes.

    Code: ReconProxy. Tests: a series returns images then closes; a connection that sends nothing is not a failed series (test_proxy.py).

  • Runs the plugin the client’s config names, by name or by the path of its file.

    Code: ReconProxy. Tests: the proxy resolves a plugin file path to its stem; a series opening with its header names no reconstruction and is refused; a manifest naming a reconstruction is read and the name ignored (test_proxy.py).

  • Reads each design once from the store, or from its own intake, and refuses a series naming none.

    Code: DesignCache, DesignIntake. Tests: a design pushed to the intake is reconstructed from its store; a series naming no stored design is refused (test_proxy.py).

  • Refuses a malformed stream with a text the console shows.

    Code: ReconProxy. Tests: a series carrying no header or two is refused; a series that ends before its last readout is refused; a message the proxy cannot read ends the output with its type; a series carrying a message the proxy cannot read is refused (test_proxy.py).

  • Returns nothing of a scan whose client ends the stream without a CLOSE, though its images were already made.

    Code: ReconProxy. Tests: a scan stopped after its last readout exports nothing (test_proxy.py).

  • Reconstructs each series in a fresh worker process, with spares that have already imported the engine, and returns why one failed.

    Code: ReconProxy. Tests: the spare worker is replaced after each series; the proxy process does not import the reconstruction engine; a crashing plugin closes its series and frees the slot; a plugin crashing while its series still arrives reports why (test_proxy.py).

  • Bounds concurrent series by slots, one per GPU by default, and by the memory available, and holds the rest on disk.

    Code: --slots, --gpu-slots, --queue. Tests: a second series waits for a slot and still returns images; a series with every slot busy is held on disk until one frees; a series arriving while memory is short is held on disk until a series finishes; a series reads the gpu its slot holds (test_proxy.py).

  • Stops a reconstruction past its timeout and tells the client.

    Code: --recon-timeout. Tests: a reconstruction past the recon timeout is stopped and reported; a reconstruction outlasting the worker timeout still returns its image (test_proxy.py).

  • Returns images as MRD images, or as DICOM.

    Code: --dicom. Tests: images come back as dicom when asked; forwarded images come back as dicom when asked (test_proxy.py).

  • Forwards each enriched series to a reconstruction server instead of reconstructing it.

    Code: --forward, ReconServer. Tests: a forwarded series returns the image a local worker returns; a forwarded series names its reconstruction in a config file message (test_proxy.py).

  • Shares an exam cache between the series of one exam, across proxies on one host.

    Code: --exams. Tests: the series of one exam share its exam cache; a closed proxy leaves the exam root for the proxies still running (test_proxy.py).

  • Publishes the poses of a motion-corrected series to the running scan.

    Code: pulserver.proxy._motion. Tests: a motion corrected series publishes its poses to the scan; a series not corrected for motion writes no pose file (test_proxy.py).

  • Keeps each series enriched, for an offline rerun that gives the same image.

    Code: --save-data. Tests: a kept series runs offline and gives the image the proxy returned; what a proxy keeps is the series it reconstructed, enriched; a kept series given its design is not enriched twice; a kept series takes its name only once its stream has ended (test_proxy.py).

  • Holds images for a client that dropped, or stores them to a DICOM receiver, and closes on its own when idle.

    Code: --idle-timeout, --dicom-receiver. Tests: images whose client has gone reach it when it returns; the images of a series whose client has gone reach the dicom receiver; a series the dicom receiver does not take is held for its client; the idle timeout counts from the last client leaving (test_proxy.py).

Division of responsibility#

Method#

../_images/session.svg

A series streamed to the proxy, enriched, and reconstructed in a worker or forwarded.#

../_images/session-dark.svg

A series streamed to the proxy, enriched, and reconstructed in a worker or forwarded.#

Messages#

A series is CONFIG, HEADER, the ACQUISITIONs and optional WAVEFORMs, then CLOSE; what returns is IMAGE, DICOM_WITHNAME and TEXT messages, then CLOSE. These are the identifiers of Gadgetron’s MRD streaming protocol. A refused series receives one TEXT beginning pulserver: and a CLOSE at once. A stream that ends without its CLOSE is a scan that did not finish: it is refused, and what its reconstruction produced is not returned. An MRD message carries no length, so a message type the proxy cannot read ends the series.

Workers and slots#

A worker reconstructs one series and exits, which frees whatever memory the reconstruction allocated; the import cost is paid by a spare started in advance. Slots are derived from memory and the GPUs found through CUDA_VISIBLE_DEVICES or nvidia-smi. A series without a slot, or arriving while another runs and the available memory is short of one reconstruction’s budget, is written to the queue, enriched, as it arrives, and the client stays connected until its images come back. Reconstruction proxy states the details.

Forwarding#

With --forward, the proxy enriches each series and sends it to an MRD server on another computer, with a config naming the plugin or --forward-config. A ReconServer runs the plugin in its own workers and enriches nothing.

Examples#