Skip to content

Commit

Permalink
Merge branch 'main' into docs-how-to-add-a-parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jetuk committed Aug 6, 2024
2 parents 6940e01 + 01bf34e commit 5aafe40
Show file tree
Hide file tree
Showing 62 changed files with 1,807 additions and 467 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/deploy-book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Deploy book
on:
# Deploy the book when the Rust (Linux) workflow completes on main
workflow_run:
workflows: ["Rust (Linux)"]
branches: [main]
workflows: [ "Rust (Linux)" ]
branches: [ main ]
types:
- completed

Expand All @@ -18,6 +18,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: swatinem/rust-cache@v2
- name: Install latest mdbook
run: |
tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name')
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:

env:
CARGO_TERM_COLOR: always
# Make sure CI fails on all warnings, including Clippy lints
RUSTFLAGS: "-Dwarnings"

jobs:
build:
Expand All @@ -17,7 +19,9 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true

- uses: swatinem/rust-cache@v2
- name: Run Clippy
run: cargo clippy --all-targets --features highs,cbc --all --exclude ipm-simd
- name: Install latest mdbook
run: |
tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name')
Expand All @@ -27,9 +31,9 @@ jobs:
echo "$(pwd)/bin" >> $GITHUB_PATH
- name: Build
run: cargo build --verbose --features highs --workspace --exclude ipm-simd --exclude pywr-python
run: cargo build --verbose --features highs,cbc --workspace --exclude ipm-simd --exclude pywr-python
- name: Run tests
run: cargo test --features highs
run: cargo test --features highs,cbc
- name: Run mdbook tests
run: mdbook test ./pywr-book

Expand All @@ -41,6 +45,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: swatinem/rust-cache@v2
- name: Build
run: cargo build --verbose --no-default-features --package [email protected]
- name: Run tests
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: swatinem/rust-cache@v2
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
Expand Down Expand Up @@ -98,6 +99,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: swatinem/rust-cache@v2
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:

env:
CARGO_TERM_COLOR: always
# Make sure CI fails on all warnings, including Clippy lints
RUSTFLAGS: "-Dwarnings"
ACTIONS_RUNNER_DEBUG: true
ACTIONS_STEP_DEBUG: true

jobs:
build:
Expand All @@ -17,7 +21,12 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: swatinem/rust-cache@v2
- name: Run Clippy
run: cargo clippy --all-targets --features highs,cbc
- name: Build
run: cargo build --verbose --workspace --exclude ipm-simd --exclude pywr-python
run: cargo build --verbose --features highs,cbc --workspace --exclude ipm-simd --exclude pywr-python
- name: Run tests
run: cargo test
# Only test the library and binaries, not the docs
# There were some issues with the docs tests timing out on Windows CI
run: cargo test --features highs,cbc --verbose --lib --bins -- --test-threads=1
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ ndarray = "0.15.3"
polars = { version = "0.41.2", features = ["lazy", "rows", "ndarray"] }
pyo3-polars = "0.15"
pyo3 = { version = "0.21", default-features = false }
pyo3-log = "0.10"
pyo3-log = "0.11"
tracing = { version = "0.1", features = ["log"] }
csv = "1.1"
hdf5 = { git = "https://github.com/aldanor/hdf5-rust.git", package = "hdf5", features = ["static", "zlib"] }
pywr-v1-schema = { git = "https://github.com/pywr/pywr-schema/", tag = "v0.13.0", package = "pywr-schema" }
pywr-v1-schema = "0.14"
chrono = { version = "0.4.34", features = ["serde"] }
schemars = { version = "0.8.16", features = ["chrono"] }
23 changes: 6 additions & 17 deletions ipm-ocl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,14 @@ where
let row_offsets = ocl::Buffer::<u32>::builder()
.queue(queue.clone())
.flags(ocl::flags::MEM_READ_WRITE)
.copy_host_slice(
a.row_offsets()
.into_iter()
.map(|r| *r as u32)
.collect::<Vec<_>>()
.as_slice(),
)
.copy_host_slice(a.row_offsets().iter().map(|r| *r as u32).collect::<Vec<_>>().as_slice())
.len(a.row_offsets().len())
.build()?;

let col_indices = ocl::Buffer::<u32>::builder()
.queue(queue.clone())
.flags(ocl::flags::MEM_READ_WRITE)
.copy_host_slice(
a.col_indices()
.into_iter()
.map(|r| *r as u32)
.collect::<Vec<_>>()
.as_slice(),
)
.copy_host_slice(a.col_indices().iter().map(|r| *r as u32).collect::<Vec<_>>().as_slice())
.len(a.col_indices().len())
.build()?;

