flux.resource.Rv1Set module

Pure-Python Rv1 implementation of the ResourceSetImplementation ABC.

Rv1Set stores resources as a per-rank dict {hostname, cores, gpus} and a property mapping {name: set-of-ranks}. It implements all abstract methods of ResourceSetImplementation and supports set operations (union, diff, intersect, append, add), properties, constraints, and round-trip serialization of the RFC 20 Rv1 R format.

class flux.resource.Rv1Set.Rv1Set(arg=None, keep_scheduling: bool = False)

Bases: ResourceSetImplementation

Pure-Python Rv1 ResourceSetImplementation.

Internal representation:

  • _ranks: mapping from rank integer to {hostname: str, cores: frozenset, gpus: frozenset}

  • _properties: mapping from property name to the set of ranks that carry that property

  • _expiration, _starttime: resource-set timestamps (float, seconds since epoch; 0 = unset)

Set operations (diff, intersect) operate at core/GPU ID granularity. Properties are propagated to the result sets by intersection.

The constructor accepts any of:

  • None or no argument → empty set

  • an R JSON string

  • a parsed R JSON dict ({"version": 1, "execution": {...}})

add(other: Rv1Set) None

Add ranks from other into self (mutating).

For ranks not yet in self, the rank is copied from other. For ranks already in self, the core and GPU ID sets are unioned so that merging disjoint subsets of a resource set (e.g. free + allocated) reconstructs the full topology.

append(other: Rv1Set) None

Add all ranks from other into self (mutating).

For ranks already in self, core and GPU ID sets are unioned so that appending disjoint subsets of a rank (e.g. core[0-3] then core[4-7]) merges them, matching C rlist_append / rnode_add behaviour.

copy() Rv1Set

Return an independent copy.

copy_constraint(constraint) Rv1Set

Return a copy containing only ranks that satisfy constraint.

constraint may be an RFC 31 constraint dict or a JSON string.

copy_ranks(ranks) Rv1Set

Return a copy containing only ranks.

count(name: str) int

Return total count of name ("core" or "gpu") across all ranks.

diff(other: Rv1Set) Rv1Set

Return a new Rv1Set with resources in self not in other.

Matching ranks have their core and GPU ID sets reduced by the IDs in other (mirroring the C rlist_diff / rnode_diff behaviour). Ranks with no remaining resources are dropped from the result.

dumps() str

Return a compact human-readable summary.

Format: rank<idset>/core<idset>[,gpu<idset>][+...]

encode() str

Serialize to an R JSON string.

get_expiration() float

Return the resource set expiration (seconds since epoch, 0 = none).

get_properties() str

Return an RFC 20 properties JSON object string.

get_starttime() float

Return the resource set start time (seconds since epoch, 0 = none).

intersect(other: Rv1Set) Rv1Set

Return a new Rv1Set with ranks in both self and other.

nnodes() int

Return the number of nodes (ranks) in this set.

nodelist() Hostlist

Return the hostnames in this set as a Hostlist.

ranks() IDset

Return the rank integers as a IDset.

remove_ranks(ranks) Rv1Set

Remove ranks from this set (mutating).

property scheduling

Return the opaque R.scheduling key, or None if not set.

The R.scheduling key is an optional RFC 20 field carrying scheduler-private data. Schedulers that set keep_scheduling=True in the constructor will preserve this field so it can be propagated to allocations.

set_expiration(expiration: float) None

Set the resource set expiration (seconds since epoch, 0 = none).

set_property(name: str, ranks=None) Rv1Set

Set property name on ranks (or all ranks if ranks is None).

set_starttime(starttime: float) None

Set the resource set start time (seconds since epoch).

to_dict() dict

Return the resource set as a parsed R JSON dict.

union(other: Rv1Set) Rv1Set

Return a new Rv1Set with the union of resources from self and other.

For ranks present in both operands, core and GPU ID sets are unioned (true ID-level union, mirroring C rlist_union / rnode_union behaviour).

version = 1