Skip to content

Commit e483575

Browse files
committed
Added a docker image containg a Py4J server.
1 parent 344824a commit e483575

File tree

6 files changed

+295
-0
lines changed

6 files changed

+295
-0
lines changed

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM maven:3.6.3-jdk-11
2+
ADD ./target/server-jar-with-dependencies.jar ./
3+
RUN mkdir -p ./snark-20120808r02
4+
COPY ./snark-20120808r02/ ./snark-20120808r02
5+
EXPOSE 25333 25334
6+
CMD java -jar server-jar-with-dependencies.jar

Example.ipynb

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 6,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"from interface import *"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 9,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"goal = \"(Believes! a (and P Q))\""
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 11,
24+
"metadata": {},
25+
"outputs": [
26+
{
27+
"data": {
28+
"text/plain": [
29+
"'[a1 ]'"
30+
]
31+
},
32+
"execution_count": 11,
33+
"metadata": {},
34+
"output_type": "execute_result"
35+
}
36+
],
37+
"source": [
38+
"plan_from_description(\"\"\"\n",
39+
" {:name \"test 1\"\n",
40+
" :background [p]\n",
41+
" :start [q]\n",
42+
" :goal [r]\n",
43+
" :actions [(define-action a1 ()\n",
44+
" {:preconditions [(or q r)]\n",
45+
" :additions [r]\n",
46+
" :deletions [q]})]\n",
47+
"\n",
48+
" :expected-plans ([a1])}\n",
49+
"\"\"\")"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": null,
55+
"metadata": {},
56+
"outputs": [],
57+
"source": []
58+
}
59+
],
60+
"metadata": {
61+
"kernelspec": {
62+
"display_name": "Python 3",
63+
"language": "python",
64+
"name": "python3"
65+
},
66+
"language_info": {
67+
"codemirror_mode": {
68+
"name": "ipython",
69+
"version": 3
70+
},
71+
"file_extension": ".py",
72+
"mimetype": "text/x-python",
73+
"name": "python",
74+
"nbconvert_exporter": "python",
75+
"pygments_lexer": "ipython3",
76+
"version": "3.6.8"
77+
},
78+
"pycharm": {
79+
"stem_cell": {
80+
"cell_type": "raw",
81+
"metadata": {
82+
"collapsed": false
83+
},
84+
"source": []
85+
}
86+
},
87+
"toc": {
88+
"base_numbering": 1,
89+
"nav_menu": {},
90+
"number_sections": false,
91+
"sideBar": false,
92+
"skip_h1_title": false,
93+
"title_cell": "Table of Contents",
94+
"title_sidebar": "Contents",
95+
"toc_cell": false,
96+
"toc_position": {},
97+
"toc_section_display": false,
98+
"toc_window_display": false
99+
}
100+
},
101+
"nbformat": 4,
102+
"nbformat_minor": 2
103+
}

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "3.0"
2+
services:
3+
py-shadowprover:
4+
image: naveensundarg/py-interface-spectra:0.1.3
5+
ports:
6+
- "25334:25334"
7+
- "25333:25333"
8+
interface:
9+
image: naveensundarg/py-interface-spectra:0.1.3
10+
ports:
11+
- "8888:8888"
12+
volumes:
13+
- ./files:/base

interface.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from py4j.java_gateway import JavaGateway
2+
3+
gateway = None
4+
5+
def start():
6+
global gateway
7+
if not (gateway):
8+
gateway = JavaGateway()
9+
10+
def stop():
11+
global gateway
12+
gateway = None
13+
14+
def plan_from_description(description):
15+
global gateway
16+
if not gateway:
17+
start()
18+
return gateway.proveFromDescription(description)
19+
20+
def prove(assumptions, goal):
21+
22+
global gateway
23+
if not gateway:
24+
start()
25+
26+
lst = gateway.newEmptyList()
27+
for assumption in assumptions:
28+
lst.append(assumption)
29+
30+
return gateway.prove(lst, goal)

pom.xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,55 @@
88
<artifactId>planner</artifactId>
99
<version>0.50</version>
1010

