Skip to content

Commit baff094

Browse files
committed
fxies
1 parent 9ee99f9 commit baff094

File tree

6 files changed

+990
-321
lines changed

6 files changed

+990
-321
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Matrix Multiplication via Tensor Decomposition
2+
3+
This example demonstrates how to use OpenEvolve to discover efficient matrix multiplication algorithms through tensor decomposition, as described in the AlphaEvolve paper.
4+
5+
This implementation uses PyTorch for tensor operations and optimization, making it widely compatible across different platforms.
6+
7+
## Background
8+
9+
Matrix multiplication is a fundamental operation in computational mathematics and computer science. The naive algorithm for multiplying two matrices requires O(n³) scalar multiplications, but more efficient algorithms exist. In 1969, Volker Strassen discovered an algorithm that requires only 7 scalar multiplications to multiply 2×2 matrices, which leads to an O(n^log₂(7)) ≈ O(n^2.81) algorithm when applied recursively.
10+
11+
The key insight in this example is that matrix multiplication can be represented as a 3D tensor, and finding a low-rank decomposition of this tensor directly translates to discovering an efficient matrix multiplication algorithm. The rank of the decomposition equals the number of scalar multiplications needed.
12+
13+
## Implementation
14+
15+
This example evolves a tensor decomposition algorithm that aims to find minimum-rank decompositions for matrix multiplication tensors. The decomposition process uses gradient-based optimization with various techniques like:
16+
17+
- Regularization to encourage sparse, interpretable solutions
18+
- Specialized initialization strategies for better convergence
19+
- Adaptive learning rates and optimization techniques
20+
- Methods to promote integer or half-integer coefficients
21+
- Techniques to improve numerical stability and convergence
22+
- Cyclical annealing schedules and noise injection for exploration
23+
24+
## Installation
25+
26+
The matrix multiplication example requires additional dependencies beyond the base OpenEvolve requirements. These include PyTorch for efficient tensor operations and gradient-based optimization.
27+
28+
### Option 1: Using the setup script
29+
30+
```bash
31+
# Make the setup script executable
32+
chmod +x setup.sh
33+
34+
# Run the setup script
35+
./setup.sh
36+
```
37+
38+
### Option 2: Manual installation
39+
40+
```bash
41+
# Create and activate a virtual environment (recommended)
42+
python -m venv .venv
43+
source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
44+
45+
# Install the main OpenEvolve package in development mode
46+
pip install -e ..
47+
48+
# Install example-specific dependencies
49+
pip install -r requirements.txt
50+
```
51+
52+
## Running the Example
53+
54+
To run the example:
55+
56+
```bash
57+
python optimize.py --iterations 100 --output output
58+
```
59+
60+
Parameters:
61+
- `--iterations`: Number of evolutionary iterations (default: 100)
62+
- `--output`: Directory to store results (default: "output")
63+
- `--config`: Path to a custom configuration file (optional)
64+
65+
Note: The first run might take longer as PyTorch compiles the computation graph.
66+
67+
## Evaluation
68+
69+
The implementation is evaluated on several key aspects:
70+
71+
1. **Correctness**: Whether the decomposition accurately reconstructs the original tensor
72+
2. **Rank Quality**: How low of a rank the algorithm can achieve for different matrix sizes
73+
3. **Time Efficiency**: How quickly the algorithm converges to a valid decomposition
74+
75+
The examples include various matrix sizes, with special emphasis on cases where improvements over known bounds are possible.
76+
77+
## Expected Results
78+
79+
After evolution, you should expect to see improvements in:
80+
81+
- The ability to find lower-rank decompositions for various matrix sizes
82+
- More reliable convergence even with lower ranks
83+
- Faster convergence to valid decompositions
84+
- Decompositions with simpler (integer or half-integer) coefficients
85+
86+
The ultimate goal is to match or beat the state-of-the-art results mentioned in the AlphaEvolve paper, such as:
87+
- 4×4 complex matrices: Finding a rank-48 decomposition (better than Strassen's recursive algorithm which requires 49)
88+
- Various rectangular matrices: Improving on previously known bounds
89+
90+
## References
91+
92+
- Strassen, V. (1969). "Gaussian elimination is not optimal". Numerische Mathematik, 13(4), 354-356.
93+
- AlphaEvolve paper: "AlphaEvolve: A coding agent for scientific and algorithmic discovery" (2025)

0 commit comments

Comments
 (0)