Class GymEnvironment
java.lang.Object
neqsim.process.ml.GymEnvironment
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SeparatorGymEnv
Gymnasium (OpenAI Gym) compatible environment interface for NeqSim.
This class provides a standardized interface compatible with Python's Gymnasium library, enabling seamless integration with popular RL frameworks like stable-baselines3, RLlib, and CleanRL.
Python Usage via JPype:
import jpype
from jpype import JClass
GymEnvironment = JClass('neqsim.process.ml.GymEnvironment')
env = MySeparatorEnv() # extends GymEnvironment
obs = env.reset()
for _ in range(1000):
action = agent.predict(obs)
obs, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
obs = env.reset()
- Version:
- 1.0
- Author:
- ESOL
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classReset result matching Gymnasium API.static classStep result matching Gymnasium API. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected double[]protected double[]Action space bounds.protected intEpisode state.protected StringEnvironment metadata.protected doubleprotected intprotected intprotected double[]protected double[]Observation space bounds.protected doubleprivate static final longprotected booleanprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected double[]clipAction(double[] action) Clip action to valid bounds.intGet action space dimension.double[]Get action space upper bounds.double[]Get action space lower bounds.intGet current episode step.getEnvId()Get environment ID.doubleGet cumulative episode reward.intGet maximum episode steps.intGet observation space dimension.double[]Get observation space upper bounds.double[]Get observation space lower bounds.booleanisDone()Check if environment is done (terminated or truncated).reset()Reset the environment to initial state.Reset the environment with optional seed and options.protected abstract double[]resetInternal(Map<String, Object> options) Internal reset implementation.voidsetMaxEpisodeSteps(int maxSteps) Set maximum episode steps.protected voidsetSeed(long seed) Set random seed for reproducibility.step(double[] action) Take a step in the environment.protected abstract GymEnvironment.StepResultstepInternal(double[] action) Internal step implementation.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
observationLow
protected double[] observationLowObservation space bounds. -
observationHigh
protected double[] observationHigh -
observationDim
protected int observationDim -
actionLow
protected double[] actionLowAction space bounds. -
actionHigh
protected double[] actionHigh -
actionDim
protected int actionDim -
envId
Environment metadata. -
maxEpisodeSteps
protected int maxEpisodeSteps -
rewardThreshold
protected double rewardThreshold -
currentStep
protected int currentStepEpisode state. -
episodeReward
protected double episodeReward -
terminated
protected boolean terminated -
truncated
protected boolean truncated
-
-
Constructor Details
-
GymEnvironment
public GymEnvironment()
-
-
Method Details
-
reset
Reset the environment to initial state.Gymnasium API:
obs, info = env.reset()- Returns:
- ResetResult with initial observation and info
-
reset
Reset the environment with optional seed and options.- Parameters:
seed- random seed for reproducibility (nullable)options- additional reset options (nullable)- Returns:
- ResetResult with initial observation and info
-
step
Take a step in the environment.Gymnasium API:
obs, reward, terminated, truncated, info = env.step(action)- Parameters:
action- action array (continuous values)- Returns:
- StepResult with next observation, reward, termination flags, and info
-
clipAction
protected double[] clipAction(double[] action) Clip action to valid bounds.- Parameters:
action- raw action- Returns:
- clipped action
-
resetInternal
-
stepInternal
Internal step implementation. Override in subclass.- Parameters:
action- clipped action- Returns:
- step result
-
setSeed
protected void setSeed(long seed) Set random seed for reproducibility.- Parameters:
seed- random seed
-
getObservationDim
public int getObservationDim()Get observation space dimension.- Returns:
- observation dimension
-
getActionDim
public int getActionDim()Get action space dimension.- Returns:
- action dimension
-
getObservationLow
public double[] getObservationLow()Get observation space lower bounds.- Returns:
- lower bounds array
-
getObservationHigh
public double[] getObservationHigh()Get observation space upper bounds.- Returns:
- upper bounds array
-
getActionLow
public double[] getActionLow()Get action space lower bounds.- Returns:
- lower bounds array
-
getActionHigh
public double[] getActionHigh()Get action space upper bounds.- Returns:
- upper bounds array
-
getEnvId
-
getMaxEpisodeSteps
public int getMaxEpisodeSteps()Get maximum episode steps.- Returns:
- max steps
-
setMaxEpisodeSteps
public void setMaxEpisodeSteps(int maxSteps) Set maximum episode steps.- Parameters:
maxSteps- max steps
-
isDone
public boolean isDone()Check if environment is done (terminated or truncated).- Returns:
- true if episode ended
-
getCurrentStep
public int getCurrentStep()Get current episode step.- Returns:
- step count
-
getEpisodeReward
public double getEpisodeReward()Get cumulative episode reward.- Returns:
- total reward
-