Setting up

Note

We assume you already have cloned DynaPlex with all dependencies (googletest, LibTorch, CMake) and have an IDE for C++.

Before we can start implementing the MDP, we first need to do some setup:

  1. Setup the CMakeUserPresets.json (only for first use of DynaPLex).

  2. Copy an empty MDP and register it (for every new MDP).

Hint

Adding a new model is easiest in debug mode (WinDeb or LinDeb).

Setup CMakeUserPresets.json

In the folder cmake/resources you can find an example CMakeUserPresets.json.

Copy CMakeUserPresets.json and paste it in the DynaPlex root folder

Hint

Visual Studio and other IDEs often hide files and folders that are ignored in Git, in settings you can set ignored files to visible.

The CMakeUserPresets.json should provide paths to certain dependencies (e.g., PyTorch). You also need to provide DYNAPLEX_IO_ROOT_DIR, which is a local directory where input and output files used and generated by DynaPlex will be stored and retrieved from.

Copy and register an empty MDP

Next, the fun part begins! Go to src/lib/models/models. This is the location where all MDP models are implemented. You already see several example MDPs lister here.

Copy the empty_example folder and paste it in the same folder. Change the foldername to airplane.

Note

The empty_example MDP is an empty shell, it has all important functions and structure, but it will throw a DynaPlex::NotImplementedError() when called.

Register the MDP

We need to register the new airplane MDP in the registration MDP.

Open the registration manager in /models/models/registrationmanager.cpp

Add the following code (you can keep the already existing MDP registrations):

//registrationmanager.cpp
namespace DynaPlex::Models {
        //forward declarations of the registration functions of MDPs:
        namespace airplane {
                void Register(DynaPlex::Registry&);
        }

        void RegistrationManager::RegisterAll(DynaPlex::Registry& registry) {
                airplane::Register(registry);
        }
}

Namespace updates

Next, we need to update the namespaces in the various files you just copy-pasted. At this moment, they are called empty_example, they should be changed to airplane.

Open mdp.cpp and change the namespace to:

namespace DynaPlex::Models {
namespace airplane /*keep this in line with id below and with namespace name in header*/
...

Do the same in mdp.h, policies.cpp, and policies.h

Next, we need to change the Register function and give a description of the MDP in mdp.cpp

void Register(DynaPlex::Registry& registry)
        {
                DynaPlex::Erasure::MDPRegistrar<MDP>::RegisterModel("airplane",
                "A relatively simple MDP for demonstrating the interface of the model", registry);
        }

Now we are all set to start implementing!