# hub.solver.openevolve.api_extraction

Domain specification

Domain

# _extract_domain_characteristics

_extract_domain_characteristics(
  domain_cls: type[skdecide.domains.Domain]
) -> dict[str, type[typing.Any]]

Extract domain characteristics defined by builders mixins.

e.g. agent -> SingleAgent observability -> FullyObservable ...

# _get_characteristic_docstring_summary

_get_characteristic_docstring_summary(
  mixin: type[typing.Any]
) ->

Extract and clean docstring first line of a builders mixin.

# _format_domain_capabilities_for_prompt

_format_domain_capabilities_for_prompt(
  domain_capabilities: dict[str, type[typing.Any]],
subtitle_level: = 1,
add_docstring_summary: = True
) ->

Format for prompt list of domain mixins.

# _extract_domain_base_types

_extract_domain_base_types(
  domain_cls: type[skdecide.domains.Domain],
skip_predefined: = True,
only_predefined: = False
) -> dict[str, type[typing.Any]]

Extract base types T_event, T_state, ... from the domain class

Skip types that are defined (and unchanged) by characteristic mixins:

  • T_memory -> skdecide.builders.domain.memory
  • T_agent -> skdecide.builders.domain.agent
  • ...

# Parameters

  • domain_cls
  • skip_predefined: if True, skip types that are defined (and unchanged) by characteristic mixins (T_memory -> skdecide.builders.domain.memory, T_agent -> skdecide.builders.domain.agent, ...) only_predefined: if True, skip non-predefined types (state, obs, action, ...)

# Returns

# is_class_to_document

is_class_to_document(
  cls: type[typing.Any],
domain_cls: typing.Optional[type[skdecide.domains.Domain]] = None,
include_hub_api: = True,
include_domain_cls_module: = True,
user_modules: typing.Optional[list[module]] = None
) ->

Check whether the class is to be included in generated doc.

Used when in recursive mode.

Filter the class according to the module it came from:

  • from skdecide core: always taken
  • from skecide hub: if include_hub_api
  • from the same module as the main domain class domain_cls: if include_domain_cls_module
  • from another module: if listed in user_modules

# Parameters

  • cls
  • domain_cls
  • include_hub_api
  • include_domain_cls_module
  • user_modules

Returns

# ApiExtractionParams

Parameters for api extraction and formating

# Attributes

  • recursive: if True, extract also the api for classes found in method/attribute annotations, according to some filters (see include_hub_api, include_domain_cls_module, and user_modules)
  • strip_admonitions: whether stripping admonitions like "!!! tip" or "!!! warning" from dosctrings
  • extract_observation_space_cls: whether using a domain instance to extract the observation space class Can be set to False if domain.get_observation_space() is too costly.
  • extract_action_space_cls: whether using a domain instance to extract the action space class Can be set to False if domain.get_observation_space() is too costly.
  • simplify_signature: whether simplifying method signatures, i.e. replace D.T_agent, T_memory and T_concurrency according to mixins and flatten Union's
  • include_hub_api: if recursive, extract api for classes defined in submodules from skdecide.hub
  • include_domain_cls_module: if recursive, extract api for classes defined in the same module as the domain class
  • user_modules: if recursive, extract api for classes defined in the listed modules
  • subtitle_level: level of subtitle to use (if nested)

# generate_public_api

generate_public_api(
  cls: type[typing.Any],
domain_cls: typing.Optional[type[typing.Any]] = None,
domain: typing.Optional[skdecide.domains.Domain] = None,
params: typing.Optional[skdecide.hub.solver.openevolve.api_extraction.ApiExtractionParams] = None
) ->

Generate a markdown string describing the public api of the class

# Parameters

  • cls: class to document
  • domain_cls: domain class for which these apis are required. Default to cls if it is a domain class.
  • domain: if provided, this domain instance is used to detect action space and observation space class (in order to expose their api) params: other parameters passed to generate_public_apis(), see ApiExtractionParams doc.

# Returns

# generate_public_apis

