Skip to content

Commit

Permalink
Merge pull request #449 from fast-aircraft-design/issue_448-reports
Browse files Browse the repository at this point in the history
Deactivated automatic reports.
  • Loading branch information
ScottDelbecq committed Jul 25, 2022
2 parents b9742b0 + de568a7 commit 710af2d
Showing 1 changed file with 40 additions and 30 deletions.
70 changes: 40 additions & 30 deletions src/fastoad/openmdao/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import os
import warnings
from copy import deepcopy
from typing import Tuple
Expand Down Expand Up @@ -38,14 +38,24 @@


class FASTOADProblem(om.Problem):
"""Vanilla OpenMDAO Problem except that it can write its outputs to a file.
"""
Vanilla OpenMDAO Problem except that it can write its outputs to a file.
It also runs :class:`~fastoad.openmdao.validity_checker.ValidityDomainChecker`
after each :meth:`run_model` or :meth:`run_driver`
(but it does nothing if no check has been registered).
"""

def __init__(self, *args, **kwargs):
if (
version.parse(openmdao.__version__) >= version.parse("3.17")
and "OPENMDAO_REPORTS" not in os.environ
and "reports" not in kwargs
and len(args) < 5
):
# Automatic reports are deactivated for FAST-OAD, unless OPENMDAO_REPORTS env
# variable is set.
kwargs["reports"] = None
super().__init__(*args, **kwargs)

#: File path where :meth:`read_inputs` will read inputs
Expand Down Expand Up @@ -244,35 +254,35 @@ def _get_io_metadata(
):
# In OpenMDAO >3.16, get_io_metadata() won't complain after dynamically shaped, non-
# connected inputs.
if version.parse(openmdao.__version__) > version.parse("3.16"):
if version.parse(openmdao.__version__) >= version.parse("3.17"):
return system.get_io_metadata(iotypes)
else:
# For OpenMDAO<=3.16, we try the vanilla get_io_metadata() and if it fails, we
# try with our simplified implementation.
try:
return system.get_io_metadata(iotypes)
except RuntimeError:
prefix = system.pathname + "." if system.pathname else ""
rel_idx = len(prefix)
if isinstance(iotypes, str):
iotypes = (iotypes,)

result = {}
for iotype in iotypes:
for abs_name, prom in system._var_abs2prom[iotype].items():
rel_name = abs_name[rel_idx:]
meta = system._var_allprocs_abs2meta[iotype].get(abs_name)
ret_meta = _MetadataDict(meta) if meta is not None else None
if ret_meta is not None:
ret_meta["prom_name"] = prom
result[rel_name] = ret_meta

warnings.warn(
"Dynamically shaped problem inputs are better managed with OpenMDAO>3.16 "
"Upgrade is recommended.",
DeprecationWarning,
)
return result

# For OpenMDAO<=3.16, we try the vanilla get_io_metadata() and if it fails, we
# try with our simplified implementation.
try:
return system.get_io_metadata(iotypes)
except RuntimeError:
prefix = system.pathname + "." if system.pathname else ""
rel_idx = len(prefix)
if isinstance(iotypes, str):
iotypes = (iotypes,)

result = {}
for iotype in iotypes:
for abs_name, prom in system._var_abs2prom[iotype].items():
rel_name = abs_name[rel_idx:]
meta = system._var_allprocs_abs2meta[iotype].get(abs_name)
ret_meta = _MetadataDict(meta) if meta is not None else None
if ret_meta is not None:
ret_meta["prom_name"] = prom
result[rel_name] = ret_meta

warnings.warn(
"Dynamically shaped problem inputs are better managed with OpenMDAO>3.16 "
"Upgrade is recommended.",
DeprecationWarning,
)
return result


class AutoUnitsDefaultGroup(om.Group):
Expand Down

0 comments on commit 710af2d

Please sign in to comment.