Fix random state for kmean clustering #313
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the kmeans algorithm is used to cluster networks, this is not deterministic by default. The result is that repeated runs of the
simplify_network
andcluster_network
rules can and usually do produce different results that vary randomly. This makes results less reproducible when given only a pypsa-eur configuration file.Changes proposed in this Pull Request
The fix is to supply a fixed random state to the k-means algorithm.
It might be considered if this should be done PyPSA itself, in the
busmap_by_kmeans
functions innetworkclustering.py
. That's an equally valid option, but maybe a bit opinionated.I have not checked in a very rigorous way if there are any other sources of randomness in the network building process, but I don't think so.
Checklist
envs/environment.yaml
andenvs/environment.docs.yaml
.config.default.yaml
,config.tutorial.yaml
, andtest/config.test1.yaml
.doc/configtables/*.csv
and line references are adjusted indoc/configuration.rst
anddoc/tutorial.rst
.doc/release_notes.rst
is amended in the format of previous release notes.