Skip to content

Commit

Permalink
SHOP command-line application. (#150)
Browse files Browse the repository at this point in the history
* First version of SHOP command-line application.

This version is simply built with buildapp.

* Add DEFGENERIC for PROBLEM-NAME.

This lets us handle the case where the PROBLEM argument is a symbol
that names a problem, instead of a PROBLEM object.

* Fix EVAL-WHEN mistake in Logistics domain file.

* Add simple bash test script for application.

* Fix buildapp scripts.

* Test the command-line apps on GitHub.

* Fix bug in buildapp installation

* Fix pathname error

* Fix variable expansion.

* Fix the makefile.

* Factor out the app building and test.

* Install ASDF when building app

* Syntax error.

* checkout action only works on GitHub repos

ASDF is hosted on common-lisp.net GitLab.

* Fix pathname

* Test script fix.

* Update test.sh

Fix a SECOND mktemp template
  • Loading branch information
rpgoldman authored Oct 23, 2023
1 parent 294db6c commit 2f4e5ae
Show file tree
Hide file tree
Showing 9 changed files with 417 additions and 63 deletions.
44 changes: 0 additions & 44 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@ jobs:
- { container: "containers.common-lisp.net/cl-docker-images/sbcl:latest", lisp: sbcl }
- { container: "containers.common-lisp.net/cl-docker-images/ccl:latest", lisp: ccl }

# test:
# - ARITY-TEST::ALL-SHOP3-INTERNAL-TESTS
# - PROTECTION-TEST::PROTECTION-TEST
# - SHOP-REPLAN-TESTS::TEST-PLAN-REPAIR
# - SHOP-THEOREM-PROVER-TESTS::THEOREM-PROVER-TESTS
# - SHOP3-OPENSTACKS::PLAN-OPENSTACKS
# - SHOP3-OPENSTACKS::TEST-OPENSTACKS-ADL
# - SHOP3-OPENSTACKS::TEST-OPENSTACKS-ADL-explicit-stack-search
# - SHOP3-USER::BLOCKS-TESTS
# - SHOP3-USER::ENHANCED-PLAN-TREE
# - SHOP3-USER::LOGISTICS-TESTS
# - SHOP3-USER::LOGISTICS-TESTS-DH
# - SHOP3-USER::MINIMAL-SUBTREE-TESTS
# - SHOP3-USER::MISC-TESTS
# - SHOP3-USER::SINGLETON-TESTS
# - SHOP3-USER::UMT-DOMAIN-TESTS
# - SHOP3::ROVERS-TESTS
# - SHOP3::SHORT-PDDL-TESTS
# - SHOP3-USER::DEPOT-TESTS
# - TEST-STATES::TEST-SHOP-STATES

steps:
- name: Get validate deps
shell: bash
Expand Down Expand Up @@ -81,26 +60,3 @@ jobs:
run: |
cd jenkins
./run-tests.sh ${{ matrix.cfg.lisp }}
# - name: tests
# shell: bash
# run: |
# ros --no-quicklisp -e "(cl:in-package :cl-user)
# (require :asdf)
# (prin1 (lisp-implementation-type)) (terpri) (prin1 (lisp-implementation-version)) (terpri)
# (princ (uiop:run-program \"date\" :output :string))
# (prin1 \"${{ matrix.test }}\") (terpri)
# (asdf:initialize-source-registry '(:source-registry (:directory \"$PWD/shop3/\") (:tree \"$PWD/jenkins/ext/\") :inherit-configuration))
# (declaim (optimize (speed 3)))
# (asdf:load-system :shop3/test)
# (defun test-fail-p (test-result)
# (typecase test-result
# (fiveam::test-passed nil)
# (fiveam::test-failure t)
# (null t)
# (list (find-if (function (lambda (x) (test-fail-p x))) test-result))
# (t nil)))
# (let ((test-results (fiveam:run! (quote ${{ matrix.test }}))))
# (format t \"Test results are:~%\")
# (princ test-results) (terpri)
# (princ (uiop:run-program \"date\" :output :string))
# (uiop:quit (if (test-fail-p test-results) 1 0)))"
71 changes: 71 additions & 0 deletions .github/workflows/shop-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

name: buildapp

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master, new-random ]
pull_request:
branches: [ master ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
buildapp:
# The type of runner that the job will run on
runs-on: ${{matrix.os}}
container:
image: ${{matrix.cfg.container}}

strategy:
matrix:
os: [ubuntu-latest]
cfg:
- { container: "containers.common-lisp.net/cl-docker-images/sbcl:latest", lisp: sbcl }
- { container: "containers.common-lisp.net/cl-docker-images/ccl:latest", lisp: ccl }

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: install up-to-date ASDF
shell: bash
run: |
cd ${HOME}
mkdir lisp
cd lisp
git clone https://gitlab.common-lisp.net/asdf/asdf.git
cd asdf
git checkout release
make
- name: install quicklisp
shell: bash
run: |
/usr/local/bin/install-quicklisp
- name: install buildapp
shell: bash
run: |
${{ matrix.cfg.lisp }} --load ${HOME}/quicklisp/setup.lisp --eval '(ql:quickload "buildapp")' --eval '(uiop:quit 0)'
- name: build buildapp binary
shell: bash
run: |
cd ${HOME}/quicklisp/dists/quicklisp/software/buildapp*
echo "Building buildapp with lisp = ${{ matrix.cfg.lisp }}"
make LISP=${{ matrix.cfg.lisp }} install
- name: build and install shop app
shell: bash
run: |
cd shop3/buildapp ; make clean ; make LISP=${{ matrix.cfg.lisp }} install
- name: test shop apps
shell: bash
run: |
cd shop3/buildapp ; ./test.sh
1 change: 1 addition & 0 deletions shop3/buildapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shop-app
14 changes: 14 additions & 0 deletions shop3/buildapp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DESTDIR = /usr/local
LISP := sbcl

shop-app: buildapp-script shop-app-entrypoints.lisp
./buildapp-script

install: shop-app
install -c -m 555 shop-app ${DESTDIR}/bin/shop
install -c -m 555 shop-app ${DESTDIR}/bin/ess-shop

clean:
rm -f shop-app

.PHONY: clean
32 changes: 32 additions & 0 deletions shop3/buildapp/buildapp-script
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -x

ASDF_DIR=${ASDF_DIR:-${HOME}/lisp/asdf/build}
THIS_DIR=$(realpath $(dirname ${BASH_SOURCE}))
QUICKLISP_DIR=${QUICKLISP_DIR:-~/quicklisp}

# --dispatched-entry "shop/shop-app::main" \
# --dispatched-entry "ess-shop/shop-app::ess-main" \
# --entry "shop-app::main" \
buildapp --logfile "/tmp/buildapp-shop-app.log" \
--output shop-app \
--dispatched-entry "/shop-app::main" \
--dispatched-entry "shop/shop-app::main" \
--dispatched-entry "ess-shop/shop-app::ess-main" \
--load "${ASDF_DIR}/asdf.lisp" \
--asdf-path "${THIS_DIR}/../" \
--asdf-tree "${THIS_DIR}/../../jenkins/ext/" \
--eval '(declaim (optimize speed space safety))' \
--load-system "shop3" \
--load "${THIS_DIR}/shop-app-entrypoints.lisp"


retVal=$?
if [ $retVal -ne 0 ]; then
echo "Build process failed with exit code $retVal"
exit $retVal
fi
exit $retVal

# Local Variables:
# mode: sh
# End:
68 changes: 68 additions & 0 deletions shop3/buildapp/shop-app-entrypoints.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
;;;---------------------------------------------------------------------------
;;; Copyright Robert P. Goldman and Smart Information Flow Technologies,
;;; d/b/a SIFT, LLC
;;;
;;; This file made available under the license terms of the SHOP3 system.
;;;---------------------------------------------------------------------------
;;; File Description:
;;;
;;; A file that gives entry points to a command-line application that runs the
;;; SHOP3 planner on an input domain and problem.
;;;
;;; History/Bugs/Notes:
;;;
;;; [2023/10/11:rpg] Created.
;;;
;;;---------------------------------------------------------------------------
(defpackage :shop-app
(:use :shop3 :iterate :common-lisp))
(in-package :shop-app)

(defun usage (progname)
(format t "~&~a: file1 [file2]~%" progname)
(format t "~%Runs the SHOP planner on the problem, and prints the result to standard output.~%")
(format t "~%If only one file is given, it should contain both domain and problem definitions.~%~
If two are given, the first should be the domain file and the second the problem file~%~
(although in fact, the ordering is not critical).~%~%~
The output plan is wrapped between two lines of equal signs (=), and is printed ~%~
in three columns, step number, a colon (:), step, a colon (:), and cost rounded to~%2 decimal places.~%"))

(defun print-plan (plan)
(let ((*print-length* nil)
(*print-right-margin* 10000)
;; best guess at package for output
(*package* (symbol-package (shop::problem-name shop::*problem*))))
(flet ((print-separator ()
(format t "~&======================================================================~%")))
(print-separator)
(iter (for (step cost . nil) on plan by 'cddr)
(as i from 1)
(format t "~3d:~t~a:~t~,2f~%"
i step cost))
(print-separator))))

(defun main (argv &key (plan-fun #'shop:find-plans))
(when (member "--help" (rest argv) :test #'string=)
(usage (first argv))
(uiop:quit 0))
(handler-bind ((error
(lambda (x)
(format *error-output* "~a" x)
(uiop:quit 1))))
(iter (for x in (rest argv))
(unless (load x :if-does-not-exist t)
(error "File ~a failed to load." x)))
(multiple-value-bind (plans time trees)
(funcall plan-fun shop::*problem*)
(declare (ignore time trees)) ; at least for now...
(unless plans
(error "Unable to find a plan for problem ~a"
(shop::problem-name shop::*problem*)))
(print-plan (first plans))))
(uiop:quit 0))

(defun ess-main (argv)
(when (member "--help" (rest argv) :test #'string=)
(usage (first argv))
(uiop:quit 0))
(main argv :plan-fun #'shop:find-plans-stack))
Loading

0 comments on commit 2f4e5ae

Please sign in to comment.