Skip to content

Commit 302f558

Browse files
authored
Merge pull request #1224 from EnergySystemsModellingLab/broken-options-naming
Refer to "dangerous" rather than "broken" options
2 parents 8a89d22 + a5fb37c commit 302f558

File tree

4 files changed

+53
-49
lines changed

4 files changed

+53
-49
lines changed

schemas/input/model.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ properties:
4949
please_give_me_broken_results:
5050
type: boolean
5151
description: |
52-
Allows other options that are known to be broken to be used. Please don't ever enable this.
52+
Allows other options that are potentially dangerous to be used, such as experimental features and parameters that are known to have correctness bugs. This option should only ever be enabled by developers.
53+
54+
Never enable this for experiments that you care about, particularly if you intend to publish the results.
5355
remaining_demand_absolute_tolerance:
5456
type: number
5557
description: |

src/input/commodity.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::commodity::{
55
BalanceType, Commodity, CommodityID, CommodityLevyMap, CommodityMap, CommodityType, DemandMap,
66
PricingStrategy,
77
};
8-
use crate::model::{ALLOW_BROKEN_OPTION_NAME, broken_model_options_allowed};
8+
use crate::model::{ALLOW_DANGEROUS_OPTION_NAME, dangerous_model_options_enabled};
99
use crate::region::RegionID;
1010
use crate::time_slice::{TimeSliceInfo, TimeSliceLevel};
1111
use anyhow::{Context, Ok, Result, ensure};
@@ -167,9 +167,9 @@ fn validate_commodity(commodity: &Commodity) -> Result<()> {
167167
// Gatekeep scarcity-adjusted pricing option
168168
if commodity.pricing_strategy == PricingStrategy::ScarcityAdjusted {
169169
ensure!(
170-
broken_model_options_allowed(),
170+
dangerous_model_options_enabled(),
171171
"The 'scarcity' pricing strategy is currently experimental. \
172-
To run anyway, set the {ALLOW_BROKEN_OPTION_NAME} option to true."
172+
To run anyway, set the {ALLOW_DANGEROUS_OPTION_NAME} option to true."
173173
);
174174
warn!(
175175
"The pricing strategy for {} is set to 'scarcity'. Commodity prices may be \

src/model.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use std::collections::HashMap;
1010
use std::path::PathBuf;
1111

1212
pub mod parameters;
13-
pub use parameters::{ALLOW_BROKEN_OPTION_NAME, ModelParameters, broken_model_options_allowed};
13+
pub use parameters::{
14+
ALLOW_DANGEROUS_OPTION_NAME, ModelParameters, dangerous_model_options_enabled,
15+
};
1416

1517
/// Model definition
1618
pub struct Model {

src/model/parameters.rs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Read and validate model parameters from `model.toml`.
22
//!
3-
//! This module defines the `ModelParameters` struct and helpers for loading and
4-
//! validating the `model.toml` configuration used by the model. Validation
5-
//! functions ensure sensible numeric ranges and invariants for runtime use.
3+
//! This module defines the `ModelParameters` struct and helpers for loading and validating the
4+
//! `model.toml` configuration used by the model. Validation functions ensure sensible numeric
5+
//! ranges and invariants for runtime use.
66
use crate::asset::check_capacity_valid_for_asset;
77
use crate::input::{
88
deserialise_proportion_nonzero, input_err_msg, is_sorted_and_unique, read_toml,
@@ -16,42 +16,42 @@ use std::sync::OnceLock;
1616

1717
const MODEL_PARAMETERS_FILE_NAME: &str = "model.toml";
1818

19-
/// The key in `model.toml` which enables known-broken model options.
19+
/// The key in `model.toml` which enables potentially dangerous model options.
2020
///
21-
/// If this option is present and true, the model will permit certain
22-
/// experimental or unsafe behaviours that are normally disallowed.
23-
pub const ALLOW_BROKEN_OPTION_NAME: &str = "please_give_me_broken_results";
21+
/// If this option is present and true, the model will permit certain experimental or unsafe
22+
/// behaviours that are normally disallowed.
23+
pub const ALLOW_DANGEROUS_OPTION_NAME: &str = "please_give_me_broken_results";
2424

25-
/// Global flag indicating whether broken model options have been enabled.
25+
/// Global flag indicating whether potentially dangerous model options have been enabled.
2626
///
27-
/// This is stored in a `OnceLock` and must be set exactly once during
28-
/// startup (see `set_broken_model_options_flag`).
29-
static BROKEN_OPTIONS_ALLOWED: OnceLock<bool> = OnceLock::new();
27+
/// This is stored in a `OnceLock` and must be set exactly once during startup (see
28+
/// [`set_dangerous_model_options_flag`]).
29+
static DANGEROUS_OPTIONS_ENABLED: OnceLock<bool> = OnceLock::new();
3030

31-
/// Return whether broken model options were enabled by the loaded config.
31+
/// Whether potentially dangerous model options were enabled by the loaded config.
3232
///
3333
/// # Panics
3434
///
3535
/// Panics if the global flag has not been set yet (the flag should be set by
36-
/// `ModelParameters::from_path` during program initialization).
37-
pub fn broken_model_options_allowed() -> bool {
38-
*BROKEN_OPTIONS_ALLOWED
36+
/// [`ModelParameters::from_path`] during program initialisation).
37+
pub fn dangerous_model_options_enabled() -> bool {
38+
*DANGEROUS_OPTIONS_ENABLED
3939
.get()
40-
.expect("Broken options flag not set")
40+
.expect("Dangerous options flag not set")
4141
}
4242

43-
/// Set the global flag indicating whether broken model options are allowed.
43+
/// Set the global flag indicating whether potentially dangerous model options are enabled.
4444
///
4545
/// Can only be called once; subsequent calls will panic (except in tests, where it can be called
4646
/// multiple times so long as the value is the same).
47-
fn set_broken_model_options_flag(allowed: bool) {
48-
let result = BROKEN_OPTIONS_ALLOWED.set(allowed);
47+
fn set_dangerous_model_options_flag(enabled: bool) {
48+
let result = DANGEROUS_OPTIONS_ENABLED.set(enabled);
4949
if result.is_err() {
5050
if cfg!(test) {
5151
// Sanity check
52-
assert_eq!(allowed, broken_model_options_allowed());
52+
assert_eq!(enabled, dangerous_model_options_enabled());
5353
} else {
54-
panic!("Attempted to set BROKEN_OPTIONS_ALLOWED twice");
54+
panic!("Attempted to set DANGEROUS_OPTIONS_ENABLED twice");
5555
}
5656
}
5757
}
@@ -89,9 +89,9 @@ define_param_default!(default_mothball_years, u32, 0);
8989
pub struct ModelParameters {
9090
/// Milestone years
9191
pub milestone_years: Vec<u32>,
92-
/// Allow known-broken options to be enabled.
92+
/// Allow potentially dangerous options to be enabled.
9393
#[serde(default, rename = "please_give_me_broken_results")] // Can't use constant here :-(
94-
pub allow_broken_options: bool,
94+
pub allow_dangerous_options: bool,
9595
/// The (small) value of capacity given to candidate assets.
9696
///
9797
/// Don't change unless you know what you're doing.
@@ -169,7 +169,7 @@ fn check_price_tolerance(value: Dimensionless) -> Result<()> {
169169
}
170170

171171
fn check_remaining_demand_absolute_tolerance(
172-
allow_broken_options: bool,
172+
dangerous_options_enabled: bool,
173173
value: Flow,
174174
) -> Result<()> {
175175
ensure!(
@@ -178,12 +178,12 @@ fn check_remaining_demand_absolute_tolerance(
178178
);
179179

180180
let default_value = default_remaining_demand_absolute_tolerance();
181-
if !allow_broken_options {
181+
if !dangerous_options_enabled {
182182
ensure!(
183183
value == default_value,
184-
"Setting a remaining_demand_absolute_tolerance different from the default value of {:e} \
185-
is potentially dangerous, set please_give_me_broken_results to true \
186-
if you want to allow this.",
184+
"Setting a remaining_demand_absolute_tolerance different from the default value of \
185+
{:e} is potentially dangerous, set {ALLOW_DANGEROUS_OPTION_NAME} to true if you want \
186+
to allow this.",
187187
default_value.0
188188
);
189189
}
@@ -215,7 +215,7 @@ impl ModelParameters {
215215
let file_path = model_dir.as_ref().join(MODEL_PARAMETERS_FILE_NAME);
216216
let model_params: ModelParameters = read_toml(&file_path)?;
217217

218-
set_broken_model_options_flag(model_params.allow_broken_options);
218+
set_dangerous_model_options_flag(model_params.allow_dangerous_options);
219219

220220
model_params
221221
.validate()
@@ -226,9 +226,9 @@ impl ModelParameters {
226226

227227
/// Validate parameters after reading in file
228228
fn validate(&self) -> Result<()> {
229-
if self.allow_broken_options {
229+
if self.allow_dangerous_options {
230230
warn!(
231-
"!!! You've enabled the {ALLOW_BROKEN_OPTION_NAME} option. !!!\n\
231+
"!!! You've enabled the {ALLOW_DANGEROUS_OPTION_NAME} option. !!!\n\
232232
I see you like to live dangerously 😈. This option should ONLY be used by \
233233
developers as it can cause peculiar behaviour that breaks things. NEVER enable it \
234234
for results you actually care about or want to publish. You have been warned!"
@@ -258,7 +258,7 @@ impl ModelParameters {
258258

259259
// remaining_demand_absolute_tolerance
260260
check_remaining_demand_absolute_tolerance(
261-
self.allow_broken_options,
261+
self.allow_dangerous_options,
262262
self.remaining_demand_absolute_tolerance,
263263
)?;
264264

@@ -390,12 +390,12 @@ mod tests {
390390
}
391391

392392
#[rstest]
393-
#[case(true, 0.0, true)] // Valid minimum value broken options allowed
394-
#[case(true, 1e-10, true)] // Valid value with broken options allowed
395-
#[case(true, 1e-15, true)] // Valid value with broken options allowed
396-
#[case(false, 1e-12, true)] // Valid value same as default, no broken options needed
397-
#[case(true, 1.0, true)] // Valid larger value with broken options allowed
398-
#[case(true, f64::MAX, true)] // Valid maximum finite value with broken options allowed
393+
#[case(true, 0.0, true)] // Valid minimum value dangerous options allowed
394+
#[case(true, 1e-10, true)] // Valid value with dangerous options allowed
395+
#[case(true, 1e-15, true)] // Valid value with dangerous options allowed
396+
#[case(false, 1e-12, true)] // Valid value same as default, no dangerous options needed
397+
#[case(true, 1.0, true)] // Valid larger value with dangerous options allowed
398+
#[case(true, f64::MAX, true)] // Valid maximum finite value with dangerous options allowed
399399
#[case(true, -1e-10, false)] // Invalid: negative value
400400
#[case(true, f64::INFINITY, false)] // Invalid: positive infinity
401401
#[case(true, f64::NEG_INFINITY, false)] // Invalid: negative infinity
@@ -405,12 +405,12 @@ mod tests {
405405
#[case(false, f64::NEG_INFINITY, false)] // Invalid: negative infinity
406406
#[case(false, f64::NAN, false)] // Invalid: NaN
407407
fn check_remaining_demand_absolute_tolerance_works(
408-
#[case] allow_broken_options: bool,
408+
#[case] allow_dangerous_options: bool,
409409
#[case] value: f64,
410410
#[case] expected_valid: bool,
411411
) {
412412
let flow = Flow::new(value);
413-
let result = check_remaining_demand_absolute_tolerance(allow_broken_options, flow);
413+
let result = check_remaining_demand_absolute_tolerance(allow_dangerous_options, flow);
414414

415415
assert_validation_result(
416416
result,
@@ -425,7 +425,7 @@ mod tests {
425425
#[case(1e-10)] // Larger than default (1e-12)
426426
#[case(1.0)] // Well above default
427427
#[case(f64::MAX)] // Maximum finite value
428-
fn check_remaining_demand_absolute_tolerance_requires_broken_options_if_non_default(
428+
fn check_remaining_demand_absolute_tolerance_requires_dangerous_options_if_non_default(
429429
#[case] value: f64,
430430
) {
431431
let flow = Flow::new(value);
@@ -434,9 +434,9 @@ mod tests {
434434
result,
435435
false,
436436
value,
437-
"Setting a remaining_demand_absolute_tolerance different from the default value \
438-
of 1e-12 is potentially dangerous, set \
439-
please_give_me_broken_results to true if you want to allow this.",
437+
"Setting a remaining_demand_absolute_tolerance different from the default value of \
438+
1e-12 is potentially dangerous, set please_give_me_broken_results to true if you want \
439+
to allow this.",
440440
);
441441
}
442442

0 commit comments

Comments
 (0)