diff --git a/api_docs.ipynb b/api_docs.ipynb deleted file mode 100644 index 790de15..0000000 --- a/api_docs.ipynb +++ /dev/null @@ -1,60 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from policyengine import Simulation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sim = Simulation(\n", - " country=\"uk\",\n", - " scope=\"macro\",\n", - " time_period=2025,\n", - " reform={\n", - " \"gov.hmrc.income_tax.allowances.personal_allowance.amount\": {\n", - " \"2025\": 0,\n", - " }\n", - " }\n", - ")\n", - "sim.calculate(\"macro\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "base", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.14" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/_toc.yml b/docs/_toc.yml index b2699f2..51cd2ae 100644 --- a/docs/_toc.yml +++ b/docs/_toc.yml @@ -3,4 +3,7 @@ root: index parts: - caption: Maintenance chapters: - - file: maintaining \ No newline at end of file + - file: maintaining + - caption: Schema + chapters: + - file: schema \ No newline at end of file diff --git a/docs/schema.ipynb b/docs/schema.ipynb new file mode 100644 index 0000000..89ed21b --- /dev/null +++ b/docs/schema.ipynb @@ -0,0 +1,140 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Schema\n", + "\n", + "This page contains examples of the schema of the returned simulation outputs for given types of simulation. Each subsection specifies the country, scope and whether a reform has been passed. The schema is given in YAML format.\n", + "\n", + "## UK, macro, reform-comparison" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "tags": [ + "hide-input" + ] + }, + "outputs": [ + { + "data": { + "text/markdown": [ + "```yaml\n", + "macro:\n", + " baseline:\n", + " gov:\n", + " balance:\n", + " total_gov_spending: \n", + " total_state_tax: \n", + " total_tax_revenue: \n", + " programs:\n", + " child_benefit: \n", + " council_tax: \n", + " fuel_duty: \n", + " income_tax: \n", + " national_insurance: \n", + " ni_employer: \n", + " pension_credit: \n", + " state_pension: \n", + " tax_credits: \n", + " universal_credit: \n", + " vat: \n", + " household:\n", + " demographic_values:\n", + " household_count_people: \n", + " household_weight: \n", + " person_weight: \n", + " comparison:\n", + " revenue_impact:\n", + " tax_revenues: \n", + " reform:\n", + " gov:\n", + " balance:\n", + " total_gov_spending: \n", + " total_state_tax: \n", + " total_tax_revenue: \n", + " programs:\n", + " child_benefit: \n", + " council_tax: \n", + " fuel_duty: \n", + " income_tax: \n", + " national_insurance: \n", + " ni_employer: \n", + " pension_credit: \n", + " state_pension: \n", + " tax_credits: \n", + " universal_credit: \n", + " vat: \n", + " household:\n", + " demographic_values:\n", + " household_count_people: \n", + " household_weight: \n", + " person_weight: \n", + "\n", + "```" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from policyengine import Simulation\n", + "from IPython.display import Markdown\n", + "import yaml\n", + "\n", + "def replace_value_with_dtype(tree):\n", + " for key in tree:\n", + " if isinstance(tree[key], dict):\n", + " replace_value_with_dtype(tree[key])\n", + " else:\n", + " tree[key] = str(type(tree[key]))\n", + " return tree\n", + "\n", + "sim = Simulation(\n", + " country=\"uk\",\n", + " scope=\"macro\",\n", + " time_period=2025,\n", + " reform={\n", + " \"gov.hmrc.income_tax.allowances.personal_allowance.amount\": {\n", + " \"2025\": 0,\n", + " }\n", + " }\n", + ")\n", + "sim.calculate(\"macro\")\n", + "tree = replace_value_with_dtype(sim.outputs)\n", + "\n", + "Markdown('```yaml\\n' + yaml.dump(tree, indent=2) + '\\n```')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "base", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.14" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/policyengine/outputs/macro/comparison/revenue_impact.py b/policyengine/outputs/macro/comparison/revenue_impact.py index 4403c3a..9cce7be 100644 --- a/policyengine/outputs/macro/comparison/revenue_impact.py +++ b/policyengine/outputs/macro/comparison/revenue_impact.py @@ -16,4 +16,7 @@ def revenue_impact(simulation: Simulation): tax_revenue_reform = simulation.calculate( "macro/reform/gov/balance" )["total_tax_revenue"] - return tax_revenue_reform - tax_revenue_baseline + tax_revenue_impact = tax_revenue_reform - tax_revenue_baseline + return { + "tax_revenues": tax_revenue_impact, + } diff --git a/test.ipynb b/test.ipynb deleted file mode 100644 index b82cee8..0000000 --- a/test.ipynb +++ /dev/null @@ -1,75 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from policyengine import Simulation" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "sim = Simulation(\n", - " country=\"uk\",\n", - " scope=\"macro\",\n", - " time_period=2025,\n", - " reform={\n", - " \"gov.hmrc.income_tax.allowances.personal_allowance.amount\": {\n", - " \"2025\": 0,\n", - " }\n", - " }\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "ename": "KeyError", - "evalue": "'comparison'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/var/folders/r_/j9kk4vmd3tj29ljn52_76m4h0000gn/T/ipykernel_62469/2089930413.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msim\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcalculate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"macro\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/policyengine/policyengine.py/policyengine/simulation.py\u001b[0m in \u001b[0;36mcalculate\u001b[0;34m(self, output)\u001b[0m\n\u001b[1;32m 89\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mchild_key\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mnode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 91\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcalculate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutput\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m\"/\"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mchild_key\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 92\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 93\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mnode\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/policyengine/policyengine.py/policyengine/simulation.py\u001b[0m in \u001b[0;36mcalculate\u001b[0;34m(self, output)\u001b[0m\n\u001b[1;32m 79\u001b[0m \u001b[0mparent\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnode\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 80\u001b[0m \u001b[0mchild_key\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0moutput\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"/\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 81\u001b[0;31m \u001b[0mnode\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mparent\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mchild_key\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 82\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[0;31m# Check if any descendants are None\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mKeyError\u001b[0m: 'comparison'" - ] - } - ], - "source": [ - "sim.calculate(\"macro\")" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "base", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.14" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}