irsim.util.decorator#

Decorators shared by IR-SIM environments and utilities.

bind_env, plot_only and normalize_actions wrap EnvBase methods; time_it / time_it2 are general timing helpers.

Functions#

time_it(→ Any)

Decorator to measure function execution time.

bind_env(method)

Decorator making self the current environment before method runs.

plot_only(method)

Decorator making an env plotting helper a no-op when the env has no figure.

normalize_actions(func)

Decorator to normalize (action, action_id) into an aligned actions list.

time_it2(→ Any)

Decorator to measure function execution time with instance attribute check.

Module Contents#

irsim.util.decorator.time_it(name: str = 'Function') Any[源代码]#

Decorator to measure function execution time.

参数:

name (str) -- Function name for logging (default "Function").

返回:

Wrapped function with timing.

返回类型:

function

irsim.util.decorator.bind_env(method)[源代码]#

Decorator making self the current environment before method runs.

Object ids, the random generator, and context-free logging are reached through the module-level env_param/world_param proxies, so methods that construct objects or draw random numbers bind their environment first.

irsim.util.decorator.plot_only(method)[源代码]#

Decorator making an env plotting helper a no-op when the env has no figure.

EnvBase creates no EnvPlot in headless mode, so rendering, drawing, and saving helpers decorated with this simply return None in that case.

irsim.util.decorator.normalize_actions(func)[源代码]#

Decorator to normalize (action, action_id) into an aligned actions list.

The wrapped method must belong to a class that has a objects attribute. It receives actions, a list aligned with self.objects (None where nothing was given). action is one action, a list of actions, or a dict {name: action}; action_id is an object id (obj.id) or name (None for the first object), or a list of them. A single action is applied to every id; a list of actions is applied to the given ids, or to consecutive objects starting from the given id. Surplus actions (or ids) are dropped with a warning; an unknown id or name raises.

irsim.util.decorator.time_it2(name: str = 'Function') Any[源代码]#

Decorator to measure function execution time with instance attribute check.

参数:

name (str) -- Function name for logging (default "Function").

返回:

Wrapped function with timing.

返回类型:

function