Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Checkout reposistory
uses: actions/checkout@master
- name: Checkout submodules
uses: snickerbockers/submodules-init@v4

8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Checkout reposistory
uses: actions/checkout@master
- name: Checkout submodules
uses: snickerbockers/submodules-init@v4

test:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -74,6 +78,10 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Checkout reposistory
uses: actions/checkout@master
- name: Checkout submodules
uses: snickerbockers/submodules-init@v4
- name: Test with pytest
run: |
pip install pytest
Expand Down
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ __pycache__/
*.py[cod]
*$py.class
.vscode/*
data/*
!data/.gitkeep
!data/domain.pddl
!data/problem.pddl

# C extensions
*.so
Expand Down Expand Up @@ -137,3 +133,4 @@ dmypy.json
logs/*
!logs/.gitkeep
data.json
pddl-examples/*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "pddl-examples"]
path = pddl-examples
url = https://github.com/APLA-Toolbox/pddl-examples
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,35 @@ $ julia --color=yes -e 'using Pkg; Pkg.add(Pkg.PackageSpec(path="https://github.
$ julia --color=yes -e 'using Pkg; Pkg.add(Pkg.PackageSpec(path="https://github.com/JuliaPy/PyCall.jl"))'
```

- Install Python dependencies
- Package installation

```bash
$ python3 -m pip install --upgrade pip
$ python3 -m pip install jupyddl
```

# REFL Mode
# Usage

- Run `python3` in the terminal.
If using the jupyddl pip package:

- If you want to use the data analysis tool, create a pddl-examples folder with pddl instances subfolders containing "problem.pddl" and "domain.pddl". (refer to APLA-Toolbox/pddl-examples)

If you want to use it by cloning the project:

```shell
$ git clone https://github.com/APLA-Toolbox/PythonPDDL
$ cd PythonPDDL
$ git submodule init
$ git submodule update
```

You should have a `pddl-examples` folder containing PDDL instances.

## [AutomatedPlanner]

```python
from jupyddl import AutomatedPlanner # takes some time because it has to instantiate the Julia interface
apl = AutomatedPlanner("data/domain.pddl", "data/problem.pddl)
apl = AutomatedPlanner("pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl)

apl.initial_state
<PyCall.jlwrap PDDL.State(Set(Julog.Term[row(r1), column(c3), row(r3), row(r2), column(c2), column(c1)]), Set(Julog.Term[white(r2, c1), white(r1, c2), white(r3, c2), white(r2, c3)]), Dict{Symbol,Any}())>
Expand All @@ -81,21 +94,21 @@ print(apl.get_actions_from_path(path))

## [Data Analyst]

Make sure you have a data folder where you run your environment that contains independent folders with "domain.pddl" and "problem.pddl" files, with those standard names.
Make sure you have a pddl-examples folder where you run your environment that contains independent folders with "domain.pddl" and "problem.pddl" files, with those standard names. ( if you didn't generate with git submodule update )

```python
from jupyddl import DataAnalyst

da = DataAnalyst()
da.plot_astar_data() # plots complexity statistics for all the problem.pddl/domain.pddl couples in the data/ folder
da.plot_astar_data() # plots complexity statistics for all the problem.pddl/domain.pddl couples in the pddl-examples/ folder

da.plot_astar_data(problem="data/flip/problem.pddl", domain="data/flip/domain.pddl") # scatter complexity statistics for the provided pddl
da.plot_astar_data(problem="pddl-examples/flip/problem.pddl", domain="pddl-examples/flip/domain.pddl") # scatter complexity statistics for the provided pddl

da.plot_astar_data(heuristic_key="zero") # use h=0 instead of goal_count for your computation

da.plot_dfs() # same as astar

da.comparative_data_plot() # Run all planners on the data folder and plots them on the same figure, data is stored in a data.json file
da.comparative_data_plot() # Run all planners on the pddl-examples folder and plots them on the same figure, data is stored in a data.json file

da.comparative_data_plot(astar=False) # Exclude astar from the comparative plot

Expand Down
Empty file removed data/.gitkeep
Empty file.
17 changes: 0 additions & 17 deletions data/domain.pddl

This file was deleted.

9 changes: 0 additions & 9 deletions data/problem.pddl

This file was deleted.

9 changes: 5 additions & 4 deletions jupyddl/data_analyst.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ def __get_all_pddl_from_data(self):
domains_problems = []
i = 0
if "DISPLAY" in os.environ:
for root, _, files in os.walk("data/", topdown=False):
for root, _, files in os.walk("pddl-examples/", topdown=False):
for name in files:
if ".gitkeep" in name:
continue
#if ".gitkeep" in name:
# continue
tested_files.append(os.getcwd() + "/" + os.path.join(root, name))
if i % 2 != 0:
domains_problems.append((tested_files[i - 1], tested_files[i]))
i += 1
return domains_problems
return [("data/problem.pddl", "data/domain.pddl")]
return [("pddl-examples/flip/problem.pddl", "pddl-examples/flip/domain.pddl"),
("pddl-examples/dinner/problem.pddl", "pddl-examples/dinner/domain.pddl")]

def __plot_data(self, times, total_nodes, plot_title):
data = dict()
Expand Down
1 change: 1 addition & 0 deletions pddl-examples
Submodule pddl-examples added at 8880ca
6 changes: 3 additions & 3 deletions tests/test_astar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@


def test_astar_init():
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
apla = AutomatedPlanner("pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl")
astar = AStarBestFirstSearch(apla, apla.available_heuristics["goal_count"])
assert astar.init.h_cost == apla.available_heuristics["goal_count"](
apla.initial_state, apla
)


def test_astar_goal():
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
apla = AutomatedPlanner("pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl")
path, _, _ = apla.astar_best_first_search()
assert apla.available_heuristics["goal_count"](path[-1].state, apla) == 0


def test_astar_path_length():
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
apla = AutomatedPlanner("pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl")
path, _, _ = apla.astar_best_first_search()
assert len(path) > 0
10 changes: 5 additions & 5 deletions tests/test_automated_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@


def test_parsing():
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
apla = AutomatedPlanner("pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl")
assert str(apla.problem) != "" and str(apla.domain) != ""


def test_available_actions():
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
apla = AutomatedPlanner("pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl")
actions = apla.available_actions(apla.initial_state)
assert len(actions) > 0


def test_execute_action():
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
apla = AutomatedPlanner("pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl")
actions = apla.available_actions(apla.initial_state)
new_state = apla.transition(apla.initial_state, actions[0])
assert str(new_state) != str(apla.initial_state)


def test_state_has_term():
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
apla = AutomatedPlanner("pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl")
is_goal = apla.state_has_term(apla.initial_state, apla.goals[0])
assert not is_goal


def test_state_assertion():
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
apla = AutomatedPlanner("pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl")
assert not apla.satisfies(apla.problem.goal, apla.initial_state)
29 changes: 26 additions & 3 deletions tests/test_data_analyst.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@ def test_data_analyst_constructor():
_ = DataAnalyst()
assert True

def test_data_analyst_plot_dfs_one_pddl():
da = DataAnalyst()
da.plot_dfs(domain="pddl-examples/flip/domain.pddl", problem="pddl-examples/flip/problem.pddl")
assert True


def test_data_analyst_plot_bfs_one_pddl():
da = DataAnalyst()
da.plot_bfs(domain="pddl-examples/flip/domain.pddl", problem="pddl-examples/flip/problem.pddl")
assert True


def test_data_analyst_plot_dijkstra_one_pddl():
da = DataAnalyst()
da.plot_dijkstra(domain="pddl-examples/flip/domain.pddl", problem="pddl-examples/flip/problem.pddl")
assert True


def test_data_analyst_plot_astar_h_goal_count_one_pddl():
da = DataAnalyst()
da.plot_astar_data(domain="pddl-examples/flip/domain.pddl", problem="pddl-examples/flip/problem.pddl")
assert True


def test_data_analyst_plot_dfs():
da = DataAnalyst()
Expand Down Expand Up @@ -75,22 +98,22 @@ def test_comparative_no_dfs():
def test_comparative_one_pddl():
da = DataAnalyst()
da.comparative_data_plot(
dfs=False, bfs=False, domain="data/domain.pddl", problem="data/problem.pddl"
dfs=False, bfs=False, domain="pddl-examples/flip/domain.pddl", problem="pddl-examples/flip/problem.pddl"
)
assert True


def test_comparative_use_data_json():
da = DataAnalyst()
da.comparative_data_plot(
domain="data/domain.pddl", problem="data/problem.pddl", collect_new_data=False
domain="pddl-examples/flip/domain.pddl", problem="pddl-examples/flip/problem.pddl", collect_new_data=False
)
assert True


def test_comparative_zero_h():
da = DataAnalyst()
da.comparative_data_plot(
domain="data/domain.pddl", problem="data/problem.pddl", heuristic_key="zero"
domain="pddl-examples/flip/domain.pddl", problem="pddl-examples/flip/problem.pddl", heuristic_key="zero"
)
assert True
4 changes: 2 additions & 2 deletions tests/test_heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@


def test_zero_heuristic():
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
apla = AutomatedPlanner("pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl")
heuristic = hs.zero_heuristic(apla.initial_state, apla)
assert heuristic == 0


def test_goal_count_heuristic():
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
apla = AutomatedPlanner("pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl")
heuristic = hs.goal_count_heuristic(apla.initial_state, apla)
assert heuristic == 1