Wrappers¶
SpecWrapper is the core of the project: it samples signals, drives the monitor,
shapes rewards and observations, steps the reward machines and applies the
constraints. Everything in the guide describes
what it does with its configuration.
Building the stack¶
wrap_env_specs(env, cfg)
¶
SpecWrapper¶
SpecWrapper
¶
Bases: Wrapper
__init__(env, cfg)
¶
step(action)
¶
reset(**kwargs)
¶
get_sample(obs, action, reward)
¶
eval_formula_cfg(f_name, f_opt, eval_res=None)
¶
eval_specs_episode(episode=None, res=dict(), res_rew_f_list=[], res_eval_f_list=[])
¶
get_rob(formula, horizon=0, online=True)
¶
get_ep_len()
¶
get_time()
¶
get_sig(sig_name)
¶
get_signal_from_str(str)
¶
Return an stlrom.Signal for a plot/signal name string.
Raw mapped signals (obs/actions/aux, env_reward) are returned
directly as the driver's stlrom.Signal -- its own plotting
handles interpolation. Other tokens (rewards, formula robustness,
RM states/rewards, ...) are re-encoded into a fresh Signal:
discrete (zero-order-hold) signals -- rewards, actions, label/states,
sat(...) -- are encoded with constant samples (derivative 0) so they
render as steps; continuous signals use linear interpolation.
get_values_from_str(str)
¶
set_episode_data(episode)
¶
show_reward_machines()
¶
Print a readable, text summary of the configured reward machines.
Intended as a lightweight visual/text diagnostic of the RM structure (states, transitions, priorities) and the label formulas that drive them.
Reward machines¶
RewardMachine
¶
A pure finite-state machine (FSM) defining reward-machine dynamics.
This class is intentionally independent of gym wrappers and STL evaluation:
it only parses a cfg_rm dict, tracks the current state, consumes a list of
true condition labels at each step, and decides a transition based on priority.
It knows nothing about how those labels are computed (STL robustness, plain
booleans, ...) -- the caller (wrapper) is responsible for building the label list.
Semantics of step(labels):
* let A be the outgoing transitions from the current state whose
condition is in labels (i.e. activated);
* if A is empty, stay in the current state and issue that state's reward;
* otherwise, take the activated transition with the highest priority
(default 0) and issue that transition's reward (default 0).
* if two or more activated transitions share the same (max) priority,
a ValueError is raised (non-determinism guard).
Config contract:
states: list of dicts: id (str), optional initial (bool),
optional final (bool), optional reward (default 0),
optional actions dict with action-shielding fields:
enable (bool, default True -- when False the state
imposes no action constraints), blocked (list of raw
action values forbidden in this state), forced (raw
action value taken unconditionally while in this state)
and fallback (raw action value used when the agent's
action is blocked and the previous action is also blocked).
Exactly one state must be initial.
transitions: list of dicts: from, to, condition (all single
strings), optional reward (default 0), optional priority
(default 0), optional id (default {from}__to__{to}__if__{condition}).
A state that is final marks the end of the episode once reached. Note that
final and initial may coexist on the same state.
state_id
property
¶
state_idx
property
¶
is_final
property
¶
True once the machine is in a state marked final.
__init__(cfg_rm)
¶
reset()
¶
Return to the unique initial state.
step(labels)
¶
Consume a list of true condition labels; take a transition if any.
Returns the reward issued this step: the transition reward if an activated transition is taken, otherwise the current state's reward (default 0). The current state is updated as a side effect.
actions_enabled(state_id=None)
¶
Actions: whether the state imposes action constraints (default True,
set per state with actions.enable).
blocked(state_id=None)
¶
Actions: raw action values blocked in the state (default: current).
The action itself is not known to this FSM; the caller (wrapper) is responsible for enforcing the constraints on the agent's action.
forced(state_id=None)
¶
Actions: raw action value forced in the state, or None.
fallback(state_id=None)
¶
Actions: fallback raw action value for the state, or None.