{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import evokit.evolvables as evolvables" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Please don't look at me, I'm not done yet." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import evokit.evolvables.lgp as lgp" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "LinearProgram.__init__() missing 1 required positional argument: 'inputs'", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[3], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m program \u001b[38;5;241m=\u001b[39m \u001b[43mlgp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mLinearProgram\u001b[49m\u001b[43m(\u001b[49m\u001b[43mregisters\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m4\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m6\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 2\u001b[0m \u001b[43m \u001b[49m\u001b[43mconstants\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m7\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m8\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m9\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m11\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(program)\n", "\u001b[1;31mTypeError\u001b[0m: LinearProgram.__init__() missing 1 required positional argument: 'inputs'" ] } ], "source": [ "program = lgp.LinearProgram(registers = (3, 4, 5, 6),\n", " constants = (7, 8, 9, 10, 11))\n", "print(program)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Benchmark (just one, need to add more)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "===== Running LGP in Context =====\n", "Collect command into structure: r[2] <- add(c[1], r[2])\n", "\n", "===== End State of LGP =====\n", "This is a linear program.Constants c = [5. 6. 7.],\n", "Registers r = [10. 7. 14. 4.]\n", "\n", "===== End State of Benchmark for Comparison =====\n", "Benchmark constants: [5.0, 6.0, 7.0]\n", "Test: benchmark registers: [10.0, 7.0, 14.0, 4.0],\n" ] } ], "source": [ "A = lgp.LinearProgram(constants=(5, 6, 7),\n", " registers=(1, 2, 3, 4))\n", "\n", "initial_registers = list(A.registers.copy())\n", "initial_constants = list(A.constants.copy())\n", "\n", "def add(a: float, b: float) -> float:\n", " return a + b\n", "\n", "def sub(a: float, b: float) -> float:\n", " return a + b\n", "\n", "def less(a: float, b: float) -> bool:\n", " return a < b\n", "\n", "def print_args(a: float, b: float) -> float:\n", " return 0\n", "from typing import Sequence\n", "oprs: Sequence[lgp.Instruction] = [lgp.Operation(add, 1, (2, 3)),\n", " lgp.Operation(sub, 0, (1, 2)),\n", " lgp.Operation(add, 2, (-2, 2)),\n", " lgp.StructOverLines(lgp.If(lgp.Condition(less, (1, 2))), 2),\n", " lgp.Operation(add, 2, (-2, 2)),\n", " lgp.Operation(add, 2, (-3, 1)),\n", " ]\n", "\n", "print(\"\\n===== Running LGP in Context =====\")\n", "A.run(oprs)\n", "print(\"\\n===== End State of LGP =====\")\n", "print(str(A))\n", "\n", "r = initial_registers\n", "c = initial_constants\n", "r[1] = add(r[2], r[3])\n", "r[0] = sub(r[1], r[2])\n", "r[2] = add(c[1], r[2])\n", "\n", "if (1 < 2):\n", " r[2] = add(c[1], r[2])\n", " r[2] = add(c[2], r[1])\n", "\n", "print(\"\\n===== End State of Benchmark for Comparison =====\")\n", "print(f\"Benchmark constants: {c}\")\n", "print(f\"Test: benchmark registers: {r},\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.12.0" } }, "nbformat": 4, "nbformat_minor": 2 }