generate_public_apis(
  classes: list[type[typing.Any]],
subtitle_level: = 1,
recursive: = False,
domain_cls: typing.Optional[type[typing.Any]] = None,
domain: typing.Optional[skdecide.domains.Domain] = None,
strip_admonitions: = False,
extract_observation_space_cls: = True,
extract_action_space_cls: = True,
simplify_signature: = True,
include_hub_api: = True,
include_domain_cls_module: = True,
user_modules: typing.Optional[list[module]] = None
) ->

Generate a markdown string describing the public api of the class

# Parameters

  • classes: classes to document
  • subtitle_level: level of subtitle to use (if nested)
  • recursive: if True, also document the classes found in method/attribute annotations, that are filtered by is_class_to_document
  • domain_cls: domain class for which these apis are required
  • domain: if provided, this domain instance is used to detect action space and observation space class (in order to expose their api)
  • strip_admonitions: whether stripping admonitions like "!!! tip" or "!!! warning" from dosctrings
  • extract_observation_space_cls: whether using the domain instance to extract the observation space class
  • extract_action_space_cls: whether using the domain instance to extract the action space class
  • simplify_signature: whether simplifying method signatures (replacing D.T_agent, T_memory and T_concurrency according to mixins, and flattening Union's)
  • include_hub_api: see is_class_to_document
  • include_domain_cls_module: see is_class_to_document
  • user_modules: see is_class_to_document

# Returns

# Api

Summary of public api for a class.

# format_api_for_prompt

format_api_for_prompt(
  api: ,
subtitle_level: = 1
) ->

Format api extracted via get_public_apis() for prompt.

# Parameters

  • api
  • subtitle_level

# Returns

# get_public_apis

get_public_apis(
  classes: list[type[typing.Any]],
recursive: = True,
domain_cls: typing.Optional[type[typing.Any]] = None,
domain: typing.Optional[skdecide.domains.Domain] = None,
strip_admonitions: = False,
extract_observation_space_cls: = True,
extract_action_space_cls: = True,
simplify_signature: = True,
include_hub_api: = True,
include_domain_cls_module: = True,
user_modules: typing.Optional[list[module]] = None
) -> list[skdecide.hub.solver.openevolve.api_extraction.Api]

Maps each class to its public api represented as a dict.

# Parameters

  • classes: list of classes to document
  • recursive: if True, also document the classes found in method/attribute annotations, that are filtered by is_class_to_document
  • domain_cls: domain class for which these apis are required
  • domain: if provided, this domain instance is used to detect action space and observation space class (in order to expose their api)
  • strip_admonitions: whether stripping admonitions like "!!! tip" or "!!! warning" from dosctrings
  • extract_observation_space_cls: whether using the domain instance to extract the observation space class
  • extract_action_space_cls: whether using the domain instance to extract the action space class
  • simplify_signature: whether simplifying method signatures (replacing D.T_agent, T_memory and T_concurrency according to mixins, and flattening Union's)
  • include_hub_api: see is_class_to_document
  • include_domain_cls_module: see is_class_to_document
  • user_modules: see is_class_to_document

# _simplify_signature_repr

_simplify_signature_repr(
  sig: ,
domain_cls: typing.Optional[type[skdecide.domains.Domain]]
) ->

Simplify method signature.

Replace D.T_xxx by their counterpart defined in characteristic mixins

  • T_agent -> Union (SingleAgent) or StrDict (Multigent)
  • T_concurrency
  • T_memory

Remove extra Union having only one argument.

# _extract_simple_types_from_nested_type

_extract_simple_types_from_nested_type(
  t: type[typing.Any]
) -> set[type[typing.Any]]

Recursively extracts base types from nested generics. Returns a set of type objects. Exclude Any, Union, and other special typing types.

# _parse_attributes_doc_with_ast

_parse_attributes_doc_with_ast(
  cls: type[typing.Any],
strip_admonitions: = False
) -> dict[str, str]

Extract class attributes doc with ast Parses the class source to map attributes names to the docstrings written immediately below them.