.. _cle-tutorials-bibi-cofig: Writing a BIBI Configuration ====================================== .. todo:: Add author/responsible .. todo:: Check links A BIBI Configuration contains all the information necessary to couple a brain model with a robot model using transfer functions and to run these simulations in the Closed Loop Engine (CLE). Thus, besides references to the brain model and the robot model, it contains the specifications of the TFs. As an XML file, such a specification may be created by tools. We have an XML Schema document to validate BIBI Configuration files. As the complete metamodel of the BIBI Configuration may be a bit complicated at the beginning, we build a BIBI Configuration stepwise in XML. However, at any point in time, you may find it useful to lookup :ref:`bibi-specification` for a complete reference. To begin, we start with a new BIBI Configuration. BIBI configuration files should have the file extension **.bibi**. .. code-block:: xml Here we have simply created a *bibi* element in the BIBI Configuration namespace. .. note:: The namespace is subject to change. In particular, the XML Schema definition currently cannot be obtained via the given URL. In order to allow editors to provide tool support, we recommend to explicitly specify the location of the schema manually. This can be done using the following XML attribute (assuming that the schema file resides in *../bibi_configuration.xsd*): *xsi:schemaLocation="http://schemas.humanbrainproject.eu/SP10/2014/BIBI ../bibi_configuration.xsd* Specification of the neuronal network ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ At the moment our BIBI Configuration is not valid. One of the reasons for this is that it lacks a description for the used neuronal network. We need to tell the CLE what brain models we are going to use and what neuron groups exist. .. code-block:: xml brain_model/braitenberg.py This code block must be inserted as a child element of the root *bibi* element. In this example, we have specified that the brain model from *braitenberg.py* should be used. This path is either absolute or relative to the **NRP_MODELS_DIRECTORY** environment variable. Models of neural networks are usually in the *brain_models* directory inside this directory. .. note:: When using the CLE through the :abbr:`NRP (Neurorobotics Platform)` platform, the **NRP_MODELS_DIRECTORY** will be your user directory. When using the CLE separately as e.g. for development machines, this environment variable should be set to a Models repository clone. We further specify two neuron groups, the sensors ranging from 0 to 5 (exclusive) and the actors from 6 to and excluding 8. Note that these neuron groups exactly match the neuron groups (colors) from :doc:`setup page`. We will use these neuron groups in the TFs for reference. .. note:: The XML Schema enforces that the neuronal network file has the correct extension **.py** (or *.h5* for legacy h5 formatted network files). Specification of the robot model ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Our BIBI Configuration also needs a robot model. We specify it simply by the file name of the robot model in the SDF format. This file then contains both the robot meshes as well as information on the plugins used by this robot. .. code-block:: xml husky_model/model.sdf .. note:: The XML Schema enforces that the brain model has the correct file extension **.sdf**. Up to this point, the BIBI Configuration should look as follows: .. code-block:: xml brain_model/braitenberg.py husky_model/model.sdf While we now have created a valid BIBI Configuration, it does not yet contain any TF, so the simulations will run in parallel with no connection to each other. To learn how to specify TFs, see :doc:`neuron2robot`. Transfer Functions ^^^^^^^^^^^^^^^^^^ There are three ways to include a Transfer Function into a BIBI model: - Reference an existing Transfer function from a Python file - Include the Python code directly in the BIBI model - Include a model-based description of the Transfer Function in the BIBI model To reference a transfer function from a file, the following code in the BIBI model is sufficient: .. code-block:: xml The file extension of the specified file does not matter as the file is loaded line by line and then executed in a sandboxed environment through RestrictedPython. Alternatively, the Python code for the Transfer Function may also be specified in-place: .. code-block:: xml # 0): # Since we want to get left and right red values, we cut the image # in 2. half = cv_image.shape[1] // 2 # Get the number of red pixels in the image. red_left = cv2.countNonZero(mask[:, :half]) red_right = cv2.countNonZero(mask[:, half:]) # We have to multiply the red rates by 2 since it is for an # half image only. We also multiply all of them by 1000 so that # we have enough spikes produced by the Poisson generator red_left_eye.rate = 2 * 1000 * (red_left / float(image_size)) red_right_eye.rate = 2 * 1000 * (red_right / float(image_size)) green_blue_eye.rate = 75 * ((image_size - (red_left + red_right)) / float(image_size)) #]]> In the third option, we also allow to specify a Transfer Function in the BIBI model directly. This way is designed for tool interactivity, not for a manual specification. The following Transfer Function makes use of a built-in function to detect red pixels and is specified entirely in the BIBI model: .. code-block:: xml