Typeguards

These functions let you test which interfaces an object implements.

Unlike naive isinstance() checks, these functions takes Gymnasium Wrappers into account and unwrap them. For convenience when using Mypy, all functions return a TypeGuard.

The functions with name is_type_class() are relatively simple wrappers around issubclass(). They work around some weaknesses in Mypy’s error reporting, and provide symmetry with the is_type() functions based on isinstance().

cernml.coi.AnyOptimizable

alias of SingleOptimizable[ParamType] | FunctionOptimizable[ParamType]

cernml.coi.is_optimizable(obj: object, /) TypeGuard[AnyOptimizable]

Combined check for SingleOptimizable/FunctionOptimizable.

cernml.coi.is_optimizable_class(obj: object, /) TypeGuard[type[AnyOptimizable]]

Combined check for SingleOptimizable/FunctionOptimizable.

cernml.coi.is_single_optimizable(obj: object, /) TypeGuard[SingleOptimizable[Any]]

Check whether the given object is a SingleOptimizable.

cernml.coi.is_single_optimizable_class(obj: object, /) TypeGuard[type[SingleOptimizable[Any]]]

Check whether the given type is a subclass of SingleOptimizable.

cernml.coi.is_function_optimizable(obj: object, /) TypeGuard[FunctionOptimizable]

Check whether the given object is a FunctionOptimizable.

cernml.coi.is_function_optimizable_class(obj: object, /) TypeGuard[type[FunctionOptimizable]]

Check whether the given type is a subclass of FunctionOptimizable.

cernml.coi.is_env(obj: object, /) TypeGuard[Env]

Check whether the given object is an Env.

cernml.coi.is_env_class(obj: object, /) TypeGuard[type[Env]]

Check whether the given type is a subclass of Env.

cernml.coi.is_goal_env(obj: object, /) TypeGuard[GoalEnv]

Check whether the given object is a GoalEnv.

cernml.coi.is_goal_env_class(obj: object, /) TypeGuard[type[GoalEnv]]

Check whether the given type is a subclass of GoalEnv.

cernml.coi.is_separable_env(obj: object, /) TypeGuard[SeparableEnv]

Check whether the given object is a SeparableEnv.

cernml.coi.is_separable_env_class(obj: object, /) TypeGuard[type[SeparableEnv]]

Check whether the given type is a subclass of SeparableEnv.

cernml.coi.is_separable_goal_env(obj: object, /) TypeGuard[SeparableGoalEnv]

Check whether the given object is a SeparableGoalEnv.

cernml.coi.is_separable_goal_env_class(obj: object, /) TypeGuard[type[SeparableGoalEnv]]

Check whether the given type is a subclass of SeparableGoalEnv.

cernml.coi.is_problem(obj: object, /) TypeGuard[Problem]

Check whether the given object is a Problem.

cernml.coi.is_problem_class(obj: object, /) TypeGuard[type[Problem]]

Check whether the given type is a subclass of Problem.

cernml.coi.is_configurable(obj: object, /) TypeGuard[Configurable]

Check whether the given object is Configurable.

cernml.coi.is_configurable_class(obj: object, /) TypeGuard[type[Configurable]]

Check whether the given type is a subclass of Configurable.

cernml.coi.is_custom_optimizer_provider(obj: object, /) TypeGuard[CustomOptimizerProvider]

Check whether the given object is a CustomOptimizerProvider.

cernml.coi.is_custom_optimizer_provider_class(
obj: object,
/,
) TypeGuard[type[CustomOptimizerProvider]]

Check whether the type is a subclass of CustomOptimizerProvider.