Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev query logger #61

Merged
merged 46 commits into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
318edf4
initial inputQuery
clazarus May 25, 2018
40feb22
progress query logger
clazarus May 26, 2018
c07bab3
query logger progress
clazarus May 27, 2018
1b50350
serializer string issues solved
clazarus May 28, 2018
e8f80cb
query logger
clazarus May 29, 2018
4c4dd13
Relu deserializer
clazarus May 30, 2018
60a1524
max constraint deserializer
clazarus May 30, 2018
6b17c57
loader complete
clazarus May 31, 2018
20c7b4d
- loader complete
clazarus May 31, 2018
bfb00db
remove comment typo
clazarus May 31, 2018
f7eae4a
Query Logger Complete
clazarus Jun 1, 2018
0ec71fa
Merge branch 'master' into dev_query_logger
clazarus Jun 1, 2018
122cc4f
removing test file
clazarus Jun 1, 2018
7f3b72e
adding functions for tests
clazarus Jun 1, 2018
8da31e5
mostly cosmetics
guykatzz Jun 1, 2018
32dc306
some cosmetics and some comments
guykatzz Jun 1, 2018
61d6fcf
cosmetics, some comments
guykatzz Jun 1, 2018
ef68f8e
gitignore
guykatzz Jun 1, 2018
45a0615
cleanup: that constructor wasn't doing anything (I don't think you can
guykatzz Jun 1, 2018
e0f5ba3
Comments have been adressed and fixed. TODO: refactor loadQuery() and…
clazarus Jun 3, 2018
0e22c7d
mostly cosmetics
guykatzz Jun 3, 2018
6fe9ac3
use our file interfaces
guykatzz Jun 3, 2018
53999d8
refactoring, use our file interface
guykatzz Jun 3, 2018
7a09604
allocate buffer on heap
guykatzz Jun 3, 2018
63b86f3
dont need buffer anymore
guykatzz Jun 3, 2018
612aef2
mock infrastructure for testing classes that use File
guykatzz Jun 3, 2018
57c727f
compilation
guykatzz Jun 3, 2018
f54bc17
Merge branch 'master' into dev_query_logger
clazarus Jun 28, 2018
5800feb
InputQuery Includes fix
clazarus Jun 28, 2018
83427fa
new bugs
clazarus Jul 6, 2018
8f012be
Merge branch 'master' into dev_query_logger
clazarus Jul 13, 2018
32a6f3f
Merge branch 'master' into dev_query_logger
clazarus Jul 16, 2018
4332309
Merge branch 'master' into dev_query_logger
clazarus Jul 22, 2018
3e1a9dc
query logger issues
clazarus Jul 24, 2018
54fefd6
Merge branch 'master' into dev_query_logger
clazarus Jul 24, 2018
085a244
Merge branch 'master' into dev_query_logger
clazarus Aug 3, 2018
69c8f72
Merge branch 'master' into dev_query_logger
clazarus Aug 8, 2018
4b2834a
query loader bugs fixed
clazarus Aug 11, 2018
6acce08
Upating code based on Guy's comments
sparth95 Oct 2, 2018
858e517
Changing the initalizer for PL constraints for query loading
sparth95 Oct 3, 2018
324113e
Minor Change
sparth95 Oct 3, 2018
369ea8c
Adding saveQuery function interface in python
sparth95 Oct 4, 2018
e1dc911
removing merge conflicts
sparth95 Oct 4, 2018
7ef35b5
Minor Change
sparth95 Oct 4, 2018
1886d5c
Updating test for max and relu constraints
Oct 4, 2018
cb1ff40
Updating make file
sparth95 Oct 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions maraboupy/Marabou.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ def read_tf(filename, inputName=None, outputName=None, savedModel=False, savedMo
marabouNetworkTF: (MarabouNetworkTF) representing network
"""
return MarabouNetworkTF(filename, inputName, outputName, savedModel, savedModelTags)

def load_query(filename, verbose=True):
MarabouNetwork.loadQuery(filename, verbose)
3 changes: 2 additions & 1 deletion maraboupy/MarabouCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ PYBIND11_MODULE(MarabouCore, m) {
.def("getUpperBound", &InputQuery::getUpperBound)
.def("getLowerBound", &InputQuery::getLowerBound)
.def("setNumberOfVariables", &InputQuery::setNumberOfVariables)
.def("addEquation", &InputQuery::addEquation);
.def("addEquation", &InputQuery::addEquation)
.def("saveQuery", &InputQuery::saveQuery);
py::class_<Equation> eq(m, "Equation");
eq.def(py::init());
eq.def(py::init<Equation::EquationType>());
Expand Down
28 changes: 28 additions & 0 deletions maraboupy/MarabouNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,34 @@ def solve(self, filename="", verbose=True):

return [vals, stats]

def loadQuery(self, filename="", verbose=True):
"""
Function to solve query represented by this network
Arguments:
filename: (string) path to redirect output to
verbose: (bool) whether to print out solution
Returns:
vals: (dict: int->float) empty if UNSAT, else SATisfying solution
stats: (Statistics) a Statistics object as defined in Marabou,
it has multiple methods that provide information related
to how an input query was solved.
"""
#ipq = self.getMarabouQuery()
ipq = MarabouCore.loadQuery(filename)
vals, stats = MarabouCore.solve(ipq, filename)
if verbose:
if len(vals)==0:
print("UNSAT")
else:
print("SAT")
for i in range(self.inputVars.size):
print("input {} = {}".format(i, vals[self.inputVars.item(i)]))

for i in range(self.outputVars.size):
print("output {} = {}".format(i, vals[self.outputVars.item(i)]))

return [vals, stats]

def evaluateWithMarabou(self, inputValues, filename="evaluateWithMarabou.log"):
"""
Function to evaluate network at a given point using Marabou as solver
Expand Down
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SUBDIRS += \
basis_factorization \
engine \
input_parsers \
query_loader \

include $(ROOT_DIR)/Rules.mk

Expand Down
55 changes: 55 additions & 0 deletions src/common/AutoFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/********************* */
/*! \file AutoFile.h
** \verbatim
** Top contributors (to current version):
** Guy Katz
** This file is part of the Marabou project.
** Copyright (c) 2016-2017 by the authors listed in the file AUTHORS
** in the top-level source directory) and their institutional affiliations.
** All rights reserved. See the file COPYING in the top-level source
** directory for licensing information.\endverbatim
**/

#ifndef __AutoFile_h__
#define __AutoFile_h__

#include "IFile.h"
#include "T/FileFactory.h"

class AutoFile
{
public:
AutoFile( const String &path )
{
_file = T::createFile( path );
}

~AutoFile()
{
T::discardFile( _file );
_file = 0;
}

operator IFile &()
{
return *_file;
}

IFile *operator->()
{
return _file;
}

private:
IFile *_file;
};

#endif // __AutoFile_h__

//
// Local Variables:
// compile-command: "make -C ../.. "
// tags-file-name: "../../TAGS"
// c-basic-offset: 4
// End:
//
4 changes: 3 additions & 1 deletion src/common/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ String File::readLine( char lineSeparatingChar )

while ( !_readLineBuffer.contains( separatorAsString ) )
{
char buffer[SIZE_OF_BUFFER + 1];
char *buffer = new char[SIZE_OF_BUFFER + 1];
int n = T::read( _descriptor, buffer, sizeof(char) * SIZE_OF_BUFFER );
if ( ( n == -1 ) || ( n == 0 ) )
{
delete[] buffer;
if ( _readLineBuffer != "" )
{
String result = _readLineBuffer;
Expand All @@ -130,6 +131,7 @@ String File::readLine( char lineSeparatingChar )

buffer[n] = 0;
_readLineBuffer += buffer;
delete[] buffer;
}

String result = _readLineBuffer.substring( 0, _readLineBuffer.find( separatorAsString ) );
Expand Down
9 changes: 2 additions & 7 deletions src/common/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@
class ConstSimpleData;
class HeapData;

#include "IFile.h"
#include "MString.h"

class File
class File : public IFile
{
public:
enum Mode {
MODE_READ,
MODE_WRITE_APPEND,
MODE_WRITE_TRUNCATE,
};

File( const String &path );
virtual ~File();
void close();
Expand Down
45 changes: 45 additions & 0 deletions src/common/IFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/********************* */
/*! \file IFile.h
** \verbatim
** Top contributors (to current version):
** Guy Katz
** This file is part of the Marabou project.
** Copyright (c) 2016-2017 by the authors listed in the file AUTHORS
** in the top-level source directory) and their institutional affiliations.
** All rights reserved. See the file COPYING in the top-level source
** directory for licensing information.\endverbatim
**/

#ifndef __IFile_h__
#define __IFile_h__

class HeapData;
class String;

class IFile
{
public:
enum Mode {
MODE_READ,
MODE_WRITE_APPEND,
MODE_WRITE_TRUNCATE,
};

virtual void open( Mode openMode ) = 0;
virtual void write( const String &line ) = 0;
virtual String readLine( char lineSeparatingChar = '\n' ) = 0;
virtual void read( HeapData &buffer, unsigned maxReadSize ) = 0;
virtual void close() = 0;

virtual ~IFile() {}
};

#endif // __IFile_h__

//
// Local Variables:
// compile-command: "make -C ../.. "
// tags-file-name: "../../TAGS"
// c-basic-offset: 4
// End:
//
36 changes: 36 additions & 0 deletions src/common/T/FileFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef __T__FileFactory_h__
#define __T__FileFactory_h__

#include "cxxtest/Mock.h"

class IFile;
class String;

namespace T
{
IFile *createFile( const String &path );
void discardFile( IFile *file );
}

CXXTEST_SUPPLY( createFile, /* => T::Base_AllocateIrp */
IFile *, /* Return type */
createFile, /* Name of mock member */
( const String &path ), /* Prototype */
T::createFile, /* Name of real function */
( path ) /* Parameter list */ );

CXXTEST_SUPPLY_VOID( discardFile, /* => T::Base_AllocateIrp */
discardFile, /* Name of mock member */
( IFile *file ), /* Prototype */
T::discardFile, /* Name of real function */
( file ) /* Parameter list */ );

#endif // __T__FileFactory_h__

//
// Local Variables:
// compile-command: "make -C ../.. "
// tags-file-name: "../../TAGS"
// c-basic-offset: 4
// End:
//
10 changes: 10 additions & 0 deletions src/common/mock/FileFactory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#define CXXTEST_MOCK_TEST_SOURCE_FILE
#include "T/FileFactory.h"

//
// Local Variables:
// compile-command: "make -C ../../.. "
// tags-file-name: "../../../TAGS"
// c-basic-offset: 4
// End:
//
12 changes: 12 additions & 0 deletions src/common/mock/Sources.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SOURCES += \
CommonMock.cpp \
Errno.cpp \
FileFactory.cpp \

#
# Local Variables:
# compile-command: "make -C ../../.. "
# tags-file-name: "../../../TAGS"
# c-basic-offset: 4
# End:
#
22 changes: 22 additions & 0 deletions src/common/real/FileFactory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "File.h"

namespace T
{
IFile *createFile( const String &path )
{
return new File( path );
}

void discardFile( IFile *file )
{
delete file;
}
}

//
// Local Variables:
// compile-command: "make -C ../../.. "
// tags-file-name: "../../../TAGS"
// c-basic-offset: 4
// End:
//
1 change: 1 addition & 0 deletions src/common/real/Sources.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SOURCES += \
CommonReal.cpp \
Errno.cpp \
FileFactory.cpp \

#
# Local Variables:
Expand Down
71 changes: 71 additions & 0 deletions src/common/tests/MockFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef __MockFile_h__
#define __MockFile_h__

#include "HeapData.h"
#include "IFile.h"

class MockFile : public IFile
{
public:
MockFile()
{
wasCreated = false;
wasDiscarded = false;
}

bool wasCreated;
bool wasDiscarded;
String lastPath;

void mockConstructor( const String &path )
{
TS_ASSERT( !wasCreated );
wasCreated = true;

lastPath = path;
}

void mockDestructor()
{
TS_ASSERT( wasCreated );
TS_ASSERT( !wasDiscarded );

wasDiscarded = true;
}

bool openWasCalled;
IFile::Mode lastOpenMode;

void open( Mode mode )
{
openWasCalled = true;
lastOpenMode = mode;
}

void write( const String &/* line */ )
{
}

String readLine( char /* lineSeparatingChar */ )
{
return "";
}

void read( HeapData &/* buffer */, unsigned /* maxReadSize */ )
{
}

void close()
{
}
};

#endif // __MockFile_h__

//
// Local Variables:
// compile-command: "make -C ../../.. "
// tags-file-name: "../../../TAGS"
// c-basic-offset: 4
// End:
//
Loading