Skip to content

API (Rust → Python bindings)

The core_rust module exposes the Rust core to Python via pyo3. It lets Python construct worlds, run MCTS episodes, draw artifacts, and assemble matrices required for scoring. The bindings are implemented in src/lib.rs and wrap types and functions from src/core/*.

Bindings

  • PyRunner(py_world: list[list[str]], abstracted: bool, py_abstraction: list[list[int]] | None)
  • Create a runner that executes either in the ground MDP (abstracted=False) or in an abstract MDP (abstracted=True, optional py_abstraction).
  • .run(sim_limit: int, sim_depth: int, c: float, gamma: float, seed: int | None, max_turns: int, runs: int, debug: bool, show_mcts: bool)list[tuple[int, float, tuple[int, int]]].
  • max_returns(py_world, gamma) -> float
  • Return the maximum discounted return from the initial state.
  • min_turns(py_world) -> int
  • Return the minimum number of turns to reach the goal.
  • visualize_world_map(py_world, output_dir) / visualize_abstraction(py_world, output_dir)
  • Save map.png and abstraction.png to output_dir.
  • generate_representations_py(py_world) -> dict
  • Return map encodings: {"json": str, "text": str, "adj": str}.
  • generate_mdp(py_world) -> dict
  • Return {"T": ndarray, "R": ndarray, "abstraction": list[list[int]]} for scoring.
  • get_number_of_states(py_world) -> int
  • Report the number of reachable ground states.

Internals

These bindings delegate to the Rust Game implementation (core::game::game_logic::Game), the abstraction routines (core::abstraction::homomorphism::get_abstraction), the matrix builder (core::utils::matrices::build_matrices), and the MCTS runner (core::runner::Runner).

Rustdoc

Full API documentation generated by cargo doc is bundled with the site. Browse it here: