Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shape handling in nom_addGlobalDV #194

Merged
merged 11 commits into from
Apr 21, 2023
Merged

Fix shape handling in nom_addGlobalDV #194

merged 11 commits into from
Apr 21, 2023

Conversation

A-CGray
Copy link
Member

@A-CGray A-CGray commented Apr 4, 2023

Purpose

This PR fixes the nom_addGlobalDV method in the MPhys wrapper so that it accepts scalar arguments to the value argument, just like the actual addGlobalDV method does. Previously this would fail because nom_addGlobalDV would try and evaluate len(value). The shape of the DV is now automatically extracted from the DV after it is added to the DVGeo object.

Also, I added a docstring because docs are nice.

Expected time until merged

1 week

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (non-backwards-compatible fix or feature)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Documentation update
  • Maintenance update
  • Other (please describe)

Testing

Checklist

  • I have run flake8 and black to make sure the Python code adheres to PEP-8 and is consistently formatted
  • I have formatted the Fortran code with fprettify or C/C++ code with clang-format as applicable
  • I have run unit and regression tests which pass locally with my changes
  • I have added new tests that prove my fix is effective or that my feature works
  • I have added necessary documentation

@A-CGray A-CGray requested a review from a team as a code owner April 4, 2023 14:34
@A-CGray A-CGray requested review from hajdik, sseraj, anilyil and bernardopacini and removed request for sseraj April 4, 2023 14:34
@codecov
Copy link

codecov bot commented Apr 4, 2023

Codecov Report

Merging #194 (5e2827f) into main (0e6b356) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #194      +/-   ##
==========================================
- Coverage   64.88%   64.87%   -0.02%     
==========================================
  Files          47       47              
  Lines       11939    11941       +2     
==========================================
  Hits         7747     7747              
- Misses       4192     4194       +2     
Impacted Files Coverage Δ
pygeo/mphys/mphys_dvgeo.py 0.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines 139 to 169
"""Add a global design variable to the DVGeo object. This is a wrapper for the DVGeo.addGlobalDV method.

Parameters
----------
dvName : str
A unique name to be given to this design variable group

value : float, or iterable list of floats
The starting value(s) for the design variable. This
parameter may be a single variable or a numpy array
(or list) if the function requires more than one
variable. The number of variables is determined by the
rank (and if rank ==1, the length) of this parameter.

func : python function
The python function handle that will be used to apply the
design variable

childIdx : int, optional
The zero-based index of the child FFD, if this DV is for a child FFD.
The index is defined by the order in which you add the child FFD to the parent.
For example, the first child FFD has an index of 0, the second an index of 1, and so on.

isComposite : bool, optional
Whether this DV is to be included in the composite DVs, by default False

Raises
------
RuntimeError
Raised if the underlying DVGeo object is not an FFD
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to start putting docstrings in the MPhys wrapper? We'd have to maintain the common attributes in two places then and that could get messy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the very very least there should be a docstring that explains the MPhys-specific arguments to the function, for the remainder of the arguments it might be fine to point to the docstring for the original DVGeo function.

bernardopacini
bernardopacini previously approved these changes Apr 7, 2023
Copy link
Contributor

@bernardopacini bernardopacini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! I agree that we should start adding doc strings for anything that is MPhys-specific, but leave the rest for the pyGeo core.

@A-CGray
Copy link
Member Author

A-CGray commented Apr 10, 2023

I have no idea what is going on with the docs build

WARNING: autodoc: failed to import class 'mphys.mphys_dvgeo.OM_DVGEOCOMP' from module 'pygeo'; the following exception was raised:
Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/mdolab-pygeo/envs/194/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py", line 58, in import_module
    return importlib.import_module(modname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mdolab-pygeo/envs/194/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/docs/checkouts/readthedocs.org/user_builds/mdolab-pygeo/checkouts/194/pygeo/mphys/__init__.py", line 1, in <module>
    from .mphys_dvgeo import OM_DVGEOCOMP
  File "/home/docs/checkouts/readthedocs.org/user_builds/mdolab-pygeo/checkouts/194/pygeo/mphys/mphys_dvgeo.py", line 4, in <module>
    import openmdao.api as om
  File "/home/docs/checkouts/readthedocs.org/user_builds/mdolab-pygeo/envs/194/lib/python3.7/site-packages/openmdao/api.py", line 20, in <module>
    from openmdao.components.exec_comp import ExecComp
  File "/home/docs/checkouts/readthedocs.org/user_builds/mdolab-pygeo/envs/194/lib/python3.7/site-packages/openmdao/components/exec_comp.py", line 1266, in <module>
    if Version(scipy.__version__) >= Version("1.5.0"):
  File "/home/docs/checkouts/readthedocs.org/user_builds/mdolab-pygeo/envs/194/lib/python3.7/site-packages/packaging/version.py", line 195, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object

@eirikurj
Copy link
Contributor

Seems to be missing the mphys module here

autodoc_mock_imports = ["numpy", "mpi4py", "scipy", "pyspline", "baseclasses", "pysurf", "prefoil", "pyOCSM", "openvsp"]

@eirikurj
Copy link
Contributor

Hmm, actually, reading this again I think its openmdao that is the issue. Let me push something quick.

@A-CGray
Copy link
Member Author

A-CGray commented Apr 17, 2023

Oh nice, thanks for fixing that. This is ready to go now @bernardopacini @hajdik

hajdik
hajdik previously approved these changes Apr 20, 2023
bernardopacini
bernardopacini previously approved these changes Apr 21, 2023
Copy link
Contributor

@bernardopacini bernardopacini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @A-CGray

@@ -1,2 +1,4 @@
numpydoc
sphinx_mdolab_theme
openmdao
mphys
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these necessary or is the mock import enough?

@hajdik hajdik dismissed stale reviews from bernardopacini and themself via 5e2827f April 21, 2023 19:05
@bernardopacini bernardopacini self-requested a review April 21, 2023 19:08
Copy link
Contributor

@bernardopacini bernardopacini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @sseraj. Looks good to me again.

@hajdik hajdik merged commit f6a44b1 into main Apr 21, 2023
@hajdik hajdik deleted the allowScalarDVMPhys branch April 21, 2023 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants