Skip to content

Commit

Permalink
Merge branch 'main' into allocation_level_control_node
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Feb 9, 2024
2 parents a560d43 + 94a02aa commit 6c757c0
Show file tree
Hide file tree
Showing 45 changed files with 3,390 additions and 3,211 deletions.
1 change: 0 additions & 1 deletion .docker/.env

This file was deleted.

12 changes: 0 additions & 12 deletions .docker/compose.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .docker/start.sh

This file was deleted.

6 changes: 0 additions & 6 deletions .docker/stop.sh

This file was deleted.

6 changes: 0 additions & 6 deletions .docker/test.sh

This file was deleted.

4 changes: 1 addition & 3 deletions .github/workflows/python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:
cancel-in-progress: true
jobs:
test:
name: Python ${{ matrix.python-version }} - ${{ matrix.os }} - ${{ matrix.arch }}
name: Python ${{ matrix.python-version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -24,8 +24,6 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
arch:
- x86
steps:
- uses: actions/checkout@v4

Expand Down
43 changes: 25 additions & 18 deletions .github/workflows/qgis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@ name: QGIS Tests

on:
push:
branches: [main, update/pixi-lock]
branches: [main]
paths-ignore: [".teamcity/**"]
tags: ["*"]
pull_request:
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test-qgis:
name: "Test"
runs-on: ubuntu-latest
if: false # Disable tests until we have time to fix them
defaults:
run:
working-directory: .docker
steps:

- name: Check out repository
uses: actions/checkout@v4
- name: Launching docker compose
run: ./start.sh
- name: Running tests
run: ./test.sh
- name: Stopping docker compose
run: ./stop.sh
test:
name: QGIS plugin ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macOS-latest
- windows-latest
steps:
- uses: actions/checkout@v4
- uses: prefix-dev/setup-pixi@v0.4.1
with:
pixi-version: "latest"
- name: Prepare pixi
run: |
pixi run install-without-pre-commit
- name: Run tests
run: pixi run test-ribasim-qgis-cov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
2 changes: 1 addition & 1 deletion core/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Ribasim"
uuid = "aac5e3d9-0b8f-4d4f-8241-b1a7a9632635"
authors = ["Deltares and contributors <ribasim.info@deltares.nl>"]
manifest = "../Manifest.toml"
version = "2024.02.0"
version = "2024.2.0"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
20 changes: 12 additions & 8 deletions core/src/Ribasim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For more granular access, see:
- [`Config`](@ref)
- [`Model`](@ref)
- [`solve!`](@ref)
- [`BMI.finalize`](@ref)
- [`write_results`](@ref)
"""
module Ribasim

Expand Down Expand Up @@ -75,19 +75,23 @@ export libribasim
const to = TimerOutput()
TimerOutputs.complement!()

include("validation.jl")
include("solve.jl")
include("schema.jl")
include("config.jl")
using .config
include("parameter.jl")
include("validation.jl")
include("solve.jl")
include("logging.jl")
include("allocation_init.jl")
include("allocation_optim.jl")
include("utils.jl")
include("lib.jl")
include("io.jl")
include("create.jl")
include("util.jl")
include("sparsity.jl")
include("graph.jl")
include("model.jl")
include("read.jl")
include("write.jl")
include("bmi.jl")
include("consts.jl")
include("callback.jl")
include("main.jl")
include("libribasim.jl")

Expand Down
33 changes: 0 additions & 33 deletions core/src/allocation_init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,39 +283,6 @@ end

const allocation_source_nodetypes = Set{Symbol}([:level_boundary, :flow_boundary])

"""
The source nodes must only have one allocation outneighbor and no allocation inneighbors.
"""
function valid_sources(p::Parameters, allocation_network_id::Int)::Bool
(; graph) = p

edge_ids = graph[].edge_ids[allocation_network_id]

errors = false

for edge in edge_ids
(id_source, id_dst) = edge
if graph[id_source, id_dst].allocation_network_id_source == allocation_network_id
from_source_node = graph[id_source].type in allocation_source_nodetypes

if is_main_network(allocation_network_id)
if !from_source_node
errors = true
@error "The source node of source edge $edge in the main network must be one of $allocation_source_nodetypes."
end
else
from_main_network = is_main_network(graph[id_source].allocation_network_id)

if !from_source_node && !from_main_network
errors = true
@error "The source node of source edge $edge for subnetwork $allocation_network_id is neither a source node nor is it coming from the main network."
end
end
end
end
return !errors
end

"""
Remove allocation user return flow edges that are upstream of the user itself.
"""
Expand Down
11 changes: 8 additions & 3 deletions core/src/allocation_optim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function set_objective_priority!(
)::Nothing
(; objective_type, problem, allocation_network_id) = allocation_model
(; graph, user, allocation, basin) = p
(; demand, node_id) = user
(; demand, demand_itp, demand_from_timeseries, node_id) = user
(; main_network_connections, subnetwork_demands, priorities) = allocation
edge_ids = graph[].edge_ids[allocation_network_id]
node_ids = graph[].node_ids[allocation_network_id]
Expand Down Expand Up @@ -160,7 +160,12 @@ function set_objective_priority!(
end

user_idx = findsorted(node_id, node_id_user)
d = demand[user_idx][priority_idx](t)
if demand_from_timeseries[user_idx]
d = demand_itp[user_idx][priority_idx](t)
set_user_demand!(user, node_id_user, priority_idx, d)
else
d = get_user_demand(user, node_id_user, priority_idx)
end
demand_max = max(demand_max, d)
add_user_term!(ex, edge_id, objective_type, d, problem)
end
Expand Down Expand Up @@ -243,7 +248,7 @@ function assign_allocations!(
push!(record.allocation_network_id, allocation_model.allocation_network_id)
push!(record.user_node_id, Int(user_node_id))
push!(record.priority, allocation.priorities[priority_idx])
push!(record.demand, user.demand[user_idx][priority_idx](t))
push!(record.demand, user.demand[user_idx])
push!(record.allocated, allocated)
# TODO: This is now the last abstraction before the allocation update,
# should be the average abstraction since the last allocation solve
Expand Down
Loading

0 comments on commit 6c757c0

Please sign in to comment.