farmgym_games.Farm1

class farmgym_games.Farm1(api_compatibility=False)[source]

Bases: Env

Farm1 is a difficult 1x1 farm with only one possible plant : beans, planted in a clay ground. The advised maximum episode length is 365 (as in 365 days).

The Farm has the weather of Lille in France (e.g. well suited for the culture of beans), the initial day is 1. Initially the field is healthy and contains all the nutrient necessary to the plant.

The reward is the number of grams of harvested beans, and there is a negative reward for very low microlife in soil (due to pesticides).

The condition for end of episode (self.step returns done) is that the day is >= 365 or that the plant is dead.

Parameters:
api_compatibility: False

If true apply step api compatibility to gym version 0.21. See https://www.gymlibrary.dev/api/utils/#gym.utils.step_api_compatibility.step_api_compatibility.

Attributes:
np_random

Returns the environment’s internal _np_random that if not set will initialise with a random seed.

render_mode
spec
unwrapped

Returns the base non-wrapped environment.

Notes

State:

The state consists of

  • Day (from 1 to 365)

  • mean air temperature (°C)

  • min air temperature (°C)

  • max air temperature (°C)

  • rain amount (mm)

  • sun-exposure (from 1 to 5)

  • consecutive dry day (int)

  • stage of growth of the plant (int)

  • size of the plant in cm.

  • Soil wet_surface#m2.day-1

  • fertilizer amount#kg

  • Pests plot_population#nb

  • Pollinators occurrence#bin

  • Weeds grow#nb

  • Weeds flowers#nb

  • Weight of fruits (g)

  • Microlife health index (%)

Actions:

The actions are :

  • doing nothing.

  • 2 levels of watering the field (1L or 5L of water)

  • harvesting

  • sow some seeds

  • scatter fertilizer

  • scatter herbicide

  • scatter pesticide

  • remove weeds by hand

Methods

close()

Override close in your subclass to perform any necessary cleanup.

render()

Compute the render frames as specified by render_mode attribute during initialization of the environment.

reset()

Resets the environment to an initial state and returns the initial observation.

step(action)

Run one timestep of the environment's dynamics.

num_to_action

close()

Override close in your subclass to perform any necessary cleanup.

Environments will automatically close() themselves when garbage collected or when the program exits.

property np_random: Generator

Returns the environment’s internal _np_random that if not set will initialise with a random seed.

render() Optional[Union[RenderFrame, List[RenderFrame]]]

Compute the render frames as specified by render_mode attribute during initialization of the environment.

The set of supported modes varies per environment. (And some third-party environments may not support rendering at all.) By convention, if render_mode is:

  • None (default): no render is computed.

  • human: render return None. The environment is continuously rendered in the current display or terminal. Usually for human consumption.

  • rgb_array: return a single frame representing the current state of the environment. A frame is a numpy.ndarray with shape (x, y, 3) representing RGB values for an x-by-y pixel image.

  • rgb_array_list: return a list of frames representing the states of the environment since the last reset. Each frame is a numpy.ndarray with shape (x, y, 3), as with rgb_array.

  • ansi: Return a strings (str) or StringIO.StringIO containing a terminal-style text representation for each time step. The text can include newlines and ANSI escape sequences (e.g. for colors).

Note:

Make sure that your class’s metadata ‘render_modes’ key includes the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.

reset()[source]

Resets the environment to an initial state and returns the initial observation.

This method can reset the environment’s random number generator(s) if seed is an integer or if the environment has not yet initialized a random number generator. If the environment already has a random number generator and reset() is called with seed=None, the RNG should not be reset. Moreover, reset() should (in the typical use case) be called with an integer seed right after initialization and then never again.

Args:
seed (optional int): The seed that is used to initialize the environment’s PRNG.

If the environment does not already have a PRNG and seed=None (the default option) is passed, a seed will be chosen from some source of entropy (e.g. timestamp or /dev/urandom). However, if the environment already has a PRNG and seed=None is passed, the PRNG will not be reset. If you pass an integer, the PRNG will be reset even if it already exists. Usually, you want to pass an integer right after the environment has been initialized and then never again. Please refer to the minimal example above to see this paradigm in action.

options (optional dict): Additional information to specify how the environment is reset (optional,

depending on the specific environment)

Returns:
observation (object): Observation of the initial state. This will be an element of observation_space

(typically a numpy array) and is analogous to the observation returned by step().

info (dictionary): This dictionary contains auxiliary information complementing observation. It should be analogous to

the info returned by step().

step(action)[source]

Run one timestep of the environment’s dynamics.

When end of episode is reached, you are responsible for calling reset() to reset this environment’s state. Accepts an action and returns either a tuple (observation, reward, terminated, truncated, info).

Args:

action (ActType): an action provided by the agent

Returns:
observation (object): this will be an element of the environment’s observation_space.

This may, for instance, be a numpy array containing the positions and velocities of certain objects.

reward (float): The amount of reward returned as a result of taking the action. terminated (bool): whether a terminal state (as defined under the MDP of the task) is reached.

In this case further step() calls could return undefined results.

truncated (bool): whether a truncation condition outside the scope of the MDP is satisfied.

Typically a timelimit, but could also be used to indicate agent physically going out of bounds. Can be used to end the episode prematurely before a terminal state is reached.

info (dictionary): info contains auxiliary diagnostic information (helpful for debugging, learning, and logging).

This might, for instance, contain: metrics that describe the agent’s performance state, variables that are hidden from observations, or individual reward terms that are combined to produce the total reward. It also can contain information that distinguishes truncation and termination, however this is deprecated in favour of returning two booleans, and will be removed in a future version.

(deprecated) done (bool): A boolean value for if the episode has ended, in which case further step() calls will return undefined results.

A done signal may be emitted for different reasons: Maybe the task underlying the environment was solved successfully, a certain timelimit was exceeded, or the physics simulation has entered an invalid state.

property unwrapped: Env

Returns the base non-wrapped environment.

Returns:

Env: The base non-wrapped gym.Env instance