{"id":27861024,"url":"https://github.com/basisresearch/effectful","last_synced_at":"2026-02-03T15:09:32.876Z","repository":{"id":272497571,"uuid":"809912799","full_name":"BasisResearch/effectful","owner":"BasisResearch","description":"An experimental library for metaprogramming with algebraic effects and handlers","archived":false,"fork":false,"pushed_at":"2025-05-04T03:55:27.000Z","size":860,"stargazers_count":6,"open_issues_count":24,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-04T04:27:15.669Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://basisresearch.github.io/effectful/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BasisResearch.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-06-03T17:32:53.000Z","updated_at":"2025-05-04T03:55:29.000Z","dependencies_parsed_at":"2025-01-14T20:41:09.464Z","dependency_job_id":"3ad639d0-aceb-4cbc-9254-284b5c6c9e31","html_url":"https://github.com/BasisResearch/effectful","commit_stats":null,"previous_names":["basisresearch/effectful"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasisResearch%2Feffectful","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasisResearch%2Feffectful/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasisResearch%2Feffectful/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasisResearch%2Feffectful/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BasisResearch","download_url":"https://codeload.github.com/BasisResearch/effectful/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252379924,"owners_count":21738671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-04T18:26:34.741Z","updated_at":"2026-02-03T15:09:31.134Z","avatar_url":"https://github.com/BasisResearch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. index-inclusion-marker\n\nEffectful\n=========\n\nEffectful is an algebraic effect system for Python, intended for use in the\nimplementation of probabilistic programming languages. It is a core component of\nthe `ChiRho \u003chttps://basisresearch.github.io/chirho/getting_started.html\u003e`_\ncausal modeling language.\n\nInstallation\n------------\n\nInstall From Source\n^^^^^^^^^^^^^^^^^^^^\n.. code:: sh\n\n   git clone git@github.com:BasisResearch/effectful.git\n   cd effectful\n   git checkout master\n   pip install -e .[pyro]\n\nInstall With Optional PyTorch/Pyro Support\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n``effectful`` has optional support for:\n\n- `PyTorch \u003chttps://pytorch.org/\u003e`_ (tensors with named dimensions)\n- `Pyro \u003chttps://pyro.ai/\u003e`_ (wrappers for Pyro effects)\n- `Jax \u003chttps://docs.jax.dev/en/latest/index.html\u003e`_ (tensors with named dimensions)\n- `Numpyro \u003chttps://num.pyro.ai\u003e`_ (operations for Numpyro distributions)\n\nTo enable PyTorch support:\n\n.. code:: sh\n\n   pip install effectful[torch]\n\nPyro support (which includes PyTorch support):\n\n.. code:: sh\n\n   pip install effectful[pyro]\n\nJax support:\n\n.. code:: sh\n\n   pip install effectful[jax]\n\nNumpyro support (which includes Jax support):\n\n.. code:: sh\n\n   pip install effectful[numpyro]\n\nGetting Started\n---------------\n\nHere's an example demonstrating how ``effectful`` can be used to implement a simple DSL that performs arithmetic on terms with free variables.\n\n.. code:: python\n\n   import functools\n\n   from effectful.ops.types import Term\n   from effectful.ops.syntax import defdata, defop\n   from effectful.ops.semantics import handler, evaluate, coproduct, fwd\n\n   add = defdata.dispatch(int).__add__\n\n   def beta_add(x: int, y: int) -\u003e int:\n       match x, y:\n           case int(), int():\n               return x + y\n           case _:\n               return fwd()\n\n   def commute_add(x: int, y: int) -\u003e int:\n       match x, y:\n           case Term(), int():\n               return y + x\n           case _:\n               return fwd()\n\n   def assoc_add(x: int, y: int) -\u003e int:\n       match x, y:\n           case _, Term(op, (a, b)) if op == add:\n               return (x + a) + b\n           case _:\n               return fwd()\n\n   beta_rules = {add: beta_add}\n   commute_rules = {add: commute_add}\n   assoc_rules = {add: assoc_add}\n\n   eager_mixed = functools.reduce(coproduct, (beta_rules, commute_rules, assoc_rules))\n\nWe can represent free variables as operations with no arguments, generated using ``defop``:\n\n.. code:: python\n\n   \u003e\u003e\u003e x = defop(int, name=\"x\")\n   \u003e\u003e\u003e y = defop(int, name=\"y\")\n\nIf we evaluate an expression containing free variables, we get a term:\n\n.. code:: python\n\n   \u003e\u003e\u003e e = 1 + 1 + (x() + 1) + (5 + y())\n   \u003e\u003e\u003e print(e)\n   add(2, add(add(x(), 1), add(5, y())))\n\nWe can make the evaluation strategy smarter by taking advantage of the commutativity and associativity of addition, as expressed by the ``commute_add`` and ``assoc_add`` handlers.\n\n.. code:: python\n\n   \u003e\u003e\u003e with handler(eager_mixed):\n   \u003e\u003e\u003e     print(evaluate(e))\n   add(8, add(x(), y()))\n\nLearn More\n----------\n\nMore examples and API documentation can be found in the `docs \u003chttps://basisresearch.github.io/effectful/index.html\u003e`_.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasisresearch%2Feffectful","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasisresearch%2Feffectful","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasisresearch%2Feffectful/lists"}