From 2f2c0f146eb70dafea8382df109d04031492bd9e Mon Sep 17 00:00:00 2001 From: Erwin Lejeune Date: Thu, 24 Dec 2020 17:27:45 +0100 Subject: [PATCH 1/5] add submodule --- .gitignore | 1 + .gitmodules | 3 +++ pddl-examples | 1 + 3 files changed, 5 insertions(+) create mode 100644 .gitmodules create mode 160000 pddl-examples diff --git a/.gitignore b/.gitignore index e2b98aa..d8a2c99 100644 --- a/.gitignore +++ b/.gitignore @@ -137,3 +137,4 @@ dmypy.json logs/* !logs/.gitkeep data.json +pddl-examples/* diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b3b96f4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "pddl-examples"] + path = pddl-examples + url = https://github.com/APLA-Toolbox/pddl-examples diff --git a/pddl-examples b/pddl-examples new file mode 160000 index 0000000..d60ad41 --- /dev/null +++ b/pddl-examples @@ -0,0 +1 @@ +Subproject commit d60ad41fa337ec32a24937e6dbae40bfcffae0af From 0a594a4113d3f6a73a5374f8b155d577fa680e01 Mon Sep 17 00:00:00 2001 From: Erwin Lejeune Date: Thu, 24 Dec 2020 17:53:48 +0100 Subject: [PATCH 2/5] update submodules commit --- pddl-examples | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pddl-examples b/pddl-examples index d60ad41..8880cab 160000 --- a/pddl-examples +++ b/pddl-examples @@ -1 +1 @@ -Subproject commit d60ad41fa337ec32a24937e6dbae40bfcffae0af +Subproject commit 8880cabe49334832892de24afc67f924759f2f8c From 24e78a91781ee7cddfc5ba66a848e2e2558abfbe Mon Sep 17 00:00:00 2001 From: Erwin Lejeune Date: Thu, 24 Dec 2020 18:09:46 +0100 Subject: [PATCH 3/5] update ci with submodule --- .github/workflows/build.yml | 4 ++++ .github/workflows/tests.yml | 8 ++++++++ .gitignore | 4 ---- README.md | 29 +++++++++++++++++++++-------- data/.gitkeep | 0 data/domain.pddl | 17 ----------------- data/problem.pddl | 9 --------- jupyddl/data_analyst.py | 9 +++++---- tests/test_astar.py | 6 +++--- tests/test_automated_planner.py | 10 +++++----- tests/test_data_analyst.py | 6 +++--- tests/test_heuristics.py | 4 ++-- 12 files changed, 51 insertions(+), 55 deletions(-) delete mode 100644 data/.gitkeep delete mode 100644 data/domain.pddl delete mode 100644 data/problem.pddl diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2de6e9b..a278fb0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: textbook/git-checkout-submodule-action@master diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 85aeba3..42007c6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: textbook/git-checkout-submodule-action@master test: runs-on: ${{ matrix.os }} @@ -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: textbook/git-checkout-submodule-action@master - name: Test with pytest run: | pip install pytest diff --git a/.gitignore b/.gitignore index d8a2c99..5574c43 100644 --- a/.gitignore +++ b/.gitignore @@ -3,10 +3,6 @@ __pycache__/ *.py[cod] *$py.class .vscode/* -data/* -!data/.gitkeep -!data/domain.pddl -!data/problem.pddl # C extensions *.so diff --git a/README.md b/README.md index 75a646b..f7447db 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/data/.gitkeep b/data/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/data/domain.pddl b/data/domain.pddl deleted file mode 100644 index 6772427..0000000 --- a/data/domain.pddl +++ /dev/null @@ -1,17 +0,0 @@ -(define (domain flip) - (:requirements :typing) - (:types row column) - (:predicates (white ?r - row ?c - column)) - (:action flip_row - :parameters (?r - row) - :effect (forall (?c - column) - (and (when (white ?r ?c) (not (white ?r ?c))) - (when (not (white ?r ?c)) (white ?r ?c)))) - ) - (:action flip_column - :parameters (?c - column) - :effect (forall (?r - row) - (and (when (white ?r ?c) (not (white ?r ?c))) - (when (not (white ?r ?c)) (white ?r ?c)))) - ) -) diff --git a/data/problem.pddl b/data/problem.pddl deleted file mode 100644 index 87be018..0000000 --- a/data/problem.pddl +++ /dev/null @@ -1,9 +0,0 @@ -(define (problem flip-problem) - (:domain flip) - (:objects r1 r2 r3 - row c1 c2 c3 - column) - (:init (white r1 c2) - (white r2 c1) - (white r2 c3) - (white r3 c2)) - (:goal (forall (?r - row ?c - column) (white ?r ?c))) -) diff --git a/jupyddl/data_analyst.py b/jupyddl/data_analyst.py index 8d62d2a..066cd96 100644 --- a/jupyddl/data_analyst.py +++ b/jupyddl/data_analyst.py @@ -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() diff --git a/tests/test_astar.py b/tests/test_astar.py index dbf7001..3a20fcf 100644 --- a/tests/test_astar.py +++ b/tests/test_astar.py @@ -9,7 +9,7 @@ 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 @@ -17,12 +17,12 @@ def test_astar_init(): 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 diff --git a/tests/test_automated_planner.py b/tests/test_automated_planner.py index de37a2e..05648a1 100644 --- a/tests/test_automated_planner.py +++ b/tests/test_automated_planner.py @@ -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) diff --git a/tests/test_data_analyst.py b/tests/test_data_analyst.py index 7e2cb8e..36ca7ad 100644 --- a/tests/test_data_analyst.py +++ b/tests/test_data_analyst.py @@ -75,7 +75,7 @@ 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 @@ -83,7 +83,7 @@ def test_comparative_one_pddl(): 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 @@ -91,6 +91,6 @@ def test_comparative_use_data_json(): 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 diff --git a/tests/test_heuristics.py b/tests/test_heuristics.py index 0d562af..44b51b8 100644 --- a/tests/test_heuristics.py +++ b/tests/test_heuristics.py @@ -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 From 1c839e76d4d9995a87514d10788f09dd0824b9d4 Mon Sep 17 00:00:00 2001 From: Erwin Lejeune Date: Thu, 24 Dec 2020 18:26:19 +0100 Subject: [PATCH 4/5] use another submodule init action --- .github/workflows/build.yml | 2 +- .github/workflows/tests.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a278fb0..3872e80 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,5 +41,5 @@ jobs: - name: Checkout reposistory uses: actions/checkout@master - name: Checkout submodules - uses: textbook/git-checkout-submodule-action@master + uses: snickerbockers/submodules-init@v4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 42007c6..f8ab0db 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -42,7 +42,7 @@ jobs: - name: Checkout reposistory uses: actions/checkout@master - name: Checkout submodules - uses: textbook/git-checkout-submodule-action@master + uses: snickerbockers/submodules-init@v4 test: runs-on: ${{ matrix.os }} @@ -81,7 +81,7 @@ jobs: - name: Checkout reposistory uses: actions/checkout@master - name: Checkout submodules - uses: textbook/git-checkout-submodule-action@master + uses: snickerbockers/submodules-init@v4 - name: Test with pytest run: | pip install pytest From 6003a55e8f5947b85af146743ea7814ce0bc64d5 Mon Sep 17 00:00:00 2001 From: Erwin Lejeune Date: Thu, 24 Dec 2020 18:32:10 +0100 Subject: [PATCH 5/5] add tests --- tests/test_data_analyst.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_data_analyst.py b/tests/test_data_analyst.py index 36ca7ad..7016cd8 100644 --- a/tests/test_data_analyst.py +++ b/tests/test_data_analyst.py @@ -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()