sciencegym.problems.problem_interface module

class sciencegym.problems.problem_interface.ProblemInterface(sim: SimulationInterface)

Bases: object

High‑level wrapper that turns a domain‑specific SimulationInterface into a Gym‑style environment component.

The class does not inherit from gym.Env on purpose; instead it exposes Gym‑compatible spaces so that downstream wrappers (or RL frameworks such as Stable‑Baselines3) can use them to validate actions and observations.

Parameters:

sim (SimulationInterface) – Concrete simulation that implements at least: step, reset, get_state_space and get_action_space. See simulation attribute below for details.

simulation

Handle to the low‑level physics, chemistry or epidemiology simulator (depending on the chosen Science‑Gym task). All environment dynamics are delegated to this object.

Type:

SimulationInterface

observation_space

Space describing the structure, bounds and dtype of observations returned by the simulator. Required by every Gym‑compatible environment to enable sampling, shape introspection, and automatic sanity checks.

Type:

gym.spaces.Space

action_space

Space that defines the legal actions the agent may send to simulation.step(). Ensures that RL algorithms can clamp, sample, or otherwise reason about admissible controls.

Type:

gym.spaces.Space

Examples

>>> from sciencegym.problems import Pendulum
>>> core_sim = Pendulum()
>>> env = ProblemInterface(core_sim)
>>> print(env.observation_space.shape)   # e.g. (3,)
>>> sample_action = env.action_space.sample()
>>> next_state = env.simulation.step(sample_action)

Notes

  • This adapter is part of Science‑Gym, a research benchmark

intended for agents that actively design and conduct experiments before attempting tasks such as symbolic regression on the generated data. * Because ProblemInterface defers the full Gym five‑tuple logic to higher‑level wrappers, it is lightweight and easy to subclass when adding new scientific domains.

evaluation(candidate: Equation, data: pandas.DataFrame)

Performs evaluation of the candidate solution to the current Problem. Since :class:`Problem`s might have more than one solution, this is evaluated against all available solutions.

Parameters:
  • candidate (Equation) – The current

  • data (pd.DataFrame) – _description_

Returns:

_description_

Return type:

_type_

get_action_space()

Retrieve the action space definition.

Returns:

Space object describing the legal range, shape and dtype of admissible actions.

Return type:

gym.spaces.Space

get_current_state()

Mirrored from Simulation. Return the most recently observed state without advancing the simulation.

Useful for logging, inspection or state‑feedback control that needs the raw observation.

Returns:

Snapshot of the current state held internally by the simulation.

Return type:

numpy.ndarray

get_simulation()

Expose the wrapped Simulation instance.

Returns:

The underlying simulation object—handy for unit tests, visualisers or fine‑grained diagnostic tools that need direct access.

Return type:

Simulation

get_state_space()

Retrieve the observation/state space definition.

Returns:

A Gym‐compatible space object (e.g. gym.spaces.Box or gym.spaces.Dict) describing the dimensionality, bounds and dtype of observations emitted by the environment.

Return type:

gym.spaces.Space

solution()

Returns the solution or solutions for the current problem.

step(action)

Advance the simulation by one control cycle.

Parameters:

action (numpy.ndarray) – Experimental action to be performed. Its datatype and shape must conform to action_space, which is delegated to the underlying simulation.

Returns:

Whatever the wrapped Simulation.step() returns. In most Gym‑style simulators this will be the 5‑tuple (next_obs, reward, terminated, truncated, info); in lighter setups it may be just next_obs. Refer to your Simulation implementation for the exact signature.

Return type:

object

Notes

No extra post‑processing or validation is performed—the call is passed straight through.

validate_context()

Validates the context of the problem’s simulation, see Section 4.2 of https://dl.acm.org/doi/10.1007/978-3-031-78977-9_15. Currently, work in progress.