diff --git a/examples/circularity/model.toml b/examples/circularity/model.toml index b26bb0a8..98be065b 100644 --- a/examples/circularity/model.toml +++ b/examples/circularity/model.toml @@ -1,2 +1 @@ milestone_years = [2020, 2030, 2040] -please_give_me_broken_results = true diff --git a/src/simulation/investment.rs b/src/simulation/investment.rs index 8c2fd0dc..2cc41e0a 100644 --- a/src/simulation/investment.rs +++ b/src/simulation/investment.rs @@ -3,14 +3,13 @@ use super::optimisation::{DispatchRun, FlowMap}; use crate::agent::{Agent, AgentID}; use crate::asset::{Asset, AssetIterator, AssetRef, AssetState}; use crate::commodity::{Commodity, CommodityID, CommodityMap}; -use crate::model::ALLOW_BROKEN_OPTION_NAME; use crate::model::Model; use crate::output::DataWriter; use crate::region::RegionID; use crate::simulation::CommodityPrices; use crate::time_slice::{TimeSliceID, TimeSliceInfo}; use crate::units::{Capacity, Dimensionless, Flow, FlowPerCapacity}; -use anyhow::{Context, Result, bail, ensure}; +use anyhow::{Context, Result, ensure}; use indexmap::IndexMap; use itertools::{Itertools, chain}; use log::debug; @@ -102,6 +101,14 @@ impl InvestmentSet { previously_selected_assets, writer, ) + .with_context(|| { + format!( + "Investments failed for market set {self} with cyclical dependencies. \ + Please note that the investment algorithm is currently experimental for \ + models with circular commodity dependencies and may not work in all \ + scenarios." + ) + }) } InvestmentSet::Layer(investment_sets) => { debug!("Starting asset selection for layer '{self}'"); @@ -332,14 +339,6 @@ fn select_assets_for_cycle( // Precompute a joined string for logging let markets_str = markets.iter().map(|(c, r)| format!("{c}|{r}")).join(", "); - if !model.parameters.allow_broken_options { - bail!( - "Detected cycle for markets ({markets_str}). \ - Cyclic investment sets are currently experimental. \ - To run anyway, set the {ALLOW_BROKEN_OPTION_NAME} option to true." - ); - } - // Iterate over the markets to select assets let mut current_demand = demand.clone(); let mut assets_for_cycle = HashMap::new(); diff --git a/tests/regenerate_test_data.sh b/tests/regenerate_test_data.sh index 263ba07b..9267bb78 100755 --- a/tests/regenerate_test_data.sh +++ b/tests/regenerate_test_data.sh @@ -30,11 +30,6 @@ run_example() { } for example in $examples; do - # Skip the circularity example - if [ "$example" = circularity ]; then - continue - fi - # We only need debug files for the simple model debug=false if [ "$example" = simple ]; then diff --git a/tests/regression_circularity.rs b/tests/regression_circularity.rs new file mode 100644 index 00000000..77631798 --- /dev/null +++ b/tests/regression_circularity.rs @@ -0,0 +1,8 @@ +//! A regression test for the `circularity` example +mod regression; +use regression::run_regression_test; + +#[test] +fn regression_circularity() { + run_regression_test("circularity"); +}