accelmo.fitting.shared_reference

Reference orbits computed once and shared with every closed-orbit worker through shared memory.

Every reference-subtracted closed-orbit series needs the orbit (and its knob Jacobian) of the reference machine state: all correctors at nominal, the current magnet knobs. That state is the same for every series, so a dedicated reference worker solves it once per iteration, in parallel with the other workers’ signal solves, and publishes it here. The signal workers map the block instead of each solving the same reference (and sending 90 MB through a pipe).

Block layout: float64 (len(reference_pts), len(coords), n_bpms, 1 + n_knobs); [..., 0] is the orbit and [..., 1:] its Jacobian with respect to the knobs.

class accelmo.fitting.shared_reference.SharedReference(name, reference_pts, coords, shape)[source]

Bases: object

Picklable description of a published block (what the fitter relays to the signal workers).

Parameters:
  • name (str)

  • reference_pts (tuple[float, ...])

  • coords (tuple[str, ...])

  • shape (tuple[int, int, int, int])

name: str
reference_pts: tuple[float, ...]
coords: tuple[str, ...]
shape: tuple[int, int, int, int]
rows(wanted)[source]

Rows of the coordinate axis holding wanted coordinates (a slice when they are all of them, in order).

Return type:

slice | list[int]

Parameters:

wanted (list[str])

class accelmo.fitting.shared_reference.ReferencePublisher[source]

Bases: object

Writer side: owns the shared-memory block and rewrites it every iteration.

publish(states, reference_pts, coords)[source]

Write one (orbit (n_coords, n_bpms), jacobian (n_coords, n_bpms, n_knobs)) per reference momentum.

Return type:

SharedReference

Parameters:
  • states (list[tuple[numpy.ndarray, numpy.ndarray]])

  • reference_pts (tuple[float, ...])

  • coords (tuple[str, ...])

publish_orbits(orbits, reference_pts, coords)[source]

Rewrite the orbits of the published block, leaving the Jacobians of the last publish().

Return type:

SharedReference

Parameters:
  • orbits (list[numpy.ndarray])

  • reference_pts (tuple[float, ...])

  • coords (tuple[str, ...])

close()[source]

Release and delete the block (readers must be done with it).

Return type:

None

accelmo.fitting.shared_reference.attach_shared_block(name)[source]

Map an existing block without making this process responsible for deleting it.

Before Python 3.13 attaching registers the block with the resource tracker, which then warns about a “leaked” block when the reader exits although the publisher has already unlinked it.

Return type:

SharedMemory

Parameters:

name (str)

class accelmo.fitting.shared_reference.ReferenceReader[source]

Bases: object

Reader side: maps the block named by a SharedReference (once) and returns views of it.

view(reference)[source]

Array view of the shared block named by reference.

Return type:

ndarray

Parameters:

reference (SharedReference)

close()[source]

Detach from the shared block.

Return type:

None