Fix incorrect variable indices in maraboupy MarabouNetwork.varMap #440
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When playing around with maraboupy, I wanted to add some constraints on the values of the hidden nodes, but I noticed that the variable indices listed in
varMap
were incorrect. For the purpose of this test, I am using a simple network (linked below) with four inputs, one ReLU hidden layer with three nodes, and two outputs. Here is the old situation:As you can see, the indices 4 and 5 are used twice, which is wrong. This is a problem when I want to specify constraints on the hidden nodes, because
varMap
does not contain the correct variable indices. I investigated what caused this error.In
maraboupy/MarabouNetworkONNX.py
andmaraboupy/MarabouNetworkTF.py
, the ONNX and TensorFlow models are loaded and variables and equations are generated from them. The generated variables are put intoself.varMap
, which is a dictionary that maps the names of the ONNX and TF nodes to their associated variables. After parsing the model, the variables are rearranged such that the lowest variable indices are occupied by the model's input variables, followed by the output variables, followed by the variables of the hidden layers.Reassigning the variable indices means that they have to be updated everywhere, including in the generated equations and in
varMap
. As you can see in the output, the indices 4 and 5 have been reassigned to be the output variables in varMap, but the other variables have not been reassigned: node'5'
still uses indices 4 and 5 as well, and the other variables have not been incremented.This PR fixes this issue.
New result:
The ONNX file I used is inside this ZIP file (GitHub does not allow onnx files here): my-nn.zip