(sec-module-artificialintelligence)= # Module: artificialIntelligence This library collects interfaces and functionality for artificial intelligence This library is under construction (2022-05); To make use of this libraries, you need to install openAI gym with 'pip install gym'; For standard machine learning algorithms, install e.g. stable_baselines3 using 'pip install stable_baselines3' - **Author**: Johannes Gerstmayr - **Date**: 2022-05-21 (created) (sec-module-artificialintelligence-class-openaigyminterfaceenv(env))= ## CLASS OpenAIGymInterfaceEnv(Env) (in module artificialIntelligence) **class description**: interface class to set up Exudyn model which can be used as model in open AI gym; see specific class functions which contain 'OVERRIDE' to integrate your model; in general, set up a model with CreateMBS(), map state to initial values, initial values to state and action to mbs; (sec-artificialintelligence-openaigyminterfaceenv(env)---init--)= ### Class function: __init__ [`__init__(self, **kwargs)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L53) - **class function description**: internal function to initialize model; store self.mbs and self.simulationSettings; special arguments **kwargs are passed to CreateMBS (sec-artificialintelligence-openaigyminterfaceenv(env)-creatembs)= ### Class function: CreateMBS [`CreateMBS(self, SC, mbs, simulationSettings, **kwargs)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L86) - **class function description**: OVERRIDE this function to create multibody system mbs and setup simulationSettings; call Assemble() at the end! you may also change SC.visualizationSettings() individually; kwargs may be used for special setup (sec-artificialintelligence-openaigyminterfaceenv(env)-setupspaces)= ### Class function: SetupSpaces [`SetupSpaces(self)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L92) - **class function description**: OVERRIDE this function to set up self.action_space and self.observation_space (sec-artificialintelligence-openaigyminterfaceenv(env)-mapaction2mbs)= ### Class function: MapAction2MBS [`MapAction2MBS(self, action)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L98) - **class function description**: OVERRIDE this function to map the action given by learning algorithm to the multibody system, e.g. as a load parameter (sec-artificialintelligence-openaigyminterfaceenv(env)-output2stateanddone)= ### Class function: Output2StateAndDone [`Output2StateAndDone(self)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L103) - **class function description**: OVERRIDE this function to collect output of simulation and map to self.state tuple - **output**: return bool done which contains information if system state is outside valid range (sec-artificialintelligence-openaigyminterfaceenv(env)-state2initialvalues)= ### Class function: State2InitialValues [`State2InitialValues(self)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L112) - **class function description**: OVERRIDE this function to maps the current state to mbs initial values - **output**: return [initialValues, initialValues_t] where initialValues[_t] are ODE2 vectors of coordinates[_t] for the mbs (sec-artificialintelligence-openaigyminterfaceenv(env)-testmodel)= ### Class function: TestModel [`TestModel(self, numberOfSteps = 500, seed = 0, model = None, solutionFileName = None, useRenderer = True, sleepTime = 0.01, stopIfDone = False, showTimeSpent = True, **kwargs)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L124) - **class function description**: test model by running in simulation environment having several options - **input**: - `numberOfSteps`: number of steps to test MBS and model (with or without learned model); with renderer, press 'Q' in render window to stop simulation - `seed`: seed value for reset function; this value initializes the randomizer; use e.g. time to obtain non-reproducible results - `model`: either None to just test the MBS model without learned model, or containing a learned model, e.g., with A2C; use A2C.save(...) and A2C.load(...) for storing and retrieving models - `solutionFileName`: if given, the MBS internal states are written to the file with given name, which can be loaded with solution viewer and visualized; solution is written every period given in simulationSettings.solution.file.writePeriod - `useRenderer`: if set True, the internal renderer is used and model updates are shown in visualization of Exudyn - `return_info`: internal value in reset function - `sleepTime`: sleep time between time steps to obtain certain frame rate for visualization - `stopIfDone`: if set to True, the simulation will reset as soon as the defined observation limits are reached and done is set True - `showTimeSpent`: if True, the total time spent is measured; this helps to check the performance of the model (e.g. how many steps can be computed per second) (sec-artificialintelligence-openaigyminterfaceenv(env)-setsolver)= ### Class function: SetSolver [`SetSolver(self, solverType)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L175) - **class function description**: use solverType = exudyn.DynamicSolverType.[...] to define solver (choose between implicit and explicit solvers!) (sec-artificialintelligence-openaigyminterfaceenv(env)-preinitializesolver)= ### Class function: PreInitializeSolver [`PreInitializeSolver(self)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L202) - **class function description**: internal function which initializes dynamic solver; adapt in special cases; this function has some overhead and should not be called during reset() or step() (sec-artificialintelligence-openaigyminterfaceenv(env)-integratestep)= ### Class function: IntegrateStep [`IntegrateStep(self)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L210) - **class function description**: internal function which is called to solve for one step (sec-artificialintelligence-openaigyminterfaceenv(env)-step)= ### Class function: step [`step(self, action)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L229) - **class function description**: openAI gym interface function which is called to compute one step (sec-artificialintelligence-openaigyminterfaceenv(env)-reset)= ### Class function: reset [`reset(self, *, seed: Optional[int] = None, return_info: bool = False, options: Optional[dict] = None)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L277) - **class function description**: openAI gym function which resets the system (sec-artificialintelligence-openaigyminterfaceenv(env)-render)= ### Class function: render [`render(self, mode = "human")`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L319) - **class function description**: openAI gym interface function to render the system (sec-artificialintelligence-openaigyminterfaceenv(env)-close)= ### Class function: close [`close(self)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/artificialIntelligence.py#L326) - **class function description**: openAI gym interface function to close system after learning or simulation