Python API for Brain Simulator
Python module for using GoodAI's Brain Simulator
The module itself serves as an interface to Brain Simulator's MyProjectRunner. You can find a documentation to MyProjectRunner on GoodAI's docs website.
Install from source
Go to folder with
pip install .or
pip install . --upgradeif you are upgrading
GoodAI-BrainSim module depends on Python for .NET which cannot be installed using easy_install, therefore you cannot use the usual
python setup.py install
How to use the module
- First thing you need to do is import a
load_brainsimmethod from the module
- Then you have to call this method. It has one optional argument in which you can specify a path to the folder where you have Brain Simulator installed. If you do not provide the path, it will try to find a path itself in the Windows registry. If the method is unable to find a path in registry, it will use the path
C:\Program Files\GoodAI\Brain Simulator.
- After that, you can import other types from the loaded Brain Simulator modules. All classes except
MyProjectRunnerare imported from the corresponding Brain Simulator namespaces
- You will always want to import
MyProjectRunner. It is used to control the Brain Simulator. It is imported from the
- Other classes are imported from GoodAI namespaces. E.g.
from GoodAI.Core.Utils import MyLog
- If you want to use Brain Simulator's School for AI, you want to import
- You can also import some other types useful e.g. for curriculum creation or logging the events. Those are
- You will always want to import
Together, beginning of your script may look like
from goodai.brainsim import load_brainsim load_brainsim("C:\Users\john.doe\my\brainsimulator\path") from goodai.brainsim import MyProjectRunner from GoodAI.Modules.School.Common import SchoolCurriculum, LearningTaskFactory from GoodAI.School.Common import CurriculumManager from GoodAI.School.Worlds import ToyWorldAdapterWorld # your code here
If you want to know how to use
MyProjectRunner please refer to its documentation.
You can find a simple example of using the API in
examples/basic.py or below. It creates simple curriculum from tasks for
ToyWorldAdapterWorld and then runs the curriculum for 10 steps sending random actions to Brain Simulator.
import random from goodai.brainsim import load_brainsim load_brainsim() from goodai.brainsim import MyProjectRunner from GoodAI.Modules.School.Common import SchoolCurriculum, LearningTaskFactory from GoodAI.School.Common import CurriculumManager from GoodAI.School.Worlds import ToyWorldAdapterWorld # Get Node # node = runner.GetNode(22) # or # node = runner # Get Memory Block # memblock = runner.Visual # Get Values # floatField = runner.GetValues(22, "Visual") # or # memblock = runner.Visual # memblock.SafeCopyToHost() # floatField = memblock.Host runner = MyProjectRunner() runner.OpenProject('C:/Users/john.doe/Desktop/test.brain') runner.DumpNodes() school = runner curr = SchoolCurriculum() for w in CurriculumManager.GetAvailableWorlds(): if w.Name == ToyWorldAdapterWorld.__name__: for t in CurriculumManager.GetTasksForWorld(w): it = LearningTaskFactory.CreateLearningTask(t, school) it.RequiredWorldType = w curr.Add(it) school.Curriculum = curr actions = 13 *  runner.RunAndPause(1) for _ in xrange(10): actions = random.random() print(actions) runner.SetValues(24, actions, "Output") runner.RunAndPause(1) tWorld = school.CurrentWorld chosenActions = tWorld.ChosenActions tWorld.ChosenActions.SafeCopyToHost() print(chosenActions.Host) runner.Shutdown()
Other examples can be found in test folder.
test/test_school.py you can see simple usage of custom
TrainingResult and loading saved curricula.