From f7239821b647d6e41d1c95a3ecf171a9a766ad27 Mon Sep 17 00:00:00 2001 From: Hosea Siu Date: Mon, 10 Jun 2024 13:36:17 -0400 Subject: [PATCH 1/7] make pytelo pip-installable --- setup.py | 25 +++++++++++++++++++++++ src/pytelo/__init__.py | 4 ++++ {stl => src/pytelo}/agm.py | 0 {stl => src/pytelo}/stl.g4 | 0 {stl => src/pytelo}/stl.py | 6 +++--- {stl => src/pytelo}/stl2milp.py | 4 ++-- {stl => src/pytelo}/test/stl2milp_test.py | 0 stl/__init__.py | 4 ---- 8 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 setup.py create mode 100644 src/pytelo/__init__.py rename {stl => src/pytelo}/agm.py (100%) rename {stl => src/pytelo}/stl.g4 (100%) rename {stl => src/pytelo}/stl.py (99%) rename {stl => src/pytelo}/stl2milp.py (98%) rename {stl => src/pytelo}/test/stl2milp_test.py (100%) delete mode 100644 stl/__init__.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c346296 --- /dev/null +++ b/setup.py @@ -0,0 +1,25 @@ +from setuptools import find_packages, setup + +DISTNAME = "PyTeLo" + +DESCRIPTION = "A Flexible and Efficient Temporal Logic Tool for Python" + +INSTALL_REQUIRES = ["antlr4-python3-runtime==4.7.1", + "scipy", + "gurobipy"] + +setup( + name=DISTNAME, + author="ERL Lehigh", + description=DESCRIPTION, + url="https://github.com/erl-lehigh/PyTeLo", + python_requires=">=3.7, <3.11", + package_dir={"": "src"}, + packages=find_packages("src"), + include_package_data=True, + install_requires=INSTALL_REQUIRES, + # extras_require=EXTRAS_REQUIRES, +) + +# to install: +# pip install . diff --git a/src/pytelo/__init__.py b/src/pytelo/__init__.py new file mode 100644 index 0000000..9c8f52c --- /dev/null +++ b/src/pytelo/__init__.py @@ -0,0 +1,4 @@ +from .stlLexer import stlLexer +from .stlParser import stlParser +from .stl import STLAbstractSyntaxTreeExtractor +from .stl import Operation, RelOperation, STLFormula, Trace \ No newline at end of file diff --git a/stl/agm.py b/src/pytelo/agm.py similarity index 100% rename from stl/agm.py rename to src/pytelo/agm.py diff --git a/stl/stl.g4 b/src/pytelo/stl.g4 similarity index 100% rename from stl/stl.g4 rename to src/pytelo/stl.g4 diff --git a/stl/stl.py b/src/pytelo/stl.py similarity index 99% rename from stl/stl.py rename to src/pytelo/stl.py index b4da16c..8c28e30 100644 --- a/stl/stl.py +++ b/src/pytelo/stl.py @@ -11,9 +11,9 @@ from scipy.interpolate import interp1d from antlr4 import InputStream, CommonTokenStream -from stlLexer import stlLexer -from stlParser import stlParser -from stlVisitor import stlVisitor +from .stlLexer import stlLexer +from .stlParser import stlParser +from .stlVisitor import stlVisitor class Operation(object): diff --git a/stl/stl2milp.py b/src/pytelo/stl2milp.py similarity index 98% rename from stl/stl2milp.py rename to src/pytelo/stl2milp.py index 0ae59d8..3c446c4 100644 --- a/stl/stl2milp.py +++ b/src/pytelo/stl2milp.py @@ -7,7 +7,7 @@ import gurobipy as grb -from stl import Operation, RelOperation, STLFormula +from .stl import Operation, RelOperation, STLFormula class stl2milp(object): @@ -86,7 +86,7 @@ def add_state(self, state, t): name='{}_{}'.format(state, t) v = self.model.addVar(vtype=vtype, lb=low, ub=high, name=name) self.variables[state][t] = v - print 'Added state:', state, 'time:', t + print('Added state:', state, 'time:', t) self.model.update() return self.variables[state][t] diff --git a/stl/test/stl2milp_test.py b/src/pytelo/test/stl2milp_test.py similarity index 100% rename from stl/test/stl2milp_test.py rename to src/pytelo/test/stl2milp_test.py diff --git a/stl/__init__.py b/stl/__init__.py deleted file mode 100644 index a75cfb5..0000000 --- a/stl/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from stlLexer import stlLexer -from stlParser import stlParser -from stl import STLAbstractSyntaxTreeExtractor -from stl import Operation, RelOperation, STLFormula, Trace \ No newline at end of file From 4970495f091f93f9ee2874bd5721dbe0a0f6c651 Mon Sep 17 00:00:00 2001 From: Hosea Siu Date: Mon, 10 Jun 2024 13:40:05 -0400 Subject: [PATCH 2/7] add pip install instructions to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 380c894..ecc3c0d 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ where `` is the directory where you cloned the `pytelo` repository. Install *Gurobi* with *gurobipy* for python3. +Pip install with `pip install pytelo/` from one directory level above. This will let other packages import pytelo functions without including pytelo in their directory structure or referencing the associated files by location. Run --- From 779565000911d55f882481a5c772879f4f577844 Mon Sep 17 00:00:00 2001 From: Hosea Siu Date: Fri, 14 Jun 2024 17:46:58 -0400 Subject: [PATCH 3/7] fix instructions for antlr4 and pytelo package installation order --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ecc3c0d..60abc2d 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,6 @@ where `` is the directory where you cloned the `pytelo` repository. Install *Gurobi* with *gurobipy* for python3. -Pip install with `pip install pytelo/` from one directory level above. This will let other packages import pytelo functions without including pytelo in their directory structure or referencing the associated files by location. - Run --- @@ -44,6 +42,17 @@ cd /src antlr4 -Dlanguage=Python3 stl.g4 ``` +Install as Package +--- +After running `antlr4` above, from one directory level above `pytelo/` + +```bash +pip install pytelo/ +``` + +This will let other packages import pytelo functions without including pytelo in their directory structure or referencing the associated files by location. + + **NOTE:** At the moment the implementation only supports python2 and python3. However, you can generate lexers, parsers, listners, and visitors for other target languages, such as Java (default), C++, C#, Go, JavaScript, and Swift. From 51c3acedb464771ee0d7077a2b96118887d6b0cd Mon Sep 17 00:00:00 2001 From: Cristian-Ioan Vasile Date: Sat, 29 Jun 2024 00:21:31 -0400 Subject: [PATCH 4/7] Created stl and mtl subpackages. --- mtl/__init__.py | 4 ---- src/pytelo/__init__.py | 6 ++---- src/pytelo/mtl/__init__.py | 4 ++++ {mtl => src/pytelo/mtl}/mtl.g4 | 0 {mtl => src/pytelo/mtl}/mtl.py | 6 +++--- {mtl => src/pytelo/mtl}/mtl2milp.py | 4 ++-- {mtl => src/pytelo/mtl}/test/mtl2milp_test.py | 0 src/pytelo/stl/__init__.py | 4 ++++ src/pytelo/{ => stl}/agm.py | 4 ++-- src/pytelo/{ => stl}/stl.g4 | 0 src/pytelo/{ => stl}/stl.py | 0 src/pytelo/{ => stl}/stl2milp.py | 0 src/pytelo/{ => stl}/test/stl2milp_test.py | 0 13 files changed, 17 insertions(+), 15 deletions(-) delete mode 100644 mtl/__init__.py create mode 100644 src/pytelo/mtl/__init__.py rename {mtl => src/pytelo/mtl}/mtl.g4 (100%) rename {mtl => src/pytelo/mtl}/mtl.py (98%) rename {mtl => src/pytelo/mtl}/mtl2milp.py (98%) rename {mtl => src/pytelo/mtl}/test/mtl2milp_test.py (100%) create mode 100644 src/pytelo/stl/__init__.py rename src/pytelo/{ => stl}/agm.py (98%) rename src/pytelo/{ => stl}/stl.g4 (100%) rename src/pytelo/{ => stl}/stl.py (100%) rename src/pytelo/{ => stl}/stl2milp.py (100%) rename src/pytelo/{ => stl}/test/stl2milp_test.py (100%) diff --git a/mtl/__init__.py b/mtl/__init__.py deleted file mode 100644 index 02886ea..0000000 --- a/mtl/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from mtlLexer import mtlLexer -from mtlParser import mtlParser -from mtl import MTLAbstractSyntaxTreeExtractor -from mtl import Operation, RelOperation, MTLFormula \ No newline at end of file diff --git a/src/pytelo/__init__.py b/src/pytelo/__init__.py index 9c8f52c..ca381ef 100644 --- a/src/pytelo/__init__.py +++ b/src/pytelo/__init__.py @@ -1,4 +1,2 @@ -from .stlLexer import stlLexer -from .stlParser import stlParser -from .stl import STLAbstractSyntaxTreeExtractor -from .stl import Operation, RelOperation, STLFormula, Trace \ No newline at end of file +from .stl import STLFormula, Trace, TraceBatch +from .mtl import MTLFormula diff --git a/src/pytelo/mtl/__init__.py b/src/pytelo/mtl/__init__.py new file mode 100644 index 0000000..6f6fca4 --- /dev/null +++ b/src/pytelo/mtl/__init__.py @@ -0,0 +1,4 @@ +from .mtlLexer import mtlLexer +from .mtlParser import mtlParser +from .mtl import MTLAbstractSyntaxTreeExtractor +from .mtl import Operation, RelOperation, MTLFormula diff --git a/mtl/mtl.g4 b/src/pytelo/mtl/mtl.g4 similarity index 100% rename from mtl/mtl.g4 rename to src/pytelo/mtl/mtl.g4 diff --git a/mtl/mtl.py b/src/pytelo/mtl/mtl.py similarity index 98% rename from mtl/mtl.py rename to src/pytelo/mtl/mtl.py index ddb6b15..044261a 100644 --- a/mtl/mtl.py +++ b/src/pytelo/mtl/mtl.py @@ -6,9 +6,9 @@ from antlr4 import InputStream, CommonTokenStream -from mtlLexer import mtlLexer -from mtlParser import mtlParser -from mtlVisitor import mtlVisitor +from .mtlLexer import mtlLexer +from .mtlParser import mtlParser +from .mtlVisitor import mtlVisitor class Operation(object): diff --git a/mtl/mtl2milp.py b/src/pytelo/mtl/mtl2milp.py similarity index 98% rename from mtl/mtl2milp.py rename to src/pytelo/mtl/mtl2milp.py index 8cd2ceb..ac57025 100644 --- a/mtl/mtl2milp.py +++ b/src/pytelo/mtl/mtl2milp.py @@ -6,7 +6,7 @@ import gurobipy as grb -from mtl import Operation, MTLFormula +from .mtl import Operation, MTLFormula class mtl2milp(object): @@ -146,4 +146,4 @@ def until(self, formula, z, t): + sum(z_children_left[:t+a+k+1])) self.model.addConstr(z >= z_conj) - self.model.addConstr(z <= sum(z_aux)) \ No newline at end of file + self.model.addConstr(z <= sum(z_aux)) diff --git a/mtl/test/mtl2milp_test.py b/src/pytelo/mtl/test/mtl2milp_test.py similarity index 100% rename from mtl/test/mtl2milp_test.py rename to src/pytelo/mtl/test/mtl2milp_test.py diff --git a/src/pytelo/stl/__init__.py b/src/pytelo/stl/__init__.py new file mode 100644 index 0000000..0bdc82d --- /dev/null +++ b/src/pytelo/stl/__init__.py @@ -0,0 +1,4 @@ +from .stlLexer import stlLexer +from .stlParser import stlParser +from .stl import STLAbstractSyntaxTreeExtractor +from .stl import Operation, RelOperation, STLFormula, Trace, TraceBatch diff --git a/src/pytelo/agm.py b/src/pytelo/stl/agm.py similarity index 98% rename from src/pytelo/agm.py rename to src/pytelo/stl/agm.py index 699d646..93670da 100644 --- a/src/pytelo/agm.py +++ b/src/pytelo/stl/agm.py @@ -9,8 +9,8 @@ import numpy as np from antlr4 import InputStream, CommonTokenStream -from stlLexer import stlLexer -from stlParser import stlParser +from .stlLexer import stlLexer +from .stlParser import stlParser from stl import Operation, RelOperation, STLAbstractSyntaxTreeExtractor, Trace diff --git a/src/pytelo/stl.g4 b/src/pytelo/stl/stl.g4 similarity index 100% rename from src/pytelo/stl.g4 rename to src/pytelo/stl/stl.g4 diff --git a/src/pytelo/stl.py b/src/pytelo/stl/stl.py similarity index 100% rename from src/pytelo/stl.py rename to src/pytelo/stl/stl.py diff --git a/src/pytelo/stl2milp.py b/src/pytelo/stl/stl2milp.py similarity index 100% rename from src/pytelo/stl2milp.py rename to src/pytelo/stl/stl2milp.py diff --git a/src/pytelo/test/stl2milp_test.py b/src/pytelo/stl/test/stl2milp_test.py similarity index 100% rename from src/pytelo/test/stl2milp_test.py rename to src/pytelo/stl/test/stl2milp_test.py From ddfe1ec2ff7c46d7ea78593a51e7159251a763a8 Mon Sep 17 00:00:00 2001 From: Cristian-Ioan Vasile Date: Sat, 29 Jun 2024 01:02:33 -0400 Subject: [PATCH 5/7] Updated version for antlr and added pytelo version. --- setup.py | 5 +++-- src/pytelo/__init__.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index c346296..cf977c0 100644 --- a/setup.py +++ b/setup.py @@ -4,16 +4,17 @@ DESCRIPTION = "A Flexible and Efficient Temporal Logic Tool for Python" -INSTALL_REQUIRES = ["antlr4-python3-runtime==4.7.1", +INSTALL_REQUIRES = ["antlr4-python3-runtime==4.13.0", "scipy", "gurobipy"] setup( name=DISTNAME, author="ERL Lehigh", + version="0.1.0", description=DESCRIPTION, url="https://github.com/erl-lehigh/PyTeLo", - python_requires=">=3.7, <3.11", + python_requires=">=3.6, <3.11", package_dir={"": "src"}, packages=find_packages("src"), include_package_data=True, diff --git a/src/pytelo/__init__.py b/src/pytelo/__init__.py index ca381ef..66498a6 100644 --- a/src/pytelo/__init__.py +++ b/src/pytelo/__init__.py @@ -1,2 +1,5 @@ from .stl import STLFormula, Trace, TraceBatch from .mtl import MTLFormula + + +__version__ = "0.1.0" From 3926d8a9e1d62558c0a058336bb51603fe7348d6 Mon Sep 17 00:00:00 2001 From: Cristian-Ioan Vasile Date: Sat, 29 Jun 2024 01:03:30 -0400 Subject: [PATCH 6/7] Corrected import in mtl subpackage, and added import of to_ast method. --- src/pytelo/mtl/__init__.py | 3 ++- src/pytelo/stl/__init__.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pytelo/mtl/__init__.py b/src/pytelo/mtl/__init__.py index 6f6fca4..6ba9f6c 100644 --- a/src/pytelo/mtl/__init__.py +++ b/src/pytelo/mtl/__init__.py @@ -1,4 +1,5 @@ from .mtlLexer import mtlLexer from .mtlParser import mtlParser from .mtl import MTLAbstractSyntaxTreeExtractor -from .mtl import Operation, RelOperation, MTLFormula +from .mtl import Operation, MTLFormula +from .mtl import to_ast diff --git a/src/pytelo/stl/__init__.py b/src/pytelo/stl/__init__.py index 0bdc82d..9026730 100644 --- a/src/pytelo/stl/__init__.py +++ b/src/pytelo/stl/__init__.py @@ -2,3 +2,4 @@ from .stlParser import stlParser from .stl import STLAbstractSyntaxTreeExtractor from .stl import Operation, RelOperation, STLFormula, Trace, TraceBatch +from .stl import to_ast From 11cb320ac5547ef55753d3d7e58b506d091c0b4d Mon Sep 17 00:00:00 2001 From: Hosea Siu Date: Tue, 13 Aug 2024 14:14:32 -0400 Subject: [PATCH 7/7] deleting extra print statement --- src/pytelo/stl2milp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pytelo/stl2milp.py b/src/pytelo/stl2milp.py index 3c446c4..f0c0312 100644 --- a/src/pytelo/stl2milp.py +++ b/src/pytelo/stl2milp.py @@ -86,7 +86,6 @@ def add_state(self, state, t): name='{}_{}'.format(state, t) v = self.model.addVar(vtype=vtype, lb=low, ub=high, name=name) self.variables[state][t] = v - print('Added state:', state, 'time:', t) self.model.update() return self.variables[state][t]