Skip to content

Use the builder pattern in core#703

Open
jetuk wants to merge 13 commits into
mainfrom
core-builder
Open

Use the builder pattern in core#703
jetuk wants to merge 13 commits into
mainfrom
core-builder

Conversation

@jetuk

@jetuk jetuk commented Jun 18, 2026

Copy link
Copy Markdown
Member

The main design goal here is to remove mutable methods from core's Network. This will allow us to make stronger guarantees about the safety of indices in any given network (because you can only create one via a builder).

It is a big refactor, but also simplifies the schema crate by removing the two stage (add-to-network then set-constraints) process. The schema now just needs to add things to the builder.

@jetuk jetuk requested a review from Batch21 June 18, 2026 14:31
jetuk added 5 commits July 2, 2026 10:12
This moves some of the logic for constructing a complex core
network into core itself. This is done using the builder pattern
and should result in general move of code from schema to core.

The eventual design goal is to have Network be generated and
have only immutable methods. The solver and state can then
be created using a unique ID (see generative pattern) allowing them
to safely access network items without bounds checking (i.e.
all indexes are known to be valid).

Removes a lot of mutability in the main structs (e.g. Network).
This will allow safe use of unchecked methods during simulation
in future. See example with the ParameterTimings struct.

# Conflicts:
#	pywr-core/src/models/multi.rs
# Conflicts:
#	pywr-schema/src/nodes/core.rs
#	pywr-schema/src/nodes/delay.rs
#	pywr-schema/src/nodes/loss_link.rs
#	pywr-schema/src/nodes/piecewise_link.rs
#	pywr-schema/src/nodes/river.rs
#	pywr-schema/src/nodes/river_gauge.rs
#	pywr-schema/src/parameters/discount_factor.rs
#	pywr-schema/src/parameters/hydropower.rs
#	pywr-schema/src/parameters/indexed_array.rs
#	pywr-schema/src/parameters/interpolated.rs
#	pywr-schema/src/parameters/polynomial.rs
#	pywr-schema/src/parameters/tables.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant