gym_tl_tools.parser

Functions

replace_special_characters(spec)

Replace special characters in the spec with underscores so that it can be used as a file name.

Classes

Parser()

ParserSymbol(*, priority, func)

Represents a symbol in the parser with its priority and function.

class gym_tl_tools.parser.Parser[source]

Bases: object

evaluate(parsed_tokens: list[str], var_dict: dict[str, float]) float[source]

Checking from the start, get tokens from the stack and compute there if there is a symbol

get_func(s: str) Callable[[...], Any][source]
get_priority(s: str) int[source]
is_num(s: str) bool[source]
is_parentheses(s: str, **kwargs) bool[source]
is_symbol(s: Any) bool[source]
is_var(s: str, var_names: list[str]) bool[source]
parse(token_list: list[str], var_names: list[str]) list[str][source]

Convert the token to Reverse Polish Notation

tl2rob(spec: str, var_dict: dict[str, float]) float[source]

Parsing a TL spec to its robustness

Parameters:
  • spec (str) – The TL spec to be parsed. e.g. “psi_1 & psi_2 | !psi_3”.

  • var_dict (dict[str, float]) – A dictionary mapping the variable names used in the TL spec to their current values. The keys should match the names of the atomic predicates defined in the spec. e.g. {“d_robot_goal”: 3.0, “d_robot_obstacle”: 1.0, “d_robot_goal”: 0.5}.

Returns:

robustness – The robustness value of the TL spec given the variable values. A positive value indicates satisfaction, while a negative value indicates violation.

Return type:

float

tokenize(spec: str) list[str][source]
class gym_tl_tools.parser.ParserSymbol(*, priority: int, func: Callable[[...], Any])[source]

Bases: BaseModel

Represents a symbol in the parser with its priority and function.

priority

The priority of the symbol, used for parsing precedence.

Type:

int

func

The function that implements the operation of the symbol. It should take the appropriate number of arguments and return a value.

Type:

Callable[…, Any]

func: Callable[[...], Any]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

priority: int
gym_tl_tools.parser.replace_special_characters(spec: str) str[source]

Replace special characters in the spec with underscores so that it can be used as a file name.

Parameters:

spec (str) – spec to be replaced. The spec can contain special characters like spaces, &, |, etc. These characters are replaced with underscores to create a valid file name.

Returns:

replaced_spec – spec with special characters replaced by underscores

Return type:

str

Examples

`python spec = replace_special_characters("F(psi_1 | psi_2) & G(!psi_3)") print(spec) # Output: "F(psi_1_or_psi_2)_and_G(!psi_3)" `