rome.utils¶
Shared helpers for laying ROME state out inside a Dragon DDict.
Every ROME component reads and writes the same distributed dictionary, which is what lets a task on one node add training data that a training task on another node picks up. The one rule that makes that safe is:
**never read-modify-write a shared container.**
d = ddict["corpus"]; d[uid] = rec; ddict["corpus"] = d loses records the
moment two nodes do it at once. So ROME gives every record, request and
result its own key and rebuilds collections by scanning a key prefix — single
key writes are atomic in a DDict, so nothing is ever clobbered.
Namespace is the small amount of glue that makes that layout pleasant
to work with. It is a view, not a store: it holds no state of its own and
several views over the same DDict compose freely.
SEP
module-attribute
¶
Separator between namespace segments. Unlikely to appear in a uid or a name.
MODEL_PATH_KEY
module-attribute
¶
Key holding the checkpoint the workflow should currently be using.
MODEL_VERSION_KEY
module-attribute
¶
Key holding the monotonically increasing checkpoint version.
Stream tasks poll this to decide when to hot-swap weights.
Namespace
¶
Bases: MutableMapping
A prefixed view over a Dragon DDict (or any mapping).
Every operation goes through a handle owned by the calling thread — see
thread_handle — so views may be shared freely across the manager
and its stream workers.
Parameters:
-
ddict(MutableMapping) –The shared dictionary. Normally a
dragon.data.ddict.DDict; any mapping works, which is what makes the components unit-testable. -
prefix(str, default:'') –Prepended to every key this view touches.
Source code in rome/utils.py
namespace
¶
Derive a child view: ns.namespace("record") -> keys record|….
Source code in rome/utils.py
get
¶
Read key, returning default when absent.
Goes through __getitem__ rather than DDict.get so the behaviour
is identical whichever mapping is underneath.
Source code in rome/utils.py
pop
¶
Remove key and return its value.
This is ROME's claim protocol: whoever pops a key owns that item, so two stream replicas draining the same queue never process a request twice. Correctness rests on the underlying pop being atomic, which is why it delegates rather than doing read-then-delete — a Dragon DDict resolves the contention manager-side, and measurably: four threads racing over 120 keys claim 120 with zero duplicates.
The single-argument form is deliberate. dict.pop(k, default)
returns the default while DDict.pop(k, default) raises
DDictKeyError regardless, so asking for the default would behave
differently on the two backings; catching KeyError (which
DDictKeyError subclasses) behaves the same on both.
Source code in rome/utils.py
increment
¶
Bump an integer counter and return the new value.
Only safe when a single component owns the counter — ROME keeps to
that (the training manager owns model_version, and so on).
Source code in rome/utils.py
keys
¶
Namespace-relative keys, optionally filtered by a further prefix.
Source code in rome/utils.py
items
¶
(key, value) pairs under prefix, skipping keys that vanish mid-scan.
Source code in rome/utils.py
drain
¶
Pop and return up to limit (key, value) pairs under prefix.
Source code in rome/utils.py
clear
¶
snapshot
¶
thread_handle
¶
Return a DDict client handle owned by the calling thread.
A Dragon DDict handle multiplexes an FLI channel and is not safe to
share between threads: concurrent use corrupts the channel and surfaces as
dragon.fli.DragonFLIEOT, usually from an unrelated later operation. It
is not a hypothetical — ROME runs the manager's event loop and its
asyncio.to_thread stream workers in one process against one dictionary,
which reproduces it within a few hundred operations.
Dragon's own remedy is that each consumer attaches its own handle, so that is what this does, once per thread and cached. Attaching is cheap and the thread pool is bounded, so the cache stays small.
serialized is None means the backing is a plain mapping (the unit-test
and single-process case), which is returned unchanged.
Source code in rome/utils.py
submit_task
¶
submit_task(asyncflow, func, *args, task_description: Optional[Dict[str, Any]] = None, service: bool = False, executable: bool = False, **kwargs)
Submit func to the workflow engine as a task.
ROME schedules nothing itself — asyncflow is the execution backend, and this is the single place ROME talks to it.
Parameters:
-
asyncflow(WorkflowEngine) –The engine the host workflow handed to ROME.
-
func(coroutine function) –The task body. asyncflow only accepts
async def. For a function task a blocking trainer or inference call belongs inside anasyncio.to_thread; for an executable taskfuncinstead returns the shell command string to run (the same shape IMPRESS uses). -
task_description(dict, default:None) –Backend-specific resource request (ranks, GPUs, placement policy, …). Passed straight through — ROME does not interpret it, because the keys depend on which execution backend the workflow is running.
-
service(bool, default:False) –Mark the task as a long-running service. ROME's inference and reward streams are services; a training round is not. Ignored for executable tasks.
-
executable(bool, default:False) –Submit as an executable (command) task rather than a function task.
func's return value is then the command line to run on the backend, not a Python result. This is how a training round runs as its own process — seerome.train.base.TrainTask.as_command.
Returns:
-
Future–Resolves when the task completes (to its return value for a function task; to the backend's execution result for an executable one).
Source code in rome/utils.py
resource_description
¶
resource_description(gpus: int = 0, nodes: int = 1, extra: Optional[Dict[str, Any]] = None) -> Dict[str, Any]
Build a default task_description from ROME's coarse resource fields.
The concrete keys an execution backend understands are its own business, so
this only fills in the two that the RADICAL backends share, and anything a
workflow passes in extra wins. Workflows on an exotic backend should set
task_description explicitly on the config and ignore gpus/nodes.