Module Fehu.InfoSource

Auxiliary diagnostic information from environment interactions.

Info dictionaries carry metadata like episode steps, debug values, or environment state. Environments return info from reset and step operations.

Auxiliary information dictionaries for environment transitions.

Info dictionaries attach metadata to observations and transitions, such as diagnostic information, intermediate values, or episode statistics. They use a schemaless key-value structure similar to JSON, allowing flexible data passing without rigid type constraints.

Usage

Create and populate info dictionaries:

  let info =
    Info.empty
    |> Info.set "episode_length" (Info.int 42)
    |> Info.set "success" (Info.bool true)

Retrieve values:

  match Info.find "episode_length" info with
  | Some (Int n) -> Printf.printf "Episode length: %d\n" n
  | _ -> ()

Merge info from different sources:

  let combined = Info.merge env_info wrapper_info
Sourcetype value =
  1. | Null
    (*

    Null/None value

    *)
  2. | Bool of bool
    (*

    Boolean value

    *)
  3. | Int of int
    (*

    Integer value

    *)
  4. | Float of float
    (*

    Floating-point value

    *)
  5. | Int_array of int array
    (*

    Array of integers

    *)
  6. | Float_array of float array
    (*

    Array of floats

    *)
  7. | Bool_array of bool array
    (*

    Array of booleans

    *)
  8. | String of string
    (*

    String value

    *)
  9. | List of value list
    (*

    List of values

    *)
  10. | Dict of (string * value) list
    (*

    Nested dictionary

    *)

Universal value type for info dictionaries.

Supports common data types with arbitrary nesting.

Sourcetype t

Immutable key-value dictionary for auxiliary information.

Sourceval empty : t

empty is the empty info dictionary with no entries.

Sourceval is_empty : t -> bool

is_empty info checks whether info contains any entries.

Sourceval singleton : string -> value -> t

singleton key value creates an info dictionary with a single entry.

Sourceval set : string -> value -> t -> t

set key value info returns a new dictionary with key bound to value.

If key already exists, its value is replaced.

Sourceval update : string -> (value option -> value option) -> t -> t

update key f info updates the value at key using function f.

f receives Some old_value if key exists, None otherwise. If f returns Some new_value, key is bound to new_value; if None, key is removed.

Sourceval find : string -> t -> value option

find key info looks up key in info.

Returns Some value if key exists, None otherwise.

Sourceval get_exn : string -> t -> value

get_exn key info retrieves the value at key.

Sourceval merge : t -> t -> t

merge info1 info2 combines two dictionaries.

Keys from info2 override those in info1 when both are present.

Sourceval to_list : t -> (string * value) list

to_list info converts info to an association list.

Sourceval of_list : (string * value) list -> t

of_list entries creates an info dictionary from an association list.

Sourceval null : value

null constructs a null value.

Sourceval bool : bool -> value

bool b constructs a boolean value.

Sourceval int : int -> value

int n constructs an integer value.

Sourceval float : float -> value

float x constructs a float value.

Non-finite values (nan, +∞, -∞) round-trip via JSON using sentinel strings and are restored on deserialization.

Sourceval int_array : int array -> value

int_array arr constructs an integer array value.

Sourceval float_array : float array -> value

float_array arr constructs a float array value.

Sourceval bool_array : bool array -> value

bool_array arr constructs a boolean array value.

Sourceval string : string -> value

string s constructs a string value.

Sourceval list : value list -> value

list values constructs a list value.

Sourceval dict : (string * value) list -> value

dict entries constructs a nested dictionary value.

Sourceval to_yojson : t -> Yojson.Safe.t

to_yojson info serializes info to JSON.

Sourceval of_yojson : Yojson.Safe.t -> (t, string) result

of_yojson json deserializes info from JSON.

Returns Error msg if the JSON structure is invalid.