Next-generation Evolutionary Search, Learning & Planning

EvoTorchâ„¢ is designed to accelerate research and applications of Evolutionary Algorithms, with dedicated support for NeuroEvolution.

pip install evotorch
// 01

Import libraries

EvoTorch provides SOTA algorithms and utilities.

1import torch
2from evotorch import Problem
3from evotorch.algorithms import SNES
4from evotorch.logging import StdOutLogger
// 02

Define an objective

Use PyTorch to define a function to optimize

1def norm(x: torch.Tensor) -> torch.Tensor:
2  return torch.linalg.norm(x, dim=-1)
// 03

Define a problem

Instantiate the problem and select device(s) to use

1problem = Problem(
2  "min",
3  norm,
4  initial_bounds=(-10.0, 10.0),
5  solution_length=100,
6  vectorized=True,
7  # device="cuda",  # Enable for GPU support
8)
// 04

Run the evolutionary algorithm

1searcher = SNES(problem, popsize=1000, stdev_init=10.0)
2_ = StdOutLogger(searcher, interval=50)
3
4searcher.run(num_generations=1000)
// Examples

EvoTorch reduces the boiler-plate and lets you focus on solving problems at scale.

GPU acceleration
1import torch
2from evotorch.algorithms import SNES
3from evotorch.logging import StdOutLogger
4from evotorch import Problem
5
6# Minimize the Lennard-Jones atom cluster potential
7def pairwise_distances(positions: torch.Tensor) -> torch.Tensor:
8    positions = positions.view(positions.shape[0], -1, 3)
9    deltas = positions.unsqueeze(2) - positions.unsqueeze(1)
10    distances = torch.norm(deltas, dim=-1)
11    return distances
12
13
14def cluster_potential(positions: torch.Tensor) -> torch.Tensor:
15    distances = pairwise_distances(positions)
16    pairwise_cost = (1 / distances).pow(12) - (1 / distances).pow(6.0)
17    ut_pairwise_cost = torch.triu(pairwise_cost, diagonal=1)
18    potential = 4 * ut_pairwise_cost.sum(dim=(1, 2))
19    return potential
20
21
22problem = Problem(
23    "min",
24    cluster_potential,
25    initial_bounds=(-1e-12, 1e-12),
26    device="cuda:0" if torch.cuda.is_available() else "cpu",
27    solution_length=150,
28    # Evaluation is vectorized
29    vectorized=True,
30    # Higher-than-default precision
31    dtype=torch.float64,
32)
33
34searcher = SNES(problem, popsize=1000, stdev_init=0.01)
35logger = StdOutLogger(searcher, interval=100)
36
37searcher.run(5000)
Code
Visualisation
// Features

Scalable Parallelism

Evolutionary Algorithms and Neural Networks both thrive at scale. That's why EvoTorch lets you easily unleash experiments on multiple CPU nodes, GPU nodes, or both, building on top of Ray and PyTorch.

Flexibility

Search

Explore the space of images, programs, designs, or anything else

Optimize

Solve large-scale single/multiobjective engineering optimization problems

Plan

Implement fast Model Predictive Control with learned dynamics models

Control

Evolve high-performance neural controllers for complex reinforcement learning tasks (neuroevolution)

Enterprise Support

NNAISENSE offers paid support including customization for your preferred domain-specific problems, compute environments, production deployments and maintenance of trained solutions.

// Install

Start using EvoTorch

pip install evotorch
Contact usfor Enterprise Support.
// Evolved atNNAISENSEin Switzerland