Skip to content

Commit 6becb60

Browse files
committed
Use broken_model_options_allowed for NPV check rather than passing as arg
1 parent 0173cb1 commit 6becb60

3 files changed

Lines changed: 8 additions & 26 deletions

File tree

src/input.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ pub fn load_model<P: AsRef<Path>>(model_dir: P) -> Result<(Model, AssetPool)> {
207207
&processes,
208208
&region_ids,
209209
years,
210-
model_params.allow_broken_options,
211210
)?;
212211
let agent_ids = agents.keys().cloned().collect();
213212
let assets = read_assets(model_dir.as_ref(), &agent_ids, &processes, &region_ids)?;

src/input/agent.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ struct AgentRaw {
4646
/// * `commodities` - Commodities for the model
4747
/// * `process_ids` - The possible valid process IDs
4848
/// * `region_ids` - The possible valid region IDs
49-
/// * `allow_broken_options` - Whether to enable options that are known to be broken
5049
///
5150
/// # Returns
5251
///
@@ -57,7 +56,6 @@ pub fn read_agents(
5756
processes: &ProcessMap,
5857
region_ids: &IndexSet<RegionID>,
5958
milestone_years: &[u32],
60-
allow_broken_options: bool,
6159
) -> Result<AgentMap> {
6260
let mut agents = read_agents_file(model_dir, region_ids)?;
6361
let agent_ids = agents.keys().cloned().collect();
@@ -76,8 +74,7 @@ pub fn read_agents(
7674
.with_context(|| format!("Missing commodity portions for agent {id}"))?;
7775
}
7876

79-
let mut objectives =
80-
read_agent_objectives(model_dir, &agents, milestone_years, allow_broken_options)?;
77+
let mut objectives = read_agent_objectives(model_dir, &agents, milestone_years)?;
8178
let commodity_ids = commodities.keys().cloned().collect();
8279
let mut search_spaces = read_agent_search_space(
8380
model_dir,

src/input/agent/objective.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use super::super::{input_err_msg, read_csv, try_insert};
33
use crate::ISSUES_URL;
44
use crate::agent::{AgentID, AgentMap, AgentObjectiveMap, DecisionRule, ObjectiveType};
5-
use crate::model::ALLOW_BROKEN_OPTION_NAME;
5+
use crate::model::{ALLOW_BROKEN_OPTION_NAME, broken_model_options_allowed};
66
use crate::units::Dimensionless;
77
use crate::year::parse_year_str;
88
use anyhow::{Context, Result, ensure};
@@ -36,7 +36,6 @@ struct AgentObjectiveRaw {
3636
/// * `model_dir` - Folder containing model configuration files
3737
/// * `agents` - Map of agents
3838
/// * `milestone_years` - Milestone years for the simulation
39-
/// * `allow_broken_options` - Whether to allow broken model options
4039
///
4140
/// # Returns
4241
///
@@ -45,24 +44,17 @@ pub fn read_agent_objectives(
4544
model_dir: &Path,
4645
agents: &AgentMap,
4746
milestone_years: &[u32],
48-
allow_broken_options: bool,
4947
) -> Result<HashMap<AgentID, AgentObjectiveMap>> {
5048
let file_path = model_dir.join(AGENT_OBJECTIVES_FILE_NAME);
5149
let agent_objectives_csv = read_csv(&file_path)?;
52-
read_agent_objectives_from_iter(
53-
agent_objectives_csv,
54-
agents,
55-
milestone_years,
56-
allow_broken_options,
57-
)
58-
.with_context(|| input_err_msg(&file_path))
50+
read_agent_objectives_from_iter(agent_objectives_csv, agents, milestone_years)
51+
.with_context(|| input_err_msg(&file_path))
5952
}
6053

6154
fn read_agent_objectives_from_iter<I>(
6255
iter: I,
6356
agents: &AgentMap,
6457
milestone_years: &[u32],
65-
allow_broken_options: bool,
6658
) -> Result<HashMap<AgentID, AgentObjectiveMap>>
6759
where
6860
I: Iterator<Item = AgentObjectiveRaw>,
@@ -109,7 +101,7 @@ where
109101
.collect_vec();
110102
if !npv_years.is_empty() {
111103
ensure!(
112-
allow_broken_options,
104+
broken_model_options_allowed(),
113105
"The NPV option is BROKEN and should not be used. See: {ISSUES_URL}/716.\n\
114106
If you are sure that you want to enable it anyway, you need to set the \
115107
{ALLOW_BROKEN_OPTION_NAME} option to true."
@@ -251,7 +243,6 @@ mod tests {
251243
iter::once(objective_raw.clone()),
252244
&agents,
253245
&milestone_years,
254-
false,
255246
)
256247
.unwrap();
257248
assert_eq!(actual, expected);
@@ -261,7 +252,7 @@ mod tests {
261252
fn test_read_agent_objectives_from_iter_invalid_no_objective_for_agent(agents: AgentMap) {
262253
// Missing objective for agent
263254
assert_error!(
264-
read_agent_objectives_from_iter(iter::empty(), &agents, &[2020], false),
255+
read_agent_objectives_from_iter(iter::empty(), &agents, &[2020]),
265256
"Agent agent1 has no objectives"
266257
);
267258
}
@@ -273,12 +264,7 @@ mod tests {
273264
) {
274265
// Missing objective for milestone year
275266
assert_error!(
276-
read_agent_objectives_from_iter(
277-
iter::once(objective_raw),
278-
&agents,
279-
&[2020, 2030],
280-
false
281-
),
267+
read_agent_objectives_from_iter(iter::once(objective_raw), &agents, &[2020, 2030]),
282268
"Agent agent1 is missing objectives for the following milestone years: [2030]"
283269
);
284270
}
@@ -294,7 +280,7 @@ mod tests {
294280
decision_lexico_order: None,
295281
};
296282
assert_error!(
297-
read_agent_objectives_from_iter([bad_objective].into_iter(), &agents, &[2020], false),
283+
read_agent_objectives_from_iter([bad_objective].into_iter(), &agents, &[2020]),
298284
"Field decision_weight should be empty for this decision rule"
299285
);
300286
}

0 commit comments

Comments
 (0)