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.
66use crate :: asset:: check_capacity_valid_for_asset;
77use crate :: input:: {
88 deserialise_proportion_nonzero, input_err_msg, is_sorted_and_unique, read_toml,
@@ -16,42 +16,42 @@ use std::sync::OnceLock;
1616
1717const 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);
8989pub 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
171171fn 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