11+
<build>
12+
<plugins>
13+
<plugin>
14+
<groupId>org.apache.maven.plugins</groupId>
15+
<artifactId>maven-assembly-plugin</artifactId>
16+
<version>2.4</version>
17+
<executions>
18+
<execution>
19+
<id>sandbox</id>
20+
<configuration>
21+
<archive>
22+
<manifest>
23+
<mainClass>com.naveensundarg.planner.Py4JServer</mainClass>
24+
</manifest>
25+
</archive>
26+
<descriptorRefs>
27+
<descriptorRef>jar-with-dependencies</descriptorRef>
28+
</descriptorRefs>
29+
<finalName>sandbox</finalName>
30+
</configuration>
31+
<phase>package</phase>
32+
<goals>
33+
<goal>single</goal>
34+
</goals>
35+
</execution>
36+
<execution>
37+
<id>server</id>
38+
<configuration>
39+
<archive>
40+
<manifest>
41+
<addClasspath>true</addClasspath>
42+
<mainClass>com.naveensundarg.planner.Py4JServer</mainClass>
43+
</manifest>
44+
</archive>
45+
<descriptorRefs>
46+
<descriptorRef>jar-with-dependencies</descriptorRef>
47+
</descriptorRefs>
48+
<finalName>server</finalName>
49+
</configuration>
50+
<phase>package</phase>
51+
<goals>
52+
<goal>single</goal>
53+
</goals>
54+
</execution>
55+
</executions>
56+
</plugin>
57+
</plugins>
58+
</build>
59+
1160
<dependencies>
1261

1362

@@ -41,6 +90,14 @@
4190
<version>[24.1.1,)</version>
4291
</dependency>
4392

93+
<!-- https://mvnrepository.com/artifact/net.sf.py4j/py4j -->
94+
<dependency>
95+
<groupId>net.sf.py4j</groupId>
96+
<artifactId>py4j</artifactId>
97+
<version>0.8.1</version>
98+
</dependency>
99+
100+
44101

45102
</dependencies>
46103
<properties>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.naveensundarg.planner;
2+
3+
import com.naveensundarg.planner.utils.PlanningProblem;
4+
import com.naveensundarg.shadow.prover.core.ccprovers.CognitiveCalculusProver;
5+
import com.naveensundarg.shadow.prover.core.proof.Justification;
6+
import com.naveensundarg.shadow.prover.representations.formula.Formula;
7+
import com.naveensundarg.shadow.prover.utils.Problem;
8+
import com.naveensundarg.shadow.prover.utils.ProblemReader;
9+
import com.naveensundarg.shadow.prover.utils.Reader;
10+
import py4j.GatewayServer;
11+
12+
import java.io.ByteArrayInputStream;
13+
import java.net.Inet4Address;
14+
import java.net.InetAddress;
15+
import java.net.UnknownHostException;
16+
import java.util.*;
17+
import java.util.stream.Collectors;
18+
19+
20+
public final class Py4JServer {
21+
22+
23+
private DepthFirstPlanner depthFirstPlanner;
24+
25+
26+
public Py4JServer(){
27+
28+
depthFirstPlanner = new DepthFirstPlanner();
29+
30+
}
31+
32+
33+
public Planner getPlanner(){
34+
return depthFirstPlanner;
35+
}
36+
37+
public static void main(String[] args) throws UnknownHostException {
38+
39+
System.out.println("--------------- Starting GatewayServer --------------- ");
40+
System.out.println("--------------- Started Py4J Gateway --------------- ");
41+
42+
InetAddress addr;
43+
System.setProperty("java.net.preferIPv4Stack", "true");
44+
addr = Inet4Address.getByName("0.0.0.0");
45+
GatewayServer server = new GatewayServer(new Py4JServer(),25333, 25334, addr,addr, 0, 0, null);
46+
System.out.println("--------------- Started Py4J Gateway --------------- ");
47+
48+
server.start();
49+
50+
}
51+
52+
public ArrayList newEmptyList(){
53+
54+
return new ArrayList();
55+
}
56+
57+
public String proveFromDescription(String fileString){
58+
try {
59+
60+
List<PlanningProblem> planningProblemList = (PlanningProblem.readFromFile(new ByteArrayInputStream(fileString.getBytes())));
61+
62+
Planner depthFirstPlanner = new DepthFirstPlanner();
63+
64+
PlanningProblem planningProblem = planningProblemList.get(0);
65+
66+
67+
Optional<Set<Plan>> optionalPlans = depthFirstPlanner.plan(
68+
planningProblem.getBackground(),
69+
planningProblem.getActions(),
70+
planningProblem.getStart(),
71+
planningProblem.getGoal());
72+
73+
if(optionalPlans.isPresent()) {
74+
return optionalPlans.get().toString();
75+
}
76+
else {
77+
return "FAILED";
78+
}
79+
80+
} catch (Reader.ParsingException e) {
81+
e.printStackTrace();
82+
return null;
83+
}
84+
}
85+
86+
}

0 commit comments

Comments
 (0)