Repository: pybamm-team/PyBaMM
Pull request #4953 (2025-04-03 09:18:24)

Adds property for `model._built`
# Description

Adds a property for accessing the built status of the model.

Fixes # (issue)

## Type of change

Please add a line in the relevant section of [CHANGELOG.md](https://github.com/pybamm-team/PyBaMM/blob/develop/CHANGELOG.md) to document the change (include PR #)

# Important checks:

Please confirm the following before marking the PR as ready for review:
- No style issues: `nox -s pre-commit`
- All tests pass: `nox -s tests`
- The documentation builds: `nox -s doctests`
- Code is commented for hard-to-understand areas
- Tests added that prove fix is effective or that feature works


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pybamm-team/PyBaMM/pull/4953?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 98.70%. Comparing base [(`d694132`)](https://app.codecov.io/gh/pybamm-team/PyBaMM/commit/d69413282d69b76c43dc4bf509abd850b222204d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team) to head [(`a95a574`)](https://app.codecov.io/gh/pybamm-team/PyBaMM/commit/a95a5744f2d15dceefbf4f1047132206fd27cfad?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff            @@
##           develop    #4953   +/-   ##
========================================
  Coverage    98.70%   98.70%           
========================================
  Files          304      304           
  Lines        23698    23701    +3     
========================================
+ Hits         23391    23394    +3     
  Misses         307      307           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/pybamm-team/PyBaMM/pull/4953?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
BradyPlanden: Thanks for the reviews @rtimms @agriyakhetarpal! I don't have merge access, so if one of you can merge when you are happy that would be appreciated.

Patch:
diff --git a/src/pybamm/models/base_model.py b/src/pybamm/models/base_model.py
index acf82f373..a8dc6aa5e 100644
--- a/src/pybamm/models/base_model.py
+++ b/src/pybamm/models/base_model.py
@@ -288,6 +288,11 @@ class BaseModel:
     def concatenated_initial_conditions(self, concatenated_initial_conditions):
         self._concatenated_initial_conditions = concatenated_initial_conditions
 
+    @property
+    def built(self):
+        "Returns a boolean for the model built status."
+        return self._built
+
     @property
     def mass_matrix(self):
         """Returns the mass matrix for the system of differential equations after discretisation."""


Test patch:
diff --git a/tests/unit/test_models/test_base_model.py b/tests/unit/test_models/test_base_model.py
index 9885c2bf0..2b1f16245 100644
--- a/tests/unit/test_models/test_base_model.py
+++ b/tests/unit/test_models/test_base_model.py
@@ -1227,6 +1227,7 @@ class TestBaseModel:
         assert not model._built
         model.build_model()
         assert model._built
+        assert model._built == model.built
         u = model.variables["u"]
         v = model.variables["v"]
         assert model.rhs[u].value == 2