Skip to content

Commit 696767e

Browse files
authored
Merge pull request #1058 from EnergySystemsModellingLab/code_documentation_fixes
Fixes for in-code documentation
2 parents e1cef62 + 373d49e commit 696767e

40 files changed

+282
-135
lines changed

src/agent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub type AgentCommodityPortionsMap = HashMap<(CommodityID, u32), Dimensionless>;
2121
/// A map for the agent's search space, keyed by commodity and year
2222
pub type AgentSearchSpaceMap = HashMap<(CommodityID, u32), Rc<Vec<Rc<Process>>>>;
2323

24-
/// A map of objectives for an agent, keyed by commodity and year.
24+
/// A map of objectives for an agent, keyed by year.
2525
///
2626
/// NB: As we currently only support the "single" decision rule, the only parameter we need for
2727
/// objectives is the type.

src/asset.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub struct AssetGroupID(u32);
6363
/// determined by the investment algorithm.
6464
///
6565
/// `Future` and `Candidate` assets can be converted to `Commissioned` assets by calling
66-
/// `commission_future` or `commission_candidate` respectively.
66+
/// the `commission` method (or via pool operations that commission future/selected assets).
6767
///
6868
/// `Commissioned` assets can be decommissioned by calling `decommission`.
6969
#[derive(Clone, Debug, PartialEq, strum::Display)]
@@ -826,12 +826,12 @@ impl Asset {
826826
mothballed_year, ..
827827
} = &self.state
828828
else {
829-
panic!("Cannot mothball an asset that hasn't been commissioned")
829+
panic!("Cannot get mothballed year for an asset that hasn't been commissioned")
830830
};
831831
*mothballed_year
832832
}
833833

834-
/// Checks if the assets corresponds to a process that has a `unit_size` and is therefore divisible.
834+
/// Checks if the asset corresponds to a process that has a `unit_size` and is therefore divisible.
835835
pub fn is_divisible(&self) -> bool {
836836
self.process.unit_size.is_some()
837837
}

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! The command line interface for the simulation.
1+
//! Command-line interface for the MUSE2 simulation.
22
use crate::graph::save_commodity_graphs_for_model;
33
use crate::input::{load_commodity_graphs, load_model};
44
use crate::log;
@@ -105,7 +105,7 @@ impl Commands {
105105
}
106106
}
107107

