Turn off warn_infinite for phase_crossover_frequencies() calculation#1106
Merged
murrayrm merged 2 commits intopython-control:mainfrom Jan 30, 2025
Merged
Conversation
slivingston
reviewed
Jan 29, 2025
Member
slivingston
left a comment
There was a problem hiding this comment.
Good work! Besides my comment about the regression test, this is ready to merge.
control/tests/margin_test.py
Outdated
Comment on lines
15
to
19
| from ..frdata import FrequencyResponseData | ||
| from ..margins import margin, phase_crossover_frequencies, stability_margins | ||
| from ..statesp import StateSpace | ||
| from ..xferfcn import TransferFunction | ||
| from ..exception import ControlMIMONotImplemented |
Member
There was a problem hiding this comment.
Should we use relative imports in test files?
Arguments against relative imports in test files
- Although the tests/ directory is a subpackage and therefore can use the relative import syntax, this change will prevent running tests from outside of the
controlpackage. - Users of
controlnecessarily write absolute imports (import controlorfrom control...). Tests of the public API should follow the patterns of users.
Arguments in favor
- Relative import syntax is more concise.
- I might have missed something, but none of the CI jobs run the tests against a copy of
controlother than where they are located. In other words, "running tests from outside of thecontrolpackage" is not done in practice, so not important to support. - We are already using the relative import syntax in config_test.py.
For comparison, neither numpy nor scipy seem to be consistent: most of their tests are written using absolute imports (import numpy or import scipy etc.), but some tests use relative imports.
Conclusion
I like the generality in principle of keeping these as absolute imports, but practically both patterns seem good.
| ((np.array([3, 11, 3]) * 1e-4, [1., -2.7145, 2.4562, -0.7408], .1), | ||
| [1.6235, 0.], [-0.28598, 1.88889]), | ||
| (([200.0], [1.0, 21.0, 20.0, 0.0]), | ||
| [4.47213595, 0], [-0.47619048, inf]), |
Member
There was a problem hiding this comment.
Warnings do not cause the test to fail, so this case does not provide a regression test. To fix this, add the decorator @pytest.mark.filterwarnings("error") as done in another test in margin_test.py.
slivingston
approved these changes
Jan 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses #1105 where warning messages were being generated if a system had poles at the origin (which generates a phase crossover at infinity). The fix was simple: warning messages should be turned off when computing the crossover gains (as they are in
stability_margins).