farmgym.v2.farm.Farm

class farmgym.v2.farm.Farm(fields, farmers, scoring, rules, policies=None, seed=None)[source]

Bases: Env

Instaniates a Farm environment. Constructed from one or several fields (Field), farmers (Farmer_API), a score (Scoring_API) and a set of rules (Rules_API). The farm can then be constructed through farm=Farm(fields,farmers,scoring,rules).

Parameters:
fieldsa list of fields, that is instances of the class Field

Field used to define the farm.

farmers: a list of farmers, that is instances of a class implementing the :class:`~farmgym.v2.farmer_api.Farmer_API`

Farmers used to define the farm.

scoring: an instance of the :class:`~farmgym.v2.scoring_api.Scoring_API`

Scoring function used to generate the reward of the farm.

rules: an instance of the :class:`~farmgym.v2.rules_api.Rules_API`

Rules used to define the farm (i.e. allowed actions, how to filter actions…)

policies: a list of policies, that is instances of a class implementing the :class:`~farmgym.v2.policy_api.Policy_API`

Expert policies defined in the farm

seed: an integer,

seed used by the random-number generator.

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

At creation, automatically generates yaml configuration files to help customize the farm. One file to specify the list of allowed actions, one file to initialize state variables, and one file to specify the score.

Methods

add_monitoring(list_of_variables)

Adds a Monitor to the farm, allowing to observe evolution of some state variables with time.

build_configurations(dir, name)

dir: path name: string used to name the farm in the yaml filename.

build_farmgym_intervention_actions(action_yaml)

Generates a list of all possible farmgym intervention-actions allowed by the configuration file action_yaml.

build_farmgym_observation_actions(action_yaml)

Generates a list of all possible farmgym observation-actions allowed by the configuration file action_yaml.

build_gym_observation_space()

Outputs an observation space in gym MultiUnion format from all possible observations.

build_gym_state_space()

Outputs a state space in gym Tuple format built from all state variables.

build_name()

Builds a standardized name for the farm as a string.

close()

Override close in your subclass to perform any necessary cleanup.

farmgym_reset([seed, options])

Resets the environment.

farmgym_step(action_schedule)

Performs a step evolution of the system, from current stage to next state given the input action.

get_free_observations()

Outputs free observations available at the current time.

gym_reset([seed, options])

Resets the environment.

gym_step(gym_action)

Performs a step evolution of the system, from current stage to next state given the input action.

gymaction_to_farmgymaction(actions)

Converts actions given in gym format to actions in farmgym format.

intervention_step(action_schedule)

Performs an intervention step, one of the two types of farmgym steps.

observation_step(observation_schedule)

Performs an observation step, one of the two types of farmgym steps.

random_allowed_intervention()

Outputs a randomly generated intervention, in farmgym format.

random_allowed_observation()

Outputs a randomly generated observation-action (action to collect observation), in farmgym format.

render([mode])

Renders the farm at current time for human display as an image.

reset([seed, options])

Resets the environment.

seed([seed])

Modifies the seed of the random generators used in the environment.

step(action)

Performs a step evolution of the system, from current stage to next state given the input action.

add_monitoring(list_of_variables)[source]

Adds a Monitor to the farm, allowing to observe evolution of some state variables with time. list_of_variables: the list of variables to be monitored. The format for one variable is (field,entity,variable,function,name,option). For instance: (“Field-0”,”Plant-0”,”fruits_per_plant#nb”,lambda x: sum_value(x),”Fruits (nb)”,”range_auto”)

build_configurations(dir, name)[source]

dir: path name: string used to name the farm in the yaml filename. Generates yaml configuration files to help customize the farm. One file to specify the list of allowed actions, one file to initialize state variables, and one file to specify the score.

build_farmgym_intervention_actions(action_yaml)[source]

Generates a list of all possible farmgym intervention-actions allowed by the configuration file action_yaml.

build_farmgym_observation_actions(action_yaml)[source]

Generates a list of all possible farmgym observation-actions allowed by the configuration file action_yaml.

build_gym_observation_space()[source]

Outputs an observation space in gym MultiUnion format from all possible observations.

build_gym_state_space()[source]

Outputs a state space in gym Tuple format built from all state variables.

build_name()[source]

Builds a standardized name for the farm as a string. example: Farm_Fields[Field-0[Weather-0_Soil-0_Plant-0]]_Farmers[BasicFarmer-0]

close()

Override close in your subclass to perform any necessary cleanup.

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

farmgym_reset(seed=None, options=None)[source]

Resets the environment.

farmgym_step(action_schedule)[source]

Performs a step evolution of the system, from current stage to next state given the input action. A farm gym step alternates between observation step and action step before moving to next day.

get_free_observations()[source]

Outputs free observations available at the current time.

gym_reset(seed=None, options=None)[source]

Resets the environment.

gym_step(gym_action)[source]

Performs a step evolution of the system, from current stage to next state given the input action. It follows the gym signature, and outputs observations, reward, is_done, information. Farmgym observations are added in information[“farmgym observations”].

gymaction_to_farmgymaction(actions)[source]

Converts actions given in gym format to actions in farmgym format. By construction, this only generates actions in the subset of available actions specified by the configuration file.

intervention_step(action_schedule)[source]

Performs an intervention step, one of the two types of farmgym steps.

property np_random: Generator

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

observation_step(observation_schedule)[source]

Performs an observation step, one of the two types of farmgym steps.

random_allowed_intervention()[source]

Outputs a randomly generated intervention, in farmgym format.

random_allowed_observation()[source]

Outputs a randomly generated observation-action (action to collect observation), in farmgym format.

render(mode='human')[source]

Renders the farm at current time for human display as an image. The image is stored as a png file. Not everything is displayed, depending on display availability of each entity of the farm. The method considerably slows down the code execution hence should only be called for visualization purpose.

reset(seed=None, options=None)[source]

Resets the environment.

seed(seed=None)[source]

Modifies the seed of the random generators used in the environment.

step(action)[source]

Performs a step evolution of the system, from current stage to next state given the input action.

property unwrapped: Env

Returns the base non-wrapped environment.

Returns:

Env: The base non-wrapped gym.Env instance