108-
/// Parse CLI arguments and start MUSE2
108+
/// Parse CLI arguments and run the requested command or show help.
109109
pub fn run_cli() -> Result<()> {
110110
let cli = Cli::parse();
111111

src/graph.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,11 @@ impl Display for GraphEdge {
6969

7070
/// Helper function to return a possible flow operating in the requested year
7171
///
72-
/// We are interested only on the flows direction, which are always the same for all years. So this
73-
/// function checks if the process can be operating in the target year and region and, if so, it
74-
/// returns its flows. It considers not only when the process can be commissioned, but also the
75-
/// lifetime of the process, since a process can be opperating many years after the commission time
76-
/// window is over. If the process cannot be opperating in the target year and region, None is
77-
/// returned.
72+
/// We are only interested in the flow directions, which are constant across years. This
73+
/// function checks whether the process can be operating in the target region and year and, if so,
74+
/// returns its flows. It considers both the commission year and the process lifetime, since a
75+
/// process may operate for years after its commission window. If the process cannot be operating
76+
/// in the target region/year, `None` is returned.
7877
fn get_flow_for_year(
7978
process: &Process,
8079
target: (RegionID, u32),
@@ -85,7 +84,7 @@ fn get_flow_for_year(
8584
}
8685

8786
// Otherwise we try to find one that operates in the target year. It is assumed that
88-
// parameters are defined in the same (region, year) combinations than flows, at least.
87+
// parameters are defined for at least the same (region, year) combinations as flows.
8988
let (target_region, target_year) = target;
9089
for ((region, year), value) in &process.flows {
9190
if *region != target_region {

src/graph/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn can_be_active(
100100

101101
/// Validates that the commodity graph follows the rules for different commodity types.
102102
///
103-
/// It takes as input a graph created by `create_commodities_graph_for_validation`, which is built
103+
/// It takes as input a graph prepared by `prepare_commodities_graph_for_validation`, which is built
104104
/// for a specific time slice selection (must match the `time_slice_level` passed to this function).
105105
///
106106
/// The validation is only performed for commodities with the specified time slice level. For full

src/id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ pub(crate) use define_id_getter;
103103

104104
/// A data structure containing a set of IDs
105105
pub trait IDCollection<ID: IDLike> {
106-
/// Check if the ID is in the collection, returning a copy of it if found.
106+
/// Check if the ID is in the collection, returning a reference to it if found.
107107
///
108108
/// # Arguments
109109
///
110110
/// * `id` - The ID to check (can be string or ID type)
111111
///
112112
/// # Returns
113113
///
114-
/// A copy of the ID in `self`, or an error if not found.
114+
/// A reference to the ID in `self`, or an error if not found.
115115
fn get_id<T: Borrow<str> + Display + ?Sized>(&self, id: &T) -> Result<&ID>;
116116
}
117117

src/input.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<K: Eq + Hash, V> Insert<K, V> for IndexMap<K, V> {
5151

5252
/// Read a series of type `T`s from a CSV file.
5353
///
54-
/// Will raise an error if the file is empty.
54+
/// Returns an error if the file is empty.
5555
///
5656
/// # Arguments
5757
///
@@ -178,9 +178,11 @@ where
178178
iter.into_iter().tuple_windows().all(|(a, b)| a < b)
179179
}
180180

181-
/// Inserts a key-value pair into a `HashMap` if the key does not already exist.
181+
/// Insert a key-value pair into a map implementing the `Insert` trait if the key does not
182+
/// already exist.
182183
///
183-
/// If the key already exists, it returns an error with a message indicating the key's existence.
184+
/// If the key already exists, this returns an error with a message indicating the key's
185+
/// existence.
184186
pub fn try_insert<M, K, V>(map: &mut M, key: &K, value: V) -> Result<()>
185187
where
186188
M: Insert<K, V>,

src/input/agent.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ struct AgentRaw {
4242
///
4343
/// * `model_dir` - Folder containing model configuration files
4444
/// * `commodities` - Commodities for the model
45-
/// * `process_ids` - The possible valid process IDs
45+
/// * `processes` - Processes available in the model
4646
/// * `region_ids` - The possible valid region IDs
47+
/// * `milestone_years` - Milestone years in the model
4748
///
4849
/// # Returns
4950
///
50-
/// A map of Agents, with the agent ID as the key
51+
/// A map of agents keyed by agent ID
5152
pub fn read_agents(
5253
model_dir: &Path,
5354
commodities: &CommodityMap,
@@ -89,17 +90,16 @@ pub fn read_agents(
8990
Ok(agents)
9091
}
9192

92-
/// Read agents info from the agents.csv file.
93+
/// Read agents info from the `agents.csv` file.
9394
///
9495
/// # Arguments
9596
///
9697
/// * `model_dir` - Folder containing model configuration files
97-
/// * `commodities` - Commodities for the model
98-
/// * `process_ids` - The possible valid process IDs
98+
/// * `region_ids` - The possible valid region IDs
9999
///
100100
/// # Returns
101101
///
102-
/// A map of Agents, with the agent ID as the key
102+
/// A map of agents keyed by agent ID
103103
fn read_agents_file(model_dir: &Path, region_ids: &IndexSet<RegionID>) -> Result<AgentMap> {
104104
let file_path = model_dir.join(AGENT_FILE_NAME);
105105
let agents_csv = read_csv(&file_path)?;

src/input/agent/commodity_portion.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Code for reading the agent commodities CSV file.
1+
//! Code for reading agent commodity portions from a CSV file.
22
use super::super::{deserialise_proportion_nonzero, input_err_msg, read_csv, try_insert};
33
use crate::agent::{AgentCommodityPortionsMap, AgentID, AgentMap};
44
use crate::commodity::{CommodityMap, CommodityType};
@@ -33,10 +33,14 @@ struct AgentCommodityPortionRaw {
3333
/// # Arguments
3434
///
3535
/// * `model_dir` - Folder containing model configuration files
36+
/// * `agents` - Known agents in the model
37+
/// * `commodities` - Known commodities in the model
38+
/// * `region_ids` - Known region identifiers
39+
/// * `milestone_years` - Milestone years used by the model
3640
///
3741
/// # Returns
3842
///
39-
/// A map of Agents, with the agent ID as the key
43+
/// A `HashMap` mapping `AgentID` to `AgentCommodityPortionsMap`.
4044
pub fn read_agent_commodity_portions(
4145
model_dir: &Path,
4246
agents: &AgentMap,

src/input/agent/objective.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Code for reading the agent objectives CSV file.
1+
//! Code for reading agent objectives from a CSV file.
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};
@@ -17,11 +17,11 @@ const AGENT_OBJECTIVES_FILE_NAME: &str = "agent_objectives.csv";
1717
/// An objective for an agent with associated parameters
1818
#[derive(Debug, Clone, Deserialize, PartialEq)]
1919
struct AgentObjectiveRaw {
20-
/// Unique agent id identifying the agent this objective belongs to
20+
/// Unique agent id identifying the agent this objective belongs to.
2121
agent_id: AgentID,
2222
/// The year(s) the objective is relevant for
2323
years: String,
24-
/// Acronym identifying the objective (e.g. LCOX)
24+
/// Acronym identifying the objective (e.g. LCOX).
2525
objective_type: ObjectiveType,
2626
/// For the weighted sum decision rule, the set of weights to apply to each objective.
2727
decision_weight: Option<Dimensionless>,
@@ -39,7 +39,7 @@ struct AgentObjectiveRaw {
3939
///
4040
/// # Returns
4141
///
42-
/// A map of Agents, with the agent ID as the key
42+
/// A `HashMap` mapping `AgentID` to `AgentObjectiveMap`.
4343
pub fn read_agent_objectives(
4444
model_dir: &Path,
4545
agents: &AgentMap,

0 commit comments

Comments
 (0)