NeuralNetworkVerification/Marabou

Three Maraboupy errors for the examples

jinqiang-yu opened this issue · 7 comments

I found some errors when trying the three examples:

  1. For the NNet example:
from maraboupy import Marabou

nnetFile = "./marabou/src/input_parsers/acas_example/ACASXU_run2a_1_1_tiny_2.nnet"
net1 = Marabou.read_nnet(nnetFile)
net1.setLowerBound(net1.outputVars[0][0], .5)

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[4], line 3
      1 nnetFile = "./marabou/src/input_parsers/acas_example/ACASXU_run2a_1_1_tiny_2.nnet"
      2 net1 = Marabou.read_nnet(nnetFile)
----> 3 net1.setLowerBound(net1.outputVars[0][0], .5)

File maraboupy/MarabouNetwork.py:99, in MarabouNetwork.setLowerBound(self, x, v)
     92 def setLowerBound(self, x, v):
     93     """Function to set lower bound for variable
     94 
     95     Args:
     96         x (int): Variable number to set
     97         v (float): Value representing lower bound
     98     """
---> 99     self.lowerBounds[x]=v

TypeError: unhashable type: 'numpy.ndarray'
  1. For ONNX example:
from maraboupy import Marabou
import numpy as np
options = Marabou.createOptions(verbosity = 0)
print("Fully Connected Network Example")
filename = "./marabou/resources/onnx/fc1.onnx"
network = Marabou.read_onnx(filename)

Error:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[5], line 6
      4 print("Fully Connected Network Example")
      5 filename = "./marabou/resources/onnx/fc1.onnx"
----> 6 network = Marabou.read_onnx(filename)

File maraboupy/Marabou.py:75, in read_onnx(filename, inputNames, outputNames, reindexOutputVars)
     64 def read_onnx(filename, inputNames=None, outputNames=None, reindexOutputVars=True):
     65     """Constructs a MarabouNetworkONNX object from an ONNX file
     66 
     67     Args:
   (...)
     73         :class:`~maraboupy.MarabouNetworkONNX.MarabouNetworkONNX`
     74     """
---> 75     return MarabouNetworkONNX(filename, inputNames, outputNames, reindexOutputVars=reindexOutputVars)

NameError: name 'MarabouNetworkONNX' is not defined
  1. For the Disjunction Example:
nnetFile = "./marabou/resources/nnet/mnist/mnist10x10.nnet"
net1 = Marabou.read_nnet(nnetFile)

for var in net1.inputVars[0][0]:
    # eq1: 1 * var = 0
    eq1 = MarabouCore.Equation(MarabouCore.Equation.EQ)
    eq1.addAddend(1, var)
    eq1.setScalar(0)

    # eq2: 1 * var = 1
    eq2 = MarabouCore.Equation(MarabouCore.Equation.EQ)
    eq2.addAddend(1, var)
    eq2.setScalar(1)

    # ( var = 0) \/ (var = 1)
    disjunction = [[eq1], [eq2]]
    net1.addDisjunctionConstraint(disjunction)

    # add additional bounds for the variable
    net1.setLowerBound(var, 0)
    net1.setUpperBound(var, 1)
    break

vals1, stats1 = net1.solve()

Error:

File "disj.py", line 36, in <module>
    vals1, stats1 = net1.solve()
                    ^^^^^^^^^^^^
  File "marabou/maraboupy/MarabouNetwork.py", line 70, in solve
    ipq = self.getInputQuery()
          ^^^^^^^^^^^^^^^^^^^^
  File "marabou/maraboupy/parsers/InputQueryBuilder.py", line 334, in getInputQuery
    eq = MarabouCore.Equation(e.EquationType)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. maraboupy.MarabouCore.Equation()
    2. maraboupy.MarabouCore.Equation(arg0: maraboupy.MarabouCore.Equation.EquationType)

Invoked with: <class 'maraboupy.MarabouCore.Equation.EquationType'>

Hi Jinqiang,

Error 1: instead of net1.outputVars[0][0], one should do net1.outputVars[0][0][0]. Need to fix this.

Error 2: I believe this is because the dependency for MarabouNetworkONNX is not installed. Please install the Python packages described in maraboupy/test_requirements.txt

Error 3: Need to look into this. Can't tell what the issue is, but probably because the example is not up-to-date.

Andrew

Thank you for your reply, Haoze.

Error 1: It's solved now.

Error 2: I got the error after installing maraboupy/test_requirements.txt

File "example/onnx.py", line 3, in <module>
    options = Marabou.createOptions(verbosity = 0)
              ^^^^^^^^^^^^^^^^^^^^^
AttributeError: partially initialized module 'maraboupy.Marabou' has no attribute 'createOptions' (most likely due to a circular import)

Error 3: Thank you for looking into this.

I can't seem to reproduce Error 2 and 3.

For Error 2, did you get any warnings when invoking the example? What happens if you comment out these lines?

try:
from maraboupy.MarabouNetworkNNet import *
except ImportError:
warnings.warn("NNet parser is unavailable because the numpy package is not installed")
try:
from maraboupy.MarabouNetworkTF import *
except ImportError:
warnings.warn("Tensorflow parser is unavailable because tensorflow package is not installed")

I created PR #768 to bring the examples up to date. With that branch, all examples terminated fine on my local machine. Could you try that branch and see if the examples work on your end?

UPDATE: branch #768 is merged. You could just pull from the master branch!

Closing due to inactivity, feel free to re-open.

I am getting the 3rd error