Resources

class batsim_py.resources.Host(id, name, pstates=None, allow_sharing=False, metadata=None)[source]

Bases: object

This class describes a Batsim computing resource (host).

A host is a resource on which a job can execute.

Parameters
  • id (int) – The host id. Must be unique within a platform.

  • name (str) – The host name.

  • pstates (Optional[Sequence[PowerState]]) – The host power states. Defaults to None. A host can have several computing power states but only one sleep and transition (On/Off) power states. Computing power states serve as a way to implement different DVFS levels while the transition power states are used only to simulate the costs of switching On/Off. A host cannot be used when it’s being switched On/Off or sleeping. If you only want to implement DVFS, there is no need to provide a sleep power state and a transition power state. Moreover, if you provide a sleep power state you must also provide both transition power states.

  • allow_sharing (bool) – Whether multiple jobs can share the host or not. Defaults to False.

  • metadata (Optional[dict]) – Extra host properties that can be used by some functions beyond the scope of Batsim or Batsim-py. Defaults to None.

Raises
  • AssertionError – In case of invalid arguments type.

  • ValueError – In case of missing pstates or pstate ids are not unique.

Examples

>>> ps1 = PowerState(0, PowerStateType.COMPUTATION, 10, 100)
>>> ps2 = PowerState(1, PowerStateType.COMPUTATION, 15, 150)
>>> h = Host(0, "Host_0", [ps1, ps2])
get_default_pstate()[source]

Get the default power state.

The default power state is the first computation state provided in the sequence power states which, is sorted by the id.

Raises
  • LookupError – In case of power state could not be found.

  • RuntimeError – In case of power states were not defined.

Return type

PowerState

Returns

The default power state.

get_pstate_by_id(pstate_id)[source]

Get a power state by id.

Parameters

pstate_id (int) – The power state id.

Raises
  • LookupError – In case of power state could not be found.

  • RuntimeError – In case of power states were not defined.

Return type

PowerState

Returns

The power state with the corresponding id.

get_pstate_by_type(ps_type)[source]

Get a power state by type.

Parameters

ps_type (PowerStateType) – The power state type.

Raises
  • RuntimeError – In case of power states were not defined.

  • LookupError – In case of power state could not be found.

Return type

List[PowerState]

Returns

All power states with the corresponding power state type.

get_sleep_pstate()[source]

Get the sleep power state.

Raises
  • LookupError – In case of sleep power state could not be found.

  • RuntimeError – In case of power states were not defined.

Return type

PowerState

Returns

The sleep power state.

property id

The Host ID

Return type

int

property is_allocated

Whether this host was allocated for some job or not.

Return type

bool

property is_computing

Whether this host is computing (100% cpu) or not.

Return type

bool

property is_idle

Whether this host is idle (0% cpu) or not.

Return type

bool

property is_shareable

Whether multiple jobs can share this host or not.

Return type

bool

property is_sleeping

Whether this host is sleeping or not.

Return type

bool

property is_switching_off

Whether this host is switching off or not.

Return type

bool

property is_switching_on

Whether this host is switching on or not.

Return type

bool

property is_unavailable

Whether it’s possible to execute jobs or not.

Return type

bool

property jobs

A sequence of job ids that are allocated on this host.

Return type

List[str]

property metadata

Host extra properties.

Return type

Optional[dict]

property name

Host name.

Return type

str

property power

Instantaneous power consumption (in Watts).

Return type

Optional[float]

property pstate

Host current power state.

Return type

Optional[PowerState]

property pstates

A sequence of all power states defined.

Return type

Optional[List[PowerState]]

property state

Host current state.

Return type

HostState

class batsim_py.resources.HostState(value)[source]

Bases: enum.Enum

Batsim Host State Types

class batsim_py.resources.Platform(resources)[source]

Bases: object

This class describes a computing platform.

A platform is composed of a set of resources (computing, storage, and network).

Parameters

resources (Sequence[Union[Host, Storage]]) – the platform resources (hosts and storages).

Raises
  • ValueError – In case of invalid size.

  • SystemError – In case of invalid resource ids.

get(resource_id)[source]

Get resource by id.

Parameters

resource_id (int) – The resource id.

Return type

Union[Host, Storage]

Returns

The resource with the corresponding id.

Raises

LookupError – In case of resource not found.

get_host(host_id)[source]

Get host by id.

Parameters

host_id (int) – The host id.

Return type

Host

Returns

The host with the corresponding id.

Raises

LookupError – In case of resource not found or invalid resource type.

get_not_allocated_hosts()[source]

Get available hosts.

An available host is the one that is not allocated for a job.

Return type

Sequence[Host]

Returns

A list with available hosts.

get_storage(storage_id)[source]

Get storage by id.

Parameters

storage_id (int) – The storage id.

Return type

Storage

Returns

The storage with the corresponding id.

Raises

LookupError – In case of resource not found or invalid resource type.

property hosts

Platform computing resources.

Return type

Iterator[Host]

property power

The instantaneous power consumption (in Watts).

Return type

float

property resources

Platform resources.

Return type

Iterator[Union[Host, Storage]]

property size

The number of resources in the platform.

Return type

int

property state

The current platform state.

Return type

Sequence[HostState]

property storages

Platform storage resources.

Return type

Iterator[Storage]

class batsim_py.resources.PowerState(pstate_id, pstate_type, watt_idle, watt_full)[source]

Bases: object

This class describes a power state model.

When the host is on, the energy consumption naturally depends on both the current CPU load and the host energy profile.

Parameters
  • pstate_id (int) – The power state id. Must be unique.

  • pstate_type (PowerStateType) – The power state type.

  • watt_idle (float) – Consumption (Watts) when the host is up but without anything to do.

  • watt_full (float) – Consumption (Watts) when the host cpu is at 100%.

Raises
  • AssertionError – In case of invalid arguments type.

  • ValueError – In case of watts are invalid values or the power profile values are not equal when the power state type is not a computation one.

Examples

>>> ps1 = PowerState(0, PowerStateType.COMPUTATION, 90, 160)
>>> ps2 = PowerState(0, PowerStateType.SLEEP, 10, 10)
property id

The Power State ID

Return type

int

property type

The power state type.

Return type

PowerStateType

property watt_full

Consumption (Watts) when the host cpu is at 100%.

Return type

float

property watt_idle

Consumption (Watts) when the host is up but without anything to do.

Return type

float

class batsim_py.resources.PowerStateType(value)[source]

Bases: enum.Enum

Batsim Host Power State Types

class batsim_py.resources.Storage(id, name, allow_sharing=True, metadata=None)[source]

Bases: object

This class describes a Batsim storage resource.

Parameters
  • id (int) – The storage id. Must be unique within a platform.

  • name (str) – The storage name.

  • allow_sharing (bool) – Whether multiple jobs can share the storage. Defaults to True.

  • metadata (Optional[dict]) – Extra storage properties that can be used by some functions beyond the scope of Batsim or Batsim-py. Defaults to None.

property id

Storage ID

Return type

int

property is_allocated

Whether the storage is being used by a job or not.

Return type

bool

property is_shareable

Whether multiple jobs can share this storage or not.

Return type

bool

property is_unavailable

Whether the storage is unavailable or not.

Return type

bool

property jobs

All jobs that are using this storage.

Return type

List[str]

property metadata

Storage extra properties.

Return type

Optional[dict]

property name

Storage name.

Return type

str

property state

The storage current state.

Return type

StorageState

class batsim_py.resources.StorageState(value)[source]

Bases: enum.Enum

Batsim Storage State Types