Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add performance benchmarking scripts and run in CI #1978

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
dae101a
benchmarks: Upload initial models from JuliaDynamics
EwoutH Jan 18, 2024
0c284be
benchmarks: Add dictionary with configurations
EwoutH Jan 18, 2024
c67ad70
benchmarks: Update configurations, use relative imports
EwoutH Jan 18, 2024
9de2647
benchmarks: Add single script to run all benchmarks
EwoutH Jan 18, 2024
b72cdb1
benchmarks: Update configurations
EwoutH Jan 19, 2024
80d61be
benchmarks: Add generated pickle files to gitignore
EwoutH Jan 19, 2024
b6611af
benchmarks: Update global script to calculate and save stuff
EwoutH Jan 19, 2024
d038758
benchmarks: Write a script to statistically compare runs
EwoutH Jan 19, 2024
d31bb27
benchmarks: Remove seperate benchmark scripts
EwoutH Jan 19, 2024
5a17e8e
benchmarks: Black and ruff
EwoutH Jan 19, 2024
70149af
benchmarks: Add GitHub Actions workflow
EwoutH Jan 19, 2024
d2f1704
update versions
EwoutH Jan 19, 2024
2915730
Update checkout
EwoutH Jan 19, 2024
0b5bba9
Update benchmarks.yml
EwoutH Jan 19, 2024
e3d9355
install dependencies
EwoutH Jan 19, 2024
2de025e
test checkout first
EwoutH Jan 19, 2024
f026679
checkout main
EwoutH Jan 19, 2024
0b5949a
Run on all PRs
EwoutH Jan 19, 2024
2f97a85
Add PR repo to checkout
EwoutH Jan 19, 2024
6da4316
Add working directories
EwoutH Jan 19, 2024
2794921
"../benchmarks"
EwoutH Jan 19, 2024
4065ea6
no string
EwoutH Jan 19, 2024
4b8d908
./benchmarks
EwoutH Jan 19, 2024
1a5b5d5
Update benchmarks.yml
EwoutH Jan 19, 2024
134edea
Update benchmarks.yml
EwoutH Jan 19, 2024
64506ca
Update benchmarks.yml
EwoutH Jan 19, 2024
63f366e
remove other workflows
EwoutH Jan 19, 2024
c5bb3a4
Python path
EwoutH Jan 19, 2024
78e34d6
install tqdm
EwoutH Jan 19, 2024
1379ece
Update benchmarks.yml
EwoutH Jan 19, 2024
723caab
working directory benchmarks
EwoutH Jan 19, 2024
b12d6ab
test
EwoutH Jan 19, 2024
8be4bda
artifact circus
EwoutH Jan 19, 2024
c78a58a
don't clean on checkout
EwoutH Jan 19, 2024
dcdeca6
Revert "don't clean on checkout"
EwoutH Jan 19, 2024
d54f477
enable benchmark again
EwoutH Jan 19, 2024
ba1680b
install tabulate
EwoutH Jan 19, 2024
f50cc4e
Resolve deprecation of set-output
EwoutH Jan 19, 2024
bc61345
1 replication to go fast
EwoutH Jan 19, 2024
e99a11a
single quotes to work in Python 3.11 and lower
EwoutH Jan 19, 2024
71be9ad
base 64 again
EwoutH Jan 19, 2024
4ac96ee
Try via text file
EwoutH Jan 19, 2024
b880496
Revert "Try via text file"
EwoutH Jan 19, 2024
9836e19
use actions/github-script@v7
EwoutH Jan 19, 2024
f649925
Add fancy colors!
EwoutH Jan 19, 2024
dfacbd3
Add permission to write to issues
EwoutH Jan 19, 2024
da5c9d9
Remove explicit token
EwoutH Jan 19, 2024
ad116b1
Try using pull_request_target
EwoutH Jan 19, 2024
6369622
run on ready_for_review and opened
EwoutH Jan 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Performance benchmarks

