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)
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;
Class function: init
class function description: internal function to initialize model; store self.mbs and self.simulationSettings; special arguments **kwargs are passed to CreateMBS
Class function: CreateMBS
CreateMBS(self, SC, mbs, simulationSettings, **kwargs)
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
Class function: SetupSpaces
class function description: OVERRIDE this function to set up self.action_space and self.observation_space
Class function: MapAction2MBS
class function description: OVERRIDE this function to map the action given by learning algorithm to the multibody system, e.g. as a load parameter
Class function: Output2StateAndDone
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
Class function: State2InitialValues
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
Class function: TestModel
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 simulationseed: seed value for reset function; this value initializes the randomizer; use e.g. time to obtain non-reproducible resultsmodel: 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 modelssolutionFileName: 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.writePerioduseRenderer: if set True, the internal renderer is used and model updates are shown in visualization of Exudynreturn_info: internal value in reset functionsleepTime: sleep time between time steps to obtain certain frame rate for visualizationstopIfDone: if set to True, the simulation will reset as soon as the defined observation limits are reached and done is set TrueshowTimeSpent: 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)
Class function: SetSolver
class function description: use solverType = exudyn.DynamicSolverType.[…] to define solver (choose between implicit and explicit solvers!)
Class function: PreInitializeSolver
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()
Class function: IntegrateStep
class function description: internal function which is called to solve for one step
Class function: step
class function description: openAI gym interface function which is called to compute one step
Class function: reset
class function description: openAI gym function which resets the system
Class function: render
class function description: openAI gym interface function to render the system
Class function: close
class function description: openAI gym interface function to close system after learning or simulation