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
8 changes: 8 additions & 0 deletions .containerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*
!Cell2Fire/*.cpp
!Cell2Fire/*.h
!Cell2Fire/makefile
!test/unit_tests/*.cpp
!test/model
!test/target_results.zip
!test/test.sh
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y g++ make libboost-dev libtiff-dev catch2
sudo apt-get install -y g++ make libboost-random-dev libtiff-dev catch2

- name: Build
run: |
Expand Down
89 changes: 89 additions & 0 deletions .github/workflows/mt19937_boost.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
name: rng boost::mt19937 cross-os congruence
on:
workflow_dispatch:
jobs:
build-and-run:
name: Build and run (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies (Ubuntu)
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get update -q
sudo apt-get install -y build-essential libboost-random-dev
- name: Install dependencies (macOS)
if: startsWith(matrix.os, 'macos')
run: |
brew update
brew install llvm boost
echo "Using clang++ from Homebrew"
echo "CXX=$(brew --prefix)/opt/llvm/bin/clang++" >> $GITHUB_ENV
- name: Set up Visual Studio shell
if: startsWith(matrix.os, 'windows')
uses: egor-tensin/vs-shell@v2
with:
arch: x64
- name: Set up Vcpkg (Windows)
if: startsWith(matrix.os, 'windows')
shell: powershell
run: |
# Use preinstalled vcpkg from runner images
& "$env:VCPKG_INSTALLATION_ROOT\vcpkg.exe" install boost-random:x64-windows
Write-Host "VCPKG include: $env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\include"
"$env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\include" | Out-File -FilePath include_path.txt -Encoding ascii
- name: Build (Ubuntu)
if: startsWith(matrix.os, 'ubuntu')
run: |
c++ -std=c++17 test/tech/mt19937_boost.cpp -o mt19937_boost
- name: Build (macOS)
if: startsWith(matrix.os, 'macos')
run: |
"$CXX" -std=c++17 -I"$(brew --prefix)/include" -L"$(brew --prefix)/lib" test/tech/mt19937_boost.cpp -o mt19937_boost
- name: Build (Windows)
if: startsWith(matrix.os, 'windows')
shell: powershell
run: |
# Add include path and compile
$include = Join-Path $env:VCPKG_INSTALLATION_ROOT 'installed\x64-windows\include'
$env:INCLUDE = "$include;$env:INCLUDE"
cmd /c "cl /std:c++17 /EHsc /I `"$include`" test\tech\mt19937_boost.cpp /Fe:mt19937_boost.exe"
- name: Run emitter
shell: bash
run: |
if [[ "$RUNNER_OS" == "Windows" ]]; then
./mt19937_boost.exe > mt19937_${{ runner.os }}.txt
else
./mt19937_boost > mt19937_${{ runner.os }}.txt
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: mt19937_${{ runner.os }}
path: mt19937_${{ runner.os }}.txt
compare:
name: Compare outputs
runs-on: ubuntu-latest
needs: build-and-run
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Diff Ubuntu vs macOS
run: |
diff -u artifacts/mt19937_Linux/mt19937_Linux.txt artifacts/mt19937_macOS/mt19937_macOS.txt
- name: Diff Ubuntu vs Windows (normalize CRLF)
run: |-
sudo apt-get install -y dos2unix
dos2unix artifacts/mt19937_Windows/mt19937_Windows.txt
diff -u artifacts/mt19937_Windows/mt19937_Windows.txt artifacts/mt19937_Linux/mt19937_Linux.txt
79 changes: 79 additions & 0 deletions .github/workflows/mt19937_std.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
name: rng std::mt19937 cross-os congruence
on:
workflow_dispatch:
jobs:
build-and-run:
name: Build and run (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup MSBuild (Windows)
if: startsWith(matrix.os, 'windows')
uses: microsoft/setup-msbuild@v2
- name: Ensure compiler (Ubuntu)
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get update -q
sudo apt-get install -y build-essential
shell: bash
- name: Ensure compiler (macOS)
if: startsWith(matrix.os, 'macos')
run: |
xcode-select --install || true
shell: bash
- name: Build (Linux/macOS)
if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
run: |
c++ -std=c++17 test/tech/mt19937_std.cpp -o mt19937_std
shell: bash
- name: Set up Visual Studio shell
if: startsWith(matrix.os, 'windows')
uses: egor-tensin/vs-shell@v2
with:
arch: x64
- name: Build (Windows)
if: startsWith(matrix.os, 'windows')
run: |
cl /std:c++17 test\tech\mt19937_std.cpp /Fe:mt19937_std.exe
shell: pwsh
- name: Run and capture (Linux/macOS)
if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
run: |
./mt19937_std > mt19937_${{ runner.os }}.txt
shell: bash
- name: Run and capture (Windows)
if: startsWith(matrix.os, 'windows')
run: |
.\mt19937_std.exe | Out-File -FilePath mt19937_${{ runner.os }}.txt -Encoding ascii
shell: pwsh
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: mt19937_${{ runner.os }}
path: mt19937_${{ runner.os }}.txt
compare:
name: Compare outputs
runs-on: ubuntu-latest
needs: build-and-run
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Diff Ubuntu vs macOS
run: |
diff -u artifacts/mt19937_Linux/mt19937_Linux.txt artifacts/mt19937_macOS/mt19937_macOS.txt
- name: Diff Ubuntu vs Windows (normalize CRLF)
run: |-
sudo apt-get install -y dos2unix
dos2unix artifacts/mt19937_Windows/mt19937_Windows.txt
diff -u artifacts/mt19937_Windows/mt19937_Windows.txt artifacts/mt19937_Linux/mt19937_Linux.txt
33 changes: 28 additions & 5 deletions Cell2Fire/ReadCSV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,41 @@

#include "tiffio.h"
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <fstream>
#include <iostream>
#include <iterator>
#include <math.h>
#include <cstring>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

// Local minimal replacement for boost::algorithm::split with is_any_of semantics.
// C++14-friendly (uses std::string, not std::string_view).
// When compress == false, preserves empty tokens (equivalent to token_compress_off).
// When compress == true, collapses consecutive delimiters.
static std::vector<std::string>
split_any_of(const std::string& s, const std::string& delims, bool compress)
{
std::vector<std::string> out;
const size_t n = s.size();
size_t i = 0;
while (i <= n) {
size_t j = s.find_first_of(delims, i);
if (j == std::string::npos) j = n;
out.emplace_back(s.substr(i, j - i));
if (j == n) break;
if (compress) {
i = j + 1;
while (i < n && delims.find(s[i]) != std::string::npos) ++i;
} else {
i = j + 1;
}
}
return out;
}

/**
* Creates an instance of CSVReader.
* @param filename name of file to read
Expand Down Expand Up @@ -104,8 +129,7 @@ CSVReader::getData(string filename)
}
else
{
std::vector<std::string> vec;
boost::algorithm::split(vec, line, boost::is_any_of(this->delimeter));
std::vector<std::string> vec = split_any_of(line, this->delimeter, false);
dataList.push_back(vec);
}
}
Expand Down Expand Up @@ -206,8 +230,7 @@ CSVReader::getData(string filename)
{
while (getline(file, line))
{
std::vector<std::string> vec;
boost::algorithm::split(vec, line, boost::is_any_of(this->delimeter));
std::vector<std::string> vec = split_any_of(line, this->delimeter, false);
dataList.push_back(vec);
}
}
Expand Down
1 change: 0 additions & 1 deletion Cell2Fire/ReadCSV.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "tiffio.h"
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <fstream>
#include <iostream>
#include <iterator>
Expand Down
1 change: 0 additions & 1 deletion Cell2Fire/WriteCSV.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "WriteCSV.h"

#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <cmath>
#include <fstream>
#include <iostream>
Expand Down
1 change: 0 additions & 1 deletion Cell2Fire/WriteCSV.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define WRITECSV

#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <cmath>
#include <fstream>
#include <iostream>
Expand Down
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,34 +105,30 @@ Cell2Fire --final-grid --output-messages --out-ros --sim S --nsims 2 --seed 123
# check the results: to convert to tiff or see the results in QGIS, use the plugin
```

### Get the container

![Tutorial here](container/README.md), TL;DR:

### Containerized
TL;DR:
```bash
# have or install podman (or docker)
sudo apt install podman

# download the container [Dockerfile](https://github.com/fire2a/C2F-W/raw/refs/heads/feature-containerize/container/Dockerfile)
wget https://github.com/fire2a/C2F-W/raw/refs/heads/feature-containerize/container/Dockerfile

# build
podman build -t c2f -f Dockerfile .

# Done! Usage mounting the instance and results directories into the container
podman build -t cell2fire -f container/Containerfile .
mkdir results
podman run -v $(pwd):/mnt c2f --input-instance-folder /mnt/data/Kitral/Portillo-tif --output-folder /mnt/results --nsims 3 --sim K --grids | tee results/log.txt
podman run -v $(pwd):/mnt cell2fire \
--input-instance-folder /mnt/data/ScottAndBurgan/Vilopriu_2013-tif \
--output-folder /mnt/results \
--nsims 3 --sim S \
--output-messages --ignitionsLog | tee results/log.txt
rm -r results/*
```

[More options and tutorial here](container/README.md)

## Collaborative

Compile it

```bash
# dependencies
sudo apt install g++-12 libboost-all-dev libeigen3-dev libtiff-dev
sudo apt install g++ libboost-random-dev libtiff-dev
# or brew
brew install gcc@12 libomp eigen boost libtiff # llvm ?
brew install gcc@12 libomp boost libtiff # llvm ?

# fork & clone
git clone git@github.com:<YOU>/C2F-W.git
Expand Down
21 changes: 21 additions & 0 deletions container/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM debian:stable-slim

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y --no-install-recommends \
g++ \
libboost-random-dev \
libtiff-dev \
make && \
rm -rf /var/lib/apt/lists/*

COPY Cell2Fire Cell2Fire

WORKDIR /Cell2Fire

RUN make clean && \
make

ENTRYPOINT ["/Cell2Fire/Cell2Fire"]

28 changes: 28 additions & 0 deletions container/Containerfile+tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM debian:stable-slim

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y --no-install-recommends \
catch2 \
g++ \
libboost-random-dev \
libtiff-dev \
make \
unzip && \
rm -rf /var/lib/apt/lists/*

COPY Cell2Fire Cell2Fire

COPY test /test

WORKDIR /Cell2Fire

RUN make clean && \
make tests && \
make

RUN cd /test && ./test.sh

ENTRYPOINT ["/Cell2Fire/Cell2Fire"]

2 changes: 1 addition & 1 deletion container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM debian:stable
LABEL authors="matilde"

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y g++-12 libboost-all-dev libeigen3-dev libtiff-dev git make unzip lsb-release catch2
RUN apt-get update && apt-get install -y g++ libboost-random-dev libtiff-dev git make unzip catch2

RUN git clone https://github.com/fire2a/C2F-W.git

Expand Down
Loading