{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": "# Problem solving metrics", "id": "eb9fb4a1a68e633" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": "!pip install amlgym", "id": "3a2c1c2a35c2e0f2" }, { "metadata": {}, "cell_type": "markdown", "source": "Learn a model to be evaluated:", "id": "243b51efc337c73b" }, { "cell_type": "code", "execution_count": null, "id": "initial_id", "metadata": { "collapsed": true }, "outputs": [], "source": [ "from amlgym.benchmarks import get_domain_path, get_trajectories_path\n", "from amlgym.algorithms import get_algorithm\n", "from amlgym.util.util import empty_domain\n", "\n", "# Get learning algorithm\n", "learner = get_algorithm('offlam')\n", "\n", "# Get an input domain with no preconditions and effects\n", "domain_ref_path = get_domain_path('blocksworld')\n", "domain_empty_path = empty_domain(domain_ref_path)\n", "\n", "# Get a set of trajectories to learn from\n", "traj_paths = get_trajectories_path('blocksworld')\n", "\n", "# Learn a domain model\n", "model = learner.learn(domain_empty_path, traj_paths)" ] }, { "metadata": {}, "cell_type": "markdown", "source": "Print the learned model", "id": "c37e9a2fcb11330c" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": "print(model)", "id": "6ca1abc82297796c" }, { "metadata": {}, "cell_type": "markdown", "source": "Save the learned model to a file:", "id": "e57ba7ed0e528f13" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "domain_eval_path = 'domain_learned.pddl'\n", "with open(domain_eval_path, 'w') as f:\n", " f.write(model)" ], "id": "180a5e01e627481f" }, { "metadata": {}, "cell_type": "markdown", "source": "Get the set of problems necessary to evaluate problem solving metrics:", "id": "c2d26df0bdcd4500" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "from amlgym.benchmarks import get_problems_path\n", "from pprint import pprint\n", "\n", "probs_paths = get_problems_path('blocksworld', kind='solving')\n", "pprint(probs_paths)" ], "id": "7442d5009738bfdc" }, { "metadata": {}, "cell_type": "markdown", "source": "Solve the problems with the model to be evaluated and evaluate it in a simulator defined by a reference model:", "id": "4bba85de1fe660c" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "from amlgym.metrics import problem_solving\n", "import unified_planning\n", "unified_planning.shortcuts.get_environment().credits_stream = None\n", "\n", "metrics = problem_solving(domain_eval_path, domain_ref_path, probs_paths, timeout=60)\n", "print(metrics)" ], "id": "5cb4c2dae24c8453" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }