Model debugging#


This is a beta feature. It does not support the full language yet and it might not work as expected. Currently known limitations:

  • lists and dicts not supported

  • string interpolation not supported

  • constructor kwargs not supported

  • plugins not supported

  • conditionals not supported

  • for loops not supported

  • boolean operations not supported

  • explicit index lookups not supported

  • only double assignment, exceeding relation arity and incomplete instance errors are supported

Support for the listed language features will be added gradually.

The inmanta DSL is essentially a data flow oriented language. As a model developer you never explicitly manipulate control flow. Instead you declare data flow: the statement x = y for example declares that the data in y should flow towards x. Even dynamic statements such as implementations and for loops do not explicitly manipulate control flow. They too can be interpreted as data flow declarations.

Because of this property conventional debugging methods such as inspecting a stack trace are not directly applicable to the inmanta language. A stack trace is meant to give the developer insight in the part of the control flow that led to the error. Extending this idea to the inmanta DSL leads to the concept of a data trace. Since the language is data flow oriented, a trace of the flow to some erroneous part of the configuration model gives the developer insight in the cause of the error.

Additionally, a root cause analysis will be done on any incomplete instances and only those root causes will be reported.

The first section, Enabling the data trace describes how to enable these two tools. The tools themselves are described in the sections Interpreting the data trace and Root cause analysis respectively. An example use case is shown in Usage example, and the final section, Graphic visualization, shortly describes a graphic representation of the data flow.

Enabling the data trace#

To show a data trace when an error occurs, compile the model with the --experimental-data-trace flag. For example:
1x = 1
2x = 2

Compiling with inmanta compile --experimental-data-trace results in

inmanta.ast.DoubleSetException: value set twice:
    old value: 1
        set at ./
    new value: 2
        set at ./

