Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 26 additions & 36 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,43 @@ jobs:
name: Check normal examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: Swatinem/rust-cache@v2
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Install system dependencies
uses: ./.github/workflows/install-deps
- run: cargo check --release

checkmpi:
name: Check mpi examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- uses: Swatinem/rust-cache@v2
- uses: mpi4py/setup-mpi@v1
with:
mpi: openmpi
- uses: dtolnay/rust-toolchain@stable
- name: Install system dependencies
uses: ./.github/workflows/install-deps
- run: cargo check --release --features distributed_mpi

checkvis:
name: Check visualization examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
- run: |
sudo apt update
sudo apt install pkg-config libx11-dev libasound2-dev libudev-dev
sudo apt install libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev
sudo apt install libxcb-render0-dev libxcb-xfixes0-dev libxcb1-dev
sudo apt install libudev-dev libasound2-dev portaudio19-dev build-essential libpulse-dev libdbus-1-dev
sudo apt install libfontconfig libfontconfig1-dev
- name: Install system dependencies
uses: ./.github/workflows/install-deps
- run: cargo check --release --features visualization

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
Expand All @@ -55,46 +54,37 @@ jobs:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Install system dependencies
uses: ./.github/workflows/install-deps
- run: cargo clippy

clippyvis:
name: Clippy visualization
name: Clippy visualization bayesian
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
with:
command: clippy
args: --features bayesian
components: clippy
- name: Install system dependencies
uses: ./.github/workflows/install-deps
- run: cargo clippy --features "visualization, bayesian"

clippympi:
name: Clippy visualization and mpi
name: Clippy mpi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- uses: mpi4py/setup-mpi@v1
with:
mpi: openmpi
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --features distributed_mpi
components: rustfmt
- run: |
sudo apt update
sudo apt install pkg-config libx11-dev libasound2-dev libudev-dev
sudo apt install libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev
sudo apt install libxcb-render0-dev libxcb-xfixes0-dev libxcb1-dev
sudo apt install libudev-dev libasound2-dev portaudio19-dev build-essential libpulse-dev libdbus-1-dev
sudo apt install libfontconfig libfontconfig1-dev
- run: cargo clippy --features "visualization, bayesian"
- name: Install system dependencies
uses: ./.github/workflows/install-deps
- run: cargo clippy --features distributed_mpi
37 changes: 37 additions & 0 deletions .github/workflows/install-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Install System Dependencies'
description: 'Install required system dependencies with caching'

runs:
using: 'composite'
steps:
- name: Cache APT packages
uses: actions/cache@v4
id: cache-apt
with:
path: /var/cache/apt/archives/*.deb
key: ${{ runner.os }}-apt-${{ hashFiles('**/action.yml') }}-v1
restore-keys: |
${{ runner.os }}-apt-

- name: Install system dependencies
if: steps.cache-apt.outputs.cache-hit != 'true'
shell: bash
run: |
sudo apt update
sudo apt install -y --download-only \
pkg-config libx11-dev libasound2-dev libudev-dev \
libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev \
libxcb-render0-dev libxcb-xfixes0-dev libxcb1-dev \
portaudio19-dev build-essential libpulse-dev libdbus-1-dev \
libfontconfig libfontconfig1-dev

