releso.parser_environment.Environment
- class releso.parser_environment.Environment(*, save_location: Path, logger_name: str | None = None, multi_processing: MultiProcessing | None = None, geometry: Geometry | FFDGeometry, spor: SPORList, max_timesteps_in_episode: ConstrainedIntValue | None = None, end_episode_on_geometry_not_changed: bool = False, reward_on_geometry_not_changed: float | None = None, reward_on_episode_exceeds_max_timesteps: float | None = None)
Bases:
BaseModelParser class of which the environment is based.
Parser Environment object is created by pydantic during the parsing of the json object defining the RL based Shape optimization. Each object can create a gym environment that represents the given problem.
- __init__(**data: Any) None
Construct the object.
Methods
close()Function is called when training is stopped.
convert_to_pathlib_add_datetime(v)Add timestamp to save_location, of applicable.
get_gym_environment([logging_information])Creates the parametrized gymnasium environment.
get_logger()Gets the currently defined environment logger.
Return the validation id of the current run, if applicable.
Check if environment uses multiprocessing.
reset([seed])Resets the environment.
set_logger_name_recursively(logger_name)Set the logger_name variable for all child elements.
set_validation(validation_values[, ...])Converts the environment to a validation environment.
step(action)Performs the step of the environment.
Attributes
defines if multi-processing can be used.
definition of the Geometry
definition of the spor objects
maximal number of timesteps to run each episode for
whether or not to reset the environment if the geometry has not change after a step
reward if episode is ended due to reaching max step in episode
reward if episode is ended due to geometry not changed
save_locationDefinition of the save location of the logs and validation results.
logger_namename of the logger.
- close()
Function is called when training is stopped.
- end_episode_on_geometry_not_changed: bool
whether or not to reset the environment if the geometry has not change after a step
- geometry: Geometry | FFDGeometry
definition of the Geometry
- get_gym_environment(logging_information: Dict[str, str | Path | VerbosityLevel] | None = None) gymnasium.Env
Creates the parametrized gymnasium environment.
Creates and configures the gymnasium environment so it can be used for training.
- Returns:
- OpenAI gymnasium environment that can be used to
train with stable_baselines[3] agents.
- Return type:
gymnasium.Env
- get_validation_id() int | None
Return the validation id of the current run, if applicable.
Checks if current environment has validation values if return the correct one otherwise return None.
- Returns:
Check text above.
- Return type:
Optional[int]
- is_multiprocessing() int
Check if environment uses multiprocessing.
Function checks if the environment is setup to be used with multiprocessing Solver. Returns the number of cores the solver should use. If no multiprocessing 1 core is returned.
- Returns:
- Number of cores used in multiprocessing. 1 If no
multiprocessing. (Single thread still ok.)
- Return type:
int
- max_timesteps_in_episode: ConstrainedIntValue | None
maximal number of timesteps to run each episode for
- multi_processing: MultiProcessing | None
defines if multi-processing can be used.
- reset(seed: int | None = None) ndarray | Dict[str, ndarray] | Tuple[ndarray, ...]
Resets the environment.
This can either be the case if the episode is done due to #time_steps or the environment emits the done signal.
- Parameters:
seed (Optional[int], optional) – Seed for the environment. Defaults
None. (to)
- Returns:
Observation of the newly reset environment.
- Return type:
Tuple[Any]
- reward_on_episode_exceeds_max_timesteps: float | None
reward if episode is ended due to geometry not changed
- reward_on_geometry_not_changed: float | None
reward if episode is ended due to reaching max step in episode
- set_validation(validation_values: List[float], end_episode_on_geometry_not_changed: bool = False, max_timesteps_in_episode: int = 0, reward_on_geometry_not_changed: float | None = None, reward_on_episode_exceeds_max_timesteps: float | None = None)
Converts the environment to a validation environment.
This environment now only sets the goal states to the predefined values.
- Parameters:
validation_values (List[float]) – List of predefined goal states. base_mesh_path (Optional[str], optional): Path to the initial mesh. Defaults to None.
end_episode_on_geometry_not_changed (bool, optional) – Should the episode end if the geometry has no changes from one episode to the next. Defaults to False.
max_timesteps_in_episode (int, optional) – Maximal timesteps per episode, if 0 no limit. Defaults to 0.
reward_on_geometry_not_changed (float, optional) – Reward to give if episode is terminated due to unchanged geometry. Defaults to None.
reward_on_episode_exceeds_max_timesteps (float, optional) – Reward given of the episode is terminated due to exceeding the max_timesteps_in_episode. Defaults to None.
save_image_in_validation (bool, optional) – Should the validation save periodically the geometry/visualization. Is broken. Defaults to False.
- step(action: Any) Tuple[Any, float, bool, Dict[str, Any]]
Performs the step of the environment.
Function that is called for each step. Contains all steps that are performed during each step inside the environment.
There was a change of what the step function returns. It now returns the following values:
observation
reward
terminated
truncated
info
The change was that done was split into terminated and truncated. Terminated is now True if the episode is done. Truncated is True if the episode was ended due to the maximum number of steps, gone outside of physical bounds or action values.
This change is really interesting for us as it means that we might be able to handle the termination of the episode other than goal_states better. Currently truncated is set to False to make it compatible. Needs work to be put in to allow this information to propagate correctly.
- Parameters:
action (Any) – Action value depends on if the ActionSpace is
discrete (int - Signifier of the action)
continuous (Continuous (List[float] - Value for each)
variable.)
- Returns:
[description]
- Return type:
Tuple[Any, float, bool, bool, Dict[str, Any]]