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

Unify controls and polynomial controls #1078

Merged
merged 18 commits into from
Jun 26, 2024

Conversation

johnjasa
Copy link
Member

Summary

This PR simplifies a lot of the controls-based logic to remove the separation between polynomial and full controls.
This doesn't add or remove any capability but it simplifies a lot of code under the hood.
We'll be able to more easily add other control types (b-splines? others?) if desired with these changes.
All tests are passing locally for me but I'll address any failures on CI as well.

Questions:

  • I've called regular controls "full" controls within the code. Is this a good name? What name should we use instead? To be clear, I've introduce a control_type option that has full or polynomial as possibilities.
  • Are there other implications of the changes in this PR that I need to address?

Backwards incompatibilities

Introduced a deprecation warning for add_polynomial_control; the method still works in this version but can be removed later on.

New Dependencies

None

@johnjasa johnjasa requested a review from robfalck June 18, 2024 16:02
@coveralls
Copy link

Coverage Status

coverage: 92.803% (+0.5%) from 92.35%
when pulling e0c8a30 on johnjasa:rework_controls
into 6ee8eec on OpenMDAO:master.

@coveralls
Copy link

Coverage Status

coverage: 92.707% (+0.4%) from 92.35%
when pulling df9e551 on johnjasa:rework_controls
into 6ee8eec on OpenMDAO:master.


def add_control(self, name, units=_unspecified, desc=_unspecified, opt=_unspecified,
fix_initial=_unspecified, fix_final=_unspecified, targets=_unspecified,
def add_control(self, name, control_type=_unspecified, order=_unspecified, units=_unspecified, desc=_unspecified,
Copy link
Contributor

Choose a reason for hiding this comment

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

We should put control_type and order at the end of the arguments list here. Anyone using positional arguments would have their code broken by this change.

We should also raise deprecation warnings for add_polynomial_control

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call, I've reordered control_type to be at the end everywhere.

I have a deprecation warning for add_polynomial_control like this, let me know if you want to see a change:

        om.issue_warning(f'{self.pathname}: The method `add_polynomial_control` is '
                         'deprecated and will be removed in Dymos 2.1. Please use '
                         '`add_control` with the appropriate options to define a polynomial control.',
                         category=om.OMDeprecationWarning)

@@ -639,8 +631,8 @@ def add_control(self, name, units=_unspecified, desc=_unspecified, opt=_unspecif
rate2_continuity_scaler=rate2_continuity_scaler,
rate2_continuity_ref=rate2_continuity_ref)

def set_control_options(self, name, units=_unspecified, desc=_unspecified, opt=_unspecified,
fix_initial=_unspecified, fix_final=_unspecified, targets=_unspecified,
def set_control_options(self, name, control_type=_unspecified, order=_unspecified, units=_unspecified, desc=_unspecified,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, move control_type and order to the end, and deprecate set_polynomial_control_options.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added it back in and added a deprecation warning.

@@ -220,12 +220,6 @@
" :noindex:\n",
"```\n",
"\n",
"## set_polynomial_control_options\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave this in as deprecated. Also search the ipynb files in docs and make sure that we use the new API in all of the documented examples.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it, I've added that back in and searched through the docs and switched to using the new API; checking CI results now.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@@ -619,6 +619,15 @@ def add_control(self, name, order=_unspecified, units=_unspecified, desc=_unspec
self.control_options[name] = ControlOptionsDictionary()
self.control_options[name]['name'] = name

# if continuity, rate_continuity, or rate2_continuity are not specified, default to False for cases when control_type is 'polynomial'
if control_type == 'polynomial':
if continuity is _unspecified:
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no such thing as continuity here anyway right? To specify it is wrong. I think you could cover the polynomial case more concisely with continuity = rate_continuity = rate2_continuity = False if the control_type == 'poylnomial'

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it, updated accordingly!

@coveralls
Copy link

Coverage Status

coverage: 92.574% (+0.2%) from 92.35%
when pulling a1854f5 on johnjasa:rework_controls
into 6ee8eec on OpenMDAO:master.

@robfalck robfalck merged commit ddb8627 into OpenMDAO:master Jun 26, 2024
10 checks passed
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.

3 participants