{"id":13577657,"url":"https://github.com/nnaisense/evotorch","last_synced_at":"2025-09-13T01:24:19.179Z","repository":{"id":55058301,"uuid":"522655946","full_name":"nnaisense/evotorch","owner":"nnaisense","description":"Advanced evolutionary computation library built directly on top of PyTorch, created at NNAISENSE.","archived":false,"fork":false,"pushed_at":"2024-04-29T21:09:07.000Z","size":44747,"stargazers_count":971,"open_issues_count":18,"forks_count":58,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-04-29T23:04:43.810Z","etag":null,"topics":["artificial-intelligence","distributed","evolutionary-algorithms","evolutionary-computation","gpu","neural-networks","neuroevolution","optimization","optimization-algorithms","python","pytorch","reinforcement-learning"],"latest_commit_sha":null,"homepage":"https://evotorch.ai","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/nnaisense.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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}},"created_at":"2022-08-08T18:03:06.000Z","updated_at":"2024-06-04T01:03:34.704Z","dependencies_parsed_at":"2022-08-14T10:30:49.433Z","dependency_job_id":"98c231fb-bb98-4d99-9bc7-6dbb1614401d","html_url":"https://github.com/nnaisense/evotorch","commit_stats":{"total_commits":61,"total_committers":6,"mean_commits":"10.166666666666666","dds":0.6557377049180328,"last_synced_commit":"5c585663aca9f1d4ee6fc86821418067f509b7cd"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnaisense%2Fevotorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnaisense%2Fevotorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnaisense%2Fevotorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnaisense%2Fevotorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nnaisense","download_url":"https://codeload.github.com/nnaisense/evotorch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247338601,"owners_count":20922989,"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":["artificial-intelligence","distributed","evolutionary-algorithms","evolutionary-computation","gpu","neural-networks","neuroevolution","optimization","optimization-algorithms","python","pytorch","reinforcement-learning"],"created_at":"2024-08-01T15:01:23.318Z","updated_at":"2025-04-05T12:30:52.044Z","avatar_url":"https://github.com/nnaisense.png","language":"Python","funding_links":[],"categories":["Python","Scientific Computation","Industry Strength Reinforcement Learning","**Other Resources**"],"sub_categories":["Code Repositories"],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://evotorch.ai\" rel=\"nofollow\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/nnaisense/evotorch/master/docs/assets/evotorch.svg\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://www.python.org/\" rel=\"nofollow\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/pyversions/evotorch\" alt=\"Python\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/evotorch/\" rel=\"nofollow\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/v/evotorch\" alt=\"PyPI\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/nnaisense/evotorch/blob/master/LICENSE\" rel=\"nofollow\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/l/evotorch\" alt=\"License\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://docs.evotorch.ai\" rel=\"nofollow\"\u003e\n        \u003cimg src=\"https://github.com/nnaisense/evotorch/actions/workflows/docs.yaml/badge.svg\" alt=\"Build\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/nnaisense/evotorch/actions/workflows/test.yaml\" rel=\"nofollow\"\u003e\n        \u003cimg src=\"https://github.com/nnaisense/evotorch/actions/workflows/test.yaml/badge.svg\" alt=\"Test\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/psf/black\" rel=\"nofollow\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" alt=\"Code style: black\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://results.pre-commit.ci/latest/github/nnaisense/evotorch/master\" rel=\"nofollow\"\u003e\n        \u003cimg src=\"https://results.pre-commit.ci/badge/github/nnaisense/evotorch/master.svg\" alt=\"pre-commit.ci status\" /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n---\n\nWelcome to the EvoTorch project!\nEvoTorch is an open source evolutionary computation library developed at [NNAISENSE](https://nnaisense.com), built on top of [PyTorch](https://pytorch.org/).\nSee the [documentation](https://docs.evotorch.ai) for in-depth guidance about using EvoTorch, and [join us on Slack](https://join.slack.com/t/evotorch/shared_invite/zt-1hcj9prrl-wQBMX4JtaB6WdGKSDjZGXw) for discussions.\n\nGet started by installing EvoTorch:\n```\npip install evotorch\n```\n\nWith EvoTorch, one can solve various optimization problems, regardless of whether they are differentiable (i.e. allow gradient descent). Among the problem types that are solvable with EvoTorch are:\n- Black-box optimization problems (continuous or discrete)\n- Reinforcement learning tasks\n- Supervised learning tasks\n\nVarious evolutionary computation algorithms are available in EvoTorch:\n- **Distribution-based search algorithms:**\n    - **PGPE:** Policy Gradients with Parameter-based Exploration.\n    - **XNES:** Exponential Natural Evolution Strategies.\n    - **CMA-ES:** Covariance Matrix Adaptation Evolution Strategies.\n    - **SNES:** Separable Natural Evolution Strategies.\n    - **CEM:** Cross Entropy Method.\n- **Population-based search algorithms:**\n    - **GeneticAlgorithm:** A genetic algorithm implementation. Also supports multiple objectives, in which case it behaves like **NSGA-II**.\n    - **CoSyNE:** Cooperative Synapse Neuroevolution.\n    - **MAPElites:** Multi-dimensional Archive of Phenotypic Elites\n\nSince all of these algorithms are implemented in PyTorch, they benefit from use of vectorization and parallelization on GPUs, drastically speeding up optimization when GPUs are available.\nUsing [Ray](https://github.com/ray-project/ray), EvoTorch scales these algorithms even further by splitting the workload across:\n- multiple CPUs\n- multiple GPUs\n- multiple computers in a Ray cluster\n\n# Examples\n\nBelow are some code examples that demonstrate the API of EvoTorch.\n\n## A black-box optimization example\n\nAny objective function defined to work with PyTorch can be used directly with EvoTorch.\nA non-vectorized objective function simply receives a solution as a 1-dimensional torch tensor, and returns a fitness as a scalar.\nA vectorized objective function receives a batch of solutions as a 2-dimensional torch tensor, and returns a 1-dimensional tensor of fitnesses.\nThe following example demonstrates how to define and solve the classical Rastrigin problem.\n\n```python\nfrom evotorch import Problem\nfrom evotorch.algorithms import SNES\nfrom evotorch.logging import StdOutLogger, PandasLogger\nimport math\nimport matplotlib.pyplot as plt\nimport torch\n\n\n# Declare the objective function\ndef rastrigin(x: torch.Tensor) -\u003e torch.Tensor:\n    A = 10\n    (_, n) = x.shape\n    return A * n + torch.sum((x**2) - A * torch.cos(2 * math.pi * x), 1)\n\n\n# Declare the problem\nproblem = Problem(\n    \"min\",\n    rastrigin,\n    initial_bounds=(-5.12, 5.12),\n    solution_length=100,\n    vectorized=True,\n    # device=\"cuda:0\"  # enable this line if you wish to use GPU\n)\n\n# Initialize the SNES algorithm to solve the problem\nsearcher = SNES(problem, popsize=1000, stdev_init=10.0)\n\n# Initialize a standard output logger, and a pandas logger\n_ = StdOutLogger(searcher, interval=10)\npandas_logger = PandasLogger(searcher)\n\n# Run SNES for the specified amount of generations\nsearcher.run(2000)\n\n# Get the progress of the evolution into a DataFrame with the\n# help of the PandasLogger, and then plot the progress.\npandas_frame = pandas_logger.to_dataframe()\npandas_frame[\"best_eval\"].plot()\nplt.show()\n```\n\n## A reinforcement learning example\n\nThe following example demonstrates how to solve reinforcement learning tasks that are available through the gym library.\n\n```python\nfrom evotorch.algorithms import PGPE\nfrom evotorch.logging import StdOutLogger, PicklingLogger\nfrom evotorch.neuroevolution import GymNE\n\n# Declare the problem to solve\nproblem = GymNE(\n    env=\"Humanoid-v4\",  # Solve the Humanoid-v4 task\n    network=\"Linear(obs_length, act_length)\",  # Linear policy\n    observation_normalization=True,  # Normalize the policy inputs\n    decrease_rewards_by=5.0,  # Decrease each reward by 5.0\n    num_actors=\"max\",  # Use all available CPUs\n    # num_actors=4,    # Explicit setting. Use 4 actors.\n)\n\n# Instantiate a PGPE algorithm to solve the problem\nsearcher = PGPE(\n    problem,\n    # Base population size\n    popsize=200,\n    # For each generation, sample more solutions until the\n    # number of simulator interactions reaches this threshold\n    num_interactions=int(200 * 1000 * 0.75),\n    # Stop re-sampling solutions if the current population size\n    # reaches or exceeds this number.\n    popsize_max=3200,\n    # Learning rates\n    center_learning_rate=0.0075,\n    stdev_learning_rate=0.1,\n    # Radius of the initial search distribution\n    radius_init=0.27,\n    # Use the ClipUp optimizer with the specified maximum speed\n    optimizer=\"clipup\",\n    optimizer_config={\"max_speed\": 0.15},\n)\n\n# Instantiate a standard output logger\n_ = StdOutLogger(searcher)\n\n# Optional: Instantiate a logger to pickle and save the results periodically.\n# In this example, among the saved results will be the center of the search\n# distribution, since we are using PGPE which is distribution-based.\n_ = PicklingLogger(searcher, interval=10)\n\n# Run the algorithm for the specified amount of generations\nsearcher.run(500)\n\n# Get the center point of the search distribution,\n# obtain a policy out of that point, and visualize the\n# agent using that policy.\ncenter_solution = searcher.status[\"center\"]\ntrained_policy = problem.make_net(center_solution)\nproblem.visualize(trained_policy)\n```\n\nMore examples can be found [here](examples/).\n\n# How to cite\n\nIf you use EvoTorch in your research, please consider citing our [paper](https://arxiv.org/abs/2302.12600).\n\n```bibtex\n@article{evotorch2023arxiv,\n  title={{EvoTorch}: Scalable Evolutionary Computation in {Python}},\n  author={Toklu, Nihat Engin and Atkinson, Timothy and Micka, Vojt\\v{e}ch and Liskowski, Pawe\\l{} and Srivastava, Rupesh Kumar},\n  journal={arXiv preprint},\n  year={2023},\n  note={https://arxiv.org/abs/2302.12600}\n}\n```\n\n# How to Contribute\n\nPlease see our [contribution guidelines](CONTRIBUTING.md).\n\n# Authors\n\n- [Nihat Engin Toklu](https://github.com/engintoklu)\n- [Timothy Atkinson](https://github.com/NaturalGradient)\n- [Vojtech Micka](https://github.com/Higgcz)\n- [Pawel Liskowski](https://github.com/pliskowski)\n- [Rupesh Kumar Srivastava](https://github.com/flukeskywalker)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnnaisense%2Fevotorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnnaisense%2Fevotorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnnaisense%2Fevotorch/lists"}