Skip to content

Commit

Permalink
Add "default" to parameters in math docs
Browse files Browse the repository at this point in the history
  • Loading branch information
brynpickering committed Sep 26, 2024
1 parent 683a5b7 commit fe41c3d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/calliope/backend/latex_backend_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import jinja2
import numpy as np
import pandas as pd
import xarray as xr

from calliope.backend import backend_model, parsing
Expand Down Expand Up @@ -424,11 +425,13 @@ def add_parameter( # noqa: D102, override
"math_repr": rf"\textit{{{parameter_name}}}"
+ self._dims_to_var_string(parameter_values),
}
if pd.notna(default):
attrs["default"] = default

self._add_to_dataset(parameter_name, parameter_values, "parameters", attrs)

def add_constraint( # noqa: D102, override
self, name: str, constraint_dict: parsing.UnparsedConstraint | None = None
self, name: str, constraint_dict: parsing.UnparsedConstraint
) -> None:
equation_strings: list = []

Expand Down Expand Up @@ -488,7 +491,7 @@ def _constraint_setter(where: xr.DataArray, references: set) -> xr.DataArray:
)

def add_global_expression( # noqa: D102, override
self, name: str, expression_dict: parsing.UnparsedExpression | None = None
self, name: str, expression_dict: parsing.UnparsedExpression
) -> None:
equation_strings: list = []

Expand All @@ -515,7 +518,7 @@ def _expression_setter(
)

def add_variable( # noqa: D102, override
self, name: str, variable_dict: parsing.UnparsedVariable | None = None
self, name: str, variable_dict: parsing.UnparsedVariable
) -> None:
domain_dict = {"real": r"\mathbb{R}\;", "integer": r"\mathbb{Z}\;"}
bound_refs: set = set()
Expand Down Expand Up @@ -544,7 +547,7 @@ def _variable_setter(where: xr.DataArray, references: set) -> xr.DataArray:
)

def add_objective( # noqa: D102, override
self, name: str, objective_dict: parsing.UnparsedObjective | None = None
self, name: str, objective_dict: parsing.UnparsedObjective
) -> None:
sense_dict = {
"minimize": r"\min{}",
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,13 @@ def dummy_model_data(config_defaults, model_defaults):
"all_nan": np.nan,
"with_inf": 100,
"only_techs": 5,
"no_dims": 0,
**model_defaults,
}
)
# This value is set on the parameter directly to ensure it finds its way through to the LaTex math.
model_data.no_dims.attrs["default"] = 0

model_data.attrs["math"] = AttrDict(
{"constraints": {}, "variables": {}, "global_expressions": {}, "objectives": {}}
)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_backend_latex_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ def test_create_obj_list(self, dummy_latex_backend_model):
\begin{itemize}
\item expr
\end{itemize}
\textbf{Default}: 0
\end{document}"""
),
),
Expand Down Expand Up @@ -421,6 +423,8 @@ def test_create_obj_list(self, dummy_latex_backend_model):
**Used in**:
* expr
**Default**: 0
"""
),
),
Expand Down Expand Up @@ -454,6 +458,8 @@ def test_create_obj_list(self, dummy_latex_backend_model):
**Used in**:
* [expr](#expr)
**Default**: 0
"""
),
),
Expand Down Expand Up @@ -589,6 +595,8 @@ def test_generate_math_doc_mkdocs_features_admonition(self, dummy_model_data):
??? info "Used in"
* [expr](#expr)
**Default**: 0
"""
)

Expand Down

0 comments on commit fe41c3d

Please sign in to comment.