Class GymEnvironment

java.lang.Object
neqsim.process.ml.GymEnvironment
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SeparatorGymEnv

public abstract class GymEnvironment extends Object implements Serializable
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:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • observationLow

      protected double[] observationLow
      Observation space bounds.
    • observationHigh

      protected double[] observationHigh
    • observationDim

      protected int observationDim
    • actionLow

      protected double[] actionLow
      Action space bounds.
    • actionHigh

      protected double[] actionHigh
    • actionDim

      protected int actionDim
    • envId

      protected String envId
      Environment metadata.
    • maxEpisodeSteps

      protected int maxEpisodeSteps
    • rewardThreshold

      protected double rewardThreshold
    • currentStep

      protected int currentStep
      Episode 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

      public GymEnvironment.ResetResult reset(Long seed, Map<String,Object> options)
      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

      public GymEnvironment.StepResult step(double[] action)
      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

      protected abstract double[] resetInternal(Map<String,Object> options)
      Internal reset implementation. Override in subclass.
      Parameters:
      options - reset options
      Returns:
      initial observation
    • stepInternal

      protected abstract GymEnvironment.StepResult stepInternal(double[] action)
      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

      public String getEnvId()
      Get environment ID.
      Returns:
      environment identifier
    • 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