data trace:
├── 1
│   SET BY `x = 1`
│   AT ./
└── 2
    SET BY `x = 2`
    AT ./
 (reported in x = 2 (./

Interpreting the data trace#

Let’s have another look at the data trace for the model above:

2├── 1
3│   SET BY `x = 1`
4│   AT ./
5└── 2
6    SET BY `x = 2`
7    AT ./

Line 1 shows the variable where the error occurred. A tree departs from there with branches going to lines 2 and 5 respectively. These branches indicate the data flow to x. In this case line 2 indicates x has been assigned the literal 1 by the statement x = 1 at and the literal 2 by the statement x = 2 at

Now let’s go one step further and add an assignment to another variable.
1x = 0
2x = y
3y = 1
data trace for
 2├── y
 3│   SET BY `x = y`
 4│   AT ./
 5│   └── 1
 6│       SET BY `y = 1`
 7│       AT ./
 8└── 0
 9    SET BY `x = 0`
10    AT ./

As before we can see the data flow to x as declared in the model. Following the tree from x to its leaves leads to the conclusion that x has indeed received two inconsistent values, and it gives insight into how those values came to be assigned to x (0 directly and 1 via y).

One more before we move on to entities:
1x = y
2y = z
3z = x
5x = 0
6z = u
7u = 1
data trace for
 3    `x = y` AT ./
 4    `y = z` AT ./
 5    `z = x` AT ./
 6├── u
 7│   SET BY `z = u`
 8│   AT ./
 9│   └── 1
10│       SET BY `u = 1`
11│       AT ./
12└── 0
13    SET BY `x = 0`
14    AT ./

This model defines an assignment loop between x, y and z. Assignment to either of these variables will result in a flow of data to all of them. In other words, the variables are equivalent. The data trace shows this information at lines 2–5 along with the statements that caused the equivalence. The rest of the trace is similar to before, except that the tree now shows all assignments to any of the three variables part of the equivalence. The tree now no longer shows just the data flow to x but to the equivalence as a whole, since any data that flows to the equivalence will also flow to x.
 1entity A:
 2    number n
 5implement A using std::none
 7x = A(n = 0)
 9template = x
11y = A(n = template.n)
12y.n = 1
data trace for
 1attribute n on __config__::A instance
 2SUBTREE for __config__::A instance:
 3    CONSTRUCTED BY `A(n=template.n)`
 4    AT ./
 5├── template.n
 6│   SET BY `A(n=template.n)`
 7│   AT ./
 8│   SUBTREE for template:
 9│       └── x
10│           SET BY `template = x`
11│           AT ./
12│           └── __config__::A instance
13│               SET BY `x = A(n=0)`
14│               AT ./
15│               CONSTRUCTED BY `A(n=0)`
16│               AT ./
17│   └── 0
18│       SET BY `A(n=0)`
19│       AT ./
20└── 1
21    SET BY `y.n = 1`
22    AT ./

As usual, line 1 states the variable that represents the root of the data flow tree. In this case it’s the attribute n of an instance of A. Which instance? That is shown in the subtree for that instance on lines 2–4. In this case it’s a very simple subtree that shows just the construction of the instance and the line number in the configuration model. The tree for the attribute starts at line 5. The first branch shows the assignment to template.n in the constructor for y. Then another subtree is shown at lines 8–16, this one more useful. It shows a data flow graph like we’re used to by now, with template as the root. Then at line 17 the trace shows the data flow template.n <- 0 referring to This line doesn’t assign to template.n directly, but it does assign to the instance at the end of the subtree for template (the data that flows to template).

Let’s have a look at an implementation:
 1entity A:
 2    number n
 5implement A using i
 7implementation i for A:
 8    self.n = 42
11x = A(n = 0)
data trace for
 1attribute n on __config__::A instance
 2SUBTREE for __config__::A instance:
 3    CONSTRUCTED BY `A(n=0)`
 4    AT ./
 5├── 0
 6│   SET BY `A(n=0)`
 7│   AT ./
 8└── 42
 9    SET BY `self.n = 42`
10    AT ./
11    IN IMPLEMENTATION WITH self = __config__::A instance
12        CONSTRUCTED BY `A(n=0)`
13        AT ./

The only thing new in this trace can be found at lines 11—13. It highlights that a statement was executed within a dynamic context and shows a subtree for the self variable.

And finally, an index:
 1entity A:
 2    number n
 3    number m
 6index A(n)
 8implement A using std::none
10A(n = 42, m = 0)
11A(n = 42, m = 1)
data trace for
 1attribute m on __config__::A instance
 2SUBTREE for __config__::A instance:
 3    CONSTRUCTED BY `A(n=42,m=0)`
 4    AT ./
 6    INDEX MATCH: `__config__::A instance`
 7        CONSTRUCTED BY `A(n=42,m=1)`
 8        AT ./
 9├── 1
10│   SET BY `A(n=42,m=1)`
11│   AT ./
12└── 0
13    SET BY `A(n=42,m=0)`
14    AT ./

This data trace highlights the index match between the two constructors at lines 6–8.

Root cause analysis#

Enabling the data trace also enables a root cause analysis when multiple attributes have not received a value. For example, compiling the model below results in three errors, one for each of the instances.

 1entity A:
 2    number n
 5implement A using std::none
 7x = A()
 8y = A()
 9z = A()
11x.n = y.n
12y.n = z.n
compile output#
1Reported 3 errors
2error 0:
3  The object __config__::A (instantiated at ./ is not complete: attribute n (./ is not set
4error 1:
5  The object __config__::A (instantiated at ./ is not complete: attribute n (./ is not set
6error 2:
7  The object __config__::A (instantiated at ./ is not complete: attribute n (./ is not set

Compiling with data trace enabled will do a root cause analysis on these errors. In this case it will infer that x.n and y.n are only unset because z.n is unset. Compiling then shows:

compile output with –experimental-data-trace#
1Reported 1 errors
2error 0:
3  The object __config__::A (instantiated at ./ is not complete: attribute n (./ is not set

In cases where a single error leads to errors for a collection of related attributes, this can greatly simplify the debugging process.

Usage example#

Let’s have a look at the model below:
 1entity Port:
 2    string host
 3    number portn
 6index Port(host, portn)
 8entity Service:
 9    string name
10    string host
11    number portn
14Service.port [0:1] -- Port.service [0:1]
17implement Port using std::none
18implement Service using bind_port
21implementation bind_port for Service:
22    self.port = Port(host =, portn = self.portn)
26sshd = Service(
27    name = "opensshd",
28    host = "my_host",
29    portn = 22,
33custom_service = Service(
34    name = "some_custom_service",
35    host = "my_host",
36    portn = 22,

Compiling this with data trace disabled outputs the following error:

compilation output for with data trace disabled#
Could not set attribute `port` on instance `__config__::Service (instantiated at ./` (reported in self.port = Construct(Port) (./
caused by:
  Could not set attribute `service` on instance `__config__::Port (instantiated at ./,./` (reported in __config__::Port (instantiated at ./,./ (./
  caused by:
    value set twice:
    old value: __config__::Service (instantiated at ./
        set at ./
    new value: __config__::Service (instantiated at ./
        set at ./
 (reported in self.port = Construct(Port) (./

The error message refers to which is part of an implementation. It is not clear which Service instance is being refined, which makes finding the cause of the error challenging. Enabling data trace results in the trace below:

data trace for
 1attribute service on __config__::Port instance
 2SUBTREE for __config__::Port instance:
 3    CONSTRUCTED BY `Port(,portn=self.portn)`
 4    AT ./
 5    IN IMPLEMENTATION WITH self = __config__::Service instance
 6        CONSTRUCTED BY `Service(name='opensshd',host='my_host',portn=22)`
 7        AT ./
 9    INDEX MATCH: `__config__::Port instance`
10        CONSTRUCTED BY `Port(,portn=self.portn)`
11        AT ./
12        IN IMPLEMENTATION WITH self = __config__::Service instance
13            CONSTRUCTED BY `Service(name='some_custom_service',host='my_host',portn=22)`
14            AT ./
15├── __config__::Service instance
16│   SET BY `self.port = Port(,portn=self.portn)`
17│   AT ./
18│   IN IMPLEMENTATION WITH self = __config__::Service instance
19│       CONSTRUCTED BY `Service(name='some_custom_service',host='my_host',portn=22)`
20│       AT ./
21│   CONSTRUCTED BY `Service(name='some_custom_service',host='my_host',portn=22)`
22│   AT ./
23└── __config__::Service instance
24    SET BY `self.port = Port(,portn=self.portn)`
25    AT ./
26    IN IMPLEMENTATION WITH self = __config__::Service instance
27        CONSTRUCTED BY `Service(name='opensshd',host='my_host',portn=22)`
28        AT ./
29    CONSTRUCTED BY `Service(name='opensshd',host='my_host',portn=22)`
30    AT ./

At lines 15 and 23 it shows the two Service instances that are also mentioned in the original error message. This time, the dynamic implementation context is mentioned and it’s clear that these instances have been assigned in a refinement for the Service instances constructed at lines 26 and 33 in the configuration model respectively.

Lines 2–14 in the trace give some additional information about the Port instance. It indicates there is an index match between the Port instances constructed in the implementations for both Service instances. This illustrates the existence of the two branches at lines 15 and 23, and why the assignment in this implementation resulted in the exceeding of the relation arity: the right hand side is the same instance in both cases.

Graphic visualization#


This representation is not as complete as the data trace explained above. It does not show information about statements responsible for each assignment. It was primarily developed as an aid in developing the data flow framework on which the data trace and the root cause analysis tools are built. It’s described here because it’s closely related to the two tools described above. Its actual use in model debugging might be limited.


Using this feature requires one of inmanta’s optional dependencies to be installed: pip install inmanta[dataflow_graphic]. It also requires the fdp command to be available on your system. This is most likely packaged in your distribution’s graphviz package.

Let’s compile the model in again, this time with --experimental-dataflow-graphic. The compile results in an error, as usual, but this time it’s accompanied by a graphic visualization of the data flow.


It shows all assignments, as well as the index match between the two Port constructions. An assignment where the right hand side is an attribute x.y is shown by an arrow to x, labeled with .y. Variables are represented by ellipses, values by diamonds and instances by rectangular containers.