- name: Install cached packages
shell: bash
run: |
sudo apt update
sudo apt install -y \
pkg-config libx11-dev libasound2-dev libudev-dev \
libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev \
libxcb-render0-dev libxcb-xfixes0-dev libxcb1-dev \
portaudio19-dev build-essential libpulse-dev libdbus-1-dev \
libfontconfig libfontconfig1-dev
12 changes: 6 additions & 6 deletions antsforaging/src/model/ant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Ant {
// with a probability of MOMENTUM_PROBABILITY. Otherwise, step in a random direction with a
// probability of RANDOM_ACTION_PROBABILITY.
pub fn act(&mut self, state: &ModelState) {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let mut max = -1.; // An initial, impossible pheromone.

let x = self.loc.x;
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Ant {
// A new maximum is found, or the maximux hasn't changed. In the latter case, we
// randomly choose whether to consider the new cell for the next step or not with an
// equal chance.
if m > max || (m == max && rng.gen_bool(1. / count as f64)) {
if m > max || (m == max && rng.random_bool(1. / count as f64)) {
// Latter expression is to take a random step towards paths with a good pheromone
max = m;
max_x = new_x;
Expand All @@ -158,7 +158,7 @@ impl Ant {
if max == 0. && self.last.is_some() {
// No tips from pheromones, consider stepping in the same direction
if let Some(last_loc) = self.last {
if rng.gen_bool(MOMENTUM_PROBABILITY) {
if rng.random_bool(MOMENTUM_PROBABILITY) {
let xm = x + (x - last_loc.x);
let ym = y + (y - last_loc.y);
// Don't go outside the field or in an obstacle
Expand All @@ -171,10 +171,10 @@ impl Ant {
}
}
}
} else if rng.gen_bool(RANDOM_ACTION_PROBABILITY) {
} else if rng.random_bool(RANDOM_ACTION_PROBABILITY) {
// All other ideas have failed, just choose a random direction
let xd: i32 = rng.gen_range(-1..2);
let yd: i32 = rng.gen_range(-1..2);
let xd: i32 = rng.random_range(-1..2);
let yd: i32 = rng.random_range(-1..2);
let xm = x + xd;
let ym = y + yd;
// Don't go outside the field, in an obstacle and do not stay still
Expand Down
10 changes: 5 additions & 5 deletions antsforaging/src/model/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ impl State for ModelState {
self.food_source_found = RwLock::new(false);
self.food_returned_home = RwLock::new(false);

let mut rng = rand::thread_rng();
let mut rng = rand::rng();

// Food generation
let x: i32 = if FOOD_XMIN == FOOD_XMAX {
FOOD_XMIN
} else {
rng.gen_range(FOOD_XMIN..FOOD_XMAX)
rng.random_range(FOOD_XMIN..FOOD_XMAX)
};
let y: i32 = if FOOD_YMIN == FOOD_YMAX {
FOOD_YMIN
} else {
rng.gen_range(FOOD_YMIN..FOOD_YMAX)
rng.random_range(FOOD_YMIN..FOOD_YMAX)
};
let food_location = Int2D { x, y };

Expand All @@ -122,12 +122,12 @@ impl State for ModelState {
let x: i32 = if HOME_XMIN == HOME_XMAX {
HOME_XMIN
} else {
rng.gen_range(HOME_XMIN..HOME_XMAX)
rng.random_range(HOME_XMIN..HOME_XMAX)
};
let y: i32 = if HOME_YMIN == HOME_YMAX {
HOME_YMIN
} else {
rng.gen_range(HOME_YMIN..HOME_YMAX)
rng.random_range(HOME_YMIN..HOME_YMAX)
};
let nest_location = Int2D { x, y };
self.obstacles_grid.set_object_location(
Expand Down
7 changes: 4 additions & 3 deletions flockers/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// No visualization specific imports
#[cfg(not(any(feature = "visualization", feature = "visualization_wasm")))]
use {
krabmaga::engine::schedule::Schedule, krabmaga::engine::state::State, krabmaga::Info,
krabmaga::*, std::time::Duration,
krabmaga::simulate,
// krabmaga::engine::state::State, krabmaga::*, std::time::Duration, krabmaga::engine::schedule::Schedule, krabmaga::Info,
};
// Visualization specific imports
#[cfg(any(feature = "visualization", feature = "visualization_wasm"))]
Expand Down Expand Up @@ -35,7 +35,8 @@ fn main() {
let dim = (800., 800.);
let num_agents = 64000;
let state = Flocker::new(dim, num_agents);
let _ = simulate_old!(state, step, 1, Info::Normal);
// let _ = simulate!(state, step, 1, Info::Normal);
let _ = simulate!(state, step, 1);
}

// Main used when a visualization feature is applied.
Expand Down
6 changes: 3 additions & 3 deletions flockers/src/model/bird.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ impl Agent for Bird {
};

//randomness
let mut rng = rand::thread_rng();
let r1: f32 = rng.gen();
let mut rng = rand::rng();
let r1: f32 = rng.random();
let x_rand = r1 * 2.0 - 1.0;
let r2: f32 = rng.gen();
let r2: f32 = rng.random();
let y_rand = r2 * 2.0 - 1.0;

let square = (x_rand * x_rand + y_rand * y_rand).sqrt();
Expand Down
6 changes: 3 additions & 3 deletions flockers/src/model/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ impl State for Flocker {
}

fn init(&mut self, schedule: &mut Schedule) {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
// Should be moved in the init method on the model exploration changes
for bird_id in 0..self.initial_flockers {
let r1: f32 = rng.gen();
let r2: f32 = rng.gen();
let r1: f32 = rng.random();
let r2: f32 = rng.random();
let last_d = Real2D { x: 0., y: 0. };
let loc = Real2D {
x: self.dim.0 * r1,
Expand Down
33 changes: 4 additions & 29 deletions flockers_mpi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,13 @@ cfg_if! {
mod model;

// No visualization specific imports
#[cfg(not(any(feature = "visualization", feature = "visualization_wasm")))]
#[cfg(any(feature = "distributed_mpi"))]
use {
krabmaga::engine::schedule::Schedule, krabmaga::engine::state::State,
krabmaga::simulate_mpi, krabmaga::Info, /* krabmaga::ProgressBar, */ krabmaga::*,
std::time::Duration,
};

//use krabmaga::*;

// Visualization specific imports
#[cfg(any(feature = "visualization", feature = "visualization_wasm"))]
use {
crate::visualization::vis_state::VisState, krabmaga::bevy::prelude::Color,
krabmaga::visualization::visualization::Visualization,
};

#[cfg(any(feature = "visualization", feature = "visualization_wasm"))]
mod visualization;

pub static COHESION: f32 = 0.8;
pub static AVOIDANCE: f32 = 1.0;
Expand All @@ -46,28 +35,14 @@ cfg_if! {

#[cfg(any(feature = "distributed_mpi"))]
fn main() {
let step = 200;
let step = 100;

let dim = (1131., 1131.);
let num_agents = 128000;
let dim = (100., 100.);
let num_agents = 1000;

let state = Flocker::new(dim, num_agents);
let _ = simulate_mpi!(state, step, 1, Info::Normal);
}

// Main used when a visualization feature is applied.
#[cfg(any(feature = "visualization", feature = "visualization_wasm"))]
fn main() {
let dim = (200., 200.);
let num_agents = 100;
let state = Flocker::new(dim, num_agents);
Visualization::default()
.with_window_dimensions(1000., 700.)
.with_simulation_dimensions(dim.0 as f32, dim.1 as f32)
.with_background_color(Color::rgb(0., 0., 0.))
.with_name("Flockers")
.start::<VisState, Flocker>(VisState, state);
}
}
else {
fn main() {}
Expand Down
6 changes: 3 additions & 3 deletions flockers_mpi/src/model/bird.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ cfg_if! {
};

//randomness
let mut rng = rand::thread_rng();
let r1: f32 = rng.gen();
let mut rng = rand::rng();
let r1: f32 = rng.random();
let x_rand = r1 * 2.0 - 1.0;
let r2: f32 = rng.gen();
let r2: f32 = rng.random();
let y_rand = r2 * 2.0 - 1.0;

let square = (x_rand * x_rand + y_rand * y_rand).sqrt();
Expand Down
6 changes: 3 additions & 3 deletions flockers_mpi/src/model/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ cfg_if! {
///The other processes, instead, will be waiting to receive the agents from process 0.
fn init(&mut self, schedule: &mut Schedule) {
let world = UNIVERSE.world();
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

//Process 0 creates the agents
if world.rank() == 0 {
Expand All @@ -63,8 +63,8 @@ cfg_if! {

//For each initial agent...
for bird_id in 0..self.initial_flockers {
let r1: f32 = rng.gen();
let r2: f32 = rng.gen();
let r1: f32 = rng.random();
let r2: f32 = rng.random();
let last_d = Real2D { x: 0., y: 0. };
let loc = Real2D {
x: self.dim.0 * r1,
Expand Down
Loading
Loading