Expand Down Expand Up @@ -439,6 +427,7 @@ impl<T> PathFollowingDirectClSolver<T>
where
T: ocl::OclPrm + GetClProgram,
{
#[allow(clippy::too_many_arguments)]
pub fn from_data(
queue: &ocl::Queue,
program: &ocl::Program,
Expand All @@ -456,7 +445,7 @@ where
let buffers = PathFollowingDirectClBuffers::from_data(&a, num_lps, queue)?;

let kernel_normal_init = ocl::Kernel::builder()
.program(&program)
.program(program)
.name("normal_eqn_init")
.queue(queue.clone())
.global_work_size(num_lps)
Expand All @@ -470,7 +459,7 @@ where
.build()?;

let kernel_normal_eq_step = ocl::Kernel::builder()
.program(&program)
.program(program)
.name("normal_eqn_step")
.queue(queue.clone())
.global_work_size(num_lps)
Expand Down Expand Up @@ -619,6 +608,6 @@ mod tests {
let queue = ocl::Queue::new(&context, device, None).unwrap();

let a = test_matrx();
let pf = PathFollowingDirectClBuffers::from_data(&a, 10, &queue).unwrap();
let _pf = PathFollowingDirectClBuffers::from_data(&a, 10, &queue).unwrap();
}
}
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ name = "pywr"
version = "2.0.0beta"
description = ""
authors = [
{name="James Tomlinson", email="[email protected]>"}
{ name = "James Tomlinson", email = "[email protected]>" }
]
readme = "README.md"
requires-python = ">=3.9"
license = "MIT OR Apache-2.0"
dependencies = [
"pandas",
"polars",
"pyarrow",
"click"
"pandas",
"polars",
"pyarrow",
"click"
]

[build-system]
Expand Down
41 changes: 21 additions & 20 deletions pywr-book/src/building_documentation.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Contributing to Documentation

The documentation for Pywr V2 is located in the pywr-next repository, [here](https://github.com/pywr/pywr-next) in the `pywr-book` subfolder.
The documentation for Pywr V2 is located in the pywr-next repository, [here](https://github.com/pywr/pywr-next) in the
`pywr-book` subfolder.

The documentation is written using 'markdown', a format which enables easy formatting for the web.
The documentation is written using 'markdown', a format which enables easy formatting for the web.

This website can help get started: [www.markdownguide.org](https://www.markdownguide.org)

To contribute documentation for Pywr V2, we recommend following the steps below to ensure we can review and integrate any changes as easily as possible.
To contribute documentation for Pywr V2, we recommend following the steps below to ensure we can review and integrate
any changes as easily as possible.

## Steps to create documentation

Expand All @@ -16,19 +18,19 @@ To contribute documentation for Pywr V2, we recommend following the steps below

2. Clone the fork

``` <bash>
```bash
git clone https://github.com/MYUSER/pywr-next
```

3. Create a branch

``` <bash>
```bash
git checkout -b my-awesome-docs
```

4. Open the book documentation in your favourite editor

``` <bash>
```bash
vi pywr-next/pywr-book/introduction.md
```

Expand All @@ -38,27 +40,26 @@ Which should look something like this:

5. Having modified the documentation, add and commit the changes <ins>using the commit format<ins>

```<bash>
```bash
git add introduction.md"
```
```<bash>
```bash
git commit -m "docs: Add an example documentation"
```
6. Create a pull request from your branch
1. In your fork, click on the 'Pull Requests' tab
![Pull request](./images/making_documentation/pr1.png "Pull Request")
6. Create a pull request from your branch
1. In your fork, click on the 'Pull Requests' tab
![Pull request](./images/making_documentation/pr1.png "Pull Request")
2. Click on 'New Pull Request'
![Pull request](./images/making_documentation/pr2.png "Pull Request")
2. Click on 'New Pull Request'
![Pull request](./images/making_documentation/pr2.png "Pull Request")
3. Choose your branch from the drop-down on the right-hand-side
![Pull request](./images/making_documentation/pr3.png "Pull Request")
3. Choose your branch from the drop-down on the right-hand-side
![Pull request](./images/making_documentation/pr3.png "Pull Request")
4. Click 'Create Pull Request' when the button appears
![Pull request](./images/making_documentation/pr4.png "Pull Request")

5. Add a note if you want, and click 'Create Pull Request'
![Pull request](./images/making_documentation/pr5.png "Pull Request")
4. Click 'Create Pull Request' when the button appears
![Pull request](./images/making_documentation/pr4.png "Pull Request")
5. Add a note if you want, and click 'Create Pull Request'
![Pull request](./images/making_documentation/pr5.png "Pull Request")
6 changes: 6 additions & 0 deletions pywr-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ schemars = { workspace = true }

pywr-core = { path = "../pywr-core" }
pywr-schema = { path = "../pywr-schema" }

[features]
cbc = ["pywr-core/cbc", "pywr-schema/cbc"]
highs = ["pywr-core/highs", "pywr-schema/highs"]
ipm-ocl = ["pywr-core/ipm-ocl", "pywr-schema/ipm-ocl"]
ipm-simd = ["pywr-core/ipm-simd", "pywr-schema/ipm-simd"]
10 changes: 5 additions & 5 deletions pywr-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::path::{Path, PathBuf};
enum Solver {
Clp,
#[cfg(feature = "highs")]
HIGHS,
Highs,
#[cfg(feature = "ipm-ocl")]
CLIPMF32,
#[cfg(feature = "ipm-ocl")]
Expand All @@ -38,7 +38,7 @@ impl Display for Solver {
match self {
Solver::Clp => write!(f, "clp"),
#[cfg(feature = "highs")]
Solver::HIGHS => write!(f, "highs"),
Solver::Highs => write!(f, "highs"),
#[cfg(feature = "ipm-ocl")]
Solver::CLIPMF32 => write!(f, "clipmf32"),
#[cfg(feature = "ipm-ocl")]
Expand Down Expand Up @@ -265,7 +265,7 @@ fn run(path: &Path, solver: &Solver, data_path: Option<&Path>, output_path: Opti
match *solver {
Solver::Clp => model.run::<ClpSolver>(&ClpSolverSettings::default()),
#[cfg(feature = "highs")]
Solver::HIGHS => model.run::<HighsSolver>(&HighsSolverSettings::default()),
Solver::Highs => model.run::<HighsSolver>(&HighsSolverSettings::default()),
#[cfg(feature = "ipm-ocl")]
Solver::CLIPMF32 => model.run_multi_scenario::<ClIpmF32Solver>(&ClIpmSolverSettings::default()),
#[cfg(feature = "ipm-ocl")]
Expand All @@ -287,7 +287,7 @@ fn run_multi(path: &Path, solver: &Solver, data_path: Option<&Path>, output_path
match *solver {
Solver::Clp => model.run::<ClpSolver>(&ClpSolverSettings::default()),
#[cfg(feature = "highs")]
Solver::HIGHS => model.run::<HighsSolver>(&HighsSolverSettings::default()),
Solver::Highs => model.run::<HighsSolver>(&HighsSolverSettings::default()),
#[cfg(feature = "ipm-ocl")]
Solver::CLIPMF32 => model.run_multi_scenario::<ClIpmF32Solver>(&ClIpmSolverSettings::default()),
#[cfg(feature = "ipm-ocl")]
Expand All @@ -305,7 +305,7 @@ fn run_random(num_systems: usize, density: usize, num_scenarios: usize, solver:
match *solver {
Solver::Clp => model.run::<ClpSolver>(&ClpSolverSettings::default()),
#[cfg(feature = "highs")]
Solver::HIGHS => model.run::<HighsSolver>(&HighsSolverSettings::default()),
Solver::Highs => model.run::<HighsSolver>(&HighsSolverSettings::default()),
#[cfg(feature = "ipm-ocl")]
Solver::CLIPMF32 => model.run_multi_scenario::<ClIpmF32Solver>(&ClIpmSolverSettings::default()),
#[cfg(feature = "ipm-ocl")]
Expand Down
1 change: 1 addition & 0 deletions pywr-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ serde = { version = "1.0.197", features = ["derive"] }
criterion = "0.5"

[features]
cbc = []
highs = ["dep:highs-sys"]
ipm-ocl = ["dep:ipm-ocl", "dep:ocl"]
ipm-simd = ["dep:ipm-simd"]
Expand Down
12 changes: 7 additions & 5 deletions pywr-core/benches/random_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ fn random_benchmark(
|b, _n| {
// Do the setup here outside of the time-step loop
let mut state =
model.setup::<ClpSolver>(&settings).expect("Failed to setup the model.");
model.setup::<ClpSolver>(settings).expect("Failed to setup the model.");

b.iter(|| model.run_with_state(&mut state, &settings))
b.iter(|| model.run_with_state(&mut state, settings))
},
);
}
Expand All @@ -74,10 +74,10 @@ fn random_benchmark(
&(n_sys, density, n_sc),
|b, _n| {
let mut state = model
.setup::<HighsSolver>(&settings)
.setup::<HighsSolver>(settings)
.expect("Failed to setup the model.");

b.iter(|| model.run_with_state(&mut state, &settings))
b.iter(|| model.run_with_state(&mut state, settings))
},
);
}
Expand Down Expand Up @@ -313,6 +313,7 @@ fn bench_threads(c: &mut Criterion) {
}

fn bench_ipm_convergence(c: &mut Criterion) {
#[cfg(any(feature = "ipm-simd", feature = "ipm-ocl"))]
const N_THREADS: usize = 0;

let solver_setups = Vec::new();
Expand Down Expand Up @@ -354,6 +355,7 @@ fn bench_ipm_convergence(c: &mut Criterion) {
}

fn bench_ocl_chunks(c: &mut Criterion) {
#[cfg(feature = "ipm-ocl")]
const N_THREADS: usize = 0;

let solver_setups = Vec::new();
Expand Down Expand Up @@ -388,7 +390,7 @@ fn bench_ocl_chunks(c: &mut Criterion) {
/// Benchmark a large number of scenarios using various solvers
fn bench_hyper_scenarios(c: &mut Criterion) {
// Go from largest to smallest
let scenarios: Vec<usize> = (10..21).into_iter().map(|p| 2_usize.pow(p)).rev().collect();
let scenarios: Vec<usize> = (10..21).map(|p| 2_usize.pow(p)).rev().collect();

const N_THREADS: usize = 0;

Expand Down
Loading

0 comments on commit 5aafe40

Please sign in to comment.