on:
pull_request_target:
types: [opened, ready_for_review]
branches:
- main
issue_comment:
types: [created]

permissions:
issues: write
pull-requests: write

jobs:
run-benchmarks:
if: >
github.event_name == 'pull_request' ||
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '/rerun-benchmarks'))
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Add project directory to PYTHONPATH
run: echo "PYTHONPATH=$PYTHONPATH:$(pwd)" >> $GITHUB_ENV
- name: Install dependencies
run: pip install numpy pandas tqdm tabulate
# - name: Checkout main branch
# uses: actions/checkout@v4
# with:
# ref: main
# repository: projectmesa/mesa
- name: Run benchmarks on main branch
working-directory: benchmarks
run: python global_benchmark.py
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: timings-main
path: benchmarks/timings_1.pickle
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
clean: false
- name: Download benchmark results
uses: actions/download-artifact@v4
with:
name: timings-main
path: benchmarks
- name: Run benchmarks on PR branch
working-directory: benchmarks
run: python global_benchmark.py
- name: Run compare timings and encode output
working-directory: benchmarks
run: |
TIMING_COMPARISON=$(python compare_timings.py | base64 -w 0) # Base64 encode the output
echo "TIMING_COMPARISON=$TIMING_COMPARISON" >> $GITHUB_ENV

- name: Comment PR
uses: actions/github-script@v7
with:
github-token: ${{ GITHUB_TOKEN }}
script: |
const output = Buffer.from(process.env.TIMING_COMPARISON, 'base64').toString('utf-8');
const issue_number = context.issue.number;
github.rest.issues.createComment({
issue_number: issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Benchmark Comparison:\n\n' + output
});
113 changes: 0 additions & 113 deletions .github/workflows/build_lint.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/codespell.yml

This file was deleted.

46 changes: 0 additions & 46 deletions .github/workflows/release.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Benchmarking
benchmarking/**/*.pickle

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
26 changes: 0 additions & 26 deletions .pre-commit-config.yaml

This file was deleted.

80 changes: 80 additions & 0 deletions benchmarks/Flocking/Flocking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""
Flockers
=============================================================
A Mesa implementation of Craig Reynolds's Boids flocker model.
Uses numpy arrays to represent vectors.
"""

import numpy as np

from mesa import Model
from mesa.space import ContinuousSpace
from mesa.time import RandomActivation

from .boid import Boid


class BoidFlockers(Model):
"""
Flocker model class. Handles agent creation, placement and scheduling.
"""

def __init__(
self,
seed,
population,
width,
height,
vision,
speed=1,
separation=1,
cohere=0.03,
separate=0.015,
match=0.05,
):
"""
Create a new Flockers model.

Args:
population: Number of Boids
width, height: Size of the space.
speed: How fast should the Boids move.
vision: How far around should each Boid look for its neighbors
separation: What's the minimum distance each Boid will attempt to
keep from any other
cohere, separate, match: factors for the relative importance of
the three drives. """
super().__init__(seed=seed)
self.population = population
self.vision = vision
self.speed = speed
self.separation = separation
self.schedule = RandomActivation(self)
self.space = ContinuousSpace(width, height, True)
self.factors = dict(cohere=cohere, separate=separate, match=match)
self.make_agents()

def make_agents(self):
"""
Create self.population agents, with random positions and starting headings.
"""
for i in range(self.population):
x = self.random.random() * self.space.x_max
y = self.random.random() * self.space.y_max
pos = np.array((x, y))
velocity = np.random.random(2) * 2 - 1
boid = Boid(
i,
self,
pos,
self.speed,
velocity,
self.vision,
self.separation,
**self.factors
)
self.space.place_agent(boid, pos)
self.schedule.add(boid)

def step(self):
self.schedule.step()
Empty file added benchmarks/Flocking/__init__.py
Empty file.
Loading