From 1a0f442bba581b17e87b57b1adabdfede43d04f7 Mon Sep 17 00:00:00 2001 From: Christina Cai Date: Wed, 12 Apr 2023 14:22:17 -0400 Subject: [PATCH 1/4] added return types for model.py --- openmc/model/model.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/openmc/model/model.py b/openmc/model/model.py index 4202cf60b..dd9251804 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -7,6 +7,7 @@ from numbers import Integral from tempfile import NamedTemporaryFile import warnings from xml.etree import ElementTree as ET +from typing import Optional import h5py @@ -16,6 +17,7 @@ from openmc.dummy_comm import DummyCommunicator from openmc.executor import _process_CLI_arguments from openmc.checkvalue import check_type, check_value from openmc.exceptions import InvalidIDError +from openmc.model import Model @contextmanager @@ -93,27 +95,27 @@ class Model: self.plots = plots @property - def geometry(self): + def geometry(self) -> Optional[openmc.Geometry]: return self._geometry @property - def materials(self): + def materials(self) -> Optional[openmc.Materials]: return self._materials @property - def settings(self): + def settings(self) -> Optional[openmc.Settings]: return self._settings @property - def tallies(self): + def tallies(self) -> Optional[openmc.Tallies]: return self._tallies @property - def plots(self): + def plots(self) -> Optional[openmc.Plots]: return self._plots @property - def is_initialized(self): + def is_initialized(self) -> bool: try: import openmc.lib return openmc.lib.is_initialized @@ -122,7 +124,7 @@ class Model: @property @lru_cache(maxsize=None) - def _materials_by_id(self): + def _materials_by_id(self) -> dict: """Dictionary mapping material ID --> material""" if self.materials: mats = self.materials @@ -132,14 +134,14 @@ class Model: @property @lru_cache(maxsize=None) - def _cells_by_id(self): + def _cells_by_id(self) -> dict: """Dictionary mapping cell ID --> cell""" cells = self.geometry.get_all_cells() return {cell.id: cell for cell in cells.values()} @property @lru_cache(maxsize=None) - def _cells_by_name(self): + def _cells_by_name(self) -> dict: # Get the names maps, but since names are not unique, store a set for # each name key. In this way when the user requests a change by a name, # the change will be applied to all of the same name. @@ -152,7 +154,7 @@ class Model: @property @lru_cache(maxsize=None) - def _materials_by_name(self): + def _materials_by_name(self) -> dict: if self.materials is None: mats = self.geometry.get_all_materials().values() else: @@ -207,7 +209,7 @@ class Model: @classmethod def from_xml(cls, geometry='geometry.xml', materials='materials.xml', settings='settings.xml', tallies='tallies.xml', - plots='plots.xml'): + plots='plots.xml') -> Model: """Create model from existing XML files Parameters @@ -597,7 +599,7 @@ class Model: def run(self, particles=None, threads=None, geometry_debug=False, restart_file=None, tracks=False, output=True, cwd='.', openmc_exec='openmc', mpi_args=None, event_based=None, - export_model_xml=True): + export_model_xml=True) -> Optional[Path]: """Runs OpenMC. If the C API has been initialized, then the C API is used, otherwise, this method creates the XML files and runs OpenMC via a system call. In both cases this method returns the path to the last From f7457d6427aa708f7140782b9447af44b80150c5 Mon Sep 17 00:00:00 2001 From: Christina Cai Date: Wed, 12 Apr 2023 15:11:13 -0400 Subject: [PATCH 2/4] fixed circular import error --- openmc/model/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/model/model.py b/openmc/model/model.py index dd9251804..caf630180 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -1,3 +1,4 @@ +from __future__ import annotations from collections.abc import Iterable from contextlib import contextmanager from functools import lru_cache @@ -17,7 +18,6 @@ from openmc.dummy_comm import DummyCommunicator from openmc.executor import _process_CLI_arguments from openmc.checkvalue import check_type, check_value from openmc.exceptions import InvalidIDError -from openmc.model import Model @contextmanager From 55b4df553c43cc0d25645621cac6927ba2e287c7 Mon Sep 17 00:00:00 2001 From: christinacai123 <63215816+christinacai123@users.noreply.github.com> Date: Sat, 15 Apr 2023 15:54:41 -0400 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Paul Romano --- openmc/model/model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openmc/model/model.py b/openmc/model/model.py index 1da6b3bf2..ba44777dd 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -8,7 +8,7 @@ from numbers import Integral from tempfile import NamedTemporaryFile import warnings from xml.etree import ElementTree as ET -from typing import Optional +from typing import Optional, Dict import h5py @@ -141,7 +141,7 @@ class Model: @property @lru_cache(maxsize=None) - def _cells_by_name(self) -> dict: + def _cells_by_name(self) -> Dict[int, openmc.Cell]: # Get the names maps, but since names are not unique, store a set for # each name key. In this way when the user requests a change by a name, # the change will be applied to all of the same name. @@ -154,7 +154,7 @@ class Model: @property @lru_cache(maxsize=None) - def _materials_by_name(self) -> dict: + def _materials_by_name(self) -> Dict[int, openmc.Material]: if self.materials is None: mats = self.geometry.get_all_materials().values() else: From 0280631fe7ee1e6b6ad5f85c8f0f44b51d3ff331 Mon Sep 17 00:00:00 2001 From: christinacai123 <63215816+christinacai123@users.noreply.github.com> Date: Tue, 18 Apr 2023 13:46:33 -0400 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Paul Romano --- openmc/model/model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openmc/model/model.py b/openmc/model/model.py index ba44777dd..933e1172e 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -606,7 +606,6 @@ class Model: this method creates the XML files and runs OpenMC via a system call. In both cases this method returns the path to the last statepoint file generated. - .. versionchanged:: 0.12 Instead of returning the final k-effective value, this function now returns the path to the final statepoint written.